Changeset 59198 for trunk/src/wp-includes/capabilities.php
- Timestamp:
- 10/08/2024 10:30:57 PM (16 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/capabilities.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/capabilities.php
r59125 r59198 914 914 * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`. 915 915 * 916 * This function replaces the current_user_can_for_blog() function. 917 * 916 918 * Example usage: 917 919 * 918 * current_user_can_for_blog( $blog_id, 'edit_posts' ); 919 * current_user_can_for_blog( $blog_id, 'edit_post', $post->ID ); 920 * current_user_can_for_blog( $blog_id, 'edit_post_meta', $post->ID, $meta_key ); 921 * 922 * @since 3.0.0 923 * @since 5.3.0 Formalized the existing and already documented `...$args` parameter 924 * by adding it to the function signature. 925 * @since 5.8.0 Wraps current_user_can() after switching to blog. 926 * 927 * @param int $blog_id Site ID. 920 * current_user_can_for_site( $site_id, 'edit_posts' ); 921 * current_user_can_for_site( $site_id, 'edit_post', $post->ID ); 922 * current_user_can_for_site( $site_id, 'edit_post_meta', $post->ID, $meta_key ); 923 * 924 * @since 6.7.0 925 * 926 * @param int $site_id Site ID. 928 927 * @param string $capability Capability name. 929 928 * @param mixed ...$args Optional further parameters, typically starting with an object ID. 930 929 * @return bool Whether the user has the given capability. 931 930 */ 932 function current_user_can_for_ blog( $blog_id, $capability, ...$args ) {933 $switched = is_multisite() ? switch_to_blog( $ blog_id ) : false;931 function current_user_can_for_site( $site_id, $capability, ...$args ) { 932 $switched = is_multisite() ? switch_to_blog( $site_id ) : false; 934 933 935 934 $can = current_user_can( $capability, ...$args ); … … 1024 1023 * Example usage: 1025 1024 * 1026 * user_can_for_ blog( $user->ID, $blog_id, 'edit_posts' );1027 * user_can_for_ blog( $user->ID, $blog_id, 'edit_post', $post->ID );1028 * user_can_for_ blog( $user->ID, $blog_id, 'edit_post_meta', $post->ID, $meta_key );1025 * user_can_for_site( $user->ID, $site_id, 'edit_posts' ); 1026 * user_can_for_site( $user->ID, $site_id, 'edit_post', $post->ID ); 1027 * user_can_for_site( $user->ID, $site_id, 'edit_post_meta', $post->ID, $meta_key ); 1029 1028 * 1030 1029 * @since 6.7.0 1031 1030 * 1032 1031 * @param int|WP_User $user User ID or object. 1033 * @param int $ blog_id Site ID.1032 * @param int $site_id Site ID. 1034 1033 * @param string $capability Capability name. 1035 1034 * @param mixed ...$args Optional further parameters, typically starting with an object ID. 1036 1035 * @return bool Whether the user has the given capability. 1037 1036 */ 1038 function user_can_for_ blog( $user, $blog_id, $capability, ...$args ) {1037 function user_can_for_site( $user, $site_id, $capability, ...$args ) { 1039 1038 if ( ! is_object( $user ) ) { 1040 1039 $user = get_userdata( $user ); … … 1048 1047 1049 1048 // Check if the blog ID is valid. 1050 if ( ! is_numeric( $ blog_id ) || $blog_id <= 0 ) {1049 if ( ! is_numeric( $site_id ) || $site_id <= 0 ) { 1051 1050 return false; 1052 1051 } 1053 1052 1054 $switched = is_multisite() ? switch_to_blog( $ blog_id ) : false;1053 $switched = is_multisite() ? switch_to_blog( $site_id ) : false; 1055 1054 1056 1055 $can = user_can( $user->ID, $capability, ...$args );
Note: See TracChangeset
for help on using the changeset viewer.