wordpress - Custom Plugin shortcode -
i need custom plugin in wordpress want change color in sub menu settings in wordpress use this
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' );
yes working if update page in shortcode is. problem if choose color , save settings automatically change color , not update in page. maybe problem code:
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;
}
Comments
Post a Comment