/** * get_item function. * * returns data about a BuddyPress site * * @access public * @param mixed $request * @return void */ public function get_item($request) { global $bp; $core = array('version' => $bp->version, 'active_components' => $bp->active_components, 'directory_page_ids' => bp_core_get_directory_page_ids()); $core = apply_filters('core_api_data_filter', $core); $response = new WP_REST_Response(); $response->set_data($core); $response = rest_ensure_response($response); return $response; }
/** * Fixes the ProSites checkout if BuddyPress registration page is set to checkout page */ public static function fix_registration() { global $psts; if (function_exists('bp_core_get_directory_page_ids')) { $bp_directory_page_ids = bp_core_get_directory_page_ids(); if (!empty($bp_directory_page_ids['register'])) { $register_url = get_permalink($bp_directory_page_ids['register']); } if (bp_is_current_component('register') && $register_url == $psts->checkout_url()) { remove_action('bp_init', 'bp_core_wpsignup_redirect'); remove_action('bp_screens', 'bp_core_screen_signup'); } } }
/** * 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 bps_add_form() { global $post; $page = $post->ID; if ($page == 0) { $bp_pages = bp_core_get_directory_page_ids(); $page = $bp_pages['members']; } $len = strlen((string) $page); $args = array('post_type' => 'bps_form', 'orderby' => 'ID', 'order' => 'ASC', 'nopaging' => true, 'meta_query' => array(array('key' => 'bps_options', 'value' => 's:9:"directory";s:3:"Yes";', 'compare' => 'LIKE'), array('key' => 'bps_options', 'value' => "s:6:\"action\";s:{$len}:\"{$page}\";", 'compare' => 'LIKE'))); $args = apply_filters('bps_form_order', $args); $posts = get_posts($args); foreach ($posts as $post) { $meta = bps_meta($post->ID); $template = $meta['template']; bps_display_form($post->ID, $template, 'directory'); } }
function add_steps() { global $nxt_rewrite; // Setup wizard steps $steps = array(); if ('install' == $this->setup_type) { $steps = array(__('Components', 'buddypress'), __('Pages', 'buddypress'), __('Permalinks', 'buddypress'), __('Theme', 'buddypress'), __('Finish', 'buddypress')); // Update wizard steps } else { if ($this->is_network_activate) { $steps[] = __('Multisite Update', 'buddypress'); } if ($this->database_version < (int) $this->new_version) { $steps[] = __('Database Update', 'buddypress'); } if ($this->database_version < 1801 || !bp_core_get_directory_page_ids()) { $steps[] = __('Components', 'buddypress'); $steps[] = __('Pages', 'buddypress'); } $steps[] = __('Finish', 'buddypress'); } return $steps; }
public function test_should_return_false_for_invalid_component() { $found = bp_core_get_directory_page_id('foo'); $pages = bp_core_get_directory_page_ids(); $this->assertFalse($found); }
function check_positive_pages($posts) { global $wp_query, $M_options; $component = bp_current_component(); if (count($posts) > 1) { return $posts; } if (!empty($component)) { // we may be on a restricted post so check the URL and redirect if needed $redirect = false; $url = ''; $exclude = array(); if (!empty($M_options['registration_page'])) { $exclude[] = get_permalink((int) $M_options['registration_page']); $exclude[] = untrailingslashit(get_permalink((int) $M_options['registration_page'])); } if (!empty($M_options['account_page'])) { $exclude[] = get_permalink((int) $M_options['account_page']); $exclude[] = untrailingslashit(get_permalink((int) $M_options['account_page'])); } if (!empty($M_options['nocontent_page'])) { $exclude[] = get_permalink((int) $M_options['nocontent_page']); $exclude[] = untrailingslashit(get_permalink((int) $M_options['nocontent_page'])); } if (!empty($wp_query->query_vars['protectedfile']) && !$forceviewing) { $exclude[] = $host; $exclude[] = untrailingslashit($host); } $existing_pages = bp_core_get_directory_page_ids(); if (!in_array(strtolower(get_permalink($existing_pages[$component])), $exclude)) { $url = get_permalink($existing_pages[$component]); } // Check if we have a url available to check if (empty($url)) { return $posts; } // we have the current page / url - get the groups selected $group_id = $this->get_group(); if ($group_id) { $group = new M_Urlgroup($group_id); if (!$group->url_matches($url)) { $redirect = true; } } if ($redirect === true && !empty($M_options['nocontent_page'])) { // we need to redirect $this->redirect(); } else { return $posts; } } return $posts; }
/** * Creates reusable markup for page setup on the Components and Pages dashboard panel. * * This markup has been abstracted so that it can be used both during the setup wizard as well as * when BP has been fully installed. * * @package BuddyPress Core * @since 1.5 */ function bp_core_admin_page_options() { global $bp; // Get the existing nxt 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(); 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 $component_name = !empty($bp->{$component_id}->name) ? $bp->{$component_id}->name : ucwords($component_id); $directory_pages[$component_id] = $component_name; } } $directory_pages = apply_filters('bp_directory_pages', $directory_pages); ?> <h3><?php _e('Directories', 'buddypress'); ?> </h3> <p><?php _e('Associate a NXTClass Page with each BuddyPress component directory.', 'buddypress'); ?> </p> <table class="form-table"> <tbody> <?php foreach ($directory_pages as $name => $label) { ?> <?php $disabled = !bp_is_active($name) ? ' disabled="disabled"' : ''; ?> <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 nxt_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)); ?> <a href="<?php echo admin_url(add_query_arg(array('post_type' => 'page'), 'post-new.php')); ?> " class="button-secondary"><?php _e('New Page'); ?> </a> <input class="button-primary" type="submit" name="bp-admin-pages-single" value="<?php _e('Save', 'buddypress'); ?> " /> <?php if (!empty($existing_pages[$name])) { ?> <a href="<?php echo get_permalink($existing_pages[$name]); ?> " class="button-secondary" target="_bp"><?php _e('View'); ?> </a> <?php } ?> <?php if (!bp_is_root_blog()) { restore_current_blog(); } ?> </td> </tr> <?php } ?> <?php do_action('bp_active_external_directories'); ?> </tbody> </table> <?php // Static pages $static_pages = array('register' => __('Register', 'buddypress'), 'activate' => __('Activate', 'buddypress')); ?> <h3><?php _e('Registration', 'buddypress'); ?> </h3> <p><?php _e('Associate NXTClass 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 echo nxt_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)); ?> <a href="<?php echo admin_url(add_query_arg(array('post_type' => 'page'), 'post-new.php')); ?> " class="button-secondary"><?php _e('New Page'); ?> </a> <input class="button-primary" type="submit" name="bp-admin-pages-single" value="<?php _e('Save', 'buddypress'); ?> " /> <?php if (!empty($existing_pages[$name])) { ?> <a href="<?php echo get_permalink($existing_pages[$name]); ?> " class="button-secondary" target="_bp"><?php _e('View'); ?> </a> <?php } ?> </td> </tr> <?php } ?> <?php do_action('bp_active_external_pages'); ?> </tbody> </table> <?php }
function yit_fix_bp_comments_list($comments, $post_id) { global $wp_query; $post = $wp_query->get_queried_object(); if (in_array($post->ID, bp_core_get_directory_page_ids())) { return array(); } return $comments; }
public function validate_positive($args = null) { $component = bp_current_component(); if ($component) { $pages = bp_core_get_directory_page_ids(); if (!empty($pages[$component])) { return in_array($pages[$component], $this->data); } } return parent::validate_positive(); }
public function test_bp_core_get_directory_page_ids_should_not_contain_register_and_activet_pages_when_registration_is_closed() { // Make sure the pages exist, to verify they're filtered out. add_filter('bp_get_signup_allowed', '__return_true', 999); $ac = buddypress()->active_components; bp_core_add_page_mappings(array_keys($ac)); remove_filter('bp_get_signup_allowed', '__return_true', 999); // Get page ids $page_ids = bp_core_get_directory_page_ids(); // Need to delete these pages as previously created. wp_delete_post($page_ids['register'], true); wp_delete_post($page_ids['activate'], true); add_filter('bp_get_signup_allowed', '__return_false', 999); bp_core_add_page_mappings(array_keys($ac)); $page_ids = bp_core_get_directory_page_ids(); remove_filter('bp_get_signup_allowed', '__return_false', 999); $page_names = array_keys($page_ids); $this->assertNotContains('register', $page_names); $this->assertNotContains('activate', $page_names); }
function step_pages_save() { global $wpdb; if (isset($_POST['submit']) && isset($_POST['bp_pages'])) { check_admin_referer('bpwizard_pages'); // Make sure that the pages are created on the bp_get_root_blog_id(), no matter which Dashboard the setup is being run on if (!empty($wpdb->blogid) && $wpdb->blogid != bp_get_root_blog_id() && !defined('BP_ENABLE_MULTIBLOG')) { switch_to_blog(bp_get_root_blog_id()); } // Delete any existing pages $existing_pages = bp_core_get_directory_page_ids(); foreach ((array) $existing_pages as $page_id) { wp_delete_post($page_id, true); } $blog_pages = $this->setup_pages((array) $_POST['bp_pages']); bp_update_option('bp-pages', $blog_pages); if (!empty($wpdb->blogid) && $wpdb->blogid != bp_get_root_blog_id() && !defined('BP_ENABLE_MULTIBLOG')) { restore_current_blog(); } return true; } return false; }
/** * Handles plugin deactivation * * @uses bp_core_get_directory_page_ids() to get the BuddyPress component page ids * @uses buddydrive_get_slug() to get BuddyDrive slug * @uses wp_delete_post() to eventually delete the BuddyDrive page * @uses bp_core_update_directory_page_ids() to update the BuddyPres component pages ids */ function buddydrive_deactivation() { // Bail if config does not match what we need if (buddydrive::bail()) { return; } $directory_pages = bp_core_get_directory_page_ids(); $buddydrive_slug = buddydrive_get_slug(); if (!empty($directory_pages[$buddydrive_slug])) { // let's remove the page as the plugin is deactivated. $buddydrive_page_id = $directory_pages[$buddydrive_slug]; wp_delete_post($buddydrive_page_id, true); unset($directory_pages[$buddydrive_slug]); bp_core_update_directory_page_ids($directory_pages); } do_action('buddydrive_deactivation'); }
function bp_core_create_root_component_page() { global $bp; $new_page_ids = array(); foreach ((array) $bp->add_root as $slug) { $new_page_ids[$slug] = wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords($slug), 'post_status' => 'publish', 'post_type' => 'page')); } $page_ids = array_merge((array) $new_page_ids, (array) bp_core_get_directory_page_ids()); bp_core_update_directory_page_ids($page_ids); }
/** * Generates the BP component pages array * * @version 1.0 * @since 1.0 * @param array $flat_pages | Flat array of all WordPress pages on the site * @return obj $pages | Exception on failure. Structured object containing page ID's, Names, and Slugs on success. */ function buildDirectoryPages($flat_pages) { if (empty($flat_pages)) { throw new FOX_exception(array('numeric' => 1, 'text' => "Called with empty flat_pages array", 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => null)); } $page_ids = (array) bp_core_get_directory_page_ids(); if (empty($page_ids)) { throw new FOX_exception(array('numeric' => 2, 'text' => "BP core directory page ids option is empty", 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => null)); } $pages = new stdClass(); // Iterate through each entry in the BP pages config option foreach ($page_ids as $component_id => $bp_page_id) { // Iterate through each WP site page in the flat pages array foreach ($flat_pages as $wp_page_id => $data) { // If the page ids match, add this page to the components array if ($wp_page_id == $bp_page_id) { $pages->{$component_id}->name = $data['slug']; $pages->{$component_id}->id = $wp_page_id; $pages->{$component_id}->title = $data['title']; $stem = array(); $stem[] = $data['slug']; $parent = $data['parent']; // If the page is not attached to the root node, traverse the page tree backwards to the // root node generating the reverse walk, then flip it and implode it to a string. while ($parent != 0) { $stem[] = $flat_pages[$parent]['slug']; $parent = $flat_pages[$parent]['parent']; } // NOTE: BuddyPress incorrectly calls this a "slug", which is confusing. The correct term // is a "stem" (in string form) and a "walk" (in array form). $pages->{$component_id}->slug = implode('/', array_reverse((array) $stem)); } unset($slug); } unset($wp_page_id, $data); } unset($component_id, $bp_page_id); return apply_filters('bp_core_get_directory_pages', $pages); }
function add_steps() { global $wp_rewrite; // Setup wizard steps $steps = array(); if ('install' == $this->setup_type) { $steps = array(__('Components', 'buddypress'), __('Pages', 'buddypress'), __('Permalinks', 'buddypress'), __('Theme', 'buddypress'), __('Finish', 'buddypress')); // Update wizard steps } else { if ($this->is_network_activate) { $steps[] = __('Multisite Update', 'buddypress'); } if ($this->db_version_raw < (int) $this->db_version) { $steps[] = __('Database Update', 'buddypress'); } // New for BP 1.5 if ($this->db_version_raw < 1801 || !bp_core_get_directory_page_ids()) { $steps[] = __('Components', 'buddypress'); $steps[] = __('Pages', 'buddypress'); } // New for BP 1.6 if ($this->db_version_raw < 5222 && !defined('BP_USE_WP_ADMIN_BAR')) { $steps[] = __('Admin Bar', 'buddypress'); } $steps[] = __('Finish', 'buddypress'); } return $steps; }
/** * registering post type */ function register_post_types() { global $bp, $wpdb; if (empty($bp->pages->{$this->id}->slug)) { $directory_ids = bp_core_get_directory_page_ids(); $page_id = $directory_ids[$this->id]; $page_slug = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM {$wpdb->base_prefix}posts WHERE ID = %d AND post_status = 'publish' ", $page_id)); } else { $page_slug = $bp->pages->{$this->id}->slug; } $slug = isset($page_slug) ? $page_slug : BP_CHECKINS_SLUG; // Set up some labels for the post type $labels = array('name' => __('Places', 'bp-checkins'), 'singular' => __('Place', 'bp-checkins'), 'menu_name' => __('Community Places', 'bp-checkins'), 'all_items' => __('All Places', 'bp-checkins'), 'singular_name' => __('Place', 'bp-checkins'), 'add_new' => __('Add New Place', 'bp-checkins'), 'add_new_item' => __('Add New Place', 'bp-checkins'), 'edit_item' => __('Edit Place', 'bp-checkins'), 'new_item' => __('New Place', 'bp-checkins'), 'view_item' => __('View Place', 'bp-checkins'), 'search_items' => __('Search Places', 'bp-checkins'), 'not_found' => __('No Places Found', 'bp-checkins'), 'not_found_in_trash' => __('No Places Found in Trash', 'bp-checkins')); $args = array('label' => __('Place', 'bp-checkins'), 'labels' => $labels, 'public' => false, 'rewrite' => array('slug' => $slug . '/place', 'with_front' => false), 'show_ui' => true, 'supports' => array('title', 'editor', 'author', 'excerpt', 'comments', 'custom-fields'), 'menu_icon' => BP_CHECKINS_PLUGIN_URL_IMG . '/community-places-post-type-icon.png', 'taxonomies' => array('places_category')); // Register the post type. register_post_type('places', $args); parent::register_post_types(); }
/** * 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 = bp_core_admin_get_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 = bp_core_admin_get_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 } }
/** * Verify that some BP prerequisites are set up properly, and notify the admin if not. * * On every Dashboard page, this function checks the following: * - that pretty permalinks are enabled. * - that every BP component that needs a WP page for a directory has one. * - that no WP page has multiple BP components associated with it. * The administrator will be shown a notice for each check that fails. * * @global WPDB $wpdb WordPress DB object * @global WP_Rewrite $wp_rewrite * * @since 1.2.0 */ function bp_core_activation_notice() { global $wp_rewrite, $wpdb; // Only the super admin gets warnings. if (!bp_current_user_can('bp_moderate')) { return; } // Bail in user admin. if (is_user_admin()) { return; } // On multisite installs, don't load on a non-root blog, unless do_network_admin is overridden. if (is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog()) { return; } // Bail if in network admin, and BuddyPress is not network activated. if (is_network_admin() && !bp_is_network_activated()) { return; } /** * Check to make sure that the blog setup routine has run. This can't * happen during the wizard because of the order which the components * are loaded. */ if (bp_is_active('blogs')) { $bp = buddypress(); $count = $wpdb->get_var("SELECT COUNT(*) FROM {$bp->blogs->table_name}"); if (empty($count)) { bp_blogs_record_existing_blogs(); } } // Add notice if no rewrite rules are enabled. if (empty($wp_rewrite->permalink_structure)) { bp_core_add_admin_notice(sprintf(__('<strong>BuddyPress is almost ready</strong>. You must <a href="%s">update your permalink structure</a> to something other than the default for it to work.', 'buddypress'), admin_url('options-permalink.php')), 'error'); } // Get BuddyPress instance. $bp = buddypress(); /** * Check for orphaned BP components (BP component is enabled, no WP page exists). */ $orphaned_components = array(); $wp_page_components = array(); // Only components with 'has_directory' require a WP page to function. foreach (array_keys($bp->loaded_components) as $component_id) { if (!empty($bp->{$component_id}->has_directory)) { $wp_page_components[] = array('id' => $component_id, 'name' => isset($bp->{$component_id}->name) ? $bp->{$component_id}->name : ucwords($bp->{$component_id}->id)); } } // Activate and Register are special cases. They are not components but they need WP pages. // If user registration is disabled, we can skip this step. if (bp_get_signup_allowed()) { $wp_page_components[] = array('id' => 'activate', 'name' => __('Activate', 'buddypress')); $wp_page_components[] = array('id' => 'register', 'name' => __('Register', 'buddypress')); } // On the first admin screen after a new installation, this isn't set, so grab it to suppress // a misleading error message. if (empty($bp->pages->members)) { $bp->pages = bp_core_get_directory_pages(); } foreach ($wp_page_components as $component) { if (!isset($bp->pages->{$component['id']})) { $orphaned_components[] = $component['name']; } } // Special case: If the Forums component is orphaned, but the bbPress 1.x installation is // not correctly set up, don't show a nag. (In these cases, it's probably the case that the // user is using bbPress 2.x; see https://buddypress.trac.wordpress.org/ticket/4292. if (isset($bp->forums->name) && in_array($bp->forums->name, $orphaned_components) && !bp_forums_is_installed_correctly()) { $forum_key = array_search($bp->forums->name, $orphaned_components); unset($orphaned_components[$forum_key]); $orphaned_components = array_values($orphaned_components); } if (!empty($orphaned_components)) { $admin_url = bp_get_admin_url(add_query_arg(array('page' => 'bp-page-settings'), 'admin.php')); $notice = sprintf(__('The following active BuddyPress Components do not have associated WordPress Pages: %2$s. <a href="%1$s">Repair</a>', 'buddypress'), esc_url($admin_url), '<strong>' . implode('</strong>, <strong>', $orphaned_components) . '</strong>'); bp_core_add_admin_notice($notice); } // BP components cannot share a single WP page. Check for duplicate assignments, and post a message if found. $dupe_names = array(); $page_ids = (array) bp_core_get_directory_page_ids(); $dupes = array_diff_assoc($page_ids, array_unique($page_ids)); if (!empty($dupes)) { foreach (array_keys($dupes) as $dupe_component) { $dupe_names[] = $bp->pages->{$dupe_component}->title; } // Make sure that there are no duplicate duplicates :). $dupe_names = array_unique($dupe_names); } // If there are duplicates, post a message about them. if (!empty($dupe_names)) { $admin_url = bp_get_admin_url(add_query_arg(array('page' => 'bp-page-settings'), 'admin.php')); $notice = sprintf(__('Each BuddyPress Component needs its own WordPress page. The following WordPress Pages have more than one component associated with them: %2$s. <a href="%1$s">Repair</a>', 'buddypress'), esc_url($admin_url), '<strong>' . implode('</strong>, <strong>', $dupe_names) . '</strong>'); bp_core_add_admin_notice($notice); } }
/** * 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 = bp_core_admin_get_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 = bp_core_admin_get_static_pages(); if (!empty($static_pages)) { ?> <h3><?php _e('Registration', 'buddypress'); ?> </h3> <?php if (bp_get_signup_allowed()) { ?> <p><?php _e('Associate WordPress Pages with the following BuddyPress Registration pages.', 'buddypress'); ?> </p> <?php } else { ?> <?php if (is_multisite()) { ?> <p><?php printf(__('Registration is currently disabled. Before associating a page is allowed, please enable registration by selecting either the "User accounts may be registered" or "Both sites and user accounts can be registered" option on <a href="%s">this page</a>.', 'buddypress'), network_admin_url('settings.php')); ?> </p> <?php } else { ?> <p><?php printf(__('Registration is currently disabled. Before associating a page is allowed, please enable registration by clicking on the "Anyone can register" checkbox on <a href="%s">this page</a>.', 'buddypress'), admin_url('options-general.php')); ?> </p> <?php } ?> <?php } ?> <table class="form-table"> <tbody> <?php if (bp_get_signup_allowed()) { 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 } }
/** * removes the BuddyDrive directory page from wp header menu * * @param array $args the menu args * @uses buddydrive_get_slug() to get the slug of the BuddyDrive directory page * @uses bp_core_get_directory_page_ids() to get an array of BP Components page ids * @return args $args with a new arg to exclude BuddyDrive page. */ function buddydrive_hide_item($args) { $buddydrive_slug = buddydrive()->buddydrive_slug; $directory_pages = bp_core_get_directory_page_ids(); if (empty($args['exclude'])) { $args['exclude'] = $directory_pages[$buddydrive_slug]; } else { $args['exclude'] .= ',' . $directory_pages[$buddydrive_slug]; } return $args; }
/** * Get the canonical URL of the current page. * * @since 1.6.0 * * @uses apply_filters() Filter bp_get_canonical_url to modify return value. * * @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 or a feed. if (false !== $front_page_component && bp_is_current_component($front_page_component) && !bp_current_action()) { $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); }
/** * 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])); } }
/** * @group BP6244 * @group bp_core_admin_get_active_components_from_submitted_settings */ public function test_bp_core_admin_get_active_components_from_submitted_settings_should_keep_custom_component_directory_page() { $bp = buddypress(); $reset_active_components = $bp->active_components; // Create and activate the foo component $bp->foo = new BP_Component(); $bp->foo->id = 'foo'; $bp->foo->slug = 'foo'; $bp->foo->name = 'Foo'; $bp->active_components[$bp->foo->id] = 1; $new_page_ids = array($bp->foo->id => $this->factory->post->create(array('post_type' => 'page', 'post_title' => $bp->foo->name, 'post_name' => $bp->foo->slug))); $page_ids = array_merge($new_page_ids, (array) bp_core_get_directory_page_ids('all')); bp_core_update_directory_page_ids($page_ids); $bp->active_components = bp_core_admin_get_active_components_from_submitted_settings($reset_active_components); bp_core_add_page_mappings($bp->active_components); $this->assertContains($bp->foo->id, array_keys(bp_core_get_directory_page_ids('all'))); // Reset buddypress() vars $bp->active_components = $reset_active_components; }
/** * Verify that some BP prerequisites are set up properly, and notify the admin if not * * On every Dashboard page, this function checks the following: * - that pretty permalinks are enabled * - that a BP-compatible theme is activated * - that every BP component that needs a WP page for a directory has one * - that no WP page has multiple BP components associated with it * The administrator will be shown a notice for each check that fails. * * @package BuddyPress Core */ function bp_core_activation_notice() { global $wp_rewrite, $wpdb, $bp; // Only the super admin gets warnings if (!bp_current_user_can('bp_moderate')) { return; } // On multisite installs, don't load on a non-root blog, unless do_network_admin is // overridden if (is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog()) { return; } // Don't show these messages during setup or upgrade if (!empty($bp->maintenance_mode)) { return; } /** * Check to make sure that the blog setup routine has run. This can't happen during the * wizard because of the order which the components are loaded. We check for multisite here * on the off chance that someone has activated the blogs component and then disabled MS */ if (bp_is_active('blogs')) { $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$bp->blogs->table_name}")); if (empty($count)) { bp_blogs_record_existing_blogs(); } } /** * Are pretty permalinks enabled? */ if (isset($_POST['permalink_structure'])) { return false; } if (empty($wp_rewrite->permalink_structure)) { bp_core_add_admin_notice(sprintf(__('<strong>BuddyPress is almost ready</strong>. You must <a href="%s">update your permalink structure</a> to something other than the default for it to work.', 'buddypress'), admin_url('options-permalink.php'))); } /** * Are you using a BP-compatible theme? */ // Get current theme info $ct = wp_get_theme(); // Make sure tags is an array to suppress notices if (!isset($ct->tags)) { $ct->tags = array(); } else { $ct->tags = (array) $ct->tags; } // The best way to remove this notice is to add a "buddypress" tag to // your active theme's CSS header. if (!defined('BP_SILENCE_THEME_NOTICE') && !in_array('buddypress', $ct->tags)) { bp_core_add_admin_notice(sprintf(__("You'll need to <a href='%s'>activate a <strong>BuddyPress-compatible theme</strong></a> to take advantage of all of BuddyPress's features. We've bundled a default theme, but you can always <a href='%s'>install some other compatible themes</a> or <a href='%s'>update your existing WordPress theme</a>.", 'buddypress'), admin_url('themes.php'), network_admin_url('theme-install.php?type=tag&s=buddypress&tab=search'), network_admin_url('plugin-install.php?type=term&tab=search&s=%22bp-template-pack%22'))); } /** * Check for orphaned BP components (BP component is enabled, no WP page exists) */ $orphaned_components = array(); $wp_page_components = array(); // Only components with 'has_directory' require a WP page to function foreach ($bp->loaded_components as $component_id => $is_active) { if (!empty($bp->{$component_id}->has_directory)) { $wp_page_components[] = array('id' => $component_id, 'name' => isset($bp->{$component_id}->name) ? $bp->{$component_id}->name : ucwords($bp->{$component_id}->id)); } } // Activate and Register are special cases. They are not components but they need WP pages. // If user registration is disabled, we can skip this step. if (bp_get_signup_allowed()) { $wp_page_components[] = array('id' => 'activate', 'name' => __('Activate', 'buddypress')); $wp_page_components[] = array('id' => 'register', 'name' => __('Register', 'buddypress')); } foreach ($wp_page_components as $component) { if (!isset($bp->pages->{$component['id']})) { $orphaned_components[] = $component['name']; } } // Special case: If the Forums component is orphaned, but the bbPress 1.x installation is // not correctly set up, don't show a nag. (In these cases, it's probably the case that the // user is using bbPress 2.x; see https://buddypress.trac.wordpress.org/ticket/4292 if (isset($bp->forums->name) && in_array($bp->forums->name, $orphaned_components) && !bp_forums_is_installed_correctly()) { $forum_key = array_search($bp->forums->name, $orphaned_components); unset($orphaned_components[$forum_key]); $orphaned_components = array_values($orphaned_components); } if (!empty($orphaned_components)) { $admin_url = bp_get_admin_url(add_query_arg(array('page' => 'bp-page-settings'), 'admin.php')); $notice = sprintf(__('The following active BuddyPress Components do not have associated WordPress Pages: %2$s. <a href="%1$s" class="button-secondary">Repair</a>', 'buddypress'), $admin_url, '<strong>' . implode('</strong>, <strong>', $orphaned_components) . '</strong>'); bp_core_add_admin_notice($notice); } /** * BP components cannot share a single WP page. Check for duplicate assignments, and post * a message if found. */ $dupe_names = array(); $page_ids = (array) bp_core_get_directory_page_ids(); $dupes = array_diff_assoc($page_ids, array_unique($page_ids)); if (!empty($dupes)) { foreach ($dupes as $dupe_component => $dupe_id) { $dupe_names[] = $bp->pages->{$dupe_component}->title; } // Make sure that there are no duplicate duplicates :) $dupe_names = array_unique($dupe_names); } // If there are duplicates, post a message about them if (!empty($dupe_names)) { $admin_url = bp_get_admin_url(add_query_arg(array('page' => 'bp-page-settings'), 'admin.php')); $notice = sprintf(__('Each BuddyPress Component needs its own WordPress page. The following WordPress Pages have more than one component associated with them: %2$s. <a href="%1$s" class="button-secondary">Repair</a>', 'buddypress'), $admin_url, '<strong>' . implode('</strong>, <strong>', $dupe_names) . '</strong>'); bp_core_add_admin_notice($notice); } }
/** * Create fake "post" objects for BP's logged-out nav menu for use in the WordPress "Menus" settings page. * * WordPress nav menus work by representing post or tax term data as a custom * post type, which is then used to populate the checkboxes that appear on * Dashboard > Appearance > Menu as well as the menu as rendered on the front * end. Most of the items in the BuddyPress set of nav items are neither posts * nor tax terms, so we fake a post-like object so as to be compatible with the * menu. * * @since BuddyPress (1.9.0) * * @return mixed A URL or an array of dummy pages. */ function bp_nav_menu_get_loggedout_pages() { // Try to catch the cached version first if (!empty(buddypress()->wp_nav_menu_items->loggedout)) { return buddypress()->wp_nav_menu_items->loggedout; } $bp_menu_items = array(); // Some BP nav menu items will not be represented in bp_nav, because // they are not real BP components. We add them manually here. $bp_menu_items[] = array('name' => __('Log In', 'buddypress'), 'slug' => 'login', 'link' => wp_login_url()); // The Register page will not always be available (ie, when // registration is disabled) $bp_directory_page_ids = bp_core_get_directory_page_ids(); if (!empty($bp_directory_page_ids['register'])) { $register_page = get_post($bp_directory_page_ids['register']); $bp_menu_items[] = array('name' => $register_page->post_title, 'slug' => 'register', 'link' => get_permalink($register_page->ID)); } // If there's nothing to show, we're done if (count($bp_menu_items) < 1) { return false; } $page_args = array(); foreach ($bp_menu_items as $bp_item) { $page_args[$bp_item['slug']] = (object) array('ID' => -1, 'post_title' => $bp_item['name'], 'post_author' => 0, 'post_date' => 0, 'post_excerpt' => $bp_item['slug'], 'post_type' => 'page', 'post_status' => 'publish', 'comment_status' => 'closed', 'guid' => $bp_item['link']); } if (empty(buddypress()->wp_nav_menu_items)) { buddypress()->wp_nav_menu_items = new stdClass(); } buddypress()->wp_nav_menu_items->loggedout = $page_args; return $page_args; }
function bps_attributes($post) { $options = bps_meta($post->ID); ?> <p><strong><?php _e('Form Method', 'bps'); ?> </strong></p> <label class="screen-reader-text" for="method"><?php _e('Form Method', 'bps'); ?> </label> <select name="options[method]" id="method"> <option value='POST' <?php selected($options['method'], 'POST'); ?> ><?php _e('POST', 'bps'); ?> </option> <option value='GET' <?php selected($options['method'], 'GET'); ?> ><?php _e('GET', 'bps'); ?> </option> </select> <p><strong><?php _e('Form Action (Results Directory)', 'bps'); ?> </strong></p> <label class="screen-reader-text" for="action"><?php _e('Form Action (Results Directory)', 'bps'); ?> </label> <?php $bp_pages = array(); $default = 0; if (function_exists('bp_core_get_directory_page_ids')) { $bp_pages = bp_core_get_directory_page_ids(); $default = $bp_pages['members']; unset($bp_pages['members']); } $selected = $options['action'] ? $options['action'] : $default; $args = array('name' => 'options[action]', 'id' => 'action', 'selected' => $selected, 'exclude' => $bp_pages); wp_dropdown_pages($args); ?> <p><?php _e('Need help? Use the Help tab in the upper right of your screen.'); ?> </p> <?php }
/** * 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 } }
function M_KeepBuddyPressPages($pages) { $existing_pages = bp_core_get_directory_page_ids(); if (!empty($existing_pages)) { $pages = array_merge($pages, $existing_pages); } return $pages; }