Make WordPress Core


Ignore:
Timestamp:
02/17/2021 10:56:34 PM (4 years ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r50266 r50380  
    26272627    $post_id  = (int) $post_id;
    26282628    $stickies = get_option( 'sticky_posts' );
     2629    $updated  = false;
    26292630
    26302631    if ( ! is_array( $stickies ) ) {
    2631         $stickies = array();
    2632     }
    2633 
    2634     $stickies = array_map( 'intval', $stickies );
     2632        $stickies = array( $post_id );
     2633    } else {
     2634        $stickies = array_unique( array_map( 'intval', $stickies ) );
     2635    }
    26352636
    26362637    if ( ! in_array( $post_id, $stickies, true ) ) {
    26372638        $stickies[] = $post_id;
    2638     }
    2639 
    2640     $updated = update_option( 'sticky_posts', $stickies );
     2639        $updated    = update_option( 'sticky_posts', array_values( $stickies ) );
     2640    }
    26412641
    26422642    if ( $updated ) {
     
    26692669    }
    26702670
    2671     $stickies = array_map( 'intval', $stickies );
     2671    $stickies = array_values( array_unique( array_map( 'intval', $stickies ) ) );
    26722672
    26732673    if ( ! in_array( $post_id, $stickies, true ) ) {
Note: See TracChangeset for help on using the changeset viewer.