Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




register_taxonomy [ WordPress Function ]

register_taxonomy ( $taxonomy, $object_type, $args = array() )
Parameters:
  • (string) $taxonomy Name of taxonomy object
  • (array|string) $object_type Name of the object type for the taxonomy object.
  • (array|string) $args See above description for the two keys values.
Uses:
  • $wp_taxonomies
  • $wp
Defined at:



Create or modify a taxonomy object. Do not use before init.

A simple function for creating or modifying a taxonomy object based on the parameters given. The function will accept an array (third optional parameter), along with strings for the taxonomy name and another string for the object type.

Nothing is returned, so expect error maybe or use taxonomy_exists() to check whether taxonomy exists.

Optional $args contents:

label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used.

hierarchical - has some defined purpose at other parts of the API and is a boolean value.

update_count_callback - works much like a hook, in that it will be called when the count is updated. Defaults to _update_post_term_count() for taxonomies attached to post types, which then confirms that the objects are published before counting them. Defaults to _update_generic_term_count() for taxonomies attached to other object types, such as links.

rewrite - false to prevent rewrite, or array('slug'=>$slug) to customize permastruct; default will use $taxonomy as slug.

query_var - false to prevent queries, or string to customize query var (?$query_var=$term); default will use $taxonomy as query var.

public - If the taxonomy should be publicly queryable; //@TODO not implemented. defaults to true.

show_ui - If the WordPress UI admin tags UI should apply to this taxonomy; defaults to public.

show_in_nav_menus - true makes this taxonomy available for selection in navigation menus. Defaults to public.

show_tagcloud - false to prevent the taxonomy being listed in the Tag Cloud Widget; defaults to show_ui which defaults to public.

labels - An array of labels for this taxonomy. You can see accepted values in {@link get_taxonomy_labels()}. By default tag labels are used for non-hierarchical types and category labels for hierarchical ones.

Source


<?php
function register_taxonomy$taxonomy$object_type$args = array() ) {
    global 
$wp_taxonomies$wp;

    if ( ! 
is_array($wp_taxonomies) )
        
$wp_taxonomies = array();

    
$defaults = array(    'hierarchical' => false,
                        
'update_count_callback' => '',
                        
'rewrite' => true,
                        
'query_var' => $taxonomy,
                        
'public' => true,
                        
'show_ui' => null,
                        
'show_tagcloud' => null,
                        
'_builtin' => false,
                        
'labels' => array(),
                        
'capabilities' => array(),
                        
'show_in_nav_menus' => null,
                    );
    
$args wp_parse_args($args$defaults);

    if ( 
false !== $args['query_var'] && !empty($wp) ) {
        if ( 
true === $args['query_var'] )
            
$args['query_var'] = $taxonomy;
        
$args['query_var'] = sanitize_title_with_dashes($args['query_var']);
        
$wp->add_query_var($args['query_var']);
    }

    if ( 
false !== $args['rewrite'] && ( is_admin() || '' != get_option('permalink_structure') ) ) {
        
$args['rewrite'] = wp_parse_args($args['rewrite'], array(
            
'slug' => sanitize_title_with_dashes($taxonomy),
            
'with_front' => true,
            
'hierarchical' => false,
            
'ep_mask' => EP_NONE,
        ));

        if ( 
$args['hierarchical'] && $args['rewrite']['hierarchical'] )
            
$tag '(.+?)';
        else
            
$tag '([^/]+)';

        
add_rewrite_tag"%$taxonomy%"$tag$args['query_var'] ? "{$args['query_var']}=" "taxonomy=$taxonomy&term=" );
        
add_permastruct$taxonomy"{$args['rewrite']['slug']}/%$taxonomy%"$args['rewrite'] );
    }

    if ( 
is_null($args['show_ui']) )
        
$args['show_ui'] = $args['public'];

    
// Whether to show this type in nav-menus.php. Defaults to the setting for public.
    
if ( null === $args['show_in_nav_menus'] )
        
$args['show_in_nav_menus'] = $args['public'];

    if ( 
is_null($args['show_tagcloud']) )
        
$args['show_tagcloud'] = $args['show_ui'];

    
$default_caps = array(
        
'manage_terms' => 'manage_categories',
        
'edit_terms'   => 'manage_categories',
        
'delete_terms' => 'manage_categories',
        
'assign_terms' => 'edit_posts',
    );
    
$args['cap'] = (object) array_merge$default_caps$args['capabilities'] );
    unset( 
$args['capabilities'] );

    
$args['name'] = $taxonomy;
    
$args['object_type'] =  array_unique( (array)$object_type );

    
$args['labels'] = get_taxonomy_labels( (object) $args );
    
$args['label'] = $args['labels']->name;

    
$wp_taxonomies[$taxonomy] = (object) $args;

    
// register callback handling for metabox
     
add_filter('wp_ajax_add-' $taxonomy'_wp_ajax_add_hierarchical_term');

    
do_action'registered_taxonomy'$taxonomy$object_type$args );
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics