From 23ca4ed3042073b700e94fc5e012345c58de6078 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Wed, 17 Feb 2021 22:58:05 +0000 Subject: [PATCH] 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 --- wp-includes/post.php | 12 ++++++------ wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 526d8f7f36..b46d97bf14 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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; diff --git a/wp-includes/version.php b/wp-includes/version.php index 7418cc09c8..2fcc767d05 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.