PluginProbe
bbPress / 2.0.3
bbPress v2.0.3
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 2.2 2.2.1 2.2.2 All 71 releases
bbpress / bbp-includes / bbp-user-template.php

bbp-user-template.php in bbPress 2.0.3, at bbp-includes/bbp-user-template.php

1,337 lines 41.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress User Template Tags
5 *
6 * @package bbPress
7 * @subpackage TemplateTags
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /** Users *********************************************************************/
14
15 /**
16 * Output a validated user id
17 *
18 * @since bbPress (r2729)
19 *
20 * @param int $user_id Optional. User id
21 * @param bool $displayed_user_fallback Fallback on displayed user?
22 * @param bool $current_user_fallback Fallback on current user?
23 * @uses bbp_get_user_id() To get the user id
24 */
25 function bbp_user_id( $user_id = 0, $displayed_user_fallback = true, $current_user_fallback = false ) {
26 echo bbp_get_user_id( $user_id, $displayed_user_fallback, $current_user_fallback );
27 }
28 /**
29 * Return a validated user id
30 *
31 * @since bbPress (r2729)
32 *
33 * @param int $user_id Optional. User id
34 * @param bool $displayed_user_fallback Fallback on displayed user?
35 * @param bool $current_user_fallback Fallback on current user?
36 * @uses get_query_var() To get the 'bbp_user_id' query var
37 * @uses apply_filters() Calls 'bbp_get_user_id' with the user id
38 * @return int Validated user id
39 */
40 function bbp_get_user_id( $user_id = 0, $displayed_user_fallback = true, $current_user_fallback = false ) {
41 global $bbp;
42
43 // Easy empty checking
44 if ( !empty( $user_id ) && is_numeric( $user_id ) )
45 $bbp_user_id = $user_id;
46
47 // Currently viewing or editing a user
48 elseif ( ( true == $displayed_user_fallback ) && !empty( $bbp->displayed_user->ID ) )
49 $bbp_user_id = $bbp->displayed_user->ID;
50
51 // Maybe fallback on the current_user ID
52 elseif ( ( true == $current_user_fallback ) && !empty( $bbp->current_user->ID ) )
53 $bbp_user_id = $bbp->current_user->ID;
54
55 // Failsafe
56 else
57 $bbp_user_id = get_query_var( 'bbp_user_id' );
58
59 return apply_filters( 'bbp_get_user_id', (int) $bbp_user_id );
60 }
61
62 /**
63 * Output ID of current user
64 *
65 * @since bbPress (r2574)
66 *
67 * @uses bbp_get_current_user_id() To get the current user id
68 */
69 function bbp_current_user_id() {
70 echo bbp_get_current_user_id();
71 }
72 /**
73 * Return ID of current user
74 *
75 * @since bbPress (r2574)
76 *
77 * @uses bbp_get_user_id() To get the current user id
78 * @uses apply_filters() Calls 'bbp_get_current_user_id' with the id
79 * @return int Current user id
80 */
81 function bbp_get_current_user_id() {
82 return apply_filters( 'bbp_get_current_user_id', bbp_get_user_id( 0, false, true ) );
83 }
84
85 /**
86 * Output ID of displayed user
87 *
88 * @since bbPress (r2688)
89 *
90 * @uses bbp_get_displayed_user_id() To get the displayed user id
91 */
92 function bbp_displayed_user_id() {
93 echo bbp_get_displayed_user_id();
94 }
95 /**
96 * Return ID of displayed user
97 *
98 * @since bbPress (r2688)
99 *
100 * @uses bbp_get_user_id() To get the displayed user id
101 * @uses apply_filters() Calls 'bbp_get_displayed_user_id' with the id
102 * @return int Displayed user id
103 */
104 function bbp_get_displayed_user_id() {
105 return apply_filters( 'bbp_get_displayed_user_id', bbp_get_user_id( 0, true, false ) );
106 }
107
108 /**
109 * Return a sanitized user field value
110 *
111 * @since bbPress (r2688)
112 *
113 * @param string $field Field to get
114 * @uses sanitize_text_field() To sanitize the field
115 * @uses esc_attr() To sanitize the field
116 * @return string|bool Value of the field if it exists, else false
117 */
118 function bbp_get_displayed_user_field( $field = '' ) {
119 global $bbp;
120
121 // Return field if exists
122 if ( isset( $bbp->displayed_user->$field ) )
123 return esc_attr( sanitize_text_field( $bbp->displayed_user->$field ) );
124
125 // Return empty
126 return false;
127 }
128
129 /**
130 * Output name of current user
131 *
132 * @since bbPress (r2574)
133 *
134 * @uses bbp_get_current_user_name() To get the current user name
135 */
136 function bbp_current_user_name() {
137 echo bbp_get_current_user_name();
138 }
139 /**
140 * Return name of current user
141 *
142 * @since bbPress (r2574)
143 *
144 * @uses apply_filters() Calls 'bbp_get_current_user_name' with the
145 * current user name
146 * @return string
147 */
148 function bbp_get_current_user_name() {
149 global $user_identity;
150
151 $current_user_name = is_user_logged_in() ? $user_identity : __( 'Anonymous', 'bbpress' );
152
153 return apply_filters( 'bbp_get_current_user_name', $current_user_name );
154 }
155
156 /**
157 * Output avatar of current user
158 *
159 * @since bbPress (r2574)
160 *
161 * @param int $size Size of the avatar. Defaults to 40
162 * @uses bbp_get_current_user_avatar() To get the current user avatar
163 */
164 function bbp_current_user_avatar( $size = 40 ) {
165 echo bbp_get_current_user_avatar( $size );
166 }
167
168 /**
169 * Return avatar of current user
170 *
171 * @since bbPress (r2574)
172 *
173 * @param int $size Size of the avatar. Defaults to 40
174 * @uses bbp_get_current_user_id() To get the current user id
175 * @uses bbp_get_current_anonymous_user_data() To get the current
176 * anonymous user's email
177 * @uses get_avatar() To get the avatar
178 * @uses apply_filters() Calls 'bbp_get_current_user_avatar' with the
179 * avatar and size
180 * @return string Current user avatar
181 */
182 function bbp_get_current_user_avatar( $size = 40 ) {
183
184 if ( !$user = bbp_get_current_user_id() )
185 $user = bbp_get_current_anonymous_user_data( 'email' );
186
187 return apply_filters( 'bbp_get_current_user_avatar', get_avatar( $user, $size ), $size );
188 }
189
190 /**
191 * Output link to the profile page of a user
192 *
193 * @since bbPress (r2688)
194 *
195 * @param int $user_id Optional. User id
196 * @uses bbp_get_user_profile_link() To get user profile link
197 */
198 function bbp_user_profile_link( $user_id = 0 ) {
199 echo bbp_get_user_profile_link( $user_id );
200 }
201 /**
202 * Return link to the profile page of a user
203 *
204 * @since bbPress (r2688)
205 *
206 * @param int $user_id Optional. User id
207 * @uses bbp_get_user_id() To get user id
208 * @uses get_userdata() To get user data
209 * @uses bbp_get_user_profile_url() To get user profile url
210 * @uses apply_filters() Calls 'bbp_get_user_profile_link' with the user
211 * profile link and user id
212 * @return string User profile link
213 */
214 function bbp_get_user_profile_link( $user_id = 0 ) {
215 if ( !$user_id = bbp_get_user_id( $user_id ) )
216 return false;
217
218 $user = get_userdata( $user_id );
219 $name = esc_attr( $user->display_name );
220 $user_link = '<a href="' . bbp_get_user_profile_url( $user_id ) . '" title="' . $name . '">' . $name . '</a>';
221
222 return apply_filters( 'bbp_get_user_profile_link', $user_link, $user_id );
223 }
224
225 /**
226 * Output URL to the profile page of a user
227 *
228 * @since bbPress (r2688)
229 *
230 * @param int $user_id Optional. User id
231 * @param string $user_nicename Optional. User nicename
232 * @uses bbp_get_user_profile_url() To get user profile url
233 */
234 function bbp_user_profile_url( $user_id = 0, $user_nicename = '' ) {
235 echo bbp_get_user_profile_url( $user_id );
236 }
237 /**
238 * Return URL to the profile page of a user
239 *
240 * @since bbPress (r2688)
241 *
242 * @param int $user_id Optional. User id
243 * @param string $user_nicename Optional. User nicename
244 * @uses bbp_get_user_id() To get user id
245 * @uses WP_Rewrite::using_permalinks() To check if the blog is using
246 * permalinks
247 * @uses add_query_arg() To add custom args to the url
248 * @uses home_url() To get blog home url
249 * @uses apply_filters() Calls 'bbp_get_user_profile_url' with the user
250 * profile url, user id and user nicename
251 * @return string User profile url
252 */
253 function bbp_get_user_profile_url( $user_id = 0, $user_nicename = '' ) {
254 global $wp_rewrite, $bbp;
255
256 // Use displayed user ID if there is one, and one isn't requested
257 if ( !$user_id = bbp_get_user_id( $user_id ) )
258 return false;
259
260 // Allow early overriding of the profile URL to cut down on processing
261 $early_profile_url = apply_filters( 'bbp_pre_get_user_profile_url', (int) $user_id );
262 if ( is_string( $early_profile_url ) )
263 return $early_profile_url;
264
265 // Pretty permalinks
266 if ( $wp_rewrite->using_permalinks() ) {
267 $url = $wp_rewrite->root . $bbp->user_slug . '/%' . $bbp->user_id . '%';
268
269 // Get username if not passed
270 if ( empty( $user_nicename ) ) {
271 $user = get_userdata( $user_id );
272 if ( !empty( $user->user_nicename ) ) {
273 $user_nicename = $user->user_nicename;
274 }
275 }
276
277 $url = str_replace( '%' . $bbp->user_id . '%', $user_nicename, $url );
278 $url = home_url( user_trailingslashit( $url ) );
279
280 // Unpretty permalinks
281 } else {
282 $url = add_query_arg( array( $bbp->user_id => $user_id ), home_url( '/' ) );
283 }
284
285 return apply_filters( 'bbp_get_user_profile_url', $url, $user_id, $user_nicename );
286
287 }
288
289 /**
290 * Output link to the profile edit page of a user
291 *
292 * @since bbPress (r2688)
293 *
294 * @param int $user_id Optional. User id
295 * @uses bbp_get_user_profile_edit_link() To get user profile edit link
296 */
297 function bbp_user_profile_edit_link( $user_id = 0 ) {
298 echo bbp_get_user_profile_edit_link( $user_id );
299 }
300 /**
301 * Return link to the profile edit page of a user
302 *
303 * @since bbPress (r2688)
304 *
305 * @param int $user_id Optional. User id
306 * @uses bbp_get_user_id() To get user id
307 * @uses get_userdata() To get user data
308 * @uses bbp_get_user_profile_edit_url() To get user profile edit url
309 * @uses apply_filters() Calls 'bbp_get_user_profile_link' with the edit
310 * link and user id
311 * @return string User profile edit link
312 */
313 function bbp_get_user_profile_edit_link( $user_id = 0 ) {
314 if ( !$user_id = bbp_get_user_id( $user_id ) )
315 return false;
316
317 $user = get_userdata( $user_id );
318 $name = $user->display_name;
319 $edit_link = '<a href="' . bbp_get_user_profile_url( $user_id ) . '" title="' . esc_attr( $name ) . '">' . $name . '</a>';
320 return apply_filters( 'bbp_get_user_profile_link', $edit_link, $user_id );
321 }
322
323 /**
324 * Output URL to the profile edit page of a user
325 *
326 * @since bbPress (r2688)
327 *
328 * @param int $user_id Optional. User id
329 * @param string $user_nicename Optional. User nicename
330 * @uses bbp_get_user_profile_edit_url() To get user profile edit url
331 */
332 function bbp_user_profile_edit_url( $user_id = 0, $user_nicename = '' ) {
333 echo bbp_get_user_profile_edit_url( $user_id );
334 }
335 /**
336 * Return URL to the profile edit page of a user
337 *
338 * @since bbPress (r2688)
339 *
340 * @param int $user_id Optional. User id
341 * @param string $user_nicename Optional. User nicename
342 * @uses bbp_get_user_id() To get user id
343 * @uses WP_Rewrite::using_permalinks() To check if the blog is using
344 * permalinks
345 * @uses add_query_arg() To add custom args to the url
346 * @uses home_url() To get blog home url
347 * @uses apply_filters() Calls 'bbp_get_user_edit_profile_url' with the
348 * edit profile url, user id and user nicename
349 * @return string
350 */
351 function bbp_get_user_profile_edit_url( $user_id = 0, $user_nicename = '' ) {
352 global $wp_rewrite, $bbp;
353
354 if ( !$user_id = bbp_get_user_id( $user_id ) )
355 return;
356
357 // Pretty permalinks
358 if ( $wp_rewrite->using_permalinks() ) {
359 $url = $wp_rewrite->root . $bbp->user_slug . '/%' . $bbp->user_id . '%/' . $bbp->edit_id;
360
361 // Get username if not passed
362 if ( empty( $user_nicename ) ) {
363 $user = get_userdata( $user_id );
364 if ( !empty( $user->user_nicename ) ) {
365 $user_nicename = $user->user_nicename;
366 }
367 }
368
369 $url = str_replace( '%' . $bbp->user_id . '%', $user_nicename, $url );
370 $url = home_url( user_trailingslashit( $url ) );
371
372 // Unpretty permalinks
373 } else {
374 $url = add_query_arg( array( $bbp->user_id => $user_id, $bbp->edit_id => '1' ), home_url( '/' ) );
375 }
376
377 return apply_filters( 'bbp_get_user_edit_profile_url', $url, $user_id, $user_nicename );
378
379 }
380
381 /**
382 * Output the link to the admin section
383 *
384 * @since bbPress (r2827)
385 *
386 * @param mixed $args Optional. See {@link bbp_get_admin_link()}
387 * @uses bbp_get_admin_link() To get the admin link
388 */
389 function bbp_admin_link( $args = '' ) {
390 echo bbp_get_admin_link( $args );
391 }
392 /**
393 * Return the link to the admin section
394 *
395 * @since bbPress (r2827)
396 *
397 * @param mixed $args Optional. This function supports these arguments:
398 * - text: The text
399 * - before: Before the lnk
400 * - after: After the link
401 * @uses current_user_can() To check if the current user can moderate
402 * @uses admin_url() To get the admin url
403 * @uses apply_filters() Calls 'bbp_get_admin_link' with the link & args
404 * @return The link
405 */
406 function bbp_get_admin_link( $args = '' ) {
407 if ( !current_user_can( 'moderate' ) )
408 return;
409
410 if ( $args && is_string( $args ) && false === strpos( $args, '=' ) )
411 $args = array( 'text' => $args );
412
413 $defaults = array( 'text' => __( 'Admin', 'bbpress' ), 'before' => '', 'after' => '' );
414 $args = wp_parse_args( $args, $defaults );
415 extract( $args, EXTR_SKIP );
416
417 $uri = admin_url();
418
419 return apply_filters( 'bbp_get_admin_link', $before . '<a href="' . $uri . '">' . $text . '</a>' . $after, $args );
420 }
421
422 /** User IP *******************************************************************/
423
424 /**
425 * Output the author IP address of a post
426 *
427 * @since bbPress (r3120)
428 *
429 * @param mixed $args Optional. If it is an integer, it is used as post id.
430 * @uses bbp_get_author_ip() To get the post author link
431 */
432 function bbp_author_ip( $args = '' ) {
433 echo bbp_get_author_ip( $args );
434 }
435 /**
436 * Return the author IP address of a post
437 *
438 * @since bbPress (r3120)
439 *
440 * @param mixed $args Optional. If an integer, it is used as reply id.
441 * @uses get_post_meta() To check if it's a topic page
442 * @return string Author link of reply
443 */
444 function bbp_get_author_ip( $args = '' ) {
445
446 // Default arguments
447 $defaults = array(
448 'post_id' => 0,
449 'before' => '<span class="bbp-author-ip">(',
450 'after' => ')</span>'
451 );
452
453 $r = wp_parse_args( $args, $defaults );
454 extract( $r );
455
456 // Used as post id
457 if ( is_numeric( $args ) )
458 $post_id = $args;
459
460 // Get the author IP meta value
461 if ( $author_ip = get_post_meta( $post_id, '_bbp_author_ip', true ) )
462 $author_ip = $before . $author_ip . $after;
463
464 // No IP address
465 else
466 $author_ip = '';
467
468 return apply_filters( 'bbp_get_author_ip', $author_ip, $args );
469 }
470
471 /** Favorites *****************************************************************/
472
473 /**
474 * Output the link to the user's favorites page (profile page)
475 *
476 * @since bbPress (r2652)
477 *
478 * @param int $user_id Optional. User id
479 * @uses bbp_get_favorites_permalink() To get the favorites permalink
480 */
481 function bbp_favorites_permalink( $user_id = 0 ) {
482 echo bbp_get_favorites_permalink( $user_id );
483 }
484 /**
485 * Return the link to the user's favorites page (profile page)
486 *
487 * @since bbPress (r2652)
488 *
489 * @param int $user_id Optional. User id
490 * @uses bbp_get_user_profile_url() To get the user profile url
491 * @uses apply_filters() Calls 'bbp_get_favorites_permalink' with the
492 * user profile url and user id
493 * @return string Permanent link to user profile page
494 */
495 function bbp_get_favorites_permalink( $user_id = 0 ) {
496 return apply_filters( 'bbp_get_favorites_permalink', bbp_get_user_profile_url( $user_id ), $user_id );
497 }
498
499 /**
500 * Output the link to make a topic favorite/remove a topic from favorites
501 *
502 * @since bbPress (r2652)
503 *
504 * @param array $add Optional. Add to favorites args
505 * @param array $rem Optional. Remove from favorites args
506 * @param int $user_id Optional. User id
507 * @uses bbp_get_user_favorites_link() To get the user favorites link
508 */
509 function bbp_user_favorites_link( $add = array(), $rem = array(), $user_id = 0 ) {
510 echo bbp_get_user_favorites_link( $add, $rem, $user_id );
511 }
512 /**
513 * User favorites link
514 *
515 * Return the link to make a topic favorite/remove a topic from
516 * favorites
517 *
518 * @since bbPress (r2652)
519 *
520 * @param array $add Optional. Add to favorites args
521 * @param array $rem Optional. Remove from favorites args
522 * @param int $user_id Optional. User id
523 * @uses bbp_get_user_id() To get the user id
524 * @uses current_user_can() If the current user can edit the user
525 * @uses bbp_get_topic_id() To get the topic id
526 * @uses bbp_is_user_favorite() To check if the topic is user's favorite
527 * @uses bbp_get_favorites_permalink() To get the favorites permalink
528 * @uses bbp_get_topic_permalink() To get the topic permalink
529 * @uses bbp_is_favorites() Is it the favorites page?
530 * @uses apply_filters() Calls 'bbp_get_user_favorites_link' with the
531 * html, add args, remove args, user & topic id
532 * @return string User favorites link
533 */
534 function bbp_get_user_favorites_link( $add = array(), $rem = array(), $user_id = 0 ) {
535 if ( !bbp_is_favorites_active() )
536 return false;
537
538 if ( !$user_id = bbp_get_user_id( $user_id, true, true ) )
539 return false;
540
541 if ( !current_user_can( 'edit_user', (int) $user_id ) )
542 return false;
543
544 if ( !$topic_id = bbp_get_topic_id() )
545 return false;
546
547 if ( empty( $add ) || !is_array( $add ) ) {
548 $add = array(
549 'mid' => __( 'Add this topic to your favorites', 'bbpress' ),
550 'post' => __( ' (%?%)', 'bbpress' )
551 );
552 }
553
554 if ( empty( $rem ) || !is_array( $rem ) ) {
555 $rem = array(
556 'pre' => __( 'This topic is one of your %favorites% [', 'bbpress' ),
557 'mid' => __( '&times;', 'bbpress' ),
558 'post' => __( ']', 'bbpress' )
559 );
560 }
561
562 if ( $is_fav = bbp_is_user_favorite( $user_id, $topic_id ) ) {
563 $url = esc_url( bbp_get_favorites_permalink( $user_id ) );
564 $rem = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $rem );
565 $favs = array( 'action' => 'bbp_favorite_remove', 'topic_id' => $topic_id );
566 $pre = ( is_array( $rem ) && isset( $rem['pre'] ) ) ? $rem['pre'] : '';
567 $mid = ( is_array( $rem ) && isset( $rem['mid'] ) ) ? $rem['mid'] : ( is_string( $rem ) ? $rem : '' );
568 $post = ( is_array( $rem ) && isset( $rem['post'] ) ) ? $rem['post'] : '';
569 } else {
570 $url = esc_url( bbp_get_topic_permalink( $topic_id ) );
571 $add = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $add );
572 $favs = array( 'action' => 'bbp_favorite_add', 'topic_id' => $topic_id );
573 $pre = ( is_array( $add ) && isset( $add['pre'] ) ) ? $add['pre'] : '';
574 $mid = ( is_array( $add ) && isset( $add['mid'] ) ) ? $add['mid'] : ( is_string( $add ) ? $add : '' );
575 $post = ( is_array( $add ) && isset( $add['post'] ) ) ? $add['post'] : '';
576 }
577
578 // Create the link based where the user is and if the topic is already the user's favorite
579 if ( bbp_is_favorites() )
580 $permalink = bbp_get_favorites_permalink( $user_id );
581 elseif ( is_singular( bbp_get_topic_post_type() ) )
582 $permalink = bbp_get_topic_permalink( $topic_id );
583 elseif ( bbp_is_query_name( 'bbp_single_topic' ) )
584 $permalink = get_permalink();
585
586 $url = esc_url( wp_nonce_url( add_query_arg( $favs, $permalink ), 'toggle-favorite_' . $topic_id ) );
587 $is_fav = $is_fav ? 'is-favorite' : '';
588 $html = '<span id="favorite-toggle"><span id="favorite-' . $topic_id . '" class="' . $is_fav . '">' . $pre . '<a href="' . $url . '" class="dim:favorite-toggle:favorite-' . $topic_id . ':is-favorite">' . $mid . '</a>' . $post . '</span></span>';
589
590 // Return the link
591 return apply_filters( 'bbp_get_user_favorites_link', $html, $add, $rem, $user_id, $topic_id );
592 }
593
594 /** Subscriptions *************************************************************/
595
596 /**
597 * Output the link to the user's subscriptions page (profile page)
598 *
599 * @since bbPress (r2688)
600 *
601 * @param int $user_id Optional. User id
602 * @uses bbp_get_subscriptions_permalink() To get the subscriptions link
603 */
604 function bbp_subscriptions_permalink( $user_id = 0 ) {
605 echo bbp_get_subscriptions_permalink( $user_id );
606 }
607 /**
608 * Return the link to the user's subscriptions page (profile page)
609 *
610 * @since bbPress (r2688)
611 *
612 * @param int $user_id Optional. User id
613 * @uses bbp_get_user_profile_url() To get the user profile url
614 * @uses apply_filters() Calls 'bbp_get_subscriptions_permalink' with
615 * the user profile url and user id
616 * @return string Permanent link to user subscriptions page
617 */
618 function bbp_get_subscriptions_permalink( $user_id = 0 ) {
619 return apply_filters( 'bbp_get_subscriptions_permalink', bbp_get_user_profile_url( $user_id ), $user_id );
620 }
621
622 /**
623 * Output the link to subscribe/unsubscribe from a topic
624 *
625 * @since bbPress (r2668)
626 *
627 * @param mixed $args See {@link bbp_get_user_subscribe_link()}
628 * @uses bbp_get_user_subscribe_link() To get the subscribe link
629 */
630 function bbp_user_subscribe_link( $args = '' ) {
631 echo bbp_get_user_subscribe_link( $args );
632 }
633 /**
634 * Return the link to subscribe/unsubscribe from a topic
635 *
636 * @since bbPress (r2668)
637 *
638 * @param mixed $args This function supports these arguments:
639 * - subscribe: Subscribe text
640 * - unsubscribe: Unsubscribe text
641 * - user_id: User id
642 * - topic_id: Topic id
643 * - before: Before the link
644 * - after: After the link
645 * @param int $user_id Optional. User id
646 * @uses bbp_get_user_id() To get the user id
647 * @uses current_user_can() To check if the current user can edit user
648 * @uses bbp_get_topic_id() To get the topic id
649 * @uses bbp_is_user_subscribed() To check if the user is subscribed
650 * @uses bbp_is_subscriptions() To check if it's the subscriptions page
651 * @uses bbp_get_subscriptions_permalink() To get subscriptions link
652 * @uses bbp_get_topic_permalink() To get topic link
653 * @uses apply_filters() Calls 'bbp_get_user_subscribe_link' with the
654 * link, args, user id & topic id
655 * @return string Permanent link to topic
656 */
657 function bbp_get_user_subscribe_link( $args = '', $user_id = 0 ) {
658 if ( !bbp_is_subscriptions_active() )
659 return;
660
661 $defaults = array (
662 'subscribe' => __( 'Subscribe', 'bbpress' ),
663 'unsubscribe' => __( 'Unsubscribe', 'bbpress' ),
664 'user_id' => 0,
665 'topic_id' => 0,
666 'before' => '&nbsp;|&nbsp;',
667 'after' => ''
668 );
669
670 $args = wp_parse_args( $args, $defaults );
671 extract( $args );
672
673 // Try to get a user_id
674 if ( !$user_id = bbp_get_user_id( $user_id, true, true ) )
675 return false;
676
677 // No link if you can't edit yourself
678 if ( !current_user_can( 'edit_user', (int) $user_id ) )
679 return false;
680
681 // No link if not viewing a topic
682 if ( !$topic_id = bbp_get_topic_id( $topic_id ) )
683 return false;
684
685 // Decine which link to show
686 if ( $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id ) ) {
687 $text = $unsubscribe;
688 $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id );
689 } else {
690 $text = $subscribe;
691 $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id );
692 }
693
694 // Create the link based where the user is and if the user is subscribed already
695 if ( bbp_is_subscriptions() )
696 $permalink = bbp_get_subscriptions_permalink( $user_id );
697 elseif ( is_singular( bbp_get_topic_post_type() ) )
698 $permalink = bbp_get_topic_permalink( $topic_id );
699 elseif ( bbp_is_query_name( 'bbp_single_topic' ) )
700 $permalink = get_permalink();
701
702 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) );
703 $is_subscribed = $is_subscribed ? 'is-subscribed' : '';
704 $html = '<span id="subscription-toggle">' . $before . '<span id="subscribe-' . $topic_id . '" class="' . $is_subscribed . '"><a href="' . $url . '" class="dim:subscription-toggle:subscribe-' . $topic_id . ':is-subscribed">' . $text . '</a></span>' . $after . '</span>';
705
706 // Return the link
707 return apply_filters( 'bbp_get_user_subscribe_link', $html, $args, $user_id, $topic_id );
708 }
709
710
711 /** Edit User *****************************************************************/
712
713 /**
714 * Edit profile success message
715 *
716 * @since bbPress (r2688)
717 *
718 * @uses bbp_is_single_user() To check if it's the profile page
719 * @uses bbp_is_single_user_edit() To check if it's the profile edit page
720 */
721 function bbp_notice_edit_user_success() {
722 if ( isset( $_GET['updated'] ) && ( bbp_is_single_user() || bbp_is_single_user_edit() ) ) : ?>
723
724 <div class="bbp-template-notice updated">
725 <p><?php _e( 'User updated.', 'bbpress' ); ?></p>
726 </div>
727
728 <?php endif;
729 }
730
731 /**
732 * Super admin privileges notice
733 *
734 * @since bbPress (r2688)
735 *
736 * @uses is_multisite() To check if the blog is multisite
737 * @uses bbp_is_single_user() To check if it's the profile page
738 * @uses bbp_is_single_user_edit() To check if it's the profile edit page
739 * @uses current_user_can() To check if the current user can manage network
740 * options
741 * @uses bbp_get_displayed_user_id() To get the displayed user id
742 * @uses is_super_admin() To check if the user is super admin
743 * @uses bbp_is_user_home() To check if it's the user home
744 */
745 function bbp_notice_edit_user_is_super_admin() {
746 if ( is_multisite() && ( bbp_is_single_user() || bbp_is_single_user_edit() ) && current_user_can( 'manage_network_options' ) && is_super_admin( bbp_get_displayed_user_id() ) ) : ?>
747
748 <div class="bbp-template-notice important">
749 <p><?php bbp_is_user_home() ? _e( 'You have super admin privileges.', 'bbpress' ) : _e( 'This user has super admin privileges.', 'bbpress' ); ?></p>
750 </div>
751
752 <?php endif;
753 }
754
755 /**
756 * Drop down for selecting the user's display name
757 *
758 * @since bbPress (r2688)
759 */
760 function bbp_edit_user_display_name() {
761 global $bbp;
762
763 $public_display = array();
764 $public_display['display_username'] = $bbp->displayed_user->user_login;
765
766 if ( !empty( $bbp->displayed_user->nickname ) )
767 $public_display['display_nickname'] = $bbp->displayed_user->nickname;
768
769 if ( !empty( $bbp->displayed_user->first_name ) )
770 $public_display['display_firstname'] = $bbp->displayed_user->first_name;
771
772 if ( !empty( $bbp->displayed_user->last_name ) )
773 $public_display['display_lastname'] = $bbp->displayed_user->last_name;
774
775 if ( !empty( $bbp->displayed_user->first_name ) && !empty( $bbp->displayed_user->last_name ) ) {
776 $public_display['display_firstlast'] = $bbp->displayed_user->first_name . ' ' . $bbp->displayed_user->last_name;
777 $public_display['display_lastfirst'] = $bbp->displayed_user->last_name . ' ' . $bbp->displayed_user->first_name;
778 }
779
780 if ( !in_array( $bbp->displayed_user->display_name, $public_display ) ) // Only add this if it isn't duplicated elsewhere
781 $public_display = array( 'display_displayname' => $bbp->displayed_user->display_name ) + $public_display;
782
783 $public_display = array_map( 'trim', $public_display );
784 $public_display = array_unique( $public_display ); ?>
785
786 <select name="display_name" id="display_name">
787
788 <?php foreach ( $public_display as $id => $item ) : ?>
789
790 <option id="<?php echo $id; ?>" value="<?php echo esc_attr( $item ); ?>"<?php selected( $bbp->displayed_user->display_name, $item ); ?>><?php echo $item; ?></option>
791
792 <?php endforeach; ?>
793
794 </select>
795
796 <?php
797 }
798
799 /**
800 * Output role selector (for user edit)
801 *
802 * @since bbPress (r2688)
803 */
804 function bbp_edit_user_role() {
805 global $bbp;
806
807 // Return if no user is displayed
808 if ( !isset( $bbp->displayed_user ) )
809 return;
810
811 // Local variables
812 $p = $r = '';
813
814 // print the 'no role' option. Make it selected if the user has no role yet.
815 if ( !$user_role = array_shift( $bbp->displayed_user->roles ) )
816 $r .= '<option value="">' . __( '&mdash; No role for this site &mdash;', 'bbpress' ) . '</option>';
817
818 // Loop through roles
819 foreach ( get_editable_roles() as $role => $details ) {
820 $name = translate_user_role( $details['name'] );
821
822 // Make default first in list
823 if ( $user_role == $role )
824 $p = "\n\t<option selected='selected' value='" . esc_attr( $role ) . "'>{$name}</option>";
825 else
826 $r .= "\n\t<option value='" . esc_attr( $role ) . "'>{$name}</option>";
827 }
828
829 // Output result
830 echo '<select name="role" id="role">' . $p . $r . '</select>';
831 }
832
833 /**
834 * Return user contact methods Selectbox
835 *
836 * @since bbPress (r2688)
837 *
838 * @uses _wp_get_user_contactmethods() To get the contact methods
839 * @uses apply_filters() Calls 'bbp_edit_user_contact_methods' with the methods
840 * @return string User contact methods
841 */
842 function bbp_edit_user_contact_methods() {
843 global $bbp;
844
845 // Get the core WordPress contact methods
846 $contact_methods = _wp_get_user_contactmethods( $bbp->displayed_user );
847
848 return apply_filters( 'bbp_edit_user_contact_methods', $contact_methods );
849 }
850
851 /** Login *********************************************************************/
852
853 /**
854 * Handle the login and registration template notices
855 *
856 * @since bbPress (r2970)
857 *
858 * @uses WP_Error bbPress::errors::add() To add an error or message
859 */
860 function bbp_login_notices() {
861
862 // loggedout was passed
863 if ( !empty( $_GET['loggedout'] ) && ( true == $_GET['loggedout'] ) ) {
864 bbp_add_error( 'loggedout', __( 'You are now logged out.', 'bbpress' ), 'message' );
865
866 // registration is disabled
867 } elseif ( !empty( $_GET['registration'] ) && ( 'disabled' == $_GET['registration'] ) ) {
868 bbp_add_error( 'registerdisabled', __( 'New user registration is currently not allowed.', 'bbpress' ) );
869
870 // Prompt user to check their email
871 } elseif ( !empty( $_GET['checkemail'] ) && in_array( $_GET['checkemail'], array( 'confirm', 'newpass', 'registered' ) ) ) {
872
873 switch ( $_GET['checkemail'] ) {
874
875 // Email needs confirmation
876 case 'confirm' :
877 bbp_add_error( 'confirm', __( 'Check your e-mail for the confirmation link.', 'bbpress' ), 'message' );
878 break;
879
880 // User requested a new password
881 case 'newpass' :
882 bbp_add_error( 'newpass', __( 'Check your e-mail for your new password.', 'bbpress' ), 'message' );
883 break;
884
885 // User is newly registered
886 case 'registered' :
887 bbp_add_error( 'registered', __( 'Registration complete. Please check your e-mail.', 'bbpress' ), 'message' );
888 break;
889 }
890 }
891 }
892
893 /**
894 * Redirect a user back to their profile if they are already logged in.
895 *
896 * This should be used before {@link get_header()} is called in template files
897 * where the user should never have access to the contents of that file.
898 *
899 * @since bbPress (r2815)
900 *
901 * @param string $url The URL to redirect to
902 * @uses is_user_logged_in() Check if user is logged in
903 * @uses wp_safe_redirect() To safely redirect
904 * @uses bbp_get_user_profile_url() To get the profile url of the user
905 * @uses bbp_get_current_user_id() To get the current user id
906 */
907 function bbp_logged_in_redirect( $url = '' ) {
908
909 // Bail if user is not logged in
910 if ( !is_user_logged_in() )
911 return;
912
913 // Setup the profile page to redirect to
914 $redirect_to = !empty( $url ) ? $url : bbp_get_user_profile_url( bbp_get_current_user_id() );
915
916 // Do a safe redirect and exit
917 wp_safe_redirect( $redirect_to );
918 exit;
919 }
920
921 /**
922 * Output the required hidden fields when logging in
923 *
924 * @since bbPress (r2815)
925 *
926 * @uses apply_filters() To allow custom redirection
927 * @uses bbp_redirect_to_field() To output the hidden request url field
928 * @uses wp_nonce_field() To generate hidden nonce fields
929 */
930 function bbp_user_login_fields() {
931 ?>
932
933 <input type="hidden" name="user-cookie" value="1" />
934
935 <?php
936
937 // Allow custom login redirection
938 $redirect_to = apply_filters( 'bbp_user_login_redirect_to', '' );
939 bbp_redirect_to_field( $redirect_to );
940
941 // Prevent intention hi-jacking of log-in form
942 wp_nonce_field( 'bbp-user-login' );
943 }
944
945 /** Register ******************************************************************/
946
947 /**
948 * Output the required hidden fields when registering
949 *
950 * @since bbPress (r2815)
951 *
952 * @uses add_query_arg() To add query args
953 * @uses bbp_login_url() To get the login url
954 * @uses apply_filters() To allow custom redirection
955 * @uses bbp_redirect_to_field() To output the redirect to field
956 * @uses wp_nonce_field() To generate hidden nonce fields
957 */
958 function bbp_user_register_fields() {
959 ?>
960
961 <input type="hidden" name="action" value="register" />
962 <input type="hidden" name="user-cookie" value="1" />
963
964 <?php
965
966 // Allow custom registration redirection
967 $redirect_to = apply_filters( 'bbp_user_register_redirect_to', '' );
968 bbp_redirect_to_field( add_query_arg( array( 'checkemail' => 'registered' ), $redirect_to ) );
969
970 // Prevent intention hi-jacking of sign-up form
971 wp_nonce_field( 'bbp-user-register' );
972 }
973
974 /** Lost Password *************************************************************/
975
976 /**
977 * Output the required hidden fields when user lost password
978 *
979 * @since bbPress (r2815)
980 *
981 * @uses apply_filters() To allow custom redirection
982 * @uses wp_referer_field() Set referer
983 * @uses wp_nonce_field() To generate hidden nonce fields
984 */
985 function bbp_user_lost_pass_fields() {
986 ?>
987
988 <input type="hidden" name="user-cookie" value="1" />
989
990 <?php
991
992 // Allow custom lost pass redirection
993 $redirect_to = apply_filters( 'bbp_user_lost_pass_redirect_to', get_permalink() );
994 bbp_redirect_to_field( add_query_arg( array( 'checkemail' => 'confirm' ), $redirect_to ) );
995
996 // Prevent intention hi-jacking of lost pass form
997 wp_nonce_field( 'bbp-user-lost-pass' );
998 }
999
1000 /** Author Avatar *************************************************************/
1001
1002 /**
1003 * Output the author link of a post
1004 *
1005 * @since bbPress (r2875)
1006 *
1007 * @param mixed $args Optional. If it is an integer, it is used as post id.
1008 * @uses bbp_get_author_link() To get the post author link
1009 */
1010 function bbp_author_link( $args = '' ) {
1011 echo bbp_get_author_link( $args );
1012 }
1013 /**
1014 * Return the author link of the post
1015 *
1016 * @since bbPress (r2875)
1017 *
1018 * @param mixed $args Optional. If an integer, it is used as reply id.
1019 * @uses bbp_is_topic() To check if it's a topic page
1020 * @uses bbp_get_topic_author_link() To get the topic author link
1021 * @uses bbp_is_reply() To check if it's a reply page
1022 * @uses bbp_get_reply_author_link() To get the reply author link
1023 * @uses get_post_field() To get the post author
1024 * @uses bbp_is_reply_anonymous() To check if the reply is by an
1025 * anonymous user
1026 * @uses get_the_author_meta() To get the author name
1027 * @uses bbp_get_user_profile_url() To get the author profile url
1028 * @uses get_avatar() To get the author avatar
1029 * @uses apply_filters() Calls 'bbp_get_reply_author_link' with the
1030 * author link and args
1031 * @return string Author link of reply
1032 */
1033 function bbp_get_author_link( $args = '' ) {
1034 $defaults = array (
1035 'post_id' => 0,
1036 'link_title' => '',
1037 'type' => 'both',
1038 'size' => 80
1039 );
1040
1041 $r = wp_parse_args( $args, $defaults );
1042 extract( $r );
1043
1044 // Used as reply_id
1045 if ( is_numeric( $args ) )
1046 $post_id = $args;
1047
1048 if ( bbp_is_topic( $post_id ) )
1049 return bbp_get_topic_author_link( $args );
1050 elseif ( bbp_is_reply( $post_id ) )
1051 return bbp_get_reply_author_link( $args );
1052 else
1053 $user_id = get_post_field( 'post_author', $post_id );
1054
1055 // Neither a reply nor a topic, so could be a revision
1056 if ( !empty( $post_id ) ) {
1057 if ( empty( $link_title ) )
1058 $link_title = sprintf( !bbp_is_reply_anonymous( $post_id ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), get_the_author_meta( 'display_name', $user_id ) );
1059
1060 $link_title = !empty( $link_title ) ? ' title="' . $link_title . '"' : '';
1061 $author_url = bbp_get_user_profile_url( $user_id );
1062 $anonymous = bbp_is_reply_anonymous( $post_id );
1063
1064 // Get avatar
1065 if ( 'avatar' == $type || 'both' == $type )
1066 $author_links[] = get_avatar( $user_id, $size );
1067
1068 // Get display name
1069 if ( 'name' == $type || 'both' == $type )
1070 $author_links[] = get_the_author_meta( 'display_name', $user_id );
1071
1072 // Add links if not anonymous
1073 if ( empty( $anonymous ) ) {
1074 foreach ( $author_links as $link_text ) {
1075 $author_link[] = sprintf( '<a href="%1$s"%2$s>%3$s</a>', $author_url, $link_title, $link_text );
1076 }
1077 $author_link = join( '&nbsp;', $author_link );
1078
1079 // No links if anonymous
1080 } else {
1081 $author_link = join( '&nbsp;', $author_links );
1082 }
1083
1084 // No post so link is empty
1085 } else {
1086 $author_link = '';
1087 }
1088
1089 return apply_filters( 'bbp_get_author_link', $author_link, $args );
1090 }
1091
1092 /** Capabilities **************************************************************/
1093
1094 /**
1095 * Check if the user can access a specific forum
1096 *
1097 * @since bbPress (r3127)
1098 *
1099 * @uses bbp_get_current_user_id()
1100 * @uses bbp_get_forum_id()
1101 * @uses bbp_allow_anonymous()
1102 * @uses wp_parse_args()
1103 * @uses bbp_get_user_id()
1104 * @uses current_user_can()
1105 * @uses is_super_admin()
1106 * @uses bbp_is_forum_public()
1107 * @uses bbp_is_forum_private()
1108 * @uses bbp_is_forum_hidden()
1109 * @uses current_user_can()
1110 * @uses apply_filters()
1111 *
1112 * @return bool
1113 */
1114 function bbp_user_can_view_forum( $args = '' ) {
1115
1116 $defaults = array(
1117 'user_id' => bbp_get_current_user_id(),
1118 'forum_id' => bbp_get_forum_id(),
1119 'check_ancestors' => false
1120 );
1121 $r = wp_parse_args( $args, $defaults );
1122 extract( $r );
1123
1124 // Validate parsed values
1125 $user_id = bbp_get_user_id ( $user_id, false, false );
1126 $forum_id = bbp_get_forum_id( $forum_id );
1127 $retval = false;
1128
1129 // User is a super admin
1130 if ( is_super_admin() )
1131 $retval = true;
1132
1133 // Forum is public, and user can read forums or is not logged in
1134 elseif ( bbp_is_forum_public ( $forum_id, $check_ancestors ) )
1135 $retval = true;
1136
1137 // Forum is private, and user can see it
1138 elseif ( bbp_is_forum_private( $forum_id, $check_ancestors ) && current_user_can( 'read_private_forums' ) )
1139 $retval = true;
1140
1141 // Forum is hidden, and user can see it
1142 elseif ( bbp_is_forum_hidden ( $forum_id, $check_ancestors ) && current_user_can( 'read_hidden_forums' ) )
1143 $retval = true;
1144
1145 return apply_filters( 'bbp_user_can_view_forum', $retval, $forum_id, $user_id );
1146 }
1147
1148 /**
1149 * Check if the current user can publish topics
1150 *
1151 * @since bbPress (r3127)
1152 *
1153 * @uses is_super_admin()
1154 * @uses is_user_logged_in()
1155 * @uses bbp_allow_anonymous()
1156 * @uses bbp_is_user_active()
1157 * @uses current_user_can()
1158 * @uses apply_filters()
1159 *
1160 * @return bool
1161 */
1162 function bbp_current_user_can_publish_topics() {
1163
1164 // Users need to earn access
1165 $retval = false;
1166
1167 // Always allow super admins
1168 if ( is_super_admin() )
1169 $retval = true;
1170
1171 // Do not allow anonymous if not enabled
1172 elseif ( !is_user_logged_in() && bbp_allow_anonymous() )
1173 $retval = true;
1174
1175 // User is logged in
1176 elseif ( bbp_is_user_active() && current_user_can( 'publish_topics' ) )
1177 $retval = true;
1178
1179 // Allow access to be filtered
1180 return apply_filters( 'bbp_current_user_can_publish_topics', (bool) $retval );
1181 }
1182
1183 /**
1184 * Check if the current user can publish replies
1185 *
1186 * @since bbPress (r3127)
1187 *
1188 * @uses is_super_admin()
1189 * @uses is_user_logged_in()
1190 * @uses bbp_allow_anonymous()
1191 * @uses bbp_is_user_active()
1192 * @uses current_user_can()
1193 * @uses apply_filters()
1194 *
1195 * @return bool
1196 */
1197 function bbp_current_user_can_publish_replies() {
1198
1199 // Users need to earn access
1200 $retval = false;
1201
1202 // Always allow super admins
1203 if ( is_super_admin() )
1204 $retval = true;
1205
1206 // Do not allow anonymous if not enabled
1207 elseif ( !is_user_logged_in() && bbp_allow_anonymous() )
1208 $retval = true;
1209
1210 // User is logged in
1211 elseif ( bbp_is_user_active() && current_user_can( 'publish_replies' ) )
1212 $retval = true;
1213
1214 // Allow access to be filtered
1215 return apply_filters( 'bbp_current_user_can_publish_replies', (bool) $retval );
1216 }
1217
1218 /** Forms *********************************************************************/
1219
1220 /**
1221 *
1222 * @since bbPress (r3127)
1223 *
1224 * @uses bbp_get_forum_post_type()
1225 * @uses get_posts()
1226 *
1227 * @param type $args
1228 * @return type
1229 */
1230 function bbp_get_forums_for_current_user( $args = array() ) {
1231
1232 // Setup arrays
1233 $private = $hidden = $post__not_in = array();
1234
1235 // Private forums
1236 if ( !current_user_can( 'read_private_forums' ) )
1237 $private = bbp_get_private_forum_ids();
1238
1239 // Hidden forums
1240 if ( !current_user_can( 'read_hidden_forums' ) )
1241 $hidden = bbp_get_hidden_forum_ids();
1242
1243 // Merge private and hidden forums together and remove any empties
1244 $forum_ids = (array) array_filter( array_merge( $private, $hidden ) );
1245
1246 // There are forums that need to be ex
1247 if ( !empty( $forum_ids ) )
1248 $post__not_in = implode( ',', $forum_ids );
1249
1250 $defaults = array(
1251 'post_type' => bbp_get_forum_post_type(),
1252 'post_status' => bbp_get_public_status_id(),
1253 'numberposts' => -1,
1254 'exclude' => $post__not_in
1255 );
1256 $r = wp_parse_args( $args, $defaults );
1257
1258 // Get the forums
1259 $forums = get_posts( $r );
1260
1261 // No availabe forums
1262 if ( empty( $forums ) )
1263 $forums = false;
1264
1265 return apply_filters( 'bbp_get_forums_for_current_user', $forums );
1266 }
1267
1268 /**
1269 * Performs a series of checks to ensure the current user can create topics.
1270 *
1271 * @since bbPress (r3127)
1272 *
1273 * @uses bbp_is_topic_edit()
1274 * @uses current_user_can()
1275 * @uses bbp_get_topic_id()
1276 * @uses bbp_allow_anonymous()
1277 * @uses is_user_logged_in()
1278 *
1279 * @return bool
1280 */
1281 function bbp_current_user_can_access_create_topic_form() {
1282
1283 // Always allow super admins
1284 if ( is_super_admin() )
1285 return true;
1286
1287 // Users need to earn access
1288 $retval = false;
1289
1290 // Looking at a single forum & forum is open
1291 if ( ( bbp_is_single_forum() || is_page() || is_single() ) && bbp_is_forum_open() )
1292 $retval = bbp_current_user_can_publish_topics();
1293
1294 // User can edit this topic
1295 elseif ( bbp_is_topic_edit() )
1296 $retval = current_user_can( 'edit_topic', bbp_get_topic_id() );
1297
1298 // Allow access to be filtered
1299 return apply_filters( 'bbp_current_user_can_access_create_topic_form', (bool) $retval );
1300 }
1301
1302 /**
1303 * Performs a series of checks to ensure the current user can create replies.
1304 *
1305 * @since bbPress (r3127)
1306 *
1307 * @uses bbp_is_topic_edit()
1308 * @uses current_user_can()
1309 * @uses bbp_get_topic_id()
1310 * @uses bbp_allow_anonymous()
1311 * @uses is_user_logged_in()
1312 *
1313 * @return bool
1314 */
1315 function bbp_current_user_can_access_create_reply_form() {
1316
1317 // Always allow super admins
1318 if ( is_super_admin() )
1319 return true;
1320
1321 // Users need to earn access
1322 $retval = false;
1323
1324 // Looking at a single topic, topic is open, and forum is open
1325 if ( ( bbp_is_single_topic() || is_page() || is_single() ) && bbp_is_topic_open() && bbp_is_forum_open() )
1326 $retval = bbp_current_user_can_publish_replies();
1327
1328 // User can edit this topic
1329 elseif ( bbp_is_reply_edit() )
1330 $retval = current_user_can( 'edit_reply', bbp_get_reply_id() );
1331
1332 // Allow access to be filtered
1333 return apply_filters( 'bbp_current_user_can_access_create_topic_form', (bool) $retval );
1334 }
1335
1336 ?>
1337