| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* bbPress BuddyPress Members Class |
| 5 |
* |
| 6 |
* @package bbPress |
| 7 |
* @subpackage BuddyPress |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly |
| 11 |
if ( !defined( 'ABSPATH' ) ) exit; |
| 12 |
|
| 13 |
if ( !class_exists( 'BBP_Forums_Members' ) ) : |
| 14 |
/** |
| 15 |
* Member profile modifications |
| 16 |
* |
| 17 |
* @since bbPress (r4395) |
| 18 |
* |
| 19 |
* @package bbPress |
| 20 |
* @subpackage BuddyPress |
| 21 |
*/ |
| 22 |
class BBP_BuddyPress_Members { |
| 23 |
|
| 24 |
/** |
| 25 |
* Main constructor for modifying bbPress profile links |
| 26 |
* |
| 27 |
* @since bbPress (r4395) |
| 28 |
*/ |
| 29 |
public function __construct() { |
| 30 |
$this->setup_actions(); |
| 31 |
$this->setup_filters(); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Setup the actions |
| 36 |
* |
| 37 |
* @since bbPress (r4395) |
| 38 |
* |
| 39 |
* @access private |
| 40 |
* @uses add_filter() To add various filters |
| 41 |
* @uses add_action() To add various actions |
| 42 |
*/ |
| 43 |
private function setup_actions() { |
| 44 |
|
| 45 |
/** Favorites *********************************************************/ |
| 46 |
|
| 47 |
// Move handler to 'bp_actions' - BuddyPress bypasses template_loader |
| 48 |
remove_action( 'template_redirect', 'bbp_favorites_handler', 1 ); |
| 49 |
add_action( 'bp_actions', 'bbp_favorites_handler', 1 ); |
| 50 |
|
| 51 |
/** Subscriptions *****************************************************/ |
| 52 |
|
| 53 |
// Move handler to 'bp_actions' - BuddyPress bypasses template_loader |
| 54 |
remove_action( 'template_redirect', 'bbp_subscriptions_handler', 1 ); |
| 55 |
add_action( 'bp_actions', 'bbp_subscriptions_handler', 1 ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Setup the filters |
| 60 |
* |
| 61 |
* @since bbPress (r4395) |
| 62 |
* |
| 63 |
* @access private |
| 64 |
* @uses add_filter() To add various filters |
| 65 |
* @uses add_action() To add various actions |
| 66 |
*/ |
| 67 |
private function setup_filters() { |
| 68 |
add_filter( 'bbp_pre_get_user_profile_url', array( $this, 'user_profile_url' ) ); |
| 69 |
add_filter( 'bbp_get_favorites_permalink', array( $this, 'get_favorites_permalink' ), 10, 2 ); |
| 70 |
add_filter( 'bbp_get_subscriptions_permalink', array( $this, 'get_subscriptions_permalink' ), 10, 2 ); |
| 71 |
} |
| 72 |
|
| 73 |
/** Filters ***************************************************************/ |
| 74 |
|
| 75 |
/** |
| 76 |
* Override bbPress profile URL with BuddyPress profile URL |
| 77 |
* |
| 78 |
* @since bbPress (r3401) |
| 79 |
* @param string $url |
| 80 |
* @param int $user_id |
| 81 |
* @param string $user_nicename |
| 82 |
* @return string |
| 83 |
*/ |
| 84 |
public function user_profile_url( $user_id ) { |
| 85 |
|
| 86 |
// Define local variable(s) |
| 87 |
$profile_url = ''; |
| 88 |
|
| 89 |
// Special handling for forum component |
| 90 |
if ( bp_is_current_component( 'forums' ) ) { |
| 91 |
|
| 92 |
// Empty action or 'topics' action |
| 93 |
if ( !bp_current_action() || bp_is_current_action( 'topics' ) ) { |
| 94 |
$profile_url = bp_core_get_user_domain( $user_id ) . 'forums/topics'; |
| 95 |
|
| 96 |
// Empty action or 'topics' action |
| 97 |
} elseif ( bp_is_current_action( 'replies' ) ) { |
| 98 |
$profile_url = bp_core_get_user_domain( $user_id ) . 'forums/replies'; |
| 99 |
|
| 100 |
// 'favorites' action |
| 101 |
} elseif ( bbp_is_favorites_active() && bp_is_current_action( 'favorites' ) ) { |
| 102 |
$profile_url = $this->get_favorites_permalink( '', $user_id ); |
| 103 |
|
| 104 |
// 'subscriptions' action |
| 105 |
} elseif ( bbp_is_subscriptions_active() && bp_is_current_action( 'subscriptions' ) ) { |
| 106 |
$profile_url = $this->get_subscriptions_permalink( '', $user_id ); |
| 107 |
} |
| 108 |
|
| 109 |
// Not in users' forums area |
| 110 |
} else { |
| 111 |
$profile_url = bp_core_get_user_domain( $user_id ); |
| 112 |
} |
| 113 |
|
| 114 |
return trailingslashit( $profile_url ); |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Override bbPress favorites URL with BuddyPress profile URL |
| 119 |
* |
| 120 |
* @since bbPress (r3721) |
| 121 |
* @param string $url |
| 122 |
* @param int $user_id |
| 123 |
* @return string |
| 124 |
*/ |
| 125 |
public function get_favorites_permalink( $url, $user_id ) { |
| 126 |
$url = trailingslashit( bp_core_get_user_domain( $user_id ) . 'forums/favorites' ); |
| 127 |
return $url; |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Override bbPress subscriptions URL with BuddyPress profile URL |
| 132 |
* |
| 133 |
* @since bbPress (r3721) |
| 134 |
* @param string $url |
| 135 |
* @param int $user_id |
| 136 |
* @return string |
| 137 |
*/ |
| 138 |
public function get_subscriptions_permalink( $url, $user_id ) { |
| 139 |
$url = trailingslashit( bp_core_get_user_domain( $user_id ) . 'forums/subscriptions' ); |
| 140 |
return $url; |
| 141 |
} |
| 142 |
} |
| 143 |
endif; |
| 144 |
|