Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/06/2012 04:24:22 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Admin Audit:

  • Introduce bp_is_network_activated() to tell if BuddyPress is active at a network level.
  • Use bp_is_network_activated() in places where multiblog or single-site activation might mistakingly link to the incorrect site/network admin.
  • Add phpdoc to bp_is_multiblog_mode() to further explain why it exists, and why you should not use it.
  • Audit usage of network_admin_url() and admin_url(), and replace with bp_get_admin_url() where appropriate.
  • Escape some admin URL usages; maybe more to do here.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-functions.php

    r6259 r6310  
    911911 * Are we running multiblog mode?
    912912 *
    913  * Note that BP_ENABLE_MULTIBLOG is different from (but dependent on) WP Multisite. "Multiblog" is
    914  * a BP setup that allows BP content to be viewed in the theme, and with the URL, of every blog
    915  * on the network. Thus, instead of having all 'boonebgorges' links go to
     913 * Note that BP_ENABLE_MULTIBLOG is different from (but dependent on) WordPress
     914 * Multisite. "Multiblog" is BuddyPress setup that allows BuddyPress components
     915 * to be viewed on every blog on the network, each with their own settings.
     916 *
     917 * Thus, instead of having all 'boonebgorges' links go to
    916918 *   http://example.com/members/boonebgorges
    917  * on the root blog, each blog will have its own version of the same profile content, eg
     919 * on the root blog, each blog will have its own version of the same content, eg
    918920 *   http://site2.example.com/members/boonebgorges (for subdomains)
    919921 *   http://example.com/site2/members/boonebgorges (for subdirectories)
    920922 *
    921  * Multiblog mode is disabled by default, meaning that all BP content must be viewed on the root
    922  * blog.
     923 * Multiblog mode is disabled by default, meaning that all BuddyPress content
     924 * must be viewed on the root blog. It's also recommended not to use the
     925 * BP_ENABLE_MULTIBLOG constant beyond 1.7, as BuddyPress can now be activated
     926 * on individual sites.
     927 *
     928 * Why would you want to use this? Originally it was intended to allow
     929 * BuddyPress to live in mu-plugins and be visible on mapped domains. This is
     930 * a very small use-case with large architectural shortcomings, so do not go
     931 * down this road unless you specifically need to.
    923932 *
    924933 * @package BuddyPress
     
    929938 */
    930939function bp_is_multiblog_mode() {
    931     return apply_filters( 'bp_is_multiblog_mode', is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG );
     940
     941    // Setup some default values
     942    $retval         = false;
     943    $is_multisite   = is_multisite();
     944    $network_active = bp_is_network_activated();
     945    $is_multiblog   = defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG;
     946
     947    // Multisite, Network Activated, and Specifically Multiblog
     948    if ( $is_multisite && $network_active && $is_multiblog ) {
     949        $retval = true;
     950
     951    // Multisite, but not network activated
     952    } elseif ( $is_multisite && ! $network_active ) {
     953        $retval = true;
     954    }
     955
     956    return apply_filters( 'bp_is_multiblog_mode', $retval );
    932957}
    933958
     
    10771102
    10781103        // Links belong in network admin
    1079         if ( bp_core_do_network_admin() )
     1104        if ( bp_core_do_network_admin() ) {
    10801105            $url = network_admin_url( $path, $scheme );
    10811106
    10821107        // Links belong in site admin
    1083         else
     1108        } else {
    10841109            $url = admin_url( $path, $scheme );
     1110        }
    10851111
    10861112        return $url;
    10871113    }
    10881114
     1115/**
     1116 * Should BuddyPress appear in network admin, or site admin?
     1117 *
     1118 * Because BuddyPress can be installed in multiple ways and with multiple
     1119 * configurations, we need to check a few things to be confident about where
     1120 * to hook into certain areas of WordPress's admin.
     1121 *
     1122 * This function defaults to BuddyPress being network activated.
     1123 * @since BuddyPress (1.5)
     1124 *
     1125 * @uses bp_is_network_activated()
     1126 * @uses bp_is_multiblog_mode()
     1127 * @return boolean
     1128 */
    10891129function bp_core_do_network_admin() {
    1090     $do_network_admin = false;
    1091 
    1092     if ( is_multisite() && !bp_is_multiblog_mode() )
    1093         $do_network_admin = true;
    1094 
    1095     return apply_filters( 'bp_core_do_network_admin', $do_network_admin );
     1130
     1131    // Default
     1132    $retval = bp_is_network_activated();
     1133
     1134    if ( bp_is_multiblog_mode() )
     1135        $retval = false;
     1136
     1137    return (bool) apply_filters( 'bp_core_do_network_admin', $retval );
    10961138}
    10971139
     
    11001142
    11011143    return apply_filters( 'bp_core_admin_hook', $hook );
     1144}
     1145
     1146/**
     1147 * Is BuddyPress active at the network level for this network?
     1148 *
     1149 * Used to determine admin menu placement, and where settings and options are
     1150 * stored. If you're being *really* clever and manually pulling BuddyPress in
     1151 * with an mu-plugin or some other method, you'll want to
     1152 *
     1153 * @since BuddyPress (1.7)
     1154 * @return boolean
     1155 */
     1156function bp_is_network_activated() {
     1157
     1158    // Default to is_multisite()
     1159    $retval  = is_multisite();
     1160
     1161    // Check the sitewide plugins array
     1162    $base    = buddypress()->basename;
     1163    $plugins = get_site_option( 'active_sitewide_plugins' );
     1164
     1165    // Override is_multisite() if not network activated
     1166    if ( ! is_array( $plugins ) || ! isset( $plugins[$base] ) )
     1167        $retval = false;
     1168
     1169    return (bool) apply_filters( 'bp_is_network_activated', $retval );
    11021170}
    11031171
Note: See TracChangeset for help on using the changeset viewer.