1 | <?php |
---|
2 | /** |
---|
3 | * Here's an example on how to completely override Favorites to behave as likes |
---|
4 | */ |
---|
5 | |
---|
6 | // Exit if accessed directly |
---|
7 | if ( ! defined( 'ABSPATH' ) ) exit; |
---|
8 | |
---|
9 | |
---|
10 | class BP_Custom_Like { |
---|
11 | |
---|
12 | public static function start() { |
---|
13 | // Bail if activity component is inactive |
---|
14 | if ( ! bp_is_active( 'activity' ) ) { |
---|
15 | return; |
---|
16 | } |
---|
17 | |
---|
18 | $bp = buddypress(); |
---|
19 | |
---|
20 | if ( empty( $bp->custom_like ) ) { |
---|
21 | $bp->custom_like = new self; |
---|
22 | } |
---|
23 | |
---|
24 | return $bp->custom_like; |
---|
25 | } |
---|
26 | |
---|
27 | public function __construct() { |
---|
28 | $this->setup_hooks(); |
---|
29 | } |
---|
30 | |
---|
31 | public function setup_hooks() { |
---|
32 | // First remove the setting screen |
---|
33 | add_filter( 'bp_activity_favorites_user_settings', '__return_false' ); |
---|
34 | |
---|
35 | // Force favorites to be public |
---|
36 | add_filter( 'bp_activity_favorites_privacy', '__return_true' ); |
---|
37 | |
---|
38 | // Define your custom strings |
---|
39 | add_filter( 'bp_activity_favorites_globals', array( $this, 'like_strings' ), 10, 1 ); |
---|
40 | |
---|
41 | // Change the unfav link to go to user's likes instead of unfavoriting the activity |
---|
42 | add_filter( 'bp_get_activity_unfavorite_link', array( $this, 'user_likes' ), 10, 1 ); |
---|
43 | |
---|
44 | // Neutralize unfav ajax action |
---|
45 | add_filter( 'bp_core_get_js_strings', array( $this, 'neutralize_unfav' ), 10, 1 ); |
---|
46 | } |
---|
47 | |
---|
48 | public function like_strings( $strings = array() ) { |
---|
49 | return array( |
---|
50 | // Activity action args |
---|
51 | 'description' => _x( 'Liked an update', 'likes activity description', 'bp-custom-like' ), |
---|
52 | 'label' => _x( 'Likes', 'likes activity dropdown label', 'bp-custom-like' ), |
---|
53 | // Wether you want to show the favorites in Activity Directory / group single item activities, |
---|
54 | // member single item activities, or the groups tab of member single item activities |
---|
55 | 'contexts' => array( 'activity', 'group', 'member', 'member_groups' ), |
---|
56 | // Strings |
---|
57 | 'directory_tab' => _x( 'My Likes', 'likes directory tab', 'bp-custom-like' ), |
---|
58 | // The action button in activity stream to favorite an update |
---|
59 | 'fav_button' => _x( 'Like', 'like button caption', 'bp-custom-like' ), |
---|
60 | // The action button in activity stream to remove a favorited update |
---|
61 | 'unfav_button' => _x( 'Liked', 'liked button caption', 'bp-custom-like' ), |
---|
62 | // Nav name |
---|
63 | 'subnav' => _x( 'Likes', 'likes member subnav', 'bp-custom-like' ), |
---|
64 | // Slug |
---|
65 | 'slug' => 'likes' |
---|
66 | ); |
---|
67 | } |
---|
68 | |
---|
69 | public function user_likes( $unfav_link = '' ) { |
---|
70 | return bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_activity_slug() . '/' . bp_get_activity_favorites_slug(); |
---|
71 | } |
---|
72 | |
---|
73 | public function neutralize_unfav( $params = array() ) { |
---|
74 | $params['no_unfav'] = 1; |
---|
75 | return $params; |
---|
76 | } |
---|
77 | } |
---|
78 | add_action( 'bp_core_components_included', array( 'BP_Custom_Like', 'start' ), 10 ); |
---|