Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malformed sticky_posts option breaks sticky posts. #2353

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2895,7 +2895,7 @@ function stick_post( $post_id ) {
$updated = false;

if ( ! is_array( $stickies ) ) {
$stickies = array( $post_id );
$stickies = array();
} else {
$stickies = array_unique( array_map( 'intval', $stickies ) );
}
Expand Down
47 changes: 47 additions & 0 deletions tests/phpunit/tests/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,53 @@ public function data_stick_post_does_not_duplicate_post_ids() {
);
}

/**
* Ensures sticking a post succeeds after deleting the 'sticky_posts' option.
*
* @ticket 52007
* @ticket 55176
* @covers ::stick_post
*/
public function test_stick_post_after_delete_sticky_posts_option() {
delete_option( 'sticky_posts' );

stick_post( 1 );
$this->assertSameSets( array( 1 ), get_option( 'sticky_posts' ) );
}

/**
* Ensures sticking works with an unexpected option value.
*
* @ticket 52007
* @ticket 55176
* @covers ::stick_post
* @dataProvider data_stick_post_with_unexpected_sticky_posts_option
*
* @param mixed $starting_option Starting value for sticky_posts option.
*/
public function test_stick_post_with_unexpected_sticky_posts_option( $starting_option ) {
update_option( 'sticky_posts', $starting_option );

stick_post( 1 );
$this->assertSameSets( array( 1 ), get_option( 'sticky_posts' ) );
}

/**
* Data provider.
*
* @return array
*/
public function data_stick_post_with_unexpected_sticky_posts_option() {
return array(
'false' => array( false ),
'a string' => array( 'string' ),
'1 int' => array( 1 ),
'null' => array( null ),
'true' => array( true ),
'an object' => array( new stdClass ),
);
}

/**
* Ensure sticking a post removes other duplicate post IDs from the option.
*
Expand Down