I am trying to develop a WordPress plugin with a menu page. I am currently just trying to save to options in the menu. But when clicking the submit button, i get an error saying, that the options page could not be found.

Here’s my complete code:

<?php

/**
 * Plugin Name: 
 * Plugin URI: 
 * Description: 
 * Version: 1.0.0
 * Author: 
 * License: GPL2
 */

    add_action('admin_menu', 'whatspress_menu');

    function whatspress_menu() {
        add_menu_page('WhatsPress Settings', 'WhatsPress', 'administrator', 'whatspress-settings', 'whatspress_settings_page', 'dashicons-admin-generic');
        add_action( 'admin_init', 'whatspress_settings' );
    }

    function whatspress_settings_page() {
?>
        <div class="wrap">
        <h2>Register Phone</h2>

        <form method="post" action="options.php">
            <?php settings_fields( 'whatspress-settings-group' ); ?>
            <?php do_settings_sections( 'whatspress-settings-group' ); ?>
            <table class="form-table">
                <tr valign="top">
                <th scope="row">Phone Number</th>
                <td><input type="text" name="phonenumber" value="<?php echo esc_attr( get_option('phonenumber') ); ?>" /></td>
                </tr>

                <tr valign="top">
                <th scope="row">Nickname</th>
                <td><input type="text" name="nickname" value="<?php echo esc_attr( get_option('nickname') ); ?>" /></td>
                </tr>
            </table>

            <?php submit_button(); ?>

        </form>
        </div>
<?php     
    }

    function whatspress_settings() {
        register_setting ('whatspress_settings_group', 'phonenumber');
        register_setting ('whatspress_settings_group', 'nickname');
    }
?>

It obvioulsy redirects to /options.php (snce it’s declared in the action parameter of the form element) which is not in my plugin folder. So I understand the error, but I looked up several tutorials and they seem to do it the same way.

Read more here: WordPress custom plugin doesn’t find options.php


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: