Skip to content
Open
27 changes: 21 additions & 6 deletions src/js/_enqueues/admin/inline-edit-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
});

Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion src/wp-admin/includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Comment thread
himanshupathak95 marked this conversation as resolved.
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 {
Expand Down
80 changes: 80 additions & 0 deletions tests/phpunit/tests/admin/includesPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}

Comment thread
himanshupathak95 marked this conversation as resolved.
/**
* 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.
Expand Down
Loading