Skip to:
Content

BuddyPress.org

Ticket #6892: 6892.03.patch

File 6892.03.patch, 3.9 KB (added by imath, 10 years ago)
  • src/bp-core/admin/bp-core-admin-schema.php

    diff --git src/bp-core/admin/bp-core-admin-schema.php src/bp-core/admin/bp-core-admin-schema.php
    index 87ec012..28af0e2 100644
    function bp_core_install_emails() { 
    688688                'groups-membership-request-rejected' => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ),
    689689        );
    690690
     691        /**
     692         * Emails are inserted on the root blog
     693         */
     694        bp_switch_to_root_blog();
     695
    691696        // Add these emails to the database.
    692697        foreach ( $emails as $id => $email ) {
    693698                $post_id = wp_insert_post( bp_parse_args( $email, $defaults, 'install_email_' . $id ) );
    function bp_core_install_emails() { 
    704709        }
    705710
    706711        /**
     712         * Restore current blog if needed
     713         */
     714        bp_restore_current_blog();
     715
     716        /**
    707717         * Fires after BuddyPress adds the posts for its emails.
    708718         *
    709719         * @since 2.5.0
  • src/bp-core/bp-core-functions.php

    diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php
    index dc93da4..0bd2a3b 100644
    function bp_is_network_activated() { 
    19231923        return (bool) apply_filters( 'bp_is_network_activated', $retval );
    19241924}
    19251925
     1926/**
     1927 * Switch to root blog if necessary
     1928 *
     1929 * @since 2.5.0
     1930 */
     1931function bp_switch_to_root_blog() {
     1932        if ( ! is_multisite() || (int) get_current_blog_id() === (int) bp_get_root_blog_id() ) {
     1933                return;
     1934        }
     1935
     1936        switch_to_blog( bp_get_root_blog_id() );
     1937
     1938        // Make sure BuddyPress post types are registered
     1939        if ( ! post_type_exists( bp_get_email_post_type() ) ) {
     1940                bp_register_post_types();
     1941        }
     1942
     1943        // Make sure BuddyPress taxonomies are registered
     1944        if ( ! taxonomy_exists( bp_get_email_tax_type() ) ) {
     1945                bp_register_taxonomies();
     1946        }
     1947
     1948        buddypress()->core->blog_is_switched = true;
     1949}
     1950
     1951/**
     1952 * Reset current blog if necessary
     1953 *
     1954 * @since 2.5.0
     1955 */
     1956function bp_restore_current_blog() {
     1957        $bp = buddypress();
     1958
     1959        if ( isset( $bp->core->blog_is_switched ) && true === $bp->core->blog_is_switched ) {
     1960                restore_current_blog();
     1961
     1962                $bp->core->blog_is_switched = false;
     1963        }
     1964}
     1965
    19261966/** Global Manipulators *******************************************************/
    19271967
    19281968/**
  • src/bp-core/bp-core-taxonomy.php

    diff --git src/bp-core/bp-core-taxonomy.php src/bp-core/bp-core-taxonomy.php
    index dedf1ce..6ee4803 100644
    add_action( 'bp_register_taxonomies', 'bp_register_default_taxonomies' ); 
    6060 * @return array Array of term taxonomy IDs.
    6161 */
    6262function bp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) {
    63         $is_root_blog = bp_is_root_blog();
    64 
    65         if ( ! $is_root_blog ) {
    66                 switch_to_blog( bp_get_root_blog_id() );
    67         }
     63        bp_switch_to_root_blog();
    6864
    6965        $retval = wp_set_object_terms( $object_id, $terms, $taxonomy, $append );
    7066
    71         if ( ! $is_root_blog ) {
    72                 restore_current_blog();
    73         }
     67        bp_restore_current_blog();
    7468
    7569        return $retval;
    7670}
    function bp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { 
    8882 * @return array
    8983 */
    9084function bp_get_object_terms( $object_ids, $taxonomies, $args = array() ) {
    91         $is_root_blog = bp_is_root_blog();
    92 
    93         if ( ! $is_root_blog ) {
    94                 switch_to_blog( bp_get_root_blog_id() );
    95         }
     85        bp_switch_to_root_blog();
    9686
    9787        $retval = wp_get_object_terms( $object_ids, $taxonomies, $args );
    9888
    99         if ( ! $is_root_blog ) {
    100                 restore_current_blog();
    101         }
     89        bp_restore_current_blog();
    10290
    10391        return $retval;
    10492}
    function bp_get_object_terms( $object_ids, $taxonomies, $args = array() ) { 
    116104 * @return bool|WP_Error True on success, false or WP_Error on failure.
    117105 */
    118106function 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         }
     107        bp_switch_to_root_blog();
    124108
    125109        $retval = wp_remove_object_terms( $object_id, $terms, $taxonomy );
    126110
    127         if ( ! $is_root_blog ) {
    128                 restore_current_blog();
    129         }
     111        bp_restore_current_blog();
    130112
    131113        return $retval;
    132114}