Example #1
0
/**
 * Return the link to the user's replies
 *
 * @since 2.2.0 bbPress (r4225)
 *
 * @param int $user_id Optional. User id
 * @uses bbp_get_user_profile_url() To get the user profile url
 * @uses apply_filters() Calls 'bbp_get_favorites_permalink' with the
 *                        user profile url and user id
 * @return string Permanent link to user profile page
 */
function bbp_get_user_replies_created_url($user_id = 0)
{
    // Use displayed user ID if there is one, and one isn't requested
    $user_id = bbp_get_user_id($user_id);
    if (empty($user_id)) {
        return false;
    }
    // Allow early overriding of the profile URL to cut down on processing
    $early_url = apply_filters('bbp_pre_get_user_replies_created_url', $user_id);
    if (is_string($early_url)) {
        return $early_url;
    }
    // Get user profile URL
    $profile_url = bbp_get_user_profile_url($user_id);
    // Pretty permalinks
    if (bbp_use_pretty_urls()) {
        $url = trailingslashit($profile_url) . bbp_get_reply_archive_slug();
        $url = user_trailingslashit($url);
        // Unpretty permalinks
    } else {
        $url = add_query_arg(array(bbp_get_user_replies_rewrite_id() => '1'), $profile_url);
    }
    return apply_filters('bbp_get_user_replies_created_url', $url, $user_id);
}
Example #2
0
 /**
  * Add bbPress-specific rewrite rules for uri's that are not
  * setup for us by way of custom post types or taxonomies. This includes:
  * - Front-end editing
  * - Topic views
  * - User profiles
  *
  * @since bbPress (r2688)
  * @todo Extract into an API
  */
 public static function add_rewrite_rules()
 {
     /** Setup *************************************************************/
     // Add rules to top or bottom?
     $priority = 'top';
     // Single Slugs
     $forum_slug = bbp_get_forum_slug();
     $topic_slug = bbp_get_topic_slug();
     $reply_slug = bbp_get_reply_slug();
     $ttag_slug = bbp_get_topic_tag_tax_slug();
     // Archive Slugs
     $user_slug = bbp_get_user_slug();
     $view_slug = bbp_get_view_slug();
     $search_slug = bbp_get_search_slug();
     $topic_archive_slug = bbp_get_topic_archive_slug();
     $reply_archive_slug = bbp_get_reply_archive_slug();
     // Tertiary Slugs
     $feed_slug = 'feed';
     $edit_slug = 'edit';
     $paged_slug = bbp_get_paged_slug();
     $user_favs_slug = bbp_get_user_favorites_slug();
     $user_subs_slug = bbp_get_user_subscriptions_slug();
     // Unique rewrite ID's
     $feed_id = 'feed';
     $edit_id = bbp_get_edit_rewrite_id();
     $view_id = bbp_get_view_rewrite_id();
     $paged_id = bbp_get_paged_rewrite_id();
     $search_id = bbp_get_search_rewrite_id();
     $user_id = bbp_get_user_rewrite_id();
     $user_favs_id = bbp_get_user_favorites_rewrite_id();
     $user_subs_id = bbp_get_user_subscriptions_rewrite_id();
     $user_tops_id = bbp_get_user_topics_rewrite_id();
     $user_reps_id = bbp_get_user_replies_rewrite_id();
     // Rewrite rule matches used repeatedly below
     $root_rule = '/([^/]+)/?$';
     $feed_rule = '/([^/]+)/' . $feed_slug . '/?$';
     $edit_rule = '/([^/]+)/' . $edit_slug . '/?$';
     $paged_rule = '/([^/]+)/' . $paged_slug . '/?([0-9]{1,})/?$';
     // Search rules (without slug check)
     $search_root_rule = '/?$';
     $search_paged_rule = '/' . $paged_slug . '/?([0-9]{1,})/?$';
     /** Add ***************************************************************/
     // User profile rules
     $tops_rule = '/([^/]+)/' . $topic_archive_slug . '/?$';
     $reps_rule = '/([^/]+)/' . $reply_archive_slug . '/?$';
     $favs_rule = '/([^/]+)/' . $user_favs_slug . '/?$';
     $subs_rule = '/([^/]+)/' . $user_subs_slug . '/?$';
     $tops_paged_rule = '/([^/]+)/' . $topic_archive_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
     $reps_paged_rule = '/([^/]+)/' . $reply_archive_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
     $favs_paged_rule = '/([^/]+)/' . $user_favs_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
     $subs_paged_rule = '/([^/]+)/' . $user_subs_slug . '/' . $paged_slug . '/?([0-9]{1,})/?$';
     // Edit Forum|Topic|Reply|Topic-tag
     add_rewrite_rule($forum_slug . $edit_rule, 'index.php?' . bbp_get_forum_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority);
     add_rewrite_rule($topic_slug . $edit_rule, 'index.php?' . bbp_get_topic_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority);
     add_rewrite_rule($reply_slug . $edit_rule, 'index.php?' . bbp_get_reply_post_type() . '=$matches[1]&' . $edit_id . '=1', $priority);
     add_rewrite_rule($ttag_slug . $edit_rule, 'index.php?' . bbp_get_topic_tag_tax_id() . '=$matches[1]&' . $edit_id . '=1', $priority);
     // User Pagination|Edit|View
     add_rewrite_rule($user_slug . $tops_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_tops_id . '=1&' . $paged_id . '=$matches[2]', $priority);
     add_rewrite_rule($user_slug . $reps_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_reps_id . '=1&' . $paged_id . '=$matches[2]', $priority);
     add_rewrite_rule($user_slug . $favs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_favs_id . '=1&' . $paged_id . '=$matches[2]', $priority);
     add_rewrite_rule($user_slug . $subs_paged_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_subs_id . '=1&' . $paged_id . '=$matches[2]', $priority);
     add_rewrite_rule($user_slug . $tops_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_tops_id . '=1', $priority);
     add_rewrite_rule($user_slug . $reps_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_reps_id . '=1', $priority);
     add_rewrite_rule($user_slug . $favs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_favs_id . '=1', $priority);
     add_rewrite_rule($user_slug . $subs_rule, 'index.php?' . $user_id . '=$matches[1]&' . $user_subs_id . '=1', $priority);
     add_rewrite_rule($user_slug . $edit_rule, 'index.php?' . $user_id . '=$matches[1]&' . $edit_id . '=1', $priority);
     add_rewrite_rule($user_slug . $root_rule, 'index.php?' . $user_id . '=$matches[1]', $priority);
     // Topic-View Pagination|Feed|View
     add_rewrite_rule($view_slug . $paged_rule, 'index.php?' . $view_id . '=$matches[1]&' . $paged_id . '=$matches[2]', $priority);
     add_rewrite_rule($view_slug . $feed_rule, 'index.php?' . $view_id . '=$matches[1]&' . $feed_id . '=$matches[2]', $priority);
     add_rewrite_rule($view_slug . $root_rule, 'index.php?' . $view_id . '=$matches[1]', $priority);
     // Search All
     add_rewrite_rule($search_slug . $search_paged_rule, 'index.php?' . $paged_id . '=$matches[1]', $priority);
     add_rewrite_rule($search_slug . $search_root_rule, 'index.php?' . $search_id, $priority);
 }
