Skip to:
Content

BuddyPress.org

Ticket #7077: 7077.2.patch

File 7077.2.patch, 1.5 KB (added by boonebgorges, 9 years ago)
  • src/bp-core/bp-core-taxonomy.php

    diff --git a/src/bp-core/bp-core-taxonomy.php b/src/bp-core/bp-core-taxonomy.php
    index bd544b4..23a88df 100644
    a b function bp_register_default_taxonomies() { 
    4545add_action( 'bp_register_taxonomies', 'bp_register_default_taxonomies' );
    4646
    4747/**
     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 */
     54function 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/**
    4867 * Set taxonomy terms on a BuddyPress object.
    4968 *
    5069 * @since 2.2.0
    add_action( 'bp_register_taxonomies', 'bp_register_default_taxonomies' ); 
    5877 * @return array Array of term taxonomy IDs.
    5978 */
    6079function 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 );
    6281
    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 );
    6585                bp_register_taxonomies();
     86                $switched = true;
    6687        }
    6788
    6889        $retval = wp_set_object_terms( $object_id, $terms, $taxonomy, $append );
    6990
    70         if ( ! $is_root_blog ) {
     91        if ( ! $switched ) {
    7192                restore_current_blog();
    7293        }
    7394