Make WordPress Core


Ignore:
Timestamp:
02/19/2020 03:50:38 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Posts, Post Types: Discard tags_input parameter in wp_update_post() if it's the same as existing post tags.

This ensures that wp_update_post() does not unintentionally modify post tags if the post has several tags with the same name but different slugs.

Tags should only be modified if tags_input parameter was explicitly provided, and is different from the existing tags.

Props kaggdesign, SergeyBiryukov.
Fixes #45121.

File:
1 edited

Legend:

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

    r47274 r47317  
    42184218    }
    42194219
     4220    // Discard 'tags_input' parameter if it's the same as existing post tags.
     4221    if ( isset( $postarr['tags_input'] ) && is_object_in_taxonomy( $postarr['post_type'], 'post_tag' ) ) {
     4222        $tags      = get_the_terms( $postarr['ID'], 'post_tag' );
     4223        $tag_names = array();
     4224
     4225        if ( $tags && ! is_wp_error( $tags ) ) {
     4226            $tag_names = wp_list_pluck( $tags, 'name' );
     4227        }
     4228
     4229        if ( $postarr['tags_input'] === $tag_names ) {
     4230            unset( $postarr['tags_input'] );
     4231        }
     4232    }
     4233
    42204234    return wp_insert_post( $postarr, $wp_error );
    42214235}
Note: See TracChangeset for help on using the changeset viewer.