Skip to:
Content

BuddyPress.org

Changeset 6310


Ignore:
Timestamp:
09/06/2012 04:24:22 AM (13 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.
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-akismet.php

    r6259 r6310  
    9898                $b[ $k ] = $item;
    9999                if ( $k == 'edit' )
    100                     $b['history'] = '<a href="' . network_admin_url( 'admin.php?page=bp-activity&amp;action=edit&aid=' . $activity['id'] ) . '#bp_activity_history"> '. __( 'History', 'buddypress' ) . '</a>';
     100                    $b['history'] = '<a href="' . esc_url( bp_get_admin_url( 'admin.php?page=bp-activity&amp;action=edit&aid=' . $activity['id'] ) ) . '#bp_activity_history"> '. __( 'History', 'buddypress' ) . '</a>';
    101101            }
    102102
     
    105105
    106106        if ( $desc )
    107             echo '<span class="akismet-status"><a href="' . network_admin_url( 'admin.php?page=bp-activity&amp;action=edit&aid=' . $activity['id'] ) . '#bp_activity_history">' . htmlspecialchars( $desc ) . '</a></span>';
     107            echo '<span class="akismet-status"><a href="' . esc_url( bp_get_admin_url( 'admin.php?page=bp-activity&amp;action=edit&aid=' . $activity['id'] ) ) . '#bp_activity_history">' . htmlspecialchars( $desc ) . '</a></span>';
    108108
    109109        return apply_filters( 'bp_akismet_comment_row_action', $actions );
  • trunk/bp-core/admin/bp-core-functions.php

    r6286 r6310  
    114114
    115115        <p><?php _e( "Don't worry! We've moved the BuddyPress options into more convenient and easier to find locations. You're seeing this page because you are running a legacy BuddyPress plugin which has not been updated.", 'buddypress' ); ?></p>
    116         <p><?php printf( __( 'Components, Pages, Settings, and Forums, have been moved to <a href="%s">Settings &gt; BuddyPress</a>. Profile Fields has been moved into the <a href="%s">Users</a> menu.', 'buddypress' ), $settings_url, network_admin_url( 'users.php?page=bp-profile-setup' ) ); ?></p>
     116        <p><?php printf( __( 'Components, Pages, Settings, and Forums, have been moved to <a href="%s">Settings &gt; BuddyPress</a>. Profile Fields has been moved into the <a href="%s">Users</a> menu.', 'buddypress' ), esc_url( $settings_url ), bp_get_admin_url( 'users.php?page=bp-profile-setup' ) ); ?></p>
    117117    </div>
    118118
  • trunk/bp-core/admin/bp-core-settings.php

    r6245 r6310  
    248248
    249249    // We're saving our own options, until the WP Settings API is updated to work with Multisite
    250     $form_action = add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
     250    $form_action = add_query_arg( 'page', 'bp-settings', bp_get_admin_url( 'admin.php' ) );
    251251
    252252    ?>
     
    314314        }
    315315
    316         bp_core_redirect( add_query_arg( array( 'page' => 'bp-settings', 'updated' => 'true' ), bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) ) );
     316        bp_core_redirect( add_query_arg( array( 'page' => 'bp-settings', 'updated' => 'true' ), bp_get_admin_url( 'admin.php' ) ) );
    317317    }
    318318}
  • trunk/bp-core/admin/bp-core-slugs.php

    r6084 r6310  
    9595
    9696                        <td>
    97                             <?php if ( !bp_is_root_blog() )
    98                                 switch_to_blog( bp_get_root_blog_id() ) ?>
     97
     98                            <?php if ( ! bp_is_root_blog() ) switch_to_blog( bp_get_root_blog_id() ); ?>
    9999
    100100                            <?php echo wp_dropdown_pages( array(
     
    114114                            <?php endif; ?>
    115115
    116                             <?php if ( !bp_is_root_blog() )
    117                                 restore_current_blog() ?>
     116                            <?php if ( ! bp_is_root_blog() ) restore_current_blog(); ?>
    118117
    119118                        </td>
     
    159158
    160159                        <td>
     160                           
     161                            <?php if ( ! bp_is_root_blog() ) switch_to_blog( bp_get_root_blog_id() ); ?>
     162
    161163                            <?php echo wp_dropdown_pages( array(
    162164                                'name'             => 'bp_pages[' . esc_attr( $name ) . ']',
     
    174176
    175177                            <?php endif; ?>
     178
     179                            <?php if ( ! bp_is_root_blog() ) restore_current_blog(); ?>
    176180
    177181                        </td>
  • trunk/bp-core/bp-core-admin.php

    r6285 r6310  
    368368     */
    369369    public function add_settings_link( $links, $file ) {
    370         global $bp;
    371 
    372         if ( plugin_basename( $bp->file ) == $file ) {
     370
     371        if ( buddypress()->basename == $file ) {
    373372            $url           = bp_core_do_network_admin() ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' );
    374373            $settings_link = '<a href="' . add_query_arg( array( 'page' => 'bp-components' ), $url ) . '">' . __( 'Settings', 'buddypress' ) . '</a>';
  • trunk/bp-core/bp-core-classes.php

    r6259 r6310  
    877877 */
    878878class BP_Button {
    879     // Button properties
     879
     880    /** Button properties *****************************************************/
    880881
    881882    /**
     
    884885     * @var integer
    885886     */
    886     var $id;
     887    private $id = '';
    887888
    888889    /**
     
    891892     * @var string
    892893     */
    893     var $component;
     894    private $component = 'core';
    894895
    895896    /**
     
    898899     * @var boolean
    899900     */
    900     var $must_be_logged_in;
    901 
    902     /**
    903      * True or false if the button should not be displayed while viewing your own profile.
     901    private $must_be_logged_in = true;
     902
     903    /**
     904     * True or false if the button should not be displayed while viewing your
     905     * own profile.
    904906     *
    905907     * @var boolean
    906908     */
    907     var $block_self;
    908 
    909 
    910     // Wrapper
     909    private $block_self = true;
     910
     911    /** Wrapper ***************************************************************/
    911912
    912913    /**
     
    916917     * @var mixed div|span|p|li, or false for no wrapper
    917918     */
    918     var $wrapper;
     919    private $wrapper = 'div';
    919920
    920921    /**
     
    923924     * @var string
    924925     */
    925     var $wrapper_class;
     926    private $wrapper_class = '';
    926927
    927928    /**
     
    930931     * @var string
    931932     */
    932     var $wrapper_id;
    933 
    934 
    935     // Button
     933    private $wrapper_id = '';
     934
     935    /** Button ****************************************************************/
    936936
    937937    /**
     
    940940     * @var string
    941941     */
    942     var $link_href;
     942    private $link_href = '';
    943943
    944944    /**
     
    947947     * @var string
    948948     */
    949     var $link_class;
     949    private $link_class = '';
    950950
    951951    /**
     
    954954     * @var string
    955955     */
    956     var $link_id;
     956    private $link_id = '';
    957957
    958958    /**
     
    961961     * @var string
    962962     */
    963     var $link_rel;
     963    private $link_rel = '';
    964964
    965965    /**
     
    968968     * @var string
    969969     */
    970     var $link_title;
     970    private $link_title = '';
    971971
    972972    /**
     
    975975     * @var string
    976976     */
    977     var $link_text;
    978 
    979 
    980     // HTML result
    981 
    982     var $contents;
    983 
    984     /**
    985      * bp_button()
    986      *
     977    private $link_text = '';
     978
     979    /** HTML result ***********************************************************/
     980
     981    public $contents = '';
     982
     983    /**
    987984     * Builds the button based on passed parameters:
    988985     *
     
    10031000     * @return bool False if not allowed
    10041001     */
    1005     function __construct( $args = '' ) {
    1006 
    1007         // Default arguments
    1008         $defaults = array(
    1009             'id'                => '',
    1010             'component'         => 'core',
    1011             'must_be_logged_in' => true,
    1012             'block_self'        => true,
    1013 
    1014             'wrapper'           => 'div',
    1015             'wrapper_id'        => '',
    1016             'wrapper_class'     => '',
    1017 
    1018             'link_href'         => '',
    1019             'link_title'        => '',
    1020             'link_id'           => '',
    1021             'link_class'        => '',
    1022             'link_rel'          => '',
    1023             'link_text'         => '',
    1024         );
    1025 
    1026         $r = wp_parse_args( $args, $defaults );
     1002    public function __construct( $args = '' ) {
     1003
     1004        $r = wp_parse_args( $args, get_class_vars( __CLASS__ ) );
    10271005        extract( $r, EXTR_SKIP );
    10281006
     
    11011079
    11021080    /**
    1103      * contents()
    1104      *
    11051081     * Return contents of button
    11061082     *
    11071083     * @return string
    11081084     */
    1109     function contents() {
     1085    public function contents() {
    11101086        return $this->contents;
    11111087    }
    11121088
    11131089    /**
    1114      * display()
    1115      *
    11161090     * Output contents of button
    11171091     */
    1118     function display() {
     1092    public function display() {
    11191093        if ( !empty( $this->contents ) )
    11201094            echo $this->contents;
  • trunk/bp-core/bp-core-cssjs.php

    r6259 r6310  
    105105 */
    106106function bp_core_add_cropper_inline_css() {
    107     global $bp;
    108107?>
    109108
    110109    <style type="text/css">
    111110        .jcrop-holder { float: left; margin: 0 20px 20px 0; text-align: left; }
    112         .jcrop-vline, .jcrop-hline { font-size: 0; position: absolute; background: white top left repeat url( <?php echo BP_PLUGIN_URL ?>/bp-core/images/Jcrop.gif ); }
     111        .jcrop-vline, .jcrop-hline { font-size: 0; position: absolute; background: white top left repeat url('<?php echo BP_PLUGIN_URL ?>/bp-core/images/Jcrop.gif'); }
    113112        .jcrop-vline { height: 100%; width: 1px !important; }
    114113        .jcrop-hline { width: 100%; height: 1px !important; }
  • 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
  • trunk/bp-forums/bp-forums-admin.php

    r6195 r6310  
    44
    55function bp_forums_add_admin_menu() {
    6     global $bp;
    76
    87    if ( !is_super_admin() )
     
    2322 */
    2423function bp_forums_bbpress_admin() {
    25     global $bp;
    2624
    2725    // The text and URL of the Site Wide Forums button differs depending on whether bbPress
     
    110108
    111109function bp_forums_bbpress_install_wizard() {
    112     $post_url                 = network_admin_url( 'admin.php?page=bb-forums-setup' );
     110    $post_url                 = bp_get_admin_url( 'admin.php?page=bb-forums-setup' );
    113111    $bbpress_plugin_is_active = false;
    114112
  • trunk/bp-forums/deprecated/1.6.php

    r6110 r6310  
    8585
    8686function bp_forums_bbpress_install_wizard() {
    87     $post_url = network_admin_url( 'admin.php?page=bb-forums-setup' );
     87    $post_url = bp_get_admin_url( 'admin.php?page=bb-forums-setup' );
    8888
    8989    $step = isset( $_REQUEST['step'] ) ? $_REQUEST['step'] : '';
Note: See TracChangeset for help on using the changeset viewer.