Make WordPress Core

Changeset 15891


Ignore:
Timestamp:
10/21/2010 02:55:15 PM (14 years ago)
Author:
nacin
Message:

Only check the post author if the post type supports authors. see #14122.

File:
1 edited

Legend:

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

    r15890 r15891  
    820820    case 'delete_page':
    821821        $author_data = get_userdata( $user_id );
    822         //echo "post ID: {$args[0]}<br />";
    823822        $post = get_post( $args[0] );
    824823        $post_type = get_post_type_object( $post->post_type );
     824
    825825        if ( 'delete_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) {
    826826            $args = array_merge( array( $post_type->cap->delete_post, $user_id ), $args );
     
    828828        }
    829829
    830         if ( '' != $post->post_author ) {
     830        if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) {
    831831            $post_author_data = get_userdata( $post->post_author );
    832832        } else {
    833             //No author set yet so default to current user for cap checks
     833            // No author set yet or post type doesn't support authors,
     834            // so default to current user for cap checks.
    834835            $post_author_data = $author_data;
    835836        }
     
    862863    case 'edit_page':
    863864        $author_data = get_userdata( $user_id );
    864         //echo "post ID: {$args[0]}<br />";
    865865        $post = get_post( $args[0] );
    866 
    867866        $post_type = get_post_type_object( $post->post_type );
     867
    868868        if ( 'edit_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) {
    869869            $args = array_merge( array( $post_type->cap->edit_post, $user_id ), $args );
    870870            return call_user_func_array( 'map_meta_cap', $args );
    871871        }
    872         $post_author_data = get_userdata( $post->post_author );
     872
     873        if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) {
     874            $post_author_data = get_userdata( $post->post_author );
     875        } else {
     876            // No author set yet or post type doesn't support authors,
     877            // so default to current user for cap checks.
     878            $post_author_data = $author_data;
     879        }
     880
    873881        //echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br />";
    874882        // If the user is the author...
     
    896904    case 'read_post':
    897905    case 'read_page':
     906        $author_data = get_userdata( $user_id );
    898907        $post = get_post( $args[0] );
    899908        $post_type = get_post_type_object( $post->post_type );
     909
    900910        if ( 'read_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) {
    901911            $args = array_merge( array( $post_type->cap->read_post, $user_id ), $args );
     
    908918        }
    909919
    910         $author_data = get_userdata( $user_id );
    911         $post_author_data = get_userdata( $post->post_author );
     920        if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) {
     921            $post_author_data = get_userdata( $post->post_author );
     922        } else {
     923            // No author set yet or post type doesn't support authors,
     924            // so default to current user for cap checks.
     925            $post_author_data = $author_data;
     926        }
     927
    912928        if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID )
    913929            $caps[] = $post_type->cap->read;
Note: See TracChangeset for help on using the changeset viewer.