wp/wp-admin/includes/taxonomy.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     9 //
     9 //
    10 // Category.
    10 // Category.
    11 //
    11 //
    12 
    12 
    13 /**
    13 /**
    14  * Check whether a category exists.
    14  * Checks whether a category exists.
    15  *
    15  *
    16  * @since 2.0.0
    16  * @since 2.0.0
    17  *
    17  *
    18  * @see term_exists()
    18  * @see term_exists()
    19  *
    19  *
    28 	}
    28 	}
    29 	return $id;
    29 	return $id;
    30 }
    30 }
    31 
    31 
    32 /**
    32 /**
    33  * Get category object for given ID and 'edit' filter context.
    33  * Gets category object for given ID and 'edit' filter context.
    34  *
    34  *
    35  * @since 2.0.0
    35  * @since 2.0.0
    36  *
    36  *
    37  * @param int $id
    37  * @param int $id
    38  * @return object
    38  * @return object
    42 	_make_cat_compat( $category );
    42 	_make_cat_compat( $category );
    43 	return $category;
    43 	return $category;
    44 }
    44 }
    45 
    45 
    46 /**
    46 /**
    47  * Add a new category to the database if it does not already exist.
    47  * Adds a new category to the database if it does not already exist.
    48  *
    48  *
    49  * @since 2.0.0
    49  * @since 2.0.0
    50  *
    50  *
    51  * @param int|string $cat_name        Category name.
    51  * @param int|string $cat_name        Category name.
    52  * @param int        $category_parent Optional. ID of parent category.
    52  * @param int        $category_parent Optional. ID of parent category.
    65 		)
    65 		)
    66 	);
    66 	);
    67 }
    67 }
    68 
    68 
    69 /**
    69 /**
    70  * Create categories for the given post.
    70  * Creates categories for the given post.
    71  *
    71  *
    72  * @since 2.0.0
    72  * @since 2.0.0
    73  *
    73  *
    74  * @param string[] $categories Array of category names to create.
    74  * @param string[] $categories Array of category names to create.
    75  * @param int      $post_id    Optional. The post ID. Default empty.
    75  * @param int      $post_id    Optional. The post ID. Default empty.
   184  *
   184  *
   185  * @param array $catarr The 'cat_ID' value is required. All other keys are optional.
   185  * @param array $catarr The 'cat_ID' value is required. All other keys are optional.
   186  * @return int|false The ID number of the new or updated Category on success. Zero or FALSE on failure.
   186  * @return int|false The ID number of the new or updated Category on success. Zero or FALSE on failure.
   187  */
   187  */
   188 function wp_update_category( $catarr ) {
   188 function wp_update_category( $catarr ) {
   189 	$cat_ID = (int) $catarr['cat_ID'];
   189 	$cat_id = (int) $catarr['cat_ID'];
   190 
   190 
   191 	if ( isset( $catarr['category_parent'] ) && ( $cat_ID == $catarr['category_parent'] ) ) {
   191 	if ( isset( $catarr['category_parent'] ) && ( $cat_id === (int) $catarr['category_parent'] ) ) {
   192 		return false;
   192 		return false;
   193 	}
   193 	}
   194 
   194 
   195 	// First, get all of the original fields.
   195 	// First, get all of the original fields.
   196 	$category = get_term( $cat_ID, 'category', ARRAY_A );
   196 	$category = get_term( $cat_id, 'category', ARRAY_A );
   197 	_make_cat_compat( $category );
   197 	_make_cat_compat( $category );
   198 
   198 
   199 	// Escape data pulled from DB.
   199 	// Escape data pulled from DB.
   200 	$category = wp_slash( $category );
   200 	$category = wp_slash( $category );
   201 
   201 
   208 //
   208 //
   209 // Tags.
   209 // Tags.
   210 //
   210 //
   211 
   211 
   212 /**
   212 /**
   213  * Check whether a post tag with a given name exists.
   213  * Checks whether a post tag with a given name exists.
   214  *
   214  *
   215  * @since 2.3.0
   215  * @since 2.3.0
   216  *
   216  *
   217  * @param int|string $tag_name
   217  * @param int|string $tag_name
   218  * @return mixed Returns null if the term does not exist.
   218  * @return mixed Returns null if the term does not exist.
   222 function tag_exists( $tag_name ) {
   222 function tag_exists( $tag_name ) {
   223 	return term_exists( $tag_name, 'post_tag' );
   223 	return term_exists( $tag_name, 'post_tag' );
   224 }
   224 }
   225 
   225 
   226 /**
   226 /**
   227  * Add a new tag to the database if it does not already exist.
   227  * Adds a new tag to the database if it does not already exist.
   228  *
   228  *
   229  * @since 2.3.0
   229  * @since 2.3.0
   230  *
   230  *
   231  * @param int|string $tag_name
   231  * @param int|string $tag_name
   232  * @return array|WP_Error
   232  * @return array|WP_Error
   234 function wp_create_tag( $tag_name ) {
   234 function wp_create_tag( $tag_name ) {
   235 	return wp_create_term( $tag_name, 'post_tag' );
   235 	return wp_create_term( $tag_name, 'post_tag' );
   236 }
   236 }
   237 
   237 
   238 /**
   238 /**
   239  * Get comma-separated list of tags available to edit.
   239  * Gets comma-separated list of tags available to edit.
   240  *
   240  *
   241  * @since 2.3.0
   241  * @since 2.3.0
   242  *
   242  *
   243  * @param int    $post_id
   243  * @param int    $post_id
   244  * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
   244  * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
   247 function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
   247 function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
   248 	return get_terms_to_edit( $post_id, $taxonomy );
   248 	return get_terms_to_edit( $post_id, $taxonomy );
   249 }
   249 }
   250 
   250 
   251 /**
   251 /**
   252  * Get comma-separated list of terms available to edit for the given post ID.
   252  * Gets comma-separated list of terms available to edit for the given post ID.
   253  *
   253  *
   254  * @since 2.8.0
   254  * @since 2.8.0
   255  *
   255  *
   256  * @param int    $post_id
   256  * @param int    $post_id
   257  * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
   257  * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
   296 
   296 
   297 	return $terms_to_edit;
   297 	return $terms_to_edit;
   298 }
   298 }
   299 
   299 
   300 /**
   300 /**
   301  * Add a new term to the database if it does not already exist.
   301  * Adds a new term to the database if it does not already exist.
   302  *
   302  *
   303  * @since 2.8.0
   303  * @since 2.8.0
   304  *
   304  *
   305  * @param string $tag_name The term name.
   305  * @param string $tag_name The term name.
   306  * @param string $taxonomy Optional. The taxonomy within which to create the term. Default 'post_tag'.
   306  * @param string $taxonomy Optional. The taxonomy within which to create the term. Default 'post_tag'.