/** * Set up bp-members global settings. * * The BP_MEMBERS_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since 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()) { global $wpdb; $bp = buddypress(); /** Component Globals ************************************************ */ // Define a slug, as a fallback for backpat. if (!defined('BP_MEMBERS_SLUG')) { define('BP_MEMBERS_SLUG', $this->id); } // Fetch the default directory title. $default_directory_titles = bp_core_get_directory_page_default_titles(); $default_directory_title = $default_directory_titles[$this->id]; // Override any passed args. $args = array('slug' => BP_MEMBERS_SLUG, 'root_slug' => isset($bp->pages->members->slug) ? $bp->pages->members->slug : BP_MEMBERS_SLUG, 'has_directory' => true, 'directory_title' => isset($bp->pages->members->title) ? $bp->pages->members->title : $default_directory_title, 'search_string' => __('Search Members...', 'buddypress'), 'global_tables' => array('table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity', 'table_name_signups' => $wpdb->base_prefix . 'signups')); parent::setup_globals($args); /** Logged in user *************************************************** */ // The core userdata of the user who is currently logged in. $bp->loggedin_user->userdata = bp_core_get_core_userdata(bp_loggedin_user_id()); // Fetch the full name for the logged in user. $bp->loggedin_user->fullname = isset($bp->loggedin_user->userdata->display_name) ? $bp->loggedin_user->userdata->display_name : ''; // Hits the DB on single WP installs so get this separately. $bp->loggedin_user->is_super_admin = $bp->loggedin_user->is_site_admin = is_super_admin(bp_loggedin_user_id()); // The domain for the user currently logged in. eg: http://example.com/members/andy. $bp->loggedin_user->domain = bp_core_get_user_domain(bp_loggedin_user_id()); /** Displayed user *************************************************** */ // The core userdata of the user who is currently being displayed. $bp->displayed_user->userdata = bp_core_get_core_userdata(bp_displayed_user_id()); // Fetch the full name displayed user. $bp->displayed_user->fullname = isset($bp->displayed_user->userdata->display_name) ? $bp->displayed_user->userdata->display_name : ''; // The domain for the user currently being displayed. $bp->displayed_user->domain = bp_core_get_user_domain(bp_displayed_user_id()); // Initialize the nav for the members component. $this->nav = new BP_Core_Nav(); // If A user is displayed, check if there is a front template if (bp_get_displayed_user()) { $bp->displayed_user->front_template = bp_displayed_user_get_front_template(); } /** Signup *********************************************************** */ $bp->signup = new stdClass(); /** Profiles Fallback ************************************************ */ if (!bp_is_active('xprofile')) { $bp->profile = new stdClass(); $bp->profile->slug = 'profile'; $bp->profile->id = 'profile'; } }
/** * Set up global settings for the blogs component. * * The BP_BLOGS_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since 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(); if (!defined('BP_BLOGS_SLUG')) { define('BP_BLOGS_SLUG', $this->id); } // Global tables for messaging component. $global_tables = array('table_name' => $bp->table_prefix . 'bp_user_blogs', 'table_name_blogmeta' => $bp->table_prefix . 'bp_user_blogs_blogmeta'); $meta_tables = array('blog' => $bp->table_prefix . 'bp_user_blogs_blogmeta'); // Fetch the default directory title. $default_directory_titles = bp_core_get_directory_page_default_titles(); $default_directory_title = $default_directory_titles[$this->id]; // All globals for blogs component. $args = array('slug' => BP_BLOGS_SLUG, 'root_slug' => isset($bp->pages->blogs->slug) ? $bp->pages->blogs->slug : BP_BLOGS_SLUG, 'has_directory' => is_multisite(), 'directory_title' => isset($bp->pages->blogs->title) ? $bp->pages->blogs->title : $default_directory_title, 'notification_callback' => 'bp_blogs_format_notifications', 'search_string' => __('Search sites...', 'buddypress'), 'autocomplete_all' => defined('BP_MESSAGES_AUTOCOMPLETE_ALL'), 'global_tables' => $global_tables, 'meta_tables' => $meta_tables); // Setup the globals. parent::setup_globals($args); /** * Filters if a blog is public. * * In case the config is not multisite, the blog_public option is ignored. * * @since 2.3.0 * * @param int $value Whether or not the blog is public. */ if (0 !== apply_filters('bp_is_blog_public', (int) get_option('blog_public')) || !is_multisite()) { /** * Filters the post types to track for the Blogs component. * * @since 1.5.0 * @deprecated 2.3.0 * * @param array $value Array of post types to track. */ $post_types = apply_filters('bp_blogs_record_post_post_types', array('post')); foreach ($post_types as $post_type) { add_post_type_support($post_type, 'buddypress-activity'); } } }
/** * Set up component global data. * * The BP_GROUPS_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since 1.5.0 * * @see BP_Component::setup_globals() for a description of arguments. * * @param array $args See BP_Component::setup_globals() for a description. */ public function setup_globals($args = array()) { $bp = buddypress(); // Define a slug, if necessary. if (!defined('BP_GROUPS_SLUG')) { define('BP_GROUPS_SLUG', $this->id); } // Global tables for groups component. $global_tables = array('table_name' => $bp->table_prefix . 'bp_groups', 'table_name_members' => $bp->table_prefix . 'bp_groups_members', 'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta'); // Metadata tables for groups component. $meta_tables = array('group' => $bp->table_prefix . 'bp_groups_groupmeta'); // Fetch the default directory title. $default_directory_titles = bp_core_get_directory_page_default_titles(); $default_directory_title = $default_directory_titles[$this->id]; // All globals for groups component. // Note that global_tables is included in this array. $args = array('slug' => BP_GROUPS_SLUG, 'root_slug' => isset($bp->pages->groups->slug) ? $bp->pages->groups->slug : BP_GROUPS_SLUG, 'has_directory' => true, 'directory_title' => isset($bp->pages->groups->title) ? $bp->pages->groups->title : $default_directory_title, 'notification_callback' => 'groups_format_notifications', 'search_string' => _x('Search Groups...', 'Component directory search', 'buddypress'), 'global_tables' => $global_tables, 'meta_tables' => $meta_tables); parent::setup_globals($args); /* Single Group Globals **********************************************/ // Are we viewing a single group? if (bp_is_groups_component() && ($group_id = BP_Groups_Group::group_exists(bp_current_action()))) { $bp->is_single_item = true; /** * Filters the current PHP Class being used. * * @since 1.5.0 * * @param string $value Name of the class being used. */ $current_group_class = apply_filters('bp_groups_current_group_class', 'BP_Groups_Group'); if ($current_group_class == 'BP_Groups_Group') { $this->current_group = groups_get_group($group_id); } else { /** * Filters the current group object being instantiated from previous filter. * * @since 1.5.0 * * @param object $value Newly instantiated object for the group. */ $this->current_group = apply_filters('bp_groups_current_group_object', new $current_group_class($group_id)); } // When in a single group, the first action is bumped down one because of the // group name, so we need to adjust this and set the group name to current_item. $bp->current_item = bp_current_action(); $bp->current_action = bp_action_variable(0); array_shift($bp->action_variables); // Using "item" not "group" for generic support in other components. if (bp_current_user_can('bp_moderate')) { bp_update_is_item_admin(true, 'groups'); } else { bp_update_is_item_admin(groups_is_user_admin(bp_loggedin_user_id(), $this->current_group->id), 'groups'); } // If the user is not an admin, check if they are a moderator. if (!bp_is_item_admin()) { bp_update_is_item_mod(groups_is_user_mod(bp_loggedin_user_id(), $this->current_group->id), 'groups'); } // Is the logged in user a member of the group? if (is_user_logged_in() && groups_is_user_member(bp_loggedin_user_id(), $this->current_group->id)) { $this->current_group->is_user_member = true; } else { $this->current_group->is_user_member = false; } // Should this group be visible to the logged in user? if ('public' == $this->current_group->status || $this->current_group->is_user_member) { $this->current_group->is_visible = true; } else { $this->current_group->is_visible = false; } // Check once if the current group has a custom front template. $this->current_group->front_template = bp_groups_get_front_template($this->current_group); // Initialize the nav for the groups component. $this->nav = new BP_Core_Nav($this->current_group->id); // Set current_group to 0 to prevent debug errors. } else { $this->current_group = 0; } /** * Filters the list of illegal groups names/slugs. * * @since 1.0.0 * * @param array $value Array of illegal group names/slugs. */ $this->forbidden_names = apply_filters('groups_forbidden_names', array('my-groups', 'create', 'invites', 'send-invites', 'forum', 'delete', 'add', 'admin', 'request-membership', 'members', 'settings', 'avatar', $this->slug, $this->root_slug)); // If the user was attempting to access a group, but no group by that name was found, 404. if (bp_is_groups_component() && empty($this->current_group) && bp_current_action() && !in_array(bp_current_action(), $this->forbidden_names)) { bp_do_404(); return; } /** * Filters the preconfigured groups creation steps. * * @since 1.1.0 * * @param array $value Array of preconfigured group creation steps. */ $this->group_creation_steps = apply_filters('groups_create_group_steps', array('group-details' => array('name' => _x('Details', 'Group screen nav', 'buddypress'), 'position' => 0), 'group-settings' => array('name' => _x('Settings', 'Group screen nav', 'buddypress'), 'position' => 10))); // If avatar uploads are not disabled, add avatar option. $disabled_avatar_uploads = (int) bp_disable_group_avatar_uploads(); if (!$disabled_avatar_uploads && $bp->avatar->show_avatars) { $this->group_creation_steps['group-avatar'] = array('name' => _x('Photo', 'Group screen nav', 'buddypress'), 'position' => 20); } if (bp_group_use_cover_image_header()) { $this->group_creation_steps['group-cover-image'] = array('name' => _x('Cover Image', 'Group screen nav', 'buddypress'), 'position' => 25); } // If friends component is active, add invitations. if (bp_is_active('friends')) { $this->group_creation_steps['group-invites'] = array('name' => _x('Invites', 'Group screen nav', 'buddypress'), 'position' => 30); } /** * Filters the list of valid groups statuses. * * @since 1.1.0 * * @param array $value Array of valid group statuses. */ $this->valid_status = apply_filters('groups_valid_status', array('public', 'private', 'hidden')); // Auto join group when non group member performs group activity. $this->auto_join = defined('BP_DISABLE_AUTO_GROUP_JOIN') && BP_DISABLE_AUTO_GROUP_JOIN ? false : true; }
/** * Update WP pages so that their post_title matches the legacy component directory title. * * As of 2.7.0, component directory titles come from the `post_title` attribute of the corresponding WP post object, * instead of being hardcoded. To ensure that directory titles don't change for existing installations, we update these * WP posts with the formerly hardcoded titles. * * @since 2.7.0 */ function bp_migrate_directory_page_titles() { $bp_pages = bp_core_get_directory_page_ids('all'); $default_titles = bp_core_get_directory_page_default_titles(); $legacy_titles = array('activity' => _x('Site-Wide Activity', 'component directory title', 'buddypress'), 'blogs' => _x('Sites', 'component directory title', 'buddypress'), 'groups' => _x('Groups', 'component directory title', 'buddypress'), 'members' => _x('Members', 'component directory title', 'buddypress')); foreach ($bp_pages as $component => $page_id) { if (!isset($legacy_titles[$component])) { continue; } $page = get_post($page_id); if (!$page) { continue; } // If the admin has changed the default title, don't touch it. if (isset($default_titles[$component]) && $default_titles[$component] !== $page->post_title) { continue; } // If the saved page title is the same as the legacy title, there's nothing to do. if ($legacy_titles[$component] == $page->post_title) { continue; } // Update the page with the legacy title. wp_update_post(array('ID' => $page_id, 'post_title' => $legacy_titles[$component])); } }
/** * Creates necessary directory pages. * * Directory pages are those WordPress pages used by BP components to display * content (eg, the 'groups' page created by BP). * * @since 1.7.0 * * @param array $components Components to create pages for. * @param string $existing 'delete' if you want to delete existing page mappings * and replace with new ones. Otherwise existing page mappings * are kept, and the gaps filled in with new pages. Default: 'keep'. */ function bp_core_add_page_mappings($components, $existing = 'keep') { // If no value is passed, there's nothing to do. if (empty($components)) { return; } // Make sure that the pages are created on the root blog no matter which // dashboard the setup is being run on. if (!bp_is_root_blog()) { switch_to_blog(bp_get_root_blog_id()); } $pages = bp_core_get_directory_page_ids('all'); // Delete any existing pages. if ('delete' === $existing) { foreach ((array) $pages as $page_id) { wp_delete_post($page_id, true); } $pages = array(); } $page_titles = bp_core_get_directory_page_default_titles(); $pages_to_create = array(); foreach (array_keys($components) as $component_name) { if (!isset($pages[$component_name]) && isset($page_titles[$component_name])) { $pages_to_create[$component_name] = $page_titles[$component_name]; } } // Register and Activate are not components, but need pages when // registration is enabled. if (bp_get_signup_allowed()) { foreach (array('register', 'activate') as $slug) { if (!isset($pages[$slug])) { $pages_to_create[$slug] = $page_titles[$slug]; } } } // No need for a Sites directory unless we're on multisite. if (!is_multisite() && isset($pages_to_create['blogs'])) { unset($pages_to_create['blogs']); } // Members must always have a page, no matter what. if (!isset($pages['members']) && !isset($pages_to_create['members'])) { $pages_to_create['members'] = $page_titles['members']; } // Create the pages. foreach ($pages_to_create as $component_name => $page_name) { $exists = get_page_by_path($component_name); // If page already exists, use it. if (!empty($exists)) { $pages[$component_name] = $exists->ID; } else { $pages[$component_name] = wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_status' => 'publish', 'post_title' => $page_name, 'post_type' => 'page')); } } // Save the page mapping. bp_update_option('bp-pages', $pages); // If we had to switch_to_blog, go back to the original site. if (!bp_is_root_blog()) { restore_current_blog(); } }
/** * Set up component global variables. * * The BP_ACTIVITY_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since 1.5.0 * * @see BP_Component::setup_globals() for a description of arguments. * * @param array $args See BP_Component::setup_globals() for a description. */ public function setup_globals($args = array()) { $bp = buddypress(); // Define a slug, if necessary. if (!defined('BP_ACTIVITY_SLUG')) { define('BP_ACTIVITY_SLUG', $this->id); } // Global tables for activity component. $global_tables = array('table_name' => $bp->table_prefix . 'bp_activity', 'table_name_meta' => $bp->table_prefix . 'bp_activity_meta'); // Metadata tables for groups component. $meta_tables = array('activity' => $bp->table_prefix . 'bp_activity_meta'); // Fetch the default directory title. $default_directory_titles = bp_core_get_directory_page_default_titles(); $default_directory_title = $default_directory_titles[$this->id]; // All globals for activity component. // Note that global_tables is included in this array. $args = array('slug' => BP_ACTIVITY_SLUG, 'root_slug' => isset($bp->pages->activity->slug) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG, 'has_directory' => true, 'directory_title' => isset($bp->pages->activity->title) ? $bp->pages->activity->title : $default_directory_title, 'notification_callback' => 'bp_activity_format_notifications', 'search_string' => __('Search Activity...', 'buddypress'), 'global_tables' => $global_tables, 'meta_tables' => $meta_tables); parent::setup_globals($args); }