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?