[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/src/includes/extend/buddypress/ -> members.php (source)

   1  <?php
   2  
   3  /**
   4   * bbPress BuddyPress Members Class
   5   *
   6   * @package bbPress
   7   * @subpackage BuddyPress
   8   */
   9  
  10  // Exit if accessed directly
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  if ( ! class_exists( 'BBP_Forums_Members' ) ) :
  14  /**
  15   * Member profile modifications
  16   *
  17   * @since 2.2.0 bbPress (r4395)
  18   * @since 2.6.0 bbPress (r6320) Add engagements support
  19   *
  20   * @package bbPress
  21   * @subpackage BuddyPress
  22   */
  23  class BBP_BuddyPress_Members {
  24  
  25      /**
  26       * Main constructor for modifying bbPress profile links
  27       *
  28       * @since 2.2.0 bbPress (r4395)
  29       */
  30  	public function __construct() {
  31          $this->setup_actions();
  32          $this->setup_filters();
  33          $this->fully_loaded();
  34      }
  35  
  36      /**
  37       * Setup the actions
  38       *
  39       * @since 2.2.0 bbPress (r4395)
  40       *
  41       * @access private
  42       */
  43  	private function setup_actions() {
  44  
  45          // Allow unsubscribe/unfavorite links to work
  46          add_action( 'bp_template_redirect', array( $this, 'set_member_forum_query_vars' ) );
  47  
  48          /** Favorites *********************************************************/
  49  
  50          // Move handler to 'bp_actions' - BuddyPress bypasses template_loader
  51          remove_action( 'bbp_get_request', 'bbp_favorites_handler', 1 );
  52          add_action(    'bp_actions',      'bbp_favorites_handler', 1 );
  53  
  54          /** Subscriptions *****************************************************/
  55  
  56          // Move handler to 'bp_actions' - BuddyPress bypasses template_loader
  57          remove_action( 'bbp_get_request', 'bbp_subscriptions_handler', 1 );
  58          add_action(    'bp_actions',      'bbp_subscriptions_handler', 1 );
  59      }
  60  
  61      /**
  62       * Setup the filters
  63       *
  64       * @since 2.2.0 bbPress (r4395)
  65       * @since 2.6.0 bbPress (r6320) Add engagements support
  66       *
  67       * @access private
  68       */
  69  	private function setup_filters() {
  70          add_filter( 'bbp_pre_get_user_profile_url',         array( $this, 'get_user_profile_url'        ) );
  71          add_filter( 'bbp_pre_get_user_topics_created_url',  array( $this, 'get_topics_created_url'      ) );
  72          add_filter( 'bbp_pre_get_user_replies_created_url', array( $this, 'get_replies_created_url'     ) );
  73          add_filter( 'bbp_pre_get_user_engagements_url',     array( $this, 'get_engagements_permalink'   ) );
  74          add_filter( 'bbp_pre_get_favorites_permalink',      array( $this, 'get_favorites_permalink'     ) );
  75          add_filter( 'bbp_pre_get_subscriptions_permalink',  array( $this, 'get_subscriptions_permalink' ) );
  76      }
  77  
  78      /**
  79       * Allow the variables, actions, and filters to be modified by third party
  80       * plugins and themes.
  81       *
  82       * @since 2.6.0 bbPress (r6808)
  83       */
  84  	private function fully_loaded() {
  85          do_action_ref_array( 'bbp_buddypress_members_loaded', array( $this ) );
  86      }
  87  
  88      /** Filters ***************************************************************/
  89  
  90      /**
  91       * Override bbPress profile URL with BuddyPress profile URL
  92       *
  93       * @since 2.0.0 bbPress (r3401)
  94       * @since 2.6.0 bbPress (r6320) Add engagements support
  95       *
  96       * @param int $user_id
  97       * @return string
  98       */
  99  	public function get_user_profile_url( $user_id = 0 ) {
 100          return $this->get_profile_url( $user_id );
 101      }
 102  
 103      /**
 104       * Override bbPress topics created URL with BuddyPress profile URL
 105       *
 106       * @since 2.6.0 bbPress (r3721)
 107       * @since 2.6.0 bbPress (r6803) Use private method
 108       *
 109       * @param int $user_id
 110       * @return string
 111       */
 112  	public function get_topics_created_url( $user_id = 0 ) {
 113          return $this->get_profile_url( $user_id, bbp_get_topic_archive_slug() );
 114      }
 115  
 116      /**
 117       * Override bbPress replies created URL with BuddyPress profile URL
 118       *
 119       * @since 2.6.0 bbPress (r3721)
 120       * @since 2.6.0 bbPress (r6803) Use private method
 121       *
 122       * @param int $user_id
 123       * @return string
 124       */
 125  	public function get_replies_created_url( $user_id = 0 ) {
 126          return $this->get_profile_url( $user_id, bbp_get_reply_archive_slug() );
 127      }
 128  
 129      /**
 130       * Override bbPress favorites URL with BuddyPress profile URL
 131       *
 132       * @since 2.1.0 bbPress (r3721)
 133       * @since 2.6.0 bbPress (r6803) Use private method
 134       *
 135       * @param int $user_id
 136       * @return string
 137       */
 138  	public function get_favorites_permalink( $user_id = 0 ) {
 139          return $this->get_profile_url( $user_id, bbp_get_user_favorites_slug() );
 140      }
 141  
 142      /**
 143       * Override bbPress subscriptions URL with BuddyPress profile URL
 144       *
 145       * @since 2.1.0 bbPress (r3721)
 146       * @since 2.6.0 bbPress (r6803) Use private method
 147       *
 148       * @param int $user_id
 149       * @return string
 150       */
 151  	public function get_subscriptions_permalink( $user_id = 0 ) {
 152          return $this->get_profile_url( $user_id, bbp_get_user_subscriptions_slug() );
 153      }
 154  
 155      /**
 156       * Override bbPress engagements URL with BuddyPress profile URL
 157       *
 158       * @since 2.6.0 bbPress (r6320)
 159       *
 160       * @param int $user_id
 161       * @return string
 162       */
 163  	public function get_engagements_permalink( $user_id = 0 ) {
 164          return $this->get_profile_url( $user_id, bbp_get_user_engagements_slug() );
 165      }
 166  
 167      /**
 168       * Set favorites and subscriptions query variables if viewing member profile
 169       * pages.
 170       *
 171       * @since 2.3.0 bbPress (r4615)
 172       * @since 2.6.0 bbPress (r6320) Support all profile sections
 173       *
 174       * @global WP_Query $wp_query
 175       * @return If not viewing your own profile
 176       */
 177  	public function set_member_forum_query_vars() {
 178  
 179          // Special handling for forum component
 180          if ( ! bp_is_my_profile() ) {
 181              return;
 182          }
 183  
 184          // Get the main query object
 185          $wp_query = bbp_get_wp_query();
 186  
 187          // 'topics' action
 188          if ( bp_is_current_action( bbp_get_topic_archive_slug() ) ) {
 189              $wp_query->bbp_is_single_user_topics = true;
 190  
 191          // 'replies' action
 192          } elseif ( bp_is_current_action( bbp_get_reply_archive_slug() ) ) {
 193              $wp_query->bbp_is_single_user_replies = true;
 194  
 195          // 'favorites' action
 196          } elseif ( bbp_is_favorites_active() && bp_is_current_action( bbp_get_user_favorites_slug() ) ) {
 197              $wp_query->bbp_is_single_user_favs = true;
 198  
 199          // 'subscriptions' action
 200          } elseif ( bbp_is_subscriptions_active() && bp_is_current_action( bbp_get_user_subscriptions_slug() ) ) {
 201              $wp_query->bbp_is_single_user_subs = true;
 202  
 203          // 'engagements' action
 204          } elseif ( bbp_is_engagements_active() && bp_is_current_action( bbp_get_user_engagements_slug() ) ) {
 205              $wp_query->bbp_is_single_user_engagements = true;
 206          }
 207      }
 208  
 209      /** Private Methods *******************************************************/
 210  
 211      /**
 212       * Private method used to concatenate user IDs and slugs into URLs
 213       *
 214       * @since 2.6.0 bbPress (r6803)
 215       *
 216       * @param int    $user_id
 217       * @param string $slug
 218       *
 219       * @return string
 220       */
 221  	private function get_profile_url( $user_id = 0, $slug = '' ) {
 222  
 223          // Do not filter if not on BuddyPress root blog
 224          if ( empty( $user_id ) || ! bp_is_root_blog() ) {
 225              return false;
 226          }
 227  
 228          // Setup profile URL
 229          $url = array( bp_core_get_user_domain( $user_id ) );
 230  
 231          // Maybe push slug to end of URL array
 232          if ( ! empty( $slug ) ) {
 233              array_push( $url, bbpress()->extend->buddypress->slug );
 234              array_push( $url, $slug );
 235          }
 236  
 237          // Return
 238          return implode( '', array_map( 'trailingslashit', $url ) );
 239      }
 240  }
 241  endif;


Generated: Thu Apr 25 01:01:05 2024 Cross-referenced by PHPXref 0.7.1