Make WordPress Core

Ticket #45197: 45197.diff

File 45197.diff, 1.1 KB (added by tmanoilov, 7 years ago)
  • src/wp-includes/capabilities.php

    diff --git a/src/wp-includes/capabilities.php b/src/wp-includes/capabilities.php
    index 375648e768..ba722f8f06 100644
    a b function current_user_can_for_blog( $blog_id, $capability ) { 
    659659        return $can;
    660660}
    661661
     662/**
     663 * Whether a particular user has a specific capability for a given site.
     664 *
     665 *
     666 * @param int|WP_User $user       User ID or object.
     667 * @param string      $capability Capability name.
     668 * @return bool Whether the user has the given capability.
     669 */
     670function user_can_for_blog( $user, $blog_id, $capability ) {
     671        if ( ! is_object( $user ) ) {
     672                $user = get_userdata( $user );
     673        }
     674
     675        if ( ! $user || ! $user->exists() ) {
     676                return false;
     677        }
     678
     679        $switched = is_multisite() ? switch_to_blog( $blog_id ) : false;
     680
     681        $args = array_slice( func_get_args(), 2 );
     682        $args = array_merge( array( $capability ), $args );
     683
     684        $can = call_user_func_array( array( $user, 'has_cap' ), $args );
     685
     686        if ( $switched ) {
     687                restore_current_blog();
     688        }
     689
     690        return $can;
     691}
     692
    662693/**
    663694 * Whether the author of the supplied post has a specific capability.
    664695 *