Admin Menu Editor - Version 1.0.1

Version Description

  • Added "Super Admin" to the "Required capability" dropdown.
  • Prevent users from accidentally making the menu editor inaccessible.
  • WordPress 3.0.1 compatibility made official.
Download this release

Release Info

Developer whiteshadow
Plugin Icon 128x128 Admin Menu Editor
Version 1.0.1
Comparing to
See all releases

Code changes from version 1.0 to 1.0.1

Files changed (3) hide show
  1. includes/menu-editor-core.php +72 -15
  2. menu-editor.php +1 -1
  3. readme.txt +10 -5
includes/menu-editor-core.php CHANGED
@@ -130,18 +130,18 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
130
  * @return void
131
  */
132
  function enqueue_scripts(){
133
- wp_enqueue_script('jquery');
134
- wp_enqueue_script('jquery-ui-sortable');
135
- wp_enqueue_script('jquery-ui-dialog');
136
- wp_enqueue_script('jquery-form');
137
-
138
  //jQuery JSON plugin
139
  wp_enqueue_script('jquery-json', $this->plugin_dir_url.'/js/jquery.json-1.3.js', array('jquery'), '1.3');
140
  //jQuery sort plugin
141
  wp_enqueue_script('jquery-sort', $this->plugin_dir_url.'/js/jquery.sort.js', array('jquery'));
142
 
143
  //Editor's scipts
144
- wp_enqueue_script('menu-editor', $this->plugin_dir_url.'/js/menu-editor.js', array('jquery'), '1.0');
 
 
 
 
 
145
  }
146
 
147
  /**
@@ -686,9 +686,6 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
686
  continue;
687
  };
688
 
689
- //Skip hidden entries
690
- if (!empty($topmenu['hidden'])) continue;
691
-
692
  //Skip leading menu separators. Fixes a superfluous separator showing up
693
  //in WP 3.0 (multisite mode) when there's a custom menu and the current user
694
  //can't access its first item ("Super Admin").
@@ -696,9 +693,14 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
696
 
697
  $first_nonseparator_found = true;
698
 
699
- //Build the WP item structure, using defaults where necessary
700
  $topmenu = $this->apply_defaults($topmenu);
701
  $topmenu = $this->apply_menu_filters($topmenu, 'menu');
 
 
 
 
 
702
  $menu[] = array(
703
  $topmenu['menu_title'],
704
  $topmenu['access_level'],
@@ -720,10 +722,6 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
720
  //Skip missing items, unless they're user-created
721
  $custom = $this->get_menu_field($item, 'custom', false);
722
  if ( !empty($item['missing']) && !$custom ) continue;
723
- //Skip hidden items
724
- if (!empty($item['hidden'])) {
725
- continue;
726
- }
727
 
728
  //Special case : plugin pages that have been moved to a different menu.
729
  //If the file field hasn't already been modified, we'll need to adjust it
@@ -741,6 +739,12 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
741
 
742
  $item = $this->apply_defaults($item);
743
  $item = $this->apply_menu_filters($item, 'submenu', $topmenu['file']);
 
 
 
 
 
 
744
  $submenu[$topmenu['file']][] = array(
745
  $item['menu_title'],
746
  $item['access_level'],
@@ -758,6 +762,39 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
758
  return array($menu, $submenu, $title_lookup);
759
  }
760
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
761
  /**
762
  * Upgrade a menu tree to the currently used structure
763
  * Does nothing if the menu is already up to date.
@@ -870,6 +907,10 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
870
  natcasesort($all_capabilities);
871
 
872
  $all_roles = $this->get_all_roles();
 
 
 
 
873
  asort($all_roles);
874
  ?>
875
  <div id='ws_menu_editor'>
@@ -1058,7 +1099,23 @@ window.wsMenuEditorPro = false; //Will be overwritten if extras are loaded
1058
 
1059
  return $roles;
1060
  }
1061
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1062
  /**
1063
  * Output the JavaScript that adds the "Feedback" widget to screen meta.
1064
  *
130
  * @return void
131
  */
132
  function enqueue_scripts(){
 
 
 
 
 
133
  //jQuery JSON plugin
134
  wp_enqueue_script('jquery-json', $this->plugin_dir_url.'/js/jquery.json-1.3.js', array('jquery'), '1.3');
135
  //jQuery sort plugin
136
  wp_enqueue_script('jquery-sort', $this->plugin_dir_url.'/js/jquery.sort.js', array('jquery'));
137
 
138
  //Editor's scipts
139
+ wp_enqueue_script(
140
+ 'menu-editor',
141
+ $this->plugin_dir_url.'/js/menu-editor.js',
142
+ array('jquery', 'jquery-ui-sortable', 'jquery-ui-dialog', 'jquery-form'),
143
+ '1.0'
144
+ );
145
  }
