I am creating a small WordPress plugin. I created setting page and there are two user inputs in setting page.

I created two option types. Those are rmpm_post_newcount and rmpm_post_newname. After active this plugin there is no rmpm_post_newcount and rmpm_post_newname in option.php page.

What is the reason for it?

// Specify Hooks/Filters
register_activation_hook(__FILE__, 'rmpm_add_defaults_options');
add_action('admin_init', 'rmpm_init_fn' );
add_action('admin_menu', 'rmpm_add_page');

// Define default option settings
function rmpm_add_defaults_options() {
    $tmp = get_option('plugin_options');

    $arr = array("rmpm_post_newcount" => "10", "rmpm_post_newname" => "My Blog Posts");
    update_option('plugin_options', $arr);


// Register our settings. Add the settings section, and settings fields
function rmpm_init_fn(){
    register_setting('plugin_options', 'plugin_options', 'plugin_options_validate' );
    add_settings_section('main_section', 'Main Settings', 'rmpm_section_text_fn', __FILE__);
    add_settings_field('rmpm_plugin_count', 'Display Posts Count', 'rmpm_setting_count_fn', __FILE__, 'main_section');
    add_settings_field('rmpm_plugin_name', 'Display Name', 'rmpm_setting_name_fn', __FILE__, 'main_section');

// Add sub page to the Settings Menu
function rmpm_add_page() {
    add_options_page('Recent Posts BP Profile', 'Recent Posts BP Profile', 'administrator', __FILE__, 'rmpm_options_page_fn');

// ************************************************************************************************************

// Callback functions

// Section HTML, displayed before the first option
function  rmpm_section_text_fn() {
    echo '<p>Theese are some setting.</p>';

// TEXTBOX - Name: plugin_options[text_string]
function rmpm_setting_count_fn() {
    $options = get_option('plugin_options');
    echo "<input id='rmpm_plugin_count' name='plugin_options[rmpm_post_newcount]' size='40' type='text' value='{$options['rmpm_post_newcount']}' />";

// PASSWORD-TEXTBOX - Name: plugin_options[text_string2]
function rmpm_setting_name_fn() {
    $options = get_option('plugin_options');
    echo "<input id='rmpm_plugin_name' name='plugin_options[rmpm_post_newname]' size='40' type='text' value='{$options['rmpm_post_newname']}' />";

function rmpm_options_page_fn() {
    <div class="wrap">
        <div class="icon32" id="icon-options-general"><br></div>
        <h2>Setting Page</h2>
        Some optional text here explaining the overall purpose of the options and what they relate to etc.
        <form action="options.php" method="post">
        <?php settings_fields('plugin_options'); ?>
        <?php do_settings_sections(__FILE__); ?>
        <p class="submit">
            <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?>" />

in register_settings you need to pass the names of the options you use. right now it seems like you left that call the same as from wherever you copy & pasted it (not criticizing at all here). If you need two options (why?) then you need to call it twice, once for each option.

The option name is the second parameter to the function, the first can be whatever you want but it needs to be the same with the one which you will use in the settings page itself. Best practice is to use the slug of the settings page in which the settings will be changed, to ensure it is unique and make it easy to identify the context.

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.