Changeset 32627
- Timestamp:
- 05/27/2015 09:59:06 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r32553 r32627 171 171 * @global array $wp_taxonomies The registered taxonomies. 172 172 * 173 * @param array|string| object $object Name of the type of taxonomy object, or an object (row from posts)174 * @param string $output Optional. The type of output to return in the array. Accepts either175 * taxonomy 'names' or 'objects'. Default 'names'.173 * @param array|string|WP_Post $object Name of the type of taxonomy object, or an object (row from posts) 174 * @param string $output Optional. The type of output to return in the array. Accepts either 175 * taxonomy 'names' or 'objects'. Default 'names'. 176 176 * @return array The names of all taxonomy of $object_type. 177 177 */ … … 211 211 * 212 212 * @param string $taxonomy Name of taxonomy object to return. 213 * @return object| boolThe Taxonomy Object or false if $taxonomy doesn't exist.213 * @return object|false The Taxonomy Object or false if $taxonomy doesn't exist. 214 214 */ 215 215 function get_taxonomy( $taxonomy ) { … … 328 328 * @global WP $wp WP instance. 329 329 * 330 * @param string $taxonomyTaxonomy key, must not exceed 32 characters.330 * @param string $taxonomy Taxonomy key, must not exceed 32 characters. 331 331 * @param array|string $object_type Name of the object type for the taxonomy object. 332 * @param array|string $args See optional args description above.333 * @return null|WP_Error WP_Error if errors, otherwise null.332 * @param array|string $args See optional args description above. 333 * @return WP_Error|void WP_Error, if errors. 334 334 */ 335 335 function register_taxonomy( $taxonomy, $object_type, $args = array() ) { … … 483 483 * @return object object with all the labels as member variables. 484 484 */ 485 486 485 function get_taxonomy_labels( $tax ) { 487 486 $tax->labels = (array) $tax->labels; … … 593 592 * @global wpdb $wpdb WordPress database abstraction object. 594 593 * 595 * @param int|array $term_idsTerm id or array of term ids of terms that will be used.594 * @param int|array $term_ids Term id or array of term ids of terms that will be used. 596 595 * @param string|array $taxonomies String of taxonomy name or Array of string values of taxonomy names. 597 * @param array|string $args Change the order of the object_ids, either ASC or DESC.596 * @param array|string $args Change the order of the object_ids, either ASC or DESC. 598 597 * @return WP_Error|array If the taxonomy does not exist, then WP_Error will be returned. On success. 599 598 * the array can be empty meaning that there are no $object_ids found or it will return the $object_ids found. … … 639 638 * @see WP_Tax_Query 640 639 * 641 * @param array $tax_queryA compact tax query640 * @param array $tax_query A compact tax query 642 641 * @param string $primary_table 643 642 * @param string $primary_id_column … … 684 683 * 685 684 * @since 3.2.0 685 * 686 * @static 686 687 * @access private 687 688 * @var string … … 867 868 * 868 869 * @since 4.1.0 870 * 871 * @static 869 872 * @access protected 870 873 * … … 880 883 * 881 884 * @since 3.1.0 885 * 886 * @static 882 887 * @access public 883 888 * … … 1148 1153 * @param array $clause Query clause. 1149 1154 * @param array $parent_query Parent query of $clause. 1150 * @return string| boolTable alias if found, otherwise false.1155 * @return string|false Table alias if found, otherwise false. 1151 1156 */ 1152 1157 protected function find_compatible_table_alias( $clause, $parent_query ) { … … 1329 1334 * @see sanitize_term_field() The $context param lists the available values for get_term_by() $filter param. 1330 1335 * 1331 * @param int|object $term If integer, will get from database. If object will apply filters and return $term.1332 * @param string $taxonomy Taxonomy name that $term is part of.1333 * @param string $outputConstant OBJECT, ARRAY_A, or ARRAY_N1334 * @param string $filterOptional, default is raw or no WordPress defined filter will applied.1335 * @return mixed|null|WP_Error Term Row from database. Will return null if $term is empty. If taxonomy does not1336 * @param int|object $term If integer, will get from database. If object will apply filters and return $term. 1337 * @param string $taxonomy Taxonomy name that $term is part of. 1338 * @param string $output Constant OBJECT, ARRAY_A, or ARRAY_N 1339 * @param string $filter Optional, default is raw or no WordPress defined filter will applied. 1340 * @return object|array|null|WP_Error Term Row from database. Will return null if $term is empty. If taxonomy does not 1336 1341 * exist then WP_Error will be returned. 1337 1342 */ … … 1339 1344 global $wpdb; 1340 1345 1341 if ( empty($term) ) { 1342 $error = new WP_Error('invalid_term', __('Empty Term')); 1343 return $error; 1344 } 1345 1346 if ( ! taxonomy_exists($taxonomy) ) { 1347 $error = new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 1348 return $error; 1346 if ( empty( $term ) ) { 1347 return new WP_Error( 'invalid_term', __( 'Empty Term' ) ); 1348 } 1349 1350 if ( ! taxonomy_exists( $taxonomy ) ) { 1351 return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) ); 1349 1352 } 1350 1353 … … 1421 1424 * @see sanitize_term_field() The $context param lists the available values for get_term_by() $filter param. 1422 1425 * 1423 * @param string $field Either 'slug', 'name', 'id' (term_id), or 'term_taxonomy_id' 1424 * @param string|int $value Search for this term value 1425 * @param string $taxonomy Taxonomy Name 1426 * @param string $output Constant OBJECT, ARRAY_A, or ARRAY_N 1427 * @param string $filter Optional, default is raw or no WordPress defined filter will applied. 1428 * @return mixed Term Row from database. Will return false if $taxonomy does not exist or $term was not found. 1426 * @param string $field Either 'slug', 'name', 'id' (term_id), or 'term_taxonomy_id' 1427 * @param string|int $value Search for this term value 1428 * @param string $taxonomy Taxonomy Name 1429 * @param string $output Constant OBJECT, ARRAY_A, or ARRAY_N 1430 * @param string $filter Optional, default is raw or no WordPress defined filter will applied. 1431 * @return object|array|null|WP_Error|false Term Row from database. 1432 * Will return false if $taxonomy does not exist or $term was not found. 1429 1433 */ 1430 1434 function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') { … … 1530 1534 * @param string $taxonomy Taxonomy Name. 1531 1535 * @param string $context Optional, default is display. Look at sanitize_term_field() for available options. 1532 * @return mixedWill return an empty string if $term is not an object or if $field is not set in $term.1536 * @return string|int|null|WP_Error Will return an empty string if $term is not an object or if $field is not set in $term. 1533 1537 */ 1534 1538 function get_term_field( $field, $term, $taxonomy, $context = 'display' ) { … … 1557 1561 * @param int|object $id Term ID or object. 1558 1562 * @param string $taxonomy Taxonomy name. 1559 * @return mixed|null|WP_Error Will return empty string if $term is not an object.1563 * @return string|int|null|WP_Error Will return empty string if $term is not an object. 1560 1564 */ 1561 1565 function get_term_to_edit( $id, $taxonomy ) { … … 1591 1595 * @since 4.2.0 Introduced 'name' and 'childless' parameters. 1592 1596 * 1593 * @global wpdb $wpdb WordPress database abstraction object. 1597 * @global wpdb $wpdb WordPress database abstraction object. 1598 * @global array $wp_filter 1594 1599 * 1595 1600 * @param string|array $taxonomies Taxonomy name or list of Taxonomy names. … … 1642 1647 * object cache. Default is 'core'. 1643 1648 * } 1644 * @return array| WP_Error List of Term Objects and their children. Will return WP_Error, if any of $taxonomies1649 * @return array|int|WP_Error List of Term Objects and their children. Will return WP_Error, if any of $taxonomies 1645 1650 * do not exist. 1646 1651 */ … … 1656 1661 foreach ( $taxonomies as $taxonomy ) { 1657 1662 if ( ! taxonomy_exists($taxonomy) ) { 1658 $error = new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 1659 return $error; 1663 return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) ); 1660 1664 } 1661 1665 } … … 1754 1758 * @param array $args An array of get_terms() arguments. 1755 1759 */ 1756 $cache = apply_filters( 'get_terms', $cache, $taxonomies, $args ); 1757 return $cache; 1760 return apply_filters( 'get_terms', $cache, $taxonomies, $args ); 1758 1761 } 1759 1762 … … 1996 1999 1997 2000 if ( 'count' == $_fields ) { 1998 $term_count = $wpdb->get_var($query); 1999 return $term_count; 2001 return $wpdb->get_var( $query ); 2000 2002 } 2001 2003 … … 2009 2011 2010 2012 /** This filter is documented in wp-includes/taxonomy.php */ 2011 $terms = apply_filters( 'get_terms', array(), $taxonomies, $args ); 2012 return $terms; 2013 return apply_filters( 'get_terms', array(), $taxonomies, $args ); 2013 2014 } 2014 2015 … … 2083 2084 2084 2085 /** This filter is documented in wp-includes/taxonomy */ 2085 $terms = apply_filters( 'get_terms', $terms, $taxonomies, $args ); 2086 return $terms; 2086 return apply_filters( 'get_terms', $terms, $taxonomies, $args ); 2087 2087 } 2088 2088 … … 2096 2096 * @global wpdb $wpdb WordPress database abstraction object. 2097 2097 * 2098 * @param int|string $term The term to check2099 * @param string $taxonomy The taxonomy name to use2100 * @param int $parentOptional. ID of parent term under which to confine the exists search.2098 * @param int|string $term The term to check 2099 * @param string $taxonomy The taxonomy name to use 2100 * @param int $parent Optional. ID of parent term under which to confine the exists search. 2101 2101 * @return mixed Returns null if the term does not exist. Returns the term ID 2102 2102 * if no taxonomy is specified and the term ID exists. Returns … … 2197 2197 */ 2198 2198 function sanitize_term($term, $taxonomy, $context = 'display') { 2199 2200 2199 $fields = array( 'term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group', 'term_taxonomy_id', 'object_id' ); 2201 2200 … … 2236 2235 * 2237 2236 * @since 2.3.0 2238 *2239 * @global wpdb $wpdb WordPress database abstraction object.2240 2237 * 2241 2238 * @param string $field Term field to sanitize. … … 2404 2401 * @since 2.3.0 2405 2402 * 2406 * @param string $taxonomy Taxonomy name2407 * @param array|string $args Overwrite defaults. See get_terms()2408 * @return int|WP_Error How many terms are in $taxonomy. WP_Error if $taxonomy does not exist.2403 * @param string $taxonomy Taxonomy name 2404 * @param array|string $args Overwrite defaults. See get_terms() 2405 * @return array|int|WP_Error How many terms are in $taxonomy. WP_Error if $taxonomy does not exist. 2409 2406 */ 2410 2407 function wp_count_terms( $taxonomy, $args = array() ) { … … 2432 2429 * @since 2.3.0 2433 2430 * 2434 * @param int $object_idThe term Object Id that refers to the term.2431 * @param int $object_id The term Object Id that refers to the term. 2435 2432 * @param string|array $taxonomies List of Taxonomy Names or single Taxonomy name. 2436 2433 */ … … 2469 2466 * @param string $taxonomy Taxonomy Name. 2470 2467 * @param array|string $args Optional. Change 'default' term id and override found term ids. 2471 * @return bool| WP_Error Returns false if not term; true if completes delete action.2468 * @return bool|int|WP_Error Returns false if not term; true if completes delete action. 2472 2469 */ 2473 2470 function wp_delete_term( $term, $taxonomy, $args = array() ) { … … 2634 2631 * 2635 2632 * @param int $cat_ID 2636 * @return mixedReturns true if completes delete action; false if term doesn't exist;2633 * @return bool|int|WP_Error Returns true if completes delete action; false if term doesn't exist; 2637 2634 * Zero on attempted deletion of default Category; WP_Error object is also a possibility. 2638 2635 */ … … 3633 3630 * @since 2.5.0 3634 3631 * 3632 * @staticvar bool $_defer 3633 * 3635 3634 * @param bool $defer Optional. Enable if true, disable if false. 3636 3635 * @return bool Whether term counting is enabled or disabled. … … 3660 3659 * @since 2.3.0 3661 3660 * 3662 * @ global wpdb $wpdb WordPress database abstraction object.3661 * @staticvar array $_deferred 3663 3662 * 3664 3663 * @param int|array $terms The term_taxonomy_id of the terms. … … 3699 3698 * @param array $terms The term_taxonomy_id of terms to update. 3700 3699 * @param string $taxonomy The context of the term. 3701 * @return boolAlways true when complete.3700 * @return true Always true when complete. 3702 3701 */ 3703 3702 function wp_update_term_count_now( $terms, $taxonomy ) { … … 3775 3774 * 3776 3775 * @global wpdb $wpdb WordPress database abstraction object. 3776 * @global bool $_wp_suspend_cache_invalidation 3777 3777 * 3778 3778 * @param int|array $ids Single or list of Term IDs. … … 3844 3844 * @param int $id Term object ID. 3845 3845 * @param string $taxonomy Taxonomy name. 3846 * @return bool| arrayEmpty array if $terms found, but not `$taxonomy`. False if nothing is in cache3846 * @return bool|mixed Empty array if $terms found, but not `$taxonomy`. False if nothing is in cache 3847 3847 * for `$taxonomy` and `$id`. 3848 3848 */ 3849 3849 function get_object_term_cache( $id, $taxonomy ) { 3850 $cache = wp_cache_get($id, "{$taxonomy}_relationships"); 3851 return $cache; 3850 return wp_cache_get( $id, "{$taxonomy}_relationships" ); 3852 3851 } 3853 3852 … … 3866 3865 * @param string|array $object_ids Comma-separated list or array of term object IDs. 3867 3866 * @param array|string $object_type The taxonomy object type. 3868 * @return null|false Null if `$object_ids` is empty, false if all of the terms in 3869 * `$object_ids` are already cached. 3867 * @return void|false False if all of the terms in `$object_ids` are already cached. 3870 3868 */ 3871 3869 function update_object_term_cache($object_ids, $object_type) { … … 3982 3980 * to prevent infinite recursion loops. For performance, `term_ids` are used as array keys, 3983 3981 * with 1 as value. Default empty array. 3984 * @return array The subset of $terms that are descendants of $term_id.3982 * @return array|WP_Error The subset of $terms that are descendants of $term_id. 3985 3983 */ 3986 3984 function _get_term_children( $term_id, $terms, $taxonomy, &$ancestors = array() ) { … … 4046 4044 * @param array $terms List of term IDs, passed by reference. 4047 4045 * @param string $taxonomy Term context. 4048 * @return null Will break from function if conditions are not met.4049 4046 */ 4050 4047 function _pad_term_counts( &$terms, $taxonomy ) { … … 4117 4114 * @global wpdb $wpdb WordPress database abstraction object. 4118 4115 * 4119 * @param array $termsList of Term taxonomy IDs.4116 * @param array $terms List of Term taxonomy IDs. 4120 4117 * @param object $taxonomy Current taxonomy object of terms. 4121 4118 */ … … 4166 4163 * @global wpdb $wpdb WordPress database abstraction object. 4167 4164 * 4168 * @param array $termsList of term taxonomy IDs.4165 * @param array $terms List of term taxonomy IDs. 4169 4166 * @param object $taxonomy Current taxonomy object of terms. 4170 4167 */ … … 4189 4186 * @ignore 4190 4187 * @since 4.2.0 4188 * 4189 * @global wpdb $wpdb 4191 4190 * 4192 4191 * @param int $term_id ID of the shared term. … … 4310 4309 * @ignore 4311 4310 * @since 4.2.0 4311 * 4312 * @global wpdb $wpdb 4312 4313 * 4313 4314 * @param int $term_id ID of the formerly shared term. … … 4363 4364 * @param int $old_term_id Term ID. This is the old, pre-split term ID. 4364 4365 * @param string $taxonomy Taxonomy that the term belongs to. 4365 * @return bool|intIf a previously split term is found corresponding to the old term_id and taxonomy,4366 * the new term_id will be returned. If no previously split term is found matching4367 * the parameters, returns false.4366 * @return int|false If a previously split term is found corresponding to the old term_id and taxonomy, 4367 * the new term_id will be returned. If no previously split term is found matching 4368 * the parameters, returns false. 4368 4369 */ 4369 4370 function wp_get_split_term( $old_term_id, $taxonomy ) { … … 4383 4384 * @since 2.5.0 4384 4385 * @since 4.3.0 Introduced `$field` argument. 4386 * 4387 * @global WP_Rewrite $wp_rewrite 4385 4388 * 4386 4389 * @param object|int|string $term The term object, ID, or slug whose link will be retrieved. … … 4657 4660 * @return bool True if object is associated with the taxonomy, otherwise false. 4658 4661 */ 4659 function is_object_in_taxonomy($object_type, $taxonomy) { 4660 $taxonomies = get_object_taxonomies($object_type); 4661 4662 if ( empty($taxonomies) ) 4662 function is_object_in_taxonomy( $object_type, $taxonomy ) { 4663 $taxonomies = get_object_taxonomies( $object_type ); 4664 if ( empty( $taxonomies ) ) { 4663 4665 return false; 4664 4665 if ( in_array($taxonomy, $taxonomies) ) 4666 return true; 4667 4668 return false; 4666 } 4667 return in_array( $taxonomy, $taxonomies ); 4669 4668 } 4670 4669 … … 4732 4731 * @param int $term_id Term ID. 4733 4732 * @param string $taxonomy Taxonomy name. 4734 * @return int| boolFalse on error.4733 * @return int|false False on error. 4735 4734 */ 4736 4735 function wp_get_term_taxonomy_parent_id( $term_id, $taxonomy ) { 4737 4736 $term = get_term( $term_id, $taxonomy ); 4738 if ( ! $term || is_wp_error( $term ) )4737 if ( ! $term || is_wp_error( $term ) ) { 4739 4738 return false; 4739 } 4740 4740 return (int) $term->parent; 4741 4741 }
Note: See TracChangeset
for help on using the changeset viewer.