Make WordPress Core

Changeset 34224


Ignore:
Timestamp:
09/16/2015 07:35:37 AM (9 years ago)
Author:
DrewAPicture
Message:

Docs: Add documentation for $object_id, the optional second parameter in current_user_can() and WP_User::has_cap(), and the optional third parameter in map_meta_cap().

This change introduces the vernacular of "meta" vs "primitive" capabilities to core docs, and providing examples for each inline and attempts to make it clear that $object_id is really only useful if the passed $capability is of the meta cap variety.

Props jliman for the initial patch.
Fixes #32694.

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

Legend:

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

    r34113 r34224  
    1717 * @since 2.0.0
    1818 *
    19  * @param string $cap Capability name.
    20  * @param int $user_id User ID.
     19 * @param string $cap       Capability name.
     20 * @param int    $user_id   User ID.
     21 * @param int    $object_id Optional. ID of the specific object to check against if `$cap` is a "meta" cap.
     22 *                          "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used
     23 *                          by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts',
     24 *                          'edit_others_posts', etc. The parameter is accessed via func_get_args().
    2125 * @return array Actual capabilities for meta capability.
    2226 */
     
    391395
    392396/**
    393  * Whether current user has capability or role.
     397 * Whether the current user has a specific capability.
     398 *
     399 * While checking against particular roles in place of a capability is supported
     400 * in part, this practice is discouraged as it may produce unreliable results.
    394401 *
    395402 * @since 2.0.0
    396403 *
    397  * @param string $capability Capability or role name.
    398  * @return bool
     404 * @see WP_User::has_cap()
     405 * @see map_meta_cap()
     406 *
     407 * @param string $capability Capability name.
     408 * @param int    $object_id  Optional. ID of the specific object to check against if `$capability` is a "meta" cap.
     409 *                           "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used
     410 *                           by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts',
     411 *                           'edit_others_posts', etc. Accessed via func_get_args() and passed to WP_User::has_cap(),
     412 *                           then map_meta_cap().
     413 * @return bool Whether the current user has the given capability. If `$capability` is a meta cap and `$object_id` is
     414 *              passed, whether the current user has the given meta capability for the given object.
    399415 */
    400416function current_user_can( $capability ) {
  • trunk/src/wp-includes/class-wp-user.php

    r34125 r34224  
    635635     * Whether user has capability or role name.
    636636     *
    637      * This is useful for looking up whether the user has a specific role
    638      * assigned to the user. The second optional parameter can also be used to
    639      * check for capabilities against a specific object, such as a post or user.
    640      *
    641      * @since 2.0.0
    642      * @access public
    643      *
    644      * @param string|int $cap Capability or role name to search.
    645      * @return bool True, if user has capability; false, if user does not have capability.
     637     * While checking against particular roles in place of a capability is supported
     638     * in part, this practice is discouraged as it may produce unreliable results.
     639     *
     640     * @since 2.0.0
     641     * @access public
     642     *
     643     * @see map_meta_cap()
     644     *
     645     * @param string $cap       Capability name.
     646     * @param int    $object_id Optional. ID of the specific object to check against if `$cap` is a "meta" cap.
     647     *                          "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used
     648     *                          by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts',
     649     *                          'edit_others_posts', etc. The parameter is accessed via func_get_args() and passed
     650     *                          to map_meta_cap().
     651     * @return bool Whether the current user has the given capability. If `$cap` is a meta cap and `$object_id` is
     652     *              passed, whether the current user has the given meta capability for the given object.
    646653     */
    647654    public function has_cap( $cap ) {
Note: See TracChangeset for help on using the changeset viewer.