示例#1
0
/**
 * Get a root option.
 *
 * "Root options" are those that apply across an entire installation, and are fetched only a single
 * time during a pageload and stored in `buddypress()->site_options` to prevent future lookups.
 * See {@see bp_core_get_root_options()}.
 *
 * @since BuddyPress (2.3.0)
 *
 * @param  string $option Name of the option key.
 * @return mixed Value, if found.
 */
function bp_core_get_root_option($option)
{
    $bp = buddypress();
    if (!isset($bp->site_options)) {
        $bp->site_options = bp_core_get_root_options();
    }
    $value = '';
    if (isset($bp->site_options[$option])) {
        $value = $bp->site_options[$option];
    }
    return $value;
}
 /**
  * Set up bp-core global settings.
  *
  * Sets up a majority of the BuddyPress globals that require a minimal
  * amount of processing, meaning they cannot be set in the BuddyPress class.
  *
  * @since BuddyPress (1.5.0)
  *
  * @see BP_Component::setup_globals() for description of parameters.
  *
  * @param array $args See {@link BP_Component::setup_globals()}.
  */
 public function setup_globals($args = array())
 {
     $bp = buddypress();
     /** Database **********************************************************/
     // Get the base database prefix
     if (empty($bp->table_prefix)) {
         $bp->table_prefix = bp_core_get_table_prefix();
     }
     // The domain for the root of the site where the main blog resides
     if (empty($bp->root_domain)) {
         $bp->root_domain = bp_core_get_root_domain();
     }
     // Fetches all of the core BuddyPress settings in one fell swoop
     if (empty($bp->site_options)) {
         $bp->site_options = bp_core_get_root_options();
     }
     // The names of the core WordPress pages used to display BuddyPress content
     if (empty($bp->pages)) {
         $bp->pages = bp_core_get_directory_pages();
     }
     /** Basic current user data *******************************************/
     // Logged in user is the 'current_user'
     $current_user = wp_get_current_user();
     // The user ID of the user who is currently logged in.
     $bp->loggedin_user = new stdClass();
     $bp->loggedin_user->id = isset($current_user->ID) ? $current_user->ID : 0;
     /** Avatars ***********************************************************/
     // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar
     $bp->grav_default = new stdClass();
     $bp->grav_default->user = apply_filters('bp_user_gravatar_default', $bp->site_options['avatar_default']);
     $bp->grav_default->group = apply_filters('bp_group_gravatar_default', $bp->grav_default->user);
     $bp->grav_default->blog = apply_filters('bp_blog_gravatar_default', $bp->grav_default->user);
     // Notifications table. Included here for legacy purposes. Use
     // bp-notifications instead.
     $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
     /**
      * Used to determine if user has admin rights on current content. If the
      * logged in user is viewing their own profile and wants to delete
      * something, is_item_admin is used. This is a generic variable so it
      * can be used by other components. It can also be modified, so when
      * viewing a group 'is_item_admin' would be 'true' if they are a group
      * admin, and 'false' if they are not.
      */
     bp_update_is_item_admin(bp_user_has_access(), 'core');
     // Is the logged in user is a mod for the current item?
     bp_update_is_item_mod(false, 'core');
     do_action('bp_core_setup_globals');
 }
示例#3
0
 /**
  * @group bp_core_get_root_option
  */
 public function test_bp_core_get_root_option_with_populated_cache()
 {
     // Back up and unset global cache.
     $old_options = buddypress()->site_options;
     buddypress()->site_options = bp_core_get_root_options();
     $expected = buddypress()->site_options['avatar_default'];
     $this->assertSame($expected, bp_core_get_root_option('avatar_default'));
 }
/**
 * Is user signup allowed?
 *
 * @return bool
 */
function bp_get_signup_allowed()
{
    $bp = buddypress();
    $signup_allowed = false;
    if (is_multisite()) {
        if (!isset($bp->site_options)) {
            $bp->site_options = bp_core_get_root_options();
        }
        if (in_array($bp->site_options['registration'], array('all', 'user'))) {
            $signup_allowed = true;
        }
    } else {
        if (bp_get_option('users_can_register')) {
            $signup_allowed = true;
        }
    }
    /**
     * Filters whether or not new signups are allowed.
     *
     * @since BuddyPress (1.5.0)
     *
     * @param bool $signup_allowed Whether or not new signups are allowed.
     */
    return apply_filters('bp_get_signup_allowed', $signup_allowed);
}
 function setup_globals()
 {
     global $bp;
     /** Database **********************************************************/
     // Get the base database prefix
     if (empty($bp->table_prefix)) {
         $bp->table_prefix = bp_core_get_table_prefix();
     }
     // The domain for the root of the site where the main blog resides
     if (empty($bp->root_domain)) {
         $bp->root_domain = bp_core_get_root_domain();
     }
     // Fetches all of the core BuddyPress settings in one fell swoop
     if (empty($bp->site_options)) {
         $bp->site_options = bp_core_get_root_options();
     }
     // The names of the core NXTClass pages used to display BuddyPress content
     if (empty($bp->pages)) {
         $bp->pages = bp_core_get_directory_pages();
     }
     /** Admin Bar *********************************************************/
     // Set the 'My Account' global to prevent debug notices
     $bp->my_account_menu_id = false;
     /** Component and Action **********************************************/
     // Used for overriding the 2nd level navigation menu so it can be used to
     // display custom navigation for an item (for example a group)
     $bp->is_single_item = false;
     // Sets up the array container for the component navigation rendered
     // by bp_get_nav()
     $bp->bp_nav = array();
     // Sets up the array container for the component options navigation
     // rendered by bp_get_options_nav()
     $bp->bp_options_nav = array();
     // Contains an array of all the active components. The key is the slug,
     // value the internal ID of the component.
     //$bp->active_components = array();
     /** Basic current user data *******************************************/
     // Logged in user is the 'current_user'
     $current_user = nxt_get_current_user();
     // The user ID of the user who is currently logged in.
     $bp->loggedin_user->id = $current_user->ID;
     /** Avatars ***********************************************************/
     // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar
     $bp->grav_default->user = apply_filters('bp_user_gravatar_default', $bp->site_options['avatar_default']);
     $bp->grav_default->group = apply_filters('bp_group_gravatar_default', $bp->grav_default->user);
     $bp->grav_default->blog = apply_filters('bp_blog_gravatar_default', $bp->grav_default->user);
     // Notifications Table
     $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
     /**
      * Used to determine if user has admin rights on current content. If the
      * logged in user is viewing their own profile and wants to delete
      * something, is_item_admin is used. This is a generic variable so it
      * can be used by other components. It can also be modified, so when
      * viewing a group 'is_item_admin' would be 'true' if they are a group
      * admin, and 'false' if they are not.
      */
     bp_update_is_item_admin(bp_user_has_access(), 'core');
     // Is the logged in user is a mod for the current item?
     bp_update_is_item_mod(false, 'core');
     do_action('bp_core_setup_globals');
 }