Ticket #13747: 13747.diff
File 13747.diff, 13.7 KB (added by , 15 years ago) |
---|
-
wp-includes/taxonomy.php
142 142 * @since 2.3.0 143 143 * 144 144 * @uses $wp_taxonomies 145 * @uses is_taxonomy() Checks whether taxonomy exists145 * @uses taxonomy_exists() Checks whether taxonomy exists 146 146 * 147 147 * @param string $taxonomy Name of taxonomy object to return 148 148 * @return object|bool The Taxonomy Object or false if $taxonomy doesn't exist … … 150 150 function get_taxonomy( $taxonomy ) { 151 151 global $wp_taxonomies; 152 152 153 if ( ! is_taxonomy($taxonomy) )153 if ( ! taxonomy_exists( $taxonomy ) ) 154 154 return false; 155 155 156 156 return $wp_taxonomies[$taxonomy]; … … 159 159 /** 160 160 * Checks that the taxonomy name exists. 161 161 * 162 * Formerly is_taxonomy(), introduced in 2.3.0. 163 * 162 164 * @package WordPress 163 165 * @subpackage Taxonomy 164 * @since 2.3.0166 * @since 3.0.0 165 167 * 166 168 * @uses $wp_taxonomies 167 169 * 168 170 * @param string $taxonomy Name of taxonomy object 169 171 * @return bool Whether the taxonomy exists. 170 172 */ 171 function is_taxonomy( $taxonomy ) {173 function taxonomy_exists( $taxonomy ) { 172 174 global $wp_taxonomies; 173 175 174 return isset( $wp_taxonomies[$taxonomy]);176 return isset( $wp_taxonomies[$taxonomy] ); 175 177 } 176 178 177 179 /** … … 186 188 * @subpackage Taxonomy 187 189 * @since 2.3.0 188 190 * 189 * @uses is_taxonomy() Checks whether taxonomy exists191 * @uses taxonomy_exists() Checks whether taxonomy exists 190 192 * @uses get_taxonomy() Used to get the taxonomy object 191 193 * 192 194 * @param string $taxonomy Name of taxonomy object 193 195 * @return bool Whether the taxonomy is hierarchical 194 196 */ 195 197 function is_taxonomy_hierarchical($taxonomy) { 196 if ( ! is_taxonomy($taxonomy) )198 if ( ! taxonomy_exists($taxonomy) ) 197 199 return false; 198 200 199 201 $taxonomy = get_taxonomy($taxonomy); … … 208 210 * parameter), along with strings for the taxonomy name and another string for 209 211 * the object type. 210 212 * 211 * 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 212 214 * whether taxonomy exists. 213 215 * 214 216 * Optional $args contents: … … 428 430 $taxonomies = array( $taxonomies ); 429 431 430 432 foreach ( (array) $taxonomies as $taxonomy ) { 431 if ( ! is_taxonomy( $taxonomy ) )433 if ( ! taxonomy_exists( $taxonomy ) ) 432 434 return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) ); 433 435 } 434 436 … … 500 502 return $error; 501 503 } 502 504 503 if ( ! is_taxonomy($taxonomy) ) {505 if ( ! taxonomy_exists($taxonomy) ) { 504 506 $error = new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); 505 507 return $error; 506 508 } … … 567 569 function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') { 568 570 global $wpdb; 569 571 570 if ( ! is_taxonomy($taxonomy) )572 if ( ! taxonomy_exists($taxonomy) ) 571 573 return false; 572 574 573 575 if ( 'slug' == $field ) { … … 625 627 * @return array|WP_Error List of Term Objects. WP_Error returned if $taxonomy does not exist 626 628 */ 627 629 function get_term_children( $term_id, $taxonomy ) { 628 if ( ! is_taxonomy($taxonomy) )630 if ( ! taxonomy_exists($taxonomy) ) 629 631 return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); 630 632 631 633 $term_id = intval( $term_id ); … … 810 812 } 811 813 812 814 foreach ( (array) $taxonomies as $taxonomy ) { 813 if ( ! is_taxonomy($taxonomy) ) {815 if ( ! taxonomy_exists($taxonomy) ) { 814 816 $error = & new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); 815 817 return $error; 816 818 } … … 1062 1064 * 1063 1065 * Returns the index of a defined term, or 0 (false) if the term doesn't exist. 1064 1066 * 1067 * Formerly is_term(), introduced in 2.3.0. 1068 * 1065 1069 * @package WordPress 1066 1070 * @subpackage Taxonomy 1067 * @since 2.3.01071 * @since 3.0.0 1068 1072 * 1069 1073 * @uses $wpdb 1070 1074 * … … 1073 1077 * @param int $parent ID of parent term under which to confine the exists search. 1074 1078 * @return mixed Get the term id or Term Object, if exists. 1075 1079 */ 1076 function is_term($term, $taxonomy = '', $parent = 0) {1080 function term_exists($term, $taxonomy = '', $parent = 0) { 1077 1081 global $wpdb; 1078 1082 1079 1083 $select = "SELECT term_id FROM $wpdb->terms as t WHERE "; … … 1334 1338 1335 1339 $term = (int) $term; 1336 1340 1337 if ( ! $ids = is_term($term, $taxonomy) )1341 if ( ! $ids = term_exists($term, $taxonomy) ) 1338 1342 return false; 1339 1343 if ( is_wp_error( $ids ) ) 1340 1344 return $ids; … … 1347 1351 1348 1352 if ( isset($default) ) { 1349 1353 $default = (int) $default; 1350 if ( ! is_term($default, $taxonomy) )1354 if ( ! term_exists($default, $taxonomy) ) 1351 1355 unset($default); 1352 1356 } 1353 1357 … … 1434 1438 $taxonomies = array($taxonomies); 1435 1439 1436 1440 foreach ( (array) $taxonomies as $taxonomy ) { 1437 if ( ! is_taxonomy($taxonomy) )1441 if ( ! taxonomy_exists($taxonomy) ) 1438 1442 return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); 1439 1443 } 1440 1444 … … 1572 1576 function wp_insert_term( $term, $taxonomy, $args = array() ) { 1573 1577 global $wpdb; 1574 1578 1575 if ( ! is_taxonomy($taxonomy) )1579 if ( ! taxonomy_exists($taxonomy) ) 1576 1580 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 1577 1581 1578 1582 $term = apply_filters( 'pre_insert_term', $term, $taxonomy ); … … 1614 1618 } 1615 1619 } 1616 1620 1617 if ( $term_id = is_term($slug) ) {1621 if ( $term_id = term_exists($slug) ) { 1618 1622 $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); 1619 1623 // We've got an existing term in the same taxonomy, which matches the name of the new term: 1620 if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && is_term( (int) $term_id, $taxonomy ) ) {1624 if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && term_exists( (int) $term_id, $taxonomy ) ) { 1621 1625 // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level. 1622 1626 $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => (int)$parent) ); 1623 1627 if ( in_array($name, $siblings) ) { … … 1634 1638 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) 1635 1639 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 1636 1640 $term_id = (int) $wpdb->insert_id; 1637 } elseif ( is_term( (int) $term_id, $taxonomy ) ) {1641 } elseif ( term_exists( (int) $term_id, $taxonomy ) ) { 1638 1642 // Same name, same slug. 1639 1643 return new WP_Error('term_exists', __('A term with the name provided already exists.')); 1640 1644 } … … 1703 1707 1704 1708 $object_id = (int) $object_id; 1705 1709 1706 if ( ! is_taxonomy($taxonomy) )1710 if ( ! taxonomy_exists($taxonomy) ) 1707 1711 return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); 1708 1712 1709 1713 if ( !is_array($terms) ) … … 1721 1725 if ( !strlen(trim($term)) ) 1722 1726 continue; 1723 1727 1724 if ( !$term_info = is_term($term, $taxonomy) ) {1728 if ( !$term_info = term_exists($term, $taxonomy) ) { 1725 1729 // Skip if a non-existent term ID is passed. 1726 1730 if ( is_int($term) ) 1727 1731 continue; … … 1796 1800 function wp_unique_term_slug($slug, $term) { 1797 1801 global $wpdb; 1798 1802 1799 if ( ! is_term( $slug ) )1803 if ( ! term_exists( $slug ) ) 1800 1804 return $slug; 1801 1805 1802 1806 // If the taxonomy supports hierarchy and the term has a parent, make the slug unique … … 1808 1812 if ( is_wp_error($parent_term) || empty($parent_term) ) 1809 1813 break; 1810 1814 $slug .= '-' . $parent_term->slug; 1811 if ( ! is_term( $slug ) )1815 if ( ! term_exists( $slug ) ) 1812 1816 return $slug; 1813 1817 1814 1818 if ( empty($parent_term->parent) ) … … 1874 1878 function wp_update_term( $term_id, $taxonomy, $args = array() ) { 1875 1879 global $wpdb; 1876 1880 1877 if ( ! is_taxonomy($taxonomy) )1881 if ( ! taxonomy_exists($taxonomy) ) 1878 1882 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 1879 1883 1880 1884 $term_id = (int) $term_id; -
wp-includes/post.php
670 670 * @return bool Whether post type is hierarchical. 671 671 */ 672 672 function is_post_type_hierarchical( $post_type ) { 673 if ( ! is_post_type( $post_type ) )673 if ( ! post_type_exists( $post_type ) ) 674 674 return false; 675 675 676 676 $post_type = get_post_type_object( $post_type ); … … 681 681 * Checks if a post type is registered. 682 682 * 683 683 * @since 3.0.0 684 * @uses get_post_type ()684 * @uses get_post_type_object() 685 685 * 686 686 * @param string Post type name 687 687 * @return bool Whether post type is registered. 688 688 */ 689 function is_post_type( $post_type ) {689 function post_type_exists( $post_type ) { 690 690 return (bool) get_post_type_object( $post_type ); 691 691 } 692 692 -
wp-includes/default-widgets.php
1041 1041 } 1042 1042 1043 1043 function _get_current_taxonomy($instance) { 1044 if ( !empty($instance['taxonomy']) && is_taxonomy($instance['taxonomy']) )1044 if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) ) 1045 1045 return $instance['taxonomy']; 1046 1046 1047 1047 return 'post_tag'; -
wp-includes/deprecated.php
2513 2513 _deprecated_function( __FUNCTION__, '3.0' ); 2514 2514 return ''; 2515 2515 } 2516 2517 /** 2518 * Checks if a post type is registered. 2519 * 2520 * @since 3.0.0 2521 * @deprecated 3.0.0 2522 * @deprecated Use post_type_exists() 2523 * @see post_type_exists() 2524 * 2525 * @param string Post type name 2526 * @return bool Whether post type is registered. 2527 */ 2528 function is_post_type( $post_type ) { 2529 _deprecated_function( __FUNCTION__, '3.0', 'post_type_exists()' ); 2530 return post_type_exists( $post_type ); 2531 } 2532 2533 /** 2534 * Checks that the taxonomy name exists. 2535 * 2536 * @since 2.3.0 2537 * @deprecated 3.0.0 2538 * @deprecated Use taxonomy_exists() 2539 * @see taxonomy_exists() 2540 * 2541 * @param string $taxonomy Name of taxonomy object 2542 * @return bool Whether the taxonomy exists. 2543 */ 2544 function is_taxonomy( $taxonomy ) { 2545 _deprecated_function( __FUNCTION__, '3.0', 'taxonomy_exists()' ); 2546 return taxonomy_exists( $post_type ); 2547 } 2548 2549 /** 2550 * Check if Term exists. 2551 * 2552 * @since 2.3.0 2553 * @deprecated 3.0.0 2554 * @deprecated Use term_exists() 2555 * @see term_exists() 2556 * 2557 * @param int|string $term The term to check 2558 * @param string $taxonomy The taxonomy name to use 2559 * @param int $parent ID of parent term under which to confine the exists search. 2560 * @return mixed Get the term id or Term Object, if exists. 2561 */ 2562 function term_exists( $term, $taxonomy = '', $parent = 0 ) { 2563 _deprecated_function( __FUNCTION__, '3.0', 'term_exists()' ); 2564 return term_exists( $term, $taxonomy, $parent ); 2565 } 2566 No newline at end of file -
wp-includes/category-template.php
482 482 483 483 extract( $r ); 484 484 485 if ( ! is_taxonomy($taxonomy) )485 if ( !taxonomy_exists($taxonomy) ) 486 486 return false; 487 487 488 488 $categories = get_categories( $r ); -
wp-admin/admin-ajax.php
237 237 $category_nicename = sanitize_title($cat_name); 238 238 if ( '' === $category_nicename ) 239 239 continue; 240 if ( !($cat_id = is_term($cat_name, $taxonomy->name, $parent)) ) {240 if ( !($cat_id = term_exists($cat_name, $taxonomy->name, $parent)) ) { 241 241 $new_term = wp_insert_term($cat_name, $taxonomy->name, array('parent' => $parent)); 242 242 $cat_id = $new_term['term_id']; 243 243 } … … 501 501 $slug = sanitize_title($cat_name); 502 502 if ( '' === $slug ) 503 503 continue; 504 if ( !$cat_id = is_term( $cat_name, 'link_category' ) ) {504 if ( !$cat_id = term_exists( $cat_name, 'link_category' ) ) { 505 505 $cat_id = wp_insert_term( $cat_name, 'link_category' ); 506 506 } 507 507 $cat_id = $cat_id['term_id']; -
wp-admin/includes/taxonomy.php
19 19 * @return unknown 20 20 */ 21 21 function category_exists($cat_name, $parent = 0) { 22 $id = is_term($cat_name, 'category', $parent);22 $id = term_exists($cat_name, 'category', $parent); 23 23 if ( is_array($id) ) 24 24 $id = $id['term_id']; 25 25 return $id; … … 240 240 * @return unknown 241 241 */ 242 242 function tag_exists($tag_name) { 243 return is_term($tag_name, 'post_tag');243 return term_exists($tag_name, 'post_tag'); 244 244 } 245 245 246 246 /** … … 264 264 * @return unknown 265 265 */ 266 266 function wp_create_term($tag_name, $taxonomy = 'post_tag') { 267 if ( $id = is_term($tag_name, $taxonomy) )267 if ( $id = term_exists($tag_name, $taxonomy) ) 268 268 return $id; 269 269 270 270 return wp_insert_term($tag_name, $taxonomy); -
wp-admin/includes/nav-menu.php
271 271 } 272 272 273 273 if ( 'get-post-item' == $type ) { 274 if ( get_post_type_object( $object_type ) ) {274 if ( post_type_exists( $object_type ) ) { 275 275 if ( isset( $request['ID'] ) ) { 276 276 $object_id = (int) $request['ID']; 277 277 if ( 'markup' == $response_format ) { … … 288 288 echo "\n"; 289 289 } 290 290 } 291 } elseif ( is_taxonomy( $object_type ) ) {291 } elseif ( taxonomy_exists( $object_type ) ) { 292 292 if ( isset( $request['ID'] ) ) { 293 293 $object_id = (int) $request['ID']; 294 294 if ( 'markup' == $response_format ) { -
wp-admin/edit-tags.php
14 14 if ( empty($taxonomy) ) 15 15 $taxonomy = 'post_tag'; 16 16 17 if ( ! is_taxonomy($taxonomy) )17 if ( !taxonomy_exists($taxonomy) ) 18 18 wp_die(__('Invalid taxonomy')); 19 19 20 20 $tax = get_taxonomy($taxonomy);