Example #1
0
 function test_bp_core_ajax_url()
 {
     $forced = force_ssl_admin();
     // (1) HTTPS off
     force_ssl_admin(false);
     $_SERVER['HTTPS'] = 'off';
     // (1a) Front-end
     $this->go_to('/');
     $this->assertEquals(bp_core_ajax_url(), get_site_url(bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'http'));
     // (1b) Dashboard
     $this->go_to('/wp-admin');
     $this->assertEquals(bp_core_ajax_url(), get_site_url(bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'http'));
     // (2) FORCE_SSL_ADMIN
     force_ssl_admin(true);
     // (2a) Front-end
     $this->go_to('/');
     $this->assertEquals(bp_core_ajax_url(), get_site_url(bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'http'));
     // (2b) Dashboard
     $this->go_to('/wp-admin');
     $this->assertEquals(bp_core_ajax_url(), get_site_url(bp_get_root_blog_id(), '/wp-admin/admin-ajax.php', 'https'));
     force_ssl_admin($forced);
     // (3) Multisite, root blog other than 1
     if (is_multisite()) {
         $original_root_blog = bp_get_root_blog_id();
         $blog_id = $this->factory->blog->create(array('path' => '/path' . rand() . time() . '/'));
         buddypress()->root_blog_id = $blog_id;
         $blog_url = get_blog_option($blog_id, 'siteurl');
         $this->go_to(trailingslashit($blog_url));
         buddypress()->root_blog_id = $original_root_blog;
         $ajax_url = bp_core_ajax_url();
         $this->go_to('/');
         $this->assertEquals($blog_url . '/wp-admin/admin-ajax.php', $ajax_url);
     }
 }
