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(); ?>
<?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?

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

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

Use get_option for both items:

  • 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 Oct 30 '14 at 12:31

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.