Make WordPress Core

Ticket #64779: 64779-notes-cap-fix.diff

File 64779-notes-cap-fix.diff, 1.1 KB (added by sachinrajcp123, 6 months ago)

Attached patch for review.

  • src/wp-includes/capabilities.php

    diff --git a/src/wp-includes/capabilities.php b/src/wp-includes/capabilities.php
    index 5b3e9d4d2c..xxxxxxxxxx 100644
    a b function map_meta_cap( $cap, $user_id, ...$args ) {  
    645645                        break;
    646646
    647647                case 'edit_comment':
     648                case 'delete_comment':
     649
     650                        if ( empty( $args[0] ) ) {
     651                                $caps[] = 'do_not_allow';
     652                                break;
     653                        }
     654
     655                        $comment = get_comment( $args[0] );
     656
     657                        if ( ! $comment ) {
     658                                $caps[] = 'do_not_allow';
     659                                break;
     660                        }
     661
     662                        /*
     663                         * Special handling for Notes.
     664                         * Notes should not be editable by users who can edit the post
     665                         * unless they are the note author. Users with manage_comments
     666                         * can still edit/delete any note.
     667                         */
     668                        if ( 'note' === $comment->comment_type ) {
     669
     670                                // Allow if user is the note author.
     671                                if ( (int) $comment->user_id === (int) $user_id ) {
     672                                        $caps[] = 'edit_posts';
     673                                } else {
     674                                        $caps[] = 'manage_comments';
     675                                }
     676
     677                                break;
     678                        }
     679
     680                        // Default behavior for normal comments continues below.
    648681
    649682                        if ( empty( $args[0] ) ) {
    650683                                $caps[] = 'do_not_allow';