0

I'm developing my first WP plugin, and I'm trying to use the Settings pages to create options for the plugin.

// add settings page
add_action('admin_menu', 'qd_button_admin_add_page');
function qd_button_admin_add_page() {
    add_options_page('QD Buttons', 'QD Buttons', 'manage_options', 'plugin', 'qd_button_options_page');

    //call register settings function
    add_action( 'admin_init', 'register_mysettings' );
}
function register_mysettings() {
    //register our settings
    register_setting( 'qd_button-settings-group', 'qd_button_color_list' );
    register_setting( 'qd_button-settings-group', 'qd_button_text_color_list' );
}

//Build out settings page
function qd_button_options_page(){ ?>
    <link rel="stylesheet" href="<?php echo plugin_dir_url( __FILE__ ); ?>/includes/css/qd_buttons.css" type="text/css">
    <div id="qdButtonSettings">
        <h1>QD Button Settings</h1>
        <form method="post" action="options.php"> 
            <?php settings_fields( 'qd_button-settings-group' ); ?>
            <?php do_settings_sections( 'qd_button-settings-group' ); ?>
            <label for="qd_button_color_list">Color List for Button Backgrounds</label><br />
            <input type="text" name="qd_button_color_list" id="qd_button_color_list" value="<?php echo esc_attr( get_option('qd_button_color_list') ); ?>" />
            <p id="instructionsText">Enter a comma separated list of the available background colors.<br />Example: Red, Blue, Green, Black</p>
            <label for="qd_button_text_color_list">Color List for Button Backgrounds</label><br />
            <input type="text" name="qd_button_text_color_list" id="qd_button_text_color_list" value="<?php echo esc_attr( get_option('qd_button_text_color_list') ); ?>" />
            <p id="instructionsText">Enter a comma separated list of the available background colors.<br />Example: Red, Blue, Green, Black</p>
            <?php submit_button(); ?>
        </form>
    </div>
<?php } ?>

The settings page builds out as-intended. I can enter values into both created fields, save the values, and they are returned on the settings page.

When I launch my TinyMCE popup, I attempt to reference the settings values with the following code:

$mySettings =  get_option('qd_button-settings-group');
echo $mySettings['qd_button_color_list'];

This does not return the Settings value for the field 'qd_button_color_list'. In fact, it causes the php files to stop loading.

Any idea what I'm missing?

2
  • Remove the echo and replace it with var_dump( $mySettings ); That should give you a clue.
    – shanebp
    Commented Oct 29, 2014 at 20:59
  • Same result with var_dump($mySettings); as the echo. Nothing is displayed.
    – Joe
    Commented Oct 29, 2014 at 21:02

1 Answer 1

0

qd_button-settings-group is a settings group, not an option.

Use get_option for both items:

get_option('qd_button_color_list');
get_option('qd_button_text_color_list');
1
  • I placed this in my TinyMCE popup, and got the same results: echo get_option('qd_button_color_list'); echo get_option('qd_button_text_color_list');
    – Joe
    Commented Oct 30, 2014 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.