Как я могу добавить страницу параметров для моего плагина на основе классов?


Я пытаюсь использовать новый API настроек с плагином на основе классов для добавления страницы настроек. Это код, который у меня есть до сих пор:

class simple_sample_plugin{
    function simple_sample_plugin()
    {
        add_action('init', array(&$this, 'init'));
    }
    function init()
    {
        add_action('admin_menu', array(&$this, 'admin_menu'));
        add_action('admin_init', array(&$this, 'admin_init'));
    }
    function admin_init()
    {
        register_setting(
            'sample'  // A settings group name. Must exist prior to the register_setting call.
            ,'sample_options' //  The name of an option to sanitize and save.
            ,array($this, 'set_options') //  A callback function that sanitizes the option's value.
        );
        // Register our settings field group
        add_settings_section(
            'sample_section1', // String for use in the 'id' attribute of tags.
            'Section 1', //  Title of the section.
            '__return_false', // Function that fills the section with the desired content. The function should echo its output.
            'sample' //  The type of settings page on which to show the section (general, reading, writing, media etc.)
        );
        // Register our individual settings fields
        add_settings_field(
            'color_scheme'  // String for use in the 'id' attribute of tags.
            ,'Color Scheme' // Title of the field.
            ,array($this, 'color_scheme') // Function that fills the field with the desired inputs as part of the larger form. Passed a single argument, the $args array. Name and id of the input should match the $id given to this function. The function should echo its output.
            ,'sample' //  The type of settings page on which to show the field (general, reading, writing, ...).
            ,'sample_section1' // The section of the settings page in which to show the box (default or a section you added with add_settings_section, look at the page in the source to see what the existing ones are.)
            ,array() // $args - Additional arguments that are passed to the $callback function. The 'label_for' key can be used to give the field a label different from $title.
        );
    }
    function set_options()
    {

    }
  function color_scheme()
    {
      echo "<textarea type='text' rows='2' cols='80' name='sample_options[color_scheme]'>";
      echo time();
      echo "</textarea>";
  }
    function admin_menu()
    {
        add_options_page(
            __('sample') //page title
            ,__('sample') //menu title
            ,'edit_posts' //capability
            ,'sample' //menu-slug
            ,array(&$this, 'settings_page') //function callback
        );

    }
    function settings_page()
    { ?>
    <div class="wrap">
    <h2>sample Options</h2>
    <form class="myform" method="post" action="options.php"> 
    <?php

        settings_fields('sample');
        do_settings_sections('sample_section1');


    ?>
    <script type="text/javascript">
        jQuery('.myform input:hidden').prop('type','text');


    </script>
    <input type="submit" value="Save" />
    </form>
    </div>
    <?php
    }
}
global $simple_sample_plugin;
$simple_sample_plugin = new simple_sample_plugin();

Я старался сделать это как можно более чистым и простым, и я пытался сделать это в соответствии с множеством руководств и документации.

У меня также есть строка jQuery для отображения скрытых полей.

Единственная проблема, однако, заключается в том, что это не работает. То есть он добавляет страницу параметров образца, но поле ценностей там нет.

Скриншот:

Снимок экрана с тенью.png http://img600.imageshack.us/img600/4526/screenshotwithshadow.png

Помогите! Что я делаю не так? Я пытаюсь это сделать уже 24 часа.

Author: cwd, 2012-01-26

1 answers

Попробуйте изменить

 do_settings_sections('sample_section1');

До

 do_settings_sections('sample');
 2
Author: ungestaltbar, 2012-01-30 08:54:24