wp/wp-admin/includes/taxonomy.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
--- a/wp/wp-admin/includes/taxonomy.php	Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-admin/includes/taxonomy.php	Mon Oct 14 18:28:13 2019 +0200
@@ -22,9 +22,10 @@
  * @return mixed
  */
 function category_exists( $cat_name, $parent = null ) {
-	$id = term_exists($cat_name, 'category', $parent);
-	if ( is_array($id) )
+	$id = term_exists( $cat_name, 'category', $parent );
+	if ( is_array( $id ) ) {
 		$id = $id['term_id'];
+	}
 	return $id;
 }
 
@@ -52,10 +53,16 @@
  * @return int|WP_Error
  */
 function wp_create_category( $cat_name, $parent = 0 ) {
-	if ( $id = category_exists($cat_name, $parent) )
+	if ( $id = category_exists( $cat_name, $parent ) ) {
 		return $id;
+	}
 
-	return wp_insert_category( array('cat_name' => $cat_name, 'category_parent' => $parent) );
+	return wp_insert_category(
+		array(
+			'cat_name'        => $cat_name,
+			'category_parent' => $parent,
+		)
+	);
 }
 
 /**
@@ -63,12 +70,12 @@
  *
  * @since 2.0.0
  *
- * @param array $categories List of categories to create.
- * @param int   $post_id    Optional. The post ID. Default empty.
+ * @param string[] $categories Array of category names to create.
+ * @param int      $post_id    Optional. The post ID. Default empty.
  * @return array List of categories to create for the given post.
  */
 function wp_create_categories( $categories, $post_id = '' ) {
-	$cat_ids = array ();
+	$cat_ids = array();
 	foreach ( $categories as $category ) {
 		if ( $id = category_exists( $category ) ) {
 			$cat_ids[] = $id;
@@ -77,8 +84,9 @@
 		}
 	}
 
-	if ( $post_id )
-		wp_set_post_categories($post_id, $cat_ids);
+	if ( $post_id ) {
+		wp_set_post_categories( $post_id, $cat_ids );
+	}
 
 	return $cat_ids;
 }
@@ -106,8 +114,15 @@
  *                    depending on param $wp_error.
  */
 function wp_insert_category( $catarr, $wp_error = false ) {
-	$cat_defaults = array( 'cat_ID' => 0, 'taxonomy' => 'category', 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '' );
-	$catarr = wp_parse_args( $catarr, $cat_defaults );
+	$cat_defaults = array(
+		'cat_ID'               => 0,
+		'taxonomy'             => 'category',
+		'cat_name'             => '',
+		'category_description' => '',
+		'category_nicename'    => '',
+		'category_parent'      => '',
+	);
+	$catarr       = wp_parse_args( $catarr, $cat_defaults );
 
 	if ( trim( $catarr['cat_name'] ) == '' ) {
 		if ( ! $wp_error ) {
@@ -120,12 +135,12 @@
 	$catarr['cat_ID'] = (int) $catarr['cat_ID'];
 
 	// Are we updating or creating?
-	$update = ! empty ( $catarr['cat_ID'] );
+	$update = ! empty( $catarr['cat_ID'] );
 
-	$name = $catarr['cat_name'];
+	$name        = $catarr['cat_name'];
 	$description = $catarr['category_description'];
-	$slug = $catarr['category_nicename'];
-	$parent = (int) $catarr['category_parent'];
+	$slug        = $catarr['category_nicename'];
+	$parent      = (int) $catarr['category_parent'];
 	if ( $parent < 0 ) {
 		$parent = 0;
 	}
@@ -136,7 +151,7 @@
 		$parent = 0;
 	}
 
-	$args = compact('name', 'slug', 'parent', 'description');
+	$args = compact( 'name', 'slug', 'parent', 'description' );
 
 	if ( $update ) {
 		$catarr['cat_ID'] = wp_update_term( $catarr['cat_ID'], $catarr['taxonomy'], $args );
@@ -165,23 +180,24 @@
  * @param array $catarr The 'cat_ID' value is required. All other keys are optional.
  * @return int|bool The ID number of the new or updated Category on success. Zero or FALSE on failure.
  */
-function wp_update_category($catarr) {
+function wp_update_category( $catarr ) {
 	$cat_ID = (int) $catarr['cat_ID'];
 
-	if ( isset($catarr['category_parent']) && ($cat_ID == $catarr['category_parent']) )
+	if ( isset( $catarr['category_parent'] ) && ( $cat_ID == $catarr['category_parent'] ) ) {
 		return false;
+	}
 
 	// First, get all of the original fields
 	$category = get_term( $cat_ID, 'category', ARRAY_A );
 	_make_cat_compat( $category );
 
 	// Escape data pulled from DB.
-	$category = wp_slash($category);
+	$category = wp_slash( $category );
 
 	// Merge old and new fields with new fields overwriting old ones.
-	$catarr = array_merge($category, $catarr);
+	$catarr = array_merge( $category, $catarr );
 
-	return wp_insert_category($catarr);
+	return wp_insert_category( $catarr );
 }
 
 //
@@ -196,8 +212,8 @@
  * @param int|string $tag_name
  * @return mixed
  */
-function tag_exists($tag_name) {
-	return term_exists($tag_name, 'post_tag');
+function tag_exists( $tag_name ) {
+	return term_exists( $tag_name, 'post_tag' );
 }
 
 /**
@@ -208,8 +224,8 @@
  * @param int|string $tag_name
  * @return array|WP_Error
  */
-function wp_create_tag($tag_name) {
-	return wp_create_term( $tag_name, 'post_tag');
+function wp_create_tag( $tag_name ) {
+	return wp_create_term( $tag_name, 'post_tag' );
 }
 
 /**
@@ -222,7 +238,7 @@
  * @return string|bool|WP_Error
  */
 function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
-	return get_terms_to_edit( $post_id, $taxonomy);
+	return get_terms_to_edit( $post_id, $taxonomy );
 }
 
 /**
@@ -236,8 +252,9 @@
  */
 function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
 	$post_id = (int) $post_id;
-	if ( !$post_id )
+	if ( ! $post_id ) {
 		return false;
+	}
 
 	$terms = get_object_term_cache( $post_id, $taxonomy );
 	if ( false === $terms ) {
@@ -265,8 +282,8 @@
 	 *
 	 * @see get_terms_to_edit()
 	 *
-	 * @param array  $terms_to_edit An array of terms.
-	 * @param string $taxonomy     The taxonomy for which to retrieve terms. Default 'post_tag'.
+	 * @param string $terms_to_edit A comma-separated list of term names.
+	 * @param string $taxonomy      The taxonomy name for which to retrieve terms.
 	 */
 	$terms_to_edit = apply_filters( 'terms_to_edit', $terms_to_edit, $taxonomy );
 
@@ -282,9 +299,10 @@
  * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
  * @return array|WP_Error
  */
-function wp_create_term($tag_name, $taxonomy = 'post_tag') {
-	if ( $id = term_exists($tag_name, $taxonomy) )
+function wp_create_term( $tag_name, $taxonomy = 'post_tag' ) {
+	if ( $id = term_exists( $tag_name, $taxonomy ) ) {
 		return $id;
+	}
 
-	return wp_insert_term($tag_name, $taxonomy);
+	return wp_insert_term( $tag_name, $taxonomy );
 }