Ticket #15242: 15242.3.diff
| File 15242.3.diff, 13.5 KB (added by , 16 years ago) |
|---|
-
wp-includes/taxonomy.php
21 21 'query_var' => 'category_name', 22 22 'rewrite' => array( 23 23 'hierarchical' => true, 24 'slug' => get_option('category_base') ? get_option('category_base') : 'category', 25 'with_front' => false), 24 'slug' => get_option( 'category_base' ) ? get_option( 'category_base' ) : 'category', 25 'with_front' => false 26 ), 26 27 'public' => true, 27 28 'show_ui' => true, 28 29 '_builtin' => true, … … 33 34 'update_count_callback' => '_update_post_term_count', 34 35 'query_var' => 'tag', 35 36 'rewrite' => array( 36 'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag' , 37 'with_front' => false), 37 'slug' => get_option( 'tag_base' ) ? get_option( 'tag_base' ) : 'tag', 38 'with_front' => false 39 ), 38 40 'public' => true, 39 41 'show_ui' => true, 40 42 '_builtin' => true, … … 52 54 'show_ui' => false, 53 55 '_builtin' => true, 54 56 'show_in_nav_menus' => false, 55 ) ) ;57 ) ); 56 58 57 59 register_taxonomy( 'link_category', 'link', array( 58 60 'hierarchical' => false, … … 75 77 'public' => false, 76 78 'show_ui' => false, 77 79 '_builtin' => true, 78 ) ) ;80 ) ); 79 81 80 register_taxonomy( 'post_format', array( 'post', 'page', 'attachment'), array(82 register_taxonomy( 'post_format', array( 'post', 'page', 'attachment' ), array( 81 83 'public' => false, 82 84 'hierarchical' => false, 83 85 'labels' => array( … … 89 91 'show_ui' => false, 90 92 '_builtin' => true, 91 93 'show_in_nav_menus' => false, 92 ) ) ;94 ) ); 93 95 } 94 96 add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority 95 97 … … 111 113 function get_taxonomies( $args = array(), $output = 'names', $operator = 'and' ) { 112 114 global $wp_taxonomies; 113 115 114 $field = ( 'names' == $output) ? 'name' : false;116 $field = ( 'names' == $output ) ? 'name' : false; 115 117 116 return wp_filter_object_list( $wp_taxonomies, $args, $operator, $field);118 return wp_filter_object_list( $wp_taxonomies, $args, $operator, $field ); 117 119 } 118 120 119 121 … … 136 138 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default. 137 139 * @return array The names of all taxonomy of $object_type. 138 140 */ 139 function get_object_taxonomies( $object, $output = 'names') {141 function get_object_taxonomies( $object, $output = 'names' ) { 140 142 global $wp_taxonomies; 141 143 142 if ( is_object( $object) ) {144 if ( is_object( $object ) ) { 143 145 if ( $object->post_type == 'attachment' ) 144 return get_attachment_taxonomies( $object);146 return get_attachment_taxonomies( $object ); 145 147 $object = $object->post_type; 146 148 } 147 149 … … 149 151 150 152 $taxonomies = array(); 151 153 foreach ( (array) $wp_taxonomies as $tax_name => $tax_obj ) { 152 if ( array_intersect( $object, (array) $tax_obj->object_type) ) {154 if ( array_intersect( $object, (array) $tax_obj->object_type ) ) { 153 155 if ( 'names' == $output ) 154 156 $taxonomies[] = $tax_name; 155 157 else … … 223 225 * @param string $taxonomy Name of taxonomy object 224 226 * @return bool Whether the taxonomy is hierarchical 225 227 */ 226 function is_taxonomy_hierarchical( $taxonomy) {227 if ( ! taxonomy_exists( $taxonomy) )228 function is_taxonomy_hierarchical( $taxonomy ) { 229 if ( ! taxonomy_exists( $taxonomy ) ) 228 230 return false; 229 231 230 $taxonomy = get_taxonomy( $taxonomy);232 $taxonomy = get_taxonomy( $taxonomy ); 231 233 return $taxonomy->hierarchical; 232 234 } 233 235 … … 286 288 function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 287 289 global $wp_taxonomies, $wp_rewrite, $wp; 288 290 289 if ( ! is_array( $wp_taxonomies) )291 if ( ! is_array( $wp_taxonomies ) ) 290 292 $wp_taxonomies = array(); 291 293 292 294 $defaults = array( 'hierarchical' => false, … … 301 303 'capabilities' => array(), 302 304 'show_in_nav_menus' => null, 303 305 ); 304 $args = wp_parse_args( $args, $defaults);306 $args = wp_parse_args( $args, $defaults ); 305 307 306 if ( false !== $args['query_var'] && !empty( $wp) ) {308 if ( false !== $args['query_var'] && !empty( $wp ) ) { 307 309 if ( true === $args['query_var'] ) 308 310 $args['query_var'] = $taxonomy; 309 $args['query_var'] = sanitize_title_with_dashes( $args['query_var']);310 $wp->add_query_var( $args['query_var']);311 $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] ); 312 $wp->add_query_var( $args['query_var'] ); 311 313 } 312 314 313 if ( false !== $args['rewrite'] && '' != get_option( 'permalink_structure') && !empty($wp_rewrite) ) {314 $args['rewrite'] = wp_parse_args( $args['rewrite'], array(315 'slug' => sanitize_title_with_dashes( $taxonomy),315 if ( false !== $args['rewrite'] && '' != get_option( 'permalink_structure' ) && !empty( $wp_rewrite ) ) { 316 $args['rewrite'] = wp_parse_args( $args['rewrite'], array( 317 'slug' => sanitize_title_with_dashes( $taxonomy ), 316 318 'with_front' => true, 317 319 'hierarchical' => false 318 ) );320 ) ); 319 321 320 322 if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] ) 321 323 $tag = '(.+?)'; 322 324 else 323 325 $tag = '([^/]+)'; 324 326 325 $wp_rewrite->add_rewrite_tag( "%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=");326 $wp_rewrite->add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']);327 $wp_rewrite->add_rewrite_tag( "%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=" ); 328 $wp_rewrite->add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front'] ); 327 329 } 328 330 329 if ( is_null( $args['show_ui']) )331 if ( is_null( $args['show_ui'] ) ) 330 332 $args['show_ui'] = $args['public']; 331 333 332 334 // Whether to show this type in nav-menus.php. Defaults to the setting for public. 333 335 if ( null === $args['show_in_nav_menus'] ) 334 336 $args['show_in_nav_menus'] = $args['public']; 335 337 336 if ( is_null( $args['show_tagcloud']) )338 if ( is_null( $args['show_tagcloud'] ) ) 337 339 $args['show_tagcloud'] = $args['show_ui']; 338 340 339 341 $default_caps = array( … … 354 356 $wp_taxonomies[$taxonomy] = (object) $args; 355 357 356 358 // register callback handling for metabox 357 add_filter( 'wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');359 add_filter( 'wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term' ); 358 360 } 359 361 360 362 /** … … 419 421 * @param array|string $object_type Name of the object type 420 422 * @return bool True if successful, false if not 421 423 */ 422 function register_taxonomy_for_object_type( $taxonomy, $object_type ) {424 function register_taxonomy_for_object_type( $taxonomy, $object_type ) { 423 425 global $wp_taxonomies; 424 426 425 if ( !isset( $wp_taxonomies[$taxonomy]) )427 if ( !isset( $wp_taxonomies[$taxonomy] ) ) 426 428 return false; 427 429 428 if ( ! get_post_type_object( $object_type) )430 if ( ! get_post_type_object( $object_type ) ) 429 431 return false; 430 432 431 433 $wp_taxonomies[$taxonomy]->object_type[] = $object_type; … … 536 538 foreach ( $terms as $i => $term ) { 537 539 $terms[$i] = sanitize_title_for_query( $term ); 538 540 } 539 $terms = array_filter( $terms);541 $terms = array_filter( $terms ); 540 542 541 543 $terms = "'" . implode( "','", $terms ) . "'"; 542 544 $sql = " … … 593 595 * @return mixed|null|WP_Error Term Row from database. Will return null if $term is empty. If taxonomy does not 594 596 * exist then WP_Error will be returned. 595 597 */ 596 function &get_term( $term, $taxonomy, $output = OBJECT, $filter = 'raw') {598 function &get_term( $term, $taxonomy, $output = OBJECT, $filter = 'raw' ) { 597 599 global $wpdb; 598 600 $null = null; 599 601 600 if ( empty( $term) ) {601 $error = new WP_Error( 'invalid_term', __('Empty Term'));602 if ( empty( $term ) ) { 603 $error = new WP_Error( 'invalid_term', __( 'Empty Term' ) ); 602 604 return $error; 603 605 } 604 606 605 if ( ! taxonomy_exists( $taxonomy) ) {606 $error = new WP_Error( 'invalid_taxonomy', __('Invalid Taxonomy'));607 if ( ! taxonomy_exists( $taxonomy ) ) { 608 $error = new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) ); 607 609 return $error; 608 610 } 609 611 610 if ( is_object( $term) && empty($term->filter) ) {611 wp_cache_add( $term->term_id, $term, $taxonomy);612 if ( is_object( $term ) && empty( $term->filter ) ) { 613 wp_cache_add( $term->term_id, $term, $taxonomy ); 612 614 $_term = $term; 613 615 } else { 614 if ( is_object( $term) )616 if ( is_object( $term ) ) 615 617 $term = $term->term_id; 616 618 $term = (int) $term; 617 if ( ! $_term = wp_cache_get( $term, $taxonomy) ) {618 $_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %s LIMIT 1", $taxonomy, $term ) );619 if ( ! $_term = wp_cache_get( $term, $taxonomy ) ) { 620 $_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %s LIMIT 1", $taxonomy, $term ) ); 619 621 if ( ! $_term ) 620 622 return $null; 621 wp_cache_add( $term, $_term, $taxonomy);623 wp_cache_add( $term, $_term, $taxonomy ); 622 624 } 623 625 } 624 626 625 $_term = apply_filters( 'get_term', $_term, $taxonomy);626 $_term = apply_filters( "get_$taxonomy", $_term, $taxonomy);627 $_term = sanitize_term( $_term, $taxonomy, $filter);627 $_term = apply_filters( 'get_term', $_term, $taxonomy ); 628 $_term = apply_filters( "get_$taxonomy", $_term, $taxonomy ); 629 $_term = sanitize_term( $_term, $taxonomy, $filter ); 628 630 629 631 if ( $output == OBJECT ) { 630 632 return $_term; 631 633 } elseif ( $output == ARRAY_A ) { 632 $__term = get_object_vars( $_term);634 $__term = get_object_vars( $_term ); 633 635 return $__term; 634 636 } elseif ( $output == ARRAY_N ) { 635 $__term = array_values( get_object_vars($_term));637 $__term = array_values( get_object_vars( $_term ) ); 636 638 return $__term; 637 639 } else { 638 640 return $_term; … … 666 668 * @param string $filter Optional, default is raw or no WordPress defined filter will applied. 667 669 * @return mixed Term Row from database. Will return false if $taxonomy does not exist or $term was not found. 668 670 */ 669 function get_term_by( $field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') {671 function get_term_by( $field, $value, $taxonomy, $output = OBJECT, $filter = 'raw' ) { 670 672 global $wpdb; 671 673 672 if ( ! taxonomy_exists( $taxonomy) )674 if ( ! taxonomy_exists( $taxonomy ) ) 673 675 return false; 674 676 675 677 if ( 'slug' == $field ) { 676 678 $field = 't.slug'; 677 $value = sanitize_title( $value);678 if ( empty( $value) )679 $value = sanitize_title( $value ); 680 if ( empty( $value ) ) 679 681 return false; 680 682 } else if ( 'name' == $field ) { 681 683 // Assume already escaped 682 $value = stripslashes( $value);684 $value = stripslashes( $value ); 683 685 $field = 't.name'; 684 686 } else { 685 return get_term( (int) $value, $taxonomy, $output, $filter );687 return get_term( (int) $value, $taxonomy, $output, $filter ); 686 688 } 687 689 688 $term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value ) );690 $term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value ) ); 689 691 if ( !$term ) 690 692 return false; 691 693 692 wp_cache_add( $term->term_id, $term, $taxonomy);694 wp_cache_add( $term->term_id, $term, $taxonomy ); 693 695 694 $term = apply_filters( 'get_term', $term, $taxonomy);695 $term = apply_filters( "get_$taxonomy", $term, $taxonomy);696 $term = sanitize_term( $term, $taxonomy, $filter);696 $term = apply_filters( 'get_term', $term, $taxonomy ); 697 $term = apply_filters( "get_$taxonomy", $term, $taxonomy ); 698 $term = sanitize_term( $term, $taxonomy, $filter ); 697 699 698 700 if ( $output == OBJECT ) { 699 701 return $term; 700 702 } elseif ( $output == ARRAY_A ) { 701 return get_object_vars( $term);703 return get_object_vars( $term ); 702 704 } elseif ( $output == ARRAY_N ) { 703 return array_values( get_object_vars($term));705 return array_values( get_object_vars( $term ) ); 704 706 } else { 705 707 return $term; 706 708 } … … 727 729 * @return array|WP_Error List of Term Objects. WP_Error returned if $taxonomy does not exist 728 730 */ 729 731 function get_term_children( $term_id, $taxonomy ) { 730 if ( ! taxonomy_exists( $taxonomy) )731 return new WP_Error( 'invalid_taxonomy', __('Invalid Taxonomy'));732 if ( ! taxonomy_exists( $taxonomy ) ) 733 return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) ); 732 734 733 735 $term_id = intval( $term_id ); 734 736 735 $terms = _get_term_hierarchy( $taxonomy);737 $terms = _get_term_hierarchy( $taxonomy ); 736 738 737 if ( ! isset( $terms[$term_id]) )739 if ( ! isset( $terms[$term_id] ) ) 738 740 return array(); 739 741 740 742 $children = $terms[$term_id]; 741 743 742 744 foreach ( (array) $terms[$term_id] as $child ) { 743 if ( isset( $terms[$child]) )744 $children = array_merge( $children, get_term_children($child, $taxonomy));745 if ( isset( $terms[$child] ) ) 746 $children = array_merge( $children, get_term_children( $child, $taxonomy ) ); 745 747 } 746 748 747 749 return $children; … … 769 771 function get_term_field( $field, $term, $taxonomy, $context = 'display' ) { 770 772 $term = (int) $term; 771 773 $term = get_term( $term, $taxonomy ); 772 if ( is_wp_error( $term) )774 if ( is_wp_error( $term ) ) 773 775 return $term; 774 776 775 if ( !is_object( $term) )777 if ( !is_object( $term ) ) 776 778 return ''; 777 779 778 if ( !isset( $term->$field) )780 if ( !isset( $term->$field ) ) 779 781 return ''; 780 782 781 return sanitize_term_field( $field, $term->$field, $term->term_id, $taxonomy, $context);783 return sanitize_term_field( $field, $term->$field, $term->term_id, $taxonomy, $context ); 782 784 } 783 785 784 786 /** … … 800 802 function get_term_to_edit( $id, $taxonomy ) { 801 803 $term = get_term( $id, $taxonomy ); 802 804 803 if ( is_wp_error( $term) )805 if ( is_wp_error( $term ) ) 804 806 return $term; 805 807 806 if ( !is_object( $term) )808 if ( !is_object( $term ) ) 807 809 return ''; 808 810 809 return sanitize_term( $term, $taxonomy, 'edit');811 return sanitize_term( $term, $taxonomy, 'edit' ); 810 812 } 811 813 812 814 /**
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)