Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have try to add hook on load my plugin page. But every time i save my config, it always return "Are you sure want to ..." message. Is there something i missed? Here's my code:

<?php

class myClassPlugin {

    public $menu_slug;

    function __construct() {
        $config = $this->get_setting();
        $this->menu_slug = 'my_menu_slug';

        if (is_admin()) {
            $hook = 'toplevel_page_' . $this->menu_slug;
            add_action('load-' . $hook, array(&$this, 'save_settings'));
            add_action('admin_menu', array(&$this, 'create_menu'));

        }
    }

    function get_setting() {
        $config = get_option('my_options_config', array('set_a' => '','set_b' => ''));
        return $config;
    }


    function create_menu() {
        $hook = add_menu_page('MyMenu', 'My Menu', 'edit_others_posts', $this->menu_slug, array(&$this, 'setting'));
    }

    function setting() {
        $config = $this->get_setting(); ?>
        <form name="my_form" action="" method="post">      
            <?php wp_nonce_field('my_nonce_name', 'my_nonce_name');  
            submit_button();
            ?>
        </form>
    </div>
    <?php
        // $this->save_setting();
}

function save_settings() {
    if (isset($_POST['my_nonce_name'])) {
        check_admin_referer('my_nonce_name');
        $options = array('set_a' => $_POST['set_a'], 'set_b' => $_POST['set_b']);

        update_option('my_options_config', $options);
    }
}

}

new myClassPlugin();
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.