[wp-trac] [WordPress Trac] #45121: wp_update_post() can modify post tag
WordPress Trac
noreply at wordpress.org
Thu Oct 18 14:47:20 UTC 2018
#45121: wp_update_post() can modify post tag
-------------------------------+-----------------------------
Reporter: kaggdesign | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: 4.9.8
Severity: normal | Keywords:
Focuses: |
-------------------------------+-----------------------------
**Problem**
Update of post by means of {{{wp_update_post()}}} can modify tags assigned
to the post.
**Steps to reproduce:**
Fresh WP install.
Create two tags with the same name (let say {{{wp_update_post_tag}}}) and
different slugs (let say {{{wp_update_post_tag_1}}}} and
{{{wp_update_post_tag_2}}}, in this sequence).
Create a post with tag {{{wp_update_post_tag_2}}}. Check that it has tag
{{{wp_update_post_tag_2}}}.
Use {{{wp_update_post( $post )}}}. Check that now it has tag
{{{wp_update_post_tag_1}}}.
This sequence is demonstrated by the plugin https://github.com/kagg-design
/update-post-bug.
-----
**Reason**
Problem is caused by the following lines in {{{wp_insert_post()}}}:
{{{
if ( isset( $postarr['tags_input'] ) && is_object_in_taxonomy(
$post_type, 'post_tag' ) ) {
wp_set_post_tags( $post_ID, $postarr['tags_input'] );
}
}}}
At this point, {{{$postarr['tags_input']}}} already is {{{array(
'wp_update_post_tag' )}}}, containing tag_name, not ID. This is because
{{{wp_update_post()}}} executes
{{{
// First, get all of the original fields.
$post = get_post($postarr['ID'], ARRAY_A);
}}}
Here {{{$post}}} gets {{{tags_input}}} as {{{array( 'wp_update_post_tag'
)}}}, containing tag_name, not ID.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45121>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list