Make WordPress Core


Ignore:
Timestamp:
06/11/2010 03:53:41 PM (16 years ago)
Author:
ryan
Message:

Deprecate is_term, is_taxonomy, is_post_type for *_exists(). Props nacin. fixes #13747

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/taxonomy.php

    r15190 r15220  
    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
     
    151151        global $wp_taxonomies;
    152152
    153         if ( ! is_taxonomy($taxonomy) )
     153        if ( ! taxonomy_exists( $taxonomy ) )
    154154                return false;
    155155
     
    160160 * Checks that the taxonomy name exists.
    161161 *
    162  * @package WordPress
    163  * @subpackage Taxonomy
    164  * @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
    165167 *
    166168 * @uses $wp_taxonomies
     
    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
     
    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 *
     
    194196 */
    195197function is_taxonomy_hierarchical($taxonomy) {
    196         if ( ! is_taxonomy($taxonomy) )
     198        if ( ! taxonomy_exists($taxonomy) )
    197199                return false;
    198200
     
    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 *
     
    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        }
     
    510512        }
    511513
    512         if ( ! is_taxonomy($taxonomy) ) {
     514        if ( ! taxonomy_exists($taxonomy) ) {
    513515                $error = new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    514516                return $error;
     
    577579        global $wpdb;
    578580
    579         if ( ! is_taxonomy($taxonomy) )
     581        if ( ! taxonomy_exists($taxonomy) )
    580582                return false;
    581583
     
    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
     
    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;
     
    10721074 * Returns the index of a defined term, or 0 (false) if the term doesn't exist.
    10731075 *
    1074  * @package WordPress
    1075  * @subpackage Taxonomy
    1076  * @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
    10771081 *
    10781082 * @uses $wpdb
     
    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
     
    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 ) )
     
    13571361        if ( isset($default) ) {
    13581362                $default = (int) $default;
    1359                 if ( ! is_term($default, $taxonomy) )
     1363                if ( ! term_exists($default, $taxonomy) )
    13601364                        unset($default);
    13611365        }
     
    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        }
     
    15821586        global $wpdb;
    15831587
    1584         if ( ! is_taxonomy($taxonomy) )
     1588        if ( ! taxonomy_exists($taxonomy) )
    15851589                return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    15861590
     
    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) );
     
    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.'));
     
    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
     
    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) )
     
    18061810        global $wpdb;
    18071811
    1808         if ( ! is_term( $slug ) )
     1812        if ( ! term_exists( $slug ) )
    18091813                return $slug;
    18101814
     
    18181822                                break;
    18191823                        $slug .= '-' . $parent_term->slug;
    1820                         if ( ! is_term( $slug ) )
     1824                        if ( ! term_exists( $slug ) )
    18211825                                return $slug;
    18221826
     
    18841888        global $wpdb;
    18851889
    1886         if ( ! is_taxonomy($taxonomy) )
     1890        if ( ! taxonomy_exists($taxonomy) )
    18871891                return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    18881892
Note: See TracChangeset for help on using the changeset viewer.