WordPress.org

Make WordPress Core

Changeset 27670


Ignore:
Timestamp:
03/24/2014 02:34:14 AM (8 years ago)
Author:
DrewAPicture
Message:

Inline documentation for hooks in wp-admin/includes/menu.php.

Also fixes syntax for a few unrelated multi-line comments in the file.

Props kpdesign for some minor cleanup.
Fixes #27430.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/menu.php

    r24455 r27670  
    11<?php
    2 
    32/**
    43 * Build Administration Menu.
     
    87 */
    98
    10 if ( is_network_admin() )
    11     do_action('_network_admin_menu');
    12 elseif ( is_user_admin() )
    13     do_action('_user_admin_menu');
    14 else
    15     do_action('_admin_menu');
     9if ( is_network_admin() ) {
     10
     11    /**
     12     * Fires before the administration menu loads in the Network Admin.
     13     *
     14     * The hook fires before menus and sub-menus are removed based on user privileges.
     15     *
     16     * @private
     17     * @since 3.1.0
     18     */
     19    do_action( '_network_admin_menu' );
     20} elseif ( is_user_admin() ) {
     21
     22    /**
     23     * Fires before the administration menu loads in the User Admin.
     24     *
     25     * The hook fires before menus and sub-menus are removed based on user privileges.
     26     *
     27     * @private
     28     * @since 3.1.0
     29     */
     30    do_action( '_user_admin_menu' );
     31} else {
     32
     33    /**
     34     * Fires before the administration menu loads in the admin.
     35     *
     36     * The hook fires before menus and sub-menus are removed based on user privileges.
     37     *
     38     * @private
     39     * @since 2.2.0
     40     */
     41    do_action( '_admin_menu' );
     42}
    1643
    1744// Create list of page plugin hook names.
     
    6289unset($sub_loop);
    6390
    64 // Loop over the top-level menu.
    65 // Menus for which the original parent is not accessible due to lack of privs will have the next
    66 // submenu in line be assigned as the new menu parent.
     91/*
     92 * Loop over the top-level menu.
     93 * Menus for which the original parent is not accessible due to lack of privileges
     94 * will have the next submenu in line be assigned as the new menu parent.
     95 */
    6796foreach ( $menu as $id => $data ) {
    6897    if ( empty($submenu[$data[2]]) )
     
    90119unset($id, $data, $subs, $first_sub, $old_parent, $new_parent);
    91120
    92 if ( is_network_admin() )
    93     do_action('network_admin_menu', '');
    94 elseif ( is_user_admin() )
    95     do_action('user_admin_menu', '');
    96 else
    97     do_action('admin_menu', '');
    98 
    99 // Remove menus that have no accessible submenus and require privs that the user does not have.
    100 // Run re-parent loop again.
     121if ( is_network_admin() ) {
     122
     123    /**
     124     * Fires before the administration menu loads in the Network Admin.
     125     *
     126     * @since 3.1.0
     127     *
     128     * @param string $context Empty context.
     129     */
     130    do_action( 'network_admin_menu', '' );
     131} elseif ( is_user_admin() ) {
     132
     133    /**
     134     * Fires before the administration menu loads in the User Admin.
     135     *
     136     * @since 3.1.0
     137     *
     138     * @param string $context Empty context.
     139     */
     140    do_action( 'user_admin_menu', '' );
     141} else {
     142
     143    /**
     144     * Fires before the administration menu loads in the admin.
     145     *
     146     * @since 1.5.0
     147     *
     148     * @param string $context Empty context.
     149     */
     150    do_action( 'admin_menu', '' );
     151}
     152
     153/*
     154 * Remove menus that have no accessible submenus and require privileges
     155 * that the user does not have. Run re-parent loop again.
     156 */
    101157foreach ( $menu as $id => $data ) {
    102158    if ( ! current_user_can($data[1]) )
    103159        $_wp_menu_nopriv[$data[2]] = true;
    104160
    105     // If there is only one submenu and it is has same destination as the parent,
    106     // remove the submenu.
     161    /*
     162     * If there is only one submenu and it is has same destination as the parent,
     163     * remove the submenu.
     164     */
    107165    if ( ! empty( $submenu[$data[2]] ) && 1 == count ( $submenu[$data[2]] ) ) {
    108166        $subs = $submenu[$data[2]];
     
    178236    }
    179237
     238    /**
     239     * Filter administration menus array with classes added for top-level items.
     240     *
     241     * @since 2.7.0
     242     *
     243     * @param array $menu Associative array of administration menu items.
     244     */
    180245    return apply_filters( 'add_menu_classes', $menu );
    181246}
     
    183248uksort($menu, "strnatcasecmp"); // make it all pretty
    184249
    185 if ( apply_filters('custom_menu_order', false) ) {
     250/**
     251 * Filter whether to enable custom ordering of the administration menu.
     252 *
     253 * See the 'menu_order' filter for reordering menu items.
     254 *
     255 * @since 2.8.0
     256 *
     257 * @param bool $custom Whether custom ordering is enabled. Default false.
     258 */
     259if ( apply_filters( 'custom_menu_order', false ) ) {
     260    log_it( 'false is true' );
    186261    $menu_order = array();
    187262    foreach ( $menu as $menu_item ) {
     
    190265    unset($menu_item);
    191266    $default_menu_order = $menu_order;
    192     $menu_order = apply_filters('menu_order', $menu_order);
     267
     268    /**
     269     * Filter the order of administration menu items.
     270     *
     271     * A truthy value must first be passed to the 'custom_menu_order' filter
     272     * for this filter to work. Use the following to enable custom menu ordering:
     273     *
     274     *     add_filter( 'custom_menu_order', '__return_true' );
     275     *
     276     * @since 2.8.0
     277     *
     278     * @param array $menu_order An ordered array of menu items.
     279     */
     280    $menu_order = apply_filters( 'menu_order', $menu_order );
    193281    $menu_order = array_flip($menu_order);
    194282    $default_menu_order = array_flip($default_menu_order);
     
    223311
    224312if ( !user_can_access_admin_page() ) {
    225     do_action('admin_page_access_denied');
     313
     314    /**
     315     * Fires when access to an admin page is denied.
     316     *
     317     * @since 2.5.0
     318     */
     319    do_action( 'admin_page_access_denied' );
     320
    226321    wp_die( __('You do not have sufficient permissions to access this page.') );
    227322}
Note: See TracChangeset for help on using the changeset viewer.