Skip to content

Commit 8f12196

Browse files
committed
Remove private posts from front page query. Aadd private posts and page caps. fixes WordPress#2613
git-svn-id: https://develop.svn.wordpress.org/trunk@3772 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 104a565 commit 8f12196

5 files changed

Lines changed: 32 additions & 8 deletions

File tree

wp-admin/upgrade-functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function upgrade_all() {
173173
if ( $wp_current_db_version < 3308 )
174174
upgrade_160();
175175

176-
if ( $wp_current_db_version < 3672 )
176+
if ( $wp_current_db_version < 3767 )
177177
upgrade_210();
178178

179179
$wp_rewrite->flush_rules();
@@ -492,7 +492,7 @@ function upgrade_210() {
492492
}
493493
}
494494

495-
if ( $wp_current_db_version < 3513 ) {
495+
if ( $wp_current_db_version < 3767 ) {
496496
populate_roles_210();
497497
}
498498

wp-admin/upgrade-schema.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@ function populate_roles_210() {
352352
$role->add_cap('delete_posts');
353353
$role->add_cap('delete_others_posts');
354354
$role->add_cap('delete_published_posts');
355+
$role->add_cap('delete_private_posts');
356+
$role->add_cap('edit_private_posts');
357+
$role->add_cap('read_private_posts');
358+
$role->add_cap('delete_private_pages');
359+
$role->add_cap('edit_private_pages');
360+
$role->add_cap('read_private_pages');
355361
}
356362

357363
$role = get_role('author');

wp-includes/capabilities.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ function map_meta_cap($cap, $user_id) {
296296
// The post is published, extra cap required.
297297
if ($post->post_status == 'publish')
298298
$caps[] = 'delete_published_posts';
299+
else if ($post->post_status == 'private')
300+
$caps[] = 'delete_private_posts';
299301
}
300302
break;
301303
case 'delete_page':
@@ -318,6 +320,8 @@ function map_meta_cap($cap, $user_id) {
318320
// The page is published, extra cap required.
319321
if ($page->post_status == 'publish')
320322
$caps[] = 'delete_published_pages';
323+
else if ($page->post_status == 'private')
324+
$caps[] = 'delete_private_pages';
321325
}
322326
break;
323327
// edit_post breaks down to edit_posts, edit_published_posts, or
@@ -346,6 +350,8 @@ function map_meta_cap($cap, $user_id) {
346350
// The post is published, extra cap required.
347351
if ($post->post_status == 'publish')
348352
$caps[] = 'edit_published_posts';
353+
else if ($post->post_status == 'private')
354+
$caps[] = 'edit_private_posts';
349355
}
350356
break;
351357
case 'edit_page':
@@ -368,6 +374,8 @@ function map_meta_cap($cap, $user_id) {
368374
// The page is published, extra cap required.
369375
if ($page->post_status == 'publish')
370376
$caps[] = 'edit_published_pages';
377+
else if ($page->post_status == 'private')
378+
$caps[] = 'edit_private_pages';
371379
}
372380
break;
373381
case 'read_post':

wp-includes/query.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -828,13 +828,23 @@ function &get_posts() {
828828
} else {
829829
$where .= " AND (post_type = '$post_type' AND (post_status = 'publish'";
830830

831-
if ( is_admin() )
831+
if ( is_admin() ) {
832832
$where .= " OR post_status = 'future' OR post_status = 'draft'";
833833

834-
if ( is_user_logged_in() )
835-
$where .= " OR post_author = $user_ID AND post_status = 'private'))";
836-
else
837-
$where .= '))';
834+
if ( is_user_logged_in() ) {
835+
if ( 'post' == $post_type )
836+
$cap = 'edit_private_posts';
837+
else
838+
$cap = 'edit_private_pages';
839+
840+
if ( current_user_can($cap) )
841+
$where .= "OR post_status = 'private'";
842+
else
843+
$where .= " OR post_author = $user_ID AND post_status = 'private'";
844+
}
845+
}
846+
847+
$where .= '))';
838848
}
839849

840850
// Apply filters on where and join prior to paging so that any

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
// This just holds the version number, in a separate file so we can bump it without cluttering the SVN
44

55
$wp_version = '2.1-alpha1';
6-
$wp_db_version = 3672;
6+
$wp_db_version = 3767;
77

88
?>

0 commit comments

Comments
 (0)