146
 
147
  /**
686
  continue;
687
  };
688
 
 
 
 
689
  //Skip leading menu separators. Fixes a superfluous separator showing up
690
  //in WP 3.0 (multisite mode) when there's a custom menu and the current user
691
  //can't access its first item ("Super Admin").
693
 
694
  $first_nonseparator_found = true;
695
 
696
+ //Apply defaults & filters
697
  $topmenu = $this->apply_defaults($topmenu);
698
  $topmenu = $this->apply_menu_filters($topmenu, 'menu');
699
+
700
+ //Skip hidden entries
701
+ if (!empty($topmenu['hidden'])) continue;
702
+
703
+ //Build the menu structure that WP expects
704
  $menu[] = array(
705
  $topmenu['menu_title'],
706
  $topmenu['access_level'],
722
  //Skip missing items, unless they're user-created
723
  $custom = $this->get_menu_field($item, 'custom', false);
724
  if ( !empty($item['missing']) && !$custom ) continue;
 
 
 
 
725
 
726
  //Special case : plugin pages that have been moved to a different menu.
727
  //If the file field hasn't already been modified, we'll need to adjust it
739
 
740
  $item = $this->apply_defaults($item);
741
  $item = $this->apply_menu_filters($item, 'submenu', $topmenu['file']);
742
+
743
+ //Skip hidden items
744
+ if (!empty($item['hidden'])) {
745
+ continue;
746
+ }
747
+
748
  $submenu[$topmenu['file']][] = array(
749
  $item['menu_title'],
750
  $item['access_level'],
762
  return array($menu, $submenu, $title_lookup);
763
  }
764
 
765
+ /**
766
+ * Prevent the "Menu Editor" menu item from becoming inaccessible.
767
+ *
768
+ * @param array $item
769
+ * @return array
770
+ */
771
+ function hook_custom_admin_submenu($item){
772
+ //To stop the user from accidentally shooting themselves in the foot, we make
773
+ //any dangerous changes made to the "Menu Editor" menu have no effect.
774
+ if ( !empty($item['file']) && ($item['file'] == 'menu_editor') ){
775
+ //Reset the important fields back to the default values.
776
+ $item['access_level'] = null;
777
+ $item['page_title'] = null;
778
+ $item['window_title'] = null;
779
+ $item = $this->apply_defaults($item);
780
+ $item['hidden'] = false; //Can't hide me!
781
+ }
782
+ return $item;
783
+ }
784
+
785
+ /**
786
+ * Prevent the menu that contains the "Menu Editor" entry from being hidden.
787
+ *
788
+ * @param array $menu
789
+ * @return array
790
+ */
791
+ function hook_custom_admin_menu($menu){
792
+ if ( !empty($menu['items']) && array_key_exists('menu_editor', $menu['items']) ){
793
+ $menu['hidden'] = false;
794
+ }
795
+ return $menu;
796
+ }
797
+
798
  /**
799
  * Upgrade a menu tree to the currently used structure
800
  * Does nothing if the menu is already up to date.
907
  natcasesort($all_capabilities);
908
 
909
  $all_roles = $this->get_all_roles();
910
+ //Multi-site installs also get the virtual "Super Admin" role
911
+ if ( is_multisite() ){
912
+ $all_roles['super_admin'] = 'Super Admin';
913
+ }
914
  asort($all_roles);
915
  ?>
916
  <div id='ws_menu_editor'>
1099
 
1100
  return $roles;
1101
  }
1102
+
1103
+ /**
1104
+ * Create a virtual 'super_admin' capability that only super admins have.
1105
+ * This function accomplishes that by by filtering 'user_has_cap' calls.
1106
+ *
1107
+ * @param array $allcaps All capabilities belonging to the current user, cap => true/false.
1108
+ * @param array $required_caps The required capabilities.
1109
+ * @param array $args The capability passed to current_user_can, the current user's ID, and other args.
1110
+ * @return array Filtered version of $allcaps
1111
+ */
1112
+ function hook_user_has_cap($allcaps, $required_caps, $args){
1113
+ if ( in_array('super_admin', $required_caps) ){
1114
+ $allcaps['super_admin'] = is_multisite() && is_super_admin($args[1]);
1115
+ }
1116
+ return $allcaps;
1117
+ }
1118
+
1119
  /**
1120
  * Output the JavaScript that adds the "Feedback" widget to screen meta.
1121
  *
menu-editor.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Admin Menu Editor
4
  Plugin URI: http://w-shadow.com/blog/2008/12/20/admin-menu-editor-for-wordpress/
5
  Description: Lets you directly edit the WordPress admin menu. You can re-order, hide or rename existing menus, add custom menus and more.
6
- Version: 1.0
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/blog/
9
  */
