codex - How to show WordPress admin menus in a custom dashboard widget? -
i want show wordpress administration menus in custom dashboard widgets. how it?
or paste tested solution in theme functions.php , modify. wherever need may call admin setting get_option()
corrected input b__ , tested again
function register_mysettings() { register_setting( 'michal-option-group', 'new_option_name' ); register_setting( 'michal-option-group', 'some_other_option' ); } add_action( 'admin_init', 'register_mysettings' ); function add_michal_dashboard_widget(){ wp_add_dashboard_widget( 'michal_dashboard_widget', // slug. 'michal dashboard widget', // title 'michal_dashboard_widget_function' // widget code ); } function michal_dashboard_widget_function(){ if (isset($_post['new_option_name'])) update_option( 'new_option_name', sanitize_text_field( $_post['new_option_name'])); if (isset($_post['some_other_option'])) update_option( 'some_other_option', sanitize_text_field( $_post['some_other_option'])); ?> <form method="post" action="<?php $_server['php_self'] ?>"> <?php settings_fields( 'michal-option-group' ); ?> <?php do_settings_sections( 'michal-option-group' ); ?> <table class="form-table"> <tr valign="top"> <th scope="row">new option name</th> <td><input type="text" name="new_option_name" value="<?php echo get_option('new_option_name'); ?>" /></td> </tr> <tr valign="top"> <th scope="row">some other option</th> <td><input type="text" name="some_other_option" value="<?php echo get_option('some_other_option'); ?>" /></td> </tr> </table> <?php submit_button(); ?> </form> <?php } add_action( 'wp_dashboard_setup', 'add_michal_dashboard_widget' );
Comments
Post a Comment