Function not working after calling class
-
I added a message handler function in my main script. That script calls a class that has a form for settings and when the form is submitted a second class is used to store the data.
In my first class, I added a call to the message handler and it works. But after submitting the form I try to display another message and the function doesn’t get called. The echo statement shows the call worked. Actually, except for the message handler, the full code saves to the database correctly. Do I need to have the form page reload something to get this to work or is there a better way?
<?php /** Plugin Name: My Script **/ add_action( 'admin_menu' , 'My_script'); function My_script(){ $page_title = 'My_script'; $menu_title = 'My_script'; $capability = 'manage_options'; $menu_slug = 'myscript_viewer'; $function = 'myscript_functions'; add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function ); add_submenu_page( $menu_slug, $page_title, 'Settings', 'manage_options', 'myscript-settings-submenu-page', 'myscript_settings_page' ); } function myscript_functions(){ } function myscript_settings_page() { require_once dirname( __FILE__ ) . '/includes/class-myscript.php'; require_once dirname( __FILE__ ) . '/includes/class-myscript-database.php'; $page = new myscript_database( plugin_basename( __FILE__ ) ); <?php $page->DisplaySettings(); } function NoticeHandler($msg) { <div class="notice notice-error"> <p> <?php echo $msg; ?> </p> </div> } add_action( 'admin_notices', 'NoticeHandler' ); //In my main class class myscript_main { public function __construct( $plugin_basename ) { } public function DisplaySettings() { NoticeHandler('test'); wp_nonce_field( 'alter-settings', 'verified' ); ?> <form name="settings-form" action="<?= esc_url( $_SERVER['REQUEST_URI'] ) ?>" method="post"> <input type="text" name="test" value="0" >Test <input type="submit" class="button button-primary" name="save-settings" id="save-settings" value="<?= esc_html_e( 'Save Settings', 'Myscript_viewer' ) ?>" /> </form> <?php if (check_admin_referer('alter-settings', 'verified')) { //form was submitted $result = $this->SaveDatabaseSettings(); echo 'got result'; } NoticeHandler('test'); } //In my database class class myscript_database extends myscript_main { public function __construct( ) { } public function SaveDatabaseSettings() { return "failed"; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Function not working after calling class’ is closed to new replies.