From fc2793bd46b13ec8beae3c0fe417e89ff602858e Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 11 Jun 2010 15:53:41 +0000 Subject: [PATCH] Deprecate is_term, is_taxonomy, is_post_type for *_exists(). Props nacin. fixes #13747 git-svn-id: https://develop.svn.wordpress.org/trunk@15220 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/admin-ajax.php | 4 +-- wp-admin/edit-tags.php | 2 +- wp-admin/includes/nav-menu.php | 4 +-- wp-admin/includes/taxonomy.php | 6 ++-- wp-includes/category-template.php | 2 +- wp-includes/default-widgets.php | 2 +- wp-includes/deprecated.php | 50 ++++++++++++++++++++++++++ wp-includes/post.php | 6 ++-- wp-includes/taxonomy.php | 58 +++++++++++++++++-------------- 9 files changed, 94 insertions(+), 40 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 07a247504a..bc1bb44e21 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -237,7 +237,7 @@ function _wp_ajax_add_hierarchical_term() { $category_nicename = sanitize_title($cat_name); if ( '' === $category_nicename ) continue; - if ( !($cat_id = is_term($cat_name, $taxonomy->name, $parent)) ) { + if ( !($cat_id = term_exists($cat_name, $taxonomy->name, $parent)) ) { $new_term = wp_insert_term($cat_name, $taxonomy->name, array('parent' => $parent)); $cat_id = $new_term['term_id']; } @@ -501,7 +501,7 @@ case 'add-link-category' : // On the Fly $slug = sanitize_title($cat_name); if ( '' === $slug ) continue; - if ( !$cat_id = is_term( $cat_name, 'link_category' ) ) { + if ( !$cat_id = term_exists( $cat_name, 'link_category' ) ) { $cat_id = wp_insert_term( $cat_name, 'link_category' ); } $cat_id = $cat_id['term_id']; diff --git a/wp-admin/edit-tags.php b/wp-admin/edit-tags.php index 64059bd619..c194ee44a0 100644 --- a/wp-admin/edit-tags.php +++ b/wp-admin/edit-tags.php @@ -14,7 +14,7 @@ wp_reset_vars( array('action', 'tag', 'taxonomy', 'post_type') ); if ( empty($taxonomy) ) $taxonomy = 'post_tag'; -if ( !is_taxonomy($taxonomy) ) +if ( !taxonomy_exists($taxonomy) ) wp_die(__('Invalid taxonomy')); $tax = get_taxonomy($taxonomy); diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php index e5f0655c8c..c2f138ec90 100644 --- a/wp-admin/includes/nav-menu.php +++ b/wp-admin/includes/nav-menu.php @@ -279,7 +279,7 @@ function _wp_ajax_menu_quick_search( $request = array() ) { } if ( 'get-post-item' == $type ) { - if ( get_post_type_object( $object_type ) ) { + if ( post_type_exists( $object_type ) ) { if ( isset( $request['ID'] ) ) { $object_id = (int) $request['ID']; if ( 'markup' == $response_format ) { @@ -296,7 +296,7 @@ function _wp_ajax_menu_quick_search( $request = array() ) { echo "\n"; } } - } elseif ( is_taxonomy( $object_type ) ) { + } elseif ( taxonomy_exists( $object_type ) ) { if ( isset( $request['ID'] ) ) { $object_id = (int) $request['ID']; if ( 'markup' == $response_format ) { diff --git a/wp-admin/includes/taxonomy.php b/wp-admin/includes/taxonomy.php index 5b3e0d95b8..b371ec2417 100644 --- a/wp-admin/includes/taxonomy.php +++ b/wp-admin/includes/taxonomy.php @@ -19,7 +19,7 @@ * @return unknown */ function category_exists($cat_name, $parent = 0) { - $id = is_term($cat_name, 'category', $parent); + $id = term_exists($cat_name, 'category', $parent); if ( is_array($id) ) $id = $id['term_id']; return $id; @@ -240,7 +240,7 @@ function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) { * @return unknown */ function tag_exists($tag_name) { - return is_term($tag_name, 'post_tag'); + return term_exists($tag_name, 'post_tag'); } /** @@ -264,7 +264,7 @@ function wp_create_tag($tag_name) { * @return unknown */ function wp_create_term($tag_name, $taxonomy = 'post_tag') { - if ( $id = is_term($tag_name, $taxonomy) ) + if ( $id = term_exists($tag_name, $taxonomy) ) return $id; return wp_insert_term($tag_name, $taxonomy); diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index 18b9cf317c..db55a12c7e 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -482,7 +482,7 @@ function wp_list_categories( $args = '' ) { extract( $r ); - if ( !is_taxonomy($taxonomy) ) + if ( !taxonomy_exists($taxonomy) ) return false; $categories = get_categories( $r ); diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php index ce4b66abe9..47e06860a7 100644 --- a/wp-includes/default-widgets.php +++ b/wp-includes/default-widgets.php @@ -1041,7 +1041,7 @@ class WP_Widget_Tag_Cloud extends WP_Widget { } function _get_current_taxonomy($instance) { - if ( !empty($instance['taxonomy']) && is_taxonomy($instance['taxonomy']) ) + if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) ) return $instance['taxonomy']; return 'post_tag'; diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 146dbaa0f3..25532a17b3 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -2513,3 +2513,53 @@ function trackback_rdf($deprecated = '') { _deprecated_function( __FUNCTION__, '3.0' ); return ''; } + +/** + * Checks if a post type is registered. + * + * @since 3.0.0 + * @deprecated 3.0.0 + * @deprecated Use post_type_exists() + * @see post_type_exists() + * + * @param string Post type name + * @return bool Whether post type is registered. + */ +function is_post_type( $post_type ) { + _deprecated_function( __FUNCTION__, '3.0', 'post_type_exists()' ); + return post_type_exists( $post_type ); +} + +/** + * Checks that the taxonomy name exists. + * + * @since 2.3.0 + * @deprecated 3.0.0 + * @deprecated Use taxonomy_exists() + * @see taxonomy_exists() + * + * @param string $taxonomy Name of taxonomy object + * @return bool Whether the taxonomy exists. + */ +function is_taxonomy( $taxonomy ) { + _deprecated_function( __FUNCTION__, '3.0', 'taxonomy_exists()' ); + return taxonomy_exists( $post_type ); +} + +/** + * Check if Term exists. + * + * @since 2.3.0 + * @deprecated 3.0.0 + * @deprecated Use term_exists() + * @see term_exists() + * + * @param int|string $term The term to check + * @param string $taxonomy The taxonomy name to use + * @param int $parent ID of parent term under which to confine the exists search. + * @return mixed Get the term id or Term Object, if exists. + */ +function is_term( $term, $taxonomy = '', $parent = 0 ) { + _deprecated_function( __FUNCTION__, '3.0', 'term_exists()' ); + return term_exists( $term, $taxonomy, $parent ); +} \ No newline at end of file diff --git a/wp-includes/post.php b/wp-includes/post.php index 17c6dbcbf4..f31923d3b4 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -673,7 +673,7 @@ function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) * @return bool Whether post type is hierarchical. */ function is_post_type_hierarchical( $post_type ) { - if ( ! is_post_type( $post_type ) ) + if ( ! post_type_exists( $post_type ) ) return false; $post_type = get_post_type_object( $post_type ); @@ -684,12 +684,12 @@ function is_post_type_hierarchical( $post_type ) { * Checks if a post type is registered. * * @since 3.0.0 - * @uses get_post_type() + * @uses get_post_type_object() * * @param string Post type name * @return bool Whether post type is registered. */ -function is_post_type( $post_type ) { +function post_type_exists( $post_type ) { return (bool) get_post_type_object( $post_type ); } diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 5a2564243c..69f9c28639 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -142,7 +142,7 @@ function get_object_taxonomies($object, $output = 'names') { * @since 2.3.0 * * @uses $wp_taxonomies - * @uses is_taxonomy() Checks whether taxonomy exists + * @uses taxonomy_exists() Checks whether taxonomy exists * * @param string $taxonomy Name of taxonomy object to return * @return object|bool The Taxonomy Object or false if $taxonomy doesn't exist @@ -150,7 +150,7 @@ function get_object_taxonomies($object, $output = 'names') { function get_taxonomy( $taxonomy ) { global $wp_taxonomies; - if ( ! is_taxonomy($taxonomy) ) + if ( ! taxonomy_exists( $taxonomy ) ) return false; return $wp_taxonomies[$taxonomy]; @@ -159,19 +159,21 @@ function get_taxonomy( $taxonomy ) { /** * Checks that the taxonomy name exists. * + * Formerly is_taxonomy(), introduced in 2.3.0. + * * @package WordPress * @subpackage Taxonomy - * @since 2.3.0 + * @since 3.0.0 * * @uses $wp_taxonomies * * @param string $taxonomy Name of taxonomy object * @return bool Whether the taxonomy exists. */ -function is_taxonomy( $taxonomy ) { +function taxonomy_exists( $taxonomy ) { global $wp_taxonomies; - return isset($wp_taxonomies[$taxonomy]); + return isset( $wp_taxonomies[$taxonomy] ); } /** @@ -186,14 +188,14 @@ function is_taxonomy( $taxonomy ) { * @subpackage Taxonomy * @since 2.3.0 * - * @uses is_taxonomy() Checks whether taxonomy exists + * @uses taxonomy_exists() Checks whether taxonomy exists * @uses get_taxonomy() Used to get the taxonomy object * * @param string $taxonomy Name of taxonomy object * @return bool Whether the taxonomy is hierarchical */ function is_taxonomy_hierarchical($taxonomy) { - if ( ! is_taxonomy($taxonomy) ) + if ( ! taxonomy_exists($taxonomy) ) return false; $taxonomy = get_taxonomy($taxonomy); @@ -208,7 +210,7 @@ function is_taxonomy_hierarchical($taxonomy) { * parameter), along with strings for the taxonomy name and another string for * the object type. * - * Nothing is returned, so expect error maybe or use is_taxonomy() to check + * Nothing is returned, so expect error maybe or use taxonomy_exists() to check * whether taxonomy exists. * * Optional $args contents: @@ -437,7 +439,7 @@ function get_objects_in_term( $term_ids, $taxonomies, $args = array() ) { $taxonomies = array( $taxonomies ); foreach ( (array) $taxonomies as $taxonomy ) { - if ( ! is_taxonomy( $taxonomy ) ) + if ( ! taxonomy_exists( $taxonomy ) ) return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) ); } @@ -509,7 +511,7 @@ function &get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { return $error; } - if ( ! is_taxonomy($taxonomy) ) { + if ( ! taxonomy_exists($taxonomy) ) { $error = new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); return $error; } @@ -576,7 +578,7 @@ function &get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') { global $wpdb; - if ( ! is_taxonomy($taxonomy) ) + if ( ! taxonomy_exists($taxonomy) ) return false; if ( 'slug' == $field ) { @@ -634,7 +636,7 @@ function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw * @return array|WP_Error List of Term Objects. WP_Error returned if $taxonomy does not exist */ function get_term_children( $term_id, $taxonomy ) { - if ( ! is_taxonomy($taxonomy) ) + if ( ! taxonomy_exists($taxonomy) ) return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); $term_id = intval( $term_id ); @@ -819,7 +821,7 @@ function &get_terms($taxonomies, $args = '') { } foreach ( (array) $taxonomies as $taxonomy ) { - if ( ! is_taxonomy($taxonomy) ) { + if ( ! taxonomy_exists($taxonomy) ) { $error = & new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); return $error; } @@ -1071,9 +1073,11 @@ function &get_terms($taxonomies, $args = '') { * * Returns the index of a defined term, or 0 (false) if the term doesn't exist. * + * Formerly is_term(), introduced in 2.3.0. + * * @package WordPress * @subpackage Taxonomy - * @since 2.3.0 + * @since 3.0.0 * * @uses $wpdb * @@ -1082,7 +1086,7 @@ function &get_terms($taxonomies, $args = '') { * @param int $parent ID of parent term under which to confine the exists search. * @return mixed Get the term id or Term Object, if exists. */ -function is_term($term, $taxonomy = '', $parent = 0) { +function term_exists($term, $taxonomy = '', $parent = 0) { global $wpdb; $select = "SELECT term_id FROM $wpdb->terms as t WHERE "; @@ -1343,7 +1347,7 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { $term = (int) $term; - if ( ! $ids = is_term($term, $taxonomy) ) + if ( ! $ids = term_exists($term, $taxonomy) ) return false; if ( is_wp_error( $ids ) ) return $ids; @@ -1356,7 +1360,7 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { if ( isset($default) ) { $default = (int) $default; - if ( ! is_term($default, $taxonomy) ) + if ( ! term_exists($default, $taxonomy) ) unset($default); } @@ -1443,7 +1447,7 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { $taxonomies = array($taxonomies); foreach ( (array) $taxonomies as $taxonomy ) { - if ( ! is_taxonomy($taxonomy) ) + if ( ! taxonomy_exists($taxonomy) ) return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); } @@ -1581,7 +1585,7 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { function wp_insert_term( $term, $taxonomy, $args = array() ) { global $wpdb; - if ( ! is_taxonomy($taxonomy) ) + if ( ! taxonomy_exists($taxonomy) ) return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); $term = apply_filters( 'pre_insert_term', $term, $taxonomy ); @@ -1623,10 +1627,10 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { } } - if ( $term_id = is_term($slug) ) { + if ( $term_id = term_exists($slug) ) { $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); // We've got an existing term in the same taxonomy, which matches the name of the new term: - if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && is_term( (int) $term_id, $taxonomy ) ) { + if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && term_exists( (int) $term_id, $taxonomy ) ) { // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level. $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => (int)$parent) ); if ( in_array($name, $siblings) ) { @@ -1643,7 +1647,7 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); $term_id = (int) $wpdb->insert_id; - } elseif ( is_term( (int) $term_id, $taxonomy ) ) { + } elseif ( term_exists( (int) $term_id, $taxonomy ) ) { // Same name, same slug. return new WP_Error('term_exists', __('A term with the name provided already exists.')); } @@ -1712,7 +1716,7 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) { $object_id = (int) $object_id; - if ( ! is_taxonomy($taxonomy) ) + if ( ! taxonomy_exists($taxonomy) ) return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); if ( !is_array($terms) ) @@ -1730,7 +1734,7 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) { if ( !strlen(trim($term)) ) continue; - if ( !$term_info = is_term($term, $taxonomy) ) { + if ( !$term_info = term_exists($term, $taxonomy) ) { // Skip if a non-existent term ID is passed. if ( is_int($term) ) continue; @@ -1805,7 +1809,7 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) { function wp_unique_term_slug($slug, $term) { global $wpdb; - if ( ! is_term( $slug ) ) + if ( ! term_exists( $slug ) ) return $slug; // If the taxonomy supports hierarchy and the term has a parent, make the slug unique @@ -1817,7 +1821,7 @@ function wp_unique_term_slug($slug, $term) { if ( is_wp_error($parent_term) || empty($parent_term) ) break; $slug .= '-' . $parent_term->slug; - if ( ! is_term( $slug ) ) + if ( ! term_exists( $slug ) ) return $slug; if ( empty($parent_term->parent) ) @@ -1883,7 +1887,7 @@ function wp_unique_term_slug($slug, $term) { function wp_update_term( $term_id, $taxonomy, $args = array() ) { global $wpdb; - if ( ! is_taxonomy($taxonomy) ) + if ( ! taxonomy_exists($taxonomy) ) return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); $term_id = (int) $term_id;