Skip to:
Content

bbPress.org

Changeset 6734


Ignore:
Timestamp:
11/16/2017 11:08:24 PM (4 years ago)
Author:
johnjamesjacoby
Message:

Abstraction: abstract site switching functions to include an is_mulitsite() check.

This allows functions that are traditionally hook-only to be called directly, regardless of the installation type, and without littering the codebase with several is_multisite() switches.

Fixes #3179.

Location:
trunk/src/includes
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/actions.php

    r6730 r6734  
    143143    }
    144144
    145     // Switch to the new blog
    146     switch_to_blog( $blog_id );
     145    // Switch to the new site
     146    bbp_switch_to_site( $blog_id );
    147147
    148148    // Do the bbPress activation routine
    149149    do_action( 'bbp_new_site', $blog_id, $user_id, $domain, $path, $site_id, $meta );
    150150
    151     // restore original blog
    152     restore_current_blog();
     151    // Restore original site
     152    bbp_restore_current_site();
    153153}
    154154
  • trunk/src/includes/admin/classes/class-bbp-admin.php

    r6705 r6734  
    11361136                            }
    11371137
    1138                             // Switch to the new blog
    1139                             switch_to_blog( $details[ 'blog_id' ] );
     1138                            // Switch to the new site
     1139                            bbp_switch_to_site( $details[ 'blog_id' ] );
    11401140
    11411141                            $basename = bbpress()->basename;
     
    11461146                            }
    11471147
    1148                             // restore original blog
    1149                             restore_current_blog();
     1148                            // Restore original site
     1149                            bbp_restore_current_site();
    11501150
    11511151                            // Do some actions to allow plugins to do things too
  • trunk/src/includes/admin/common.php

    r6730 r6734  
    156156    }
    157157
    158     switch_to_blog( $site_id );
     158    bbp_switch_to_site( $site_id );
    159159    bbp_delete_options();
    160160    bbp_remove_roles();
    161161    bbp_remove_caps();
    162162    flush_rewrite_rules();
    163     restore_current_blog();
     163    bbp_restore_current_site();
    164164}
    165165
  • trunk/src/includes/core/abstraction.php

    r6723 r6734  
    335335}
    336336
     337/**
     338 * Switch to a site in a multisite installation.
     339 *
     340 * If not a multisite installation, no switching will occur.
     341 *
     342 * @since 2.6.0 bbPress (r6733)
     343 *
     344 * @param int $site_id
     345 */
     346function bbp_switch_to_site( $site_id = 0 ) {
     347
     348    // Switch to a specific site
     349    if ( is_multisite() ) {
     350        switch_to_blog( $site_id );
     351    }
     352}
     353
     354/**
     355 * Switch back to the original site in a multisite installation.
     356 *
     357 * If not a multisite installation, no switching will occur.
     358 *
     359 * @since 2.6.0 bbPress (r6733)
     360 */
     361function bbp_restore_current_site( ) {
     362
     363    // Switch back to the original site
     364    if ( is_multisite() ) {
     365        restore_current_blog();
     366    }
     367}
     368
    337369/** Engagements ***************************************************************/
    338370
  • trunk/src/includes/core/capabilities.php

    r6573 r6734  
    326326 * bbPress does not have an intercept point to add its dynamic roles.
    327327 *
    328  * @see switch_to_blog()
    329  * @see restore_current_blog()
     328 * @see bbp_switch_to_site()
     329 * @see bbp_restore_current_site()
    330330 * @see WP_Roles::_init()
    331331 *
  • trunk/src/includes/users/capabilities.php

    r6708 r6734  
    492492    foreach ( (array) array_keys( $blogs ) as $blog_id ) {
    493493
    494         // Switch to the blog ID
    495         switch_to_blog( $blog_id );
     494        // Switch to the site ID
     495        bbp_switch_to_site( $blog_id );
    496496
    497497        // Get topics and replies
     
    518518        }
    519519
    520         // Switch back to current blog
    521         restore_current_blog();
     520        // Switch back to current site
     521        bbp_restore_current_site();
    522522    }
    523523
     
    570570    foreach ( (array) array_keys( $blogs ) as $blog_id ) {
    571571
    572         // Switch to the blog ID
    573         switch_to_blog( $blog_id );
     572        // Switch to the site ID
     573        bbp_switch_to_site( $blog_id );
    574574
    575575        // Get topics and replies
     
    596596        }
    597597
    598         // Switch back to current blog
    599         restore_current_blog();
     598        // Switch back to current site
     599        bbp_restore_current_site();
    600600    }
    601601
Note: See TracChangeset for help on using the changeset viewer.