Make WordPress Core


Ignore:
Timestamp:
03/04/2014 03:08:54 AM (12 years ago)
Author:
nacin
Message:

Don't default to current user for capability checks when dealing with a post without an author (post_author = 0).

Undoes [12053]. While it risks breakage, this is a far safer and saner default for these situations.

props danielbachhuber.
fixes #27020.

File:
1 edited

Legend:

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

    r26126 r27390  
    10721072                }
    10731073
    1074                 $post_author_id = $post->post_author;
    1075 
    1076                 // If no author set yet, default to current user for cap checks.
    1077                 if ( ! $post_author_id )
    1078                         $post_author_id = $user_id;
    1079 
    1080                 // If the user is the author...
    1081                 if ( $user_id == $post_author_id ) {
     1074                // If the post author is set and the user is the author...
     1075                if ( $post->post_author && $user_id == $post->post_author ) {
    10821076                        // If the post is published...
    10831077                        if ( 'publish' == $post->post_status ) {
    10841078                                $caps[] = $post_type->cap->delete_published_posts;
    10851079                        } elseif ( 'trash' == $post->post_status ) {
    1086                                 if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
     1080                                if ( 'publish' == get_post_meta( $post->ID, '_wp_trash_meta_status', true ) ) {
    10871081                                        $caps[] = $post_type->cap->delete_published_posts;
     1082                                }
    10881083                        } else {
    10891084                                // If the post is draft...
     
    10941089                        $caps[] = $post_type->cap->delete_others_posts;
    10951090                        // The post is published, extra cap required.
    1096                         if ( 'publish' == $post->post_status )
     1091                        if ( 'publish' == $post->post_status ) {
    10971092                                $caps[] = $post_type->cap->delete_published_posts;
    1098                         elseif ( 'private' == $post->post_status )
     1093                        } elseif ( 'private' == $post->post_status ) {
    10991094                                $caps[] = $post_type->cap->delete_private_posts;
     1095                        }
    11001096                }
    11011097                break;
     
    11221118                }
    11231119
    1124                 $post_author_id = $post->post_author;
    1125 
    1126                 // If no author set yet, default to current user for cap checks.
    1127                 if ( ! $post_author_id )
    1128                         $post_author_id = $user_id;
    1129 
    1130                 // If the user is the author...
    1131                 if ( $user_id == $post_author_id ) {
     1120                // If the post author is set and the user is the author...
     1121                if ( $post->post_author && $user_id == $post->post_author ) {
    11321122                        // If the post is published...
    11331123                        if ( 'publish' == $post->post_status ) {
    11341124                                $caps[] = $post_type->cap->edit_published_posts;
    11351125                        } elseif ( 'trash' == $post->post_status ) {
    1136                                 if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
     1126                                if ( 'publish' == get_post_meta( $post->ID, '_wp_trash_meta_status', true ) ) {
    11371127                                        $caps[] = $post_type->cap->edit_published_posts;
     1128                                }
    11381129                        } else {
    11391130                                // If the post is draft...
     
    11441135                        $caps[] = $post_type->cap->edit_others_posts;
    11451136                        // The post is published, extra cap required.
    1146                         if ( 'publish' == $post->post_status )
     1137                        if ( 'publish' == $post->post_status ) {
    11471138                                $caps[] = $post_type->cap->edit_published_posts;
    1148                         elseif ( 'private' == $post->post_status )
     1139                        } elseif ( 'private' == $post->post_status ) {
    11491140                                $caps[] = $post_type->cap->edit_private_posts;
     1141                        }
    11501142                }
    11511143                break;
     
    11741166                }
    11751167
    1176                 $post_author_id = $post->post_author;
    1177 
    1178                 // If no author set yet, default to current user for cap checks.
    1179                 if ( ! $post_author_id )
    1180                         $post_author_id = $user_id;
    1181 
    1182                 if ( $user_id == $post_author_id )
     1168                if ( $post->post_author && $user_id == $post->post_author ) {
    11831169                        $caps[] = $post_type->cap->read;
    1184                 elseif ( $status_obj->private )
     1170                } elseif ( $status_obj->private ) {
    11851171                        $caps[] = $post_type->cap->read_private_posts;
    1186                 else
     1172                } else {
    11871173                        $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
     1174                }
    11881175                break;
    11891176        case 'publish_post':
Note: See TracChangeset for help on using the changeset viewer.