From e9fa9a56a8ee7ad5cdd5d09dc0b5715d2a8219b2 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Thu, 4 Aug 2022 14:07:28 +0000 Subject: [PATCH] Posts, Post Types: Change variable name in `wp_set_post_terms()` for clarity. This changes the `$tags` variable used within `wp_set_post_terms()` to `$terms`. While the default for the `$taxonomy` argument is `post_tag`, the function can be used to assign terms to a post for any taxonomy. When a different taxonomy is passed, `$tags` is an inaccurate name and could be confusing. Props hilayt24, costdev, SergeyBiryukov, krishaweb, desrosj. Fixes #56331. git-svn-id: https://develop.svn.wordpress.org/trunk@53825 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index df509fd114..d8f21403ca 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -5209,7 +5209,7 @@ function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) { * @see wp_set_object_terms() * * @param int $post_id Optional. The Post ID. Does not default to the ID of the global $post. - * @param string|array $tags Optional. An array of terms to set for the post, or a string of terms + * @param string|array $terms Optional. An array of terms to set for the post, or a string of terms * separated by commas. Hierarchical taxonomies must always pass IDs rather * than names so that children with the same names but different parents * aren't confused. Default empty. @@ -5218,23 +5218,23 @@ function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) { * replace the terms with the new terms. Default false. * @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure. */ -function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $append = false ) { +function wp_set_post_terms( $post_id = 0, $terms = '', $taxonomy = 'post_tag', $append = false ) { $post_id = (int) $post_id; if ( ! $post_id ) { return false; } - if ( empty( $tags ) ) { - $tags = array(); + if ( empty( $terms ) ) { + $terms = array(); } - if ( ! is_array( $tags ) ) { + if ( ! is_array( $terms ) ) { $comma = _x( ',', 'tag delimiter' ); if ( ',' !== $comma ) { - $tags = str_replace( $comma, ',', $tags ); + $terms = str_replace( $comma, ',', $terms ); } - $tags = explode( ',', trim( $tags, " \n\t\r\0\x0B," ) ); + $terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) ); } /* @@ -5242,10 +5242,10 @@ function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $a * children with the same names but different parents aren't confused. */ if ( is_taxonomy_hierarchical( $taxonomy ) ) { - $tags = array_unique( array_map( 'intval', $tags ) ); + $terms = array_unique( array_map( 'intval', $terms ) ); } - return wp_set_object_terms( $post_id, $tags, $taxonomy, $append ); + return wp_set_object_terms( $post_id, $terms, $taxonomy, $append ); } /**