PluginProbe
bbPress / 2.6.19
bbPress v2.6.19
2.6.19 2.6.18 2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 All 74 releases
bbpress / includes / extend / buddypress / functions.php

functions.php in bbPress 2.6.19, at includes/extend/buddypress/functions.php

930 lines 23.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Main bbPress BuddyPress Class
5 *
6 * @package bbPress
7 * @subpackage BuddyPress
8 */
9
10 // Exit if accessed directly
11 defined( 'ABSPATH' ) || exit;
12
13 // Hooks
14 add_filter( 'bp_modify_page_title', 'bbp_filter_modify_page_title', 10, 3 );
15 add_filter( 'bbp_get_user_id', 'bbp_filter_user_id', 10, 3 );
16 add_filter( 'bbp_is_single_user', 'bbp_filter_is_single_user', 10, 1 );
17 add_filter( 'bbp_is_user_home', 'bbp_filter_is_user_home', 10, 1 );
18
19 // Group Forum Root
20 add_action( 'load-settings_page_bbpress', 'bbp_maybe_create_group_forum_root' );
21 add_action( 'bbp_delete_forum', 'bbp_maybe_delete_group_forum_root' );
22
23 /** BuddyPress Helpers ********************************************************/
24
25 /**
26 * Return component name/ID ('forums' by default)
27 *
28 * This is used primarily for Notifications integration.
29 *
30 * @since 2.6.0 bbPress (r5232)
31 *
32 * @return string
33 */
34 function bbp_get_component_name() {
35
36 // Use existing ID or default
37 $retval = ! empty( bbpress()->extend->buddypress->id )
38 ? bbpress()->extend->buddypress->id
39 : 'forums';
40
41 // Filter & return
42 return apply_filters( 'bbp_get_component_name', $retval );
43 }
44
45 /**
46 * Filter the current bbPress user ID with the current BuddyPress user ID
47 *
48 * @since 2.1.0 bbPress (r3552)
49 *
50 * @param int $user_id
51 * @param bool $displayed_user_fallback
52 * @param bool $current_user_fallback
53 *
54 * @return int User ID
55 */
56 function bbp_filter_user_id( $user_id = 0, $displayed_user_fallback = true, $current_user_fallback = false ) {
57
58 // Define local variable
59 $bbp_user_id = 0;
60
61 // Get possible user ID's
62 $did = bp_displayed_user_id();
63 $lid = bp_loggedin_user_id();
64
65 // Easy empty checking
66 if ( ! empty( $user_id ) && is_numeric( $user_id ) ) {
67 $bbp_user_id = $user_id;
68
69 // Currently viewing or editing a user
70 } elseif ( ( true === $displayed_user_fallback ) && ! empty( $did ) ) {
71 $bbp_user_id = $did;
72
73 // Maybe fallback on the current_user ID
74 } elseif ( ( true === $current_user_fallback ) && ! empty( $lid ) ) {
75 $bbp_user_id = $lid;
76 }
77
78 return $bbp_user_id;
79 }
80
81 /**
82 * Filter the bbPress is_single_user function with BuddyPress equivalent
83 *
84 * @since 2.1.0 bbPress (r3552)
85 *
86 * @param bool $is Optional. Default false
87 * @return bool True if viewing single user, false if not
88 */
89 function bbp_filter_is_single_user( $is = false ) {
90 if ( ! empty( $is ) ) {
91 return $is;
92 }
93
94 return bp_is_user();
95 }
96
97 /**
98 * Filter the bbPress is_user_home function with BuddyPress equivalent
99 *
100 * @since 2.1.0 bbPress (r3552)
101 *
102 * @param bool $is Optional. Default false
103 * @return bool True if viewing single user, false if not
104 */
105 function bbp_filter_is_user_home( $is = false ) {
106 if ( ! empty( $is ) ) {
107 return $is;
108 }
109
110 return bp_is_my_profile();
111 }
112
113 /**
114 * Add the topic title to the <title> if viewing a single group forum topic
115 *
116 * @since 2.5.0 bbPress (r5161)
117 *
118 * @param string $new_title The title to filter
119 * @param string $old_title (Not used)
120 * @param string $sep The separator to use
121 * @return string The possibly modified title
122 */
123 function bbp_filter_modify_page_title( $new_title = '', $old_title = '', $sep = '' ) {
124
125 // Only filter if group forums are active
126 if ( bbp_is_group_forums_active() ) {
127
128 // Only filter for single group forum topics
129 if ( bp_is_group_forum_topic() || bp_is_group_forum_topic_edit() ) {
130 if ( ! bp_group_is_visible( bp_get_current_group_id() ) ) {
131 return $new_title;
132 }
133
134 $forum_ids = bbp_get_group_forum_ids();
135
136 if ( empty( $forum_ids ) ) {
137 return $new_title;
138 }
139
140 // Get a topic belonging to the current group's forums
141 $topic = get_posts(
142 array(
143 'name' => bp_action_variable( 1 ),
144 'post_parent__in' => $forum_ids,
145 'post_status' => array_keys( bbp_get_topic_statuses() ),
146 'post_type' => bbp_get_topic_post_type(),
147 'numberposts' => 1
148 )
149 );
150
151 // Add the title only when the topic and its forum are readable
152 if ( ! empty( $topic ) && bbp_user_can_view_forum( array( 'forum_id' => $topic[0]->post_parent ) ) && ( bbp_is_topic_public( $topic[0]->ID ) || current_user_can( 'read_topic', $topic[0]->ID ) ) ) {
153 $new_title .= bbp_get_topic_title( $topic[0]->ID ) . ' ' . $sep . ' ';
154 }
155 }
156 }
157
158 // Return the title
159 return $new_title;
160 }
161
162 /** BuddyPress Screens ********************************************************/
163
164 /**
165 * Hook bbPress topics template into plugins template
166 *
167 * @since 2.1.0 bbPress (r3552)
168 */
169 function bbp_member_forums_screen_topics() {
170 add_action( 'bp_template_content', 'bbp_member_forums_topics_content' );
171 bp_core_load_template( apply_filters( 'bbp_member_forums_screen_topics', 'members/single/plugins' ) );
172 }
173
174 /**
175 * Hook bbPress replies template into plugins template
176 *
177 * @since 2.1.0 bbPress (r3552)
178 */
179 function bbp_member_forums_screen_replies() {
180 add_action( 'bp_template_content', 'bbp_member_forums_replies_content' );
181 bp_core_load_template( apply_filters( 'bbp_member_forums_screen_replies', 'members/single/plugins' ) );
182 }
183
184 /**
185 * Hook bbPress engagements template into plugins template
186 *
187 * @since 2.6.0 bbPress (r6320)
188 */
189 function bbp_member_forums_screen_engagements() {
190 add_action( 'bp_template_content', 'bbp_member_forums_engagements_content' );
191 bp_core_load_template( apply_filters( 'bbp_member_forums_screen_engagements', 'members/single/plugins' ) );
192 }
193
194 /**
195 * Hook bbPress favorites template into plugins template
196 *
197 * @since 2.1.0 bbPress (r3552)
198 */
199 function bbp_member_forums_screen_favorites() {
200 add_action( 'bp_template_content', 'bbp_member_forums_favorites_content' );
201 bp_core_load_template( apply_filters( 'bbp_member_forums_screen_favorites', 'members/single/plugins' ) );
202 }
203
204 /**
205 * Hook bbPress subscriptions template into plugins template
206 *
207 * @since 2.1.0 bbPress (r3552)
208 */
209 function bbp_member_forums_screen_subscriptions() {
210 add_action( 'bp_template_content', 'bbp_member_forums_subscriptions_content' );
211 bp_core_load_template( apply_filters( 'bbp_member_forums_screen_subscriptions', 'members/single/plugins' ) );
212 }
213
214 /** BuddyPress Templates ******************************************************/
215
216 /**
217 * Get the topics created template part
218 *
219 * @since 2.1.0 bbPress (r3552)
220 */
221 function bbp_member_forums_topics_content() {
222 ?>
223
224 <div id="bbpress-forums" class="bbpress-wrapper">
225
226 <?php bbp_get_template_part( 'user', 'topics-created' ); ?>
227
228 </div>
229
230 <?php
231 }
232
233 /**
234 * Get the topics replied to template part
235 *
236 * @since 2.1.0 bbPress (r3552)
237 */
238 function bbp_member_forums_replies_content() {
239 ?>
240
241 <div id="bbpress-forums" class="bbpress-wrapper">
242
243 <?php bbp_get_template_part( 'user', 'replies-created' ); ?>
244
245 </div>
246
247 <?php
248 }
249
250 /**
251 * Get the topic engagements template part
252 *
253 * @since 2.6.0 bbPress (r6320)
254 */
255 function bbp_member_forums_engagements_content() {
256 ?>
257
258 <div id="bbpress-forums" class="bbpress-wrapper">
259
260 <?php bbp_get_template_part( 'user', 'engagements' ); ?>
261
262 </div>
263
264 <?php
265 }
266
267 /**
268 * Get the topics favorited template part
269 *
270 * @since 2.1.0 bbPress (r3552)
271 */
272 function bbp_member_forums_favorites_content() {
273 ?>
274
275 <div id="bbpress-forums" class="bbpress-wrapper">
276
277 <?php bbp_get_template_part( 'user', 'favorites' ); ?>
278
279 </div>
280
281 <?php
282 }
283
284 /**
285 * Get the topics subscribed template part
286 *
287 * @since 2.1.0 bbPress (r3552)
288 */
289 function bbp_member_forums_subscriptions_content() {
290 ?>
291
292 <div id="bbpress-forums" class="bbpress-wrapper">
293
294 <?php bbp_get_template_part( 'user', 'subscriptions' ); ?>
295
296 </div>
297
298 <?php
299 }
300
301 /** Forum Group Root **********************************************************/
302
303 /**
304 * Clean up the group root setting if the forum is being deleted
305 *
306 * @since 2.6.0 bbPress (r6485)
307 *
308 * @param int $forum_id The forum ID being deleted
309 */
310 function bbp_maybe_delete_group_forum_root( $forum_id = 0 ) {
311
312 // Bail if no forum ID
313 $forum_id = bbp_get_forum_id();
314 if ( empty( $forum_id ) ) {
315 return;
316 }
317
318 // Get the group root
319 $group_root = (int) get_option( '_bbp_group_forums_root_id', 0 );
320
321 // Delete the group root if the forum just got deleted
322 if ( $group_root === $forum_id ) {
323 delete_option( '_bbp_group_forums_root_id' );
324 }
325 }
326
327 /**
328 * Handle the new group forum root creation
329 *
330 * @since 2.6.0 bbPress (r6485)
331 *
332 * @return
333 */
334 function bbp_maybe_create_group_forum_root() {
335
336 // Bail if no nonce
337 if ( empty( $_GET['_wpnonce'] ) || ( empty( $_GET['create'] ) || ( 'bbp-group-forum-root' !== $_GET['create'] ) ) ) {
338 return;
339 }
340
341 // Bail if user cannot publish forums
342 if ( ! current_user_can( 'publish_forums' ) ) {
343 return;
344 }
345
346 // Bail if nonce check fails
347 if ( ! wp_verify_nonce( $_GET['_wpnonce'], '_bbp_group_forums_root_id' ) ) {
348 return;
349 }
350
351 // Create new forum
352 $forum_id = bbp_insert_forum(
353 array( 'post_title' => esc_html__( 'Group Forums', 'bbpress' ) ),
354 array( 'forum_type' => 'category' )
355 );
356
357 // Update & redirect
358 if ( ! empty( $forum_id ) ) {
359
360 // Create
361 update_option( '_bbp_group_forums_root_id', $forum_id );
362
363 // Redirect
364 bbp_redirect(
365 add_query_arg(
366 array(
367 'page' => 'bbpress',
368 'updated' => true
369 ),
370 admin_url( 'options-general.php' )
371 )
372 );
373 }
374 }
375
376 /** Forum/Group Sync **********************************************************/
377
378 /**
379 * These functions are used to keep the many-to-many relationships between
380 * groups and forums synchronized. Each forum and group stores pointers to each
381 * other in their respective meta. This way if a group or forum is deleted
382 * their associations can be updated without much effort.
383 */
384
385 /**
386 * Get forum ID's for a group
387 *
388 * @since 2.1.0 bbPress (r3654)
389 *
390 * @param int $group_id
391 */
392 function bbp_get_group_forum_ids( $group_id = 0 ) {
393
394 // Assume no forums
395 $forum_ids = array();
396
397 // Use current group if none is set
398 if ( empty( $group_id ) ) {
399 $group_id = bp_get_current_group_id();
400 }
401
402 // Get the forums
403 if ( ! empty( $group_id ) ) {
404 $forum_ids = groups_get_groupmeta( $group_id, 'forum_id' );
405 }
406
407 // Make sure result is an array of ints
408 $forum_ids = array_filter( wp_parse_id_list( $forum_ids ) );
409
410 // Filter & return
411 return (array) apply_filters( 'bbp_get_group_forum_ids', $forum_ids, $group_id );
412 }
413
414 /**
415 * Get group ID's for a forum
416 *
417 * @since 2.1.0 bbPress (r3654)
418 *
419 * @param int $forum_id
420 */
421 function bbp_get_forum_group_ids( $forum_id = 0 ) {
422
423 // Assume no forums
424 $group_ids = array();
425
426 // Use current group if none is set
427 if ( empty( $forum_id ) ) {
428 $forum_id = bbp_get_forum_id();
429 }
430
431 // Get the forums
432 if ( ! empty( $forum_id ) ) {
433 $group_ids = get_post_meta( $forum_id, '_bbp_group_ids', true );
434 }
435
436 // Make sure result is an array of ints
437 $group_ids = array_filter( wp_parse_id_list( $group_ids ) );
438
439 // Filter & return
440 return (array) apply_filters( 'bbp_get_forum_group_ids', $group_ids, $forum_id );
441 }
442
443 /**
444 * Get forum ID's for a group
445 *
446 * @since 2.1.0 bbPress (r3654)
447 *
448 * @param int $group_id
449 */
450 function bbp_update_group_forum_ids( $group_id = 0, $forum_ids = array() ) {
451
452 // Use current group if none is set
453 if ( empty( $group_id ) ) {
454 $group_id = bp_get_current_group_id();
455 }
456
457 // Trim out any empties
458 $forum_ids = array_filter( wp_parse_id_list( $forum_ids ) );
459
460 // Get the forums
461 return groups_update_groupmeta( $group_id, 'forum_id', $forum_ids );
462 }
463
464 /**
465 * Update group ID's for a forum
466 *
467 * @since 2.1.0 bbPress (r3654)
468 *
469 * @param int $forum_id
470 */
471 function bbp_update_forum_group_ids( $forum_id = 0, $group_ids = array() ) {
472 $forum_id = bbp_get_forum_id( $forum_id );
473
474 // Trim out any empties
475 $group_ids = array_filter( wp_parse_id_list( $group_ids ) );
476
477 // Get the forums
478 return update_post_meta( $forum_id, '_bbp_group_ids', $group_ids );
479 }
480
481 /**
482 * Add a group to a forum
483 *
484 * @since 2.1.0 bbPress (r3654)
485 *
486 * @param int $group_id
487 */
488 function bbp_add_group_id_to_forum( $forum_id = 0, $group_id = 0 ) {
489
490 // Validate forum_id
491 $forum_id = bbp_get_forum_id( $forum_id );
492
493 // Use current group if none is set
494 if ( empty( $group_id ) ) {
495 $group_id = bp_get_current_group_id();
496 }
497
498 // Get current group IDs
499 $group_ids = bbp_get_forum_group_ids( $forum_id );
500
501 // Maybe update the groups forums
502 if ( ! in_array( $group_id, $group_ids, true ) ) {
503 $group_ids[] = $group_id;
504 return bbp_update_forum_group_ids( $forum_id, $group_ids );
505 }
506 }
507
508 /**
509 * Remove a forum from a group
510 *
511 * @since 2.1.0 bbPress (r3654)
512 *
513 * @param int $group_id
514 */
515 function bbp_add_forum_id_to_group( $group_id = 0, $forum_id = 0 ) {
516
517 // Validate forum_id
518 $forum_id = bbp_get_forum_id( $forum_id );
519
520 // Use current group if none is set
521 if ( empty( $group_id ) ) {
522 $group_id = bp_get_current_group_id();
523 }
524
525 // Get current group IDs
526 $forum_ids = bbp_get_group_forum_ids( $group_id );
527
528 // Maybe update the groups forums
529 if ( ! in_array( $forum_id, $forum_ids, true ) ) {
530 $forum_ids[] = $forum_id;
531 return bbp_update_group_forum_ids( $group_id, $forum_ids );
532 }
533 }
534
535 /**
536 * Remove a group from a forum
537 *
538 * @since 2.1.0 bbPress (r3654)
539 *
540 * @param int $group_id
541 */
542 function bbp_remove_group_id_from_forum( $forum_id = 0, $group_id = 0 ) {
543
544 // Validate forum_id
545 $forum_id = bbp_get_forum_id( $forum_id );
546
547 // Use current group if none is set
548 if ( empty( $group_id ) ) {
549 $group_id = bp_get_current_group_id();
550 }
551
552 // Get current group IDs
553 $group_ids = bbp_get_forum_group_ids( $forum_id );
554
555 // Maybe update the groups forums
556 if ( in_array( $group_id, $group_ids, true ) ) {
557 $group_ids = array_diff( array_values( $group_ids ), (array) $group_id );
558 return bbp_update_forum_group_ids( $forum_id, $group_ids );
559 }
560 }
561
562 /**
563 * Remove a forum from a group
564 *
565 * @since 2.1.0 bbPress (r3654)
566 *
567 * @param int $group_id
568 */
569 function bbp_remove_forum_id_from_group( $group_id = 0, $forum_id = 0 ) {
570
571 // Validate forum_id
572 $forum_id = bbp_get_forum_id( $forum_id );
573
574 // Use current group if none is set
575 if ( empty( $group_id ) ) {
576 $group_id = bp_get_current_group_id();
577 }
578
579 // Get current group IDs
580 $forum_ids = bbp_get_group_forum_ids( $group_id );
581
582 // Maybe update the groups forums
583 if ( in_array( $forum_id, $forum_ids, true ) ) {
584 $forum_ids = array_diff( array_values( $forum_ids ), (array) $forum_id );
585 return bbp_update_group_forum_ids( $group_id, $forum_ids );
586 }
587 }
588
589 /**
590 * Remove a group from all forums
591 *
592 * @since 2.1.0 bbPress (r3654)
593 *
594 * @param int $group_id
595 */
596 function bbp_remove_group_id_from_all_forums( $group_id = 0 ) {
597
598 // Use current group if none is set
599 if ( empty( $group_id ) ) {
600 $group_id = bp_get_current_group_id();
601 }
602
603 // Get current group IDs
604 $forum_ids = bbp_get_group_forum_ids( $group_id );
605
606 // Loop through forums and remove this group from each one
607 foreach ( $forum_ids as $forum_id ) {
608 bbp_remove_group_id_from_forum( $group_id, $forum_id );
609 }
610 }
611
612 /**
613 * Remove a forum from all groups
614 *
615 * @since 2.1.0 bbPress (r3654)
616 *
617 * @param int $forum_id
618 */
619 function bbp_remove_forum_id_from_all_groups( $forum_id = 0 ) {
620
621 // Validate
622 $forum_id = bbp_get_forum_id( $forum_id );
623 $group_ids = bbp_get_forum_group_ids( $forum_id );
624
625 // Loop through groups and remove this forum from each one
626 foreach ( $group_ids as $group_id ) {
627 bbp_remove_forum_id_from_group( $forum_id, $group_id );
628 }
629 }
630
631 /**
632 * Return true if a forum is a group forum
633 *
634 * @since 2.3.0 bbPress (r4572)
635 *
636 * @param int $forum_id
637 * @return bool True if it is a group forum, false if not
638 */
639 function bbp_is_forum_group_forum( $forum_id = 0 ) {
640
641 // Validate
642 $forum_id = bbp_get_forum_id( $forum_id );
643
644 // Check for group ID's
645 $group_ids = bbp_get_forum_group_ids( $forum_id );
646
647 // Check if the forum has groups
648 $retval = (bool) ! empty( $group_ids );
649
650 // Filter & return
651 return (bool) apply_filters( 'bbp_is_forum_group_forum', $retval, $forum_id, $group_ids );
652 }
653
654 /*** Group Member Status ******************************************************/
655
656 /**
657 * Is the current user an admin of the current group
658 *
659 * @since 2.3.0 bbPress (r4633)
660 *
661 * @return bool If current user is an admin of the current group
662 */
663 function bbp_group_is_admin() {
664
665 // Bail if user is not logged in or not looking at a group
666 if ( ! is_user_logged_in() || ! bp_is_group() ) {
667 return false;
668 }
669
670 $bbp = bbpress();
671
672 // Set the global if not set
673 if ( ! isset( $bbp->current_user->is_group_admin ) ) {
674 $bbp->current_user->is_group_admin = groups_is_user_admin( bp_loggedin_user_id(), bp_get_current_group_id() );
675 }
676
677 // Return the value
678 return (bool) $bbp->current_user->is_group_admin;
679 }
680
681 /**
682 * Is the current user a moderator of the current group
683 *
684 * @since 2.3.0 bbPress (r4633)
685 *
686 * @return bool If current user is a moderator of the current group
687 */
688 function bbp_group_is_mod() {
689
690 // Bail if user is not logged in or not looking at a group
691 if ( ! is_user_logged_in() || ! bp_is_group() ) {
692 return false;
693 }
694
695 $bbp = bbpress();
696
697 // Set the global if not set
698 if ( ! isset( $bbp->current_user->is_group_mod ) ) {
699 $bbp->current_user->is_group_mod = groups_is_user_mod( bp_loggedin_user_id(), bp_get_current_group_id() );
700 }
701
702 // Return the value
703 return (bool) $bbp->current_user->is_group_mod;
704 }
705
706 /**
707 * Is the current user a member of the current group
708 *
709 * @since 2.3.0 bbPress (r4633)
710 *
711 * @return bool If current user is a member of the current group
712 */
713 function bbp_group_is_member() {
714
715 // Bail if user is not logged in or not looking at a group
716 if ( ! is_user_logged_in() || ! bp_is_group() ) {
717 return false;
718 }
719
720 $bbp = bbpress();
721
722 // Set the global if not set
723 if ( ! isset( $bbp->current_user->is_group_member ) ) {
724 $bbp->current_user->is_group_member = groups_is_user_member( bp_loggedin_user_id(), bp_get_current_group_id() );
725 }
726
727 // Return the value
728 return (bool) $bbp->current_user->is_group_member;
729 }
730
731 /**
732 * Is the current user banned from the current group
733 *
734 * @since 2.3.0 bbPress (r4633)
735 *
736 * @return bool If current user is banned from the current group
737 */
738 function bbp_group_is_banned() {
739
740 // Bail if user is not logged in or not looking at a group
741 if ( ! is_user_logged_in() || ! bp_is_group() ) {
742 return false;
743 }
744
745 $bbp = bbpress();
746
747 // Set the global if not set
748 if ( ! isset( $bbp->current_user->is_group_banned ) ) {
749 $bbp->current_user->is_group_banned = groups_is_user_banned( bp_loggedin_user_id(), bp_get_current_group_id() );
750 }
751
752 // Return the value
753 return (bool) $bbp->current_user->is_group_banned;
754 }
755
756 /**
757 * Is the current user the creator of the current group
758 *
759 * @since 2.3.0 bbPress (r4633)
760 *
761 * @return bool If current user the creator of the current group
762 */
763 function bbp_group_is_creator() {
764
765 // Bail if user is not logged in or not looking at a group
766 if ( ! is_user_logged_in() || ! bp_is_group() ) {
767 return false;
768 }
769
770 $bbp = bbpress();
771
772 // Set the global if not set
773 if ( ! isset( $bbp->current_user->is_group_creator ) ) {
774 $bbp->current_user->is_group_creator = groups_is_user_creator( bp_loggedin_user_id(), bp_get_current_group_id() );
775 }
776
777 // Return the value
778 return (bool) $bbp->current_user->is_group_creator;
779 }
780
781 /* BuddyPress Activity Action Callbacks ***************************************/
782
783 /**
784 * Return an array of allowed activity actions
785 *
786 * @since 2.6.0 bbPress (r6370)
787 *
788 * @return array
789 */
790 function bbp_get_activity_actions() {
791
792 // Filter & return
793 return (array) apply_filters( 'bbp_get_activity_actions',
794 array(
795
796 'topic' =>
797 /* translators: 1: User linked profile, 2: Topic linked title, 3: Forum linked title */
798 esc_html__( '%1$s started the topic %2$s in the forum %3$s', 'bbpress' ),
799
800 'reply' =>
801 /* translators: 1: User linked profile, 2: Topic linked title, 3: Forum linked title */
802 esc_html__( '%1$s replied to the topic %2$s in the forum %3$s', 'bbpress' )
803 )
804 );
805 }
806
807 /**
808 * Generic function to format the dynamic BuddyPress activity action for new
809 * topics/replies.
810 *
811 * @since 2.6.0 bbPress (r6370)
812 *
813 * @param string $type The type of post. Expects `topic` or `reply`.
814 * @param string $action The current action string.
815 * @param BP_Activity_Activity $activity The BuddyPress activity object.
816 *
817 * @return string The formatted activity action.
818 */
819 function bbp_format_activity_action_new_post( $type = '', $action = '', $activity = false ) {
820
821 // Get actions
822 $actions = bbp_get_activity_actions();
823
824 // Bail early if we don't have a valid type
825 if ( ! in_array( $type, array_keys( $actions ), true ) ) {
826 return $action;
827 }
828
829 // Bail if intercepted
830 $intercept = bbp_maybe_intercept( __FUNCTION__, func_get_args() );
831 if ( bbp_is_intercepted( $intercept ) ) {
832 return $intercept;
833 }
834
835 // Groups component
836 if ( 'groups' === $activity->component ) {
837 if ( 'topic' === $type ) {
838 $topic_id = bbp_get_topic_id( $activity->secondary_item_id );
839 $forum_id = bbp_get_topic_forum_id( $topic_id );
840 } else {
841 $topic_id = bbp_get_reply_topic_id( $activity->secondary_item_id );
842 $forum_id = bbp_get_topic_forum_id( $topic_id );
843 }
844
845 // General component (bbpress/forums/other)
846 } elseif ( 'topic' === $type ) {
847 $topic_id = bbp_get_topic_id( $activity->item_id );
848 $forum_id = bbp_get_forum_id( $activity->secondary_item_id );
849 } else {
850 $topic_id = bbp_get_topic_id( $activity->secondary_item_id );
851 $forum_id = bbp_get_topic_forum_id( $topic_id );
852 }
853
854 // User link for topic author
855 $user_link = bbp_get_user_profile_link( $activity->user_id );
856
857 // Topic link
858 $topic_permalink = bbp_get_topic_permalink( $topic_id );
859 $topic_title = get_post_field( 'post_title', $topic_id, 'raw' );
860 $topic_link = '<a href="' . esc_url( $topic_permalink ) . '">' . esc_html( $topic_title ) . '</a>';
861
862 // Forum link
863 $forum_permalink = bbp_get_forum_permalink( $forum_id );
864 $forum_title = get_post_field( 'post_title', $forum_id, 'raw' );
865 $forum_link = '<a href="' . esc_url( $forum_permalink ) . '">' . esc_html( $forum_title ) . '</a>';
866
867 // Format
868 $activity_action = sprintf( $actions[ $type ], $user_link, $topic_link, $forum_link );
869
870 /**
871 * Filters the formatted activity action new activity string.
872 *
873 * @since 2.6.0 bbPress (r6370)
874 *
875 * @param string $activity_action Activity action string value
876 * @param string $type The type of post. Expects `topic` or `reply`.
877 * @param string $action The current action string.
878 * @param BP_Activity_Activity $activity The BuddyPress activity object.
879 */
880 return apply_filters( 'bbp_format_activity_action_new_post', $activity_action, $type, $action, $activity );
881 }
882
883 /**
884 * Formats the dynamic BuddyPress activity action for new topics.
885 *
886 * @since 2.6.0 bbPress (r6370)
887 *
888 * @param string $action The current action string
889 * @param object $activity The BuddyPress activity object
890 *
891 * @return string The formatted activity action.
892 */
893 function bbp_format_activity_action_new_topic( $action, $activity ) {
894 $action = bbp_format_activity_action_new_post( bbp_get_topic_post_type(), $action, $activity );
895
896 /**
897 * Filters the formatted activity action new topic string.
898 *
899 * @since 2.6.0 bbPress (r6370)
900 *
901 * @param string $action Activity action string value
902 * @param BP_Activity_Activity $activity Activity item object
903 */
904 return apply_filters( 'bbp_format_activity_action_new_topic', $action, $activity );
905 }
906
907 /**
908 * Formats the dynamic BuddyPress activity action for new replies.
909 *
910 * @since 2.6.0 bbPress (r6370)
911 *
912 * @param string $action The current action string
913 * @param object $activity The BuddyPress activity object
914 *
915 * @return string The formatted activity action
916 */
917 function bbp_format_activity_action_new_reply( $action, $activity ) {
918 $action = bbp_format_activity_action_new_post( bbp_get_reply_post_type(), $action, $activity );
919
920 /**
921 * Filters the formatted activity action new reply string.
922 *
923 * @since 2.6.0 bbPress (r6370)
924 *
925 * @param string $action Activity action string value
926 * @param BP_Activity_Activity $activity Activity item object
927 */
928 return apply_filters( 'bbp_format_activity_action_new_reply', $action, $activity );
929 }
930