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