PluginProbe
bbPress / 2.0-rc-4
bbPress v2.0-rc-4
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 2.2 2.2.1 All 72 releases
bbpress / bbp-includes / bbp-user-template.php

bbp-user-template.php in bbPress 2.0-rc-4, at bbp-includes/bbp-user-template.php

1,335 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 ( !$user_id = bbp_get_user_id( $user_id, true, true ) )
536 return false;
537
538 if ( !current_user_can( 'edit_user', (int) $user_id ) )
539 return false;
540
541 if ( !$topic_id = bbp_get_topic_id() )
542 return false;
543
544 if ( empty( $add ) || !is_array( $add ) ) {
545 $add = array(
546 'mid' => __( 'Add this topic to your favorites', 'bbpress' ),
547 'post' => __( ' (%?%)', 'bbpress' )
548 );
549 }
550
551 if ( empty( $rem ) || !is_array( $rem ) ) {
552 $rem = array(
553 'pre' => __( 'This topic is one of your %favorites% [', 'bbpress' ),
554 'mid' => __( '&times;', 'bbpress' ),
555 'post' => __( ']', 'bbpress' )
556 );
557 }
558
559 if ( $is_fav = bbp_is_user_favorite( $user_id, $topic_id ) ) {
560 $url = esc_url( bbp_get_favorites_permalink( $user_id ) );
561 $rem = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $rem );
562 $favs = array( 'action' => 'bbp_favorite_remove', 'topic_id' => $topic_id );
563 $pre = ( is_array( $rem ) && isset( $rem['pre'] ) ) ? $rem['pre'] : '';
564 $mid = ( is_array( $rem ) && isset( $rem['mid'] ) ) ? $rem['mid'] : ( is_string( $rem ) ? $rem : '' );
565 $post = ( is_array( $rem ) && isset( $rem['post'] ) ) ? $rem['post'] : '';
566 } else {
567 $url = esc_url( bbp_get_topic_permalink( $topic_id ) );
568 $add = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $add );
569 $favs = array( 'action' => 'bbp_favorite_add', 'topic_id' => $topic_id );
570 $pre = ( is_array( $add ) && isset( $add['pre'] ) ) ? $add['pre'] : '';
571 $mid = ( is_array( $add ) && isset( $add['mid'] ) ) ? $add['mid'] : ( is_string( $add ) ? $add : '' );
572 $post = ( is_array( $add ) && isset( $add['post'] ) ) ? $add['post'] : '';
573 }
574
575 // Create the link based where the user is and if the topic is already the user's favorite
576 if ( bbp_is_favorites() )
577 $permalink = bbp_get_favorites_permalink( $user_id );
578 elseif ( is_singular( bbp_get_topic_post_type() ) )
579 $permalink = bbp_get_topic_permalink( $topic_id );
580 elseif ( bbp_is_query_name( 'bbp_single_topic' ) )
581 $permalink = get_permalink();
582
583 $url = esc_url( wp_nonce_url( add_query_arg( $favs, $permalink ), 'toggle-favorite_' . $topic_id ) );
584 $is_fav = $is_fav ? 'is-favorite' : '';
585 $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>';
586
587 // Return the link
588 return apply_filters( 'bbp_get_user_favorites_link', $html, $add, $rem, $user_id, $topic_id );
589 }
590
591 /** Subscriptions *************************************************************/
592
593 /**
594 * Output the link to the user's subscriptions page (profile page)
595 *
596 * @since bbPress (r2688)
597 *
598 * @param int $user_id Optional. User id
599 * @uses bbp_get_subscriptions_permalink() To get the subscriptions link
600 */
601 function bbp_subscriptions_permalink( $user_id = 0 ) {
602 echo bbp_get_subscriptions_permalink( $user_id );
603 }
604 /**
605 * Return the link to the user's subscriptions page (profile page)
606 *
607 * @since bbPress (r2688)
608 *
609 * @param int $user_id Optional. User id
610 * @uses bbp_get_user_profile_url() To get the user profile url
611 * @uses apply_filters() Calls 'bbp_get_subscriptions_permalink' with
612 * the user profile url and user id
613 * @return string Permanent link to user subscriptions page
614 */
615 function bbp_get_subscriptions_permalink( $user_id = 0 ) {
616 return apply_filters( 'bbp_get_subscriptions_permalink', bbp_get_user_profile_url( $user_id ), $user_id );
617 }
618
619 /**
620 * Output the link to subscribe/unsubscribe from a topic
621 *
622 * @since bbPress (r2668)
623 *
624 * @param mixed $args See {@link bbp_get_user_subscribe_link()}
625 * @uses bbp_get_user_subscribe_link() To get the subscribe link
626 */
627 function bbp_user_subscribe_link( $args = '' ) {
628 echo bbp_get_user_subscribe_link( $args );
629 }
630 /**
631 * Return the link to subscribe/unsubscribe from a topic
632 *
633 * @since bbPress (r2668)
634 *
635 * @param mixed $args This function supports these arguments:
636 * - subscribe: Subscribe text
637 * - unsubscribe: Unsubscribe text
638 * - user_id: User id
639 * - topic_id: Topic id
640 * - before: Before the link
641 * - after: After the link
642 * @param int $user_id Optional. User id
643 * @uses bbp_get_user_id() To get the user id
644 * @uses current_user_can() To check if the current user can edit user
645 * @uses bbp_get_topic_id() To get the topic id
646 * @uses bbp_is_user_subscribed() To check if the user is subscribed
647 * @uses bbp_is_subscriptions() To check if it's the subscriptions page
648 * @uses bbp_get_subscriptions_permalink() To get subscriptions link
649 * @uses bbp_get_topic_permalink() To get topic link
650 * @uses apply_filters() Calls 'bbp_get_user_subscribe_link' with the
651 * link, args, user id & topic id
652 * @return string Permanent link to topic
653 */
654 function bbp_get_user_subscribe_link( $args = '', $user_id = 0 ) {
655 if ( !bbp_is_subscriptions_active() )
656 return;
657
658 $defaults = array (
659 'subscribe' => __( 'Subscribe', 'bbpress' ),
660 'unsubscribe' => __( 'Unsubscribe', 'bbpress' ),
661 'user_id' => 0,
662 'topic_id' => 0,
663 'before' => '&nbsp;|&nbsp;',
664 'after' => ''
665 );
666
667 $args = wp_parse_args( $args, $defaults );
668 extract( $args );
669
670 // Try to get a user_id
671 if ( !$user_id = bbp_get_user_id( $user_id, true, true ) )
672 return false;
673
674 // No link if you can't edit yourself
675 if ( !current_user_can( 'edit_user', (int) $user_id ) )
676 return false;
677
678 // No link if not viewing a topic
679 if ( !$topic_id = bbp_get_topic_id( $topic_id ) )
680 return false;
681
682 // Decine which link to show
683 if ( $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id ) ) {
684 $text = $unsubscribe;
685 $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id );
686 } else {
687 $text = $subscribe;
688 $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id );
689 }
690
691 // Create the link based where the user is and if the user is subscribed already
692 if ( bbp_is_subscriptions() )
693 $permalink = bbp_get_subscriptions_permalink( $user_id );
694 elseif ( is_singular( bbp_get_topic_post_type() ) )
695 $permalink = bbp_get_topic_permalink( $topic_id );
696 elseif ( bbp_is_query_name( 'bbp_single_topic' ) )
697 $permalink = get_permalink();
698
699 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) );
700 $is_subscribed = $is_subscribed ? 'is-subscribed' : '';
701 $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>';
702
703 // Return the link
704 return apply_filters( 'bbp_get_user_subscribe_link', $html, $args, $user_id, $topic_id );
705 }
706
707
708 /** Edit User *****************************************************************/
709
710 /**
711 * Edit profile success message
712 *
713 * @since bbPress (r2688)
714 *
715 * @uses bbp_is_single_user() To check if it's the profile page
716 * @uses bbp_is_single_user_edit() To check if it's the profile edit page
717 */
718 function bbp_notice_edit_user_success() {
719 if ( isset( $_GET['updated'] ) && ( bbp_is_single_user() || bbp_is_single_user_edit() ) ) : ?>
720
721 <div class="bbp-template-notice updated">
722 <p><?php _e( 'User updated.', 'bbpress' ); ?></p>
723 </div>
724
725 <?php endif;
726 }
727
728 /**
729 * Super admin privileges notice
730 *
731 * @since bbPress (r2688)
732 *
733 * @uses is_multisite() To check if the blog is multisite
734 * @uses bbp_is_single_user() To check if it's the profile page
735 * @uses bbp_is_single_user_edit() To check if it's the profile edit page
736 * @uses current_user_can() To check if the current user can manage network
737 * options
738 * @uses bbp_get_displayed_user_id() To get the displayed user id
739 * @uses is_super_admin() To check if the user is super admin
740 * @uses bbp_is_user_home() To check if it's the user home
741 */
742 function bbp_notice_edit_user_is_super_admin() {
743 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() ) ) : ?>
744
745 <div class="bbp-template-notice important">
746 <p><?php bbp_is_user_home() ? _e( 'You have super admin privileges.', 'bbpress' ) : _e( 'This user has super admin privileges.', 'bbpress' ); ?></p>
747 </div>
748
749 <?php endif;
750 }
751
752 /**
753 * Drop down for selecting the user's display name
754 *
755 * @since bbPress (r2688)
756 */
757 function bbp_edit_user_display_name() {
758 global $bbp;
759
760 $public_display = array();
761 $public_display['display_username'] = $bbp->displayed_user->user_login;
762
763 if ( !empty( $bbp->displayed_user->nickname ) )
764 $public_display['display_nickname'] = $bbp->displayed_user->nickname;
765
766 if ( !empty( $bbp->displayed_user->first_name ) )
767 $public_display['display_firstname'] = $bbp->displayed_user->first_name;
768
769 if ( !empty( $bbp->displayed_user->last_name ) )
770 $public_display['display_lastname'] = $bbp->displayed_user->last_name;
771
772 if ( !empty( $bbp->displayed_user->first_name ) && !empty( $bbp->displayed_user->last_name ) ) {
773 $public_display['display_firstlast'] = $bbp->displayed_user->first_name . ' ' . $bbp->displayed_user->last_name;
774 $public_display['display_lastfirst'] = $bbp->displayed_user->last_name . ' ' . $bbp->displayed_user->first_name;
775 }
776
777 if ( !in_array( $bbp->displayed_user->display_name, $public_display ) ) // Only add this if it isn't duplicated elsewhere
778 $public_display = array( 'display_displayname' => $bbp->displayed_user->display_name ) + $public_display;
779
780 $public_display = array_map( 'trim', $public_display );
781 $public_display = array_unique( $public_display ); ?>
782
783 <select name="display_name" id="display_name">
784
785 <?php foreach ( $public_display as $id => $item ) : ?>
786
787 <option id="<?php echo $id; ?>" value="<?php echo esc_attr( $item ); ?>"<?php selected( $bbp->displayed_user->display_name, $item ); ?>><?php echo $item; ?></option>
788
789 <?php endforeach; ?>
790
791 </select>
792
793 <?php
794 }
795
796 /**
797 * Output role selector (for user edit)
798 *
799 * @since bbPress (r2688)
800 */
801 function bbp_edit_user_role() {
802 global $bbp;
803
804 // Return if no user is displayed
805 if ( !isset( $bbp->displayed_user ) )
806 return;
807
808 // Local variables
809 $p = $r = '';
810
811 // print the 'no role' option. Make it selected if the user has no role yet.
812 if ( !$user_role = array_shift( $bbp->displayed_user->roles ) )
813 $r .= '<option value="">' . __( '&mdash; No role for this site &mdash;', 'bbpress' ) . '</option>';
814
815 // Loop through roles
816 foreach ( get_editable_roles() as $role => $details ) {
817 $name = translate_user_role( $details['name'] );
818
819 // Make default first in list
820 if ( $user_role == $role )
821 $p = "\n\t<option selected='selected' value='" . esc_attr( $role ) . "'>{$name}</option>";
822 else
823 $r .= "\n\t<option value='" . esc_attr( $role ) . "'>{$name}</option>";
824 }
825
826 // Output result
827 echo '<select name="role" id="role">' . $p . $r . '</select>';
828 }
829
830 /**
831 * Return user contact methods Selectbox
832 *
833 * @since bbPress (r2688)
834 *
835 * @uses _wp_get_user_contactmethods() To get the contact methods
836 * @uses apply_filters() Calls 'bbp_edit_user_contact_methods' with the methods
837 * @return string User contact methods
838 */
839 function bbp_edit_user_contact_methods() {
840 global $bbp;
841
842 // Get the core WordPress contact methods
843 $contact_methods = _wp_get_user_contactmethods( $bbp->displayed_user );
844
845 return apply_filters( 'bbp_edit_user_contact_methods', $contact_methods );
846 }
847
848 /** Login *********************************************************************/
849
850 /**
851 * Handle the login and registration template notices
852 *
853 * @since bbPress (r2970)
854 *
855 * @uses WP_Error bbPress::errors::add() To add an error or message
856 */
857 function bbp_login_notices() {
858 global $bbp;
859
860 // loggedout was passed
861 if ( !empty( $_GET['loggedout'] ) && ( true == $_GET['loggedout'] ) ) {
862 bbp_add_error( 'loggedout', __( 'You are now logged out.', 'bbpress' ), 'message' );
863
864 // registration is disabled
865 } elseif ( !empty( $_GET['registration'] ) && ( 'disabled' == $_GET['registration'] ) ) {
866 bbp_add_error( 'registerdisabled', __( 'New user registration is currently not allowed.', 'bbpress' ) );
867
868 // Prompt user to check their email
869 } elseif ( !empty( $_GET['checkemail'] ) && in_array( $_GET['checkemail'], array( 'confirm', 'newpass', 'registered' ) ) ) {
870
871 switch ( $_GET['checkemail'] ) {
872
873 // Email needs confirmation
874 case 'confirm' :
875 bbp_add_error( 'confirm', __( 'Check your e-mail for the confirmation link.', 'bbpress' ), 'message' );
876 break;
877
878 // User requested a new password
879 case 'newpass' :
880 bbp_add_error( 'newpass', __( 'Check your e-mail for your new password.', 'bbpress' ), 'message' );
881 break;
882
883 // User is newly registered
884 case 'registered' :
885 bbp_add_error( 'registered', __( 'Registration complete. Please check your e-mail.', 'bbpress' ), 'message' );
886 break;
887 }
888 }
889 }
890
891 /**
892 * Redirect a user back to their profile if they are already logged in.
893 *
894 * This should be used before {@link get_header()} is called in template files
895 * where the user should never have access to the contents of that file.
896 *
897 * @since bbPress (r2815)
898 *
899 * @param string $url The URL to redirect to
900 * @uses is_user_logged_in() Check if user is logged in
901 * @uses wp_safe_redirect() To safely redirect
902 * @uses bbp_get_user_profile_url() To get the profile url of the user
903 * @uses bbp_get_current_user_id() To get the current user id
904 */
905 function bbp_logged_in_redirect( $url = '' ) {
906
907 // Bail if user is not logged in
908 if ( !is_user_logged_in() )
909 return;
910
911 // Setup the profile page to redirect to
912 $redirect_to = !empty( $url ) ? $url : bbp_get_user_profile_url( bbp_get_current_user_id() );
913
914 // Do a safe redirect and exit
915 wp_safe_redirect( $redirect_to );
916 exit;
917 }
918
919 /**
920 * Output the required hidden fields when logging in
921 *
922 * @since bbPress (r2815)
923 *
924 * @uses apply_filters() To allow custom redirection
925 * @uses bbp_redirect_to_field() To output the hidden request url field
926 * @uses wp_nonce_field() To generate hidden nonce fields
927 */
928 function bbp_user_login_fields() {
929 ?>
930
931 <input type="hidden" name="user-cookie" value="1" />
932
933 <?php
934
935 // Allow custom login redirection
936 $redirect_to = apply_filters( 'bbp_user_login_redirect_to', '' );
937 bbp_redirect_to_field( $redirect_to );
938
939 // Prevent intention hi-jacking of log-in form
940 wp_nonce_field( 'bbp-user-login' );
941 }
942
943 /** Register ******************************************************************/
944
945 /**
946 * Output the required hidden fields when registering
947 *
948 * @since bbPress (r2815)
949 *
950 * @uses add_query_arg() To add query args
951 * @uses bbp_login_url() To get the login url
952 * @uses apply_filters() To allow custom redirection
953 * @uses bbp_redirect_to_field() To output the redirect to field
954 * @uses wp_nonce_field() To generate hidden nonce fields
955 */
956 function bbp_user_register_fields() {
957 ?>
958
959 <input type="hidden" name="action" value="register" />
960 <input type="hidden" name="user-cookie" value="1" />
961
962 <?php
963
964 // Allow custom registration redirection
965 $redirect_to = apply_filters( 'bbp_user_register_redirect_to', '' );
966 bbp_redirect_to_field( add_query_arg( array( 'checkemail' => 'registered' ), $redirect_to ) );
967
968 // Prevent intention hi-jacking of sign-up form
969 wp_nonce_field( 'bbp-user-register' );
970 }
971
972 /** Lost Password *************************************************************/
973
974 /**
975 * Output the required hidden fields when user lost password
976 *
977 * @since bbPress (r2815)
978 *
979 * @uses apply_filters() To allow custom redirection
980 * @uses wp_referer_field() Set referer
981 * @uses wp_nonce_field() To generate hidden nonce fields
982 */
983 function bbp_user_lost_pass_fields() {
984 ?>
985
986 <input type="hidden" name="user-cookie" value="1" />
987
988 <?php
989
990 // Allow custom lost pass redirection
991 $redirect_to = apply_filters( 'bbp_user_lost_pass_redirect_to', get_permalink() );
992 bbp_redirect_to_field( add_query_arg( array( 'checkemail' => 'confirm' ), $redirect_to ) );
993
994 // Prevent intention hi-jacking of lost pass form
995 wp_nonce_field( 'bbp-user-lost-pass' );
996 }
997
998 /** Author Avatar *************************************************************/
999
1000 /**
1001 * Output the author link of a post
1002 *
1003 * @since bbPress (r2875)
1004 *
1005 * @param mixed $args Optional. If it is an integer, it is used as post id.
1006 * @uses bbp_get_author_link() To get the post author link
1007 */
1008 function bbp_author_link( $args = '' ) {
1009 echo bbp_get_author_link( $args );
1010 }
1011 /**
1012 * Return the author link of the post
1013 *
1014 * @since bbPress (r2875)
1015 *
1016 * @param mixed $args Optional. If an integer, it is used as reply id.
1017 * @uses bbp_is_topic() To check if it's a topic page
1018 * @uses bbp_get_topic_author_link() To get the topic author link
1019 * @uses bbp_is_reply() To check if it's a reply page
1020 * @uses bbp_get_reply_author_link() To get the reply author link
1021 * @uses get_post_field() To get the post author
1022 * @uses bbp_is_reply_anonymous() To check if the reply is by an
1023 * anonymous user
1024 * @uses get_the_author_meta() To get the author name
1025 * @uses bbp_get_user_profile_url() To get the author profile url
1026 * @uses get_avatar() To get the author avatar
1027 * @uses apply_filters() Calls 'bbp_get_reply_author_link' with the
1028 * author link and args
1029 * @return string Author link of reply
1030 */
1031 function bbp_get_author_link( $args = '' ) {
1032 $defaults = array (
1033 'post_id' => 0,
1034 'link_title' => '',
1035 'type' => 'both',
1036 'size' => 80
1037 );
1038
1039 $r = wp_parse_args( $args, $defaults );
1040 extract( $r );
1041
1042 // Used as reply_id
1043 if ( is_numeric( $args ) )
1044 $post_id = $args;
1045
1046 if ( bbp_is_topic( $post_id ) )
1047 return bbp_get_topic_author_link( $args );
1048 elseif ( bbp_is_reply( $post_id ) )
1049 return bbp_get_reply_author_link( $args );
1050 else
1051 $user_id = get_post_field( 'post_author', $post_id );
1052
1053 // Neither a reply nor a topic, so could be a revision
1054 if ( !empty( $post_id ) ) {
1055 if ( empty( $link_title ) )
1056 $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 ) );
1057
1058 $link_title = !empty( $link_title ) ? ' title="' . $link_title . '"' : '';
1059 $author_url = bbp_get_user_profile_url( $user_id );
1060 $anonymous = bbp_is_reply_anonymous( $post_id );
1061
1062 // Get avatar
1063 if ( 'avatar' == $type || 'both' == $type )
1064 $author_links[] = get_avatar( $user_id, $size );
1065
1066 // Get display name
1067 if ( 'name' == $type || 'both' == $type )
1068 $author_links[] = get_the_author_meta( 'display_name', $user_id );
1069
1070 // Add links if not anonymous
1071 if ( empty( $anonymous ) ) {
1072 foreach ( $author_links as $link_text ) {
1073 $author_link[] = sprintf( '<a href="%1$s"%2$s>%3$s</a>', $author_url, $link_title, $link_text );
1074 }
1075 $author_link = join( '&nbsp;', $author_link );
1076
1077 // No links if anonymous
1078 } else {
1079 $author_link = join( '&nbsp;', $author_links );
1080 }
1081
1082 // No post so link is empty
1083 } else {
1084 $author_link = '';
1085 }
1086
1087 return apply_filters( 'bbp_get_author_link', $author_link, $args );
1088 }
1089
1090 /** Capabilities **************************************************************/
1091
1092 /**
1093 * Check if the user can access a specific forum
1094 *
1095 * @since bbPress (r3127)
1096 *
1097 * @uses bbp_get_current_user_id()
1098 * @uses bbp_get_forum_id()
1099 * @uses bbp_allow_anonymous()
1100 * @uses wp_parse_args()
1101 * @uses bbp_get_user_id()
1102 * @uses current_user_can()
1103 * @uses is_super_admin()
1104 * @uses bbp_is_forum_public()
1105 * @uses bbp_is_forum_private()
1106 * @uses bbp_is_forum_hidden()
1107 * @uses current_user_can()
1108 * @uses apply_filters()
1109 *
1110 * @return bool
1111 */
1112 function bbp_user_can_view_forum( $args = '' ) {
1113
1114 $defaults = array(
1115 'user_id' => bbp_get_current_user_id(),
1116 'forum_id' => bbp_get_forum_id(),
1117 'check_ancestors' => false
1118 );
1119 $r = wp_parse_args( $args, $defaults );
1120 extract( $r );
1121
1122 // Validate parsed values
1123 $user_id = bbp_get_user_id ( $user_id, false, false );
1124 $forum_id = bbp_get_forum_id( $forum_id );
1125 $retval = false;
1126
1127 // User is a super admin
1128 if ( is_super_admin() )
1129 $retval = true;
1130
1131 // Forum is public, and user can read forums or is not logged in
1132 elseif ( bbp_is_forum_public ( $forum_id, $check_ancestors ) )
1133 $retval = true;
1134
1135 // Forum is private, and user can see it
1136 elseif ( bbp_is_forum_private( $forum_id, $check_ancestors ) && current_user_can( 'read_private_forums' ) )
1137 $retval = true;
1138
1139 // Forum is hidden, and user can see it
1140 elseif ( bbp_is_forum_hidden ( $forum_id, $check_ancestors ) && current_user_can( 'read_hidden_forums' ) )
1141 $retval = true;
1142
1143 return apply_filters( 'bbp_user_can_view_forum', $retval, $forum_id, $user_id );
1144 }
1145
1146 /**
1147 * Check if the current user can publish topics
1148 *
1149 * @since bbPress (r3127)
1150 *
1151 * @uses is_super_admin()
1152 * @uses is_user_logged_in()
1153 * @uses bbp_allow_anonymous()
1154 * @uses current_user_can()
1155 * @uses apply_filters()
1156 *
1157 * @return bool
1158 */
1159 function bbp_current_user_can_publish_topics() {
1160
1161 // Users need to earn access
1162 $retval = false;
1163
1164 // Always allow super admins
1165 if ( is_super_admin() )
1166 $retval = true;
1167
1168 // Do not allow anonymous if not enabled
1169 elseif ( !is_user_logged_in() && bbp_allow_anonymous() )
1170 $retval = true;
1171
1172 // User is logged in
1173 elseif ( !bbp_is_user_spammer() && !bbp_is_user_deleted() && current_user_can( 'publish_topics' ) )
1174 $retval = true;
1175
1176 // Allow access to be filtered
1177 return apply_filters( 'bbp_current_user_can_publish_topics', (bool) $retval );
1178 }
1179
1180 /**
1181 * Check if the current user can publish replies
1182 *
1183 * @since bbPress (r3127)
1184 *
1185 * @uses is_super_admin()
1186 * @uses is_user_logged_in()
1187 * @uses bbp_allow_anonymous()
1188 * @uses current_user_can()
1189 * @uses apply_filters()
1190 *
1191 * @return bool
1192 */
1193 function bbp_current_user_can_publish_replies() {
1194
1195 // Users need to earn access
1196 $retval = false;
1197
1198 // Always allow super admins
1199 if ( is_super_admin() )
1200 $retval = true;
1201
1202 // Do not allow anonymous if not enabled
1203 elseif ( !is_user_logged_in() && bbp_allow_anonymous() )
1204 $retval = true;
1205
1206 // User is logged in
1207 elseif ( !bbp_is_user_spammer() && !bbp_is_user_deleted() && current_user_can( 'publish_replies' ) )
1208 $retval = true;
1209
1210 // Allow access to be filtered
1211 return apply_filters( 'bbp_current_user_can_publish_replies', (bool) $retval );
1212 }
1213
1214 /** Forms *********************************************************************/
1215
1216 /**
1217 *
1218 * @since bbPress (r3127)
1219 *
1220 * @uses bbp_get_forum_post_type()
1221 * @uses get_posts()
1222 *
1223 * @param type $args
1224 * @return type
1225 */
1226 function bbp_get_forums_for_current_user( $args = array() ) {
1227
1228 // Setup arrays
1229 $private = $hidden = $post__not_in = array();
1230
1231 // Private forums
1232 if ( !current_user_can( 'read_private_forums' ) )
1233 $private = bbp_get_private_forum_ids();
1234
1235 // Hidden forums
1236 if ( !current_user_can( 'read_hidden_forums' ) )
1237 $hidden = bbp_get_hidden_forum_ids();
1238
1239 // Merge private and hidden forums together and remove any empties
1240 $forum_ids = (array) array_filter( array_merge( $private, $hidden ) );
1241
1242 // There are forums that need to be ex
1243 if ( !empty( $forum_ids ) )
1244 $post__not_in = implode( ',', $forum_ids );
1245
1246 $defaults = array(
1247 'post_type' => bbp_get_forum_post_type(),
1248 'post_status' => 'publish',
1249 'numberposts' => -1,
1250 'exclude' => $post__not_in
1251 );
1252 $r = wp_parse_args( $args, $defaults );
1253
1254 // Get the forums
1255 $forums = get_posts( $r );
1256
1257 // No availabe forums
1258 if ( empty( $forums ) )
1259 $forums = false;
1260
1261 return apply_filters( 'bbp_get_forums_for_current_user', $forums );
1262 }
1263
1264 /**
1265 * Performs a series of checks to ensure the current user can create topics.
1266 *
1267 * @since bbPress (r3127)
1268 *
1269 * @uses bbp_is_topic_edit()
1270 * @uses current_user_can()
1271 * @uses bbp_get_topic_id()
1272 * @uses bbp_allow_anonymous()
1273 * @uses is_user_logged_in()
1274 *
1275 * @return bool
1276 */
1277 function bbp_current_user_can_access_create_topic_form() {
1278
1279 // Always allow super admins
1280 if ( is_super_admin() )
1281 return true;
1282
1283 // Users need to earn access
1284 $retval = false;
1285
1286 // Looking at a single forum & forum is open
1287 if ( ( bbp_is_single_forum() || is_page() || is_single() ) && bbp_is_forum_open() ) {
1288 $retval = bbp_current_user_can_publish_topics();
1289
1290 // User can edit this topic
1291 } elseif ( bbp_is_topic_edit() ) {
1292 $retval = current_user_can( 'edit_topic', bbp_get_topic_id() );
1293 }
1294
1295 // Allow access to be filtered
1296 return apply_filters( 'bbp_current_user_can_access_create_topic_form', (bool) $retval );
1297 }
1298
1299 /**
1300 * Performs a series of checks to ensure the current user can create replies.
1301 *
1302 * @since bbPress (r3127)
1303 *
1304 * @uses bbp_is_topic_edit()
1305 * @uses current_user_can()
1306 * @uses bbp_get_topic_id()
1307 * @uses bbp_allow_anonymous()
1308 * @uses is_user_logged_in()
1309 *
1310 * @return bool
1311 */
1312 function bbp_current_user_can_access_create_reply_form() {
1313
1314 // Always allow super admins
1315 if ( is_super_admin() )
1316 return true;
1317
1318 // Users need to earn access
1319 $retval = false;
1320
1321 // Looking at a single topic, topic is open, and forum is open
1322 if ( ( bbp_is_single_topic() || is_page() || is_single() ) && bbp_is_topic_open() && bbp_is_forum_open() ) {
1323 $retval = bbp_current_user_can_publish_replies();
1324
1325 // User can edit this topic
1326 } elseif ( bbp_is_reply_edit() ) {
1327 $retval = current_user_can( 'edit_reply', bbp_get_reply_id() );
1328 }
1329
1330 // Allow access to be filtered
1331 return apply_filters( 'bbp_current_user_can_access_create_topic_form', (bool) $retval );
1332 }
1333
1334 ?>
1335