1

I'm trying to make an options page for a plugin and i'm getting The requested URL /site/wp-admin/plugin-email.php was not found on this server. every time i press 'Save settings'.

Here is my code:

add_action( 'admin_menu', 'settings_menu_email' );

function settings_menu_email() {
    add_options_page( 
        'Set Email', 
        'Set Email', 
        'manage_options', 
        'set-email', 
        'display_set_email_settings'
    );

    add_action( 'admin_init', 'register_set_email_options' );
}

function register_set_email_options() {
    register_setting( 'set-email-option-group', 'set-email' );
}

function display_set_email_settings() {
?>
    <div class="wrap">
    <h1>Schimba email</h1>

    <?php settings_fields( 'set-email-option-group' ); ?>
    <?php do_settings_sections( 'set-email-option-group' ); ?>

    <form method="post" action="plugin-email.php">
    <table class="form-table">
        <tr valign="top">
        <th scope="row">Email</th>
        <td><input type="text" name="set-email" value="<?php echo esc_attr( get_option('set-email') ); ?>" /></td>
        </tr>
    </table>
    <?php  submit_button(); ?>
    </form>
    </div>

I tried making an options.php file, but i get the same thing.

  • where exactly is your file plugin-email.php located in your WordPress installation? – Michael Jun 11 '17 at 23:07
  • /wp-content/plugins/plugin-email, i tried to link the full path, still get error The requested URL /site/wp-contet/plugins/plugin-email/plugin-email.php was not found on this server. – Andrei Cojocaru Jun 11 '17 at 23:16
0

Looking at an old commit on a plugin I am writing, I am seeing a couple of things that jump out at me.

First is your options page declaration. I had mine as follows, using your labels:

function settings_menu_email() {
    add_menu_page(
        'Set Email',
        'Set Email',
        'manage_options',
        'email_admin_menu',
        'email_admin_menu_callback',
    );

    add_submenu_page(
        'email_admin_menu',
        __( 'Options', 'textdomain' ),
        __( 'Options', 'textdomain' ),
        'administrator',
        'email_admin_menu_options',
        'email_admin_menu_options_callback'
    );
}
add_action( 'admin_menu', 'settings_menu_email' );

Then define your settings groups outside of the callback function.

function email_initialize_plugin_options() {
    add_settings_section(
        'email_settings_section',
        'EMail Options',
        'email_options_callback',
        'email_admin_menu_options'
    );

    // Add Email Address Option
    add_settings_field(
        'email_settings_section',
        'EMail Address',
        'email_set_address_callback',
        'email_admin_menu_options',
        'email_settings_section',
        array(
            'Enter a description here...',
        )
    );

    // Register Email Address Option
    register_setting(
        'email_settings_section',
        'email_settings_section'
    );
}
add_action( 'admin_init', 'email_initialize_plugin_options' );

Then you do your callbacks.

In order to test this, just add empty callback functions.

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.