diff --git a/src/js/_enqueues/admin/inline-edit-post.js b/src/js/_enqueues/admin/inline-edit-post.js index 6e6e3bef606ed..0d5b64bb9a323 100644 --- a/src/js/_enqueues/admin/inline-edit-post.js +++ b/src/js/_enqueues/admin/inline-edit-post.js @@ -109,14 +109,19 @@ window.wp = window.wp || {}; }); /** - * Disables the password input field when the private post checkbox is checked. + * Disables the password input field and sticky option when the private post checkbox is checked. */ - $('#inline-edit .inline-edit-private input[value="private"]').on( 'click', function(){ - var pw = $('input.inline-edit-password-input'); - if ( $(this).prop('checked') ) { - pw.val('').prop('disabled', true); + $( 'table.widefat' ).on( 'change', '.inline-edit-private input[value="private"]', function() { + var editRow = $( this ).closest( 'tr' ), + pw = $( 'input.inline-edit-password-input', editRow ), + sticky = $( 'input[name="sticky"]', editRow ); + + if ( $( this ).prop( 'checked' ) ) { + pw.val( '' ).prop( 'disabled', true ); + sticky.prop( 'checked', false ).prop( 'disabled', true ); } else { - pw.prop('disabled', false); + pw.prop( 'disabled', false ); + sticky.prop( 'disabled', false ); } }); @@ -144,6 +149,15 @@ window.wp = window.wp || {}; $('select[name="_status"] option[value="future"]', bulkRow).remove(); + // Disable sticky option when the status is set to 'Private' in bulk edit. + $( '#bulk-edit' ).on( 'change', 'select[name="_status"]', function() { + if ( 'private' === $( this ).val() ) { + $( '#bulk-edit select[name="sticky"]' ).val( '-1' ).prop( 'disabled', true ); + } else { + $( '#bulk-edit select[name="sticky"]' ).prop( 'disabled', false ); + } + }); + /** * Adds onclick events to the apply buttons. */ @@ -449,6 +463,7 @@ window.wp = window.wp || {}; if ( 'private' === status ) { $('input[name="keep_private"]', editRow).prop('checked', true); pw.val( '' ).prop( 'disabled', true ); + $('input[name="sticky"]', editRow).prop('checked', false).prop('disabled', true); } // Remove the current page and children from the parent dropdown. diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 39d267b623037..a754c3aa44c47 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -706,7 +706,12 @@ function bulk_edit_posts( $post_data = null ) { update_post_meta( $post_id, '_edit_last', get_current_user_id() ); $updated[] = $post_id; - if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) { + $post_status = ! empty( $post_data['post_status'] ) ? $post_data['post_status'] : $post->post_status; + + // Private posts cannot be sticky. + if ( 'private' === $post_status ) { + unstick_post( $post_id ); + } elseif ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) { if ( 'sticky' === $post_data['sticky'] ) { stick_post( $post_id ); } else { diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index d9d39d8da727d..252aa2912db65 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -258,6 +258,86 @@ public function test_bulk_edit_posts_stomping() { $this->assertSame( 'closed', $post->ping_status ); } + /** + * Private posts should not be made sticky during bulk edit. + * + * @ticket 39946 + */ + public function test_bulk_edit_posts_should_not_make_private_posts_sticky() { + wp_set_current_user( self::$admin_id ); + + $post_id = self::factory()->post->create( + array( + 'post_status' => 'publish', + ) + ); + + $request = array( + 'post_type' => 'post', + 'sticky' => 'sticky', + '_status' => 'private', + 'post' => array( $post_id ), + ); + + bulk_edit_posts( $request ); + + $this->assertSame( 'private', get_post_status( $post_id ) ); + $this->assertFalse( is_sticky( $post_id ) ); + } + + /** + * Existing private posts should not be made sticky during bulk edit. + * + * @ticket 39946 + */ + public function test_bulk_edit_posts_should_unstick_existing_private_posts() { + wp_set_current_user( self::$admin_id ); + + $post_id = self::factory()->post->create( + array( + 'post_status' => 'private', + ) + ); + stick_post( $post_id ); + + $request = array( + 'post_type' => 'post', + 'sticky' => 'sticky', + '_status' => '-1', + 'post' => array( $post_id ), + ); + + bulk_edit_posts( $request ); + + $this->assertFalse( is_sticky( $post_id ) ); + } + + /** + * Non-private posts should be made sticky during bulk edit. + * + * @ticket 39946 + */ + public function test_bulk_edit_posts_should_make_non_private_posts_sticky() { + wp_set_current_user( self::$admin_id ); + + $post_id = self::factory()->post->create( + array( + 'post_status' => 'publish', + ) + ); + + $request = array( + 'post_type' => 'post', + 'sticky' => 'sticky', + '_status' => '-1', + 'post' => array( $post_id ), + ); + + bulk_edit_posts( $request ); + + $this->assertTrue( is_sticky( $post_id ) ); + } + /** * The bulk_edit_posts() function should preserve the post format * when it's unchanged.