function friends_notification_accepted_request($friendship_id, $initiator_id, $friend_id)
{
    global $bp;
    $friendship = new BP_Friends_Friendship($friendship_id, false, false);
    $friend_name = bp_core_get_user_displayname($friend_id);
    if ('no' == bp_get_user_meta((int) $initiator_id, 'notification_friends_friendship_accepted', true)) {
        return false;
    }
    $ud = get_userdata($initiator_id);
    $friend_link = bp_core_get_user_domain($friend_id);
    $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
    $settings_link = bp_core_get_user_domain($initiator_id) . $settings_slug . '/notifications';
    // Set up and send the message
    $to = $ud->user_email;
    $sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
    $subject = '[' . $sitename . '] ' . sprintf(__('%s accepted your friendship request', 'buddypress'), $friend_name);
    $message = sprintf(__('%1$s accepted your friend request.

To view %2$s\'s profile: %3$s

---------------------
', 'buddypress'), $friend_name, $friend_name, $friend_link);
    $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
    /* Send the message */
    $to = apply_filters('friends_notification_accepted_request_to', $to);
    $subject = apply_filters('friends_notification_accepted_request_subject', $subject, $friend_name);
    $message = apply_filters('friends_notification_accepted_request_message', $message, $friend_name, $friend_link, $settings_link);
    nxt_mail($to, $subject, $message);
    do_action('bp_friends_sent_accepted_email', $initiator_id, $subject, $message, $friendship_id, $friend_id);
}
function bp_adminbar_authors_menu()
{
    global $bp, $nxtdb;
    // Only for multisite
    if (!is_multisite()) {
        return false;
    }
    // Hide on root blog
    if ($nxtdb->blogid == bp_get_root_blog_id() || !bp_is_active('blogs')) {
        return false;
    }
    $blog_prefix = $nxtdb->get_blog_prefix($nxtdb->blogid);
    $authors = $nxtdb->get_results("SELECT user_id, user_login, user_nicename, display_name, user_email, meta_value as caps FROM {$nxtdb->users} u, {$nxtdb->usermeta} um WHERE u.ID = um.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY um.user_id");
    if (!empty($authors)) {
        // This is a blog, render a menu with links to all authors
        echo '<li id="bp-adminbar-authors-menu"><a href="/">';
        _e('Blog Authors', 'buddypress');
        echo '</a>';
        echo '<ul class="author-list">';
        foreach ((array) $authors as $author) {
            $caps = maybe_unserialize($author->caps);
            if (isset($caps['subscriber']) || isset($caps['contributor'])) {
                continue;
            }
            echo '<li>';
            echo '<a href="' . bp_core_get_user_domain($author->user_id, $author->user_nicename, $author->user_login) . '">';
            echo bp_core_fetch_avatar(array('item_id' => $author->user_id, 'email' => $author->user_email, 'width' => 15, 'height' => 15));
            echo ' ' . $author->display_name . '</a>';
            echo '<div class="admin-bar-clear"></div>';
            echo '</li>';
        }
        echo '</ul>';
        echo '</li>';
    }
}
function bp_blogs_register_widgets()
{
    global $wpdb;
    if (bp_is_active('activity') && (int) $wpdb->blogid == bp_get_root_blog_id()) {
        add_action('widgets_init', create_function('', 'return register_widget("BP_Blogs_Recent_Posts_Widget");'));
    }
}
/**
 * bp_core_allow_default_theme()
 *
 * On multiblog installations you must first allow themes to be activated and show
 * up on the theme selection screen. This function will let the BuddyPress bundled
 * themes show up on the root blog selection screen and bypass this step. It also
 * means that the themes won't show for selection on other blogs.
 *
 * @package BuddyPress Core
 */
function bp_core_allow_default_theme($themes)
{
    global $wpdb;
    if (!bp_current_user_can('bp_moderate')) {
        return $themes;
    }
    if ($wpdb->blogid == bp_get_root_blog_id()) {
        $themes['bp-default'] = 1;
    }
    return $themes;
}
/**
 * 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;
}
Example #7
0
function thatcamp_blogs_register_widgets()
{
    global $wpdb;
    if (bp_is_active('activity') && bp_is_active('blogs') && class_exists('BP_Blogs_Recent_Posts_Widget') && (int) $wpdb->blogid == bp_get_root_blog_id()) {
        include __DIR__ . '/includes/posts-widget.php';
        add_action('widgets_init', create_function('', 'unregister_widget( "BP_Blogs_Recent_Posts_Widget" ); return register_widget("THATCamp_Blogs_Recent_Posts_Widget");'));
    }
    if (bp_is_active('groups') && (int) $wpdb->blogid == bp_get_root_blog_id()) {
        include __DIR__ . '/includes/groups-widget.php';
        add_action('widgets_init', create_function('', 'unregister_widget( "BP_Groups_Widget" ); return register_widget("THATCamp_Groups_Widget");'));
    }
}
/**
 * Gets the ID of the site that BP should use for taxonomy term storage.
 *
 * Defaults to the root blog ID.
 *
 * @since 2.6.0
 *
 * @param string $taxonomy Taxonomy slug to check for.
 * @return int
 */
function bp_get_taxonomy_term_site_id($taxonomy = '')
{
    $site_id = bp_get_root_blog_id();
    /**
     * Filters the ID of the site where BP should store taxonomy terms.
     *
     * @since 2.6.0
     *
     * @param int    $site_id  Site ID to cehck for.
     * @param string $taxonomy Taxonomy slug to check for.
     */
    return (int) apply_filters('bp_get_taxonomy_term_site_id', $site_id, $taxonomy);
}
 /**
  * Constructor method
  *
  * @package Rendez_Vous
  * @subpackage Component
  *
  * @since Rendez Vous (1.0.0)
  */
 function __construct()
 {
     $bp = buddypress();
     parent::start('rendez_vous', rendez_vous()->get_component_name(), rendez_vous()->includes_dir);
     $this->includes();
     $bp->active_components[$this->id] = '1';
     /**
      * Only register the post type on the blog where BuddyPress is activated.
      */
     if (get_current_blog_id() == bp_get_root_blog_id()) {
         add_action('init', array(&$this, 'register_post_types'));
     }
 }
 /**
  * set some actions
  *
  *
  * @package BuddyDrive
  * @since 1.2.0
  */
 private function actions()
 {
     buddypress()->active_components[$this->id] = '1';
     /**
      * Register the BuddyDrive custom post types
      */
     if (get_current_blog_id() == bp_get_root_blog_id()) {
         add_action('init', array(&$this, 'register_post_types'), 9);
         // Register the BuddyDrive upload dir
         add_action('bp_init', array($this, 'register_upload_dir'));
     }
     // register the embed handler
     add_action('bp_init', array($this, 'register_embed_code'), 4);
 }
Example #11
0
/**
 * On multiblog installations you must first allow themes to be activated and
 * show up on the theme selection screen. This function will let the BuddyPress
 * bundled themes show up on the root blog selection screen and bypass this
 * step. It also means that the themes won't show for selection on other blogs.
 *
 * @deprecated BuddyPress (1.7)
 * @package BuddyPress Core
 */
function bp_core_allow_default_theme($themes)
{
    _deprecated_function(__FUNCTION__, '1.7');
    if (!bp_current_user_can('bp_moderate')) {
        return $themes;
    }
    if (bp_get_root_blog_id() != get_current_blog_id()) {
        return $themes;
    }
    if (isset($themes['bp-default'])) {
        return $themes;
    }
    $themes['bp-default'] = true;
    return $themes;
}
Example #12
0
 /**
  * @ticket BP6501
  */
 public function test_bp_current_user_can_should_respect_blog_id_passed_in_args_array()
 {
     if (!is_multisite()) {
         $this->markTestSkipped(__METHOD__ . ' requires multisite.');
     }
     $b = $this->factory->blog->create();
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     add_filter('user_has_cap', array($this, 'grant_cap_foo'), 10, 2);
     $can = bp_current_user_can('foo', array('blog_id' => bp_get_root_blog_id()));
     $cant = bp_current_user_can('foo', array('blog_id' => $b));
     remove_filter('user_has_cap', array($this, 'grant_cap_foo'), 10, 2);
     $this->assertTrue($can);
     $this->assertFalse($cant);
 }
Example #13
0
function bp_forums_bbpress_install($location = '')
{
    global $wpdb, $bbdb;
    check_admin_referer('bp_forums_new_install_init');
    if (empty($location)) {
        $location = ABSPATH . 'bb-config.php';
    }
    $bp = buddypress();
    // Create the bb-config.php file.
    $initial_write = bp_forums_bbpress_write($bp->plugin_dir . '/bp-forums/bbpress/bb-config-sample.php', $location, array("define( 'BBDB_NAME'," => array("'bbpress'", "'" . DB_NAME . "'"), "define( 'BBDB_USER'," => array("'username'", "'" . DB_USER . "'"), "define( 'BBDB_PASSWO" => array("'password'", "'" . DB_PASSWORD . "'"), "define( 'BBDB_HOST'," => array("'localhost'", "'" . DB_HOST . "'"), "define( 'BBDB_CHARSE" => array("'utf8'", "'" . DB_CHARSET . "'"), "define( 'BBDB_COLLAT" => array("''", "'" . DB_COLLATE . "'"), "define( 'BB_AUTH_KEY" => array("'put your unique phrase here'", "'" . addslashes(AUTH_KEY) . "'"), "define( 'BB_SECURE_A" => array("'put your unique phrase here'", "'" . addslashes(SECURE_AUTH_KEY) . "'"), "define( 'BB_LOGGED_I" => array("'put your unique phrase here'", "'" . addslashes(LOGGED_IN_KEY) . "'"), "define( 'BB_NONCE_KE" => array("'put your unique phrase here'", "'" . addslashes(NONCE_KEY) . "'"), "\$bb_table_prefix = '" => array("'bb_'", "'" . $bp->table_prefix . "bb_'"), "define( 'BB_LANG', '" => array("''", "'" . get_locale() . "'")));
    // Add the custom user and usermeta entries to the config file.
    if ($initial_write == 1) {
        $file = file_get_contents($location);
    } else {
        $file =& $initial_write;
    }
    $file = trim($file);
    if ('?>' == substr($file, -2, 2)) {
        $file = substr($file, 0, -2);
    }
    $file .= "\n" . '$bb->custom_user_table = \'' . $wpdb->users . '\';';
    $file .= "\n" . '$bb->custom_user_meta_table = \'' . $wpdb->usermeta . '\';';
    $file .= "\n\n" . '$bb->uri = \'' . $bp->plugin_url . '/bp-forums/bbpress/\';';
    $file .= "\n" . '$bb->name = \'' . get_blog_option(bp_get_root_blog_id(), 'blogname') . ' ' . __('Forums', 'buddypress') . '\';';
    if (is_multisite()) {
        $file .= "\n" . '$bb->wordpress_mu_primary_blog_id = ' . bp_get_root_blog_id() . ';';
    }
    if (defined('AUTH_SALT')) {
        $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', \'' . addslashes(AUTH_SALT) . '\');';
    }
    if (defined('LOGGED_IN_SALT')) {
        $file .= "\n" . 'define(\'BB_LOGGED_IN_SALT\', \'' . addslashes(LOGGED_IN_SALT) . '\');';
    }
    if (defined('SECURE_AUTH_SALT')) {
        $file .= "\n" . 'define(\'BB_SECURE_AUTH_SALT\', \'' . addslashes(SECURE_AUTH_SALT) . '\');';
    }
    $file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);';
    $file .= "\n\n" . '?>';
    if ($initial_write == 1) {
        $file_handle = fopen($location, 'w');
        fwrite($file_handle, $file);
        fclose($file_handle);
    } else {
        $initial_write = $file;
    }
    bp_update_option('bb-config-location', $location);
    return $initial_write;
}
function messages_notification_new_message($args = array())
{
    // These should be extracted below
    $recipients = array();
    $email_subject = $email_content = '';
    extract($args);
    $sender_name = bp_core_get_user_displayname($sender_id);
    // Bail if no recipients
    if (!empty($recipients)) {
        foreach ($recipients as $recipient) {
            if ($sender_id == $recipient->user_id || 'no' == bp_get_user_meta($recipient->user_id, 'notification_messages_new_message', true)) {
                continue;
            }
            // User data and links
            $ud = get_userdata($recipient->user_id);
            $message_link = bp_core_get_user_domain($recipient->user_id) . bp_get_messages_slug() . '/';
            $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
            $settings_link = bp_core_get_user_domain($recipient->user_id) . $settings_slug . '/notifications/';
            // Sender info
            $sender_name = stripslashes($sender_name);
            $subject = stripslashes(wp_filter_kses($subject));
            $content = stripslashes(wp_filter_kses($content));
            // Set up and send the message
            $email_to = $ud->user_email;
            $sitename = wp_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
            $email_subject = '[' . $sitename . '] ' . sprintf(__('New message from %s', 'buddypress'), $sender_name);
            $email_content = sprintf(__('%1$s sent you a new message:

Subject: %2$s

"%3$s"

To view and read your messages please log in and visit: %4$s

---------------------
', 'buddypress'), $sender_name, $subject, $content, $message_link);
            $email_content .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
            // Send the message
            $email_to = apply_filters('messages_notification_new_message_to', $email_to);
            $email_subject = apply_filters('messages_notification_new_message_subject', $email_subject, $sender_name);
            $email_content = apply_filters('messages_notification_new_message_message', $email_content, $sender_name, $subject, $content, $message_link, $settings_link);
            wp_mail($email_to, $email_subject, $email_content);
        }
    }
    do_action('bp_messages_sent_notification_email', $recipients, $email_subject, $email_content, $args);
}
/**
 * Add a menu for the root site of this BuddyPress network
 *
 * @global type $nxt_admin_bar
 * @return If in ajax
 */
function bp_admin_bar_root_site()
{
    global $nxt_admin_bar;
    // Create the root blog menu
    $nxt_admin_bar->add_menu(array('id' => 'bp-root-blog', 'title' => get_blog_option(bp_get_root_blog_id(), 'blogname'), 'href' => bp_get_root_domain()));
    // Logged in user
    if (is_user_logged_in()) {
        // Dashboard links
        if (is_super_admin()) {
            // Add site admin link
            $nxt_admin_bar->add_menu(array('id' => 'dashboard', 'parent' => 'bp-root-blog', 'title' => __('Admin Dashboard', 'buddypress'), 'href' => get_admin_url(bp_get_root_blog_id())));
            // Add network admin link
            if (is_multisite()) {
                // Link to the network admin dashboard
                $nxt_admin_bar->add_menu(array('id' => 'network-dashboard', 'parent' => 'bp-root-blog', 'title' => __('Network Dashboard', 'buddypress'), 'href' => network_admin_url()));
            }
        }
    }
}
 /**
  * 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();
     }
 }
function bp_core_confirmation_js()
{
    global $nxtdb;
    if (is_multisite() && $nxtdb->blogid != bp_get_root_blog_id()) {
        return false;
    }
    if (!nxt_script_is('jquery')) {
        nxt_enqueue_script('jquery');
    }
    if (!nxt_script_is('jquery', 'done')) {
        nxt_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 
}
/**
 * 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 
    }
}
<?php

/**
 * Radio-box selection with descriptions template. 
 * 
 * Copy this file into your theme directory and edit away!
 * You can also use $templates array to iterate through your templates.
 */
if (defined('BP_VERSION') && 'bp-default' == get_blog_option(bp_get_root_blog_id(), 'stylesheet')) {
    echo '<br style="clear:both" />';
}
?>
<div id="blog_template-selection">
	<div class="blog_template-option">
		<label for="blog_template"><?php 
_e('Select a template', 'blog_templates');
?>
</label>
	<?php 
foreach ($templates as $tkey => $template) {
    ?>
		<label for="blog_template-<?php 
    echo $tkey;
    ?>
">
			<input type="radio" id="blog_template-<?php 
    echo $tkey;
    ?>
" name="blog_template" value="<?php 
    echo $tkey;
    ?>
Example #20
0
/**
 * Whether current user has a capability or role. Can be passed blog ID, or will
 * use the root blod by default
 *
 * @since BuddyPress (1.6)
 *
 * @param string $capability Capability or role name.
 * @param int $blog_id Blog ID
 * @return bool
 */
function bp_current_user_can($capability, $blog_id = 0)
{
    // Use root blog if no ID passed
    if (empty($blog_id)) {
        $blog_id = bp_get_root_blog_id();
    }
    $retval = current_user_can_for_blog($blog_id, $capability);
    return (bool) apply_filters('bp_current_user_can', $retval, $capability, $blog_id);
}
 /**
  * @see restore_current_blog()
  */
 function restore_current_blog()
 {
     return bp_get_root_blog_id();
 }
/**
 * Is this the root blog?
 *
 * @since BuddyPress (1.5.0)
 *
 * @param int $blog_id Optional. Default: the ID of the current blog.
 * @return bool $is_root_blog Returns true if this is bp_get_root_blog_id().
 */
function bp_is_root_blog($blog_id = 0)
{
    // Assume false
    $is_root_blog = false;
    // Use current blog if no ID is passed
    if (empty($blog_id)) {
        $blog_id = get_current_blog_id();
    }
    // Compare to root blog ID
    if ($blog_id == bp_get_root_blog_id()) {
        $is_root_blog = true;
    }
    return (bool) apply_filters('bp_is_root_blog', (bool) $is_root_blog);
}
 function step_theme_save()
 {
     if (isset($_POST['submit']) && isset($_POST['theme'])) {
         check_admin_referer('bpwizard_theme');
         if (is_multisite() && bp_get_root_blog_id() != get_current_blog_id()) {
             switch_to_blog(bp_get_root_blog_id());
         }
         switch ($_POST['theme']) {
             // Activate the bp-default theme
             case 'bp_default':
                 switch_theme('bp-default', 'bp-default');
                 break;
                 // Activate Template Pack plugin
             // Activate Template Pack plugin
             case 'manual_nxt':
                 // Include
                 require_once ABSPATH . nxtINC . '/plugin.php';
                 $installed_plugins = get_plugins();
                 foreach ($installed_plugins as $key => $plugin) {
                     if ('BuddyPress Template Pack' == $plugin['Name']) {
                         activate_plugin($key);
                     }
                 }
                 break;
                 // Pick a theme from the repo
             // Pick a theme from the repo
             case '3rd_party':
                 if (empty($_POST['3rd_party_theme'])) {
                     return false;
                 }
                 $theme = explode(',', $_POST['3rd_party_theme']);
                 switch_theme($theme[0], $theme[1]);
                 break;
                 // Keep existing theme
             // Keep existing theme
             case 'do_not_change':
                 return true;
                 break;
         }
         if (is_multisite()) {
             restore_current_blog();
         }
         return true;
     }
     return false;
 }
Example #24
0
function bp_forums_bbpress_install_wizard()
{
    $post_url = bp_get_admin_url('admin.php?page=bb-forums-setup');
    $bbpress_plugin_is_active = false;
    $step = isset($_REQUEST['step']) ? $_REQUEST['step'] : '';
    // The text and URL of the Site Wide Forums button differs depending on whether bbPress
    // is running
    if (is_plugin_active('bbpress/bbpress.php')) {
        $bbpress_plugin_is_active = true;
        // The bbPress admin page will always be on the root blog. switch_to_blog() will
        // pass through if we're already there.
        switch_to_blog(bp_get_root_blog_id());
        $button_url = admin_url(add_query_arg(array('page' => 'bbpress'), 'options-general.php'));
        restore_current_blog();
        $button_text = __('Configure bbPress', 'buddypress');
    } else {
        $button_url = bp_get_admin_url(add_query_arg(array('tab' => 'plugin-information', 'plugin' => 'bbpress', 'TB_iframe' => 'true', 'width' => '640', 'height' => '500'), 'plugin-install.php'));
        $button_text = __('Install bbPress', 'buddypress');
    }
    switch ($step) {
        case 'existing':
            if (isset($_REQUEST['doinstall']) && 1 == (int) $_REQUEST['doinstall']) {
                if (!bp_forums_configure_existing_install()) {
                    _e('The bb-config.php file was not found at that location, please try again.', 'buddypress');
                } else {
                    ?>
					<h3><?php 
                    _e('Forums were set up correctly using your existing bbPress install!', 'buddypress');
                    ?>
</h3>
					<p><?php 
                    _e('BuddyPress will now use its internal copy of bbPress to run the forums on your site. If you wish, you can remove your old bbPress installation files, as long as you keep the bb-config.php file in the same location.', 'buddypress');
                    ?>
</p><?php 
                }
            } else {
                ?>

					<form action="" method="post">
						<h3><?php 
                _e('Existing bbPress Installation', 'buddypress');
                ?>
</h3>
						<p><?php 
                _e("BuddyPress can make use of your existing bbPress install. Just provide the location of your <code>bb-config.php</code> file, and BuddyPress will do the rest.", 'buddypress');
                ?>
</p>
						<p><label><code>bb-config.php</code> file location:</label><br /><input style="width: 50%" type="text" name="bbconfigloc" id="bbconfigloc" value="<?php 
                echo str_replace('buddypress', '', $_SERVER['DOCUMENT_ROOT']);
                ?>
" /></p>
						<p><input type="submit" class="button-primary" value="<?php 
                _e('Complete Installation', 'buddypress');
                ?>
" /></p>
						<input type="hidden" name="step" value="existing" />
						<input type="hidden" name="doinstall" value="1" />
						<?php 
                wp_nonce_field('bp_forums_existing_install_init');
                ?>
					</form>

				<?php 
            }
            break;
        case 'new':
            if (isset($_REQUEST['doinstall']) && 1 == (int) $_REQUEST['doinstall']) {
                $result = bp_forums_bbpress_install();
                switch ($result) {
                    case 1:
                        _e('<p>All done! Configuration settings have been saved to the file <code>bb-config.php</code> in the root of your WordPress install.</p>', 'buddypress');
                        break;
                    default:
                        // Just write the contents to screen
                        _e('<p>A configuration file could not be created. No problem, but you will need to save the text shown below into a file named <code>bb-config.php</code> in the root directory of your WordPress installation before you can start using the forum functionality.</p>', 'buddypress');
                        ?>

						<textarea style="display:block; margin-top: 30px; width: 80%;" rows="50"><?php 
                        echo htmlspecialchars($result);
                        ?>
</textarea>

					<?php 
                        break;
                }
            } else {
                ?>

				<h3><?php 
                _e('New bbPress Installation', 'buddypress');
                ?>
</h3>
				<p><?php 
                _e("You've decided to set up a new installation of bbPress for forum management in BuddyPress. This is very simple and is usually just a one click\n\t\t\t\tprocess. When you're ready, hit the link below.", 'buddypress');
                ?>
</p>
				<p><a class="button-primary" href="<?php 
                echo wp_nonce_url($post_url . '&step=new&doinstall=1', 'bp_forums_new_install_init');
                ?>
"><?php 
                _e('Complete Installation', 'buddypress');
                ?>
</a></p>

				<?php 
            }
            break;
        default:
            if (!file_exists(BP_PLUGIN_DIR . '/bp-forums/bbpress/')) {
                ?>

				<div id="message" class="error">
					<p><?php 
                printf(__('bbPress files were not found. To install the forums component you must download a copy of bbPress and make sure it is in the folder: "%s"', 'buddypress'), 'wp-content/plugins/buddypress/bp-forums/bbpress/');
                ?>
</p>
				</div>

			<?php 
            } else {
                // Include the plugin install
                add_thickbox();
                wp_enqueue_script('plugin-install');
                wp_admin_css('plugin-install');
                ?>

				<div style="width: 45%; float: left;  margin-top: 20px;">
					<h3><?php 
                _e('Forums for Groups', 'buddypress');
                ?>
</h3>

					<p><?php 
                _e('Give each individual group its own discussion forum. Choose this if you\'d like to keep your members\' conversations separated into distinct areas.', 'buddypress');
                ?>
</p>

					<p><?php 
                _e('Note: This component is retired and will not be receiving any updates in the future.  Only use this component if your current site relies on it.', 'buddypress');
                ?>
</p>

					<h4 style="margin-bottom: 10px;"><?php 
                _e('Features', 'buddypress');
                ?>
</h4>
					<ul class="description" style="list-style: square; margin-left: 30px;">
						<li><?php 
                _e('Group Integration', 'buddypress');
                ?>
</p></li>
						<li><?php 
                _e('Member Profile Integration', 'buddypress');
                ?>
</p></li>
						<li><?php 
                _e('Activity Stream Integration', 'buddypress');
                ?>
</p></li>
						<li><?php 
                _e('@ Mention Integration', 'buddypress');
                ?>
</p></li>
					</ul>

					<div>
						<a class="button button-primary" href="<?php 
                echo $post_url . '&step=new';
                ?>
"><?php 
                _e('Install Group Forums', 'buddypress');
                ?>
</a> &nbsp;
						<a class="button" href="<?php 
                echo $post_url . '&step=existing';
                ?>
"><?php 
                _e('Use Existing Installation', 'buddypress');
                ?>
</a>
					</div>
				</div>

				<div style="width: 45%; float: left; margin: 20px 0 20px 20px; padding: 0 20px 20px 20px; border: 1px solid #ddd; background-color: #fff;">
					<h3><?php 
                _e('New! bbPress', 'buddypress');
                ?>
</h3>
					<p><?php 
                _e('bbPress is a brand-new forum plugin from one of the lead developers of BuddyPress.', 'buddypress');
                ?>
</p>

					<p><?php 
                _e('It boasts a bunch of cool features that the BP Legacy Discussion Forums does not have including:', 'buddypress');
                ?>
</p>

					<ul class="description" style="list-style: square; margin-left: 30px;">
						<li><?php 
                _e('Non-group specific forum creation', 'buddypress');
                ?>
</p></li>
						<li><?php 
                _e('Moderation via the WP admin dashboard', 'buddypress');
                ?>
</p></li>
						<li><?php 
                _e('Topic splitting', 'buddypress');
                ?>
</p></li>
						<li><?php 
                _e('Revisions', 'buddypress');
                ?>
</p></li>
						<li><?php 
                _e('Spam management', 'buddypress');
                ?>
</p></li>
						<li><?php 
                _e('Subscriptions', 'buddypress');
                ?>
</p></li>
						<li><?php 
                _e('And more!', 'buddypress');
                ?>
</p></li>
					</ul>

					<p><?php 
                printf(__('If you decide to use bbPress, you will need to deactivate the legacy group forum component.  For more info, <a href="%s">read this codex article</a>.', 'buddypress'), 'http://codex.buddypress.org/user/setting-up-a-new-installation/installing-group-and-sitewide-forums/using-bbpress-2-2-with-buddypress/');
                ?>
</p>
					<div>
						<a class="button button-primary <?php 
                if (!$bbpress_plugin_is_active) {
                    echo esc_attr('thickbox');
                }
                ?>
" href="<?php 
                echo esc_attr($button_url);
                ?>
"><?php 
                echo esc_html($button_text);
                ?>
</a> &nbsp;
					</div>
				</div>

			<?php 
            }
            break;
    }
}
Example #25
0
/**
 * Fetch data from the BP root blog's upload directory.
 *
 * Handy for multisite instances because all uploads are made on the BP root
 * blog and we need to query the BP root blog for the upload directory data.
 *
 * This function ensures that we only need to use {@link switch_to_blog()}
 * once to get what we need.
 *
 * @since BuddyPress (1.8.0)
 *
 * @uses wp_upload_dir()
 *
 * @param string $type The variable we want to return from the $bp->avatars
 *        object. Only 'upload_path' and 'url' are supported. Default: 'upload_path'.
 * @return string The avatar upload directory path.
 */
function bp_core_get_upload_dir($type = 'upload_path')
{
    $bp = buddypress();
    switch ($type) {
        case 'upload_path':
            $constant = 'BP_AVATAR_UPLOAD_PATH';
            $key = 'basedir';
            break;
        case 'url':
            $constant = 'BP_AVATAR_URL';
            $key = 'baseurl';
            break;
        default:
            return false;
            break;
    }
    // See if the value has already been calculated and stashed in the $bp global
    if (isset($bp->avatar->{$type})) {
        $retval = $bp->avatar->{$type};
    } else {
        // If this value has been set in a constant, just use that
        if (defined($constant)) {
            $retval = constant($constant);
        } else {
            // Use cached upload dir data if available
            if (!empty($bp->avatar->upload_dir)) {
                $upload_dir = $bp->avatar->upload_dir;
                // No cache, so query for it
            } else {
                // We need to switch to the root blog on multisite installs
                if (is_multisite()) {
                    switch_to_blog(bp_get_root_blog_id());
                }
                // Get upload directory information from current site
                $upload_dir = wp_upload_dir();
                // Will bail if not switched
                restore_current_blog();
                // Stash upload directory data for later use
                $bp->avatar->upload_dir = $upload_dir;
            }
            // Directory does not exist and cannot be created
            if (!empty($upload_dir['error'])) {
                $retval = '';
            } else {
                $retval = $upload_dir[$key];
                // If $key is 'baseurl', check to see if we're on SSL
                // Workaround for WP13941, WP15928, WP19037.
                if ($key == 'baseurl' && is_ssl()) {
                    $retval = str_replace('http://', 'https://', $retval);
                }
            }
        }
        // Stash in $bp for later use
        $bp->avatar->{$type} = $retval;
    }
    return $retval;
}
Example #26
0
/**
 * Fetch global BP options.
 *
 * BuddyPress uses common options to store configuration settings. Many of these
 * settings are needed at run time. Instead of fetching them all and adding many
 * initial queries to each page load, let's fetch them all in one go.
 *
 * @todo Use settings API and audit these methods.
 *
 * @return array $root_blog_options_meta List of options.
 */
function bp_core_get_root_options()
{
    global $wpdb;
    // Get all the BuddyPress settings, and a few useful WP ones too
    $root_blog_options = bp_get_default_options();
    $root_blog_options['registration'] = '0';
    $root_blog_options['avatar_default'] = 'mysteryman';
    $root_blog_option_keys = array_keys($root_blog_options);
    // Do some magic to get all the root blog options in 1 swoop
    // Check cache first - We cache here instead of using the standard WP
    // settings cache because the current blog may not be the root blog,
    // and it's not practical to access the cache across blogs
    $root_blog_options_meta = wp_cache_get('root_blog_options', 'bp');
    if (false === $root_blog_options_meta) {
        $blog_options_keys = "'" . join("', '", (array) $root_blog_option_keys) . "'";
        $blog_options_table = bp_is_multiblog_mode() ? $wpdb->options : $wpdb->get_blog_prefix(bp_get_root_blog_id()) . 'options';
        $blog_options_query = "SELECT option_name AS name, option_value AS value FROM {$blog_options_table} WHERE option_name IN ( {$blog_options_keys} )";
        $root_blog_options_meta = $wpdb->get_results($blog_options_query);
        // On Multisite installations, some options must always be fetched from sitemeta
        if (is_multisite()) {
            /**
             * Filters multisite options retrieved from sitemeta.
             *
             * @since BuddyPress (1.5.0)
             *
             * @param array $value Array of multisite options from sitemeta table.
             */
            $network_options = apply_filters('bp_core_network_options', array('tags_blog_id' => '0', 'sitewide_tags_blog' => '', 'registration' => '0', 'fileupload_maxk' => '1500'));
            $current_site = get_current_site();
            $network_option_keys = array_keys($network_options);
            $sitemeta_options_keys = "'" . join("', '", (array) $network_option_keys) . "'";
            $sitemeta_options_query = $wpdb->prepare("SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ( {$sitemeta_options_keys} ) AND site_id = %d", $current_site->id);
            $network_options_meta = $wpdb->get_results($sitemeta_options_query);
            // Sitemeta comes second in the merge, so that network 'registration' value wins
            $root_blog_options_meta = array_merge($root_blog_options_meta, $network_options_meta);
        }
        // Missing some options, so do some one-time fixing
        if (empty($root_blog_options_meta) || count($root_blog_options_meta) < count($root_blog_option_keys)) {
            // Get a list of the keys that are already populated
            $existing_options = array();
            foreach ($root_blog_options_meta as $already_option) {
                $existing_options[$already_option->name] = $already_option->value;
            }
            // Unset the query - We'll be resetting it soon
            unset($root_blog_options_meta);
            // Loop through options
            foreach ($root_blog_options as $old_meta_key => $old_meta_default) {
                if (isset($existing_options[$old_meta_key])) {
                    continue;
                }
                // Get old site option
                if (is_multisite()) {
                    $old_meta_value = get_site_option($old_meta_key);
                }
                // No site option so look in root blog
                if (empty($old_meta_value)) {
                    $old_meta_value = bp_get_option($old_meta_key, $old_meta_default);
                }
                // Update the root blog option
                bp_update_option($old_meta_key, $old_meta_value);
                // Update the global array
                $root_blog_options_meta[$old_meta_key] = $old_meta_value;
                // Clear out the value for the next time around
                unset($old_meta_value);
            }
            $root_blog_options_meta = array_merge($root_blog_options_meta, $existing_options);
            unset($existing_options);
            // We're all matched up
        } else {
            // Loop through our results and make them usable
            foreach ($root_blog_options_meta as $root_blog_option) {
                $root_blog_options[$root_blog_option->name] = $root_blog_option->value;
            }
            // Copy the options no the return val
            $root_blog_options_meta = $root_blog_options;
            // Clean up our temporary copy
            unset($root_blog_options);
        }
        wp_cache_set('root_blog_options', $root_blog_options_meta, 'bp');
    }
    /**
     * Filters the global BP options.
     *
     * @since BuddyPress (1.5.0)
     *
     * @param array $root_blog_options_meta Array of global BP options.
     */
    return apply_filters('bp_core_get_root_options', $root_blog_options_meta);
}
/**
 * Process account deletion requests.
 *
 * Primarily used for self-deletions, as requested through Settings.
 *
 * @since 1.0.0
 *
 * @param int $user_id Optional. ID of the user to be deleted. Default: the
 *                     logged-in user.
 * @return bool True on success, false on failure.
 */
function bp_core_delete_account($user_id = 0)
{
    // Use logged in user ID if none is passed.
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    // Site admins cannot be deleted.
    if (is_super_admin($user_id)) {
        return false;
    }
    // Extra checks if user is not deleting themselves.
    if (bp_loggedin_user_id() !== absint($user_id)) {
        // Bail if current user cannot delete any users.
        if (!bp_current_user_can('delete_users')) {
            return false;
        }
        // Bail if current user cannot delete this user.
        if (!current_user_can_for_blog(bp_get_root_blog_id(), 'delete_user', $user_id)) {
            return false;
        }
    }
    /**
     * Fires before the processing of an account deletion.
     *
     * @since 1.6.0
     *
     * @param int $user_id ID of the user account being deleted.
     */
    do_action('bp_core_pre_delete_account', $user_id);
    // Specifically handle multi-site environment.
    if (is_multisite()) {
        require_once ABSPATH . '/wp-admin/includes/ms.php';
        require_once ABSPATH . '/wp-admin/includes/user.php';
        $retval = wpmu_delete_user($user_id);
        // Single site user deletion.
    } else {
        require_once ABSPATH . '/wp-admin/includes/user.php';
        $retval = wp_delete_user($user_id);
    }
    /**
     * Fires after the deletion of an account.
     *
     * @since 1.6.0
     *
     * @param int $user_id ID of the user account that was deleted.
     */
    do_action('bp_core_deleted_account', $user_id);
    return $retval;
}
 /**
  * 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;
 }
function bp_adminbar_logo()
{
    global $bp;
    echo '<a href="' . bp_get_root_domain() . '" id="admin-bar-logo">' . get_blog_option(bp_get_root_blog_id(), 'blogname') . '</a>';
}
Example #30
0
/**
 * 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;
}