Changes in trunk/wp-includes/taxonomy.php [15220:14934]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/taxonomy.php
r15220 r14934 46 46 'show_ui' => false, 47 47 '_builtin' => true, 48 'show_in_nav_menus' => false,49 48 ) ) ; 50 49 … … 143 142 * 144 143 * @uses $wp_taxonomies 145 * @uses taxonomy_exists() Checks whether taxonomy exists144 * @uses is_taxonomy() Checks whether taxonomy exists 146 145 * 147 146 * @param string $taxonomy Name of taxonomy object to return … … 151 150 global $wp_taxonomies; 152 151 153 if ( ! taxonomy_exists( $taxonomy) )152 if ( ! is_taxonomy($taxonomy) ) 154 153 return false; 155 154 … … 160 159 * Checks that the taxonomy name exists. 161 160 * 162 * Formerly is_taxonomy(), introduced in 2.3.0. 163 * 164 * @package WordPress 165 * @subpackage Taxonomy 166 * @since 3.0.0 161 * @package WordPress 162 * @subpackage Taxonomy 163 * @since 2.3.0 167 164 * 168 165 * @uses $wp_taxonomies … … 171 168 * @return bool Whether the taxonomy exists. 172 169 */ 173 function taxonomy_exists( $taxonomy ) {170 function is_taxonomy( $taxonomy ) { 174 171 global $wp_taxonomies; 175 172 176 return isset( $wp_taxonomies[$taxonomy]);173 return isset($wp_taxonomies[$taxonomy]); 177 174 } 178 175 … … 189 186 * @since 2.3.0 190 187 * 191 * @uses taxonomy_exists() Checks whether taxonomy exists188 * @uses is_taxonomy() Checks whether taxonomy exists 192 189 * @uses get_taxonomy() Used to get the taxonomy object 193 190 * … … 196 193 */ 197 194 function is_taxonomy_hierarchical($taxonomy) { 198 if ( ! taxonomy_exists($taxonomy) )195 if ( ! is_taxonomy($taxonomy) ) 199 196 return false; 200 197 … … 211 208 * the object type. 212 209 * 213 * Nothing is returned, so expect error maybe or use taxonomy_exists() to check210 * Nothing is returned, so expect error maybe or use is_taxonomy() to check 214 211 * whether taxonomy exists. 215 212 * … … 235 232 * show_ui - If the WordPress UI admin tags UI should apply to this taxonomy; 236 233 * defaults to public. 237 *238 * show_in_nav_menus - true makes this taxonomy available for selection in navigation menus.239 * Defaults to public.240 234 * 241 235 * show_tagcloud - false to prevent the taxonomy being listed in the Tag Cloud Widget; … … 271 265 'labels' => array(), 272 266 'capabilities' => array(), 273 'show_in_nav_menus' => null,274 267 ); 275 268 $args = wp_parse_args($args, $defaults); … … 293 286 if ( is_null($args['show_ui']) ) 294 287 $args['show_ui'] = $args['public']; 295 296 // Whether to show this type in nav-menus.php. Defaults to the setting for public.297 if ( null === $args['show_in_nav_menus'] )298 $args['show_in_nav_menus'] = $args['public'];299 288 300 289 if ( is_null($args['show_tagcloud']) ) … … 329 318 * - singular_name - name for one object of this taxonomy. Default is Post Tag/Category 330 319 * - search_items - Default is Search Tags/Search Categories 331 * - popular_items - This string isn't used on hierarchical taxonomies. Default is Popular Tags320 * - popular_items - Default is Popular Tags/Popular Categories 332 321 * - all_items - Default is All Tags/All Categories 333 322 * - parent_item - This string isn't used on non-hierarchical taxonomies. In hierarchical ones the default is Parent Category … … 337 326 * - add_new_item - Default is Add New Tag/Add New Category 338 327 * - new_item_name - Default is New Tag Name/New Category Name 339 * - separate_items_with_commas - This string isn't used on hierarchical taxonomies. Default is "Separate tags with commas," used in the meta box.340 * - add_or_remove_items - This string isn't used on hierarchical taxonomies. Default is "Add or remove tags," used in the meta box when JavaScript is disabled.341 * - choose_from_most_used - This string isn't used on hierarchical taxonomies. Default is "Choose from the most used tags," used in the meta box.342 328 * 343 329 * Above, the first default value is for non-hierarchical taxonomies (like tags) and the second one is for hierarchical taxonomies (like categories.) … … 349 335 350 336 function get_taxonomy_labels( $tax ) { 351 if ( isset( $tax->helps ) && empty( $tax->labels['separate_items_with_commas'] ) )352 $tax->labels['separate_items_with_commas'] = $tax->helps;353 354 337 $nohier_vs_hier_defaults = array( 355 338 'name' => array( _x( 'Post Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ), 356 339 'singular_name' => array( _x( 'Post Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ), 357 340 'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ), 358 'popular_items' => array( __( 'Popular Tags' ), null),341 'popular_items' => array( __( 'Popular Tags' ), __( 'Popular Category' ) ), 359 342 'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ), 360 343 'parent_item' => array( null, __( 'Parent Category' ) ), … … 364 347 'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ), 365 348 'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ), 366 'separate_items_with_commas' => array( __( 'Separate tags with commas' ), null ),367 'add_or_remove_items' => array( __( 'Add or remove tags' ), null ),368 'choose_from_most_used' => array( __( 'Choose from the most used tags' ), null ),369 349 ); 370 350 … … 440 420 441 421 foreach ( (array) $taxonomies as $taxonomy ) { 442 if ( ! taxonomy_exists( $taxonomy ) )422 if ( ! is_taxonomy( $taxonomy ) ) 443 423 return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) ); 444 424 } … … 512 492 } 513 493 514 if ( ! taxonomy_exists($taxonomy) ) {494 if ( ! is_taxonomy($taxonomy) ) { 515 495 $error = new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); 516 496 return $error; … … 579 559 global $wpdb; 580 560 581 if ( ! taxonomy_exists($taxonomy) )561 if ( ! is_taxonomy($taxonomy) ) 582 562 return false; 583 563 … … 637 617 */ 638 618 function get_term_children( $term_id, $taxonomy ) { 639 if ( ! taxonomy_exists($taxonomy) )619 if ( ! is_taxonomy($taxonomy) ) 640 620 return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); 641 621 … … 822 802 823 803 foreach ( (array) $taxonomies as $taxonomy ) { 824 if ( ! taxonomy_exists($taxonomy) ) {804 if ( ! is_taxonomy($taxonomy) ) { 825 805 $error = & new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); 826 806 return $error; … … 1074 1054 * Returns the index of a defined term, or 0 (false) if the term doesn't exist. 1075 1055 * 1076 * Formerly is_term(), introduced in 2.3.0. 1077 * 1078 * @package WordPress 1079 * @subpackage Taxonomy 1080 * @since 3.0.0 1056 * @package WordPress 1057 * @subpackage Taxonomy 1058 * @since 2.3.0 1081 1059 * 1082 1060 * @uses $wpdb … … 1087 1065 * @return mixed Get the term id or Term Object, if exists. 1088 1066 */ 1089 function term_exists($term, $taxonomy = '', $parent = 0) {1067 function is_term($term, $taxonomy = '', $parent = 0) { 1090 1068 global $wpdb; 1091 1069 … … 1348 1326 $term = (int) $term; 1349 1327 1350 if ( ! $ids = term_exists($term, $taxonomy) )1328 if ( ! $ids = is_term($term, $taxonomy) ) 1351 1329 return false; 1352 1330 if ( is_wp_error( $ids ) ) … … 1361 1339 if ( isset($default) ) { 1362 1340 $default = (int) $default; 1363 if ( ! term_exists($default, $taxonomy) )1341 if ( ! is_term($default, $taxonomy) ) 1364 1342 unset($default); 1365 1343 } … … 1448 1426 1449 1427 foreach ( (array) $taxonomies as $taxonomy ) { 1450 if ( ! taxonomy_exists($taxonomy) )1428 if ( ! is_taxonomy($taxonomy) ) 1451 1429 return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); 1452 1430 } … … 1586 1564 global $wpdb; 1587 1565 1588 if ( ! taxonomy_exists($taxonomy) )1566 if ( ! is_taxonomy($taxonomy) ) 1589 1567 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 1590 1568 … … 1628 1606 } 1629 1607 1630 if ( $term_id = term_exists($slug) ) {1608 if ( $term_id = is_term($slug) ) { 1631 1609 $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); 1632 1610 // We've got an existing term in the same taxonomy, which matches the name of the new term: 1633 if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && term_exists( (int) $term_id, $taxonomy ) ) {1611 if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && is_term( (int) $term_id, $taxonomy ) ) { 1634 1612 // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level. 1635 1613 $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => (int)$parent) ); … … 1648 1626 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 1649 1627 $term_id = (int) $wpdb->insert_id; 1650 } elseif ( term_exists( (int) $term_id, $taxonomy ) ) {1628 } elseif ( is_term( (int) $term_id, $taxonomy ) ) { 1651 1629 // Same name, same slug. 1652 1630 return new WP_Error('term_exists', __('A term with the name provided already exists.')); … … 1717 1695 $object_id = (int) $object_id; 1718 1696 1719 if ( ! taxonomy_exists($taxonomy) )1697 if ( ! is_taxonomy($taxonomy) ) 1720 1698 return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); 1721 1699 … … 1735 1713 continue; 1736 1714 1737 if ( !$term_info = term_exists($term, $taxonomy) ) {1715 if ( !$term_info = is_term($term, $taxonomy) ) { 1738 1716 // Skip if a non-existent term ID is passed. 1739 1717 if ( is_int($term) ) … … 1810 1788 global $wpdb; 1811 1789 1812 if ( ! term_exists( $slug ) )1790 if ( ! is_term( $slug ) ) 1813 1791 return $slug; 1814 1792 … … 1822 1800 break; 1823 1801 $slug .= '-' . $parent_term->slug; 1824 if ( ! term_exists( $slug ) )1802 if ( ! is_term( $slug ) ) 1825 1803 return $slug; 1826 1804 … … 1888 1866 global $wpdb; 1889 1867 1890 if ( ! taxonomy_exists($taxonomy) )1868 if ( ! is_taxonomy($taxonomy) ) 1891 1869 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 1892 1870 … … 2407 2385 2408 2386 // Get the object and term ids and stick them in a lookup table 2409 $tax_obj = get_taxonomy($taxonomy); 2410 $object_types = esc_sql($tax_obj->object_type); 2411 $results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode(',', array_keys($term_ids)) . ") AND post_type IN ('" . implode("', '", $object_types) . "') AND post_status = 'publish'"); 2387 $results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (".join(',', array_keys($term_ids)).") AND post_type = 'post' AND post_status = 'publish'"); 2412 2388 foreach ( $results as $row ) { 2413 2389 $id = $term_ids[$row->term_taxonomy_id];
Note: See TracChangeset
for help on using the changeset viewer.