diff --git src/bp-core/bp-core-taxonomy.php src/bp-core/bp-core-taxonomy.php
index bd544b4..c5a50ab 100644
|
|
function bp_register_default_taxonomies() { |
45 | 45 | add_action( 'bp_register_taxonomies', 'bp_register_default_taxonomies' ); |
46 | 46 | |
47 | 47 | /** |
| 48 | * Get the ID of the site that BP should use for taxonomy term storage. |
| 49 | * |
| 50 | * Defaults to the root blog ID. |
| 51 | * |
| 52 | * @return int |
| 53 | */ |
| 54 | function bp_get_taxonomy_term_site_id( $taxonomy = '' ) { |
| 55 | $site_id = bp_get_root_blog_id(); |
| 56 | |
| 57 | /** |
| 58 | * Filters the ID of the site where BP should store taxonomy terms. |
| 59 | * |
| 60 | * @param int $site_id |
| 61 | * @param string $taxonomy |
| 62 | */ |
| 63 | return (int) apply_filters( 'bp_get_taxonomy_term_site_id', $site_id, $taxonomy ); |
| 64 | } |
| 65 | |
| 66 | /** |
48 | 67 | * Set taxonomy terms on a BuddyPress object. |
49 | 68 | * |
50 | 69 | * @since 2.2.0 |
… |
… |
add_action( 'bp_register_taxonomies', 'bp_register_default_taxonomies' ); |
58 | 77 | * @return array Array of term taxonomy IDs. |
59 | 78 | */ |
60 | 79 | function bp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { |
61 | | $is_root_blog = bp_is_root_blog(); |
| 80 | $site_id = bp_get_taxonomy_term_site_id( $taxonomy ); |
62 | 81 | |
63 | | if ( ! $is_root_blog ) { |
64 | | switch_to_blog( bp_get_root_blog_id() ); |
| 82 | $switched = false; |
| 83 | if ( $site_id !== get_current_blog_id() ) { |
| 84 | switch_to_blog( $site_id ); |
65 | 85 | bp_register_taxonomies(); |
| 86 | $switched = true; |
66 | 87 | } |
67 | 88 | |
68 | 89 | $retval = wp_set_object_terms( $object_id, $terms, $taxonomy, $append ); |
69 | 90 | |
70 | | if ( ! $is_root_blog ) { |
| 91 | if ( ! $switched ) { |
71 | 92 | restore_current_blog(); |
72 | 93 | } |
73 | 94 | |
… |
… |
function bp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { |
87 | 108 | * @return array |
88 | 109 | */ |
89 | 110 | function bp_get_object_terms( $object_ids, $taxonomies, $args = array() ) { |
90 | | $is_root_blog = bp_is_root_blog(); |
| 111 | $site_id = bp_get_taxonomy_term_site_id( $taxonomy ); |
91 | 112 | |
92 | | if ( ! $is_root_blog ) { |
93 | | switch_to_blog( bp_get_root_blog_id() ); |
| 113 | $switched = false; |
| 114 | if ( $site_id !== get_current_blog_id() ) { |
| 115 | switch_to_blog( $site_id ); |
94 | 116 | bp_register_taxonomies(); |
| 117 | $switched = true; |
95 | 118 | } |
96 | 119 | |
97 | 120 | $retval = wp_get_object_terms( $object_ids, $taxonomies, $args ); |
98 | 121 | |
99 | | if ( ! $is_root_blog ) { |
| 122 | if ( ! $switched ) { |
100 | 123 | restore_current_blog(); |
101 | 124 | } |
102 | 125 | |
… |
… |
function bp_get_object_terms( $object_ids, $taxonomies, $args = array() ) { |
116 | 139 | * @return bool|WP_Error True on success, false or WP_Error on failure. |
117 | 140 | */ |
118 | 141 | function bp_remove_object_terms( $object_id, $terms, $taxonomy ) { |
119 | | $is_root_blog = bp_is_root_blog(); |
| 142 | $site_id = bp_get_taxonomy_term_site_id( $taxonomy ); |
120 | 143 | |
121 | | if ( ! $is_root_blog ) { |
122 | | switch_to_blog( bp_get_root_blog_id() ); |
| 144 | $switched = false; |
| 145 | if ( $site_id !== get_current_blog_id() ) { |
| 146 | switch_to_blog( $site_id ); |
123 | 147 | bp_register_taxonomies(); |
| 148 | $switched = true; |
124 | 149 | } |
125 | 150 | |
126 | 151 | $retval = wp_remove_object_terms( $object_id, $terms, $taxonomy ); |
127 | 152 | |
128 | | if ( ! $is_root_blog ) { |
| 153 | if ( ! $switched ) { |
129 | 154 | restore_current_blog(); |
130 | 155 | } |
131 | 156 | |