Changeset 10818
- Timestamp:
- 05/28/2016 01:43:05 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-taxonomy.php
r10765 r10818 46 46 47 47 /** 48 * Gets the ID of the site that BP should use for taxonomy term storage. 49 * 50 * Defaults to the root blog ID. 51 * 52 * @since 2.6.0 53 * 54 * @return int 55 */ 56 function bp_get_taxonomy_term_site_id( $taxonomy = '' ) { 57 $site_id = bp_get_root_blog_id(); 58 59 /** 60 * Filters the ID of the site where BP should store taxonomy terms. 61 * 62 * @since 2.6.0 63 * 64 * @param int $site_id 65 * @param string $taxonomy 66 */ 67 return (int) apply_filters( 'bp_get_taxonomy_term_site_id', $site_id, $taxonomy ); 68 } 69 70 /** 48 71 * Set taxonomy terms on a BuddyPress object. 49 72 * … … 59 82 */ 60 83 function bp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { 61 $ is_root_blog = bp_is_root_blog();84 $site_id = bp_get_taxonomy_term_site_id( $taxonomy ); 62 85 63 if ( ! $is_root_blog ) { 64 switch_to_blog( bp_get_root_blog_id() ); 86 $switched = false; 87 if ( $site_id !== get_current_blog_id() ) { 88 switch_to_blog( $site_id ); 65 89 bp_register_taxonomies(); 90 $switched = true; 66 91 } 67 92 68 93 $retval = wp_set_object_terms( $object_id, $terms, $taxonomy, $append ); 69 94 70 if ( ! $ is_root_blog) {95 if ( ! $switched ) { 71 96 restore_current_blog(); 72 97 } … … 88 113 */ 89 114 function bp_get_object_terms( $object_ids, $taxonomies, $args = array() ) { 90 $is_root_blog = bp_is_root_blog();91 92 if ( ! $is_root_blog) {93 switch_to_blog( bp_get_root_blog_id());94 bp_register_taxonomies();115 // Different taxonomies must be stored on different sites. 116 $taxonomy_site_map = array(); 117 foreach ( (array) $taxonomies as $taxonomy ) { 118 $taxonomy_site_id = bp_get_taxonomy_term_site_id( $taxonomy ); 119 $taxonomy_site_map[ $taxonomy_site_id ][] = $taxonomy; 95 120 } 96 121 97 $retval = wp_get_object_terms( $object_ids, $taxonomies, $args ); 122 $retval = array(); 123 foreach ( $taxonomy_site_map as $taxonomy_site_id => $site_taxonomies ) { 124 $switched = false; 125 if ( $taxonomy_site_id !== get_current_blog_id() ) { 126 switch_to_blog( $site_id ); 127 bp_register_taxonomies(); 128 $switched = true; 129 } 98 130 99 if ( ! $is_root_blog ) { 100 restore_current_blog(); 131 $site_terms = wp_get_object_terms( $object_ids, $site_taxonomies, $args ); 132 $retval = array_merge( $retval, $site_terms ); 133 134 if ( ! $switched ) { 135 restore_current_blog(); 136 } 101 137 } 102 138 … … 117 153 */ 118 154 function bp_remove_object_terms( $object_id, $terms, $taxonomy ) { 119 $ is_root_blog = bp_is_root_blog();155 $site_id = bp_get_taxonomy_term_site_id( $taxonomy ); 120 156 121 if ( ! $is_root_blog ) { 122 switch_to_blog( bp_get_root_blog_id() ); 157 $switched = false; 158 if ( $site_id !== get_current_blog_id() ) { 159 switch_to_blog( $site_id ); 123 160 bp_register_taxonomies(); 161 $switched = true; 124 162 } 125 163 126 164 $retval = wp_remove_object_terms( $object_id, $terms, $taxonomy ); 127 165 128 if ( ! $ is_root_blog) {166 if ( ! $switched ) { 129 167 restore_current_blog(); 130 168 }
Note: See TracChangeset
for help on using the changeset viewer.