Example #3
0
 /**
  * Set up the admin bar
  *
  * @since bbPress (r3552)
  */
 public function setup_admin_bar($wp_admin_nav = array())
 {
     // Menus for logged in user
     if (is_user_logged_in()) {
         // Setup the logged in user variables
         $user_domain = bp_loggedin_user_domain();
         $forums_link = trailingslashit($user_domain . $this->slug);
         // Add the "My Account" sub menus
         $wp_admin_nav[] = array('parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => __('Forums', 'bbpress'), 'href' => trailingslashit($forums_link));
         // Topics
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-topics', 'title' => __('Topics Started', 'bbpress'), 'href' => trailingslashit($forums_link . bbp_get_topic_archive_slug()));
         // Replies
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-replies', 'title' => __('Replies Created', 'bbpress'), 'href' => trailingslashit($forums_link . bbp_get_reply_archive_slug()));
         // Favorites
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-favorites', 'title' => __('Favorite Topics', 'bbpress'), 'href' => trailingslashit($forums_link . bbp_get_user_favorites_slug()));
         // Subscriptions
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-subscriptions', 'title' => __('Subscribed Topics', 'bbpress'), 'href' => trailingslashit($forums_link . bbp_get_user_subscriptions_slug()));
     }
     parent::setup_admin_bar($wp_admin_nav);
 }
Example #4
0
 /**
  * Set up the admin bar
  *
  * @since 2.1.0 bbPress (r3552)
  */
 public function setup_admin_bar($wp_admin_nav = array())
 {
     // Menus for logged in user
     if (is_user_logged_in()) {
         // If BuddyPress is network activated and bbPress is
         // not activated on a the root blog but on any child one
         if (!bp_is_root_blog()) {
             $user_id = bbp_get_current_user_id();
             $my_account_link = bbp_get_user_profile_url($user_id);
             $my_topics_link = bbp_get_user_topics_created_url($user_id);
             $my_replies_link = bbp_get_user_replies_created_url($user_id);
             $my_favorites_link = bbp_get_favorites_permalink($user_id);
             $my_subscriptions_link = bbp_get_subscriptions_permalink($user_id);
         } else {
             // Setup the logged in user variables
             $user_domain = bp_loggedin_user_domain();
             $forums_link = trailingslashit($user_domain . $this->slug);
             $my_account_link = trailingslashit($forums_link);
             $my_topics_link = trailingslashit($forums_link . bbp_get_topic_archive_slug());
             $my_replies_link = trailingslashit($forums_link . bbp_get_reply_archive_slug());
             $my_favorites_link = trailingslashit($forums_link . bbp_get_user_favorites_slug());
             $my_subscriptions_link = trailingslashit($forums_link . bbp_get_user_subscriptions_slug());
         }
         // Add the "My Account" sub menus
         $wp_admin_nav[] = array('parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => __('Forums', 'bbpress'), 'href' => $my_account_link);
         // Topics
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-topics', 'title' => __('Topics Started', 'bbpress'), 'href' => $my_topics_link);
         // Replies
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-replies', 'title' => __('Replies Created', 'bbpress'), 'href' => $my_replies_link);
         // Favorites
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-favorites', 'title' => __('Favorite Topics', 'bbpress'), 'href' => $my_favorites_link);
         // Subscriptions
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-subscriptions', 'title' => __('Subscribed Topics', 'bbpress'), 'href' => $my_subscriptions_link);
     }
     parent::setup_admin_bar($wp_admin_nav);
 }
Example #5
0
 /**
  * Override bbPress profile URL with BuddyPress profile URL
  *
  * @since bbPress (r3401)
  * @param string $url
  * @param int $user_id
  * @param string $user_nicename
  * @return string
  */
 public function user_profile_url($user_id)
 {
     // Define local variable(s)
     $profile_url = '';
     $component_slug = bbpress()->extend->buddypress->slug;
     // Special handling for forum component
     if (bp_is_current_component($component_slug)) {
         // Empty action or 'topics' action
         if (!bp_current_action() || bp_is_current_action(bbp_get_topic_archive_slug())) {
             $profile_url = bp_core_get_user_domain($user_id) . $component_slug . '/' . bbp_get_topic_archive_slug();
             // Empty action or 'topics' action
         } elseif (bp_is_current_action(bbp_get_reply_archive_slug())) {
             $profile_url = bp_core_get_user_domain($user_id) . $component_slug . '/' . bbp_get_reply_archive_slug();
             // 'favorites' action
         } elseif (bbp_is_favorites_active() && bp_is_current_action(bbp_get_user_favorites_slug())) {
             $profile_url = $this->get_favorites_permalink('', $user_id);
             // 'subscriptions' action
         } elseif (bbp_is_subscriptions_active() && bp_is_current_action(bbp_get_user_subscriptions_slug())) {
             $profile_url = $this->get_subscriptions_permalink('', $user_id);
         }
         // Not in users' forums area
     } else {
         $profile_url = bp_core_get_user_domain($user_id);
     }
     return trailingslashit($profile_url);
 }
/**
 * Return the link to the user's replies
 *
 * @since bbPress (r4225)
 *
 * @param int $user_id Optional. User id
 * @uses bbp_get_user_profile_url() To get the user profile url
 * @uses apply_filters() Calls 'bbp_get_favorites_permalink' with the
 *                        user profile url and user id
 * @return string Permanent link to user profile page
 */
function bbp_get_user_replies_created_url($user_id = 0)
{
    global $wp_rewrite;
    // Use displayed user ID if there is one, and one isn't requested
    $user_id = bbp_get_user_id($user_id);
    if (empty($user_id)) {
        return false;
    }
    // Allow early overriding of the profile URL to cut down on processing
    $early_url = apply_filters('bbp_pre_get_user_replies_created_url', (int) $user_id);
    if (is_string($early_url)) {
        return $early_url;
    }
    // Pretty permalinks
    if ($wp_rewrite->using_permalinks()) {
        $url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . bbp_get_user_rewrite_id() . '%/' . bbp_get_reply_archive_slug();
        $user = get_userdata($user_id);
        if (!empty($user->user_nicename)) {
            $user_nicename = $user->user_nicename;
        } else {
            $user_nicename = $user->user_login;
        }
        $url = str_replace('%' . bbp_get_user_rewrite_id() . '%', $user_nicename, $url);
        $url = home_url(user_trailingslashit($url));
        // Unpretty permalinks
    } else {
        $url = add_query_arg(array(bbp_get_user_rewrite_id() => $user_id, bbp_get_user_replies_rewrite_id() => '1'), home_url('/'));
    }
    return apply_filters('bbp_get_user_replies_created_url', $url, $user_id);
}