59 * @link http://trac.wordpress.org/ticket/5651 Previous Optimizations. |
63 * @link http://trac.wordpress.org/ticket/5651 Previous Optimizations. |
60 * @link http://trac.wordpress.org/ticket/7372 Further and better Optimizations. |
64 * @link http://trac.wordpress.org/ticket/7372 Further and better Optimizations. |
61 * @since 1.5.0 |
65 * @since 1.5.0 |
62 * |
66 * |
63 * @param string $plugin_file Path to the plugin file |
67 * @param string $plugin_file Path to the plugin file |
64 * @param bool $markup If the returned data should have HTML markup applied |
68 * @param bool $markup Optional. If the returned data should have HTML markup applied. Defaults to true. |
65 * @param bool $translate If the returned data should be translated |
69 * @param bool $translate Optional. If the returned data should be translated. Defaults to true. |
66 * @return array See above for description. |
70 * @return array See above for description. |
67 */ |
71 */ |
68 function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { |
72 function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { |
69 |
73 |
70 $default_headers = array( |
74 $default_headers = array( |
71 'Name' => 'Plugin Name', |
75 'Name' => 'Plugin Name', |
72 'PluginURI' => 'Plugin URI', |
76 'PluginURI' => 'Plugin URI', |
73 'Version' => 'Version', |
77 'Version' => 'Version', |
74 'Description' => 'Description', |
78 'Description' => 'Description', |
75 'Author' => 'Author', |
79 'Author' => 'Author', |
76 'AuthorURI' => 'Author URI', |
80 'AuthorURI' => 'Author URI', |
77 'TextDomain' => 'Text Domain', |
81 'TextDomain' => 'Text Domain', |
78 'DomainPath' => 'Domain Path' |
82 'DomainPath' => 'Domain Path', |
79 ); |
83 'Network' => 'Network', |
|
84 // Site Wide Only is deprecated in favor of Network. |
|
85 '_sitewide' => 'Site Wide Only', |
|
86 ); |
80 |
87 |
81 $plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' ); |
88 $plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' ); |
82 |
89 |
83 //For backward compatibility by default Title is the same as Name. |
90 // Site Wide Only is the old header for Network |
84 $plugin_data['Title'] = $plugin_data['Name']; |
91 if ( ! $plugin_data['Network'] && $plugin_data['_sitewide'] ) { |
85 |
92 _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The <code>%1$s</code> plugin header is deprecated. Use <code>%2$s</code> instead.' ), 'Site Wide Only: true', 'Network: true' ) ); |
86 if ( $markup || $translate ) |
93 $plugin_data['Network'] = $plugin_data['_sitewide']; |
|
94 } |
|
95 $plugin_data['Network'] = ( 'true' == strtolower( $plugin_data['Network'] ) ); |
|
96 unset( $plugin_data['_sitewide'] ); |
|
97 |
|
98 if ( $markup || $translate ) { |
87 $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate ); |
99 $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate ); |
|
100 } else { |
|
101 $plugin_data['Title'] = $plugin_data['Name']; |
|
102 $plugin_data['AuthorName'] = $plugin_data['Author']; |
|
103 } |
88 |
104 |
89 return $plugin_data; |
105 return $plugin_data; |
90 } |
106 } |
91 |
107 |
92 function _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup = true, $translate = true) { |
108 /** |
93 |
109 * Sanitizes plugin data, optionally adds markup, optionally translates. |
94 //Translate fields |
110 * |
95 if( $translate && ! empty($plugin_data['TextDomain']) ) { |
111 * @since 2.7.0 |
96 if( ! empty( $plugin_data['DomainPath'] ) ) |
112 * @access private |
97 load_plugin_textdomain($plugin_data['TextDomain'], false, dirname($plugin_file). $plugin_data['DomainPath']); |
113 * @see get_plugin_data() |
98 else |
114 */ |
99 load_plugin_textdomain($plugin_data['TextDomain'], false, dirname($plugin_file)); |
115 function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup = true, $translate = true ) { |
100 |
116 |
101 foreach ( array('Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version') as $field ) |
117 // Translate fields |
102 $plugin_data[ $field ] = translate($plugin_data[ $field ], $plugin_data['TextDomain']); |
118 if ( $translate ) { |
103 } |
119 if ( $textdomain = $plugin_data['TextDomain'] ) { |
104 |
120 if ( $plugin_data['DomainPath'] ) |
105 //Apply Markup |
121 load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin_data['DomainPath'] ); |
|
122 else |
|
123 load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) ); |
|
124 } elseif ( in_array( basename( $plugin_file ), array( 'hello.php', 'akismet.php' ) ) ) { |
|
125 $textdomain = 'default'; |
|
126 } |
|
127 if ( $textdomain ) { |
|
128 foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) |
|
129 $plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain ); |
|
130 } |
|
131 } |
|
132 |
|
133 // Sanitize fields |
|
134 $allowed_tags = $allowed_tags_in_links = array( |
|
135 'abbr' => array( 'title' => true ), |
|
136 'acronym' => array( 'title' => true ), |
|
137 'code' => true, |
|
138 'em' => true, |
|
139 'strong' => true, |
|
140 ); |
|
141 $allowed_tags['a'] = array( 'href' => true, 'title' => true ); |
|
142 |
|
143 // Name is marked up inside <a> tags. Don't allow these. |
|
144 // Author is too, but some plugins have used <a> here (omitting Author URI). |
|
145 $plugin_data['Name'] = wp_kses( $plugin_data['Name'], $allowed_tags_in_links ); |
|
146 $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $allowed_tags ); |
|
147 |
|
148 $plugin_data['Description'] = wp_kses( $plugin_data['Description'], $allowed_tags ); |
|
149 $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $allowed_tags ); |
|
150 |
|
151 $plugin_data['PluginURI'] = esc_url( $plugin_data['PluginURI'] ); |
|
152 $plugin_data['AuthorURI'] = esc_url( $plugin_data['AuthorURI'] ); |
|
153 |
|
154 $plugin_data['Title'] = $plugin_data['Name']; |
|
155 $plugin_data['AuthorName'] = $plugin_data['Author']; |
|
156 |
|
157 // Apply markup |
106 if ( $markup ) { |
158 if ( $markup ) { |
107 if ( ! empty($plugin_data['PluginURI']) && ! empty($plugin_data['Name']) ) |
159 if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) |
108 $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __( 'Visit plugin homepage' ) . '">' . $plugin_data['Name'] . '</a>'; |
160 $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin homepage' ) . '">' . $plugin_data['Name'] . '</a>'; |
109 else |
161 |
110 $plugin_data['Title'] = $plugin_data['Name']; |
162 if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) |
111 |
163 $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>'; |
112 if ( ! empty($plugin_data['AuthorURI']) && ! empty($plugin_data['Author']) ) |
|
113 $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>'; |
|
114 |
164 |
115 $plugin_data['Description'] = wptexturize( $plugin_data['Description'] ); |
165 $plugin_data['Description'] = wptexturize( $plugin_data['Description'] ); |
116 if( ! empty($plugin_data['Author']) ) |
166 |
117 $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s'), $plugin_data['Author'] ) . '.</cite>'; |
167 if ( $plugin_data['Author'] ) |
118 } |
168 $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s.'), $plugin_data['Author'] ) . '</cite>'; |
119 |
169 } |
120 $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); |
|
121 |
|
122 // Sanitize all displayed data |
|
123 $plugin_data['Title'] = wp_kses($plugin_data['Title'], $plugins_allowedtags); |
|
124 $plugin_data['Version'] = wp_kses($plugin_data['Version'], $plugins_allowedtags); |
|
125 $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags); |
|
126 $plugin_data['Author'] = wp_kses($plugin_data['Author'], $plugins_allowedtags); |
|
127 |
170 |
128 return $plugin_data; |
171 return $plugin_data; |
129 } |
172 } |
130 |
173 |
131 /** |
174 /** |
240 continue; |
283 continue; |
241 |
284 |
242 $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; |
285 $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; |
243 } |
286 } |
244 |
287 |
245 uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' )); |
288 uasort( $wp_plugins, '_sort_uname_callback' ); |
246 |
289 |
247 $cache_plugins[ $plugin_folder ] = $wp_plugins; |
290 $cache_plugins[ $plugin_folder ] = $wp_plugins; |
248 wp_cache_set('plugins', $cache_plugins, 'plugins'); |
291 wp_cache_set('plugins', $cache_plugins, 'plugins'); |
249 |
292 |
250 return $wp_plugins; |
293 return $wp_plugins; |
251 } |
294 } |
252 |
295 |
253 /** |
296 /** |
|
297 * Check the mu-plugins directory and retrieve all mu-plugin files with any plugin data. |
|
298 * |
|
299 * WordPress only includes mu-plugin files in the base mu-plugins directory (wp-content/mu-plugins). |
|
300 * |
|
301 * @since 3.0.0 |
|
302 * @return array Key is the mu-plugin file path and the value is an array of the mu-plugin data. |
|
303 */ |
|
304 function get_mu_plugins() { |
|
305 $wp_plugins = array(); |
|
306 // Files in wp-content/mu-plugins directory |
|
307 $plugin_files = array(); |
|
308 |
|
309 if ( ! is_dir( WPMU_PLUGIN_DIR ) ) |
|
310 return $wp_plugins; |
|
311 if ( $plugins_dir = @ opendir( WPMU_PLUGIN_DIR ) ) { |
|
312 while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
|
313 if ( substr( $file, -4 ) == '.php' ) |
|
314 $plugin_files[] = $file; |
|
315 } |
|
316 } else { |
|
317 return $wp_plugins; |
|
318 } |
|
319 |
|
320 @closedir( $plugins_dir ); |
|
321 |
|
322 if ( empty($plugin_files) ) |
|
323 return $wp_plugins; |
|
324 |
|
325 foreach ( $plugin_files as $plugin_file ) { |
|
326 if ( !is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) ) |
|
327 continue; |
|
328 |
|
329 $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. |
|
330 |
|
331 if ( empty ( $plugin_data['Name'] ) ) |
|
332 $plugin_data['Name'] = $plugin_file; |
|
333 |
|
334 $wp_plugins[ $plugin_file ] = $plugin_data; |
|
335 } |
|
336 |
|
337 if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) // silence is golden |
|
338 unset( $wp_plugins['index.php'] ); |
|
339 |
|
340 uasort( $wp_plugins, '_sort_uname_callback' ); |
|
341 |
|
342 return $wp_plugins; |
|
343 } |
|
344 |
|
345 /** |
|
346 * Callback to sort array by a 'Name' key. |
|
347 * |
|
348 * @since 3.1.0 |
|
349 * @access private |
|
350 */ |
|
351 function _sort_uname_callback( $a, $b ) { |
|
352 return strnatcasecmp( $a['Name'], $b['Name'] ); |
|
353 } |
|
354 |
|
355 /** |
|
356 * Check the wp-content directory and retrieve all drop-ins with any plugin data. |
|
357 * |
|
358 * @since 3.0.0 |
|
359 * @return array Key is the file path and the value is an array of the plugin data. |
|
360 */ |
|
361 function get_dropins() { |
|
362 $dropins = array(); |
|
363 $plugin_files = array(); |
|
364 |
|
365 $_dropins = _get_dropins(); |
|
366 |
|
367 // These exist in the wp-content directory |
|
368 if ( $plugins_dir = @ opendir( WP_CONTENT_DIR ) ) { |
|
369 while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
|
370 if ( isset( $_dropins[ $file ] ) ) |
|
371 $plugin_files[] = $file; |
|
372 } |
|
373 } else { |
|
374 return $dropins; |
|
375 } |
|
376 |
|
377 @closedir( $plugins_dir ); |
|
378 |
|
379 if ( empty($plugin_files) ) |
|
380 return $dropins; |
|
381 |
|
382 foreach ( $plugin_files as $plugin_file ) { |
|
383 if ( !is_readable( WP_CONTENT_DIR . "/$plugin_file" ) ) |
|
384 continue; |
|
385 $plugin_data = get_plugin_data( WP_CONTENT_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. |
|
386 if ( empty( $plugin_data['Name'] ) ) |
|
387 $plugin_data['Name'] = $plugin_file; |
|
388 $dropins[ $plugin_file ] = $plugin_data; |
|
389 } |
|
390 |
|
391 uksort( $dropins, 'strnatcasecmp' ); |
|
392 |
|
393 return $dropins; |
|
394 } |
|
395 |
|
396 /** |
|
397 * Returns drop-ins that WordPress uses. |
|
398 * |
|
399 * Includes Multisite drop-ins only when is_multisite() |
|
400 * |
|
401 * @since 3.0.0 |
|
402 * @return array Key is file name. The value is an array, with the first value the |
|
403 * purpose of the drop-in and the second value the name of the constant that must be |
|
404 * true for the drop-in to be used, or true if no constant is required. |
|
405 */ |
|
406 function _get_dropins() { |
|
407 $dropins = array( |
|
408 'advanced-cache.php' => array( __( 'Advanced caching plugin.' ), 'WP_CACHE' ), // WP_CACHE |
|
409 'db.php' => array( __( 'Custom database class.' ), true ), // auto on load |
|
410 'db-error.php' => array( __( 'Custom database error message.' ), true ), // auto on error |
|
411 'install.php' => array( __( 'Custom install script.' ), true ), // auto on install |
|
412 'maintenance.php' => array( __( 'Custom maintenance message.' ), true ), // auto on maintenance |
|
413 'object-cache.php' => array( __( 'External object cache.' ), true ), // auto on load |
|
414 ); |
|
415 |
|
416 if ( is_multisite() ) { |
|
417 $dropins['sunrise.php' ] = array( __( 'Executed before Multisite is loaded.' ), 'SUNRISE' ); // SUNRISE |
|
418 $dropins['blog-deleted.php' ] = array( __( 'Custom site deleted message.' ), true ); // auto on deleted blog |
|
419 $dropins['blog-inactive.php' ] = array( __( 'Custom site inactive message.' ), true ); // auto on inactive blog |
|
420 $dropins['blog-suspended.php'] = array( __( 'Custom site suspended message.' ), true ); // auto on archived or spammed blog |
|
421 } |
|
422 |
|
423 return $dropins; |
|
424 } |
|
425 |
|
426 /** |
254 * Check whether the plugin is active by checking the active_plugins list. |
427 * Check whether the plugin is active by checking the active_plugins list. |
255 * |
428 * |
256 * @since 2.5.0 |
429 * @since 2.5.0 |
257 * |
430 * |
258 * @param string $plugin Base plugin path from plugins directory. |
431 * @param string $plugin Base plugin path from plugins directory. |
259 * @return bool True, if in the active plugins list. False, not in the list. |
432 * @return bool True, if in the active plugins list. False, not in the list. |
260 */ |
433 */ |
261 function is_plugin_active($plugin) { |
434 function is_plugin_active( $plugin ) { |
262 return in_array( $plugin, apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ); |
435 return in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) || is_plugin_active_for_network( $plugin ); |
|
436 } |
|
437 |
|
438 /** |
|
439 * Check whether the plugin is inactive. |
|
440 * |
|
441 * Reverse of is_plugin_active(). Used as a callback. |
|
442 * |
|
443 * @since 3.1.0 |
|
444 * @see is_plugin_active() |
|
445 * |
|
446 * @param string $plugin Base plugin path from plugins directory. |
|
447 * @return bool True if inactive. False if active. |
|
448 */ |
|
449 function is_plugin_inactive( $plugin ) { |
|
450 return ! is_plugin_active( $plugin ); |
|
451 } |
|
452 |
|
453 /** |
|
454 * Check whether the plugin is active for the entire network. |
|
455 * |
|
456 * @since 3.0.0 |
|
457 * |
|
458 * @param string $plugin Base plugin path from plugins directory. |
|
459 * @return bool True, if active for the network, otherwise false. |
|
460 */ |
|
461 function is_plugin_active_for_network( $plugin ) { |
|
462 if ( !is_multisite() ) |
|
463 return false; |
|
464 |
|
465 $plugins = get_site_option( 'active_sitewide_plugins'); |
|
466 if ( isset($plugins[$plugin]) ) |
|
467 return true; |
|
468 |
|
469 return false; |
|
470 } |
|
471 |
|
472 /** |
|
473 * Checks for "Network: true" in the plugin header to see if this should |
|
474 * be activated only as a network wide plugin. The plugin would also work |
|
475 * when Multisite is not enabled. |
|
476 * |
|
477 * Checks for "Site Wide Only: true" for backwards compatibility. |
|
478 * |
|
479 * @since 3.0.0 |
|
480 * |
|
481 * @param string $plugin Plugin to check |
|
482 * @return bool True if plugin is network only, false otherwise. |
|
483 */ |
|
484 function is_network_only_plugin( $plugin ) { |
|
485 $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
|
486 if ( $plugin_data ) |
|
487 return $plugin_data['Network']; |
|
488 return false; |
263 } |
489 } |
264 |
490 |
265 /** |
491 /** |
266 * Attempts activation of plugin in a "sandbox" and redirects on success. |
492 * Attempts activation of plugin in a "sandbox" and redirects on success. |
267 * |
493 * |
581 |
868 |
582 // |
869 // |
583 // Menu |
870 // Menu |
584 // |
871 // |
585 |
872 |
586 function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '', $position = NULL ) { |
873 /** |
587 global $menu, $admin_page_hooks, $_registered_pages; |
874 * Add a top level menu page |
588 |
875 * |
589 $file = plugin_basename( $file ); |
876 * This function takes a capability which will be used to determine whether |
590 |
877 * or not a page is included in the menu. |
591 $admin_page_hooks[$file] = sanitize_title( $menu_title ); |
878 * |
592 |
879 * The function which is hooked in to handle the output of the page must check |
593 $hookname = get_plugin_page_hookname( $file, '' ); |
880 * that the user has the required capability as well. |
594 if (!empty ( $function ) && !empty ( $hookname )) |
881 * |
|
882 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
883 * @param string $menu_title The text to be used for the menu |
|
884 * @param string $capability The capability required for this menu to be displayed to the user. |
|
885 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
886 * @param callback $function The function to be called to output the content for this page. |
|
887 * @param string $icon_url The url to the icon to be used for this menu |
|
888 * @param int $position The position in the menu order this one should appear |
|
889 * |
|
890 * @return string The resulting page's hook_suffix |
|
891 */ |
|
892 function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = null ) { |
|
893 global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages; |
|
894 |
|
895 $menu_slug = plugin_basename( $menu_slug ); |
|
896 |
|
897 $admin_page_hooks[$menu_slug] = sanitize_title( $menu_title ); |
|
898 |
|
899 $hookname = get_plugin_page_hookname( $menu_slug, '' ); |
|
900 |
|
901 if ( !empty( $function ) && !empty( $hookname ) && current_user_can( $capability ) ) |
595 add_action( $hookname, $function ); |
902 add_action( $hookname, $function ); |
596 |
903 |
597 if ( empty($icon_url) ) { |
904 if ( empty($icon_url) ) |
598 $icon_url = 'images/generic.png'; |
905 $icon_url = esc_url( admin_url( 'images/generic.png' ) ); |
599 } elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') ) { |
906 elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') ) |
600 $icon_url = 'https://' . substr($icon_url, 7); |
907 $icon_url = 'https://' . substr($icon_url, 7); |
601 } |
908 |
602 |
909 $new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); |
603 $new_menu = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); |
910 |
604 |
911 if ( null === $position ) |
605 if ( NULL === $position ) { |
|
606 $menu[] = $new_menu; |
912 $menu[] = $new_menu; |
607 } else { |
913 else |
608 $menu[$position] = $new_menu; |
914 $menu[$position] = $new_menu; |
609 } |
|
610 |
915 |
611 $_registered_pages[$hookname] = true; |
916 $_registered_pages[$hookname] = true; |
612 |
917 |
|
918 // No parent as top level |
|
919 $_parent_pages[$menu_slug] = false; |
|
920 |
613 return $hookname; |
921 return $hookname; |
614 } |
922 } |
615 |
923 |
616 function add_object_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '') { |
924 /** |
|
925 * Add a top level menu page in the 'objects' section |
|
926 * |
|
927 * This function takes a capability which will be used to determine whether |
|
928 * or not a page is included in the menu. |
|
929 * |
|
930 * The function which is hooked in to handle the output of the page must check |
|
931 * that the user has the required capability as well. |
|
932 * |
|
933 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
934 * @param string $menu_title The text to be used for the menu |
|
935 * @param string $capability The capability required for this menu to be displayed to the user. |
|
936 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
937 * @param callback $function The function to be called to output the content for this page. |
|
938 * @param string $icon_url The url to the icon to be used for this menu |
|
939 * |
|
940 * @return string The resulting page's hook_suffix |
|
941 */ |
|
942 function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') { |
617 global $_wp_last_object_menu; |
943 global $_wp_last_object_menu; |
618 |
944 |
619 $_wp_last_object_menu++; |
945 $_wp_last_object_menu++; |
620 |
946 |
621 return add_menu_page($page_title, $menu_title, $access_level, $file, $function, $icon_url, $_wp_last_object_menu); |
947 return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $_wp_last_object_menu); |
622 } |
948 } |
623 |
949 |
624 function add_utility_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '') { |
950 /** |
|
951 * Add a top level menu page in the 'utility' section |
|
952 * |
|
953 * This function takes a capability which will be used to determine whether |
|
954 * or not a page is included in the menu. |
|
955 * |
|
956 * The function which is hooked in to handle the output of the page must check |
|
957 * that the user has the required capability as well. |
|
958 * |
|
959 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
960 * @param string $menu_title The text to be used for the menu |
|
961 * @param string $capability The capability required for this menu to be displayed to the user. |
|
962 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
963 * @param callback $function The function to be called to output the content for this page. |
|
964 * @param string $icon_url The url to the icon to be used for this menu |
|
965 * |
|
966 * @return string The resulting page's hook_suffix |
|
967 */ |
|
968 function add_utility_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') { |
625 global $_wp_last_utility_menu; |
969 global $_wp_last_utility_menu; |
626 |
970 |
627 $_wp_last_utility_menu++; |
971 $_wp_last_utility_menu++; |
628 |
972 |
629 return add_menu_page($page_title, $menu_title, $access_level, $file, $function, $icon_url, $_wp_last_utility_menu); |
973 return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $_wp_last_utility_menu); |
630 } |
974 } |
631 |
975 |
632 function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) { |
976 /** |
|
977 * Add a sub menu page |
|
978 * |
|
979 * This function takes a capability which will be used to determine whether |
|
980 * or not a page is included in the menu. |
|
981 * |
|
982 * The function which is hooked in to handle the output of the page must check |
|
983 * that the user has the required capability as well. |
|
984 * |
|
985 * @param string $parent_slug The slug name for the parent menu (or the file name of a standard WordPress admin page) |
|
986 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
987 * @param string $menu_title The text to be used for the menu |
|
988 * @param string $capability The capability required for this menu to be displayed to the user. |
|
989 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
990 * @param callback $function The function to be called to output the content for this page. |
|
991 * |
|
992 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
993 */ |
|
994 function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
633 global $submenu; |
995 global $submenu; |
634 global $menu; |
996 global $menu; |
635 global $_wp_real_parent_file; |
997 global $_wp_real_parent_file; |
636 global $_wp_submenu_nopriv; |
998 global $_wp_submenu_nopriv; |
637 global $_registered_pages; |
999 global $_registered_pages; |
638 |
1000 global $_parent_pages; |
639 $file = plugin_basename( $file ); |
1001 |
640 |
1002 $menu_slug = plugin_basename( $menu_slug ); |
641 $parent = plugin_basename( $parent); |
1003 $parent_slug = plugin_basename( $parent_slug); |
642 if ( isset( $_wp_real_parent_file[$parent] ) ) |
1004 |
643 $parent = $_wp_real_parent_file[$parent]; |
1005 if ( isset( $_wp_real_parent_file[$parent_slug] ) ) |
644 |
1006 $parent_slug = $_wp_real_parent_file[$parent_slug]; |
645 if ( !current_user_can( $access_level ) ) { |
1007 |
646 $_wp_submenu_nopriv[$parent][$file] = true; |
1008 if ( !current_user_can( $capability ) ) { |
|
1009 $_wp_submenu_nopriv[$parent_slug][$menu_slug] = true; |
647 return false; |
1010 return false; |
648 } |
1011 } |
649 |
1012 |
650 // If the parent doesn't already have a submenu, add a link to the parent |
1013 // If the parent doesn't already have a submenu, add a link to the parent |
651 // as the first item in the submenu. If the submenu file is the same as the |
1014 // as the first item in the submenu. If the submenu file is the same as the |
652 // parent file someone is trying to link back to the parent manually. In |
1015 // parent file someone is trying to link back to the parent manually. In |
653 // this case, don't automatically add a link back to avoid duplication. |
1016 // this case, don't automatically add a link back to avoid duplication. |
654 if (!isset( $submenu[$parent] ) && $file != $parent ) { |
1017 if (!isset( $submenu[$parent_slug] ) && $menu_slug != $parent_slug ) { |
655 foreach ( (array)$menu as $parent_menu ) { |
1018 foreach ( (array)$menu as $parent_menu ) { |
656 if ( $parent_menu[2] == $parent && current_user_can( $parent_menu[1] ) ) |
1019 if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) |
657 $submenu[$parent][] = $parent_menu; |
1020 $submenu[$parent_slug][] = $parent_menu; |
658 } |
1021 } |
659 } |
1022 } |
660 |
1023 |
661 $submenu[$parent][] = array ( $menu_title, $access_level, $file, $page_title ); |
1024 $submenu[$parent_slug][] = array ( $menu_title, $capability, $menu_slug, $page_title ); |
662 |
1025 |
663 $hookname = get_plugin_page_hookname( $file, $parent); |
1026 $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug); |
664 if (!empty ( $function ) && !empty ( $hookname )) |
1027 if (!empty ( $function ) && !empty ( $hookname )) |
665 add_action( $hookname, $function ); |
1028 add_action( $hookname, $function ); |
666 |
1029 |
667 $_registered_pages[$hookname] = true; |
1030 $_registered_pages[$hookname] = true; |
668 // backwards-compatibility for plugins using add_management page. See wp-admin/admin.php for redirect from edit.php to tools.php |
1031 // backwards-compatibility for plugins using add_management page. See wp-admin/admin.php for redirect from edit.php to tools.php |
669 if ( 'tools.php' == $parent ) |
1032 if ( 'tools.php' == $parent_slug ) |
670 $_registered_pages[get_plugin_page_hookname( $file, 'edit.php')] = true; |
1033 $_registered_pages[get_plugin_page_hookname( $menu_slug, 'edit.php')] = true; |
|
1034 |
|
1035 // No parent as top level |
|
1036 $_parent_pages[$menu_slug] = $parent_slug; |
671 |
1037 |
672 return $hookname; |
1038 return $hookname; |
673 } |
1039 } |
674 |
1040 |
675 /** |
1041 /** |
676 * Add sub menu page to the tools main menu. |
1042 * Add sub menu page to the tools main menu. |
677 * |
1043 * |
678 * @param string $page_title |
1044 * This function takes a capability which will be used to determine whether |
679 * @param unknown_type $menu_title |
1045 * or not a page is included in the menu. |
680 * @param unknown_type $access_level |
1046 * |
681 * @param unknown_type $file |
1047 * The function which is hooked in to handle the output of the page must check |
682 * @param unknown_type $function |
1048 * that the user has the required capability as well. |
683 * @return unknown |
1049 * |
684 */ |
1050 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
685 function add_management_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
1051 * @param string $menu_title The text to be used for the menu |
686 return add_submenu_page( 'tools.php', $page_title, $menu_title, $access_level, $file, $function ); |
1052 * @param string $capability The capability required for this menu to be displayed to the user. |
687 } |
1053 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
688 |
1054 * @param callback $function The function to be called to output the content for this page. |
689 function add_options_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
1055 * |
690 return add_submenu_page( 'options-general.php', $page_title, $menu_title, $access_level, $file, $function ); |
1056 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. |
691 } |
1057 */ |
692 |
1058 function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
693 function add_theme_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
1059 return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
694 return add_submenu_page( 'themes.php', $page_title, $menu_title, $access_level, $file, $function ); |
1060 } |
695 } |
1061 |
696 |
1062 /** |
697 function add_users_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
1063 * Add sub menu page to the options main menu. |
|
1064 * |
|
1065 * This function takes a capability which will be used to determine whether |
|
1066 * or not a page is included in the menu. |
|
1067 * |
|
1068 * The function which is hooked in to handle the output of the page must check |
|
1069 * that the user has the required capability as well. |
|
1070 * |
|
1071 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
1072 * @param string $menu_title The text to be used for the menu |
|
1073 * @param string $capability The capability required for this menu to be displayed to the user. |
|
1074 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
1075 * @param callback $function The function to be called to output the content for this page. |
|
1076 * |
|
1077 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
1078 */ |
|
1079 function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1080 return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1081 } |
|
1082 |
|
1083 /** |
|
1084 * Add sub menu page to the themes main menu. |
|
1085 * |
|
1086 * This function takes a capability which will be used to determine whether |
|
1087 * or not a page is included in the menu. |
|
1088 * |
|
1089 * The function which is hooked in to handle the output of the page must check |
|
1090 * that the user has the required capability as well. |
|
1091 * |
|
1092 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
1093 * @param string $menu_title The text to be used for the menu |
|
1094 * @param string $capability The capability required for this menu to be displayed to the user. |
|
1095 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
1096 * @param callback $function The function to be called to output the content for this page. |
|
1097 * |
|
1098 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
1099 */ |
|
1100 function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1101 return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1102 } |
|
1103 |
|
1104 /** |
|
1105 * Add sub menu page to the plugins main menu. |
|
1106 * |
|
1107 * This function takes a capability which will be used to determine whether |
|
1108 * or not a page is included in the menu. |
|
1109 * |
|
1110 * The function which is hooked in to handle the output of the page must check |
|
1111 * that the user has the required capability as well. |
|
1112 * |
|
1113 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
1114 * @param string $menu_title The text to be used for the menu |
|
1115 * @param string $capability The capability required for this menu to be displayed to the user. |
|
1116 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
1117 * @param callback $function The function to be called to output the content for this page. |
|
1118 * |
|
1119 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
1120 */ |
|
1121 function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1122 return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1123 } |
|
1124 |
|
1125 /** |
|
1126 * Add sub menu page to the Users/Profile main menu. |
|
1127 * |
|
1128 * This function takes a capability which will be used to determine whether |
|
1129 * or not a page is included in the menu. |
|
1130 * |
|
1131 * The function which is hooked in to handle the output of the page must check |
|
1132 * that the user has the required capability as well. |
|
1133 * |
|
1134 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
1135 * @param string $menu_title The text to be used for the menu |
|
1136 * @param string $capability The capability required for this menu to be displayed to the user. |
|
1137 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
1138 * @param callback $function The function to be called to output the content for this page. |
|
1139 * |
|
1140 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
1141 */ |
|
1142 function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
698 if ( current_user_can('edit_users') ) |
1143 if ( current_user_can('edit_users') ) |
699 $parent = 'users.php'; |
1144 $parent = 'users.php'; |
700 else |
1145 else |
701 $parent = 'profile.php'; |
1146 $parent = 'profile.php'; |
702 return add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function ); |
1147 return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function ); |
703 } |
1148 } |
704 |
1149 /** |
705 function add_dashboard_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
1150 * Add sub menu page to the Dashboard main menu. |
706 return add_submenu_page( 'index.php', $page_title, $menu_title, $access_level, $file, $function ); |
1151 * |
707 } |
1152 * This function takes a capability which will be used to determine whether |
708 |
1153 * or not a page is included in the menu. |
709 function add_posts_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
1154 * |
710 return add_submenu_page( 'edit.php', $page_title, $menu_title, $access_level, $file, $function ); |
1155 * The function which is hooked in to handle the output of the page must check |
711 } |
1156 * that the user has the required capability as well. |
712 |
1157 * |
713 function add_media_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
1158 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
714 return add_submenu_page( 'upload.php', $page_title, $menu_title, $access_level, $file, $function ); |
1159 * @param string $menu_title The text to be used for the menu |
715 } |
1160 * @param string $capability The capability required for this menu to be displayed to the user. |
716 |
1161 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
717 function add_links_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
1162 * @param callback $function The function to be called to output the content for this page. |
718 return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $access_level, $file, $function ); |
1163 * |
719 } |
1164 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. |
720 |
1165 */ |
721 function add_pages_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
1166 function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
722 return add_submenu_page( 'edit-pages.php', $page_title, $menu_title, $access_level, $file, $function ); |
1167 return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
723 } |
1168 } |
724 |
1169 |
725 function add_comments_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
1170 /** |
726 return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $access_level, $file, $function ); |
1171 * Add sub menu page to the posts main menu. |
|
1172 * |
|
1173 * This function takes a capability which will be used to determine whether |
|
1174 * or not a page is included in the menu. |
|
1175 * |
|
1176 * The function which is hooked in to handle the output of the page must check |
|
1177 * that the user has the required capability as well. |
|
1178 * |
|
1179 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
1180 * @param string $menu_title The text to be used for the menu |
|
1181 * @param string $capability The capability required for this menu to be displayed to the user. |
|
1182 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
1183 * @param callback $function The function to be called to output the content for this page. |
|
1184 * |
|
1185 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
1186 */ |
|
1187 function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1188 return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1189 } |
|
1190 |
|
1191 /** |
|
1192 * Add sub menu page to the media main menu. |
|
1193 * |
|
1194 * This function takes a capability which will be used to determine whether |
|
1195 * or not a page is included in the menu. |
|
1196 * |
|
1197 * The function which is hooked in to handle the output of the page must check |
|
1198 * that the user has the required capability as well. |
|
1199 * |
|
1200 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
1201 * @param string $menu_title The text to be used for the menu |
|
1202 * @param string $capability The capability required for this menu to be displayed to the user. |
|
1203 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
1204 * @param callback $function The function to be called to output the content for this page. |
|
1205 * |
|
1206 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
1207 */ |
|
1208 function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1209 return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1210 } |
|
1211 |
|
1212 /** |
|
1213 * Add sub menu page to the links main menu. |
|
1214 * |
|
1215 * This function takes a capability which will be used to determine whether |
|
1216 * or not a page is included in the menu. |
|
1217 * |
|
1218 * The function which is hooked in to handle the output of the page must check |
|
1219 * that the user has the required capability as well. |
|
1220 * |
|
1221 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
1222 * @param string $menu_title The text to be used for the menu |
|
1223 * @param string $capability The capability required for this menu to be displayed to the user. |
|
1224 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
1225 * @param callback $function The function to be called to output the content for this page. |
|
1226 * |
|
1227 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
1228 */ |
|
1229 function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1230 return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1231 } |
|
1232 |
|
1233 /** |
|
1234 * Add sub menu page to the pages main menu. |
|
1235 * |
|
1236 * This function takes a capability which will be used to determine whether |
|
1237 * or not a page is included in the menu. |
|
1238 * |
|
1239 * The function which is hooked in to handle the output of the page must check |
|
1240 * that the user has the required capability as well. |
|
1241 * |
|
1242 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
1243 * @param string $menu_title The text to be used for the menu |
|
1244 * @param string $capability The capability required for this menu to be displayed to the user. |
|
1245 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
1246 * @param callback $function The function to be called to output the content for this page. |
|
1247 * |
|
1248 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
1249 */ |
|
1250 function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1251 return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1252 } |
|
1253 |
|
1254 /** |
|
1255 * Add sub menu page to the comments main menu. |
|
1256 * |
|
1257 * This function takes a capability which will be used to determine whether |
|
1258 * or not a page is included in the menu. |
|
1259 * |
|
1260 * The function which is hooked in to handle the output of the page must check |
|
1261 * that the user has the required capability as well. |
|
1262 * |
|
1263 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected |
|
1264 * @param string $menu_title The text to be used for the menu |
|
1265 * @param string $capability The capability required for this menu to be displayed to the user. |
|
1266 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
1267 * @param callback $function The function to be called to output the content for this page. |
|
1268 * |
|
1269 * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
1270 */ |
|
1271 function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { |
|
1272 return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function ); |
|
1273 } |
|
1274 |
|
1275 /** |
|
1276 * Remove a top level admin menu |
|
1277 * |
|
1278 * @since 3.1.0 |
|
1279 * |
|
1280 * @param string $menu_slug The slug of the menu |
|
1281 * @return array|bool The removed menu on success, False if not found |
|
1282 */ |
|
1283 function remove_menu_page( $menu_slug ) { |
|
1284 global $menu; |
|
1285 |
|
1286 foreach ( $menu as $i => $item ) { |
|
1287 if ( $menu_slug == $item[2] ) { |
|
1288 unset( $menu[$i] ); |
|
1289 return $item; |
|
1290 } |
|
1291 } |
|
1292 |
|
1293 return false; |
|
1294 } |
|
1295 |
|
1296 /** |
|
1297 * Remove an admin submenu |
|
1298 * |
|
1299 * @since 3.1.0 |
|
1300 * |
|
1301 * @param string $menu_slug The slug for the parent menu |
|
1302 * @param string $submenu_slug The slug of the submenu |
|
1303 * @return array|bool The removed submenu on success, False if not found |
|
1304 */ |
|
1305 function remove_submenu_page( $menu_slug, $submenu_slug ) { |
|
1306 global $submenu; |
|
1307 |
|
1308 if ( !isset( $submenu[$menu_slug] ) ) |
|
1309 return false; |
|
1310 |
|
1311 foreach ( $submenu[$menu_slug] as $i => $item ) { |
|
1312 if ( $submenu_slug == $item[2] ) { |
|
1313 unset( $submenu[$menu_slug][$i] ); |
|
1314 return $item; |
|
1315 } |
|
1316 } |
|
1317 |
|
1318 return false; |
|
1319 } |
|
1320 |
|
1321 /** |
|
1322 * Get the url to access a particular menu page based on the slug it was registered with. |
|
1323 * |
|
1324 * If the slug hasn't been registered properly no url will be returned |
|
1325 * |
|
1326 * @since 3.0 |
|
1327 * |
|
1328 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) |
|
1329 * @param bool $echo Whether or not to echo the url - default is true |
|
1330 * @return string the url |
|
1331 */ |
|
1332 function menu_page_url($menu_slug, $echo = true) { |
|
1333 global $_parent_pages; |
|
1334 |
|
1335 if ( isset( $_parent_pages[$menu_slug] ) ) { |
|
1336 $parent_slug = $_parent_pages[$menu_slug]; |
|
1337 if ( $parent_slug && ! isset( $_parent_pages[$parent_slug] ) ) { |
|
1338 $url = admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) ); |
|
1339 } else { |
|
1340 $url = admin_url( 'admin.php?page=' . $menu_slug ); |
|
1341 } |
|
1342 } else { |
|
1343 $url = ''; |
|
1344 } |
|
1345 |
|
1346 $url = esc_url($url); |
|
1347 |
|
1348 if ( $echo ) |
|
1349 echo $url; |
|
1350 |
|
1351 return $url; |
727 } |
1352 } |
728 |
1353 |
729 // |
1354 // |
730 // Pluggable Menu Support -- Private |
1355 // Pluggable Menu Support -- Private |
731 // |
1356 // |