Docs: Standardise documentation for capability-related variadic functions.
See #37402 git-svn-id: https://develop.svn.wordpress.org/trunk@45419 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b64f812a59
commit
51ab0b5824
@ -7,7 +7,17 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Map meta capabilities to primitive capabilities.
|
||||
* Maps meta capabilities to primitive capabilities.
|
||||
*
|
||||
* This function also accepts an ID of an object to map against if the capability is a meta capability. Meta
|
||||
* capabilities such as `edit_post` and `edit_user` are capabilities used by this function to map to primitive
|
||||
* capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* map_meta_cap( 'edit_posts', $user->ID );
|
||||
* map_meta_cap( 'edit_post', $user->ID, $post->ID );
|
||||
* map_meta_cap( 'edit_post_meta', $user->ID, $post->ID, $meta_key );
|
||||
*
|
||||
* This does not actually compare whether the user ID has the actual capability,
|
||||
* just what the capability or capabilities are. Meta capability list value can
|
||||
@ -20,10 +30,7 @@
|
||||
*
|
||||
* @param string $cap Capability name.
|
||||
* @param int $user_id User ID.
|
||||
* @param int $object_id Optional. ID of the specific object to check against if `$cap` is a "meta" cap.
|
||||
* "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used
|
||||
* by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts',
|
||||
* 'edit_others_posts', etc. The parameter is accessed via func_get_args().
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return array Actual capabilities for meta capability.
|
||||
*/
|
||||
function map_meta_cap( $cap, $user_id ) {
|
||||
@ -615,7 +622,17 @@ function map_meta_cap( $cap, $user_id ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the current user has a specific capability.
|
||||
* Returns whether the current user has the specified capability.
|
||||
*
|
||||
* This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
|
||||
* capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
|
||||
* map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* current_user_can( 'edit_posts' );
|
||||
* current_user_can( 'edit_post', $post->ID );
|
||||
* current_user_can( 'edit_post_meta', $post->ID, $meta_key );
|
||||
*
|
||||
* While checking against particular roles in place of a capability is supported
|
||||
* in part, this practice is discouraged as it may produce unreliable results.
|
||||
@ -628,11 +645,7 @@ function map_meta_cap( $cap, $user_id ) {
|
||||
* @see map_meta_cap()
|
||||
*
|
||||
* @param string $capability Capability name.
|
||||
* @param int $object_id Optional. ID of the specific object to check against if `$capability` is a "meta" cap.
|
||||
* "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used
|
||||
* by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts',
|
||||
* 'edit_others_posts', etc. Accessed via func_get_args() and passed to WP_User::has_cap(),
|
||||
* then map_meta_cap().
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return bool Whether the current user has the given capability. If `$capability` is a meta cap and `$object_id` is
|
||||
* passed, whether the current user has the given meta capability for the given object.
|
||||
*/
|
||||
@ -650,12 +663,23 @@ function current_user_can( $capability ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the current user has a specific capability for a given site.
|
||||
* Returns whether the current user has the specified capability for a given site.
|
||||
*
|
||||
* This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
|
||||
* capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
|
||||
* map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* current_user_can_for_blog( $blog_id, 'edit_posts' );
|
||||
* current_user_can_for_blog( $blog_id, 'edit_post', $post->ID );
|
||||
* current_user_can_for_blog( $blog_id, 'edit_post_meta', $post->ID, $meta_key );
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param int $blog_id Site ID.
|
||||
* @param string $capability Capability name.
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return bool Whether the user has the given capability.
|
||||
*/
|
||||
function current_user_can_for_blog( $blog_id, $capability ) {
|
||||
@ -683,12 +707,23 @@ function current_user_can_for_blog( $blog_id, $capability ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the author of the supplied post has a specific capability.
|
||||
* Returns whether the author of the supplied post has the specified capability.
|
||||
*
|
||||
* This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
|
||||
* capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
|
||||
* map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* author_can( $post, 'edit_posts' );
|
||||
* author_can( $post, 'edit_post', $post->ID );
|
||||
* author_can( $post, 'edit_post_meta', $post->ID, $meta_key );
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @param int|WP_Post $post Post ID or post object.
|
||||
* @param string $capability Capability name.
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return bool Whether the post author has the given capability.
|
||||
*/
|
||||
function author_can( $post, $capability ) {
|
||||
@ -709,12 +744,23 @@ function author_can( $post, $capability ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a particular user has a specific capability.
|
||||
* Returns whether a particular user has the specified capability.
|
||||
*
|
||||
* This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
|
||||
* capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
|
||||
* map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* user_can( $user->ID, 'edit_posts' );
|
||||
* user_can( $user->ID, 'edit_post', $post->ID );
|
||||
* user_can( $user->ID, 'edit_post_meta', $post->ID, $meta_key );
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param int|WP_User $user User ID or object.
|
||||
* @param string $capability Capability name.
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return bool Whether the user has the given capability.
|
||||
*/
|
||||
function user_can( $user, $capability ) {
|
||||
|
@ -712,7 +712,17 @@ class WP_User {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the user has a specific capability.
|
||||
* Returns whether the user has the specified capability.
|
||||
*
|
||||
* This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
|
||||
* capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
|
||||
* map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* $user->has_cap( 'edit_posts' );
|
||||
* $user->has_cap( 'edit_post', $post->ID );
|
||||
* $user->has_cap( 'edit_post_meta', $post->ID, $meta_key );
|
||||
*
|
||||
* While checking against a role in place of a capability is supported in part, this practice is discouraged as it
|
||||
* may produce unreliable results.
|
||||
@ -722,11 +732,8 @@ class WP_User {
|
||||
* @see map_meta_cap()
|
||||
*
|
||||
* @param string $cap Capability name.
|
||||
* @param int ...$object_id Optional. ID of a specific object to check against if `$cap` is a "meta" capability.
|
||||
* Meta capabilities such as `edit_post` and `edit_user` are capabilities used by
|
||||
* by the `map_meta_cap()` function to map to primitive capabilities that a user or
|
||||
* role has, such as `edit_posts` and `edit_others_posts`.
|
||||
* @return bool Whether the user has the given capability, or, if `$object_id` is passed, whether the user has
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return bool Whether the user has the given capability, or, if an object ID is passed, whether the user has
|
||||
* the given capability for that object.
|
||||
*/
|
||||
public function has_cap( $cap ) {
|
||||
|
Loading…
Reference in New Issue
Block a user