我正在开发我的第一个WP插件,我正在尝试使用设置页面为插件创建选项。
// 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 } ?>
“设置”页面按预期构建。我可以在两个创建的字段中输入值,保存值,然后在设置页面上返回值。
启动TinyMCE弹出窗口时,我尝试使用以下代码引用设置值:
$mySettings = get_option(\'qd_button-settings-group\');
echo $mySettings[\'qd_button_color_list\'];
这不会返回字段“qd\\u button\\u color\\u list”的设置值。实际上,它会导致php文件停止加载。
知道我错过了什么吗?