Force visibility to password when editing a post in quick edit. - #11180
Force visibility to password when editing a post in quick edit.#11180Hug0-Drelon wants to merge 3 commits into
visibility to password when editing a post in quick edit.#11180Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the 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. |
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. |
There was a problem hiding this comment.
Pull request overview
Ensures Quick Edit requests correctly treat posts with a post_password as “password-protected” visibility so that edit_post() applies the existing visibility handling (notably unsetting sticky) for password-protected posts.
Changes:
- In
edit_post(), infervisibility = 'password'whenpost_passwordis present in the incoming post data.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Password visibility. | ||
| if ( ! empty( $post_data['post_password'] ) ) { | ||
| $post_data['visibility'] = 'password'; | ||
| } |
| // Password visibility. | ||
| if ( ! empty( $post_data['post_password'] ) ) { | ||
| $post_data['visibility'] = 'password'; | ||
| } |
|
Hi @Hug0-Drelon, do you have the bandwidth to address the reviews and add some test coverage for this PR? |
|
The ticket carries It reproduces Quick Edit's actual payload: /**
* Ensures that giving a sticky post a password through edit_post() unsticks it,
* even when the caller never sends an explicit `visibility` value.
*
* The block editor sends `visibility`, so `edit_post()` reaches the
* `case 'password'` branch and drops the `sticky` flag. Quick Edit never sends
* it, so a post could end up both sticky and password protected, a combination
* the editor itself forbids.
*
* @ticket 64810
*
* @covers ::edit_post
*/
public function test_edit_post_unsticks_a_post_when_a_password_is_set_without_visibility() {
wp_set_current_user( self::$admin_id );
$post_id = self::factory()->post->create(
array(
'post_status' => 'publish',
'post_author' => self::$admin_id,
)
);
stick_post( $post_id );
$this->assertTrue( is_sticky( $post_id ), 'The post was not sticky to begin with: check test setup.' );
// Mirrors Quick Edit, which posts `sticky` but no `visibility`.
edit_post(
array(
'post_ID' => $post_id,
'post_title' => 'Protected and sticky',
'post_status' => 'publish',
'post_password' => 'secret',
'sticky' => 'sticky',
)
);
$this->assertSame(
'secret',
get_post( $post_id )->post_password,
'The password was not saved: check test setup.'
);
$this->assertFalse(
is_sticky( $post_id ),
'A password protected post was left sticky when no explicit visibility was sent.'
);
}It goes in Verified against a local build: Whole file still green with the patch applied: 52 tests, 118 assertions, 0 failures (6 warnings, all pre-existing PHPUnit 10 deprecation notices in Also attached to the ticket as |
|
Rather than leave the test as a paste, I've opened it as a commit against this branch: Hug0-Drelon#1. Merging it there brings the test into this PR so the fix and its coverage land as one changeset, and nothing else on your side changes. The fix stays yours; I only wrote the test. |
Visibility is never set for password when using quick edit, thus
edit_post()cannot unset sticky status in https://github.com/WordPress/wordpress-develop/blob/6.9.1/src/wp-admin/includes/post.php#L308-L322.Looking at it, I thought that
wp_ajax_inline_save()would handle that like it does forprivatestatus. But it might be dead code around https://github.com/WordPress/wordpress-develop/blob/6.9.1/src/wp-admin/includes/ajax-actions.php#L2117-L2122.Removing it doesn't affect the feature (remove sticky status when a post is private).
Trac ticket: https://core.trac.wordpress.org/ticket/64810
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.