diff --git a/src/wp-includes/capabilities.php b/src/wp-includes/capabilities.php
index 0c40c7e384..09a133b88f 100644
--- a/src/wp-includes/capabilities.php
+++ b/src/wp-includes/capabilities.php
@@ -381,7 +381,12 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
 			}
 
 			$post = get_post( $comment->comment_post_ID );
+			$author = $comment->user_id;
 
+			if ( ! (int) $author === 0 ) {
+				$caps[] = 'do_not_allow';
+				break;
+			}
 			/*
 			 * If the post doesn't exist, we have an orphaned comment.
 			 * Fall back to the edit_posts capability, instead.
@@ -391,6 +396,9 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
 			} else {
 				$caps = map_meta_cap( 'edit_posts', $user_id );
 			}
+			if ( (int) $author === $user_id ) {
+				$caps = [$cap];
+			}
 			break;
 		case 'unfiltered_upload':
 			if ( defined( 'ALLOW_UNFILTERED_UPLOADS' ) && ALLOW_UNFILTERED_UPLOADS && ( ! is_multisite() || is_super_admin( $user_id ) ) ) {
@@ -1047,6 +1055,31 @@ function wp_maybe_grant_site_health_caps( $allcaps, $caps, $args, $user ) {
 	return $allcaps;
 }
 
+/**
+ * Filters the user capabilities to grant the 'edit_comment' capability as necessary.
+ *
+ * @since 5.4
+ *
+ * @param bool[]   $allcaps An array of all the user's capabilities.
+ * @param string[] $caps    Required primitive capabilities for the requested capability.
+ * @param array    $args {
+ *     Arguments that accompany the requested capability check.
+ *
+ *     @type string    $0 Requested capability.
+ *     @type int       $1 Concerned user ID.
+ *     @type mixed  ...$2 Optional second and further parameters, typically object ID.
+ * }
+ * @param WP_User  $user    The user object.
+ * @return bool[] Filtered array of the user's capabilities.
+ */
+function wp_maybe_grant_edit_comment($allcaps, $caps, $args, $user ) {
+	if( in_array('edit_comment', $caps) ) {
+		$allcaps['edit_comment'] = true;
+	}
+
+	return $allcaps;
+}
+
 return;
 
 // Dummy gettext calls to get strings in the catalog.
diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php
index 26cdfeba20..662bab6ac4 100644
--- a/src/wp-includes/default-filters.php
+++ b/src/wp-includes/default-filters.php
@@ -582,5 +582,6 @@ add_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10, 3 );
 add_filter( 'user_has_cap', 'wp_maybe_grant_install_languages_cap', 1 );
 add_filter( 'user_has_cap', 'wp_maybe_grant_resume_extensions_caps', 1 );
 add_filter( 'user_has_cap', 'wp_maybe_grant_site_health_caps', 1, 4 );
+add_filter( 'user_has_cap', 'wp_maybe_grant_edit_comment', 1, 5);
 
 unset( $filter, $action );
