/** * Add a Sites menu to the BuddyBar. * * @since BuddyPress (1.0.0) * @deprecated BuddyPress (2.1.0) * * @global object $bp The BuddyPress global settings object. * * @return bool|null Returns false on failure. Otherwise echoes the menu item. */ function bp_adminbar_blogs_menu() { global $bp; if (!is_user_logged_in() || !bp_is_active('blogs')) { return false; } if (!is_multisite()) { return false; } $blogs = wp_cache_get('bp_blogs_of_user_' . bp_loggedin_user_id() . '_inc_hidden', 'bp'); if (empty($blogs)) { $blogs = bp_blogs_get_blogs_for_user(bp_loggedin_user_id(), true); wp_cache_set('bp_blogs_of_user_' . bp_loggedin_user_id() . '_inc_hidden', $blogs, 'bp'); } $counter = 0; if (is_array($blogs['blogs']) && (int) $blogs['count']) { echo '<li id="bp-adminbar-blogs-menu"><a href="' . trailingslashit(bp_loggedin_user_domain() . bp_get_blogs_slug()) . '">'; _e('My Sites', 'buddypress'); echo '</a>'; echo '<ul>'; foreach ((array) $blogs['blogs'] as $blog) { $alt = 0 == $counter % 2 ? ' class="alt"' : ''; $site_url = esc_attr($blog->siteurl); echo '<li' . $alt . '>'; echo '<a href="' . $site_url . '">' . esc_html($blog->name) . '</a>'; echo '<ul>'; echo '<li class="alt"><a href="' . $site_url . 'wp-admin/">' . __('Dashboard', 'buddypress') . '</a></li>'; echo '<li><a href="' . $site_url . 'wp-admin/post-new.php">' . __('New Post', 'buddypress') . '</a></li>'; echo '<li class="alt"><a href="' . $site_url . 'wp-admin/edit.php">' . __('Manage Posts', 'buddypress') . '</a></li>'; echo '<li><a href="' . $site_url . 'wp-admin/edit-comments.php">' . __('Manage Comments', 'buddypress') . '</a></li>'; echo '</ul>'; do_action('bp_adminbar_blog_items', $blog); echo '</li>'; $counter++; } $alt = 0 == $counter % 2 ? ' class="alt"' : ''; if (bp_blog_signup_enabled()) { echo '<li' . $alt . '>'; echo '<a href="' . bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/create/">' . __('Create a Site!', 'buddypress') . '</a>'; echo '</li>'; } echo '</ul>'; echo '</li>'; } }
/** * Setup BuddyBar navigation * * @global obj $bp */ function setup_nav() { global $bp; /** * Blog/post/comment menus should not appear on single WordPress setups. * Although comments and posts made by users will still show on their * activity stream. */ if (!is_multisite()) { return false; } // Add 'Sites' to the main navigation $main_nav = array('name' => sprintf(__('Sites <span>%d</span>', 'buddypress'), bp_blogs_total_blogs_for_user()), 'slug' => $this->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-sites', 'item_css_id' => $this->id); $parent_url = trailingslashit(bp_displayed_user_domain() . bp_get_blogs_slug()); $sub_nav[] = array('name' => __('My Sites', 'buddypress'), 'slug' => 'my-sites', 'parent_url' => $parent_url, 'parent_slug' => $bp->blogs->slug, 'screen_function' => 'bp_blogs_screen_my_blogs', 'position' => 10); // Setup navigation parent::setup_nav($main_nav, $sub_nav); }
bp_root_domain(); ?> /<?php bp_blogs_root_slug(); ?> "><?php printf(__('All Sites <span>%s</span>', 'buddypress'), bp_get_total_blog_count()); ?> </a></li> <?php if (is_user_logged_in() && bp_get_total_blog_count_for_user(bp_loggedin_user_id())) { ?> <li id="blogs-personal"><a href="<?php echo bp_loggedin_user_domain() . bp_get_blogs_slug(); ?> "><?php printf(__('My Sites <span>%s</span>', 'buddypress'), bp_get_total_blog_count_for_user(bp_loggedin_user_id())); ?> </a></li> <?php } ?> <?php do_action('bp_blogs_directory_blog_types'); ?> </ul>
/** * Action handler when a follow blogs button is clicked. * * Handles both following and unfollowing a blog. */ public static function action_handler() { if (empty($_GET['blog_id']) || !is_user_logged_in()) { return; } $action = false; if (!empty($_GET['bpfb-follow']) || !empty($_GET['bpfb-unfollow'])) { $nonce = !empty($_GET['bpfb-follow']) ? $_GET['bpfb-follow'] : $_GET['bpfb-unfollow']; $action = !empty($_GET['bpfb-follow']) ? 'follow' : 'unfollow'; $save = !empty($_GET['bpfb-follow']) ? 'bp_follow_start_following' : 'bp_follow_stop_following'; } if (!$action) { return; } if (!wp_verify_nonce($nonce, "bp_follow_blog_{$action}")) { return; } if (!$save(array('leader_id' => (int) $_GET['blog_id'], 'follower_id' => bp_loggedin_user_id(), 'follow_type' => 'blogs'))) { if ('follow' == $action) { $message = __('You are already following that blog.', 'bp-follow'); } else { $message = __('You are not following that blog.', 'bp-follow'); } bp_core_add_message($message, 'error'); // success on follow action } else { $blog_name = bp_blogs_get_blogmeta((int) $_GET['blog_id'], 'name'); // blog has never been recorded into BP; record it now if ('' === $blog_name && apply_filters('bp_follow_blogs_record_blog', true, (int) $_GET['blog_id'])) { // get the admin of the blog $admin = get_users(array('blog_id' => get_current_blog_id(), 'role' => 'administrator', 'orderby' => 'ID', 'number' => 1, 'fields' => array('ID'))); // record the blog $record_site = bp_blogs_record_blog((int) $_GET['blog_id'], $admin[0]->ID, true); // now refetch the blog name from blogmeta if (false !== $record_site) { $blog_name = bp_blogs_get_blogmeta((int) $_GET['blog_id'], 'name'); } } if ('follow' == $action) { if (!empty($blog_name)) { $message = sprintf(__('You are now following the site, %s.', 'bp-follow'), $blog_name); } else { $message = __('You are now following that site.', 'bp-follow'); } } else { if (!empty($blog_name)) { $message = sprintf(__('You are no longer following the site, %s.', 'bp-follow'), $blog_name); } else { $message = __('You are no longer following that site.', 'bp-follow'); } } bp_core_add_message($message); } // it's possible that wp_get_referer() returns false, so let's fallback to the displayed user's page $redirect = wp_get_referer() ? wp_get_referer() : bp_displayed_user_domain() . bp_get_blogs_slug() . '/' . constant('BP_FOLLOW_BLOGS_USER_FOLLOWING_SLUG') . '/'; bp_core_redirect($redirect); }
$max_pages = max(ceil($blogs_template->total_blog_count / 14), 1); ?> <h3><?php _e('Site Directory', 'huddle'); ?> </h3> <p class="subtitle"> <?php bp_blogs_pagination_count(); ?> <?php if (is_user_logged_in() && bp_blog_signup_enabled()) { ?> <a class="btn-gray quick-create-blog" href="<?php echo add_query_arg('w-iframe', '1', bp_get_root_domain() . '/' . bp_get_blogs_slug() . '/create/'); ?> "><?php _e('Create a Blog', 'huddle'); ?> </a><?php } ?> </p> <?php do_action('bp_before_directory_blogs_content'); ?> <div id="blog-dir-search" class="dir-search" role="search">
/** * Output navigation tabs for a user Blogs page. * * Currently unused by BuddyPress. */ function bp_blogs_blog_tabs() { // Don't show these tabs on a user's own profile if (bp_is_my_profile()) { return false; } ?> <ul class="content-header-nav"> <li<?php if (bp_is_current_action('my-blogs') || !bp_current_action()) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_displayed_user_domain() . bp_get_blogs_slug() . '/my-blogs'); ?> "><?php printf(__("%s's Sites", 'buddypress'), bp_get_displayed_user_fullname()); ?> </a></li> <li<?php if (bp_is_current_action('recent-posts')) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_displayed_user_domain() . bp_get_blogs_slug() . '/recent-posts'); ?> "><?php printf(__("%s's Recent Posts", 'buddypress'), bp_get_displayed_user_fullname()); ?> </a></li> <li<?php if (bp_is_current_action('recent-comments')) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_displayed_user_domain() . bp_get_blogs_slug() . '/recent-comments'); ?> "><?php printf(__("%s's Recent Comments", 'buddypress'), bp_get_displayed_user_fullname()); ?> </a></li> </ul> <?php /** * Fires after the markup for the navigation tabs for a user Blogs page. * * @since BuddyPress (1.0.0) */ do_action('bp_blogs_blog_tabs'); }
/** * Set up bp-blogs integration with the WordPress admin bar. * * @since 1.5.0 * * @see BP_Component::setup_admin_bar() for a description of arguments. * * @param array $wp_admin_nav See BP_Component::setup_admin_bar() * for description. * @return bool */ public function setup_admin_bar($wp_admin_nav = array()) { /** * Site/post/comment menus should not appear on single WordPress setups. * * Comments and posts made by users will still show in their activity. */ if (!is_multisite()) { return false; } // Menus for logged in user. if (is_user_logged_in()) { // Setup the logged in user variables. $blogs_link = trailingslashit(bp_loggedin_user_domain() . bp_get_blogs_slug()); // Add the "Sites" sub menu. $wp_admin_nav[] = array('parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => __('Sites', 'buddypress'), 'href' => $blogs_link); // My Sites. $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-my-sites', 'title' => __('My Sites', 'buddypress'), 'href' => $blogs_link); // Create a Site. if (bp_blog_signup_enabled()) { $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-create', 'title' => __('Create a Site', 'buddypress'), 'href' => trailingslashit(bp_get_blogs_directory_permalink() . 'create')); } } parent::setup_admin_bar($wp_admin_nav); }
function bp_blogs_blog_tabs() { global $bp, $groups_template; // Don't show these tabs on a user's own profile if (bp_is_my_profile()) { return false; } ?> <ul class="content-header-nav"> <li<?php if (bp_is_current_action('my-blogs') || !bp_current_action()) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_displayed_user_domain() . bp_get_blogs_slug() . '/my-blogs'); ?> "><?php printf(__("%s's Sites", 'buddypress'), bp_get_displayed_user_fullname()); ?> </a></li> <li<?php if (bp_is_current_action('recent-posts')) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_displayed_user_domain() . bp_get_blogs_slug() . '/recent-posts'); ?> "><?php printf(__("%s's Recent Posts", 'buddypress'), bp_get_displayed_user_fullname()); ?> </a></li> <li<?php if (bp_is_current_action('recent-comments')) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_displayed_user_domain() . bp_get_blogs_slug() . '/recent-comments'); ?> "><?php printf(__("%s's Recent Comments", 'buddypress'), bp_get_displayed_user_fullname()); ?> </a></li> </ul> <?php do_action('bp_blogs_blog_tabs', $current_tab); }
/** * Ensures that the 'Create a new site' link at wp-admin/my-sites.php points to the BP blog signup * * @since 1.6 * @uses apply_filters() Filter bp_blogs_creation_location to alter the returned value * * @param string $url The original URL (points to wp-signup.php by default) * @return string The new URL */ function bp_blogs_creation_location($url) { return apply_filters('bp_blogs_creation_location', trailingslashit(bp_get_root_domain() . '/' . bp_get_blogs_slug() . '/create', $url)); }
/** * Set up component navigation for bp-blogs. * * @see BP_Component::setup_nav() for a description of arguments. * * @param array $main_nav Optional. See BP_Component::setup_nav() for * description. * @param array $sub_nav Optional. See BP_Component::setup_nav() for * description. */ public function setup_nav($main_nav = array(), $sub_nav = array()) { $bp = buddypress(); /** * Blog/post/comment menus should not appear on single WordPress setups. * Although comments and posts made by users will still show on their * activity stream. */ if (!is_multisite()) { return false; } // Add 'Sites' to the main navigation $count = (int) bp_get_total_blog_count_for_user(); $class = 0 === $count ? 'no-count' : 'count'; $nav_text = sprintf(__('Sites <span class="%s">%s</span>', 'buddypress'), esc_attr($class), number_format_i18n($count)); $main_nav = array('name' => $nav_text, 'slug' => $this->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-sites', 'item_css_id' => $this->id); // Determine user to use if (bp_displayed_user_domain()) { $user_domain = bp_displayed_user_domain(); } elseif (bp_loggedin_user_domain()) { $user_domain = bp_loggedin_user_domain(); } else { return; } $parent_url = trailingslashit($user_domain . bp_get_blogs_slug()); $sub_nav[] = array('name' => __('My Sites', 'buddypress'), 'slug' => 'my-sites', 'parent_url' => $parent_url, 'parent_slug' => $bp->blogs->slug, 'screen_function' => 'bp_blogs_screen_my_blogs', 'position' => 10); // Setup navigation parent::setup_nav($main_nav, $sub_nav); }