3
  Plugin Name: Admin Menu Editor
4
  Plugin URI: http://w-shadow.com/blog/2008/12/20/admin-menu-editor-for-wordpress/
5
  Description: Lets you directly edit the WordPress admin menu. You can re-order, hide or rename existing menus, add custom menus and more.
6
+ Version: 1.0.1
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/blog/
9
  */
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: whiteshadow
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A6P9S6CE3SRSW
4
  Tags: admin, dashboard, menu, security, wpmu
5
  Requires at least: 3.0
6
- Tested up to: 3.0
7
- Stable tag: 1.0
8
 
9
  Lets you directly edit the WordPress admin menu. You can re-order, hide or rename existing menus, add custom menus and more.
10
 
@@ -23,12 +23,12 @@ The [Pro version](http://wpplugins.com/plugin/146/admin-menu-editor-pro) of the
23
 
24
  [Suggest new features and improvements here](http://feedback.w-shadow.com/forums/58572-admin-menu-editor)
25
 
26
- **Known Issues**
27
 
28
  * If you delete any of the default menus they will reappear after saving. This is by design. To get rid of a menu for good, either hide it or set it's access rights to a higher level.
29
  * If one of your menu items is only visible in the editor but not the Dashboard menu itself, make sure its "Custom" checkbox is ticked. The plugin will usually do this for you when you create a new menu.
30
  * You can't lower a menu's required access rights, but you can change them to be more restrictive.
31
-
32
 
33
  == Installation ==
34
 
@@ -61,6 +61,11 @@ Plugins installed in the `mu-plugins` directory are treated as "always on", so y
61
 
62
  == Changelog ==
63
 
 
 
 
 
 
64
  = 1.0 =
65
  * Added a "Feedback" link.
66
  * Added a dropdown list of all roles and capabilities to the menu editor.
@@ -73,7 +78,7 @@ Plugins installed in the `mu-plugins` directory are treated as "always on", so y
73
  * Fixed moved pages not having a window title.
74
  * Hide advanced menu fields by default (can be turned off in Screen Options).
75
  * Changed a lot of UI text to be a bit more intuitive.
76
- * In emergencies, administrators can now reset the custom menu by going to http:://example.com/wp-admin/?reset\_admin\_menu=1
77
  * Fixed the "Donate" link in readme.txt
78
  * Unbundle the JSON.php JSON parser/encoder and use the built-in class-json.php instead.
79
  * Use the native JSON decoding routine if it's available.
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A6P9S6CE3SRSW
4
  Tags: admin, dashboard, menu, security, wpmu
5
  Requires at least: 3.0
6
+ Tested up to: 3.1-alpha
7
+ Stable tag: 1.0.1
8
 
9
  Lets you directly edit the WordPress admin menu. You can re-order, hide or rename existing menus, add custom menus and more.
10
 
23
 
24
  [Suggest new features and improvements here](http://feedback.w-shadow.com/forums/58572-admin-menu-editor)
25
 
26
+ **Notes**
27
 
28
  * If you delete any of the default menus they will reappear after saving. This is by design. To get rid of a menu for good, either hide it or set it's access rights to a higher level.
29
  * If one of your menu items is only visible in the editor but not the Dashboard menu itself, make sure its "Custom" checkbox is ticked. The plugin will usually do this for you when you create a new menu.
30
  * You can't lower a menu's required access rights, but you can change them to be more restrictive.
31
+ * In case of emergency, you can reset the menu configuration back to the default by going to http://example.com/wp-admin/?reset\_admin\_menu=1
32
 
33
  == Installation ==
34
 
61
 
62
  == Changelog ==
63
 
64
+ = 1.0.1 =
65
+ * Added "Super Admin" to the "Required capability" dropdown.
66
+ * Prevent users from accidentally making the menu editor inaccessible.
67
+ * WordPress 3.0.1 compatibility made official.
68
+
69
  = 1.0 =
70
  * Added a "Feedback" link.
71
  * Added a dropdown list of all roles and capabilities to the menu editor.
78
  * Fixed moved pages not having a window title.
79
  * Hide advanced menu fields by default (can be turned off in Screen Options).
80
  * Changed a lot of UI text to be a bit more intuitive.
81
+ * In emergencies, administrators can now reset the custom menu by going to http://example.com/wp-admin/?reset\_admin\_menu=1
82
  * Fixed the "Donate" link in readme.txt
83
  * Unbundle the JSON.php JSON parser/encoder and use the built-in class-json.php instead.
84
  * Use the native JSON decoding routine if it's available.