Changeset 47864 for trunk/src/wp-includes/category.php
- Timestamp:
- 05/29/2020 10:05:36 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/category.php
r47863 r47864 8 8 9 9 /** 10 * Retrieve list of category objects.10 * Retrieves a list of category objects. 11 11 * 12 12 * If you set the 'taxonomy' argument to 'link_category', the link categories … … 81 81 * 82 82 * @param int|object $category Category ID or Category row object 83 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a 84 * WP_Term object, an associative array, or a numeric array, respectively. Default OBJECT. 83 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, 84 * which correspond to a WP_Term object, an associative array, or a numeric array, 85 * respectively. Default OBJECT. 85 86 * @param string $filter Optional. Default is raw or no WordPress defined filter will applied. 86 87 * @return object|array|WP_Error|null Category data in type defined by $output parameter. … … 100 101 101 102 /** 102 * Retrieve category based on URL containing the category slug.103 * Retrieves a category based on URL containing the category slug. 103 104 * 104 105 * Breaks the $category_path parameter up to get the category slug. … … 115 116 * @param string $category_path URL containing category slugs. 116 117 * @param bool $full_match Optional. Whether full path should be matched. 117 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to 118 * a WP_Term object, an associative array, or a numeric array, respectively. Default OBJECT. 118 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, 119 * which correspond to a WP_Term object, an associative array, or a numeric array, 120 * respectively. Default OBJECT. 119 121 * @return WP_Term|array|WP_Error|null Type is based on $output value. 120 122 */ … … 149 151 while ( ( 0 != $curcategory->parent ) && ( $curcategory->parent != $curcategory->term_id ) ) { 150 152 $curcategory = get_term( $curcategory->parent, 'category' ); 153 151 154 if ( is_wp_error( $curcategory ) ) { 152 155 return $curcategory; 153 156 } 157 154 158 $path = '/' . $curcategory->slug . $path; 155 159 } … … 158 162 $category = get_term( $category->term_id, 'category', $output ); 159 163 _make_cat_compat( $category ); 164 160 165 return $category; 161 166 } … … 166 171 $category = get_term( reset( $categories )->term_id, 'category', $output ); 167 172 _make_cat_compat( $category ); 173 168 174 return $category; 169 175 } … … 171 177 172 178 /** 173 * Retrieve category object by category slug.179 * Retrieves a category object by category slug. 174 180 * 175 181 * @since 2.3.0 … … 189 195 190 196 /** 191 * Retrieve the ID of a category from its name.197 * Retrieves the ID of a category from its name. 192 198 * 193 199 * @since 1.0.0 194 200 * 195 201 * @param string $cat_name Category name. 196 * @return int 0, if failure and ID of category on success.202 * @return int Category ID on success, 0 if the category doesn't exist. 197 203 */ 198 204 function get_cat_ID( $cat_name ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid 199 205 $cat = get_term_by( 'name', $cat_name, 'category' ); 206 200 207 if ( $cat ) { 201 208 return $cat->term_id; 202 209 } 210 203 211 return 0; 204 212 } 205 213 206 214 /** 207 * Retrieve the name of a category from its ID.215 * Retrieves the name of a category from its ID. 208 216 * 209 217 * @since 1.0.0 210 218 * 211 * @param int $cat_id Category ID 212 * @return string Category name, or an empty string if category doesn't exist.219 * @param int $cat_id Category ID. 220 * @return string Category name, or an empty string if the category doesn't exist. 213 221 */ 214 222 function get_cat_name( $cat_id ) { 215 223 $cat_id = (int) $cat_id; 216 224 $category = get_term( $cat_id, 'category' ); 225 217 226 if ( ! $category || is_wp_error( $category ) ) { 218 227 return ''; 219 228 } 229 220 230 return $category->name; 221 231 } 222 232 223 233 /** 224 * Check if a category is an ancestor of another category.225 * 226 * You can use either an id or the category object for both parameters. If you227 * use an integerthe category will be retrieved.234 * Checks if a category is an ancestor of another category. 235 * 236 * You can use either an ID or the category object for both parameters. 237 * If you use an integer, the category will be retrieved. 228 238 * 229 239 * @since 2.1.0 … … 231 241 * @param int|object $cat1 ID or object to check if this is the parent category. 232 242 * @param int|object $cat2 The child category. 233 * @return bool Whether $cat2 is child of $cat1 243 * @return bool Whether $cat2 is child of $cat1. 234 244 */ 235 245 function cat_is_ancestor_of( $cat1, $cat2 ) { … … 242 252 * @since 2.3.0 243 253 * 244 * @param object|array $category Category data 245 * @param string $context Optional. Default is'display'.254 * @param object|array $category Category data. 255 * @param string $context Optional. Default 'display'. 246 256 * @return object|array Same type as $category with sanitized data for safe use. 247 257 */ … … 255 265 * @since 2.3.0 256 266 * 257 * @param string $field Category key to sanitize258 * @param mixed $value Category value to sanitize259 * @param int $cat_id Category ID267 * @param string $field Category key to sanitize. 268 * @param mixed $value Category value to sanitize. 269 * @param int $cat_id Category ID. 260 270 * @param string $context What filter to use, 'raw', 'display', etc. 261 271 * @return mixed Same type as $value after $value has been sanitized. … … 296 306 */ 297 307 $tags = apply_filters( 'get_tags', $tags, $args ); 308 298 309 return $tags; 299 310 } 300 311 301 312 /** 302 * Retrieve post tag by tag ID or tag object.313 * Retrieves a post tag by tag ID or tag object. 303 314 * 304 315 * If you pass the $tag parameter an object, which is assumed to be the tag row 305 * object retrieved the database. It will cache the tag data.306 * 307 * If you pass $tag an integer of the tag ID, then that tag will 308 * be retrieved from the database, if it isn't already cached, and pass itback.309 * 310 * If you look at get_term(), then both types will be passed through several311 * filtersand finally sanitized based on the $filter parameter value.316 * object retrieved from the database, it will cache the tag data. 317 * 318 * If you pass $tag an integer of the tag ID, then that tag will be retrieved 319 * from the database, if it isn't already cached, and passed back. 320 * 321 * If you look at get_term(), both types will be passed through several filters 322 * and finally sanitized based on the $filter parameter value. 312 323 * 313 324 * @since 2.3.0 314 325 * 315 326 * @param int|WP_Term|object $tag A tag ID or object. 316 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to 317 * a WP_Term object, an associative array, or a numeric array, respectively. Default OBJECT. 327 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, 328 * which correspond to a WP_Term object, an associative array, or a numeric array, 329 * respectively. Default OBJECT. 318 330 * @param string $filter Optional. Default is raw or no WordPress defined filter will applied. 319 * @return WP_Term|array|WP_Error|null Tag data in type defined by $output parameter. WP_Error if $tag is empty, null if it does not exist. 331 * @return WP_Term|array|WP_Error|null Tag data in type defined by $output parameter. 332 * WP_Error if $tag is empty, null if it does not exist. 320 333 */ 321 334 function get_tag( $tag, $output = OBJECT, $filter = 'raw' ) { … … 326 339 327 340 /** 328 * Remove the category cache data based on ID.341 * Removes the category cache data based on ID. 329 342 * 330 343 * @since 2.1.0 … … 337 350 338 351 /** 339 * Update category structure to old pre-2.3 from new taxonomy structure.352 * Updates category structure to old pre-2.3 from new taxonomy structure. 340 353 * 341 354 * This function was added for the taxonomy support to update the new category
Note: See TracChangeset
for help on using the changeset viewer.