插件设置页面未更新

时间:2019-02-25 作者:A new 1

跟踪之后this tutorial
除了命名之外,我目前面临着一个错误:Error: Settings page wasn\'t found (翻译)

这是我的代码:

class ConfigPlugin
{

public function __construct()
{
    add_action(\'admin_menu\', array($this, \'create_plugin_settings_page\'));
    add_action(\'admin_menu\', array($this, \'setup_section\'));
    add_action( \'admin_init\', array( $this, \'setup_fields\' ) );
}

public function create_plugin_settings_page()
{
    $page_title = \'Configg harray kotter\';
    $menu_title = \'Config my plug-in\';
    $capability = \'manage_options\';
    $slug = \'Plugin\';
    $callback = array( $this, \'plugin_settings_page_content\' );
    $icon = \'dashicons-admin-plugins\';
    $position = 100;

    add_menu_page($page_title, $menu_title, $capability, $slug, $callback, $icon, $position);
}

public function plugin_settings_page_content()
{
    ?>
<div class="wrap">
    <h2>My Awesome Settings Page</h2>
    <form method="post" action="options.php">
        <?php
            settings_fields( \'Plugin\' );
            do_settings_sections( \'Plugin\' );
            submit_button();
        ?>
    </form>
</div> <?php
}

public function setup_section()
{
    add_settings_section(\'section\', \'1\', [$this, \'callback\'], \'Plugin\');

}

public function  callback($params) {
    switch ($params[\'id\']) {
        case \'section\' :
            echo \'Im so depressed<br>\';

            break;
    }
}

public function setup_fields() {
    add_settings_field( \'field\', \'Text Name\', array( $this, \'field_callback\' ), \'Plugin\', \'section\' );
}

public function field_callback($arguments)
{
    echo \'<input name="field" id="field" type="text" value="hi\' . get_option( \'field\' ) . \'" />\';
    register_setting(\'Plugin\', \'field\');
}

}
我不知道发生了什么,我很感激每一个小小的暗示:)

更新:
我现在知道出了什么问题。我发布了解决方案here.
感谢您提供6个视图,但没有任何线索:/

1 个回复
SO网友:A new 1

我不知道为什么会这样,但看起来register_setting 不应该在的回调中add_settings_field

// no actual code
// this worked
add_settings_field(\'id\',\'title\', /*callback*/ function($arguments) {echo $htmlcode;}), \'page\', \'section\');
register_setting(\'option_group\', \'option_name\');
我希望这有帮助