/** * Generate the current member type message. * * @since 2.3.0 * * @return string */ function bp_get_current_member_type_message() { $type_object = bp_get_member_type_object(bp_get_current_member_type()); $message = sprintf(__('Viewing members of the type: %s', 'buddypress'), '<strong>' . $type_object->labels['singular_name'] . '</strong>'); return apply_filters('bp_get_current_member_type_message', $message); }
/** * Analyze the URI and break it down into BuddyPress-usable chunks. * * BuddyPress can use complete custom friendly URIs without the user having to * add new rewrite rules. Custom components are able to use their own custom * URI structures with very little work. * * The URIs are broken down as follows: * - http:// example.com / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ... * - OUTSIDE ROOT: http:// example.com / sites / buddypress / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ... * * Example: * - http://example.com/members/andy/profile/edit/group/5/ * - $bp->current_component: string 'xprofile' * - $bp->current_action: string 'edit' * - $bp->action_variables: array ['group', 5] * * @since 1.0.0 */ function bp_core_set_uri_globals() { global $current_blog, $wp_rewrite; // Don't catch URIs on non-root blogs unless multiblog mode is on. if (!bp_is_root_blog() && !bp_is_multiblog_mode()) { return false; } $bp = buddypress(); // Define local variables. $root_profile = $match = false; $key_slugs = $matches = $uri_chunks = array(); // Fetch all the WP page names for each component. if (empty($bp->pages)) { $bp->pages = bp_core_get_directory_pages(); } // Ajax or not? if (defined('DOING_AJAX') && DOING_AJAX || strpos($_SERVER['REQUEST_URI'], 'wp-load.php')) { $path = bp_get_referer_path(); } else { $path = esc_url($_SERVER['REQUEST_URI']); } /** * Filters the BuddyPress global URI path. * * @since 1.0.0 * * @param string $path Path to set. */ $path = apply_filters('bp_uri', $path); // Take GET variables off the URL to avoid problems. $path = strtok($path, '?'); // Fetch current URI and explode each part separated by '/' into an array. $bp_uri = explode('/', $path); // Loop and remove empties. foreach ((array) $bp_uri as $key => $uri_chunk) { if (empty($bp_uri[$key])) { unset($bp_uri[$key]); } } // If running off blog other than root, any subdirectory names must be // removed from $bp_uri. This includes two cases: // // 1. when WP is installed in a subdirectory, // 2. when BP is running on secondary blog of a subdirectory // multisite installation. Phew! if (is_multisite() && !is_subdomain_install() && (bp_is_multiblog_mode() || 1 != bp_get_root_blog_id())) { // Blow chunks. $chunks = explode('/', $current_blog->path); // If chunks exist... if (!empty($chunks)) { // ...loop through them... foreach ($chunks as $key => $chunk) { $bkey = array_search($chunk, $bp_uri); // ...and unset offending keys if (false !== $bkey) { unset($bp_uri[$bkey]); } $bp_uri = array_values($bp_uri); } } } // Get site path items. $paths = explode('/', bp_core_get_site_path()); // Take empties off the end of path. if (empty($paths[count($paths) - 1])) { array_pop($paths); } // Take empties off the start of path. if (empty($paths[0])) { array_shift($paths); } // Reset indexes. $bp_uri = array_values($bp_uri); $paths = array_values($paths); // Unset URI indices if they intersect with the paths. foreach ((array) $bp_uri as $key => $uri_chunk) { if (isset($paths[$key]) && $uri_chunk == $paths[$key]) { unset($bp_uri[$key]); } } // Reset the keys by merging with an empty array. $bp_uri = array_merge(array(), $bp_uri); // If a component is set to the front page, force its name into $bp_uri // so that $current_component is populated (unless a specific WP post is being requested // via a URL parameter, usually signifying Preview mode). if ('page' == get_option('show_on_front') && get_option('page_on_front') && empty($bp_uri) && empty($_GET['p']) && empty($_GET['page_id'])) { $post = get_post(get_option('page_on_front')); if (!empty($post)) { $bp_uri[0] = $post->post_name; } } // Keep the unfiltered URI safe. $bp->unfiltered_uri = $bp_uri; // Don't use $bp_unfiltered_uri, this is only for backpat with old plugins. Use $bp->unfiltered_uri. $GLOBALS['bp_unfiltered_uri'] =& $bp->unfiltered_uri; // Get slugs of pages into array. foreach ((array) $bp->pages as $page_key => $bp_page) { $key_slugs[$page_key] = trailingslashit('/' . $bp_page->slug); } // Bail if keyslugs are empty, as BP is not setup correct. if (empty($key_slugs)) { return; } // Loop through page slugs and look for exact match to path. foreach ($key_slugs as $key => $slug) { if ($slug == $path) { $match = $bp->pages->{$key}; $match->key = $key; $matches[] = 1; break; } } // No exact match, so look for partials. if (empty($match)) { // Loop through each page in the $bp->pages global. foreach ((array) $bp->pages as $page_key => $bp_page) { // Look for a match (check members first). if (in_array($bp_page->name, (array) $bp_uri)) { // Match found, now match the slug to make sure. $uri_chunks = explode('/', $bp_page->slug); // Loop through uri_chunks. foreach ((array) $uri_chunks as $key => $uri_chunk) { // Make sure chunk is in the correct position. if (!empty($bp_uri[$key]) && $bp_uri[$key] == $uri_chunk) { $matches[] = 1; // No match. } else { $matches[] = 0; } } // Have a match. if (!in_array(0, (array) $matches)) { $match = $bp_page; $match->key = $page_key; break; } // Unset matches. unset($matches); } // Unset uri chunks. unset($uri_chunks); } } // URLs with BP_ENABLE_ROOT_PROFILES enabled won't be caught above. if (empty($matches) && bp_core_enable_root_profiles()) { // Switch field based on compat. $field = bp_is_username_compatibility_mode() ? 'login' : 'slug'; // Make sure there's a user corresponding to $bp_uri[0]. if (!empty($bp->pages->members) && !empty($bp_uri[0]) && ($root_profile = get_user_by($field, $bp_uri[0]))) { // Force BP to recognize that this is a members page. $matches[] = 1; $match = $bp->pages->members; $match->key = 'members'; } } // Search doesn't have an associated page, so we check for it separately. if (!empty($bp_uri[0]) && bp_get_search_slug() == $bp_uri[0]) { $matches[] = 1; $match = new stdClass(); $match->key = 'search'; $match->slug = bp_get_search_slug(); } // This is not a BuddyPress page, so just return. if (empty($matches)) { return false; } $wp_rewrite->use_verbose_page_rules = false; // Find the offset. With $root_profile set, we fudge the offset down so later parsing works. $slug = !empty($match) ? explode('/', $match->slug) : ''; $uri_offset = empty($root_profile) ? 0 : -1; // Rejig the offset. if (!empty($slug) && 1 < count($slug)) { // Only offset if not on a root profile. Fixes issue when Members page is nested. if (false === $root_profile) { array_pop($slug); $uri_offset = count($slug); } } // Global the unfiltered offset to use in bp_core_load_template(). // To avoid PHP warnings in bp_core_load_template(), it must always be >= 0. $bp->unfiltered_uri_offset = $uri_offset >= 0 ? $uri_offset : 0; // We have an exact match. if (isset($match->key)) { // Set current component to matched key. $bp->current_component = $match->key; // If members component, do more work to find the actual component. if ('members' == $match->key) { $after_member_slug = false; if (!empty($bp_uri[$uri_offset + 1])) { $after_member_slug = $bp_uri[$uri_offset + 1]; } // Are we viewing a specific user? if ($after_member_slug) { // If root profile, we've already queried for the user. if ($root_profile instanceof WP_User) { $bp->displayed_user->id = $root_profile->ID; // Switch the displayed_user based on compatibility mode. } elseif (bp_is_username_compatibility_mode()) { $bp->displayed_user->id = (int) bp_core_get_userid(urldecode($after_member_slug)); } else { $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename($after_member_slug); } } // Is this a member type directory? if (!bp_displayed_user_id() && $after_member_slug === apply_filters('bp_members_member_type_base', _x('type', 'member type URL base', 'buddypress')) && !empty($bp_uri[$uri_offset + 2])) { $matched_types = bp_get_member_types(array('has_directory' => true, 'directory_slug' => $bp_uri[$uri_offset + 2])); if (!empty($matched_types)) { $bp->current_member_type = reset($matched_types); unset($bp_uri[$uri_offset + 1]); } } // If the slug matches neither a member type nor a specific member, 404. if (!bp_displayed_user_id() && !bp_get_current_member_type() && $after_member_slug) { // Prevent components from loading their templates. $bp->current_component = ''; bp_do_404(); return; } // If the displayed user is marked as a spammer, 404 (unless logged-in user is a super admin). if (bp_displayed_user_id() && bp_is_user_spammer(bp_displayed_user_id())) { if (bp_current_user_can('bp_moderate')) { bp_core_add_message(__('This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress'), 'warning'); } else { bp_do_404(); return; } } // Bump the offset. if (bp_displayed_user_id()) { if (isset($bp_uri[$uri_offset + 2])) { $bp_uri = array_merge(array(), array_slice($bp_uri, $uri_offset + 2)); $bp->current_component = $bp_uri[0]; // No component, so default will be picked later. } else { $bp_uri = array_merge(array(), array_slice($bp_uri, $uri_offset + 2)); $bp->current_component = ''; } // Reset the offset. $uri_offset = 0; } } } // Determine the current action. $current_action = isset($bp_uri[$uri_offset + 1]) ? $bp_uri[$uri_offset + 1] : ''; /* * If a BuddyPress directory is set to the WP front page, URLs like example.com/members/?s=foo * shouldn't interfere with blog searches. */ if (empty($current_action) && !empty($_GET['s']) && 'page' == get_option('show_on_front') && !empty($match->id)) { $page_on_front = (int) get_option('page_on_front'); if ((int) $match->id === $page_on_front) { $bp->current_component = ''; return false; } } $bp->current_action = $current_action; // Slice the rest of the $bp_uri array and reset offset. $bp_uri = array_slice($bp_uri, $uri_offset + 2); $uri_offset = 0; // Set the entire URI as the action variables, we will unset the current_component and action in a second. $bp->action_variables = $bp_uri; // Reset the keys by merging with an empty array. $bp->action_variables = array_merge(array(), $bp->action_variables); }
<?php bp_directory_members_search_form(); ?> </div><!-- #members-dir-search --> <?php do_action('bp_before_directory_members_tabs'); ?> <form action="" method="post" id="members-directory-form" class="dir-form"> <div id="subnav" class="item-list-tabs" role="navigation"> <ul> <?php $member_type = bp_get_current_member_type(); if ($member_type) { $member_type = bp_get_member_type_object($member_type); ?> <li class="selected" id="members-all"><a href="<?php bp_members_directory_permalink(); ?> "><?php printf(__('All %s <span>%s</span>', 'kleo_framework'), $member_type->labels['name'], bp_get_total_member_count()); ?> </a></li> <?php } else { ?> <li class="selected" id="members-all"><a href="<?php bp_members_directory_permalink();
/** * Customize the body class, according to the currently displayed BP content. * * Uses the above is_() functions to output a body class for each scenario. * * @since 1.1.0 * * @param array $wp_classes The body classes coming from WP. * @param array|bool $custom_classes Classes that were passed to get_body_class(). * @return array $classes The BP-adjusted body classes. */ function bp_get_the_body_class($wp_classes = array(), $custom_classes = false) { $bp_classes = array(); /* Pages *************************************************************/ if (is_front_page()) { $bp_classes[] = 'home-page'; } if (bp_is_directory()) { $bp_classes[] = 'directory'; } if (bp_is_single_item()) { $bp_classes[] = 'single-item'; } /* Components ********************************************************/ if (!bp_is_blog_page()) { if (bp_is_user_profile()) { $bp_classes[] = 'xprofile'; } if (bp_is_activity_component()) { $bp_classes[] = 'activity'; } if (bp_is_blogs_component()) { $bp_classes[] = 'blogs'; } if (bp_is_messages_component()) { $bp_classes[] = 'messages'; } if (bp_is_friends_component()) { $bp_classes[] = 'friends'; } if (bp_is_groups_component()) { $bp_classes[] = 'groups'; } if (bp_is_settings_component()) { $bp_classes[] = 'settings'; } } /* User **************************************************************/ if (bp_is_user()) { $bp_classes[] = 'bp-user'; // Add current user member types. if ($member_types = bp_get_member_type(bp_displayed_user_id(), false)) { foreach ($member_types as $member_type) { $bp_classes[] = sprintf('member-type-%s', esc_attr($member_type)); } } } if (!bp_is_directory()) { if (bp_is_user_blogs()) { $bp_classes[] = 'my-blogs'; } if (bp_is_user_groups()) { $bp_classes[] = 'my-groups'; } if (bp_is_user_activity()) { $bp_classes[] = 'my-activity'; } } else { if (bp_get_current_member_type()) { $bp_classes[] = 'type'; } } if (bp_is_my_profile()) { $bp_classes[] = 'my-account'; } if (bp_is_user_profile()) { $bp_classes[] = 'my-profile'; } if (bp_is_user_friends()) { $bp_classes[] = 'my-friends'; } if (bp_is_user_messages()) { $bp_classes[] = 'my-messages'; } if (bp_is_user_recent_commments()) { $bp_classes[] = 'recent-comments'; } if (bp_is_user_recent_posts()) { $bp_classes[] = 'recent-posts'; } if (bp_is_user_change_avatar()) { $bp_classes[] = 'change-avatar'; } if (bp_is_user_profile_edit()) { $bp_classes[] = 'profile-edit'; } if (bp_is_user_friends_activity()) { $bp_classes[] = 'friends-activity'; } if (bp_is_user_groups_activity()) { $bp_classes[] = 'groups-activity'; } /* Messages **********************************************************/ if (bp_is_messages_inbox()) { $bp_classes[] = 'inbox'; } if (bp_is_messages_sentbox()) { $bp_classes[] = 'sentbox'; } if (bp_is_messages_compose_screen()) { $bp_classes[] = 'compose'; } if (bp_is_notices()) { $bp_classes[] = 'notices'; } if (bp_is_user_friend_requests()) { $bp_classes[] = 'friend-requests'; } if (bp_is_create_blog()) { $bp_classes[] = 'create-blog'; } /* Groups ************************************************************/ if (bp_is_group()) { $bp_classes[] = 'group-' . groups_get_current_group()->slug; // Add current group types. if ($group_types = bp_groups_get_group_type(bp_get_current_group_id(), false)) { foreach ($group_types as $group_type) { $bp_classes[] = sprintf('group-type-%s', esc_attr($group_type)); } } } if (bp_is_group_leave()) { $bp_classes[] = 'leave-group'; } if (bp_is_group_invites()) { $bp_classes[] = 'group-invites'; } if (bp_is_group_members()) { $bp_classes[] = 'group-members'; } if (bp_is_group_forum_topic()) { $bp_classes[] = 'group-forum-topic'; } if (bp_is_group_forum_topic_edit()) { $bp_classes[] = 'group-forum-topic-edit'; } if (bp_is_group_forum()) { $bp_classes[] = 'group-forum'; } if (bp_is_group_admin_page()) { $bp_classes[] = 'group-admin'; $bp_classes[] = bp_get_group_current_admin_tab(); } if (bp_is_group_create()) { $bp_classes[] = 'group-create'; $bp_classes[] = bp_get_groups_current_create_step(); } if (bp_is_group_home()) { $bp_classes[] = 'group-home'; } if (bp_is_single_activity()) { $bp_classes[] = 'activity-permalink'; } /* Registration ******************************************************/ if (bp_is_register_page()) { $bp_classes[] = 'registration'; } if (bp_is_activation_page()) { $bp_classes[] = 'activation'; } /* Current Component & Action ****************************************/ if (!bp_is_blog_page()) { $bp_classes[] = bp_current_component(); $bp_classes[] = bp_current_action(); } /* Clean up ***********************************************************/ // Add BuddyPress class if we are within a BuddyPress page. if (!bp_is_blog_page()) { $bp_classes[] = 'buddypress'; } // Merge WP classes with BuddyPress classes and remove any duplicates. $classes = array_unique(array_merge((array) $bp_classes, (array) $wp_classes)); /** * Filters the BuddyPress classes to be added to body_class() * * @since 1.1.0 * * @param array $classes Array of body classes to add. * @param array $bp_classes Array of BuddyPress-based classes. * @param array $wp_classes Array of WordPress-based classes. * @param array $custom_classes Array of classes that were passed to get_body_class(). */ return apply_filters('bp_get_the_body_class', $classes, $bp_classes, $wp_classes, $custom_classes); }
* @package BuddyPress * @subpackage bp-legacy */ ?> <?php /** * Fires before the display of the members loop. * * @since BuddyPress (1.2.0) */ do_action('bp_before_members_loop'); ?> <?php if (bp_get_current_member_type()) { ?> <p class="current-member-type"><?php bp_current_member_type_message(); ?> </p> <?php } ?> <?php if (bp_has_members(bp_ajax_querystring('members'))) { ?> <div id="pag-top" class="pagination">
/** * Add template hierarchy to theme compat for the members directory page. * * This is to mirror how WordPress has * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. * * @since 1.8.0 * * @param array $templates The templates from bp_get_theme_compat_templates(). * @return array $templates Array of custom templates to look for. */ public function directory_template_hierarchy($templates = array()) { // Set up the template hierarchy. $new_templates = array(); if ('' !== bp_get_current_member_type()) { $new_templates[] = 'members/index-directory-type-' . sanitize_file_name(bp_get_current_member_type()) . '.php'; } $new_templates[] = 'members/index-directory.php'; /** * Filters the template hierarchy for theme compat and members directory page. * * @since 1.8.0 * * @param array $value Array of template paths to add to hierarchy. */ $new_templates = apply_filters('bp_template_hierarchy_members_directory', $new_templates); // Merge new templates with existing stack // @see bp_get_theme_compat_templates(). $templates = array_merge((array) $new_templates, $templates); return $templates; }
/** * Generate the current member type message. * * @since 2.3.0 * * @return string */ function bp_get_current_member_type_message() { $type_object = bp_get_member_type_object(bp_get_current_member_type()); $message = sprintf(__('Viewing members of the type: %s', 'buddypress'), '<strong>' . $type_object->labels['singular_name'] . '</strong>'); /** * Filters the current member type message. * * @since 2.3.0 * * @param string $message Message to filter. */ return apply_filters('bp_get_current_member_type_message', $message); }
function kleo_bp_set_has_members_type_arg($args) { $member_type = bp_get_current_member_type(); $member_types = bp_get_member_types(array(), 'names'); if (isset($args['scope']) && !isset($args['member_type']) && in_array($args['scope'], $member_types)) { if ($member_type) { unset($args['scope']); } else { $args['member_type'] = $args['scope']; } } return $args; }
/** * Get the canonical URL of the current page. * * @since 1.6.0 * * @param array $args { * Optional array of arguments. * @type bool $include_query_args Whether to include current URL arguments * in the canonical URL returned from the function. * } * @return string Canonical URL for the current page. */ function bp_get_canonical_url($args = array()) { // For non-BP content, return the requested url, and let WP do the work. if (bp_is_blog_page()) { return bp_get_requested_url(); } $bp = buddypress(); $defaults = array('include_query_args' => false); $r = wp_parse_args($args, $defaults); extract($r); // Special case: when a BuddyPress directory (eg example.com/members) // is set to be the front page, ensure that the current canonical URL // is the home page URL. if ('page' == get_option('show_on_front') && ($page_on_front = (int) get_option('page_on_front'))) { $front_page_component = array_search($page_on_front, bp_core_get_directory_page_ids()); /* * If requesting the front page component directory, canonical * URL is the front page. We detect whether we're detecting a * component *directory* by checking that bp_current_action() * is empty - ie, this not a single item, a feed, or an item * type directory. */ if (false !== $front_page_component && bp_is_current_component($front_page_component) && !bp_current_action() && !bp_get_current_member_type()) { $bp->canonical_stack['canonical_url'] = trailingslashit(bp_get_root_domain()); // Except when the front page is set to the registration page // and the current user is logged in. In this case we send to // the members directory to avoid redirect loops. } elseif (bp_is_register_page() && 'register' == $front_page_component && is_user_logged_in()) { /** * Filters the logged in register page redirect URL. * * @since 1.5.1 * * @param string $value URL to redirect logged in members to. */ $bp->canonical_stack['canonical_url'] = apply_filters('bp_loggedin_register_page_redirect_to', bp_get_members_directory_permalink()); } } if (empty($bp->canonical_stack['canonical_url'])) { // Build the URL in the address bar. $requested_url = bp_get_requested_url(); // Stash query args. $url_stack = explode('?', $requested_url); // Build the canonical URL out of the redirect stack. if (isset($bp->canonical_stack['base_url'])) { $url_stack[0] = $bp->canonical_stack['base_url']; } if (isset($bp->canonical_stack['component'])) { $url_stack[0] = trailingslashit($url_stack[0] . $bp->canonical_stack['component']); } if (isset($bp->canonical_stack['action'])) { $url_stack[0] = trailingslashit($url_stack[0] . $bp->canonical_stack['action']); } if (!empty($bp->canonical_stack['action_variables'])) { foreach ((array) $bp->canonical_stack['action_variables'] as $av) { $url_stack[0] = trailingslashit($url_stack[0] . $av); } } // Add trailing slash. $url_stack[0] = trailingslashit($url_stack[0]); // Stash in the $bp global. $bp->canonical_stack['canonical_url'] = implode('?', $url_stack); } $canonical_url = $bp->canonical_stack['canonical_url']; if (!$include_query_args) { $canonical_url = array_reverse(explode('?', $canonical_url)); $canonical_url = array_pop($canonical_url); } /** * Filters the canonical url of the current page. * * @since 1.6.0 * * @param string $canonical_url Canonical URL of the current page. * @param array $args Array of arguments to help determine canonical URL. */ return apply_filters('bp_get_canonical_url', $canonical_url, $args); }