function bp_core_confirmation_js() { if (is_multisite() && !bp_is_root_blog()) { return false; } if (!wp_script_is('jquery')) { wp_enqueue_script('jquery'); } if (!wp_script_is('jquery', 'done')) { wp_print_scripts('jquery'); } ?> <script type="text/javascript"> jQuery( document ).ready( function() { jQuery( 'a.confirm').click( function() { if ( confirm( '<?php _e('Are you sure?', 'buddypress'); ?> ' ) ) return true; else return false; }); }); </script> <?php }
/** * Register our default taxonomies. * * @since 2.2.0 */ function bp_register_default_taxonomies() { // Member Type. register_taxonomy(bp_get_member_type_tax_name(), 'user', array('public' => false)); // Email type. register_taxonomy(bp_get_email_tax_type(), bp_get_email_post_type(), apply_filters('bp_register_email_tax_type', array('description' => _x('BuddyPress email types', 'email type taxonomy description', 'buddypress'), 'labels' => bp_get_email_tax_type_labels(), 'meta_box_cb' => 'bp_email_tax_type_metabox', 'public' => false, 'query_var' => false, 'rewrite' => false, 'show_in_menu' => false, 'show_tagcloud' => false, 'show_ui' => bp_is_root_blog() && bp_current_user_can('bp_moderate')))); }
public function grant_cap_foo($allcaps, $caps) { if (bp_is_root_blog()) { $allcaps['foo'] = 1; } return $allcaps; }
/** * Register the widgets for the Blogs component. */ function bp_blogs_register_widgets() { global $wpdb; if (bp_is_active('activity') && bp_is_root_blog($wpdb->blogid)) { add_action('widgets_init', create_function('', 'return register_widget("BP_Blogs_Recent_Posts_Widget");')); } }
/** * Load the JS for "Are you sure?" .confirm links. * * @since 1.1.0 */ function bp_core_confirmation_js() { if (is_multisite() && !bp_is_root_blog()) { return false; } wp_enqueue_script('bp-confirm'); wp_localize_script('bp-confirm', 'BP_Confirm', array('are_you_sure' => __('Are you sure?', 'buddypress'))); }
/** * Register an hidden post type to save custom group front pages */ private function register_post_type() { if (!bp_is_root_blog()) { return; } $labels = array('name' => _x('Groups front', 'post type general name', 'altctrl-public-group'), 'singular_name' => _x('Group front', 'post type singular name', 'altctrl-public-group')); $args = array('labels' => $labels, 'public' => false, 'publicly_queryable' => false, 'show_ui' => false, 'show_in_menu' => false, 'query_var' => false, 'rewrite' => false, 'has_archive' => false, 'hierarchical' => true, 'supports' => array('editor')); register_post_type('group_front', $args); }
/** * Load the JS for "Are you sure?" .confirm links. */ function bp_core_confirmation_js() { if (is_multisite() && !bp_is_root_blog()) { return false; } $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('bp-confirm', buddypress()->plugin_url . "bp-core/js/confirm{$min}.js", array('jquery'), bp_get_version()); wp_localize_script('bp-confirm', 'BP_Confirm', array('are_you_sure' => __('Are you sure?', 'buddypress'))); }
function thatcamp_add_styles_alt() { if (bp_is_root_blog()) { return; } ?> <style type="text/css"> div.generic-button { margin-bottom: 1rem; } div.generic-button a { background: #668800 url('<?php echo WP_CONTENT_URL; ?> /themes/thatcamp-karma/assets/images/thatcamp-greenbutton.jpg'); border: 1px solid #668800; opacity: 1; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; color: #ffffff; cursor: pointer; font-family: Francois One; font-size: 1.1rem; outline: none; padding: 4px 10px; text-align: center; text-decoration: none; line-height: 14px; text-decoration: -1px -1px 0px #668800; } div.generic-button a:hover { opacity: 0.9; } div.generic-button.disabled-button { position: relative; } div.generic-button.disabled-button a { opacity: 0.5; } div.generic-button.disabled-button span { margin-left: -999em; position: absolute; } div.generic-button.disabled-button:hover span { border-radius: 5px 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1); -webkit-box-shadow: 5px 5px rgba(0, 0, 0, 0.1); -moz-box-shadow: 5px 5px rgba(0, 0, 0, 0.1); position: absolute; left: 1em; top: 2em; z-index: 99; margin-left: 0; background: #FFFFAA; border: 1px solid #FFAD33; padding: 4px 8px; white-space: nowrap; } </style> <?php }
/** * Get taxonomy terms for a BuddyPress object. * * @since BuddyPress (2.2.0) * * @see wp_get_object_terms() for a full description of function and parameters. * * @param int|array $object_ids ID or IDs of objects. * @param string|array $taxonomies Name or names of taxonomies to match. * @param array $args See {@see wp_get_object_terms()}. * @return array */ function bp_get_object_terms( $object_ids, $taxonomies, $args = array() ) { if ( ! bp_is_root_blog() ) { switch_to_blog( bp_get_root_blog_id() ); } $retval = wp_get_object_terms( $object_ids, $taxonomies, $args ); restore_current_blog(); return $retval; }
/** * Remove taxonomy terms on a BuddyPress object. * * @since BuddyPress (2.3.0) * * @see wp_remove_object_terms() for a full description of function and parameters. * * @param int $object_id Object ID. * @param string|array $terms Term or terms to remove. * @param string $taxonomy Taxonomy name. * @return bool|WP_Error True on success, false or WP_Error on failure. */ function bp_remove_object_terms($object_id, $terms, $taxonomy) { $is_root_blog = bp_is_root_blog(); if (!$is_root_blog) { switch_to_blog(bp_get_root_blog_id()); } $retval = wp_remove_object_terms($object_id, $terms, $taxonomy); if (!$is_root_blog) { restore_current_blog(); } return $retval; }
/** * Register the friends widget. * * @since 1.9.0 */ function bp_friends_register_widgets() { if (!bp_is_active('friends')) { return; } // The Friends widget works only when looking an a displayed user, // and the concept of "displayed user" doesn't exist on non-root blogs, // so we don't register the widget there. if (!bp_is_root_blog()) { return; } add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Friends_Widget");')); }
/** * Setup our admin settings page and hooks */ public function setup_admin() { // Temporary workaround for the fact that WP's settings API doesn't work with MS if (bp_core_do_network_admin()) { if (!bp_is_root_blog()) { return; } $parent = 'options-general.php'; } else { $parent = 'bp-general-settings'; } $page = add_submenu_page($parent, __('BuddyPress Reply By Email', 'bp-rbe'), __('BP Reply By Email', 'bp-rbe'), 'manage_options', 'bp-rbe', array($this, 'load')); add_action("admin_head-{$page}", array($this, 'head')); add_action("admin_footer-{$page}", array($this, 'footer')); }
/** * Clear the directory_pages cache when one of the pages is updated. * * @since BuddyPress (2.0.0) * * @param int $post_id */ function bp_core_clear_directory_pages_cache_page_edit($post_id) { if (!bp_is_root_blog()) { return; } // Bail if BP is not defined here if (!buddypress()) { return; } $page_ids = bp_core_get_directory_page_ids('all'); if (!in_array($post_id, (array) $page_ids)) { return; } wp_cache_delete('directory_pages', 'bp'); }
function wff_child_scripts() { if (WEFOSTER_LESS_TYPE == 'less') { if (class_exists('BuddyPress') && bp_is_root_blog() || class_exists('BuddyPress') && defined('BP_ENABLE_MULTIBLOG') || WEFOSTER_MS_LOAD_BUDDYPRESS_STYLES == 'on') { wp_enqueue_style('wff_child_custom_bp_less', get_stylesheet_directory_uri() . '/assets/css/bp.min.css', false, 'bdc9fa64dc6df3b6c674c3ea195c0d44'); } wp_enqueue_style('wff_child_custom_main_less', get_stylesheet_directory_uri() . '/assets/css/main.min.css', false, 'bdc9fa64dc6df3b6c674c3ea195c0d44'); } if (WEFOSTER_LESS_TYPE == 'css') { wp_enqueue_style('wff_child_custom_css', get_stylesheet_directory_uri() . '/custom.css'); } if (WEFOSTER_CUSTOM_JS == 'true') { wp_register_script('wff_child_scripts', get_stylesheet_directory_uri() . '/assets/js/scripts.min.js', array(), '911acd948151184ec83b6b47b9bebfad', true); } wp_enqueue_script('wff_child_scripts'); }
/** * bp_core_exclude_pages() * * Excludes specific pages from showing on page listings, for example the "Activation" page. * * @package BuddyPress Core * @uses bp_is_active() checks if a BuddyPress component is active. * @return array The list of page ID's to exclude */ function bp_core_exclude_pages($pages) { global $bp; if (bp_is_root_blog()) { if (!empty($bp->pages->activate)) { $pages[] = $bp->pages->activate->id; } if (!empty($bp->pages->register)) { $pages[] = $bp->pages->register->id; } if (!empty($bp->pages->forums) && (!bp_is_active('forums') || bp_is_active('forums') && bp_forums_has_directory() && !bp_forums_is_installed_correctly())) { $pages[] = $bp->pages->forums->id; } } return apply_filters('bp_core_exclude_pages', $pages); }
/** * Redirect to user's Profile * * @return void */ function newwriting_child_redirect() { // bail if not logged in if (!is_user_logged_in()) { return; } // bail if not BP root site if (!bp_is_root_blog()) { return; } // bail if POST if ($_SERVER['REQUEST_METHOD'] == 'POST') { return; } // if restricted pages requested if (bp_is_activity_directory() or bp_is_members_directory()) { // get profile URL $home = bp_core_get_user_domain(bp_loggedin_user_id()) . 'groups/'; // redirect to member's profile wp_redirect($home); exit; } // groups directory if (bp_is_groups_directory()) { // bail if admin if (!is_super_admin()) { // get profile URL $home = bp_core_get_user_domain(bp_loggedin_user_id()) . 'groups/'; // redirect to member's profile wp_redirect($home); exit; } } // groups directory if (is_front_page()) { // bail if admin if (!is_super_admin()) { // get profile URL $home = bp_core_get_user_domain(bp_loggedin_user_id()) . 'groups/'; // redirect to member's profile wp_redirect($home); exit; } } }
/** * Enqueue scripts and stylesheets * * @since 1.0.0 */ function wff_scripts() { // Register path $path = get_template_directory_uri() . '/assets'; // First let's remove the default BuddyPress CSS wp_deregister_style('bp-child-css'); wp_deregister_style('bp-parent-css'); wp_deregister_style('bp-legacy-css'); // Enqueue our Main Stylesheet. wp_enqueue_style('wff_main', $path . '/css/main.css', false, '6ee17105aaae3sffd20bb56ee840e0cabcd'); // Load our BuddyPress Stylesheet based on being active (on root or multiblog) if (class_exists('BuddyPress') && bp_is_root_blog() || class_exists('BuddyPress') && defined('BP_ENABLE_MULTIBLOG') || WEFOSTER_MS_LOAD_BUDDYPRESS_STYLES == 'on') { wp_enqueue_style('wff_buddypress', $path . '/css/buddypress.css', false, '9ad14980d2sd75af2ed431fe686bad3f0'); } if (WEFOSTER_ICON_FONT == 'font-awesome') { // Enqueue Font Awesome wp_enqueue_style('wff_font_awesome', $path . '/css/font-awesome.css', false, '6ee17s105aaae3sffd20bb56ee840e0cabcd'); } if (is_single() && comments_open() && get_option('thread_comments')) { wp_enqueue_script('comment-reply'); } // Modernizr wp_register_script('modernizr', $path . '/js/vendor/modernizr-2.7.0.min.js', array(), null, false); //Mobile Scripts wp_register_script('touchswipe_js', $path . '/js/vendor/jquery.touchSwipe.min.js', array(), null, false); wp_register_script('sidr_js', $path . '/js/vendor/jquery.sidr.min.js', array(), null, false); wp_register_script('perfect_scrollbar', $path . '/js/vendor/perfect-scrollbar.jquery.js', array(), null, false); // Enqueue Font Awesome // Custom Scripts wp_register_script('wff_scripts', $path . '/js/scripts.min.js', array(), '2592531929b0a0de360daca45107315b', true); wp_enqueue_script('modernizr'); //Developer: See lib/constants.php to enable mobile optimisation. This is currently experimentatal. if (wff_is_device() || WEFOSTER_MOBILE_OPTIMISATION == 'off') { //Only load our scripts on mobile wp_enqueue_script('touchswipe_js'); wp_enqueue_script('sidr_js'); wp_enqueue_script('perfect_scrollbar'); wp_register_script('wff-fastclick', $path . '/vendor/fastclick/lib/fastclick.js', array(), null, false); wp_enqueue_script('wff-fastclick'); } wp_enqueue_script('jquery'); wp_enqueue_script('wff_scripts'); }
/** * Register taxonomy for hashtags. */ function bp_activity_hashtags_register_taxonomy() { // Setup our taxonomy args $args = array('labels' => array('name' => __('Activity Hashtags', 'bp-activity-hashtags'), 'singular_name' => __('Hashtag', 'bp-activity-hashtags'), 'menu_name' => __('Hashtags', 'bp-activity-hashtags'), 'search_items' => __('Search Hashtags', 'bp-activity-hashtags')), 'capabilities' => array('manage_terms' => 'edit_users', 'edit_terms' => 'edit_users', 'delete_terms' => 'edit_users', 'assign_terms' => 'read'), 'query_var' => false, 'rewrite' => false, 'show_in_nav_menus' => bp_is_root_blog()); // register the 'hashtag' taxonomy // // issues to be aware of: // (1) we're attaching this to the 'bp_activity' object type, which doesn't exist // and is more like a pseudo-type. but WP doesn't block this functionality // at the moment. however WP could "fix" this in the future and break this // // FWIW, Justin Tadlock does the same thing in his tutorial: // http://justintadlock.com/archives/2011/10/20/custom-user-taxonomies-in-wordpress // // The 'user' object type doesn't exist. // // (2) Conflicting object IDs noted by Boone Gorges // http://justintadlock.com/archives/2011/10/20/custom-user-taxonomies-in-wordpress#comment-503194 register_taxonomy(bp_activity_hashtags_get_data('taxonomy'), apply_filters('bp_activity_hashtags_object_type', 'bp_activity'), apply_filters('bp_activity_hashtags_taxonomy_args', $args)); }
/** * Register all active member types * */ public function register_member_type() { //$this->register_post_type(); $is_root_blog = bp_is_root_blog(); //if we are not on the main bp site, switch to it before registering member type if (!$is_root_blog) { switch_to_blog(bp_get_root_blog_id()); } //get all posts in memeber type post type $post_ids = $this->get_active_member_types(); // get_posts( array( 'post_type'=> bp_member_type_generator()->get_post_type(), 'posts_per_page'=> -1, 'post_status'=> 'publish' ) ); //update meta cache to avoid multiple db calls update_meta_cache('post', $post_ids); //build to register the memebr type $member_types = array(); foreach ($post_ids as $post_id) { $is_active = get_post_meta($post_id, '_bp_member_type_is_active', true); $name = get_post_meta($post_id, '_bp_member_type_name', true); if (!$is_active || !$name) { continue; //if not active or no unique key, do not register } $enable_directory = get_post_meta($post_id, '_bp_member_type_enable_directory', true); $directory_slug = get_post_meta($post_id, '_bp_member_type_directory_slug', true); $has_dir = false; if ($enable_directory) { if ($directory_slug) { $has_dir = $directory_slug; } else { $has_dir = true; } } $member_types[$name] = array('labels' => array('name' => get_post_meta($post_id, '_bp_member_type_label_name', true), 'singular_name' => get_post_meta($post_id, '_bp_member_type_label_singular_name', true)), 'has_directory' => $has_dir); } foreach ($member_types as $member_type => $args) { bp_register_member_type($member_type, $args); } if (!$is_root_blog) { restore_current_blog(); } }
/** * Register the BP Group documents widgets. * @version 2, 22/4/2014 */ function bp_group_documents_register_widgets() { if (!bp_is_active('groups')) { return; } register_widget('BP_Group_Documents_Newest_Widget'); register_widget('BP_Group_Documents_Popular_Widget'); register_widget('BP_Group_Documents_Usergroups_Widget'); // add_action( 'widgets_init' , create_function( '' , 'register_widget( "BP_Group_Documents_Newest_Widget" );' ) ) ; // add_action( 'widgets_init' , create_function( '' , 'register_widget("BP_Group_Documents_Popular_Widget");' ) ) ; // add_action( 'widgets_init' , create_function( '' , 'register_widget("BP_Group_Documents_Usergroups_Widget");' ) ) ; if (is_active_widget(false, false, 'bp_group_documents_newest_widget') || is_active_widget(false, false, 'bp_group_documents_popular_widget')) { add_action('wp_enqueue_scripts', 'bp_group_documents_add_my_stylesheet'); } // The BP_Group_Documents_CurrentGroup widget works only when looking at a group page, // and the concept of "current group " doesn't exist on non-root blogs, // so we don't register the widget there. if (!bp_is_root_blog()) { return; } register_widget('BP_Group_Documents_CurrentGroup_Widget'); // add_action( 'widgets_init' , create_function( '' , 'register_widget("BP_Group_Documents_CurrentGroup_Widget");' ) ) ; }
/** * 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); }
/** * Creates reusable markup for page setup on the Components and Pages dashboard panel. * * @package BuddyPress * @since 1.6.0 * @todo Use settings API */ function bp_core_admin_slugs_options() { $bp = buddypress(); // Get the existing WP pages $existing_pages = bp_core_get_directory_page_ids(); // Set up an array of components (along with component names) that have // directory pages. $directory_pages = array(); // Loop through loaded components and collect directories if (is_array($bp->loaded_components)) { foreach ($bp->loaded_components as $component_slug => $component_id) { // Only components that need directories should be listed here if (isset($bp->{$component_id}) && !empty($bp->{$component_id}->has_directory)) { // component->name was introduced in BP 1.5, so we must provide a fallback $directory_pages[$component_id] = !empty($bp->{$component_id}->name) ? $bp->{$component_id}->name : ucwords($component_id); } } } /** Directory Display *****************************************************/ /** * Filters the loaded components needing directory page association to a WordPress page. * * @since 1.5.0 * * @param array $directory_pages Array of available components to set associations for. */ $directory_pages = apply_filters('bp_directory_pages', $directory_pages); if (!empty($directory_pages)) { ?> <h3><?php _e('Directories', 'buddypress'); ?> </h3> <p><?php _e('Associate a WordPress Page with each BuddyPress component directory.', 'buddypress'); ?> </p> <table class="form-table"> <tbody> <?php foreach ($directory_pages as $name => $label) { ?> <tr valign="top"> <th scope="row"> <label for="bp_pages[<?php echo esc_attr($name); ?> ]"><?php echo esc_html($label); ?> </label> </th> <td> <?php if (!bp_is_root_blog()) { switch_to_blog(bp_get_root_blog_id()); } ?> <?php echo wp_dropdown_pages(array('name' => 'bp_pages[' . esc_attr($name) . ']', 'echo' => false, 'show_option_none' => __('- None -', 'buddypress'), 'selected' => !empty($existing_pages[$name]) ? $existing_pages[$name] : false)); ?> <?php if (!empty($existing_pages[$name])) { ?> <a href="<?php echo get_permalink($existing_pages[$name]); ?> " class="button-secondary" target="_bp"><?php _e('View', 'buddypress'); ?> </a> <?php } ?> <?php if (!bp_is_root_blog()) { restore_current_blog(); } ?> </td> </tr> <?php } ?> <?php /** * Fires after the display of default directories. * * Allows plugins to add their own directory associations. * * @since 1.5.0 */ do_action('bp_active_external_directories'); ?> </tbody> </table> <?php } /** Static Display ********************************************************/ // Static pages $static_pages = array('register' => __('Register', 'buddypress'), 'activate' => __('Activate', 'buddypress')); /** * Filters the default static pages for BuddyPress setup. * * @since 1.6.0 * * @param array $static_pages Array of static default static pages. */ $static_pages = apply_filters('bp_static_pages', $static_pages); if (!empty($static_pages)) { ?> <h3><?php _e('Registration', 'buddypress'); ?> </h3> <p><?php _e('Associate WordPress Pages with the following BuddyPress Registration pages.', 'buddypress'); ?> </p> <table class="form-table"> <tbody> <?php foreach ($static_pages as $name => $label) { ?> <tr valign="top"> <th scope="row"> <label for="bp_pages[<?php echo esc_attr($name); ?> ]"><?php echo esc_html($label); ?> </label> </th> <td> <?php if (!bp_is_root_blog()) { switch_to_blog(bp_get_root_blog_id()); } ?> <?php echo wp_dropdown_pages(array('name' => 'bp_pages[' . esc_attr($name) . ']', 'echo' => false, 'show_option_none' => __('- None -', 'buddypress'), 'selected' => !empty($existing_pages[$name]) ? $existing_pages[$name] : false)); ?> <?php if (!empty($existing_pages[$name])) { ?> <a href="<?php echo get_permalink($existing_pages[$name]); ?> " class="button-secondary" target="_bp"><?php _e('View', 'buddypress'); ?> </a> <?php } ?> <?php if (!bp_is_root_blog()) { restore_current_blog(); } ?> </td> </tr> <?php } ?> <?php /** * Fires after the display of default static pages for BuddyPress setup. * * @since 1.5.0 */ do_action('bp_active_external_pages'); ?> </tbody> </table> <?php } }
/** * Maps settings capabilities * * @since bbPress (r4242) * * @param array $caps Capabilities for meta capability * @param string $cap Capability name * @param int $user_id User id * @param mixed $args Arguments * @uses get_post() To get the post * @uses apply_filters() Calls 'bbp_map_meta_caps' with caps, cap, user id and * args * @return array Actual capabilities for meta capability */ public static function map_settings_meta_caps($caps = array(), $cap = '', $user_id = 0, $args = array()) { // What capability is being checked? switch ($cap) { // BuddyPress case 'bbp_settings_buddypress': if (is_plugin_active('buddypress/bp-loader.php') && defined('BP_VERSION') && bp_is_root_blog() && is_super_admin()) { $caps = array(bbpress()->admin->minimum_capability); } else { $caps = array('do_not_allow'); } break; // Akismet // Akismet case 'bbp_settings_akismet': if (is_plugin_active('akismet/akismet.php') && defined('AKISMET_VERSION') && is_super_admin()) { $caps = array(bbpress()->admin->minimum_capability); } else { $caps = array('do_not_allow'); } break; // bbPress // bbPress case 'bbp_about_page': // About and Credits // About and Credits case 'bbp_tools_page': // Tools Page // Tools Page case 'bbp_tools_repair_page': // Tools - Repair Page // Tools - Repair Page case 'bbp_tools_import_page': // Tools - Import Page // Tools - Import Page case 'bbp_tools_reset_page': // Tools - Reset Page // Tools - Reset Page case 'bbp_settings_page': // Settings Page // Settings Page case 'bbp_settings_users': // Settings - Users // Settings - Users case 'bbp_settings_features': // Settings - Features // Settings - Features case 'bbp_settings_theme_compat': // Settings - Theme compat // Settings - Theme compat case 'bbp_settings_root_slugs': // Settings - Root slugs // Settings - Root slugs case 'bbp_settings_single_slugs': // Settings - Single slugs // Settings - Single slugs case 'bbp_settings_user_slugs': // Settings - User slugs // Settings - User slugs case 'bbp_settings_per_page': // Settings - Per page // Settings - Per page case 'bbp_settings_per_rss_page': // Settings - Per RSS page $caps = array(bbpress()->admin->minimum_capability); break; } return apply_filters('bbp_map_settings_meta_caps', $caps, $cap, $user_id, $args); }
/** * Whether to show the blog footer buttons. * * @return bool Defaults to true. False when on BP root blog and not on a blog * page deemed by BuddyPress. */ public static function show_footer_button() { $retval = true; // @todo might need to tweak this a bit... if (bp_is_root_blog() && !bp_is_blog_page()) { $retval = false; } return apply_filters('bp_follow_blogs_show_footer_button', $retval); }
/** * Fires the WP query and loads the appropriate template * * @package BuddyPress Docs * @since 1.0-beta */ function load_template() { global $bp, $post; // Docs are stored on the root blog if (!bp_is_root_blog()) { switch_to_blog(BP_ROOT_BLOG); } switch ($this->current_view) { case 'create': // Todo: Make sure the user has permission to create /** * Load the template tags for the edit screen */ require BP_DOCS_INCLUDES_PATH . 'templatetags-edit.php'; $template = 'edit-doc.php'; break; case 'list': $args = $this->build_query(); /* Todo: Get this into its own 'tree' view */ /* $the_docs = get_posts( $args ); $f = walk_page_tree($the_docs, 0, 0, array( 'walker' => new Walker_Page ) ); print_r( $f ); */ query_posts($args); $template = 'docs-loop.php'; break; case 'category': // Check to make sure the category exists // If not, redirect back to list view with error // Otherwise, get args based on category ID // Then load the loop template break; case 'single': case 'edit': case 'delete': case 'history': $args = $this->build_query(); // Add a 'name' argument so that we only get the specific post $args['name'] = $this->doc_slug; query_posts($args); // If this is the edit screen, we won't really be able to use a // regular have_posts() loop in the template, so we'll stash the // post in the $bp global for the edit-specific template tags if ($this->current_view == 'edit') { if (have_posts()) { while (have_posts()) { the_post(); $bp->bp_docs->current_post = $post; // Set an edit lock wp_set_post_lock($post->ID); } } /** * Load the template tags for the edit screen */ require BP_DOCS_INCLUDES_PATH . 'templatetags-edit.php'; } switch ($this->current_view) { case 'single': $template = 'single-doc.php'; break; case 'edit': $template = 'edit-doc.php'; break; case 'history': $template = 'history-doc.php'; break; } // Todo: Maybe some sort of error if there is no edit permission? break; } // Only register on the root blog if (!bp_is_root_blog()) { restore_current_blog(); } $template_path = bp_docs_locate_template($template); if (!empty($template)) { include apply_filters('bp_docs_template', $template_path, $this); } }
/** * Remove the entry from bp_pages when the corresponding WP page is deleted. * * Bails early on multisite installations when not viewing the root site. * @link https://buddypress.trac.wordpress.org/ticket/6226 * * @since BuddyPress (2.2.0) * * @param int $post_id Post ID. */ function bp_core_on_directory_page_delete($post_id) { // Stop if we are not on the main BP root blog if (!bp_is_root_blog()) { return; } $page_ids = bp_core_get_directory_page_ids('all'); $component_name = array_search($post_id, $page_ids); if (!empty($component_name)) { unset($page_ids[$component_name]); } bp_core_update_directory_page_ids($page_ids); }
/** * Register meta box and associated JS for BuddyPress WP Nav Menu. * * @since 1.9.0 */ function bp_admin_wp_nav_menu_meta_box() { if (!bp_is_root_blog()) { return; } add_meta_box('add-buddypress-nav-menu', __('BuddyPress', 'buddypress'), 'bp_admin_do_wp_nav_menu_meta_box', 'nav-menus', 'side', 'default'); add_action('admin_print_footer_scripts', 'bp_admin_wp_nav_menu_restrict_items'); }
/** * Get a SQL clause representing member_type include/exclusion. * * @since 2.4.0 * * @param string|array $member_types Array or comma-separated list of member types. * @param string $operator 'IN' or 'NOT IN'. * @return string */ protected function get_sql_clause_for_member_types($member_types, $operator) { global $wpdb; // Sanitize. if ('NOT IN' !== $operator) { $operator = 'IN'; } // Parse and sanitize types. if (!is_array($member_types)) { $member_types = preg_split('/[,\\s+]/', $member_types); } $types = array(); foreach ($member_types as $mt) { if (bp_get_member_type_object($mt)) { $types[] = $mt; } } $tax_query = new WP_Tax_Query(array(array('taxonomy' => 'bp_member_type', 'field' => 'name', 'operator' => $operator, 'terms' => $types))); // Switch to the root blog, where member type taxonomies live. $switched = false; if (!bp_is_root_blog()) { switch_to_blog(bp_get_root_blog_id()); $switched = true; } $sql_clauses = $tax_query->get_sql('u', $this->uid_name); if ($switched) { restore_current_blog(); } $clause = ''; // The no_results clauses are the same between IN and NOT IN. if (false !== strpos($sql_clauses['where'], '0 = 1')) { $clause = $this->no_results['where']; // The tax_query clause generated for NOT IN can be used almost as-is. We just trim the leading 'AND'. } elseif ('NOT IN' === $operator) { $clause = preg_replace('/^\\s*AND\\s*/', '', $sql_clauses['where']); // IN clauses must be converted to a subquery. } elseif (preg_match('/' . $wpdb->term_relationships . '\\.term_taxonomy_id IN \\([0-9, ]+\\)/', $sql_clauses['where'], $matches)) { $clause = "u.{$this->uid_name} IN ( SELECT object_id FROM {$wpdb->term_relationships} WHERE {$matches[0]} )"; } return $clause; }
/** * 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 BuddyPress (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(); // Delete any existing pages if ('delete' == $existing) { foreach ((array) $pages as $page_id) { wp_delete_post($page_id, true); } $pages = array(); } $page_titles = array('activity' => _x('Activity', 'Page title for the Activity directory.', 'buddypress'), 'groups' => _x('Groups', 'Page title for the Groups directory.', 'buddypress'), 'sites' => _x('Sites', 'Page title for the Sites directory.', 'buddypress'), 'activate' => _x('Activate', 'Page title for the user account activation screen.', 'buddypress'), 'members' => _x('Members', 'Page title for the Members directory.', 'buddypress'), 'register' => _x('Register', 'Page title for the user registration screen.', 'buddypress')); $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['sites'])) { unset($pages_to_create['sites']); } // 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) { $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 a default role for the current user. * * Give a user the default role when creating content on a site they do not * already have a role or capability on. * * @since BuddyPress (1.6.0) * * @global BuddyPress $bp Global BuddyPress settings object. * * @uses is_multisite() * @uses bp_allow_global_access() * @uses bp_is_user_inactive() * @uses is_user_logged_in() * @uses current_user_can() * @uses WP_User::set_role() */ function bp_set_current_user_default_role() { // Bail if not multisite or not root blog if (!is_multisite() || !bp_is_root_blog()) { return; } // Bail if user is not logged in or already a member if (!is_user_logged_in() || is_user_member_of_blog()) { return; } // Bail if user is not active if (bp_is_user_inactive()) { return; } // Set the current users default role buddypress()->current_user->set_role(bp_get_option('default_role', 'subscriber')); }