Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r14934 r15220  
    4646        'show_ui' => false,
    4747        '_builtin' => true,
     48        'show_in_nav_menus' => false,
    4849    ) ) ;
    4950
     
    142143 *
    143144 * @uses $wp_taxonomies
    144  * @uses is_taxonomy() Checks whether taxonomy exists
     145 * @uses taxonomy_exists() Checks whether taxonomy exists
    145146 *
    146147 * @param string $taxonomy Name of taxonomy object to return
     
    150151    global $wp_taxonomies;
    151152
    152     if ( ! is_taxonomy($taxonomy) )
     153    if ( ! taxonomy_exists( $taxonomy ) )
    153154        return false;
    154155
     
    159160 * Checks that the taxonomy name exists.
    160161 *
    161  * @package WordPress
    162  * @subpackage Taxonomy
    163  * @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
    164167 *
    165168 * @uses $wp_taxonomies
     
    168171 * @return bool Whether the taxonomy exists.
    169172 */
    170 function is_taxonomy( $taxonomy ) {
     173function taxonomy_exists( $taxonomy ) {
    171174    global $wp_taxonomies;
    172175
    173     return isset($wp_taxonomies[$taxonomy]);
     176    return isset( $wp_taxonomies[$taxonomy] );
    174177}
    175178
     
    186189 * @since 2.3.0
    187190 *
    188  * @uses is_taxonomy() Checks whether taxonomy exists
     191 * @uses taxonomy_exists() Checks whether taxonomy exists
    189192 * @uses get_taxonomy() Used to get the taxonomy object
    190193 *
     
    193196 */
    194197function is_taxonomy_hierarchical($taxonomy) {
    195     if ( ! is_taxonomy($taxonomy) )
     198    if ( ! taxonomy_exists($taxonomy) )
    196199        return false;
    197200
     
    208211 * the object type.
    209212 *
    210  * 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
    211214 * whether taxonomy exists.
    212215 *
     
    232235 * show_ui - If the WordPress UI admin tags UI should apply to this taxonomy;
    233236 * defaults to public.
     237 *
     238 * show_in_nav_menus - true makes this taxonomy available for selection in navigation menus.
     239 * Defaults to public.
    234240 *
    235241 * show_tagcloud - false to prevent the taxonomy being listed in the Tag Cloud Widget;
     
    265271                        'labels' => array(),
    266272                        'capabilities' => array(),
     273                        'show_in_nav_menus' => null,
    267274                    );
    268275    $args = wp_parse_args($args, $defaults);
     
    286293    if ( is_null($args['show_ui']) )
    287294        $args['show_ui'] = $args['public'];
     295
     296    // Whether to show this type in nav-menus.php. Defaults to the setting for public.
     297    if ( null === $args['show_in_nav_menus'] )
     298        $args['show_in_nav_menus'] = $args['public'];
    288299
    289300    if ( is_null($args['show_tagcloud']) )
     
    318329 * - singular_name - name for one object of this taxonomy. Default is Post Tag/Category
    319330 * - search_items - Default is Search Tags/Search Categories
    320  * - popular_items - Default is Popular Tags/Popular Categories
     331 * - popular_items - This string isn't used on hierarchical taxonomies. Default is Popular Tags
    321332 * - all_items - Default is All Tags/All Categories
    322333 * - parent_item - This string isn't used on non-hierarchical taxonomies. In hierarchical ones the default is Parent Category
     
    326337 * - add_new_item - Default is Add New Tag/Add New Category
    327338 * - new_item_name - Default is New Tag Name/New Category Name
     339 * - separate_items_with_commas - This string isn't used on hierarchical taxonomies. Default is "Separate tags with commas," used in the meta box.
     340 * - add_or_remove_items - This string isn't used on hierarchical taxonomies. Default is "Add or remove tags," used in the meta box when JavaScript is disabled.
     341 * - choose_from_most_used - This string isn't used on hierarchical taxonomies. Default is "Choose from the most used tags," used in the meta box.
    328342 *
    329343 * Above, the first default value is for non-hierarchical taxonomies (like tags) and the second one is for hierarchical taxonomies (like categories.)
     
    335349
    336350function get_taxonomy_labels( $tax ) {
     351    if ( isset( $tax->helps ) && empty( $tax->labels['separate_items_with_commas'] ) )
     352        $tax->labels['separate_items_with_commas'] = $tax->helps;
     353
    337354    $nohier_vs_hier_defaults = array(
    338355        'name' => array( _x( 'Post Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ),
    339356        'singular_name' => array( _x( 'Post Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ),
    340357        'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ),
    341         'popular_items' => array( __( 'Popular Tags' ), __( 'Popular Category' ) ),
     358        'popular_items' => array( __( 'Popular Tags' ), null ),
    342359        'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ),
    343360        'parent_item' => array( null, __( 'Parent Category' ) ),
     
    347364        'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ),
    348365        'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ),
     366        'separate_items_with_commas' => array( __( 'Separate tags with commas' ), null ),
     367        'add_or_remove_items' => array( __( 'Add or remove tags' ), null ),
     368        'choose_from_most_used' => array( __( 'Choose from the most used tags' ), null ),
    349369    );
    350370
     
    420440
    421441    foreach ( (array) $taxonomies as $taxonomy ) {
    422         if ( ! is_taxonomy( $taxonomy ) )
     442        if ( ! taxonomy_exists( $taxonomy ) )
    423443            return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) );
    424444    }
     
    492512    }
    493513
    494     if ( ! is_taxonomy($taxonomy) ) {
     514    if ( ! taxonomy_exists($taxonomy) ) {
    495515        $error = new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    496516        return $error;
     
    559579    global $wpdb;
    560580
    561     if ( ! is_taxonomy($taxonomy) )
     581    if ( ! taxonomy_exists($taxonomy) )
    562582        return false;
    563583
     
    617637 */
    618638function get_term_children( $term_id, $taxonomy ) {
    619     if ( ! is_taxonomy($taxonomy) )
     639    if ( ! taxonomy_exists($taxonomy) )
    620640        return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    621641
     
    802822
    803823    foreach ( (array) $taxonomies as $taxonomy ) {
    804         if ( ! is_taxonomy($taxonomy) ) {
     824        if ( ! taxonomy_exists($taxonomy) ) {
    805825            $error = & new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    806826            return $error;
     
    10541074 * Returns the index of a defined term, or 0 (false) if the term doesn't exist.
    10551075 *
    1056  * @package WordPress
    1057  * @subpackage Taxonomy
    1058  * @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
    10591081 *
    10601082 * @uses $wpdb
     
    10651087 * @return mixed Get the term id or Term Object, if exists.
    10661088 */
    1067 function is_term($term, $taxonomy = '', $parent = 0) {
     1089function term_exists($term, $taxonomy = '', $parent = 0) {
    10681090    global $wpdb;
    10691091
     
    13261348    $term = (int) $term;
    13271349
    1328     if ( ! $ids = is_term($term, $taxonomy) )
     1350    if ( ! $ids = term_exists($term, $taxonomy) )
    13291351        return false;
    13301352    if ( is_wp_error( $ids ) )
     
    13391361    if ( isset($default) ) {
    13401362        $default = (int) $default;
    1341         if ( ! is_term($default, $taxonomy) )
     1363        if ( ! term_exists($default, $taxonomy) )
    13421364            unset($default);
    13431365    }
     
    14261448
    14271449    foreach ( (array) $taxonomies as $taxonomy ) {
    1428         if ( ! is_taxonomy($taxonomy) )
     1450        if ( ! taxonomy_exists($taxonomy) )
    14291451            return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    14301452    }
     
    15641586    global $wpdb;
    15651587
    1566     if ( ! is_taxonomy($taxonomy) )
     1588    if ( ! taxonomy_exists($taxonomy) )
    15671589        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    15681590
     
    16061628    }
    16071629
    1608     if ( $term_id = is_term($slug) ) {
     1630    if ( $term_id = term_exists($slug) ) {
    16091631        $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A );
    16101632        // We've got an existing term in the same taxonomy, which matches the name of the new term:
    1611         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 ) ) {
    16121634            // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level.
    16131635            $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => (int)$parent) );
     
    16261648                return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
    16271649            $term_id = (int) $wpdb->insert_id;
    1628         } elseif ( is_term( (int) $term_id, $taxonomy ) )  {
     1650        } elseif ( term_exists( (int) $term_id, $taxonomy ) )  {
    16291651            // Same name, same slug.
    16301652            return new WP_Error('term_exists', __('A term with the name provided already exists.'));
     
    16951717    $object_id = (int) $object_id;
    16961718
    1697     if ( ! is_taxonomy($taxonomy) )
     1719    if ( ! taxonomy_exists($taxonomy) )
    16981720        return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    16991721
     
    17131735            continue;
    17141736
    1715         if ( !$term_info = is_term($term, $taxonomy) ) {
     1737        if ( !$term_info = term_exists($term, $taxonomy) ) {
    17161738            // Skip if a non-existent term ID is passed.
    17171739            if ( is_int($term) )
     
    17881810    global $wpdb;
    17891811
    1790     if ( ! is_term( $slug ) )
     1812    if ( ! term_exists( $slug ) )
    17911813        return $slug;
    17921814
     
    18001822                break;
    18011823            $slug .= '-' . $parent_term->slug;
    1802             if ( ! is_term( $slug ) )
     1824            if ( ! term_exists( $slug ) )
    18031825                return $slug;
    18041826
     
    18661888    global $wpdb;
    18671889
    1868     if ( ! is_taxonomy($taxonomy) )
     1890    if ( ! taxonomy_exists($taxonomy) )
    18691891        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    18701892
     
    23852407
    23862408    // Get the object and term ids and stick them in a lookup table
    2387     $results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (".join(',', array_keys($term_ids)).") AND post_type = 'post' AND post_status = 'publish'");
     2409    $tax_obj = get_taxonomy($taxonomy);
     2410    $object_types = esc_sql($tax_obj->object_type);
     2411    $results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode(',', array_keys($term_ids)) . ") AND post_type IN ('" . implode("', '", $object_types) . "') AND post_status = 'publish'");
    23882412    foreach ( $results as $row ) {
    23892413        $id = $term_ids[$row->term_taxonomy_id];
Note: See TracChangeset for help on using the changeset viewer.