From 6b2df3479c5c81a1d06ac47540069b7087c2b8a2 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 9 Sep 2015 06:01:28 +0000 Subject: [PATCH] Capabilities: Fall back to the `edit_posts` capability for orphaned comments. Merge of the `capabilities.php` part of [33614] to the 4.2 branch. Props pento, dd32. See #33154. Built from https://develop.svn.wordpress.org/branches/4.2@33972 git-svn-id: http://core.svn.wordpress.org/branches/4.2@33941 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/capabilities.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index 8a3d335030..b73eb41b3c 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -1260,7 +1260,16 @@ function map_meta_cap( $cap, $user_id ) { if ( empty( $comment ) ) break; $post = get_post( $comment->comment_post_ID ); - $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); + + /* + * If the post doesn't exist, we have an orphaned comment. + * Fall back to the edit_posts capability, instead. + */ + if ( $post ) { + $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); + } else { + $caps = map_meta_cap( 'edit_posts', $user_id ); + } break; case 'unfiltered_upload': if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) )