diff --git src/bp-core/bp-core-taxonomy.php src/bp-core/bp-core-taxonomy.php
index bd544b4..61c29c5 100644
|
|
add_action( 'bp_register_taxonomies', 'bp_register_default_taxonomies' ); |
50 | 50 | * @since 2.2.0 |
51 | 51 | * |
52 | 52 | * @see wp_set_object_terms() for a full description of function and parameters. |
| 53 | * @uses apply_filters() Calls 'bp_taxonomy_scope. |
53 | 54 | * |
54 | 55 | * @param int $object_id Object ID. |
55 | 56 | * @param string|array $terms Term or terms to set. |
56 | 57 | * @param string $taxonomy Taxonomy name. |
57 | 58 | * @param bool $append Optional. True to append terms to existing terms. Default: false. |
| 59 | * @param string $scope Local, Network or Global |
58 | 60 | * @return array Array of term taxonomy IDs. |
59 | 61 | */ |
60 | | function bp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { |
61 | | $is_root_blog = bp_is_root_blog(); |
| 62 | function bp_set_object_terms( $object_id, $terms, $taxonomy, $append = false, $scope = 'network' ) { |
| 63 | $starting_blog_id = get_current_blog_id(); |
| 64 | |
| 65 | $scope = apply_filters( "bp_taxonomy_${taxonomy}_scope", $scope ); |
| 66 | |
| 67 | switch ( $scope ) { |
| 68 | case 'local': |
| 69 | $target_blog_id = $starting_blog_id; |
| 70 | break; |
| 71 | case 'network': |
| 72 | $target_blog_id = bp_get_root_blog_id(); |
| 73 | break; |
| 74 | case 'global': |
| 75 | $main_network = wp_get_network( get_main_network_id() ); |
| 76 | $target_blog_id = get_site_by_path( $main_network->domain, $main_network->path ); |
| 77 | break; |
| 78 | } |
62 | 79 | |
63 | | if ( ! $is_root_blog ) { |
64 | | switch_to_blog( bp_get_root_blog_id() ); |
| 80 | if ( $starting_blog_id !== $target_blog_id ) { |
| 81 | switch_to_blog( $target_blog_id ); |
65 | 82 | bp_register_taxonomies(); |
66 | 83 | } |
67 | | |
| 84 | |
68 | 85 | $retval = wp_set_object_terms( $object_id, $terms, $taxonomy, $append ); |
69 | | |
70 | | if ( ! $is_root_blog ) { |
| 86 | |
| 87 | if ( $starting_blog_id !== $target_blog_id ) { |
71 | 88 | restore_current_blog(); |
72 | 89 | } |
73 | 90 | |
… |
… |
function bp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { |
80 | 97 | * @since 2.2.0 |
81 | 98 | * |
82 | 99 | * @see wp_get_object_terms() for a full description of function and parameters. |
| 100 | * @uses apply_filters() Calls 'bp_taxonomy_scope. |
83 | 101 | * |
84 | 102 | * @param int|array $object_ids ID or IDs of objects. |
85 | 103 | * @param string|array $taxonomies Name or names of taxonomies to match. |
86 | 104 | * @param array $args See {@see wp_get_object_terms()}. |
| 105 | * @param string $scope Local, Network or Global |
87 | 106 | * @return array |
88 | 107 | */ |
89 | | function bp_get_object_terms( $object_ids, $taxonomies, $args = array() ) { |
90 | | $is_root_blog = bp_is_root_blog(); |
| 108 | function bp_get_object_terms( $object_ids, $taxonomies, $args = array(), $scope = 'network' ) { |
| 109 | $starting_blog_id = get_current_blog_id(); |
91 | 110 | |
92 | | if ( ! $is_root_blog ) { |
93 | | switch_to_blog( bp_get_root_blog_id() ); |
94 | | bp_register_taxonomies(); |
| 111 | if ( ! is_array( $taxonomies ) ) { // If we want to handle an array here then all results should match otherwise ignore the results. |
| 112 | $scope = apply_filters( "bp_taxonomy_${taxonomies}_scope", $scope ); |
95 | 113 | } |
96 | 114 | |
| 115 | switch ( $scope ) { |
| 116 | case 'local': |
| 117 | $target_blog_id = $starting_blog_id; |
| 118 | break; |
| 119 | case 'network': |
| 120 | $target_blog_id = bp_get_root_blog_id(); |
| 121 | break; |
| 122 | case 'global': |
| 123 | $main_network = wp_get_network( get_main_network_id() ); |
| 124 | $target_blog_id = get_site_by_path( $main_network->domain, $main_network->path ); |
| 125 | break; |
| 126 | } |
| 127 | |
| 128 | if ( $starting_blog_id !== $target_blog_id ) { |
| 129 | switch_to_blog( $target_blog_id ); |
| 130 | bp_register_taxonomies(); |
| 131 | } |
| 132 | |
97 | 133 | $retval = wp_get_object_terms( $object_ids, $taxonomies, $args ); |
98 | 134 | |
99 | | if ( ! $is_root_blog ) { |
100 | | restore_current_blog(); |
101 | | } |
| 135 | if ( $starting_blog_id !== $target_blog_id ) { |
| 136 | restore_current_blog(); |
| 137 | } |
102 | 138 | |
103 | 139 | return $retval; |
104 | 140 | } |
… |
… |
function bp_get_object_terms( $object_ids, $taxonomies, $args = array() ) { |
109 | 145 | * @since 2.3.0 |
110 | 146 | * |
111 | 147 | * @see wp_remove_object_terms() for a full description of function and parameters. |
| 148 | * @uses apply_filters() Calls 'bp_taxonomy_scope. |
112 | 149 | * |
113 | 150 | * @param int $object_id Object ID. |
114 | 151 | * @param string|array $terms Term or terms to remove. |
115 | 152 | * @param string $taxonomy Taxonomy name. |
| 153 | * @param string $scope Local, Network or Global |
116 | 154 | * @return bool|WP_Error True on success, false or WP_Error on failure. |
117 | 155 | */ |
118 | | function bp_remove_object_terms( $object_id, $terms, $taxonomy ) { |
119 | | $is_root_blog = bp_is_root_blog(); |
120 | | |
121 | | if ( ! $is_root_blog ) { |
122 | | switch_to_blog( bp_get_root_blog_id() ); |
123 | | bp_register_taxonomies(); |
124 | | } |
| 156 | function bp_remove_object_terms( $object_id, $terms, $taxonomy, $scope = 'network' ) { |
| 157 | $starting_blog_id = get_current_blog_id(); |
| 158 | |
| 159 | $scope = apply_filters( "bp_taxonomy_${taxonomy}_scope", $scope ); |
| 160 | |
| 161 | switch ( $scope ) { |
| 162 | case 'local': |
| 163 | $target_blog_id = $starting_blog_id; |
| 164 | break; |
| 165 | case 'network': |
| 166 | $target_blog_id = bp_get_root_blog_id(); |
| 167 | break; |
| 168 | case 'global': |
| 169 | $main_network = wp_get_network( get_main_network_id() ); |
| 170 | $target_blog_id = get_site_by_path( $main_network->domain, $main_network->path ); |
| 171 | break; |
| 172 | } |
| 173 | |
| 174 | if ( $starting_blog_id !== $target_blog_id ) { |
| 175 | switch_to_blog( $target_blog_id ); |
| 176 | bp_register_taxonomies(); |
| 177 | } |
125 | 178 | |
126 | 179 | $retval = wp_remove_object_terms( $object_id, $terms, $taxonomy ); |
127 | 180 | |
128 | | if ( ! $is_root_blog ) { |
129 | | restore_current_blog(); |
130 | | } |
| 181 | if ( $starting_blog_id !== $target_blog_id ) { |
| 182 | restore_current_blog(); |
| 183 | } |
131 | 184 | |
132 | 185 | return $retval; |
133 | 186 | } |