PluginProbe
wpForo Forum / 3.0.5
wpForo Forum v3.0.5
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / integrations / BuddyPress.php

BuddyPress.php in wpForo Forum 3.0.5, at integrations/BuddyPress.php

126 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace wpforo\integrations;
4
5 use BP_Component;
6
7 // Exit if accessed directly
8 if( ! defined( 'ABSPATH' ) ) exit;
9
10 class BuddyPress extends BP_Component {
11 public function __construct() {
12 parent::start( 'community', __( 'Forums', 'wpforo' ) );
13 $this->includes();
14 $this->setup_globals();
15 $this->setup_actions();
16 }
17
18 public function includes( $includes = [] ) {
19 $includes[] = 'functions.php';
20 $includes[] = 'members.php';
21 if( bp_is_active( 'notifications' ) ) $includes[] = 'notifications.php';
22 if( bp_is_active( 'activity' ) ) $includes[] = 'activity.php';
23 parent::includes( $includes );
24 }
25
26 public function setup_globals( $args = [] ) {
27 $bp = buddypress();
28 $wpfpath = WPF()->board->route ?: 'community';
29 $args = [
30 'path' => WPFORO_DIR,
31 'slug' => $wpfpath,
32 'root_slug' => isset( $bp->pages->forums->slug ) ? $bp->pages->forums->slug : $wpfpath,
33 'has_directory' => false,
34 'search_string' => __( 'Search Forums...', 'wpforo' ),
35 ];
36 parent::setup_globals( $args );
37 }
38
39 public function setup_nav( $main_nav = [], $sub_nav = [] ) {
40 if( ! is_user_logged_in() && ! bp_displayed_user_id() ) return;
41
42 // Add 'Forums' to the main navigation
43 $main_nav = [
44 'name' => __( 'Forums', 'wpforo' ),
45 'slug' => $this->slug,
46 'position' => 81,
47 'screen_function' => 'wpforo_bp_forums_screen_topics',
48 'default_subnav_slug' => 'topics',
49 'item_css_id' => $this->id,
50 ];
51
52 // Determine user to use
53 if( bp_displayed_user_id() ) {
54 $user_domain = bp_displayed_user_domain();
55 } elseif( bp_loggedin_user_domain() ) {
56 $user_domain = bp_loggedin_user_domain();
57 } else {
58 return;
59 }
60
61 // User link
62 $forums_link = trailingslashit( $user_domain . $this->slug );
63
64 // Topics started
65 $sub_nav[] = [
66 'name' => __( 'Topics Started', 'wpforo' ),
67 'slug' => 'topics',
68 'parent_url' => $forums_link,
69 'parent_slug' => $this->slug,
70 'screen_function' => 'wpforo_bp_forums_screen_topics',
71 'position' => 21,
72 'item_css_id' => 'wpf-topics',
73 ];
74
75 // Replies to topics
76 $sub_nav[] = [
77 'name' => __( 'Replies Created', 'wpforo' ),
78 'slug' => 'replies',
79 'parent_url' => $forums_link,
80 'parent_slug' => $this->slug,
81 'screen_function' => 'wpforo_bp_forums_screen_replies',
82 'position' => 41,
83 'item_css_id' => 'wpf-replies',
84 ];
85
86 // Liked Posts
87 $sub_nav[] = [
88 'name' => __( 'Liked Posts', 'wpforo' ),
89 'slug' => 'likes',
90 'parent_url' => $forums_link,
91 'parent_slug' => $this->slug,
92 'screen_function' => 'wpforo_bp_forums_screen_likes',
93 'position' => 61,
94 'item_css_id' => 'wpf-likes',
95 ];
96
97 // Subscribed topics (my profile only)
98 if( bp_is_my_profile() ) {
99 $sub_nav[] = [
100 'name' => __( 'Subscriptions', 'wpforo' ),
101 'slug' => 'subscriptions',
102 'parent_url' => $forums_link,
103 'parent_slug' => $this->slug,
104 'screen_function' => 'wpforo_bp_forums_screen_subscriptions',
105 'position' => 61,
106 'item_css_id' => 'wpf-subscriptions',
107 ];
108 }
109
110 parent::setup_nav( $main_nav, $sub_nav );
111 }
112
113 public function setup_title() {
114 $bp = buddypress();
115 if( bp_is_forums_component() ) {
116 if( bp_is_my_profile() ) {
117 $bp->bp_options_title = __( 'Forums', 'wpforo' );
118 } elseif( bp_is_user() ) {
119 $bp->bp_options_avatar = bp_core_fetch_avatar( [ 'item_id' => bp_displayed_user_id(), 'type' => 'thumb' ] );
120 $bp->bp_options_title = bp_get_displayed_user_fullname();
121 }
122 }
123 parent::setup_title();
124 }
125 }
126