Ticket #27238: 27238.diff
File 27238.diff, 13.9 KB (added by , 11 years ago) |
---|
-
wp-includes/taxonomy.php
123 123 /** 124 124 * Get a list of registered taxonomy objects. 125 125 * 126 * @package WordPress 127 * @subpackage Taxonomy 126 128 * @since 3.0.0 127 129 * @uses $wp_taxonomies 128 130 * @see register_taxonomy … … 150 152 * <code><?php $taxonomies = get_object_taxonomies('post'); ?></code> Should 151 153 * result in <code>Array('category', 'post_tag')</code> 152 154 * 155 * @package WordPress 156 * @subpackage Taxonomy 153 157 * @since 2.3.0 154 158 * 155 159 * @uses $wp_taxonomies … … 188 192 * The get_taxonomy function will first check that the parameter string given 189 193 * is a taxonomy object and if it is, it will return it. 190 194 * 195 * @package WordPress 196 * @subpackage Taxonomy 191 197 * @since 2.3.0 192 198 * 193 199 * @uses $wp_taxonomies … … 210 216 * 211 217 * Formerly is_taxonomy(), introduced in 2.3.0. 212 218 * 219 * @package WordPress 220 * @subpackage Taxonomy 213 221 * @since 3.0.0 214 222 * 215 223 * @uses $wp_taxonomies … … 231 239 * 232 240 * A false return value might also mean that the taxonomy does not exist. 233 241 * 242 * @package WordPress 243 * @subpackage Taxonomy 234 244 * @since 2.3.0 235 245 * 236 246 * @uses taxonomy_exists() Checks whether taxonomy exists … … 279 289 * * If not set, the default is inherited from public. 280 290 * - show_tagcloud - Whether to list the taxonomy in the Tag Cloud Widget. 281 291 * * If not set, the default is inherited from show_ui. 282 * - show_admin_column - Whether to display a column for the taxonomy on its post type listing screens.283 * * Defaults to false.284 292 * - meta_box_cb - Provide a callback function for the meta box display. 285 293 * * If not set, defaults to post_categories_meta_box for hierarchical taxonomies 286 294 * and post_tags_meta_box for non-hierarchical. … … 328 336 'show_in_menu' => null, 329 337 'show_in_nav_menus' => null, 330 338 'show_tagcloud' => null, 331 'show_admin_column' => false,332 339 'meta_box_cb' => null, 333 340 'capabilities' => array(), 334 341 'rewrite' => true, … … 478 485 /** 479 486 * Add an already registered taxonomy to an object type. 480 487 * 488 * @package WordPress 489 * @subpackage Taxonomy 481 490 * @since 3.0.0 482 491 * @uses $wp_taxonomies Modifies taxonomy object 483 492 * … … 545 554 * using PHP sort family functions or using the database by using $args with 546 555 * either ASC or DESC array. The value should be in the key named 'order'. 547 556 * 557 * @package WordPress 558 * @subpackage Taxonomy 548 559 * @since 2.3.0 549 560 * 550 561 * @uses $wpdb … … 904 915 * example, if 'category', it would be 'get_category' as the filter name. Useful 905 916 * for custom taxonomies or plugging into default taxonomies. 906 917 * 918 * @package WordPress 919 * @subpackage Taxonomy 907 920 * @since 2.3.0 908 921 * 909 922 * @uses $wpdb … … 919 932 */ 920 933 function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { 921 934 global $wpdb; 935 $null = null; 922 936 923 937 if ( empty($term) ) { 924 938 $error = new WP_Error('invalid_term', __('Empty Term')); … … 937 951 if ( is_object($term) ) 938 952 $term = $term->term_id; 939 953 if ( !$term = (int) $term ) 940 return null;954 return $null; 941 955 if ( ! $_term = wp_cache_get($term, $taxonomy) ) { 942 956 $_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 = %d LIMIT 1", $taxonomy, $term) ); 943 957 if ( ! $_term ) 944 return null;958 return $null; 945 959 wp_cache_add($term, $_term, $taxonomy); 946 960 } 947 961 } … … 975 989 * If $value does not exist, the return value will be false. If $taxonomy exists 976 990 * and $field and $value combinations exist, the Term will be returned. 977 991 * 992 * @package WordPress 993 * @subpackage Taxonomy 978 994 * @since 2.3.0 979 995 * 980 996 * @uses $wpdb … … 1042 1058 * 1043 1059 * Will return an empty array if $term does not exist in $taxonomy. 1044 1060 * 1061 * @package WordPress 1062 * @subpackage Taxonomy 1045 1063 * @since 2.3.0 1046 1064 * 1047 1065 * @uses $wpdb … … 1080 1098 * reasons and for simplicity of usage. See sanitize_term_field() for more 1081 1099 * information. 1082 1100 * 1101 * @package WordPress 1102 * @subpackage Taxonomy 1083 1103 * @since 2.3.0 1084 1104 * 1085 1105 * @uses sanitize_term_field() Passes the return value in sanitize_term_field on success. … … 1111 1131 * Return value is sanitize_term() and usage is for sanitizing the term for 1112 1132 * editing. Function is for contextual and simplicity. 1113 1133 * 1134 * @package WordPress 1135 * @subpackage Taxonomy 1114 1136 * @since 2.3.0 1115 1137 * 1116 1138 * @uses sanitize_term() Passes the return value on success … … 1220 1242 * query (such as 'terms_clauses'), setting 'cache_domain' to a unique value will not overwrite 1221 1243 * the cache for similar queries. Default value is 'core'. 1222 1244 * 1245 * @package WordPress 1246 * @subpackage Taxonomy 1223 1247 * @since 2.3.0 1224 1248 * 1225 1249 * @uses $wpdb … … 1253 1277 $args['number'] = absint( $args['number'] ); 1254 1278 $args['offset'] = absint( $args['offset'] ); 1255 1279 if ( !$single_taxonomy || ! is_taxonomy_hierarchical( reset( $taxonomies ) ) || 1256 ( '' !== $args['parent'] && 0 !== $args['parent'] )) {1280 '' !== $args['parent'] ) { 1257 1281 $args['child_of'] = 0; 1258 1282 $args['hierarchical'] = false; 1259 1283 $args['pad_counts'] = false; … … 1525 1549 * 1526 1550 * Formerly is_term(), introduced in 2.3.0. 1527 1551 * 1552 * @package WordPress 1553 * @subpackage Taxonomy 1528 1554 * @since 3.0.0 1529 1555 * 1530 1556 * @uses $wpdb … … 1619 1645 * 1620 1646 * The $term is expected to be either an array or an object. 1621 1647 * 1648 * @package WordPress 1649 * @subpackage Taxonomy 1622 1650 * @since 2.3.0 1623 1651 * 1624 1652 * @uses sanitize_term_field Used to sanitize all fields in a term … … 1667 1695 * without creating your own filter function. Simply create a function that 1668 1696 * hooks into the filter you need. 1669 1697 * 1698 * @package WordPress 1699 * @subpackage Taxonomy 1670 1700 * @since 2.3.0 1671 1701 * 1672 1702 * @uses $wpdb … … 1725 1755 * 1726 1756 * Default $args is 'hide_empty' which can be 'hide_empty=true' or array('hide_empty' => true). 1727 1757 * 1758 * @package WordPress 1759 * @subpackage Taxonomy 1728 1760 * @since 2.3.0 1729 1761 * 1730 1762 * @uses get_terms() … … 1756 1788 * a particular taxonomy or taxonomies. Does not remove the term or 1757 1789 * taxonomy itself. 1758 1790 * 1791 * @package WordPress 1792 * @subpackage Taxonomy 1759 1793 * @since 2.3.0 1760 1794 * @uses wp_remove_object_terms() 1761 1795 * … … 1786 1820 * 1787 1821 * The $args 'force_default' will force the term supplied as default to be 1788 1822 * assigned even if the object was not going to be termless 1789 * 1823 * @package WordPress 1824 * @subpackage Taxonomy 1790 1825 * @since 2.3.0 1791 1826 * 1792 1827 * @uses $wpdb … … 1916 1951 * terms objects will be returned. If either 'ids' or 'names' is used, then an 1917 1952 * array of all matching term ids or term names will be returned respectively. 1918 1953 * 1954 * @package WordPress 1955 * @subpackage Taxonomy 1919 1956 * @since 2.3.0 1920 1957 * @uses $wpdb 1921 1958 * … … 1933 1970 if ( !is_array($taxonomies) ) 1934 1971 $taxonomies = array($taxonomies); 1935 1972 1936 foreach ( $taxonomies as $taxonomy ) {1973 foreach ( (array) $taxonomies as $taxonomy ) { 1937 1974 if ( ! taxonomy_exists($taxonomy) ) 1938 1975 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 1939 1976 } … … 2202 2239 * A term has no meaning until it is given context by defining which taxonomy it 2203 2240 * exists under. 2204 2241 * 2242 * @package WordPress 2243 * @subpackage Taxonomy 2205 2244 * @since 2.3.0 2206 2245 * @uses wp_remove_object_terms() 2207 2246 * … … 2296 2335 /** 2297 2336 * Add term(s) associated with a given object. 2298 2337 * 2299 * @since 3.6.0 2338 * @package WordPress 2339 * @subpackage Taxonomy 2340 * @since 3.6 2300 2341 * @uses wp_set_object_terms() 2301 2342 * 2302 2343 * @param int $object_id The ID of the object to which the terms will be added. … … 2311 2352 /** 2312 2353 * Remove term(s) associated with a given object. 2313 2354 * 2314 * @since 3.6.0 2355 * @package WordPress 2356 * @subpackage Taxonomy 2357 * @since 3.6 2315 2358 * @uses $wpdb 2316 2359 * 2317 2360 * @uses apply_filters() Calls 'delete_term_relationships' hook with object_id and tt_ids as parameters. … … 2384 2427 * 2385 2428 * The only purpose for $term is for appending a parent, if one exists. 2386 2429 * 2430 * @package WordPress 2431 * @subpackage Taxonomy 2387 2432 * @since 2.3.0 2388 2433 * @uses $wpdb 2389 2434 * … … 2455 2500 * For what can be overrode in $args, check the term scheme can contain and stay 2456 2501 * away from the term keys. 2457 2502 * 2503 * @package WordPress 2504 * @subpackage Taxonomy 2458 2505 * @since 2.3.0 2459 2506 * 2460 2507 * @uses $wpdb … … 2545 2592 $wpdb->update( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' => $tt_id ) ); 2546 2593 do_action( 'edited_term_taxonomy', $tt_id, $taxonomy ); 2547 2594 2548 // Clean the relationship caches for all object types using this term2549 $objects = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) );2550 $tax_object = get_taxonomy( $taxonomy );2551 foreach ( $tax_object->object_type as $object_type )2552 clean_object_term_cache( $objects, $object_type );2553 2554 2595 do_action("edit_term", $term_id, $tt_id, $taxonomy); 2555 2596 do_action("edit_$taxonomy", $term_id, $tt_id); 2556 2597 … … 2594 2635 * The default action is to count what the amount of terms have the relationship 2595 2636 * of term ID. Once that is done, then update the database. 2596 2637 * 2638 * @package WordPress 2639 * @subpackage Taxonomy 2597 2640 * @since 2.3.0 2598 2641 * @uses $wpdb 2599 2642 * … … 2676 2719 * term IDs have to exist within the taxonomy $object_type for the deletion to 2677 2720 * take place. 2678 2721 * 2722 * @package WordPress 2723 * @subpackage Taxonomy 2679 2724 * @since 2.3.0 2680 2725 * 2681 2726 * @see get_object_taxonomies() for more on $object_type … … 2691 2736 2692 2737 $taxonomies = get_object_taxonomies( $object_type ); 2693 2738 2694 foreach ( $object_ids as $id ) {2695 foreach ( $taxonomies as $taxonomy ) {2739 foreach ( $object_ids as $id ) 2740 foreach ( $taxonomies as $taxonomy ) 2696 2741 wp_cache_delete($id, "{$taxonomy}_relationships"); 2697 }2698 }2699 2742 2700 2743 do_action('clean_object_term_cache', $object_ids, $object_type); 2701 2744 } … … 2703 2746 /** 2704 2747 * Will remove all of the term ids from the cache. 2705 2748 * 2749 * @package WordPress 2750 * @subpackage Taxonomy 2706 2751 * @since 2.3.0 2707 2752 * @uses $wpdb 2708 2753 * … … 2712 2757 */ 2713 2758 function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { 2714 2759 global $wpdb; 2760 static $cleaned = array(); 2715 2761 2716 2762 if ( !is_array($ids) ) 2717 2763 $ids = array($ids); … … 2739 2785 } 2740 2786 2741 2787 foreach ( $taxonomies as $taxonomy ) { 2788 if ( isset($cleaned[$taxonomy]) ) 2789 continue; 2790 $cleaned[$taxonomy] = true; 2791 2742 2792 if ( $clean_taxonomy ) { 2743 2793 wp_cache_delete('all_ids', $taxonomy); 2744 2794 wp_cache_delete('get', $taxonomy); … … 2756 2806 /** 2757 2807 * Retrieves the taxonomy relationship to the term object id. 2758 2808 * 2809 * @package WordPress 2810 * @subpackage Taxonomy 2759 2811 * @since 2.3.0 2760 2812 * 2761 2813 * @uses wp_cache_get() Retrieves taxonomy relationship from cache … … 2782 2834 * lot of terms that exist in a lot of taxonomies. The amount of time increases 2783 2835 * for each term and it also increases for each taxonomy the term belongs to. 2784 2836 * 2837 * @package WordPress 2838 * @subpackage Taxonomy 2785 2839 * @since 2.3.0 2786 2840 * @uses wp_get_object_terms() Used to get terms from the database to update 2787 2841 * … … 2839 2893 /** 2840 2894 * Updates Terms to Taxonomy in cache. 2841 2895 * 2896 * @package WordPress 2897 * @subpackage Taxonomy 2842 2898 * @since 2.3.0 2843 2899 * 2844 2900 * @param array $terms List of Term objects to change … … 2861 2917 /** 2862 2918 * Retrieves children of taxonomy as Term IDs. 2863 2919 * 2920 * @package WordPress 2921 * @subpackage Taxonomy 2864 2922 * @access private 2865 2923 * @since 2.3.0 2866 2924 * … … 2894 2952 * If $terms is an array of objects, then _get_term_children returns an array of objects. 2895 2953 * If $terms is an array of IDs, then _get_term_children returns an array of IDs. 2896 2954 * 2955 * @package WordPress 2956 * @subpackage Taxonomy 2897 2957 * @access private 2898 2958 * @since 2.3.0 2899 2959 * … … 2922 2982 $use_id = true; 2923 2983 } 2924 2984 2925 if ( $term->term_id == $term_id ) { 2926 if ( isset( $has_children[$term_id] ) ) { 2927 $current_id = $term_id; 2928 while ( $current_id > 0 ) { 2929 foreach ( $has_children[$current_id] as $t_id ) { 2930 if ( $use_id ) { 2931 $term_list[] = $t_id; 2932 } else { 2933 $term_list[] = get_term( $t_id, $taxonomy ); 2934 } 2935 } 2936 2937 $current_id = isset( $has_children[$t_id] ) ? $t_id : 0; 2938 } 2939 } 2985 if ( $term->term_id == $term_id ) 2940 2986 continue; 2941 }2942 2987 2943 2988 if ( $term->parent == $term_id ) { 2944 2989 if ( $use_id ) … … 2963 3008 * Recalculates term counts by including items from child terms. Assumes all 2964 3009 * relevant children are already in the $terms argument. 2965 3010 * 3011 * @package WordPress 3012 * @subpackage Taxonomy 2966 3013 * @access private 2967 3014 * @since 2.3.0 2968 3015 * @uses $wpdb … … 3027 3074 * Private function for the default callback for post_tag and category 3028 3075 * taxonomies. 3029 3076 * 3077 * @package WordPress 3078 * @subpackage Taxonomy 3030 3079 * @access private 3031 3080 * @since 2.3.0 3032 3081 * @uses $wpdb … … 3073 3122 * 3074 3123 * Default callback for the link_category taxonomy. 3075 3124 * 3125 * @package WordPress 3126 * @subpackage Taxonomy 3076 3127 * @since 3.3.0 3077 3128 * @uses $wpdb 3078 3129 * … … 3186 3237 'before' => '', 3187 3238 'sep' => ' ', 3188 3239 'after' => '', 3189 'template' => '%s: %l.' 3240 'template' => '%s: %l.', 3241 'links' => true, 3190 3242 ); 3191 3243 3192 3244 $r = wp_parse_args( $args, $defaults ); … … 3212 3264 3213 3265 $args = wp_parse_args( $args, array( 3214 3266 'template' => '%s: %l.', 3267 'links' => true, 3215 3268 ) ); 3216 3269 extract( $args, EXTR_SKIP ); 3217 3270 … … 3233 3286 if ( false === $terms ) 3234 3287 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); 3235 3288 3236 $links = array();3237 3289 3238 foreach ( $terms as $term ) 3239 $links[] = "<a href='" . esc_attr( get_term_link($term) ) . "'>$term->name</a>"; 3290 $list = array(); 3291 3292 if ( $links ) { 3240 3293 3241 if ( $links ) 3242 $taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links, $terms); 3294 foreach ( $terms as $term ) 3295 $list[] = "<a href='" . esc_attr( get_term_link($term) ) . "'>$term->name</a>"; 3296 3297 } else { 3298 3299 foreach ( $terms as $term ) 3300 $list[] = $term->name; 3301 3302 } 3303 3304 if ( $list ) 3305 $taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $list, $terms); 3243 3306 } 3307 3308 // return $args; 3244 3309 return $taxonomies; 3245 3310 } 3246 3311 … … 3415 3480 wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) ); 3416 3481 3417 3482 return $parent; 3418 } 3419 No newline at end of file 3483 }