[wp-trac] [WordPress Trac] #50894: Replicate default behaviour for Custom taxonomies while creating/updating a post.
WordPress Trac
noreply at wordpress.org
Tue Aug 11 08:43:27 UTC 2020
#50894: Replicate default behaviour for Custom taxonomies while creating/updating a
post.
----------------------------+-----------------------------
Reporter: shashwatmittal | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 5.4.2
Severity: normal | Keywords: needs-patch
Focuses: |
----------------------------+-----------------------------
Generally when creating/updating a post, while inserting the default
taxonomies, there is a check to ensure that the taxonomy is associated
with the given post type.
But the same doesn't applies with custom taxonomies. In case the data is
passed, and the taxonomies is not associated with the passed post type, it
still gets added. We should add a check for the same.
{{{
if ( ! empty( $postarr['tax_input'] ) ) {
foreach ( $postarr['tax_input'] as $taxonomy => $tags ) {
$taxonomy_obj = get_taxonomy( $taxonomy );
if ( ! $taxonomy_obj ) {
/* translators: %s: Taxonomy name. */
_doing_it_wrong( __FUNCTION__, sprintf(
__( 'Invalid taxonomy: %s.' ), $taxonomy ), '4.4.0' );
continue;
}
// array = hierarchical, string = non-
hierarchical.
if ( is_array( $tags ) ) {
$tags = array_filter( $tags );
}
if ( current_user_can(
$taxonomy_obj->cap->assign_terms ) ) {
wp_set_post_terms( $post_ID, $tags,
$taxonomy );
}
}
}
}}}
The above code should check if the taxonomy passed in the `tax_input`
exists for current post type or not.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50894>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list