Make WordPress Core


Ignore:
Timestamp:
01/04/2010 04:58:43 PM (15 years ago)
Author:
ryan
Message:

More custom post type support. Props scribu. see #9674

File:
1 edited

Legend:

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

    r12515 r12597  
    181181    }
    182182
    183     if ( false !== $args['rewrite'] && !empty($wp_rewrite) ) {
     183    if ( false !== $args['rewrite'] && '' != get_option('permalink_structure') ) {
    184184        if ( !is_array($args['rewrite']) )
    185185            $args['rewrite'] = array();
     
    187187            $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy);
    188188        $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=$term");
    189         $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%");
     189        $wp_rewrite->add_permastruct($taxonomy, "/{$args['rewrite']['slug']}/%$taxonomy%");
    190190    }
    191191
    192192    $args['name'] = $taxonomy;
    193     $args['object_type'] = $object_type;
     193    $args['object_type'] = (array) $object_type;
    194194    $wp_taxonomies[$taxonomy] = (object) $args;
     195}
     196
     197/**
     198 * Add an already registered taxonomy to an object type.
     199 *
     200 * @package WordPress
     201 * @subpackage Taxonomy
     202 * @since 3.0
     203 * @uses $wp_taxonomies Modifies taxonomy object
     204 *
     205 * @param string $taxonomy Name of taxonomy object
     206 * @param array|string $object_type Name of the object type
     207 * @return bool True if successful, false if not
     208 */
     209function register_taxonomy_for_object_type( $taxonomy, $object_type) {
     210    global $wp_taxonomies;
     211
     212    if ( !isset($wp_taxonomies[$taxonomy]) )
     213        return false;
     214
     215    if ( ! get_post_type_object($object_type) )
     216        return false;
     217
     218    $wp_taxonomies[$taxonomy]->object_type[] = $object_type;
     219
     220    return true;
    195221}
    196222
     
    23792405}
    23802406
     2407/**
     2408 * Determine if the given object type is associated with the given taxonomy.
     2409 *
     2410 * @since 3.0
     2411 * @uses get_object_taxonomies()
     2412 *
     2413 * @param string $object_type Object type string
     2414 * @param string $taxonomy.  Single taxonomy name
     2415 * @return bool True if object is associated with the taxonomy, otherwise false.
     2416 */
     2417function is_object_in_taxonomy($object_type, $taxonomy) {
     2418    $taxonomies = get_object_taxonomies($object_type);
     2419
     2420    if ( empty($taxonomies) )
     2421        return false;
     2422
     2423    if ( in_array($taxonomy, $taxonomies) )
     2424        return true;
     2425
     2426    return false;
     2427}
     2428
    23812429?>
Note: See TracChangeset for help on using the changeset viewer.