Make WordPress Core

Changeset 45419


Ignore:
Timestamp:
05/25/2019 10:26:22 PM (5 years ago)
Author:
johnbillion
Message:

Docs: Standardise documentation for capability-related variadic functions.

See #37402

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

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

    r44976 r45419  
    88
    99/**
    10  * Map meta capabilities to primitive capabilities.
     10 * Maps meta capabilities to primitive capabilities.
     11 *
     12 * This function also accepts an ID of an object to map against if the capability is a meta capability. Meta
     13 * capabilities such as `edit_post` and `edit_user` are capabilities used by this function to map to primitive
     14 * capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
     15 *
     16 * Example usage:
     17 *
     18 *     map_meta_cap( 'edit_posts', $user->ID );
     19 *     map_meta_cap( 'edit_post', $user->ID, $post->ID );
     20 *     map_meta_cap( 'edit_post_meta', $user->ID, $post->ID, $meta_key );
    1121 *
    1222 * This does not actually compare whether the user ID has the actual capability,
     
    1929 * @global array $post_type_meta_caps Used to get post type meta capabilities.
    2030 *
    21  * @param string $cap       Capability name.
    22  * @param int    $user_id   User ID.
    23  * @param int    $object_id Optional. ID of the specific object to check against if `$cap` is a "meta" cap.
    24  *                          "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used
    25  *                          by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts',
    26  *                          'edit_others_posts', etc. The parameter is accessed via func_get_args().
     31 * @param string $cap     Capability name.
     32 * @param int    $user_id User ID.
     33 * @param mixed  ...$args Optional further parameters, typically starting with an object ID.
    2734 * @return array Actual capabilities for meta capability.
    2835 */
     
    616623
    617624/**
    618  * Whether the current user has a specific capability.
     625 * Returns whether the current user has the specified capability.
     626 *
     627 * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
     628 * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
     629 * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
     630 *
     631 * Example usage:
     632 *
     633 *     current_user_can( 'edit_posts' );
     634 *     current_user_can( 'edit_post', $post->ID );
     635 *     current_user_can( 'edit_post_meta', $post->ID, $meta_key );
    619636 *
    620637 * While checking against particular roles in place of a capability is supported
     
    629646 *
    630647 * @param string $capability Capability name.
    631  * @param int    $object_id  Optional. ID of the specific object to check against if `$capability` is a "meta" cap.
    632  *                           "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used
    633  *                           by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts',
    634  *                           'edit_others_posts', etc. Accessed via func_get_args() and passed to WP_User::has_cap(),
    635  *                           then map_meta_cap().
     648 * @param mixed  ...$args    Optional further parameters, typically starting with an object ID.
    636649 * @return bool Whether the current user has the given capability. If `$capability` is a meta cap and `$object_id` is
    637650 *              passed, whether the current user has the given meta capability for the given object.
     
    651664
    652665/**
    653  * Whether the current user has a specific capability for a given site.
     666 * Returns whether the current user has the specified capability for a given site.
     667 *
     668 * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
     669 * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
     670 * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
     671 *
     672 * Example usage:
     673 *
     674 *     current_user_can_for_blog( $blog_id, 'edit_posts' );
     675 *     current_user_can_for_blog( $blog_id, 'edit_post', $post->ID );
     676 *     current_user_can_for_blog( $blog_id, 'edit_post_meta', $post->ID, $meta_key );
    654677 *
    655678 * @since 3.0.0
     
    657680 * @param int    $blog_id    Site ID.
    658681 * @param string $capability Capability name.
     682 * @param mixed  ...$args    Optional further parameters, typically starting with an object ID.
    659683 * @return bool Whether the user has the given capability.
    660684 */
     
    684708
    685709/**
    686  * Whether the author of the supplied post has a specific capability.
     710 * Returns whether the author of the supplied post has the specified capability.
     711 *
     712 * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
     713 * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
     714 * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
     715 *
     716 * Example usage:
     717 *
     718 *     author_can( $post, 'edit_posts' );
     719 *     author_can( $post, 'edit_post', $post->ID );
     720 *     author_can( $post, 'edit_post_meta', $post->ID, $meta_key );
    687721 *
    688722 * @since 2.9.0
     
    690724 * @param int|WP_Post $post       Post ID or post object.
    691725 * @param string      $capability Capability name.
     726 * @param mixed       ...$args    Optional further parameters, typically starting with an object ID.
    692727 * @return bool Whether the post author has the given capability.
    693728 */
     
    710745
    711746/**
    712  * Whether a particular user has a specific capability.
     747 * Returns whether a particular user has the specified capability.
     748 *
     749 * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
     750 * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
     751 * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
     752 *
     753 * Example usage:
     754 *
     755 *     user_can( $user->ID, 'edit_posts' );
     756 *     user_can( $user->ID, 'edit_post', $post->ID );
     757 *     user_can( $user->ID, 'edit_post_meta', $post->ID, $meta_key );
    713758 *
    714759 * @since 3.1.0
     
    716761 * @param int|WP_User $user       User ID or object.
    717762 * @param string      $capability Capability name.
     763 * @param mixed       ...$args    Optional further parameters, typically starting with an object ID.
    718764 * @return bool Whether the user has the given capability.
    719765 */
  • trunk/src/wp-includes/class-wp-user.php

    r45418 r45419  
    713713
    714714    /**
    715      * Whether the user has a specific capability.
     715     * Returns whether the user has the specified capability.
     716     *
     717     * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
     718     * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
     719     * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
     720     *
     721     * Example usage:
     722     *
     723     *     $user->has_cap( 'edit_posts' );
     724     *     $user->has_cap( 'edit_post', $post->ID );
     725     *     $user->has_cap( 'edit_post_meta', $post->ID, $meta_key );
    716726     *
    717727     * While checking against a role in place of a capability is supported in part, this practice is discouraged as it
     
    722732     * @see map_meta_cap()
    723733     *
    724      * @param string $cap          Capability name.
    725      * @param int    ...$object_id Optional. ID of a specific object to check against if `$cap` is a "meta" capability.
    726      *                             Meta capabilities such as `edit_post` and `edit_user` are capabilities used by
    727      *                             by the `map_meta_cap()` function to map to primitive capabilities that a user or
    728      *                             role has, such as `edit_posts` and `edit_others_posts`.
    729      * @return bool Whether the user has the given capability, or, if `$object_id` is passed, whether the user has
     734     * @param string $cap     Capability name.
     735     * @param mixed  ...$args Optional further parameters, typically starting with an object ID.
     736     * @return bool Whether the user has the given capability, or, if an object ID is passed, whether the user has
    730737     *              the given capability for that object.
    731738     */
Note: See TracChangeset for help on using the changeset viewer.