0

I'm working on my first plugin. I am having difficulty getting the settings_fields function to display the results of the settings fields' callback functions. I've been studying the settings api, but I cannot figure out where I've gone wrong. I've attached a screenshot of what is rendering, as well as the code in question. Thanks for any help provided.

Result: the results of do_settings_sections shows up, but not settings_fields

if(!class_exists('ce_add_scripts')){

    class ce_add_scripts{

        function __construct(){
            add_action('admin_init', array(&$this,'ceas_admin_init'));
            add_action('admin_menu', array(&$this,'ceas_admin_menu'));
            add_action('wp_head', array(&$this,'ceas_wp_head'));
            add_action('wp_footer', array(&$this,'ceas_wp_footer'));
        }

        function ceas_admin_menu(){
            add_submenu_page(
                'tools.php', 
                'CE Add Scripts', 
                'CE Add Scripts', 
                'update_plugins', 
                'ceas_menu_page', 
                array(&$this,'ceas_page_callback') );
        }

        function ceas_admin_init(){
            $args= array(
                'type'=>'string',
                'default'=>NULL,);

            register_setting(
                'ceas_options', 
                'ceas_main_settings', 
                $args);

            add_settings_section(
                'ceas_options_section',
                'Insert Scripts to Head or Footer',
                array(&$this,'ceas_section_display'),
                'ceas_menu_page');

            add_settings_field(
                'ceas_options_field_0',
                'Head Script Entry',
                'ceas_head_script',
                'CE Add Scripts',
                'ceas_options_section');

            add_settings_field(
                'ceas_options_field_1',
                'Footer Script Entry',
                'ceas_footer_script',
                'CE Add Scripts',
                'ceas_options_section');
        }

        function ceas_section_display(){
            echo 'Add scripts to the Head or Footer';
        }

        function ceas_head_script(){
            $options = get_option('ceas_main_settings');

            echo "<textarea cols='40' rows='5' name='ceas_main_settings[ceas_options_field_0]'>";
            echo $options['ceas_options_field_0'];
            echo "</textarea>";
        }

        function ceas_footer_script(){
            $options = get_option('ceas_main_settings');

            echo "<textarea cols='40' rows='5' name='ceas_main_settings[ceas_options_field_1]'>";
            echo $options['ceas_options_field_1'];
            echo "</textarea>";
        }

        function ceas_page_callback(){

            echo "<div class='wrap'>

            <form action='options.php' method='post'>

            <h1>CE Add Scripts Settings</h1>";

            settings_fields("ceas_options");
            do_settings_sections('ceas_menu_page');
            submit_button();


            echo "</form> 
            </div>";
        }

    }

    $ce_actualize= new ce_add_scripts();
}
0

The the code below:

if(!class_exists('ce_add_scripts')){

    class ce_add_scripts{

        function __construct(){
            add_action('admin_init', array(&$this,'ceas_admin_init'));
            add_action('admin_menu', array(&$this,'ceas_admin_menu'));
            add_action('wp_head', array(&$this,'ceas_wp_head'));
            add_action('wp_footer', array(&$this,'ceas_wp_footer'));
        }

        function ceas_admin_menu(){
            add_submenu_page(
                'tools.php', 
                'CE Add Scripts', 
                'CE Add Scripts', 
                'update_plugins', 
                'ceas_menu_page', 
                array(&$this,'ceas_page_callback') );
        }

        function ceas_admin_init(){
            $args= array(
                'type'=>'string',
                'default'=>NULL,);

            register_setting(
                'ceas_options', 
                'ceas_main_settings', 
                $args);

            add_settings_section(
                'ceas_options_section',
                'Insert Scripts to Head or Footer',
                array(&$this,'ceas_section_display'),
                'ceas_menu_page');

            add_settings_field(
                'ceas_options_field_0',
                'Head Script Entry',
                'ceas_head_script',
                'CE Add Scripts',
                'ceas_options_section');

            add_settings_field(
                'ceas_options_field_1',
                'Footer Script Entry',
                'ceas_footer_script',
                'CE Add Scripts',
                'ceas_options_section');
        }

        function ceas_section_display(){
            echo 'Add scripts to the Head or Footer';
        }

        function ceas_head_script(){
            $options = get_option('ceas_main_settings');
            if(!isset($options['ceas_options_field_0'])){
                $options['ceas_options_field_0'] = '';
            }
            echo "<textarea cols='40' rows='5' name='ceas_main_settings[ceas_options_field_0]'>";
            echo $options['ceas_options_field_0'];
            echo "</textarea>";
        }

        function ceas_footer_script(){
            $options = get_option('ceas_main_settings');
            if(!isset($options['ceas_options_field_1'])){
                $options['ceas_options_field_1'] = '';
            }
            echo "<textarea cols='40' rows='5' name='ceas_main_settings[ceas_options_field_1]'>";
            echo $options['ceas_options_field_1'];
            echo "</textarea>";
        }

        function ceas_page_callback(){

            echo "<div class='wrap'>

            <form action='options.php' method='post'>

            <h1>CE Add Scripts Settings</h1>";

            settings_fields("ceas_options");
            do_settings_sections('ceas_menu_page');
            $this->ceas_head_script();
            $this->ceas_footer_script();
            submit_button();


            echo "</form> 
            </div>";
        }

    }

    $ce_actualize= new ce_add_scripts();
}
  • Can you provide some comments as to what you changed and why it's different? – MikeNGarrett Apr 9 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.