Repository navigation
Conversation
…filtered_html capability. See #57343. Change comment filtering logic to use current user capability instead of comment author capability.
…tering. See #57343. Added a test to verify that a privileged user can edit an unprivileged user's comment with HTML content, ensuring proper filtering behavior on multisite.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
…site. See #57343. Added a check for multisite to grant super admin capability before updating a comment.
What
Trac ticket: https://core.trac.wordpress.org/ticket/57343
wp_update_comment()decides whether to runwp_filter_kses()on the comment content based on the comment author'sunfiltered_htmlcapability. As a result, when an administrator edits another user's comment, any HTML beyond the author's allowed markup (images, classes, scripts) is stripped on save.This PR bases the decision on the capability of the user performing the update instead, consistent with the post editor behavior (as noted by @westonruter on the ticket): a non-admin's post edited by an admin keeps the admin's markup, and is filtered again if the non-admin edits it. Comments now behave the same way.
Behavior
unfiltered_html) editing another user's comment: HTML is preserved.unfiltered_htmlediting any comment: content is filtered, regardless of who authored the comment.wp_update_comment()calls with no logged-in user continue to filter by default (current_user_can( 'unfiltered_html' )is false), preserving existing behavior for cron jobs, importers, and other unattended code.unfiltered_html, content is still filtered, as before.Tests
New
tests/phpunit/tests/comment/wpUpdateComment.phpwith three tests:unfiltered_html(unchanged default behavior).unfiltered_htmledits another user's comment (the bug; fails on trunk).The existing
Tests_Comment::test_update_comment_from_unprivileged_user_by_privileged_userencoded the old author-based behavior and is updated to expect the preserved markup on single site (filtered on multisite).Test results
Tests_Commentgroup: 828 tests, 1900 assertions, OK.WP_Test_REST_Comments_Controller: 291 tests, 1337 assertions, OK.