$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>options - Plugins Settings page not updating|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

options - Plugins Settings page not updating

matteradmin10PV0评论

After following this tutorial
in mostly everything, except the naming,
I am currently facing an error: Error: Settings page wasn't found (translated)

This is my code:

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');
}

}

I have no idea whats happening and I am thankful for every little hint :)

UPDATE:
I now know what went wrong. I posted the solution here.
Thank you for 6 views and no clues :/

After following this tutorial
in mostly everything, except the naming,
I am currently facing an error: Error: Settings page wasn't found (translated)

This is my code:

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');
}

}

I have no idea whats happening and I am thankful for every little hint :)

UPDATE:
I now know what went wrong. I posted the solution here.
Thank you for 6 views and no clues :/

Share Improve this question edited Feb 26, 2019 at 10:39 A new 1 asked Feb 25, 2019 at 15:41 A new 1A new 1 93 bronze badges 2
  • 1 I suggest you to write a self-answer to this question, post it as mark as correct, so others will find a solution in case they need. – Fabrizio Mele Commented Feb 26, 2019 at 10:40
  • @FabrizioMele I'll do – A new 1 Commented Feb 26, 2019 at 10:45
Add a comment  | 

1 Answer 1

Reset to default -1

I don't know why this happened, but it seems that register_setting shouldn't be in the callback of 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');

I hope this helps

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far