7 */ |
7 */ |
8 |
8 |
9 /** |
9 /** |
10 * Constructs the admin menu. |
10 * Constructs the admin menu. |
11 * |
11 * |
12 * The elements in the array are : |
12 * The elements in the array are: |
13 * 0: Menu item name |
13 * 0: Menu item name. |
14 * 1: Minimum level or capability required. |
14 * 1: Minimum level or capability required. |
15 * 2: The URL of the item's file |
15 * 2: The URL of the item's file. |
16 * 3: Class |
16 * 3: Page title. |
17 * 4: ID |
17 * 4: Classes. |
18 * 5: Icon for top level menu |
18 * 5: ID. |
|
19 * 6: Icon for top level menu. |
19 * |
20 * |
20 * @global array $menu |
21 * @global array $menu |
21 */ |
22 */ |
22 |
23 |
23 $menu[2] = array( __( 'Dashboard' ), 'read', 'index.php', '', 'menu-top menu-top-first menu-icon-dashboard', 'menu-dashboard', 'dashicons-dashboard' ); |
24 $menu[2] = array( __( 'Dashboard' ), 'read', 'index.php', '', 'menu-top menu-top-first menu-icon-dashboard', 'menu-dashboard', 'dashicons-dashboard' ); |
40 } elseif ( current_user_can( 'update_themes' ) ) { |
41 } elseif ( current_user_can( 'update_themes' ) ) { |
41 $cap = 'update_themes'; |
42 $cap = 'update_themes'; |
42 } else { |
43 } else { |
43 $cap = 'update_languages'; |
44 $cap = 'update_languages'; |
44 } |
45 } |
45 /* translators: %s: number of pending updates */ |
46 $submenu['index.php'][10] = array( |
46 $submenu['index.php'][10] = array( sprintf( __( 'Updates %s' ), "<span class='update-plugins count-{$update_data['counts']['total']}'><span class='update-count'>" . number_format_i18n( $update_data['counts']['total'] ) . '</span></span>' ), $cap, 'update-core.php' ); |
47 sprintf( |
|
48 /* translators: %s: Number of pending updates. */ |
|
49 __( 'Updates %s' ), |
|
50 sprintf( |
|
51 '<span class="update-plugins count-%s"><span class="update-count">%s</span></span>', |
|
52 $update_data['counts']['total'], |
|
53 number_format_i18n( $update_data['counts']['total'] ) |
|
54 ) |
|
55 ), |
|
56 $cap, |
|
57 'update-core.php', |
|
58 ); |
47 unset( $cap ); |
59 unset( $cap ); |
48 } |
60 } |
49 |
61 |
50 $menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' ); |
62 $menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' ); |
51 |
63 |
52 // $menu[5] = Posts |
64 // $menu[5] = Posts. |
53 |
65 |
54 $menu[10] = array( __( 'Media' ), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'dashicons-admin-media' ); |
66 $menu[10] = array( __( 'Media' ), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'dashicons-admin-media' ); |
55 $submenu['upload.php'][5] = array( __( 'Library' ), 'upload_files', 'upload.php' ); |
67 $submenu['upload.php'][5] = array( __( 'Library' ), 'upload_files', 'upload.php' ); |
56 /* translators: add new file */ |
68 /* translators: Add new file. */ |
57 $submenu['upload.php'][10] = array( _x( 'Add New', 'file' ), 'upload_files', 'media-new.php' ); |
69 $submenu['upload.php'][10] = array( _x( 'Add New', 'file' ), 'upload_files', 'media-new.php' ); |
58 $i = 15; |
70 $i = 15; |
59 foreach ( get_taxonomies_for_attachments( 'objects' ) as $tax ) { |
71 foreach ( get_taxonomies_for_attachments( 'objects' ) as $tax ) { |
60 if ( ! $tax->show_ui || ! $tax->show_in_menu ) { |
72 if ( ! $tax->show_ui || ! $tax->show_in_menu ) { |
61 continue; |
73 continue; |
65 } |
77 } |
66 unset( $tax, $i ); |
78 unset( $tax, $i ); |
67 |
79 |
68 $menu[15] = array( __( 'Links' ), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'dashicons-admin-links' ); |
80 $menu[15] = array( __( 'Links' ), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'dashicons-admin-links' ); |
69 $submenu['link-manager.php'][5] = array( _x( 'All Links', 'admin menu' ), 'manage_links', 'link-manager.php' ); |
81 $submenu['link-manager.php'][5] = array( _x( 'All Links', 'admin menu' ), 'manage_links', 'link-manager.php' ); |
70 /* translators: add new links */ |
82 /* translators: Add new links. */ |
71 $submenu['link-manager.php'][10] = array( _x( 'Add New', 'link' ), 'manage_links', 'link-add.php' ); |
83 $submenu['link-manager.php'][10] = array( _x( 'Add New', 'link' ), 'manage_links', 'link-add.php' ); |
72 $submenu['link-manager.php'][15] = array( __( 'Link Categories' ), 'manage_categories', 'edit-tags.php?taxonomy=link_category' ); |
84 $submenu['link-manager.php'][15] = array( __( 'Link Categories' ), 'manage_categories', 'edit-tags.php?taxonomy=link_category' ); |
73 |
85 |
74 // $menu[20] = Pages |
86 // $menu[20] = Pages. |
75 |
87 |
76 // Avoid the comment count query for users who cannot edit_posts. |
88 // Avoid the comment count query for users who cannot edit_posts. |
77 if ( current_user_can( 'edit_posts' ) ) { |
89 if ( current_user_can( 'edit_posts' ) ) { |
78 $awaiting_mod = wp_count_comments(); |
90 $awaiting_mod = wp_count_comments(); |
79 $awaiting_mod = $awaiting_mod->moderated; |
91 $awaiting_mod = $awaiting_mod->moderated; |
80 $awaiting_mod_i18n = number_format_i18n( $awaiting_mod ); |
92 $awaiting_mod_i18n = number_format_i18n( $awaiting_mod ); |
81 /* translators: %s: number of comments in moderation */ |
93 /* translators: %s: Number of comments. */ |
82 $awaiting_mod_text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ), $awaiting_mod_i18n ); |
94 $awaiting_mod_text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ), $awaiting_mod_i18n ); |
83 |
95 |
84 $menu[25] = array( |
96 $menu[25] = array( |
85 /* translators: %s: number of comments in moderation */ |
97 /* translators: %s: Number of comments. */ |
86 sprintf( __( 'Comments %s' ), '<span class="awaiting-mod count-' . absint( $awaiting_mod ) . '"><span class="pending-count" aria-hidden="true">' . $awaiting_mod_i18n . '</span><span class="comments-in-moderation-text screen-reader-text">' . $awaiting_mod_text . '</span></span>' ), |
98 sprintf( __( 'Comments %s' ), '<span class="awaiting-mod count-' . absint( $awaiting_mod ) . '"><span class="pending-count" aria-hidden="true">' . $awaiting_mod_i18n . '</span><span class="comments-in-moderation-text screen-reader-text">' . $awaiting_mod_text . '</span></span>' ), |
87 'edit_posts', |
99 'edit_posts', |
88 'edit-comments.php', |
100 'edit-comments.php', |
89 '', |
101 '', |
90 'menu-top menu-icon-comments', |
102 'menu-top menu-icon-comments', |
107 ); |
119 ); |
108 $builtin = array( 'post', 'page' ); |
120 $builtin = array( 'post', 'page' ); |
109 foreach ( array_merge( $builtin, $types ) as $ptype ) { |
121 foreach ( array_merge( $builtin, $types ) as $ptype ) { |
110 $ptype_obj = get_post_type_object( $ptype ); |
122 $ptype_obj = get_post_type_object( $ptype ); |
111 // Check if it should be a submenu. |
123 // Check if it should be a submenu. |
112 if ( $ptype_obj->show_in_menu !== true ) { |
124 if ( true !== $ptype_obj->show_in_menu ) { |
113 continue; |
125 continue; |
114 } |
126 } |
115 $ptype_menu_position = is_int( $ptype_obj->menu_position ) ? $ptype_obj->menu_position : ++$_wp_last_object_menu; // If we're to use $_wp_last_object_menu, increment it first. |
127 $ptype_menu_position = is_int( $ptype_obj->menu_position ) ? $ptype_obj->menu_position : ++$_wp_last_object_menu; // If we're to use $_wp_last_object_menu, increment it first. |
116 $ptype_for_id = sanitize_html_class( $ptype ); |
128 $ptype_for_id = sanitize_html_class( $ptype ); |
117 |
129 |
121 if ( 0 === strpos( $ptype_obj->menu_icon, 'data:image/svg+xml;base64,' ) || 0 === strpos( $ptype_obj->menu_icon, 'dashicons-' ) ) { |
133 if ( 0 === strpos( $ptype_obj->menu_icon, 'data:image/svg+xml;base64,' ) || 0 === strpos( $ptype_obj->menu_icon, 'dashicons-' ) ) { |
122 $menu_icon = $ptype_obj->menu_icon; |
134 $menu_icon = $ptype_obj->menu_icon; |
123 } else { |
135 } else { |
124 $menu_icon = esc_url( $ptype_obj->menu_icon ); |
136 $menu_icon = esc_url( $ptype_obj->menu_icon ); |
125 } |
137 } |
126 } elseif ( in_array( $ptype, $builtin ) ) { |
138 } elseif ( in_array( $ptype, $builtin, true ) ) { |
127 $menu_icon = 'dashicons-admin-' . $ptype; |
139 $menu_icon = 'dashicons-admin-' . $ptype; |
128 } |
140 } |
129 |
141 |
130 $menu_class = 'menu-top menu-icon-' . $ptype_for_id; |
142 $menu_class = 'menu-top menu-icon-' . $ptype_for_id; |
131 // 'post' special case |
143 // 'post' special case. |
132 if ( 'post' === $ptype ) { |
144 if ( 'post' === $ptype ) { |
133 $menu_class .= ' open-if-no-js'; |
145 $menu_class .= ' open-if-no-js'; |
134 $ptype_file = 'edit.php'; |
146 $ptype_file = 'edit.php'; |
135 $post_new_file = 'post-new.php'; |
147 $post_new_file = 'post-new.php'; |
136 $edit_tags_file = 'edit-tags.php?taxonomy=%s'; |
148 $edit_tags_file = 'edit-tags.php?taxonomy=%s'; |
138 $ptype_file = "edit.php?post_type=$ptype"; |
150 $ptype_file = "edit.php?post_type=$ptype"; |
139 $post_new_file = "post-new.php?post_type=$ptype"; |
151 $post_new_file = "post-new.php?post_type=$ptype"; |
140 $edit_tags_file = "edit-tags.php?taxonomy=%s&post_type=$ptype"; |
152 $edit_tags_file = "edit-tags.php?taxonomy=%s&post_type=$ptype"; |
141 } |
153 } |
142 |
154 |
143 if ( in_array( $ptype, $builtin ) ) { |
155 if ( in_array( $ptype, $builtin, true ) ) { |
144 $ptype_menu_id = 'menu-' . $ptype_for_id . 's'; |
156 $ptype_menu_id = 'menu-' . $ptype_for_id . 's'; |
145 } else { |
157 } else { |
146 $ptype_menu_id = 'menu-posts-' . $ptype_for_id; |
158 $ptype_menu_id = 'menu-posts-' . $ptype_for_id; |
147 } |
159 } |
148 /* |
160 /* |
149 * If $ptype_menu_position is already populated or will be populated |
161 * If $ptype_menu_position is already populated or will be populated |
150 * by a hard-coded value below, increment the position. |
162 * by a hard-coded value below, increment the position. |
151 */ |
163 */ |
152 $core_menu_positions = array( 59, 60, 65, 70, 75, 80, 85, 99 ); |
164 $core_menu_positions = array( 59, 60, 65, 70, 75, 80, 85, 99 ); |
153 while ( isset( $menu[ $ptype_menu_position ] ) || in_array( $ptype_menu_position, $core_menu_positions ) ) { |
165 while ( isset( $menu[ $ptype_menu_position ] ) || in_array( $ptype_menu_position, $core_menu_positions, true ) ) { |
154 $ptype_menu_position++; |
166 $ptype_menu_position++; |
155 } |
167 } |
156 |
168 |
157 $menu[ $ptype_menu_position ] = array( esc_attr( $ptype_obj->labels->menu_name ), $ptype_obj->cap->edit_posts, $ptype_file, '', $menu_class, $ptype_menu_id, $menu_icon ); |
169 $menu[ $ptype_menu_position ] = array( esc_attr( $ptype_obj->labels->menu_name ), $ptype_obj->cap->edit_posts, $ptype_file, '', $menu_class, $ptype_menu_id, $menu_icon ); |
158 $submenu[ $ptype_file ][5] = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, $ptype_file ); |
170 $submenu[ $ptype_file ][5] = array( $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, $ptype_file ); |
206 * |
218 * |
207 * @access private |
219 * @access private |
208 * @since 3.0.0 |
220 * @since 3.0.0 |
209 */ |
221 */ |
210 function _add_themes_utility_last() { |
222 function _add_themes_utility_last() { |
211 // Must use API on the admin_menu hook, direct modification is only possible on/before the _admin_menu hook |
223 // Must use API on the admin_menu hook, direct modification is only possible on/before the _admin_menu hook. |
212 add_submenu_page( 'themes.php', __( 'Theme Editor' ), __( 'Theme Editor' ), 'edit_themes', 'theme-editor.php' ); |
224 add_submenu_page( 'themes.php', __( 'Theme Editor' ), __( 'Theme Editor' ), 'edit_themes', 'theme-editor.php' ); |
213 } |
225 } |
214 |
226 |
215 $count = ''; |
227 $count = ''; |
216 if ( ! is_multisite() && current_user_can( 'update_plugins' ) ) { |
228 if ( ! is_multisite() && current_user_can( 'update_plugins' ) ) { |
217 if ( ! isset( $update_data ) ) { |
229 if ( ! isset( $update_data ) ) { |
218 $update_data = wp_get_update_data(); |
230 $update_data = wp_get_update_data(); |
219 } |
231 } |
220 $count = "<span class='update-plugins count-{$update_data['counts']['plugins']}'><span class='plugin-count'>" . number_format_i18n( $update_data['counts']['plugins'] ) . '</span></span>'; |
232 $count = sprintf( |
221 } |
233 '<span class="update-plugins count-%s"><span class="plugin-count">%s</span></span>', |
222 |
234 $update_data['counts']['plugins'], |
223 /* translators: %s: number of pending plugin updates */ |
235 number_format_i18n( $update_data['counts']['plugins'] ) |
|
236 ); |
|
237 } |
|
238 |
|
239 /* translators: %s: Number of pending plugin updates. */ |
224 $menu[65] = array( sprintf( __( 'Plugins %s' ), $count ), 'activate_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'dashicons-admin-plugins' ); |
240 $menu[65] = array( sprintf( __( 'Plugins %s' ), $count ), 'activate_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'dashicons-admin-plugins' ); |
225 |
241 |
226 $submenu['plugins.php'][5] = array( __( 'Installed Plugins' ), 'activate_plugins', 'plugins.php' ); |
242 $submenu['plugins.php'][5] = array( __( 'Installed Plugins' ), 'activate_plugins', 'plugins.php' ); |
227 |
243 |
228 if ( ! is_multisite() ) { |
244 if ( ! is_multisite() ) { |
229 /* translators: add new plugin */ |
245 /* translators: Add new plugin. */ |
230 $submenu['plugins.php'][10] = array( _x( 'Add New', 'plugin' ), 'install_plugins', 'plugin-install.php' ); |
246 $submenu['plugins.php'][10] = array( _x( 'Add New', 'plugin' ), 'install_plugins', 'plugin-install.php' ); |
231 $submenu['plugins.php'][15] = array( __( 'Plugin Editor' ), 'edit_plugins', 'plugin-editor.php' ); |
247 $submenu['plugins.php'][15] = array( __( 'Plugin Editor' ), 'edit_plugins', 'plugin-editor.php' ); |
232 } |
248 } |
233 |
249 |
234 unset( $update_data ); |
250 unset( $update_data ); |
246 $submenu['users.php'][10] = array( _x( 'Add New', 'user' ), 'create_users', 'user-new.php' ); |
262 $submenu['users.php'][10] = array( _x( 'Add New', 'user' ), 'create_users', 'user-new.php' ); |
247 } elseif ( is_multisite() ) { |
263 } elseif ( is_multisite() ) { |
248 $submenu['users.php'][10] = array( _x( 'Add New', 'user' ), 'promote_users', 'user-new.php' ); |
264 $submenu['users.php'][10] = array( _x( 'Add New', 'user' ), 'promote_users', 'user-new.php' ); |
249 } |
265 } |
250 |
266 |
251 $submenu['users.php'][15] = array( __( 'Your Profile' ), 'read', 'profile.php' ); |
267 $submenu['users.php'][15] = array( __( 'Profile' ), 'read', 'profile.php' ); |
252 } else { |
268 } else { |
253 $_wp_real_parent_file['users.php'] = 'profile.php'; |
269 $_wp_real_parent_file['users.php'] = 'profile.php'; |
254 $submenu['profile.php'][5] = array( __( 'Your Profile' ), 'read', 'profile.php' ); |
270 $submenu['profile.php'][5] = array( __( 'Profile' ), 'read', 'profile.php' ); |
255 if ( current_user_can( 'create_users' ) ) { |
271 if ( current_user_can( 'create_users' ) ) { |
256 $submenu['profile.php'][10] = array( __( 'Add New User' ), 'create_users', 'user-new.php' ); |
272 $submenu['profile.php'][10] = array( __( 'Add New User' ), 'create_users', 'user-new.php' ); |
257 } elseif ( is_multisite() ) { |
273 } elseif ( is_multisite() ) { |
258 $submenu['profile.php'][10] = array( __( 'Add New User' ), 'promote_users', 'user-new.php' ); |
274 $submenu['profile.php'][10] = array( __( 'Add New User' ), 'promote_users', 'user-new.php' ); |
259 } |
275 } |
262 $menu[75] = array( __( 'Tools' ), 'edit_posts', 'tools.php', '', 'menu-top menu-icon-tools', 'menu-tools', 'dashicons-admin-tools' ); |
278 $menu[75] = array( __( 'Tools' ), 'edit_posts', 'tools.php', '', 'menu-top menu-icon-tools', 'menu-tools', 'dashicons-admin-tools' ); |
263 $submenu['tools.php'][5] = array( __( 'Available Tools' ), 'edit_posts', 'tools.php' ); |
279 $submenu['tools.php'][5] = array( __( 'Available Tools' ), 'edit_posts', 'tools.php' ); |
264 $submenu['tools.php'][10] = array( __( 'Import' ), 'import', 'import.php' ); |
280 $submenu['tools.php'][10] = array( __( 'Import' ), 'import', 'import.php' ); |
265 $submenu['tools.php'][15] = array( __( 'Export' ), 'export', 'export.php' ); |
281 $submenu['tools.php'][15] = array( __( 'Export' ), 'export', 'export.php' ); |
266 $submenu['tools.php'][20] = array( __( 'Site Health' ), 'view_site_health_checks', 'site-health.php' ); |
282 $submenu['tools.php'][20] = array( __( 'Site Health' ), 'view_site_health_checks', 'site-health.php' ); |
|
283 $submenu['tools.php'][25] = array( __( 'Export Personal Data' ), 'export_others_personal_data', 'export-personal-data.php' ); |
|
284 $submenu['tools.php'][30] = array( __( 'Erase Personal Data' ), 'erase_others_personal_data', 'erase-personal-data.php' ); |
267 if ( is_multisite() && ! is_main_site() ) { |
285 if ( is_multisite() && ! is_main_site() ) { |
268 $submenu['tools.php'][25] = array( __( 'Delete Site' ), 'delete_site', 'ms-delete-site.php' ); |
286 $submenu['tools.php'][35] = array( __( 'Delete Site' ), 'delete_site', 'ms-delete-site.php' ); |
269 } |
287 } |
270 if ( ! is_multisite() && defined( 'WP_ALLOW_MULTISITE' ) && WP_ALLOW_MULTISITE ) { |
288 if ( ! is_multisite() && defined( 'WP_ALLOW_MULTISITE' ) && WP_ALLOW_MULTISITE ) { |
271 $submenu['tools.php'][50] = array( __( 'Network Setup' ), 'setup_network', 'network.php' ); |
289 $submenu['tools.php'][50] = array( __( 'Network Setup' ), 'setup_network', 'network.php' ); |
272 } |
290 } |
273 |
291 |
276 $submenu['options-general.php'][15] = array( __( 'Writing' ), 'manage_options', 'options-writing.php' ); |
294 $submenu['options-general.php'][15] = array( __( 'Writing' ), 'manage_options', 'options-writing.php' ); |
277 $submenu['options-general.php'][20] = array( __( 'Reading' ), 'manage_options', 'options-reading.php' ); |
295 $submenu['options-general.php'][20] = array( __( 'Reading' ), 'manage_options', 'options-reading.php' ); |
278 $submenu['options-general.php'][25] = array( __( 'Discussion' ), 'manage_options', 'options-discussion.php' ); |
296 $submenu['options-general.php'][25] = array( __( 'Discussion' ), 'manage_options', 'options-discussion.php' ); |
279 $submenu['options-general.php'][30] = array( __( 'Media' ), 'manage_options', 'options-media.php' ); |
297 $submenu['options-general.php'][30] = array( __( 'Media' ), 'manage_options', 'options-media.php' ); |
280 $submenu['options-general.php'][40] = array( __( 'Permalinks' ), 'manage_options', 'options-permalink.php' ); |
298 $submenu['options-general.php'][40] = array( __( 'Permalinks' ), 'manage_options', 'options-permalink.php' ); |
281 $submenu['options-general.php'][45] = array( __( 'Privacy' ), 'manage_privacy_options', 'privacy.php' ); |
299 $submenu['options-general.php'][45] = array( __( 'Privacy' ), 'manage_privacy_options', 'options-privacy.php' ); |
282 |
300 |
283 $_wp_last_utility_menu = 80; // The index of the last top-level menu in the utility menu group |
301 $_wp_last_utility_menu = 80; // The index of the last top-level menu in the utility menu group. |
284 |
302 |
285 $menu[99] = array( '', 'read', 'separator-last', '', 'wp-menu-separator' ); |
303 $menu[99] = array( '', 'read', 'separator-last', '', 'wp-menu-separator' ); |
286 |
304 |
287 // Back-compat for old top-levels |
305 // Back-compat for old top-levels. |
288 $_wp_real_parent_file['post.php'] = 'edit.php'; |
306 $_wp_real_parent_file['post.php'] = 'edit.php'; |
289 $_wp_real_parent_file['post-new.php'] = 'edit.php'; |
307 $_wp_real_parent_file['post-new.php'] = 'edit.php'; |
290 $_wp_real_parent_file['edit-pages.php'] = 'edit.php?post_type=page'; |
308 $_wp_real_parent_file['edit-pages.php'] = 'edit.php?post_type=page'; |
291 $_wp_real_parent_file['page-new.php'] = 'edit.php?post_type=page'; |
309 $_wp_real_parent_file['page-new.php'] = 'edit.php?post_type=page'; |
292 $_wp_real_parent_file['wpmu-admin.php'] = 'tools.php'; |
310 $_wp_real_parent_file['wpmu-admin.php'] = 'tools.php'; |