我需要有关wordpress中自定义插件的帮助我想更改wordpress子菜单设置中的颜色,所以我用这个
add_action('admin_menu', 'register_my_custom_submenu_page');
function register_my_custom_submenu_page() {
add_submenu_page( 'options-general.php', 'PJ-Plugin Settings', 'PJ-Plugin Settings', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' );
add_action( 'admin_init', 'register_mysettings' );
}
function pj_menu()
{
add_theme_page( 'Theme Option', 'Theme Options', 'manage_options', 'pu_theme_options.php', 'pu_theme_page');
}
add_action('admin_menu', 'pj_menu');
function register_mysettings() {
//register settings
register_setting( 'pj_options', 'colors' );
}
function my_custom_submenu_page_callback() {
if(isset($_POST['colors'])){
update_option('colors', $_POST['colors']);
}
echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>';
echo '<h2>PJ-Plugin Settings</h2>';
?>
<form method="post" nctype="multipart/form-data">
<?php
settings_fields('pj_options');
do_settings_sections('pj_options');
echo '<h3>Choose Color</h3>';
?>
<select name="colors">
<option value="red"> red </option>
<option value="blue"> blue </option>
<option value="green"> green </option>
<input type="submit" class="button" value="<?php _e('Save Changes') ?>" name="one" />
</select>
</form>
<?php
echo '</div>';
}
function samp_func_1( $atts ){
global $options;
echo 'color : '.$color = get_option('colors');
$html = "<div class='forplug' style= 'color:".$color."'>Hello World</div>";
return $html;
}
add_shortcode( 'hello_world', 'samp_func_1' );
是的它正在运行,但是如果我将更新短代码所在的页面。我的问题是,如果我选择颜色并保存设置,它将自动更改颜色,而不是在页面中更新。也许问题是这段代码:
function samp_func_1( $atts ){
global $options;
echo 'color : '.$color = get_option('colors');
$html = "<div class='forplug' style= 'color:".$color."'>Hello World</div>";
return $html;
}