Advertisement
amereservant

Customize and Remove WordPress Admin Panel Items/Widgets

Aug 5th, 2011
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.79 KB | None | 0 0
  1. <?php
  2. /*****************************************
  3.  * WordPress Admin Customization Snippets
  4.  *
  5.  * These are several snippets that can be used to customise your WordPress Admin Dashboard
  6.  * by removing specific elements/items from it and even adding custom ones.
  7.  *
  8.  * These can be added to a plugin or theme's functions.php file and customised as needed.
  9.  * I HIGHLY recommend renaming the functions with more unique names to lessen the potential
  10.  * for name collisions with other plugins/themes.
  11.  */
  12.  
  13. /**
  14.  * Remove WP Admin Menu Panels
  15.  *
  16.  * This hides complete groups from the admin menu, such as 'Links', 'Media', 'Pages', etc.
  17.  * The sections are still accessible by typing in the direct URL, but they are removed
  18.  * from the menu itself.
  19.  *
  20.  * @link    http://sixrevisions.com/wordpress/how-to-customize-the-wordpress-admin-area/
  21.  * @param   void
  22.  * @return  void
  23.  */
  24. function remove_menu_items()
  25. {
  26.     global $menu;
  27.     // The menu items to hide
  28.     $restricted = array( __('Links'),    __('Comments'),    __('Media'),
  29.                          __('Plugins'),  __('Tools'),       __('Users'),
  30.                          __('Settings'), __('Appearance'),  __('Pages'), __('Posts')
  31.     );
  32.     // Move array pointer to the end of the array and loop backwards
  33.     end($menu);
  34.     while( prev($menu) )
  35.     {
  36.         $value = explode(' ',$menu[key($menu)][0]);
  37.         if( in_array($value[0] != NULL?$value[0]:"" , $restricted) )
  38.             unset( $menu[key($menu)] );
  39.     }
  40. }
  41. add_action('admin_menu', 'remove_menu_items');
  42.  
  43. /**
  44.  * Remove WP Admin Dashboard Widgets
  45.  *
  46.  * This removes the various widgets from the admin dashboard so un-needed dashboard items
  47.  * can be hidden to decrease clutter.
  48.  *
  49.  * @link    http://sixrevisions.com/wordpress/how-to-customize-the-wordpress-admin-area/
  50.  * @param   void
  51.  * @return  void
  52.  */
  53. function remove_dashboard_widgets()
  54. {
  55.     global$wp_meta_boxes;
  56.     // All of these will strip most dashboards of ALL widgets.  Comment out the ones needed...
  57.     unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
  58.     unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
  59.     unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
  60.     unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
  61.     unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
  62.     unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
  63.     unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
  64.     unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
  65. }
  66. add_action('wp_dashboard_setup', 'remove_dashboard_widgets');
  67.  
  68. /**
  69.  * Custom WP Dashboard Widget Contents
  70.  *
  71.  * This adds the contents for a custom dashboard widget and called by
  72.  * add_your_dashboard_widget().
  73.  *
  74.  * @link    http://wp-snippets.com/82/add-a-dashboard-widget/
  75.  * @param   void
  76.  * @return  void
  77.  */
  78. function your_dashboard_widget() { ?>
  79.     <h3>Hello WordPress user!</h3>
  80.     <p>Fill this with HTML or PHP.<br>
  81.     Just imagine all the stuff you can put here!</p>
  82.     <p>The possibilities are endless and that's no joke!</p>
  83. <?php
  84. }
  85.  
  86. /**
  87.  * Add Custom WP Dashboard Widget
  88.  *
  89.  * This will add a custom dashboard widget to WordPress, allowing for customized dashboard
  90.  * contents.
  91.  *
  92.  * @uses    your_dashboard_widget() Calls function to add contents for custom widget.
  93.  * @link    http://wp-snippets.com/82/add-a-dashboard-widget/
  94.  * @param   void
  95.  * @return  void
  96.  */
  97. function add_your_dashboard_widget() {
  98.     wp_add_dashboard_widget( 'your_dashboard_widget', __( 'Widget Title!' ), 'your_dashboard_widget' );
  99. }
  100. add_action('wp_dashboard_setup', 'add_your_dashboard_widget' );
  101.  
  102. /**
  103.  * Add Custom Help Page
  104.  *
  105.  * Adds custom help contents to the 'Help' tab in WordPress's admin area.
  106.  * This will be added to whichever pages it is hooked to.
  107.  *
  108.  * By using this function to hook the contextual_help hook, we limit the custom
  109.  * help contents from being added to EVERY page.  
  110.  * If you want it to show on every page's help dropdown, just add the filter hook in
  111.  * this function directly below the custom_page_help() function.
  112.  *
  113.  * @link    http://wp-snippets.com/98/edit-the-help-dropdown/
  114.  * @uses    custom_page_help() Calls function to render the custom help contents.
  115.  * @param   void
  116.  * @return  void
  117.  */
  118. function add_custom_help_page() {
  119.    //the contextual help filter
  120.    add_filter('contextual_help','custom_page_help');
  121. }
  122.  
  123. /**
  124.  * Custom Help Page Contents
  125.  *
  126.  * This renders the custom help contents.  If the parameter $help is not echoed,
  127.  * then the existing help contents will be excluded in the help dropdown.
  128.  *
  129.  * @link    http://wp-snippets.com/98/edit-the-help-dropdown/
  130.  * @param   string  $help   The existing help contents
  131.  * @return  void
  132.  */
  133. function custom_page_help($help) {
  134.    // Keep the existing help copy - comment the following line to exclude existing help contents.
  135.    echo $help;
  136.    
  137.    // Add the new help contents
  138.    echo "<h5>Custom Features</h5>";
  139.    echo "<p>Content placed above the more divider will appear in column 1. Content placed ".
  140.         "below the divider will appear in column 2.</p>";
  141. }
  142. // Specify a specific page to hook to like so: 'load-<specific page>.php'
  143. add_action('load-my-sites.php','add_custom_help_page');
  144. add_action('load-index.php','add_custom_help_page');
  145.  
  146. /**
  147.  * Replace the Admin Footer Text
  148.  *
  149.  * Overrides the admin footer text with your own custom text.
  150.  *
  151.  * @link    http://wp-snippets.com/59/change-footer-text-in-wp-admin/
  152.  * @param   void
  153.  * @return  void
  154.  */
  155. function remove_footer_admin () {
  156.   echo 'My footer text. Thank you <a href="http://wordpress.org">WordPress</a> for giving me this filter.';
  157. }
  158. add_filter('admin_footer_text', 'remove_footer_admin');
  159.  
  160. /**
  161.  * Hide Update Notifications in WordPress
  162.  *
  163.  * @link    http://wp-snippets.com/79/disable-wordpress-update/
  164.  */
  165. add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
  166.  
  167. /**
  168.  * Change the WP Version in Footer
  169.  *
  170.  * You can hide the version all together, replace it with something else, or spoof the
  171.  * version to show as something else.
  172.  *
  173.  * @link    http://wp-snippets.com/701/change-version-in-wp-admin-footer/
  174.  * @param   void
  175.  * @return  void
  176.  */
  177. function change_footer_version() {
  178.     return 'Version 120.0.0';
  179. }
  180. add_filter( 'update_footer', 'change_footer_version', 9999 );
  181.  
  182. /**
  183.  * Hide WP Admin Screen Options tab
  184.  *
  185.  * This will hide the 'Screen Options' tab at the top-right in the WordPress admin area.
  186.  *
  187.  * @param   void
  188.  * @return  bool    false   Keeps WordPress from rendering the Screen Options tab
  189.  */
  190. function hide_screen_options() {
  191.     return false;
  192. }
  193. add_filter('screen_options_show_screen', 'hide_screen_options');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement