Make WordPress Core

Ticket #13747: 13747.2.diff

File 13747.2.diff, 13.7 KB (added by nacin, 14 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:
     
    437439                $taxonomies = array( $taxonomies );
    438440
    439441        foreach ( (array) $taxonomies as $taxonomy ) {
    440                 if ( ! is_taxonomy( $taxonomy ) )
     442                if ( ! taxonomy_exists( $taxonomy ) )
    441443                        return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) );
    442444        }
    443445
     
    509511                return $error;
    510512        }
    511513
    512         if ( ! is_taxonomy($taxonomy) ) {
     514        if ( ! taxonomy_exists($taxonomy) ) {
    513515                $error = new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    514516                return $error;
    515517        }
     
    576578function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') {
    577579        global $wpdb;
    578580
    579         if ( ! is_taxonomy($taxonomy) )
     581        if ( ! taxonomy_exists($taxonomy) )
    580582                return false;
    581583
    582584        if ( 'slug' == $field ) {
     
    634636 * @return array|WP_Error List of Term Objects. WP_Error returned if $taxonomy does not exist
    635637 */
    636638function get_term_children( $term_id, $taxonomy ) {
    637         if ( ! is_taxonomy($taxonomy) )
     639        if ( ! taxonomy_exists($taxonomy) )
    638640                return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    639641
    640642        $term_id = intval( $term_id );
     
    819821        }
    820822
    821823        foreach ( (array) $taxonomies as $taxonomy ) {
    822                 if ( ! is_taxonomy($taxonomy) ) {
     824                if ( ! taxonomy_exists($taxonomy) ) {
    823825                        $error = & new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    824826                        return $error;
    825827                }
     
    10711073 *
    10721074 * Returns the index of a defined term, or 0 (false) if the term doesn't exist.
    10731075 *
     1076 * Formerly is_term(), introduced in 2.3.0.
     1077 *
    10741078 * @package WordPress
    10751079 * @subpackage Taxonomy
    1076  * @since 2.3.0
     1080 * @since 3.0.0
    10771081 *
    10781082 * @uses $wpdb
    10791083 *
     
    10821086 * @param int $parent ID of parent term under which to confine the exists search.
    10831087 * @return mixed Get the term id or Term Object, if exists.
    10841088 */
    1085 function is_term($term, $taxonomy = '', $parent = 0) {
     1089function term_exists($term, $taxonomy = '', $parent = 0) {
    10861090        global $wpdb;
    10871091
    10881092        $select = "SELECT term_id FROM $wpdb->terms as t WHERE ";
     
    13431347
    13441348        $term = (int) $term;
    13451349
    1346         if ( ! $ids = is_term($term, $taxonomy) )
     1350        if ( ! $ids = term_exists($term, $taxonomy) )
    13471351                return false;
    13481352        if ( is_wp_error( $ids ) )
    13491353                return $ids;
     
    13561360
    13571361        if ( isset($default) ) {
    13581362                $default = (int) $default;
    1359                 if ( ! is_term($default, $taxonomy) )
     1363                if ( ! term_exists($default, $taxonomy) )
    13601364                        unset($default);
    13611365        }
    13621366
     
    14431447                $taxonomies = array($taxonomies);
    14441448
    14451449        foreach ( (array) $taxonomies as $taxonomy ) {
    1446                 if ( ! is_taxonomy($taxonomy) )
     1450                if ( ! taxonomy_exists($taxonomy) )
    14471451                        return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    14481452        }
    14491453
     
    15811585function wp_insert_term( $term, $taxonomy, $args = array() ) {
    15821586        global $wpdb;
    15831587
    1584         if ( ! is_taxonomy($taxonomy) )
     1588        if ( ! taxonomy_exists($taxonomy) )
    15851589                return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    15861590
    15871591        $term = apply_filters( 'pre_insert_term', $term, $taxonomy );
     
    16231627                }
    16241628        }
    16251629
    1626         if ( $term_id = is_term($slug) ) {
     1630        if ( $term_id = term_exists($slug) ) {
    16271631                $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A );
    16281632                // We've got an existing term in the same taxonomy, which matches the name of the new term:
    1629                 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 ) ) {
    16301634                        // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level.
    16311635                        $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => (int)$parent) );
    16321636                        if ( in_array($name, $siblings) ) {
     
    16431647                        if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
    16441648                                return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
    16451649                        $term_id = (int) $wpdb->insert_id;
    1646                 } elseif ( is_term( (int) $term_id, $taxonomy ) )  {
     1650                } elseif ( term_exists( (int) $term_id, $taxonomy ) )  {
    16471651                        // Same name, same slug.
    16481652                        return new WP_Error('term_exists', __('A term with the name provided already exists.'));
    16491653                }
     
    17121716
    17131717        $object_id = (int) $object_id;
    17141718
    1715         if ( ! is_taxonomy($taxonomy) )
     1719        if ( ! taxonomy_exists($taxonomy) )
    17161720                return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    17171721
    17181722        if ( !is_array($terms) )
     
    17301734                if ( !strlen(trim($term)) )
    17311735                        continue;
    17321736
    1733                 if ( !$term_info = is_term($term, $taxonomy) ) {
     1737                if ( !$term_info = term_exists($term, $taxonomy) ) {
    17341738                        // Skip if a non-existent term ID is passed.
    17351739                        if ( is_int($term) )
    17361740                                continue;
     
    18051809function wp_unique_term_slug($slug, $term) {
    18061810        global $wpdb;
    18071811
    1808         if ( ! is_term( $slug ) )
     1812        if ( ! term_exists( $slug ) )
    18091813                return $slug;
    18101814
    18111815        // If the taxonomy supports hierarchy and the term has a parent, make the slug unique
     
    18171821                        if ( is_wp_error($parent_term) || empty($parent_term) )
    18181822                                break;
    18191823                        $slug .= '-' . $parent_term->slug;
    1820                         if ( ! is_term( $slug ) )
     1824                        if ( ! term_exists( $slug ) )
    18211825                                return $slug;
    18221826
    18231827                        if ( empty($parent_term->parent) )
     
    18831887function wp_update_term( $term_id, $taxonomy, $args = array() ) {
    18841888        global $wpdb;
    18851889
    1886         if ( ! is_taxonomy($taxonomy) )
     1890        if ( ! taxonomy_exists($taxonomy) )
    18871891                return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    18881892
    18891893        $term_id = (int) $term_id;
  • wp-includes/post.php

     
    673673 * @return bool Whether post type is hierarchical.
    674674 */
    675675function is_post_type_hierarchical( $post_type ) {
    676         if ( ! is_post_type( $post_type ) )
     676        if ( ! post_type_exists( $post_type ) )
    677677                return false;
    678678
    679679        $post_type = get_post_type_object( $post_type );
     
    684684 * Checks if a post type is registered.
    685685 *
    686686 * @since 3.0.0
    687  * @uses get_post_type()
     687 * @uses get_post_type_object()
    688688 *
    689689 * @param string Post type name
    690690 * @return bool Whether post type is registered.
    691691 */
    692 function is_post_type( $post_type ) {
     692function post_type_exists( $post_type ) {
    693693        return (bool) get_post_type_object( $post_type );
    694694}
    695695
  • 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 is_term( $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

     
    274274        }
    275275
    276276        if ( 'get-post-item' == $type ) {
    277                 if ( get_post_type_object( $object_type ) ) {
     277                if ( post_type_exists( $object_type ) ) {
    278278                        if ( isset( $request['ID'] ) ) {
    279279                                $object_id = (int) $request['ID'];
    280280                                if ( 'markup' == $response_format ) {
     
    291291                                        echo "\n";
    292292                                }
    293293                        }
    294                 } elseif ( is_taxonomy( $object_type ) ) {
     294                } elseif ( taxonomy_exists( $object_type ) ) {
    295295                        if ( isset( $request['ID'] ) ) {
    296296                                $object_id = (int) $request['ID'];
    297297                                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);