WordPress.org

Make WordPress Core

Ticket #14602: user_can.diff

File user_can.diff, 1.6 KB (added by simonwheatley, 9 years ago)

Now using ! is_object() instead of is_int

  • wp-includes/capabilities.php

     
    10611061        if ( empty( $current_user ) )
    10621062                return false;
    10631063
    1064         $args = array_slice( func_get_args(), 1 );
    1065         $args = array_merge( array( $capability ), $args );
    1066 
    1067         return call_user_func_array( array( &$current_user, 'has_cap' ), $args );
     1064        return user_can( $current_user, $capability );
    10681065}
    10691066
    10701067/**
     
    10911088        // Set the blog id.  @todo add blog id arg to WP_User constructor?
    10921089        $user->for_blog( $blog_id );
    10931090
    1094         $args = array_slice( func_get_args(), 2 );
    1095         $args = array_merge( array( $capability ), $args );
    1096 
    1097         return call_user_func_array( array( &$user, 'has_cap' ), $args );
     1091        return user_can( $user, $capability );
    10981092}
    10991093
    11001094/**
     
    11101104        if ( !$post = get_post($post) )
    11111105                return false;
    11121106
    1113         $author = new WP_User( $post->post_author );
     1107        return user_can( $post->post_author, $capability );
     1108}
    11141109
    1115         if ( empty( $author->ID ) )
     1110/**
     1111 * Whether a user has capability or role.
     1112 *
     1113 * @param int|object $user The ID for a user or a WP_User object
     1114 * @param string $capability Capability or role name.
     1115 * @return bool
     1116 **/
     1117function user_can( $user, $capability ) {
     1118        if ( ! is_object( $user ) )
     1119                $user = new WP_User( $user );
     1120               
     1121        if ( ! $user || ! $user->ID )
    11161122                return false;
    1117 
     1123       
    11181124        $args = array_slice( func_get_args(), 2 );
    11191125        $args = array_merge( array( $capability ), $args );
    11201126
    1121         return call_user_func_array( array( &$author, 'has_cap' ), $args );
     1127        return call_user_func_array( array( &$user, 'has_cap' ), $args );
    11221128}
    11231129
    11241130/**