Posts/Post Types: Prevent duplicates in sticky posts option.

In `unstick_post()` if a post ID is duplicated in the `sticky_posts` option remove all instances.

In both `stick_post()` and `unstick_post()` check for duplicate IDs already stored in the `sticky_post` option and remove them if the option is updated.

Props rahmohn, archon810.
Fixes #52007.

Built from https://develop.svn.wordpress.org/trunk@50380


git-svn-id: http://core.svn.wordpress.org/trunk@49991 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2021-02-17 22:58:05 +00:00
parent 64b43a44db
commit 23ca4ed304
2 changed files with 7 additions and 7 deletions

View File

@ -2626,19 +2626,19 @@ function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) {
function stick_post( $post_id ) {
$post_id = (int) $post_id;
$stickies = get_option( 'sticky_posts' );
$updated = false;
if ( ! is_array( $stickies ) ) {
$stickies = array();
$stickies = array( $post_id );
} else {
$stickies = array_unique( array_map( 'intval', $stickies ) );
}
$stickies = array_map( 'intval', $stickies );
if ( ! in_array( $post_id, $stickies, true ) ) {
$stickies[] = $post_id;
$updated = update_option( 'sticky_posts', array_values( $stickies ) );
}
$updated = update_option( 'sticky_posts', $stickies );
if ( $updated ) {
/**
* Fires once a post has been added to the sticky list.
@ -2668,7 +2668,7 @@ function unstick_post( $post_id ) {
return;
}
$stickies = array_map( 'intval', $stickies );
$stickies = array_values( array_unique( array_map( 'intval', $stickies ) ) );
if ( ! in_array( $post_id, $stickies, true ) ) {
return;

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.7-beta3-50379';
$wp_version = '5.7-beta3-50380';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.