Changes in trunk/wp-includes/taxonomy.php [19077:20972]
- File:
-
- 1 edited
-
trunk/wp-includes/taxonomy.php (modified) (37 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/taxonomy.php
r19077 r20972 13 13 14 14 /** 15 * Creates the initial taxonomies when 'init' action is fired. 15 * Creates the initial taxonomies. 16 * 17 * This function fires twice: in wp-settings.php before plugins are loaded (for 18 * backwards compatibility reasons), and again on the 'init' action. We must avoid 19 * registering rewrite rules before the 'init' action. 16 20 */ 17 21 function create_initial_taxonomies() { 18 22 global $wp_rewrite; 23 24 if ( ! did_action( 'init' ) ) { 25 $rewrite = array( 'category' => false, 'post_tag' => false, 'post_format' => false ); 26 } else { 27 $post_format_base = apply_filters( 'post_format_rewrite_base', 'type' ); 28 $rewrite = array( 29 'category' => array( 30 'hierarchical' => true, 31 'slug' => get_option('category_base') ? get_option('category_base') : 'category', 32 'with_front' => ! get_option('category_base') || $wp_rewrite->using_index_permalinks(), 33 'ep_mask' => EP_CATEGORIES, 34 ), 35 'post_tag' => array( 36 'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag', 37 'with_front' => ! get_option('tag_base') || $wp_rewrite->using_index_permalinks(), 38 'ep_mask' => EP_TAGS, 39 ), 40 'post_format' => $post_format_base ? array( 'slug' => $post_format_base ) : false, 41 ); 42 } 19 43 20 44 register_taxonomy( 'category', 'post', array( 21 45 'hierarchical' => true, 22 46 'query_var' => 'category_name', 23 'rewrite' => did_action( 'init' ) ? array( 24 'hierarchical' => true, 25 'slug' => get_option('category_base') ? get_option('category_base') : 'category', 26 'with_front' => ( get_option('category_base') && ! $wp_rewrite->using_index_permalinks() ) ? false : true ) : false, 47 'rewrite' => $rewrite['category'], 27 48 'public' => true, 28 49 'show_ui' => true, … … 33 54 'hierarchical' => false, 34 55 'query_var' => 'tag', 35 'rewrite' => did_action( 'init' ) ? array( 36 'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag', 37 'with_front' => ( get_option('tag_base') && ! $wp_rewrite->using_index_permalinks() ) ? false : true ) : false, 56 'rewrite' => $rewrite['post_tag'], 38 57 'public' => true, 39 58 'show_ui' => true, … … 78 97 ) ); 79 98 80 $rewrite = false;81 if ( did_action( 'init' ) ) {82 $rewrite = apply_filters( 'post_format_rewrite_base', 'type' );83 $rewrite = $rewrite ? array( 'slug' => $rewrite ) : false;84 }85 86 99 register_taxonomy( 'post_format', 'post', array( 87 100 'public' => true, … … 92 105 ), 93 106 'query_var' => true, 94 'rewrite' => $rewrite ,107 'rewrite' => $rewrite['post_format'], 95 108 'show_ui' => false, 96 109 '_builtin' => true, 97 'show_in_nav_menus' => false,110 'show_in_nav_menus' => current_theme_supports( 'post-formats' ), 98 111 ) ); 99 112 } … … 122 135 return wp_filter_object_list($wp_taxonomies, $args, $operator, $field); 123 136 } 124 125 137 126 138 /** … … 285 297 * @since 2.3.0 286 298 * @uses $wp_taxonomies Inserts new taxonomy object into the list 287 * @uses $wp_rewrite Adds rewrite tags and permastructs288 299 * @uses $wp Adds query vars 289 300 * … … 293 304 */ 294 305 function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 295 global $wp_taxonomies, $wp _rewrite, $wp;306 global $wp_taxonomies, $wp; 296 307 297 308 if ( ! is_array($wp_taxonomies) ) … … 319 330 } 320 331 321 if ( false !== $args['rewrite'] && '' != get_option('permalink_structure') ) {332 if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option('permalink_structure') ) ) { 322 333 $args['rewrite'] = wp_parse_args($args['rewrite'], array( 323 334 'slug' => sanitize_title_with_dashes($taxonomy), 324 335 'with_front' => true, 325 'hierarchical' => false 336 'hierarchical' => false, 337 'ep_mask' => EP_NONE, 326 338 )); 327 339 … … 331 343 $tag = '([^/]+)'; 332 344 333 $wp_rewrite->add_rewrite_tag("%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=");334 $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']);345 add_rewrite_tag( "%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=" ); 346 add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite'] ); 335 347 } 336 348 … … 380 392 * - parent_item_colon - The same as <code>parent_item</code>, but with colon <code>:</code> in the end 381 393 * - edit_item - Default is Edit Tag/Edit Category 394 * - view_item - Default is View Tag/View Category 382 395 * - update_item - Default is Update Tag/Update Category 383 396 * - add_new_item - Default is Add New Tag/Add New Category 384 397 * - new_item_name - Default is New Tag Name/New Category Name 385 * - separate_items_with_commas - This string isn't used on hierarchical taxonomies. Default is "Separate tags with commas ,"used in the meta box.386 * - 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.387 * - 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.388 * 389 * Above, the first default value is for non-hierarchical taxonomies (like tags) and the second one is for hierarchical taxonomies (like categories .)398 * - separate_items_with_commas - This string isn't used on hierarchical taxonomies. Default is "Separate tags with commas", used in the meta box. 399 * - 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. 400 * - 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. 401 * 402 * Above, the first default value is for non-hierarchical taxonomies (like tags) and the second one is for hierarchical taxonomies (like categories). 390 403 * 391 404 * @since 3.0.0 … … 429 442 * 430 443 * @param string $taxonomy Name of taxonomy object 431 * @param array|string $object_type Name of the object type444 * @param string $object_type Name of the object type 432 445 * @return bool True if successful, false if not 433 446 */ … … 490 503 foreach ( (array) $taxonomies as $taxonomy ) { 491 504 if ( ! taxonomy_exists( $taxonomy ) ) 492 return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) );505 return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) ); 493 506 } 494 507 … … 843 856 844 857 if ( ! taxonomy_exists($taxonomy) ) { 845 $error = new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));858 $error = new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 846 859 return $error; 847 860 } … … 972 985 function get_term_children( $term_id, $taxonomy ) { 973 986 if ( ! taxonomy_exists($taxonomy) ) 974 return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));987 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 975 988 976 989 $term_id = intval( $term_id ); … … 1084 1097 * terms whose count is 0 according to the given taxonomy. 1085 1098 * 1086 * exclude - Default is an empty array. An array, comma- or space-delimited string1087 * of term ids to exclude from the return array. If 'include' is non-empty,1099 * exclude - Default is an empty array. An array, comma- or space-delimited string 1100 * of term ids to exclude from the return array. If 'include' is non-empty, 1088 1101 * 'exclude' is ignored. 1089 1102 * 1090 * exclude_tree - Default is an empty array. An array, comma- or space-delimited1103 * exclude_tree - Default is an empty array. An array, comma- or space-delimited 1091 1104 * string of term ids to exclude from the return array, along with all of their 1092 * descendant terms according to the primary taxonomy. If 'include' is non-empty,1105 * descendant terms according to the primary taxonomy. If 'include' is non-empty, 1093 1106 * 'exclude_tree' is ignored. 1094 1107 * 1095 * include - Default is an empty array. An array, comma- or space-delimited string1108 * include - Default is an empty array. An array, comma- or space-delimited string 1096 1109 * of term ids to include in the return array. 1097 1110 * 1098 * number - The maximum number of terms to return. Default is to return them all.1111 * number - The maximum number of terms to return. Default is to return them all. 1099 1112 * 1100 1113 * offset - The number by which to offset the terms query. … … 1110 1123 * 1111 1124 * search - Returned terms' names will contain the value of 'search', 1112 * case-insensitive. Default is an empty string.1125 * case-insensitive. Default is an empty string. 1113 1126 * 1114 1127 * name__like - Returned terms' names will begin with the value of 'name__like', … … 1121 1134 * returns terms regardless of ancestry or whether the terms are empty. 1122 1135 * 1123 * The 'child_of' argument, when used, should be set to the integer of a term ID. Its default1124 * is 0. If set to a non-zero value, all returned terms will be descendants1125 * of that term according to the given taxonomy. Hence 'child_of' is set to 01136 * The 'child_of' argument, when used, should be set to the integer of a term ID. Its default 1137 * is 0. If set to a non-zero value, all returned terms will be descendants 1138 * of that term according to the given taxonomy. Hence 'child_of' is set to 0 1126 1139 * if more than one taxonomy is passed in $taxonomies, because multiple taxonomies 1127 1140 * make term ancestry ambiguous. 1128 1141 * 1129 * The 'parent' argument, when used, should be set to the integer of a term ID. Its default is1142 * The 'parent' argument, when used, should be set to the integer of a term ID. Its default is 1130 1143 * the empty string '', which has a different meaning from the integer 0. 1131 1144 * If set to an integer value, all returned terms will have as an immediate … … 1162 1175 foreach ( $taxonomies as $taxonomy ) { 1163 1176 if ( ! taxonomy_exists($taxonomy) ) { 1164 $error = new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));1177 $error = new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 1165 1178 return $error; 1166 1179 } … … 1432 1445 * Check if Term exists. 1433 1446 * 1434 * Returns the index of a defined term, or 0 (false) if the term doesn't exist.1435 *1436 1447 * Formerly is_term(), introduced in 2.3.0. 1437 1448 * … … 1445 1456 * @param string $taxonomy The taxonomy name to use 1446 1457 * @param int $parent ID of parent term under which to confine the exists search. 1447 * @return mixed Get the term id or Term Object, if exists. 1458 * @return mixed Returns 0 if the term does not exist. Returns the term ID if no taxonomy is specified 1459 * and the term ID exists. Returns an array of the term ID and the taxonomy if the pairing exists. 1448 1460 */ 1449 1461 function term_exists($term, $taxonomy = '', $parent = 0) { … … 1494 1506 1495 1507 return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where", $else_where_fields) ); 1508 } 1509 1510 /** 1511 * Check if a term is an ancestor of another term. 1512 * 1513 * You can use either an id or the term object for both parameters. 1514 * 1515 * @since 3.4.0 1516 * 1517 * @param int|object $term1 ID or object to check if this is the parent term. 1518 * @param int|object $term2 The child term. 1519 * @param string $taxonomy Taxonomy name that $term1 and $term2 belong to. 1520 * @return bool Whether $term2 is child of $term1 1521 */ 1522 function term_is_ancestor_of( $term1, $term2, $taxonomy ) { 1523 if ( ! isset( $term1->term_id ) ) 1524 $term1 = get_term( $term1, $taxonomy ); 1525 if ( ! isset( $term2->parent ) ) 1526 $term2 = get_term( $term2, $taxonomy ); 1527 1528 if ( empty( $term1->term_id ) || empty( $term2->parent ) ) 1529 return false; 1530 if ( $term2->parent == $term1->term_id ) 1531 return true; 1532 1533 return term_is_ancestor_of( $term1, get_term( $term2->parent, $taxonomy ), $taxonomy ); 1496 1534 } 1497 1535 … … 1766 1804 1767 1805 do_action( 'delete_term_taxonomy', $tt_id ); 1768 $wpdb-> query( $wpdb->prepare( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d",$tt_id ) );1806 $wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $tt_id ) ); 1769 1807 do_action( 'deleted_term_taxonomy', $tt_id ); 1770 1808 1771 1809 // Delete the term if no taxonomies use it. 1772 1810 if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) ) 1773 $wpdb-> query( $wpdb->prepare( "DELETE FROM $wpdb->terms WHERE term_id = %d", $term) );1811 $wpdb->delete( $wpdb->terms, array( 'term_id' => $term ) ); 1774 1812 1775 1813 clean_term_cache($term, $taxonomy); … … 1825 1863 * @param string|array $taxonomies The taxonomies to retrieve terms from. 1826 1864 * @param array|string $args Change what is returned 1827 * @return array|WP_Error The requested term data or empty array if no terms found. WP_Error if $taxonomy does not exist.1865 * @return array|WP_Error The requested term data or empty array if no terms found. WP_Error if any of the $taxonomies don't exist. 1828 1866 */ 1829 1867 function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { 1830 1868 global $wpdb; 1831 1869 1870 if ( empty( $object_ids ) || empty( $taxonomies ) ) 1871 return array(); 1872 1832 1873 if ( !is_array($taxonomies) ) 1833 1874 $taxonomies = array($taxonomies); … … 1835 1876 foreach ( (array) $taxonomies as $taxonomy ) { 1836 1877 if ( ! taxonomy_exists($taxonomy) ) 1837 return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));1878 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 1838 1879 } 1839 1880 … … 2106 2147 2107 2148 if ( ! taxonomy_exists($taxonomy) ) 2108 return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));2149 return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); 2109 2150 2110 2151 if ( !is_array($terms) ) … … 2474 2515 // 2475 2516 2476 2477 2517 /** 2478 2518 * Removes the taxonomy relationship to terms from the cache. … … 2503 2543 do_action('clean_object_term_cache', $object_ids, $object_type); 2504 2544 } 2505 2506 2545 2507 2546 /** … … 2565 2604 } 2566 2605 2567 2568 2606 /** 2569 2607 * Retrieves the taxonomy relationship to the term object id. … … 2583 2621 return $cache; 2584 2622 } 2585 2586 2623 2587 2624 /** … … 2638 2675 2639 2676 foreach ( $ids as $id ) { 2640 foreach ( $taxonomies as $taxonomy ) {2677 foreach ( $taxonomies as $taxonomy ) { 2641 2678 if ( ! isset($object_terms[$id][$taxonomy]) ) { 2642 2679 if ( !isset($object_terms[$id]) ) … … 2649 2686 foreach ( $object_terms as $id => $value ) { 2650 2687 foreach ( $value as $taxonomy => $terms ) { 2651 wp_cache_set($id, $terms, "{$taxonomy}_relationships"); 2652 } 2653 } 2654 } 2655 2688 wp_cache_add( $id, $terms, "{$taxonomy}_relationships" ); 2689 } 2690 } 2691 } 2656 2692 2657 2693 /** … … 2678 2714 // Private 2679 2715 // 2680 2681 2716 2682 2717 /** … … 2712 2747 } 2713 2748 2714 2715 2749 /** 2716 2750 * Get the subset of $terms that are descendants of $term_id. … … 2768 2802 return $term_list; 2769 2803 } 2770 2771 2804 2772 2805 /** … … 2878 2911 if ( $object_types ) 2879 2912 $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type IN ('" . implode("', '", $object_types ) . "') AND term_taxonomy_id = %d", $term ) ); 2880 2881 2913 2882 2914 do_action( 'edit_term_taxonomy', $term, $taxonomy ); … … 3095 3127 * @param int $object_id ID of the object (post ID, link ID, ...) 3096 3128 * @param string $taxonomy Single taxonomy name 3097 * @param int|string|array $terms Optional. Term term_id, name, slug or array of said3129 * @param int|string|array $terms Optional. Term term_id, name, slug or array of said 3098 3130 * @return bool|WP_Error. WP_Error on input error. 3099 3131 */ … … 3241 3273 return 0; 3242 3274 3243 // There's a loop, but it doesn't contain $term_id. Break the loop.3275 // There's a loop, but it doesn't contain $term_id. Break the loop. 3244 3276 foreach ( array_keys( $loop ) as $loop_member ) 3245 3277 wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) );
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)