Ticket #27020: 27020.2.diff
| File 27020.2.diff, 6.0 KB (added by , 12 years ago) |
|---|
-
src/wp-includes/capabilities.php
1071 1071 break; 1072 1072 } 1073 1073 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 ) { 1082 1076 // If the post is published... 1083 1077 if ( 'publish' == $post->post_status ) { 1084 1078 $caps[] = $post_type->cap->delete_published_posts; 1085 1079 } 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 ) ) { 1087 1081 $caps[] = $post_type->cap->delete_published_posts; 1082 } 1088 1083 } else { 1089 1084 // If the post is draft... 1090 1085 $caps[] = $post_type->cap->delete_posts; … … 1093 1088 // The user is trying to edit someone else's post. 1094 1089 $caps[] = $post_type->cap->delete_others_posts; 1095 1090 // The post is published, extra cap required. 1096 if ( 'publish' == $post->post_status ) 1091 if ( 'publish' == $post->post_status ) { 1097 1092 $caps[] = $post_type->cap->delete_published_posts; 1098 elseif ( 'private' == $post->post_status )1093 } else if ( 'private' == $post->post_status ) { 1099 1094 $caps[] = $post_type->cap->delete_private_posts; 1095 } 1100 1096 } 1101 1097 break; 1102 1098 // edit_post breaks down to edit_posts, edit_published_posts, or … … 1121 1117 break; 1122 1118 } 1123 1119 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 ) { 1132 1122 // If the post is published... 1133 1123 if ( 'publish' == $post->post_status ) { 1134 1124 $caps[] = $post_type->cap->edit_published_posts; 1135 1125 } 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 ) ) { 1137 1127 $caps[] = $post_type->cap->edit_published_posts; 1128 } 1138 1129 } else { 1139 1130 // If the post is draft... 1140 1131 $caps[] = $post_type->cap->edit_posts; … … 1143 1134 // The user is trying to edit someone else's post. 1144 1135 $caps[] = $post_type->cap->edit_others_posts; 1145 1136 // The post is published, extra cap required. 1146 if ( 'publish' == $post->post_status ) 1137 if ( 'publish' == $post->post_status ) { 1147 1138 $caps[] = $post_type->cap->edit_published_posts; 1148 elseif ( 'private' == $post->post_status )1139 } else if ( 'private' == $post->post_status ) { 1149 1140 $caps[] = $post_type->cap->edit_private_posts; 1141 } 1150 1142 } 1151 1143 break; 1152 1144 case 'read_post': … … 1173 1165 break; 1174 1166 } 1175 1167 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 ) { 1183 1169 $caps[] = $post_type->cap->read; 1184 elseif ( $status_obj->private )1170 } else if ( $status_obj->private ) { 1185 1171 $caps[] = $post_type->cap->read_private_posts; 1186 else1172 } else { 1187 1173 $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); 1174 } 1188 1175 break; 1189 1176 case 'publish_post': 1190 1177 $post = get_post( $args[0] ); -
tests/phpunit/tests/user/capabilities.php
525 525 } 526 526 527 527 /** 528 * @ticket 27020 529 */ 530 function test_authorless_post() { 531 532 // Make a post without an author 533 $post = $this->factory->post->create( array( 'post_author' => 0, 'post_type' => 'post', 'post_status' => 'draft' ) ); 534 535 // Add an editor and contributor 536 $editor = new WP_User( $this->factory->user->create( array( 'role' => 'editor' ) ) ); 537 $contributor = new WP_User( $this->factory->user->create( array( 'role' => 'contributor' ) ) ); 538 539 // editor can edit, view, and trash 540 $this->assertTrue( $editor->has_cap( 'edit_post', $post ) ); 541 $this->assertTrue( $editor->has_cap( 'read_post', $post ) ); 542 $this->assertTrue( $editor->has_cap( 'delete_post', $post ) ); 543 // an contributor cannot 544 $this->assertFalse( $contributor->has_cap( 'edit_post', $post ) ); 545 $this->assertFalse( $contributor->has_cap( 'read_post', $post ) ); 546 $this->assertFalse( $contributor->has_cap( 'delete_post', $post ) ); 547 548 } 549 550 /** 528 551 * @ticket 16714 529 552 */ 530 553 function test_create_posts_caps() { -
tests/phpunit/tests/user/mapMetaCap.php
232 232 $this->assertEquals( array( 'update_core' ), map_meta_cap( 'update_core', $this->user_id ) ); 233 233 $this->assertEquals( array( 'edit_plugins' ), map_meta_cap( 'edit_plugins', $this->user_id ) ); 234 234 } 235 236 /** 237 * @ticket 27020 238 */ 239 function test_authorless_posts_capabilties() { 240 241 // Make a post without an author 242 $post_id = $this->factory->post->create( array( 'post_author' => 0, 'post_type' => 'post', 'post_status' => 'publish' ) ); 243 244 // Add an editor 245 $editor = new WP_User( $this->factory->user->create( array( 'role' => 'editor' ) ) ); 246 247 $this->assertEquals( array( 'edit_others_posts', 'edit_published_posts' ), map_meta_cap( 'edit_post', $editor->ID, $post_id ) ); 248 $this->assertEquals( array( 'delete_others_posts', 'delete_published_posts' ), map_meta_cap( 'delete_post', $editor->ID, $post_id ) ); 249 250 } 235 251 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)