Make WordPress Core

Ticket #13747: 13747.diff

File 13747.diff, 13.7 KB (added by nacin, 15 years ago)
  • wp-includes/taxonomy.php

     
    142142 * @since 2.3.0
    143143 *
    144144 * @uses $wp_taxonomies
    145  * @uses is_taxonomy() Checks whether taxonomy exists
     145 * @uses taxonomy_exists() Checks whether taxonomy exists
    146146 *
    147147 * @param string $taxonomy Name of taxonomy object to return
    148148 * @return object|bool The Taxonomy Object or false if $taxonomy doesn't exist
     
    150150function get_taxonomy( $taxonomy ) {
    151151        global $wp_taxonomies;
    152152
    153         if ( ! is_taxonomy($taxonomy) )
     153        if ( ! taxonomy_exists( $taxonomy ) )
    154154                return false;
    155155
    156156        return $wp_taxonomies[$taxonomy];
     
    159159/**
    160160 * Checks that the taxonomy name exists.
    161161 *
     162 * Formerly is_taxonomy(), introduced in 2.3.0.
     163 *
    162164 * @package WordPress
    163165 * @subpackage Taxonomy
    164  * @since 2.3.0
     166 * @since 3.0.0
    165167 *
    166168 * @uses $wp_taxonomies
    167169 *
    168170 * @param string $taxonomy Name of taxonomy object
    169171 * @return bool Whether the taxonomy exists.
    170172 */
    171 function is_taxonomy( $taxonomy ) {
     173function taxonomy_exists( $taxonomy ) {
    172174        global $wp_taxonomies;
    173175
    174         return isset($wp_taxonomies[$taxonomy]);
     176        return isset( $wp_taxonomies[$taxonomy] );
    175177}
    176178
    177179/**
     
    186188 * @subpackage Taxonomy
    187189 * @since 2.3.0
    188190 *
    189  * @uses is_taxonomy() Checks whether taxonomy exists
     191 * @uses taxonomy_exists() Checks whether taxonomy exists
    190192 * @uses get_taxonomy() Used to get the taxonomy object
    191193 *
    192194 * @param string $taxonomy Name of taxonomy object
    193195 * @return bool Whether the taxonomy is hierarchical
    194196 */
    195197function is_taxonomy_hierarchical($taxonomy) {
    196         if ( ! is_taxonomy($taxonomy) )
     198        if ( ! taxonomy_exists($taxonomy) )
    197199                return false;
    198200
    199201        $taxonomy = get_taxonomy($taxonomy);
     
    208210 * parameter), along with strings for the taxonomy name and another string for
    209211 * the object type.
    210212 *
    211  * Nothing is returned, so expect error maybe or use is_taxonomy() to check
     213 * Nothing is returned, so expect error maybe or use taxonomy_exists() to check
    212214 * whether taxonomy exists.
    213215 *
    214216 * Optional $args contents:
     
    428430                $taxonomies = array( $taxonomies );
    429431
    430432        foreach ( (array) $taxonomies as $taxonomy ) {
    431                 if ( ! is_taxonomy( $taxonomy ) )
     433                if ( ! taxonomy_exists( $taxonomy ) )
    432434                        return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) );
    433435        }
    434436
     
    500502                return $error;
    501503        }
    502504
    503         if ( ! is_taxonomy($taxonomy) ) {
     505        if ( ! taxonomy_exists($taxonomy) ) {
    504506                $error = new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    505507                return $error;
    506508        }
     
    567569function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') {
    568570        global $wpdb;
    569571
    570         if ( ! is_taxonomy($taxonomy) )
     572        if ( ! taxonomy_exists($taxonomy) )
    571573                return false;
    572574
    573575        if ( 'slug' == $field ) {
     
    625627 * @return array|WP_Error List of Term Objects. WP_Error returned if $taxonomy does not exist
    626628 */
    627629function get_term_children( $term_id, $taxonomy ) {
    628         if ( ! is_taxonomy($taxonomy) )
     630        if ( ! taxonomy_exists($taxonomy) )
    629631                return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    630632
    631633        $term_id = intval( $term_id );
     
    810812        }
    811813
    812814        foreach ( (array) $taxonomies as $taxonomy ) {
    813                 if ( ! is_taxonomy($taxonomy) ) {
     815                if ( ! taxonomy_exists($taxonomy) ) {
    814816                        $error = & new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    815817                        return $error;
    816818                }
     
    10621064 *
    10631065 * Returns the index of a defined term, or 0 (false) if the term doesn't exist.
    10641066 *
     1067 * Formerly is_term(), introduced in 2.3.0.
     1068 *
    10651069 * @package WordPress
    10661070 * @subpackage Taxonomy
    1067  * @since 2.3.0
     1071 * @since 3.0.0
    10681072 *
    10691073 * @uses $wpdb
    10701074 *
     
    10731077 * @param int $parent ID of parent term under which to confine the exists search.
    10741078 * @return mixed Get the term id or Term Object, if exists.
    10751079 */
    1076 function is_term($term, $taxonomy = '', $parent = 0) {
     1080function term_exists($term, $taxonomy = '', $parent = 0) {
    10771081        global $wpdb;
    10781082
    10791083        $select = "SELECT term_id FROM $wpdb->terms as t WHERE ";
     
    13341338
    13351339        $term = (int) $term;
    13361340
    1337         if ( ! $ids = is_term($term, $taxonomy) )
     1341        if ( ! $ids = term_exists($term, $taxonomy) )
    13381342                return false;
    13391343        if ( is_wp_error( $ids ) )
    13401344                return $ids;
     
    13471351
    13481352        if ( isset($default) ) {
    13491353                $default = (int) $default;
    1350                 if ( ! is_term($default, $taxonomy) )
     1354                if ( ! term_exists($default, $taxonomy) )
    13511355                        unset($default);
    13521356        }
    13531357
     
    14341438                $taxonomies = array($taxonomies);
    14351439
    14361440        foreach ( (array) $taxonomies as $taxonomy ) {
    1437                 if ( ! is_taxonomy($taxonomy) )
     1441                if ( ! taxonomy_exists($taxonomy) )
    14381442                        return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    14391443        }
    14401444
     
    15721576function wp_insert_term( $term, $taxonomy, $args = array() ) {
    15731577        global $wpdb;
    15741578
    1575         if ( ! is_taxonomy($taxonomy) )
     1579        if ( ! taxonomy_exists($taxonomy) )
    15761580                return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    15771581
    15781582        $term = apply_filters( 'pre_insert_term', $term, $taxonomy );
     
    16141618                }
    16151619        }
    16161620
    1617         if ( $term_id = is_term($slug) ) {
     1621        if ( $term_id = term_exists($slug) ) {
    16181622                $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A );
    16191623                // 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 ) ) {
    16211625                        // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level.
    16221626                        $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => (int)$parent) );
    16231627                        if ( in_array($name, $siblings) ) {
     
    16341638                        if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
    16351639                                return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
    16361640                        $term_id = (int) $wpdb->insert_id;
    1637                 } elseif ( is_term( (int) $term_id, $taxonomy ) )  {
     1641                } elseif ( term_exists( (int) $term_id, $taxonomy ) )  {
    16381642                        // Same name, same slug.
    16391643                        return new WP_Error('term_exists', __('A term with the name provided already exists.'));
    16401644                }
     
    17031707
    17041708        $object_id = (int) $object_id;
    17051709
    1706         if ( ! is_taxonomy($taxonomy) )
     1710        if ( ! taxonomy_exists($taxonomy) )
    17071711                return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    17081712
    17091713        if ( !is_array($terms) )
     
    17211725                if ( !strlen(trim($term)) )
    17221726                        continue;
    17231727
    1724                 if ( !$term_info = is_term($term, $taxonomy) ) {
     1728                if ( !$term_info = term_exists($term, $taxonomy) ) {
    17251729                        // Skip if a non-existent term ID is passed.
    17261730                        if ( is_int($term) )
    17271731                                continue;
     
    17961800function wp_unique_term_slug($slug, $term) {
    17971801        global $wpdb;
    17981802
    1799         if ( ! is_term( $slug ) )
     1803        if ( ! term_exists( $slug ) )
    18001804                return $slug;
    18011805
    18021806        // If the taxonomy supports hierarchy and the term has a parent, make the slug unique
     
    18081812                        if ( is_wp_error($parent_term) || empty($parent_term) )
    18091813                                break;
    18101814                        $slug .= '-' . $parent_term->slug;
    1811                         if ( ! is_term( $slug ) )
     1815                        if ( ! term_exists( $slug ) )
    18121816                                return $slug;
    18131817
    18141818                        if ( empty($parent_term->parent) )
     
    18741878function wp_update_term( $term_id, $taxonomy, $args = array() ) {
    18751879        global $wpdb;
    18761880
    1877         if ( ! is_taxonomy($taxonomy) )
     1881        if ( ! taxonomy_exists($taxonomy) )
    18781882                return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    18791883
    18801884        $term_id = (int) $term_id;
  • wp-includes/post.php

     
    670670 * @return bool Whether post type is hierarchical.
    671671 */
    672672function is_post_type_hierarchical( $post_type ) {
    673         if ( ! is_post_type( $post_type ) )
     673        if ( ! post_type_exists( $post_type ) )
    674674                return false;
    675675
    676676        $post_type = get_post_type_object( $post_type );
     
    681681 * Checks if a post type is registered.
    682682 *
    683683 * @since 3.0.0
    684  * @uses get_post_type()
     684 * @uses get_post_type_object()
    685685 *
    686686 * @param string Post type name
    687687 * @return bool Whether post type is registered.
    688688 */
    689 function is_post_type( $post_type ) {
     689function post_type_exists( $post_type ) {
    690690        return (bool) get_post_type_object( $post_type );
    691691}
    692692
  • wp-includes/default-widgets.php

     
    10411041        }
    10421042
    10431043        function _get_current_taxonomy($instance) {
    1044                 if ( !empty($instance['taxonomy']) && is_taxonomy($instance['taxonomy']) )
     1044                if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
    10451045                        return $instance['taxonomy'];
    10461046
    10471047                return 'post_tag';
  • wp-includes/deprecated.php

     
    25132513        _deprecated_function( __FUNCTION__, '3.0' );
    25142514        return '';
    25152515}
     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 */
     2528function 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 */
     2544function 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 */
     2562function 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

     
    482482
    483483        extract( $r );
    484484
    485         if ( !is_taxonomy($taxonomy) )
     485        if ( !taxonomy_exists($taxonomy) )
    486486                return false;
    487487
    488488        $categories = get_categories( $r );
  • wp-admin/admin-ajax.php

     
    237237                $category_nicename = sanitize_title($cat_name);
    238238                if ( '' === $category_nicename )
    239239                        continue;
    240                 if ( !($cat_id = is_term($cat_name, $taxonomy->name, $parent)) ) {
     240                if ( !($cat_id = term_exists($cat_name, $taxonomy->name, $parent)) ) {
    241241                        $new_term = wp_insert_term($cat_name, $taxonomy->name, array('parent' => $parent));
    242242                        $cat_id = $new_term['term_id'];
    243243                }
     
    501501                $slug = sanitize_title($cat_name);
    502502                if ( '' === $slug )
    503503                        continue;
    504                 if ( !$cat_id = is_term( $cat_name, 'link_category' ) ) {
     504                if ( !$cat_id = term_exists( $cat_name, 'link_category' ) ) {
    505505                        $cat_id = wp_insert_term( $cat_name, 'link_category' );
    506506                }
    507507                $cat_id = $cat_id['term_id'];
  • wp-admin/includes/taxonomy.php

     
    1919 * @return unknown
    2020 */
    2121function category_exists($cat_name, $parent = 0) {
    22         $id = is_term($cat_name, 'category', $parent);
     22        $id = term_exists($cat_name, 'category', $parent);
    2323        if ( is_array($id) )
    2424                $id = $id['term_id'];
    2525        return $id;
     
    240240 * @return unknown
    241241 */
    242242function tag_exists($tag_name) {
    243         return is_term($tag_name, 'post_tag');
     243        return term_exists($tag_name, 'post_tag');
    244244}
    245245
    246246/**
     
    264264 * @return unknown
    265265 */
    266266function wp_create_term($tag_name, $taxonomy = 'post_tag') {
    267         if ( $id = is_term($tag_name, $taxonomy) )
     267        if ( $id = term_exists($tag_name, $taxonomy) )
    268268                return $id;
    269269
    270270        return wp_insert_term($tag_name, $taxonomy);
  • wp-admin/includes/nav-menu.php

     
    271271        }
    272272
    273273        if ( 'get-post-item' == $type ) {
    274                 if ( get_post_type_object( $object_type ) ) {
     274                if ( post_type_exists( $object_type ) ) {
    275275                        if ( isset( $request['ID'] ) ) {
    276276                                $object_id = (int) $request['ID'];
    277277                                if ( 'markup' == $response_format ) {
     
    288288                                        echo "\n";
    289289                                }
    290290                        }
    291                 } elseif ( is_taxonomy( $object_type ) ) {
     291                } elseif ( taxonomy_exists( $object_type ) ) {
    292292                        if ( isset( $request['ID'] ) ) {
    293293                                $object_id = (int) $request['ID'];
    294294                                if ( 'markup' == $response_format ) {
  • wp-admin/edit-tags.php

     
    1414if ( empty($taxonomy) )
    1515        $taxonomy = 'post_tag';
    1616
    17 if ( !is_taxonomy($taxonomy) )
     17if ( !taxonomy_exists($taxonomy) )
    1818        wp_die(__('Invalid taxonomy'));
    1919
    2020$tax = get_taxonomy($taxonomy);