1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * bbPress Common Template Tags |
---|
5 | * |
---|
6 | * Common template tags are ones that are used by more than one component, like |
---|
7 | * forums, topics, replies, users, topic tags, etc... |
---|
8 | * |
---|
9 | * @package bbPress |
---|
10 | * @subpackage TemplateTags |
---|
11 | */ |
---|
12 | |
---|
13 | // Exit if accessed directly |
---|
14 | defined( 'ABSPATH' ) || exit; |
---|
15 | |
---|
16 | /** URLs **********************************************************************/ |
---|
17 | |
---|
18 | /** |
---|
19 | * Ouput the forum URL |
---|
20 | * |
---|
21 | * @since 2.1.0 bbPress (r3979) |
---|
22 | * |
---|
23 | * @uses bbp_get_forums_url() To get the forums URL |
---|
24 | * @param string $path Additional path with leading slash |
---|
25 | */ |
---|
26 | function bbp_forums_url( $path = '/' ) { |
---|
27 | echo esc_url( bbp_get_forums_url( $path ) ); |
---|
28 | } |
---|
29 | /** |
---|
30 | * Return the forum URL |
---|
31 | * |
---|
32 | * @since 2.1.0 bbPress (r3979) |
---|
33 | * |
---|
34 | * @uses home_url() To get the home URL |
---|
35 | * @uses bbp_get_root_slug() To get the forum root location |
---|
36 | * @param string $path Additional path with leading slash |
---|
37 | */ |
---|
38 | function bbp_get_forums_url( $path = '/' ) { |
---|
39 | return home_url( bbp_get_root_slug() . $path ); |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * Ouput the forum URL |
---|
44 | * |
---|
45 | * @since 2.1.0 bbPress (r3979) |
---|
46 | * |
---|
47 | * @uses bbp_get_topics_url() To get the topics URL |
---|
48 | * @param string $path Additional path with leading slash |
---|
49 | */ |
---|
50 | function bbp_topics_url( $path = '/' ) { |
---|
51 | echo esc_url( bbp_get_topics_url( $path ) ); |
---|
52 | } |
---|
53 | /** |
---|
54 | * Return the forum URL |
---|
55 | * |
---|
56 | * @since 2.1.0 bbPress (r3979) |
---|
57 | * |
---|
58 | * @uses home_url() To get the home URL |
---|
59 | * @uses bbp_get_topic_archive_slug() To get the topics archive location |
---|
60 | * @param string $path Additional path with leading slash |
---|
61 | * @return The URL to the topics archive |
---|
62 | */ |
---|
63 | function bbp_get_topics_url( $path = '/' ) { |
---|
64 | return home_url( bbp_get_topic_archive_slug() . $path ); |
---|
65 | } |
---|
66 | |
---|
67 | /** Add-on Actions ************************************************************/ |
---|
68 | |
---|
69 | /** |
---|
70 | * Add our custom head action to wp_head |
---|
71 | * |
---|
72 | * @since 2.0.0 bbPress (r2464) |
---|
73 | * |
---|
74 | * @uses do_action() Calls 'bbp_head' |
---|
75 | */ |
---|
76 | function bbp_head() { |
---|
77 | do_action( 'bbp_head' ); |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * Add our custom head action to wp_head |
---|
82 | * |
---|
83 | * @since 2.0.0 bbPress (r2464) |
---|
84 | * |
---|
85 | * @uses do_action() Calls 'bbp_footer' |
---|
86 | */ |
---|
87 | function bbp_footer() { |
---|
88 | do_action( 'bbp_footer' ); |
---|
89 | } |
---|
90 | |
---|
91 | /** is_ ***********************************************************************/ |
---|
92 | |
---|
93 | /** |
---|
94 | * Check if current site is public |
---|
95 | * |
---|
96 | * @since 2.0.0 bbPress (r3398) |
---|
97 | * |
---|
98 | * @param int $site_id |
---|
99 | * @uses get_current_blog_id() |
---|
100 | * @uses get_blog_option() |
---|
101 | * @uses apply_filters() |
---|
102 | * @return bool True if site is public, false if private |
---|
103 | */ |
---|
104 | function bbp_is_site_public( $site_id = 0 ) { |
---|
105 | |
---|
106 | // Get the current site ID |
---|
107 | if ( empty( $site_id ) ) { |
---|
108 | $site_id = get_current_blog_id(); |
---|
109 | } |
---|
110 | |
---|
111 | // Get the site visibility setting |
---|
112 | $public = get_blog_option( $site_id, 'blog_public', 1 ); |
---|
113 | |
---|
114 | return (bool) apply_filters( 'bbp_is_site_public', $public, $site_id ); |
---|
115 | } |
---|
116 | |
---|
117 | /** |
---|
118 | * Check if current page is a bbPress forum |
---|
119 | * |
---|
120 | * @since 2.0.0 bbPress (r2549) |
---|
121 | * |
---|
122 | * @param int $post_id Possible post_id to check |
---|
123 | * @uses bbp_get_forum_post_type() To get the forum post type |
---|
124 | * @return bool True if it's a forum page, false if not |
---|
125 | */ |
---|
126 | function bbp_is_forum( $post_id = 0 ) { |
---|
127 | |
---|
128 | // Assume false |
---|
129 | $retval = false; |
---|
130 | |
---|
131 | // Supplied ID is a forum |
---|
132 | if ( ! empty( $post_id ) && ( bbp_get_forum_post_type() === get_post_type( $post_id ) ) ) { |
---|
133 | $retval = true; |
---|
134 | } |
---|
135 | |
---|
136 | return (bool) apply_filters( 'bbp_is_forum', $retval, $post_id ); |
---|
137 | } |
---|
138 | |
---|
139 | /** |
---|
140 | * Check if we are viewing a forum archive. |
---|
141 | * |
---|
142 | * @since 2.0.0 bbPress (r3251) |
---|
143 | * |
---|
144 | * @uses is_post_type_archive() To check if we are looking at the forum archive |
---|
145 | * @uses bbp_get_forum_post_type() To get the forum post type ID |
---|
146 | * |
---|
147 | * @return bool |
---|
148 | */ |
---|
149 | function bbp_is_forum_archive() { |
---|
150 | global $wp_query; |
---|
151 | |
---|
152 | // Default to false |
---|
153 | $retval = false; |
---|
154 | |
---|
155 | // In forum archive |
---|
156 | if ( is_post_type_archive( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_forum_archive' ) || ! empty( $wp_query->bbp_show_topics_on_root ) ) { |
---|
157 | $retval = true; |
---|
158 | } |
---|
159 | |
---|
160 | return (bool) apply_filters( 'bbp_is_forum_archive', $retval ); |
---|
161 | } |
---|
162 | |
---|
163 | /** |
---|
164 | * Viewing a single forum |
---|
165 | * |
---|
166 | * @since 2.0.0 bbPress (r3338) |
---|
167 | * |
---|
168 | * @uses is_single() |
---|
169 | * @uses bbp_get_forum_post_type() |
---|
170 | * @uses get_post_type() |
---|
171 | * @uses apply_filters() |
---|
172 | * |
---|
173 | * @return bool |
---|
174 | */ |
---|
175 | function bbp_is_single_forum() { |
---|
176 | |
---|
177 | // Assume false |
---|
178 | $retval = false; |
---|
179 | |
---|
180 | // Edit is not a single forum |
---|
181 | if ( bbp_is_forum_edit() ) { |
---|
182 | return false; |
---|
183 | } |
---|
184 | |
---|
185 | // Single and a match |
---|
186 | if ( is_singular( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_single_forum' ) ) { |
---|
187 | $retval = true; |
---|
188 | } |
---|
189 | |
---|
190 | return (bool) apply_filters( 'bbp_is_single_forum', $retval ); |
---|
191 | } |
---|
192 | |
---|
193 | /** |
---|
194 | * Check if current page is a forum edit page |
---|
195 | * |
---|
196 | * @since 2.1.0 bbPress (r3553) |
---|
197 | * |
---|
198 | * @uses WP_Query Checks if WP_Query::bbp_is_forum_edit is true |
---|
199 | * @return bool True if it's the forum edit page, false if not |
---|
200 | */ |
---|
201 | function bbp_is_forum_edit() { |
---|
202 | global $wp_query, $pagenow; |
---|
203 | |
---|
204 | // Assume false |
---|
205 | $retval = false; |
---|
206 | |
---|
207 | // Check query |
---|
208 | if ( ! empty( $wp_query->bbp_is_forum_edit ) && ( $wp_query->bbp_is_forum_edit === true ) ) { |
---|
209 | $retval = true; |
---|
210 | |
---|
211 | // Editing in admin |
---|
212 | } elseif ( is_admin() && ( 'post.php' === $pagenow ) && ( get_post_type() === bbp_get_forum_post_type() ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) { |
---|
213 | $retval = true; |
---|
214 | } |
---|
215 | |
---|
216 | return (bool) apply_filters( 'bbp_is_forum_edit', $retval ); |
---|
217 | } |
---|
218 | |
---|
219 | /** |
---|
220 | * Check if current page is a bbPress topic |
---|
221 | * |
---|
222 | * @since 2.0.0 bbPress (r2549) |
---|
223 | * |
---|
224 | * @param int $post_id Possible post_id to check |
---|
225 | * @uses bbp_get_topic_post_type() To get the topic post type |
---|
226 | * @uses get_post_type() To get the post type of the post id |
---|
227 | * @return bool True if it's a topic page, false if not |
---|
228 | */ |
---|
229 | function bbp_is_topic( $post_id = 0 ) { |
---|
230 | |
---|
231 | // Assume false |
---|
232 | $retval = false; |
---|
233 | |
---|
234 | // Supplied ID is a topic |
---|
235 | if ( ! empty( $post_id ) && ( bbp_get_topic_post_type() === get_post_type( $post_id ) ) ) { |
---|
236 | $retval = true; |
---|
237 | } |
---|
238 | |
---|
239 | return (bool) apply_filters( 'bbp_is_topic', $retval, $post_id ); |
---|
240 | } |
---|
241 | |
---|
242 | /** |
---|
243 | * Viewing a single topic |
---|
244 | * |
---|
245 | * @since 2.0.0 bbPress (r3338) |
---|
246 | * |
---|
247 | * @uses is_single() |
---|
248 | * @uses bbp_get_topic_post_type() |
---|
249 | * @uses get_post_type() |
---|
250 | * @uses apply_filters() |
---|
251 | * |
---|
252 | * @return bool |
---|
253 | */ |
---|
254 | function bbp_is_single_topic() { |
---|
255 | |
---|
256 | // Assume false |
---|
257 | $retval = false; |
---|
258 | |
---|
259 | // Edit is not a single topic |
---|
260 | if ( bbp_is_topic_edit() ) { |
---|
261 | return false; |
---|
262 | } |
---|
263 | |
---|
264 | // Single and a match |
---|
265 | if ( is_singular( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_single_topic' ) ) { |
---|
266 | $retval = true; |
---|
267 | } |
---|
268 | |
---|
269 | return (bool) apply_filters( 'bbp_is_single_topic', $retval ); |
---|
270 | } |
---|
271 | |
---|
272 | /** |
---|
273 | * Check if we are viewing a topic archive. |
---|
274 | * |
---|
275 | * @since 2.0.0 bbPress (r3251) |
---|
276 | * |
---|
277 | * @uses is_post_type_archive() To check if we are looking at the topic archive |
---|
278 | * @uses bbp_get_topic_post_type() To get the topic post type ID |
---|
279 | * |
---|
280 | * @return bool |
---|
281 | */ |
---|
282 | function bbp_is_topic_archive() { |
---|
283 | |
---|
284 | // Default to false |
---|
285 | $retval = false; |
---|
286 | |
---|
287 | // In topic archive |
---|
288 | if ( is_post_type_archive( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_topic_archive' ) ) { |
---|
289 | $retval = true; |
---|
290 | } |
---|
291 | |
---|
292 | return (bool) apply_filters( 'bbp_is_topic_archive', $retval ); |
---|
293 | } |
---|
294 | |
---|
295 | /** |
---|
296 | * Check if current page is a topic edit page |
---|
297 | * |
---|
298 | * @since 2.0.0 bbPress (r2753) |
---|
299 | * |
---|
300 | * @uses WP_Query Checks if WP_Query::bbp_is_topic_edit is true |
---|
301 | * @return bool True if it's the topic edit page, false if not |
---|
302 | */ |
---|
303 | function bbp_is_topic_edit() { |
---|
304 | global $wp_query, $pagenow; |
---|
305 | |
---|
306 | // Assume false |
---|
307 | $retval = false; |
---|
308 | |
---|
309 | // Check query |
---|
310 | if ( ! empty( $wp_query->bbp_is_topic_edit ) && ( $wp_query->bbp_is_topic_edit === true ) ) { |
---|
311 | $retval = true; |
---|
312 | |
---|
313 | // Editing in admin |
---|
314 | } elseif ( is_admin() && ( 'post.php' === $pagenow ) && ( get_post_type() === bbp_get_topic_post_type() ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) { |
---|
315 | $retval = true; |
---|
316 | } |
---|
317 | |
---|
318 | return (bool) apply_filters( 'bbp_is_topic_edit', $retval ); |
---|
319 | } |
---|
320 | |
---|
321 | /** |
---|
322 | * Check if current page is a topic merge page |
---|
323 | * |
---|
324 | * @since 2.0.0 bbPress (r2756) |
---|
325 | * |
---|
326 | * @uses bbp_is_topic_edit() To check if it's a topic edit page |
---|
327 | * @return bool True if it's the topic merge page, false if not |
---|
328 | */ |
---|
329 | function bbp_is_topic_merge() { |
---|
330 | |
---|
331 | // Assume false |
---|
332 | $retval = false; |
---|
333 | |
---|
334 | // Check topic edit and GET params |
---|
335 | if ( bbp_is_topic_edit() && ! empty( $_GET['action'] ) && ( 'merge' === $_GET['action'] ) ) { |
---|
336 | return true; |
---|
337 | } |
---|
338 | |
---|
339 | return (bool) apply_filters( 'bbp_is_topic_merge', $retval ); |
---|
340 | } |
---|
341 | |
---|
342 | /** |
---|
343 | * Check if current page is a topic split page |
---|
344 | * |
---|
345 | * @since 2.0.0 bbPress (r2756) |
---|
346 | * |
---|
347 | * @uses bbp_is_topic_edit() To check if it's a topic edit page |
---|
348 | * @return bool True if it's the topic split page, false if not |
---|
349 | */ |
---|
350 | function bbp_is_topic_split() { |
---|
351 | |
---|
352 | // Assume false |
---|
353 | $retval = false; |
---|
354 | |
---|
355 | // Check topic edit and GET params |
---|
356 | if ( bbp_is_topic_edit() && ! empty( $_GET['action'] ) && ( 'split' === $_GET['action'] ) ) { |
---|
357 | $retval = true; |
---|
358 | } |
---|
359 | |
---|
360 | return (bool) apply_filters( 'bbp_is_topic_split', $retval ); |
---|
361 | } |
---|
362 | |
---|
363 | /** |
---|
364 | * Check if the current page is a topic tag |
---|
365 | * |
---|
366 | * @since 2.0.0 bbPress (r3311) |
---|
367 | * |
---|
368 | * @return bool True if it's a topic tag, false if not |
---|
369 | */ |
---|
370 | function bbp_is_topic_tag() { |
---|
371 | |
---|
372 | // Bail if topic-tags are off |
---|
373 | if ( ! bbp_allow_topic_tags() ) { |
---|
374 | return false; |
---|
375 | } |
---|
376 | |
---|
377 | // Return false if editing a topic tag |
---|
378 | if ( bbp_is_topic_tag_edit() ) { |
---|
379 | return false; |
---|
380 | } |
---|
381 | |
---|
382 | // Assume false |
---|
383 | $retval = false; |
---|
384 | |
---|
385 | // Check tax and query vars |
---|
386 | if ( is_tax( bbp_get_topic_tag_tax_id() ) || ! empty( bbpress()->topic_query->is_tax ) || get_query_var( 'bbp_topic_tag' ) ) { |
---|
387 | $retval = true; |
---|
388 | } |
---|
389 | |
---|
390 | return (bool) apply_filters( 'bbp_is_topic_tag', $retval ); |
---|
391 | } |
---|
392 | |
---|
393 | /** |
---|
394 | * Check if the current page is editing a topic tag |
---|
395 | * |
---|
396 | * @since 2.0.0 bbPress (r3346) |
---|
397 | * |
---|
398 | * @uses WP_Query Checks if WP_Query::bbp_is_topic_tag_edit is true |
---|
399 | * @return bool True if editing a topic tag, false if not |
---|
400 | */ |
---|
401 | function bbp_is_topic_tag_edit() { |
---|
402 | global $wp_query, $pagenow, $taxnow; |
---|
403 | |
---|
404 | // Bail if topic-tags are off |
---|
405 | if ( ! bbp_allow_topic_tags() ) { |
---|
406 | return false; |
---|
407 | } |
---|
408 | |
---|
409 | // Assume false |
---|
410 | $retval = false; |
---|
411 | |
---|
412 | // Check query |
---|
413 | if ( ! empty( $wp_query->bbp_is_topic_tag_edit ) && ( true === $wp_query->bbp_is_topic_tag_edit ) ) { |
---|
414 | $retval = true; |
---|
415 | |
---|
416 | // Editing in admin |
---|
417 | } elseif ( is_admin() && ( 'edit-tags.php' === $pagenow ) && ( bbp_get_topic_tag_tax_id() === $taxnow ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) { |
---|
418 | $retval = true; |
---|
419 | } |
---|
420 | |
---|
421 | return (bool) apply_filters( 'bbp_is_topic_tag_edit', $retval ); |
---|
422 | } |
---|
423 | |
---|
424 | /** |
---|
425 | * Check if the current post type is one of bbPress's |
---|
426 | * |
---|
427 | * @since 2.0.0 bbPress (r3311) |
---|
428 | * |
---|
429 | * @param mixed $the_post Optional. Post object or post ID. |
---|
430 | * @uses get_post_type() |
---|
431 | * @uses bbp_get_forum_post_type() |
---|
432 | * @uses bbp_get_topic_post_type() |
---|
433 | * @uses bbp_get_reply_post_type() |
---|
434 | * |
---|
435 | * @return bool |
---|
436 | */ |
---|
437 | function bbp_is_custom_post_type( $the_post = false ) { |
---|
438 | |
---|
439 | // Assume false |
---|
440 | $retval = false; |
---|
441 | |
---|
442 | // Viewing one of the bbPress post types |
---|
443 | if ( in_array( get_post_type( $the_post ), array( |
---|
444 | bbp_get_forum_post_type(), |
---|
445 | bbp_get_topic_post_type(), |
---|
446 | bbp_get_reply_post_type() |
---|
447 | ) ) ) { |
---|
448 | $retval = true; |
---|
449 | } |
---|
450 | |
---|
451 | return (bool) apply_filters( 'bbp_is_custom_post_type', $retval, $the_post ); |
---|
452 | } |
---|
453 | |
---|
454 | /** |
---|
455 | * Check if current page is a bbPress reply |
---|
456 | * |
---|
457 | * @since 2.0.0 bbPress (r2549) |
---|
458 | * |
---|
459 | * @param int $post_id Possible post_id to check |
---|
460 | * @uses bbp_get_reply_post_type() To get the reply post type |
---|
461 | * @uses get_post_type() To get the post type of the post id |
---|
462 | * @return bool True if it's a reply page, false if not |
---|
463 | */ |
---|
464 | function bbp_is_reply( $post_id = 0 ) { |
---|
465 | |
---|
466 | // Assume false |
---|
467 | $retval = false; |
---|
468 | |
---|
469 | // Supplied ID is a reply |
---|
470 | if ( ! empty( $post_id ) && ( bbp_get_reply_post_type() === get_post_type( $post_id ) ) ) { |
---|
471 | $retval = true; |
---|
472 | } |
---|
473 | |
---|
474 | return (bool) apply_filters( 'bbp_is_reply', $retval, $post_id ); |
---|
475 | } |
---|
476 | |
---|
477 | /** |
---|
478 | * Check if current page is a reply edit page |
---|
479 | * |
---|
480 | * @since 2.0.0 bbPress (r2753) |
---|
481 | * |
---|
482 | * @uses WP_Query Checks if WP_Query::bbp_is_reply_edit is true |
---|
483 | * @return bool True if it's the reply edit page, false if not |
---|
484 | */ |
---|
485 | function bbp_is_reply_edit() { |
---|
486 | global $wp_query, $pagenow; |
---|
487 | |
---|
488 | // Assume false |
---|
489 | $retval = false; |
---|
490 | |
---|
491 | // Check query |
---|
492 | if ( ! empty( $wp_query->bbp_is_reply_edit ) && ( true === $wp_query->bbp_is_reply_edit ) ) { |
---|
493 | $retval = true; |
---|
494 | |
---|
495 | // Editing in admin |
---|
496 | } elseif ( is_admin() && ( 'post.php' === $pagenow ) && ( get_post_type() === bbp_get_reply_post_type() ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) { |
---|
497 | $retval = true; |
---|
498 | } |
---|
499 | |
---|
500 | return (bool) apply_filters( 'bbp_is_reply_edit', $retval ); |
---|
501 | } |
---|
502 | |
---|
503 | /** |
---|
504 | * Check if current page is a reply move page |
---|
505 | * |
---|
506 | * @uses bbp_is_reply_move() To check if it's a reply move page |
---|
507 | * @return bool True if it's the reply move page, false if not |
---|
508 | */ |
---|
509 | function bbp_is_reply_move() { |
---|
510 | |
---|
511 | // Assume false |
---|
512 | $retval = false; |
---|
513 | |
---|
514 | // Check reply edit and GET params |
---|
515 | if ( bbp_is_reply_edit() && ! empty( $_GET['action'] ) && ( 'move' === $_GET['action'] ) ) { |
---|
516 | $retval = true; |
---|
517 | } |
---|
518 | |
---|
519 | return (bool) apply_filters( 'bbp_is_reply_move', $retval ); |
---|
520 | } |
---|
521 | |
---|
522 | /** |
---|
523 | * Viewing a single reply |
---|
524 | * |
---|
525 | * @since 2.0.0 bbPress (r3344) |
---|
526 | * |
---|
527 | * @uses is_single() |
---|
528 | * @uses bbp_get_reply_post_type() |
---|
529 | * @uses get_post_type() |
---|
530 | * @uses apply_filters() |
---|
531 | * |
---|
532 | * @return bool |
---|
533 | */ |
---|
534 | function bbp_is_single_reply() { |
---|
535 | |
---|
536 | // Assume false |
---|
537 | $retval = false; |
---|
538 | |
---|
539 | // Edit is not a single reply |
---|
540 | if ( bbp_is_reply_edit() ) { |
---|
541 | return false; |
---|
542 | } |
---|
543 | |
---|
544 | // Single and a match |
---|
545 | if ( is_singular( bbp_get_reply_post_type() ) || ( bbp_is_query_name( 'bbp_single_reply' ) ) ) { |
---|
546 | $retval = true; |
---|
547 | } |
---|
548 | |
---|
549 | return (bool) apply_filters( 'bbp_is_single_reply', $retval ); |
---|
550 | } |
---|
551 | |
---|
552 | /** |
---|
553 | * Check if current page is a bbPress user's favorites page (profile page) |
---|
554 | * |
---|
555 | * @since 2.0.0 bbPress (r2652) |
---|
556 | * |
---|
557 | * @return bool True if it's the favorites page, false if not |
---|
558 | */ |
---|
559 | function bbp_is_favorites() { |
---|
560 | global $wp_query; |
---|
561 | |
---|
562 | // Assume false |
---|
563 | $retval = false; |
---|
564 | |
---|
565 | // Check query |
---|
566 | if ( ! empty( $wp_query->bbp_is_single_user_favs ) && ( true === $wp_query->bbp_is_single_user_favs ) ) { |
---|
567 | $retval = true; |
---|
568 | } |
---|
569 | |
---|
570 | return (bool) apply_filters( 'bbp_is_favorites', $retval ); |
---|
571 | } |
---|
572 | |
---|
573 | /** |
---|
574 | * Check if current page is a bbPress user's subscriptions page (profile page) |
---|
575 | * |
---|
576 | * @since 2.0.0 bbPress (r2652) |
---|
577 | * |
---|
578 | * @return bool True if it's the subscriptions page, false if not |
---|
579 | */ |
---|
580 | function bbp_is_subscriptions() { |
---|
581 | global $wp_query; |
---|
582 | |
---|
583 | // Assume false |
---|
584 | $retval = false; |
---|
585 | |
---|
586 | // Check query |
---|
587 | if ( ! empty( $wp_query->bbp_is_single_user_subs ) && ( true === $wp_query->bbp_is_single_user_subs ) ) { |
---|
588 | $retval = true; |
---|
589 | } |
---|
590 | |
---|
591 | return (bool) apply_filters( 'bbp_is_subscriptions', $retval ); |
---|
592 | } |
---|
593 | |
---|
594 | /** |
---|
595 | * Check if current page shows the topics created by a bbPress user (profile |
---|
596 | * page) |
---|
597 | * |
---|
598 | * @since 2.0.0 bbPress (r2688) |
---|
599 | * |
---|
600 | * @return bool True if it's the topics created page, false if not |
---|
601 | */ |
---|
602 | function bbp_is_topics_created() { |
---|
603 | global $wp_query; |
---|
604 | |
---|
605 | // Assume false |
---|
606 | $retval = false; |
---|
607 | |
---|
608 | // Check query |
---|
609 | if ( ! empty( $wp_query->bbp_is_single_user_topics ) && ( true === $wp_query->bbp_is_single_user_topics ) ) { |
---|
610 | $retval = true; |
---|
611 | } |
---|
612 | |
---|
613 | return (bool) apply_filters( 'bbp_is_topics_created', $retval ); |
---|
614 | } |
---|
615 | |
---|
616 | /** |
---|
617 | * Check if current page shows the topics created by a bbPress user (profile |
---|
618 | * page) |
---|
619 | * |
---|
620 | * @since 2.2.0 bbPress (r4225) |
---|
621 | * |
---|
622 | * @return bool True if it's the topics created page, false if not |
---|
623 | */ |
---|
624 | function bbp_is_replies_created() { |
---|
625 | global $wp_query; |
---|
626 | |
---|
627 | // Assume false |
---|
628 | $retval = false; |
---|
629 | |
---|
630 | // Check query |
---|
631 | if ( ! empty( $wp_query->bbp_is_single_user_replies ) && ( true === $wp_query->bbp_is_single_user_replies ) ) { |
---|
632 | $retval = true; |
---|
633 | } |
---|
634 | |
---|
635 | return (bool) apply_filters( 'bbp_is_replies_created', $retval ); |
---|
636 | } |
---|
637 | |
---|
638 | /** |
---|
639 | * Check if current page is the currently logged in users author page |
---|
640 | * |
---|
641 | * @since 2.0.0 bbPress (r2688) |
---|
642 | * |
---|
643 | * @uses bbp_is_single_user() Check query variable |
---|
644 | * @uses is_user_logged_in() Must be logged in to be home |
---|
645 | * @uses bbp_get_displayed_user_id() |
---|
646 | * @uses bbp_get_current_user_id() |
---|
647 | * @return bool True if it's the user's home, false if not |
---|
648 | */ |
---|
649 | function bbp_is_user_home() { |
---|
650 | global $wp_query; |
---|
651 | |
---|
652 | // Assume false |
---|
653 | $retval = false; |
---|
654 | |
---|
655 | // Check query |
---|
656 | if ( ! empty( $wp_query->bbp_is_single_user_home ) && ( true === $wp_query->bbp_is_single_user_home ) ) { |
---|
657 | $retval = true; |
---|
658 | } |
---|
659 | |
---|
660 | return (bool) apply_filters( 'bbp_is_user_home', $retval ); |
---|
661 | } |
---|
662 | |
---|
663 | /** |
---|
664 | * Check if current page is the currently logged in users author edit page |
---|
665 | * |
---|
666 | * @since 2.1.0 bbPress (r3918) |
---|
667 | * |
---|
668 | * @uses bbp_is_single_user_edit() Check query variable |
---|
669 | * @uses is_user_logged_in() Must be logged in to be home |
---|
670 | * @uses bbp_get_displayed_user_id() |
---|
671 | * @uses bbp_get_current_user_id() |
---|
672 | * @return bool True if it's the user's home, false if not |
---|
673 | */ |
---|
674 | function bbp_is_user_home_edit() { |
---|
675 | |
---|
676 | // Assume false |
---|
677 | $retval = false; |
---|
678 | |
---|
679 | if ( bbp_is_user_home() && bbp_is_single_user_edit() ) { |
---|
680 | $retval = true; |
---|
681 | } |
---|
682 | |
---|
683 | return (bool) apply_filters( 'bbp_is_user_home_edit', $retval ); |
---|
684 | } |
---|
685 | |
---|
686 | /** |
---|
687 | * Check if current page is a user profile page |
---|
688 | * |
---|
689 | * @since 2.0.0 bbPress (r2688) |
---|
690 | * |
---|
691 | * @uses WP_Query Checks if WP_Query::bbp_is_single_user is set to true |
---|
692 | * @return bool True if it's a user's profile page, false if not |
---|
693 | */ |
---|
694 | function bbp_is_single_user() { |
---|
695 | global $wp_query; |
---|
696 | |
---|
697 | // Assume false |
---|
698 | $retval = false; |
---|
699 | |
---|
700 | // Check query |
---|
701 | if ( ! empty( $wp_query->bbp_is_single_user ) && ( true === $wp_query->bbp_is_single_user ) ) { |
---|
702 | $retval = true; |
---|
703 | } |
---|
704 | |
---|
705 | return (bool) apply_filters( 'bbp_is_single_user', $retval ); |
---|
706 | } |
---|
707 | |
---|
708 | /** |
---|
709 | * Check if current page is a user profile edit page |
---|
710 | * |
---|
711 | * @since 2.0.0 bbPress (r2688) |
---|
712 | * |
---|
713 | * @uses WP_Query Checks if WP_Query::bbp_is_single_user_edit is set to true |
---|
714 | * @return bool True if it's a user's profile edit page, false if not |
---|
715 | */ |
---|
716 | function bbp_is_single_user_edit() { |
---|
717 | global $wp_query; |
---|
718 | |
---|
719 | // Assume false |
---|
720 | $retval = false; |
---|
721 | |
---|
722 | // Check query |
---|
723 | if ( ! empty( $wp_query->bbp_is_single_user_edit ) && ( true === $wp_query->bbp_is_single_user_edit ) ) { |
---|
724 | $retval = true; |
---|
725 | } |
---|
726 | |
---|
727 | return (bool) apply_filters( 'bbp_is_single_user_edit', $retval ); |
---|
728 | } |
---|
729 | |
---|
730 | /** |
---|
731 | * Check if current page is a user profile page |
---|
732 | * |
---|
733 | * @since 2.2.0 bbPress (r4225) |
---|
734 | * |
---|
735 | * @uses WP_Query Checks if WP_Query::bbp_is_single_user_profile is set to true |
---|
736 | * @return bool True if it's a user's profile page, false if not |
---|
737 | */ |
---|
738 | function bbp_is_single_user_profile() { |
---|
739 | global $wp_query; |
---|
740 | |
---|
741 | // Assume false |
---|
742 | $retval = false; |
---|
743 | |
---|
744 | // Check query |
---|
745 | if ( ! empty( $wp_query->bbp_is_single_user_profile ) && ( true === $wp_query->bbp_is_single_user_profile ) ) { |
---|
746 | $retval = true; |
---|
747 | } |
---|
748 | |
---|
749 | return (bool) apply_filters( 'bbp_is_single_user_profile', $retval ); |
---|
750 | } |
---|
751 | |
---|
752 | /** |
---|
753 | * Check if current page is a user topics created page |
---|
754 | * |
---|
755 | * @since 2.2.0 bbPress (r4225) |
---|
756 | * |
---|
757 | * @uses WP_Query Checks if WP_Query::bbp_is_single_user_topics is set to true |
---|
758 | * @return bool True if it's a user's topics page, false if not |
---|
759 | */ |
---|
760 | function bbp_is_single_user_topics() { |
---|
761 | global $wp_query; |
---|
762 | |
---|
763 | // Assume false |
---|
764 | $retval = false; |
---|
765 | |
---|
766 | // Check query |
---|
767 | if ( ! empty( $wp_query->bbp_is_single_user_topics ) && ( true === $wp_query->bbp_is_single_user_topics ) ) { |
---|
768 | $retval = true; |
---|
769 | } |
---|
770 | |
---|
771 | return (bool) apply_filters( 'bbp_is_single_user_topics', $retval ); |
---|
772 | } |
---|
773 | |
---|
774 | /** |
---|
775 | * Check if current page is a user replies created page |
---|
776 | * |
---|
777 | * @since 2.2.0 bbPress (r4225) |
---|
778 | * |
---|
779 | * @uses WP_Query Checks if WP_Query::bbp_is_single_user_replies is set to true |
---|
780 | * @return bool True if it's a user's replies page, false if not |
---|
781 | */ |
---|
782 | function bbp_is_single_user_replies() { |
---|
783 | global $wp_query; |
---|
784 | |
---|
785 | // Assume false |
---|
786 | $retval = false; |
---|
787 | |
---|
788 | // Check query |
---|
789 | if ( ! empty( $wp_query->bbp_is_single_user_replies ) && ( true === $wp_query->bbp_is_single_user_replies ) ) { |
---|
790 | $retval = true; |
---|
791 | } |
---|
792 | |
---|
793 | return (bool) apply_filters( 'bbp_is_single_user_replies', $retval ); |
---|
794 | } |
---|
795 | |
---|
796 | /** |
---|
797 | * Check if current page is a view page |
---|
798 | * |
---|
799 | * @since 2.0.0 bbPress (r2789) |
---|
800 | * |
---|
801 | * @global WP_Query $wp_query To check if WP_Query::bbp_is_view is true |
---|
802 | * @uses bbp_is_query_name() To get the query name |
---|
803 | * @return bool Is it a view page? |
---|
804 | */ |
---|
805 | function bbp_is_single_view() { |
---|
806 | global $wp_query; |
---|
807 | |
---|
808 | // Assume false |
---|
809 | $retval = false; |
---|
810 | |
---|
811 | // Check query |
---|
812 | if ( ! empty( $wp_query->bbp_is_view ) && ( true === $wp_query->bbp_is_view ) ) { |
---|
813 | $retval = true; |
---|
814 | } |
---|
815 | |
---|
816 | // Check query name |
---|
817 | if ( empty( $retval ) && bbp_is_query_name( 'bbp_single_view' ) ) { |
---|
818 | $retval = true; |
---|
819 | } |
---|
820 | |
---|
821 | return (bool) apply_filters( 'bbp_is_single_view', $retval ); |
---|
822 | } |
---|
823 | |
---|
824 | /** |
---|
825 | * Check if current page is a search page |
---|
826 | * |
---|
827 | * @since 2.3.0 bbPress (r4579) |
---|
828 | * |
---|
829 | * @global WP_Query $wp_query To check if WP_Query::bbp_is_search is true |
---|
830 | * @uses bbp_is_query_name() To get the query name |
---|
831 | * @return bool Is it a search page? |
---|
832 | */ |
---|
833 | function bbp_is_search() { |
---|
834 | global $wp_query; |
---|
835 | |
---|
836 | // Bail if search is disabled |
---|
837 | if ( ! bbp_allow_search() ) { |
---|
838 | return false; |
---|
839 | } |
---|
840 | |
---|
841 | // Assume false |
---|
842 | $retval = false; |
---|
843 | |
---|
844 | // Check query |
---|
845 | if ( ! empty( $wp_query->bbp_is_search ) && ( true === $wp_query->bbp_is_search ) ) { |
---|
846 | $retval = true; |
---|
847 | } |
---|
848 | |
---|
849 | // Check query name |
---|
850 | if ( empty( $retval ) && bbp_is_query_name( bbp_get_search_rewrite_id() ) ) { |
---|
851 | $retval = true; |
---|
852 | } |
---|
853 | |
---|
854 | // Check $_GET |
---|
855 | if ( empty( $retval ) && isset( $_REQUEST[ bbp_get_search_rewrite_id() ] ) && empty( $_REQUEST[ bbp_get_search_rewrite_id() ] ) ) { |
---|
856 | $retval = true; |
---|
857 | } |
---|
858 | |
---|
859 | return (bool) apply_filters( 'bbp_is_search', $retval ); |
---|
860 | } |
---|
861 | |
---|
862 | /** |
---|
863 | * Check if current page is a search results page |
---|
864 | * |
---|
865 | * @since 2.4.0 bbPress (r4919) |
---|
866 | * |
---|
867 | * @global WP_Query $wp_query To check if WP_Query::bbp_is_search is true |
---|
868 | * @uses bbp_is_query_name() To get the query name |
---|
869 | * @return bool Is it a search page? |
---|
870 | */ |
---|
871 | function bbp_is_search_results() { |
---|
872 | global $wp_query; |
---|
873 | |
---|
874 | // Bail if search is disabled |
---|
875 | if ( ! bbp_allow_search() ) { |
---|
876 | return false; |
---|
877 | } |
---|
878 | |
---|
879 | // Assume false |
---|
880 | $retval = false; |
---|
881 | |
---|
882 | // Check query |
---|
883 | if ( ! empty( $wp_query->bbp_search_terms ) ) { |
---|
884 | $retval = true; |
---|
885 | } |
---|
886 | |
---|
887 | // Check query name |
---|
888 | if ( empty( $retval ) && bbp_is_query_name( 'bbp_search_results' ) ) { |
---|
889 | $retval = true; |
---|
890 | } |
---|
891 | |
---|
892 | // Check $_REQUEST |
---|
893 | if ( empty( $retval ) && ! empty( $_REQUEST[ bbp_get_search_rewrite_id() ] ) ) { |
---|
894 | $retval = true; |
---|
895 | } |
---|
896 | |
---|
897 | return (bool) apply_filters( 'bbp_is_search_results', $retval ); |
---|
898 | } |
---|
899 | |
---|
900 | /** |
---|
901 | * Check if current page is an edit page |
---|
902 | * |
---|
903 | * @since 2.1.0 bbPress (r3585) |
---|
904 | * |
---|
905 | * @uses WP_Query Checks if WP_Query::bbp_is_edit is true |
---|
906 | * @return bool True if it's the edit page, false if not |
---|
907 | */ |
---|
908 | function bbp_is_edit() { |
---|
909 | global $wp_query; |
---|
910 | |
---|
911 | // Assume false |
---|
912 | $retval = false; |
---|
913 | |
---|
914 | // Check query |
---|
915 | if ( ! empty( $wp_query->bbp_is_edit ) && ( $wp_query->bbp_is_edit === true ) ) { |
---|
916 | $retval = true; |
---|
917 | } |
---|
918 | |
---|
919 | return (bool) apply_filters( 'bbp_is_edit', $retval ); |
---|
920 | } |
---|
921 | |
---|
922 | /** |
---|
923 | * Use the above is_() functions to output a body class for each scenario |
---|
924 | * |
---|
925 | * @since 2.0.0 bbPress (r2926) |
---|
926 | * |
---|
927 | * @param array $wp_classes |
---|
928 | * @param array $custom_classes |
---|
929 | * @uses bbp_is_single_forum() |
---|
930 | * @uses bbp_is_single_topic() |
---|
931 | * @uses bbp_is_topic_edit() |
---|
932 | * @uses bbp_is_topic_merge() |
---|
933 | * @uses bbp_is_topic_split() |
---|
934 | * @uses bbp_is_single_reply() |
---|
935 | * @uses bbp_is_reply_edit() |
---|
936 | * @uses bbp_is_reply_move() |
---|
937 | * @uses bbp_is_single_view() |
---|
938 | * @uses bbp_is_single_user_edit() |
---|
939 | * @uses bbp_is_single_user() |
---|
940 | * @uses bbp_is_user_home() |
---|
941 | * @uses bbp_is_subscriptions() |
---|
942 | * @uses bbp_is_favorites() |
---|
943 | * @uses bbp_is_topics_created() |
---|
944 | * @uses bbp_is_replies_created() |
---|
945 | * @uses bbp_is_forum_archive() |
---|
946 | * @uses bbp_is_topic_archive() |
---|
947 | * @uses bbp_is_topic_tag() |
---|
948 | * @uses bbp_is_topic_tag_edit() |
---|
949 | * @uses bbp_get_topic_tag_tax_id() |
---|
950 | * @uses bbp_get_topic_tag_slug() |
---|
951 | * @uses bbp_get_topic_tag_id() |
---|
952 | * @return array Body Classes |
---|
953 | */ |
---|
954 | function bbp_body_class( $wp_classes, $custom_classes = false ) { |
---|
955 | |
---|
956 | $bbp_classes = array(); |
---|
957 | |
---|
958 | /** Archives **************************************************************/ |
---|
959 | |
---|
960 | if ( bbp_is_forum_archive() ) { |
---|
961 | $bbp_classes[] = bbp_get_forum_post_type() . '-archive'; |
---|
962 | |
---|
963 | } elseif ( bbp_is_topic_archive() ) { |
---|
964 | $bbp_classes[] = bbp_get_topic_post_type() . '-archive'; |
---|
965 | |
---|
966 | /** Topic Tags ************************************************************/ |
---|
967 | |
---|
968 | } elseif ( bbp_is_topic_tag() ) { |
---|
969 | $bbp_classes[] = bbp_get_topic_tag_tax_id(); |
---|
970 | $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug(); |
---|
971 | $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id(); |
---|
972 | } elseif ( bbp_is_topic_tag_edit() ) { |
---|
973 | $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-edit'; |
---|
974 | $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug() . '-edit'; |
---|
975 | $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id() . '-edit'; |
---|
976 | |
---|
977 | /** Components ************************************************************/ |
---|
978 | |
---|
979 | } elseif ( bbp_is_single_forum() ) { |
---|
980 | $bbp_classes[] = bbp_get_forum_post_type(); |
---|
981 | |
---|
982 | } elseif ( bbp_is_single_topic() ) { |
---|
983 | $bbp_classes[] = bbp_get_topic_post_type(); |
---|
984 | |
---|
985 | } elseif ( bbp_is_single_reply() ) { |
---|
986 | $bbp_classes[] = bbp_get_reply_post_type(); |
---|
987 | |
---|
988 | } elseif ( bbp_is_topic_edit() ) { |
---|
989 | $bbp_classes[] = bbp_get_topic_post_type() . '-edit'; |
---|
990 | |
---|
991 | } elseif ( bbp_is_topic_merge() ) { |
---|
992 | $bbp_classes[] = bbp_get_topic_post_type() . '-merge'; |
---|
993 | |
---|
994 | } elseif ( bbp_is_topic_split() ) { |
---|
995 | $bbp_classes[] = bbp_get_topic_post_type() . '-split'; |
---|
996 | |
---|
997 | } elseif ( bbp_is_reply_edit() ) { |
---|
998 | $bbp_classes[] = bbp_get_reply_post_type() . '-edit'; |
---|
999 | |
---|
1000 | } elseif ( bbp_is_reply_move() ) { |
---|
1001 | $bbp_classes[] = bbp_get_reply_post_type() . '-move'; |
---|
1002 | |
---|
1003 | } elseif ( bbp_is_single_view() ) { |
---|
1004 | $bbp_classes[] = 'bbp-view'; |
---|
1005 | |
---|
1006 | /** User ******************************************************************/ |
---|
1007 | |
---|
1008 | } elseif ( bbp_is_single_user_edit() ) { |
---|
1009 | $bbp_classes[] = 'bbp-user-edit'; |
---|
1010 | $bbp_classes[] = 'single'; |
---|
1011 | $bbp_classes[] = 'singular'; |
---|
1012 | |
---|
1013 | } elseif ( bbp_is_single_user() ) { |
---|
1014 | $bbp_classes[] = 'bbp-user-page'; |
---|
1015 | $bbp_classes[] = 'single'; |
---|
1016 | $bbp_classes[] = 'singular'; |
---|
1017 | |
---|
1018 | } elseif ( bbp_is_user_home() ) { |
---|
1019 | $bbp_classes[] = 'bbp-user-home'; |
---|
1020 | $bbp_classes[] = 'single'; |
---|
1021 | $bbp_classes[] = 'singular'; |
---|
1022 | |
---|
1023 | } elseif ( bbp_is_user_home_edit() ) { |
---|
1024 | $bbp_classes[] = 'bbp-user-home-edit'; |
---|
1025 | $bbp_classes[] = 'single'; |
---|
1026 | $bbp_classes[] = 'singular'; |
---|
1027 | |
---|
1028 | } elseif ( bbp_is_topics_created() ) { |
---|
1029 | $bbp_classes[] = 'bbp-topics-created'; |
---|
1030 | $bbp_classes[] = 'single'; |
---|
1031 | $bbp_classes[] = 'singular'; |
---|
1032 | |
---|
1033 | } elseif ( bbp_is_replies_created() ) { |
---|
1034 | $bbp_classes[] = 'bbp-replies-created'; |
---|
1035 | $bbp_classes[] = 'single'; |
---|
1036 | $bbp_classes[] = 'singular'; |
---|
1037 | |
---|
1038 | } elseif ( bbp_is_favorites() ) { |
---|
1039 | $bbp_classes[] = 'bbp-favorites'; |
---|
1040 | $bbp_classes[] = 'single'; |
---|
1041 | $bbp_classes[] = 'singular'; |
---|
1042 | |
---|
1043 | } elseif ( bbp_is_subscriptions() ) { |
---|
1044 | $bbp_classes[] = 'bbp-subscriptions'; |
---|
1045 | $bbp_classes[] = 'single'; |
---|
1046 | $bbp_classes[] = 'singular'; |
---|
1047 | |
---|
1048 | /** Search ****************************************************************/ |
---|
1049 | |
---|
1050 | } elseif ( bbp_is_search() ) { |
---|
1051 | $bbp_classes[] = 'bbp-search'; |
---|
1052 | $bbp_classes[] = 'forum-search'; |
---|
1053 | |
---|
1054 | } elseif ( bbp_is_search_results() ) { |
---|
1055 | $bbp_classes[] = 'bbp-search-results'; |
---|
1056 | $bbp_classes[] = 'forum-search-results'; |
---|
1057 | } |
---|
1058 | |
---|
1059 | /** Clean up **************************************************************/ |
---|
1060 | |
---|
1061 | // Add bbPress class if we are within a bbPress page |
---|
1062 | if ( ! empty( $bbp_classes ) ) { |
---|
1063 | $bbp_classes[] = 'bbpress'; |
---|
1064 | } |
---|
1065 | |
---|
1066 | // Merge WP classes with bbPress classes and remove any duplicates |
---|
1067 | $classes = array_unique( array_merge( (array) $bbp_classes, (array) $wp_classes ) ); |
---|
1068 | |
---|
1069 | // Deprecated filter (do not use) |
---|
1070 | $classes = apply_filters( 'bbp_get_the_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes ); |
---|
1071 | |
---|
1072 | return apply_filters( 'bbp_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes ); |
---|
1073 | } |
---|
1074 | |
---|
1075 | /** |
---|
1076 | * Use the above is_() functions to return if in any bbPress page |
---|
1077 | * |
---|
1078 | * @since 2.0.0 bbPress (r3344) |
---|
1079 | * |
---|
1080 | * @uses bbp_is_single_forum() |
---|
1081 | * @uses bbp_is_single_topic() |
---|
1082 | * @uses bbp_is_topic_edit() |
---|
1083 | * @uses bbp_is_topic_merge() |
---|
1084 | * @uses bbp_is_topic_split() |
---|
1085 | * @uses bbp_is_single_reply() |
---|
1086 | * @uses bbp_is_reply_edit() |
---|
1087 | * @uses bbp_is_reply_move() |
---|
1088 | * @uses bbp_is_single_view() |
---|
1089 | * @uses bbp_is_single_user_edit() |
---|
1090 | * @uses bbp_is_single_user() |
---|
1091 | * @uses bbp_is_user_home() |
---|
1092 | * @uses bbp_is_subscriptions() |
---|
1093 | * @uses bbp_is_favorites() |
---|
1094 | * @uses bbp_is_topics_created() |
---|
1095 | * @uses bbp_is_replies_created() |
---|
1096 | * @return bool In a bbPress page |
---|
1097 | */ |
---|
1098 | function is_bbpress() { |
---|
1099 | |
---|
1100 | // Defalt to false |
---|
1101 | $retval = false; |
---|
1102 | |
---|
1103 | /** Archives **************************************************************/ |
---|
1104 | |
---|
1105 | if ( bbp_is_forum_archive() ) { |
---|
1106 | $retval = true; |
---|
1107 | |
---|
1108 | } elseif ( bbp_is_topic_archive() ) { |
---|
1109 | $retval = true; |
---|
1110 | |
---|
1111 | /** Topic Tags ************************************************************/ |
---|
1112 | |
---|
1113 | } elseif ( bbp_is_topic_tag() ) { |
---|
1114 | $retval = true; |
---|
1115 | |
---|
1116 | } elseif ( bbp_is_topic_tag_edit() ) { |
---|
1117 | $retval = true; |
---|
1118 | |
---|
1119 | /** Components ************************************************************/ |
---|
1120 | |
---|
1121 | } elseif ( bbp_is_single_forum() ) { |
---|
1122 | $retval = true; |
---|
1123 | |
---|
1124 | } elseif ( bbp_is_single_topic() ) { |
---|
1125 | $retval = true; |
---|
1126 | |
---|
1127 | } elseif ( bbp_is_single_reply() ) { |
---|
1128 | $retval = true; |
---|
1129 | |
---|
1130 | } elseif ( bbp_is_topic_edit() ) { |
---|
1131 | $retval = true; |
---|
1132 | |
---|
1133 | } elseif ( bbp_is_topic_merge() ) { |
---|
1134 | $retval = true; |
---|
1135 | |
---|
1136 | } elseif ( bbp_is_topic_split() ) { |
---|
1137 | $retval = true; |
---|
1138 | |
---|
1139 | } elseif ( bbp_is_reply_edit() ) { |
---|
1140 | $retval = true; |
---|
1141 | |
---|
1142 | } elseif ( bbp_is_reply_move() ) { |
---|
1143 | $retval = true; |
---|
1144 | |
---|
1145 | } elseif ( bbp_is_single_view() ) { |
---|
1146 | $retval = true; |
---|
1147 | |
---|
1148 | /** User ******************************************************************/ |
---|
1149 | |
---|
1150 | } elseif ( bbp_is_single_user_edit() ) { |
---|
1151 | $retval = true; |
---|
1152 | |
---|
1153 | } elseif ( bbp_is_single_user() ) { |
---|
1154 | $retval = true; |
---|
1155 | |
---|
1156 | } elseif ( bbp_is_user_home() ) { |
---|
1157 | $retval = true; |
---|
1158 | |
---|
1159 | } elseif ( bbp_is_user_home_edit() ) { |
---|
1160 | $retval = true; |
---|
1161 | |
---|
1162 | } elseif ( bbp_is_topics_created() ) { |
---|
1163 | $retval = true; |
---|
1164 | |
---|
1165 | } elseif ( bbp_is_replies_created() ) { |
---|
1166 | $retval = true; |
---|
1167 | |
---|
1168 | } elseif ( bbp_is_favorites() ) { |
---|
1169 | $retval = true; |
---|
1170 | |
---|
1171 | } elseif ( bbp_is_subscriptions() ) { |
---|
1172 | $retval = true; |
---|
1173 | |
---|
1174 | /** Search ****************************************************************/ |
---|
1175 | |
---|
1176 | } elseif ( bbp_is_search() ) { |
---|
1177 | $retval = true; |
---|
1178 | |
---|
1179 | } elseif ( bbp_is_search_results() ) { |
---|
1180 | $retval = true; |
---|
1181 | } |
---|
1182 | |
---|
1183 | /** Done ******************************************************************/ |
---|
1184 | |
---|
1185 | return (bool) apply_filters( 'is_bbpress', $retval ); |
---|
1186 | } |
---|
1187 | |
---|
1188 | /** Forms *********************************************************************/ |
---|
1189 | |
---|
1190 | /** |
---|
1191 | * Output the login form action url |
---|
1192 | * |
---|
1193 | * @since 2.0.0 bbPress (r2815) |
---|
1194 | * |
---|
1195 | * @param array $args This function supports these arguments: |
---|
1196 | * - action: The action being taken |
---|
1197 | * - context: The context the action is being taken from |
---|
1198 | * @uses add_query_arg() To add a arg to the url |
---|
1199 | * @uses site_url() Toget the site url |
---|
1200 | * @uses apply_filters() Calls 'bbp_wp_login_action' with the url and args |
---|
1201 | */ |
---|
1202 | function bbp_wp_login_action( $args = array() ) { |
---|
1203 | echo esc_url( bbp_get_wp_login_action( $args ) ); |
---|
1204 | } |
---|
1205 | |
---|
1206 | /** |
---|
1207 | * Return the login form action url |
---|
1208 | * |
---|
1209 | * @since 2.6.0 bbPress (r5684) |
---|
1210 | * |
---|
1211 | * @param array $args This function supports these arguments: |
---|
1212 | * - action: The action being taken |
---|
1213 | * - context: The context the action is being taken from |
---|
1214 | * @uses add_query_arg() To add a arg to the url |
---|
1215 | * @uses site_url() Toget the site url |
---|
1216 | * @uses apply_filters() Calls 'bbp_wp_login_action' with the url and args |
---|
1217 | */ |
---|
1218 | function bbp_get_wp_login_action( $args = array() ) { |
---|
1219 | |
---|
1220 | // Parse arguments against default values |
---|
1221 | $r = bbp_parse_args( $args, array( |
---|
1222 | 'action' => '', |
---|
1223 | 'context' => '', |
---|
1224 | 'url' => 'wp-login.php' |
---|
1225 | ), 'login_action' ); |
---|
1226 | |
---|
1227 | // Add action as query arg |
---|
1228 | if ( ! empty( $r['action'] ) ) { |
---|
1229 | $login_url = add_query_arg( array( 'action' => $r['action'] ), $r['url'] ); |
---|
1230 | |
---|
1231 | // No query arg |
---|
1232 | } else { |
---|
1233 | $login_url = $r['url']; |
---|
1234 | } |
---|
1235 | |
---|
1236 | $login_url = site_url( $login_url, $r['context'] ); |
---|
1237 | |
---|
1238 | return apply_filters( 'bbp_get_wp_login_action', $login_url, $r, $args ); |
---|
1239 | } |
---|
1240 | |
---|
1241 | /** |
---|
1242 | * Output hidden request URI field for user forms. |
---|
1243 | * |
---|
1244 | * The referer link is the current Request URI from the server super global. To |
---|
1245 | * check the field manually, use bbp_get_redirect_to(). |
---|
1246 | * |
---|
1247 | * @since 2.0.0 bbPress (r2815) |
---|
1248 | * |
---|
1249 | * @param string $redirect_to Pass a URL to redirect to |
---|
1250 | * |
---|
1251 | * @uses wp_get_referer() To get the referer |
---|
1252 | * @uses esc_attr() To escape the url |
---|
1253 | * @uses apply_filters() Calls 'bbp_redirect_to_field', passes field and to |
---|
1254 | */ |
---|
1255 | function bbp_redirect_to_field( $redirect_to = '' ) { |
---|
1256 | |
---|
1257 | // Make sure we are directing somewhere |
---|
1258 | if ( empty( $redirect_to ) ) { |
---|
1259 | if ( isset( $_SERVER['REQUEST_URI'] ) ) { |
---|
1260 | $redirect_to = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
---|
1261 | } else { |
---|
1262 | $redirect_to = wp_get_referer(); |
---|
1263 | } |
---|
1264 | } |
---|
1265 | |
---|
1266 | // Remove loggedout query arg if it's there |
---|
1267 | $redirect_to = remove_query_arg( 'loggedout', $redirect_to ); |
---|
1268 | $redirect_field = '<input type="hidden" id="bbp_redirect_to" name="redirect_to" value="' . esc_url( $redirect_to ) . '" />'; |
---|
1269 | |
---|
1270 | echo apply_filters( 'bbp_redirect_to_field', $redirect_field, $redirect_to ); |
---|
1271 | } |
---|
1272 | |
---|
1273 | /** |
---|
1274 | * Echo sanitized $_REQUEST value. |
---|
1275 | * |
---|
1276 | * Use the $input_type parameter to properly process the value. This |
---|
1277 | * ensures correct sanitization of the value for the receiving input. |
---|
1278 | * |
---|
1279 | * @since 2.0.0 bbPress (r2815) |
---|
1280 | * |
---|
1281 | * @param string $request Name of $_REQUEST to look for |
---|
1282 | * @param string $input_type Type of input. Default: text. Accepts: |
---|
1283 | * textarea|password|select|radio|checkbox |
---|
1284 | * @uses bbp_get_sanitize_val() To sanitize the value. |
---|
1285 | */ |
---|
1286 | function bbp_sanitize_val( $request = '', $input_type = 'text' ) { |
---|
1287 | echo bbp_get_sanitize_val( $request, $input_type ); |
---|
1288 | } |
---|
1289 | /** |
---|
1290 | * Return sanitized $_REQUEST value. |
---|
1291 | * |
---|
1292 | * Use the $input_type parameter to properly process the value. This |
---|
1293 | * ensures correct sanitization of the value for the receiving input. |
---|
1294 | * |
---|
1295 | * @since 2.0.0 bbPress (r2815) |
---|
1296 | * |
---|
1297 | * @param string $request Name of $_REQUEST to look for |
---|
1298 | * @param string $input_type Type of input. Default: text. Accepts: |
---|
1299 | * textarea|password|select|radio|checkbox |
---|
1300 | * @uses esc_attr() To escape the string |
---|
1301 | * @uses apply_filters() Calls 'bbp_get_sanitize_val' with the sanitized |
---|
1302 | * value, request and input type |
---|
1303 | * @return string Sanitized value ready for screen display |
---|
1304 | */ |
---|
1305 | function bbp_get_sanitize_val( $request = '', $input_type = 'text' ) { |
---|
1306 | |
---|
1307 | // Check that requested |
---|
1308 | if ( empty( $_REQUEST[ $request ] ) ) { |
---|
1309 | return false; |
---|
1310 | } |
---|
1311 | |
---|
1312 | // Set request varaible |
---|
1313 | $pre_ret_val = $_REQUEST[ $request ]; |
---|
1314 | |
---|
1315 | // Treat different kinds of fields in different ways |
---|
1316 | switch ( $input_type ) { |
---|
1317 | case 'text' : |
---|
1318 | case 'textarea' : |
---|
1319 | $retval = esc_attr( wp_unslash( $pre_ret_val ) ); |
---|
1320 | break; |
---|
1321 | |
---|
1322 | case 'password' : |
---|
1323 | case 'select' : |
---|
1324 | case 'radio' : |
---|
1325 | case 'checkbox' : |
---|
1326 | default : |
---|
1327 | $retval = esc_attr( $pre_ret_val ); |
---|
1328 | break; |
---|
1329 | } |
---|
1330 | |
---|
1331 | return apply_filters( 'bbp_get_sanitize_val', $retval, $request, $input_type ); |
---|
1332 | } |
---|
1333 | |
---|
1334 | /** |
---|
1335 | * Output the current tab index of a given form |
---|
1336 | * |
---|
1337 | * Use this function to handle the tab indexing of user facing forms within a |
---|
1338 | * template file. Calling this function will automatically increment the global |
---|
1339 | * tab index by default. |
---|
1340 | * |
---|
1341 | * @since 2.0.0 bbPress (r2810) |
---|
1342 | * |
---|
1343 | * @deprecated 2.6.0 bbPress (r5561) |
---|
1344 | * |
---|
1345 | * @link https://bbpress.trac.wordpress.org/attachment/ticket/2714 Trac Ticket |
---|
1346 | * @param int $auto_increment Optional. Default true. Set to false to prevent |
---|
1347 | * increment |
---|
1348 | */ |
---|
1349 | function bbp_tab_index( $auto_increment = true ) { |
---|
1350 | echo bbp_get_tab_index( $auto_increment ); |
---|
1351 | } |
---|
1352 | |
---|
1353 | /** |
---|
1354 | * Return the current tab index of a given form |
---|
1355 | * |
---|
1356 | * Use this function to handle the tab indexing of user facing forms |
---|
1357 | * within a template file. Calling this function will automatically |
---|
1358 | * increment the global tab index by default. |
---|
1359 | * |
---|
1360 | * @since 2.0.0 bbPress (r2810) |
---|
1361 | * |
---|
1362 | * @deprecated 2.6.0 bbPress (r5561) |
---|
1363 | * |
---|
1364 | * @link https://bbpress.trac.wordpress.org/attachment/ticket/2714 Trac Ticket |
---|
1365 | * @uses apply_filters Allows return value to be filtered |
---|
1366 | * @param int $auto_increment Optional. Default true. Set to false to |
---|
1367 | * prevent the increment |
---|
1368 | * @return int $bbp->tab_index The global tab index |
---|
1369 | */ |
---|
1370 | function bbp_get_tab_index( $auto_increment = true ) { |
---|
1371 | $bbp = bbpress(); |
---|
1372 | |
---|
1373 | if ( true === $auto_increment ) { |
---|
1374 | ++$bbp->tab_index; |
---|
1375 | } |
---|
1376 | |
---|
1377 | return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index ); |
---|
1378 | } |
---|
1379 | |
---|
1380 | /** |
---|
1381 | * Output a select box allowing to pick which forum/topic a new topic/reply |
---|
1382 | * belongs in. |
---|
1383 | * |
---|
1384 | * Can be used for any post type, but is mostly used for topics and forums. |
---|
1385 | * |
---|
1386 | * @since 2.0.0 bbPress (r2746) |
---|
1387 | * |
---|
1388 | * @param array $args See {@link bbp_get_dropdown()} for arguments |
---|
1389 | */ |
---|
1390 | function bbp_dropdown( $args = array() ) { |
---|
1391 | echo bbp_get_dropdown( $args ); |
---|
1392 | } |
---|
1393 | /** |
---|
1394 | * Return a select box allowing to pick which forum/topic a new |
---|
1395 | * topic/reply belongs in. |
---|
1396 | * |
---|
1397 | * @since 2.0.0 bbPress (r2746) |
---|
1398 | * |
---|
1399 | * @param array $args The function supports these args: |
---|
1400 | * - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum) |
---|
1401 | * - selected: Selected ID, to not have any value as selected, pass |
---|
1402 | * anything smaller than 0 (due to the nature of select |
---|
1403 | * box, the first value would of course be selected - |
---|
1404 | * though you can have that as none (pass 'show_none' arg)) |
---|
1405 | * - orderby: Defaults to 'menu_order title' |
---|
1406 | * - post_parent: Post parent. Defaults to 0 |
---|
1407 | * - post_status: Which all post_statuses to find in? Can be an array |
---|
1408 | * or CSV of publish, category, closed, private, spam, |
---|
1409 | * trash (based on post type) - if not set, these are |
---|
1410 | * automatically determined based on the post_type |
---|
1411 | * - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get |
---|
1412 | * all posts |
---|
1413 | * - walker: Which walker to use? Defaults to |
---|
1414 | * {@link BBP_Walker_Dropdown} |
---|
1415 | * - select_id: ID of the select box. Defaults to 'bbp_forum_id' |
---|
1416 | * - tab: Deprecated. Tabindex value. False or integer |
---|
1417 | * - options_only: Show only <options>? No <select>? |
---|
1418 | * - show_none: Boolean or String __( '— No Forum —', 'bbpress' ) |
---|
1419 | * - disable_categories: Disable forum categories and closed forums? |
---|
1420 | * Defaults to true. Only for forums and when |
---|
1421 | * the category option is displayed. |
---|
1422 | * @uses BBP_Walker_Dropdown() As the default walker to generate the |
---|
1423 | * dropdown |
---|
1424 | * @uses current_user_can() To check if the current user can read |
---|
1425 | * private forums |
---|
1426 | * @uses bbp_get_forum_post_type() To get the forum post type |
---|
1427 | * @uses bbp_get_topic_post_type() To get the topic post type |
---|
1428 | * @uses walk_page_dropdown_tree() To generate the dropdown using the |
---|
1429 | * walker |
---|
1430 | * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown |
---|
1431 | * and args |
---|
1432 | * @return string The dropdown |
---|
1433 | */ |
---|
1434 | function bbp_get_dropdown( $args = array() ) { |
---|
1435 | |
---|
1436 | // Setup return value |
---|
1437 | $retval = ''; |
---|
1438 | |
---|
1439 | /** Arguments *********************************************************/ |
---|
1440 | |
---|
1441 | // Parse arguments against default values |
---|
1442 | $r = bbp_parse_args( $args, array( |
---|
1443 | 'post_type' => bbp_get_forum_post_type(), |
---|
1444 | 'post_parent' => null, |
---|
1445 | 'post_status' => null, |
---|
1446 | 'selected' => 0, |
---|
1447 | 'exclude' => array(), |
---|
1448 | 'numberposts' => -1, |
---|
1449 | 'orderby' => 'menu_order title', |
---|
1450 | 'order' => 'ASC', |
---|
1451 | 'posts' => array(), |
---|
1452 | 'walker' => '', |
---|
1453 | |
---|
1454 | // Output-related |
---|
1455 | 'select_id' => 'bbp_forum_id', |
---|
1456 | 'select_class' => 'bbp_dropdown', |
---|
1457 | 'tab' => false, |
---|
1458 | 'options_only' => false, |
---|
1459 | 'show_none' => false, |
---|
1460 | 'disable_categories' => true, |
---|
1461 | 'disabled' => '' |
---|
1462 | ), 'get_dropdown' ); |
---|
1463 | |
---|
1464 | if ( empty( $r['walker'] ) ) { |
---|
1465 | $r['walker'] = new BBP_Walker_Dropdown(); |
---|
1466 | $r['walker']->tree_type = $r['post_type']; |
---|
1467 | } |
---|
1468 | |
---|
1469 | // Force 0 |
---|
1470 | if ( is_numeric( $r['selected'] ) && $r['selected'] < 0 ) { |
---|
1471 | $r['selected'] = 0; |
---|
1472 | } |
---|
1473 | |
---|
1474 | // Force array |
---|
1475 | if ( ! empty( $r['exclude'] ) && !is_array( $r['exclude'] ) ) { |
---|
1476 | $r['exclude'] = explode( ',', $r['exclude'] ); |
---|
1477 | } |
---|
1478 | |
---|
1479 | /** Setup Posts *******************************************************/ |
---|
1480 | |
---|
1481 | /** |
---|
1482 | * Allow passing of custom posts data |
---|
1483 | * |
---|
1484 | * @see bbp_get_reply_to_dropdown() as an example |
---|
1485 | */ |
---|
1486 | if ( empty( $r['posts'] ) ) { |
---|
1487 | $r['posts'] = get_posts( array( |
---|
1488 | 'post_type' => $r['post_type'], |
---|
1489 | 'post_status' => $r['post_status'], |
---|
1490 | 'post_parent' => $r['post_parent'], |
---|
1491 | 'exclude' => $r['exclude'], |
---|
1492 | 'numberposts' => $r['numberposts'], |
---|
1493 | 'orderby' => $r['orderby'], |
---|
1494 | 'order' => $r['order'], |
---|
1495 | ) ); |
---|
1496 | } |
---|
1497 | |
---|
1498 | /** Drop Down *********************************************************/ |
---|
1499 | |
---|
1500 | // Build the opening tag for the select element |
---|
1501 | if ( empty( $r['options_only'] ) ) { |
---|
1502 | |
---|
1503 | // Should this select appear disabled? |
---|
1504 | $disabled = disabled( isset( bbpress()->options[ $r['disabled'] ] ), true, false ); |
---|
1505 | |
---|
1506 | // Setup the tab index attribute |
---|
1507 | $tab = ! empty( $r['tab'] ) ? ' tabindex="' . intval( $r['tab'] ) . '"' : ''; |
---|
1508 | |
---|
1509 | // Open the select tag |
---|
1510 | $retval .= '<select name="' . esc_attr( $r['select_id'] ) . '" id="' . esc_attr( $r['select_id'] ) . '" class="' . esc_attr( $r['select_class'] ) . '"' . $disabled . $tab . '>' . "\n"; |
---|
1511 | } |
---|
1512 | |
---|
1513 | // Display a leading 'no-value' option, with or without custom text |
---|
1514 | if ( ! empty( $r['show_none'] ) || ! empty( $r['none_found'] ) ) { |
---|
1515 | |
---|
1516 | // Open the 'no-value' option tag |
---|
1517 | $retval .= "\t<option value=\"\" class=\"level-0\">"; |
---|
1518 | |
---|
1519 | // Use deprecated 'none_found' first for backpat |
---|
1520 | if ( ! empty( $r['none_found'] ) && is_string( $r['none_found'] ) ) { |
---|
1521 | $retval .= esc_html( $r['none_found'] ); |
---|
1522 | |
---|
1523 | // Use 'show_none' second |
---|
1524 | } elseif ( ! empty( $r['show_none'] ) && is_string( $r['show_none'] ) ) { |
---|
1525 | $retval .= esc_html( $r['show_none'] ); |
---|
1526 | |
---|
1527 | // Otherwise, make some educated guesses |
---|
1528 | } else { |
---|
1529 | |
---|
1530 | // Switch the response based on post type |
---|
1531 | switch ( $r['post_type'] ) { |
---|
1532 | |
---|
1533 | // Topics |
---|
1534 | case bbp_get_topic_post_type() : |
---|
1535 | $retval .= esc_html__( 'No topics available', 'bbpress' ); |
---|
1536 | break; |
---|
1537 | |
---|
1538 | // Forums |
---|
1539 | case bbp_get_forum_post_type() : |
---|
1540 | $retval .= esc_html__( 'No forums available', 'bbpress' ); |
---|
1541 | break; |
---|
1542 | |
---|
1543 | // Any other |
---|
1544 | default : |
---|
1545 | $retval .= esc_html__( 'None available', 'bbpress' ); |
---|
1546 | break; |
---|
1547 | } |
---|
1548 | } |
---|
1549 | |
---|
1550 | // Close the 'no-value' option tag |
---|
1551 | $retval .= '</option>'; |
---|
1552 | } |
---|
1553 | |
---|
1554 | // Items found so walk the tree |
---|
1555 | if ( ! empty( $r['posts'] ) ) { |
---|
1556 | $retval .= walk_page_dropdown_tree( $r['posts'], 0, $r ); |
---|
1557 | } |
---|
1558 | |
---|
1559 | // Close the selecet tag |
---|
1560 | if ( empty( $r['options_only'] ) ) { |
---|
1561 | $retval .= '</select>'; |
---|
1562 | } |
---|
1563 | |
---|
1564 | return apply_filters( 'bbp_get_dropdown', $retval, $r ); |
---|
1565 | } |
---|
1566 | |
---|
1567 | /** |
---|
1568 | * Output the required hidden fields when creating/editing a forum |
---|
1569 | * |
---|
1570 | * @since 2.1.0 bbPress (r3553) |
---|
1571 | * |
---|
1572 | * @uses bbp_is_forum_edit() To check if it's the forum edit page |
---|
1573 | * @uses wp_nonce_field() To generate hidden nonce fields |
---|
1574 | * @uses bbp_forum_id() To output the forum id |
---|
1575 | * @uses bbp_is_single_forum() To check if it's a forum page |
---|
1576 | * @uses bbp_forum_id() To output the forum id |
---|
1577 | */ |
---|
1578 | function bbp_forum_form_fields() { |
---|
1579 | |
---|
1580 | if ( bbp_is_forum_edit() ) : ?> |
---|
1581 | |
---|
1582 | <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-forum" /> |
---|
1583 | <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" /> |
---|
1584 | |
---|
1585 | <?php if ( current_user_can( 'unfiltered_html' ) ) : |
---|
1586 | wp_nonce_field( 'bbp-unfiltered-html-forum_' . bbp_get_forum_id(), '_bbp_unfiltered_html_forum', false ); |
---|
1587 | endif; ?> |
---|
1588 | |
---|
1589 | <?php wp_nonce_field( 'bbp-edit-forum_' . bbp_get_forum_id() ); |
---|
1590 | |
---|
1591 | else : |
---|
1592 | |
---|
1593 | if ( bbp_is_single_forum() ) : ?> |
---|
1594 | |
---|
1595 | <input type="hidden" name="bbp_forum_parent_id" id="bbp_forum_parent_id" value="<?php bbp_forum_parent_id(); ?>" /> |
---|
1596 | |
---|
1597 | <?php endif; ?> |
---|
1598 | |
---|
1599 | <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-forum" /> |
---|
1600 | |
---|
1601 | <?php if ( current_user_can( 'unfiltered_html' ) ) : |
---|
1602 | wp_nonce_field( 'bbp-unfiltered-html-forum_new', '_bbp_unfiltered_html_forum', false ); |
---|
1603 | endif; ?> |
---|
1604 | |
---|
1605 | <?php wp_nonce_field( 'bbp-new-forum' ); |
---|
1606 | |
---|
1607 | endif; |
---|
1608 | } |
---|
1609 | |
---|
1610 | /** |
---|
1611 | * Output the required hidden fields when creating/editing a topic |
---|
1612 | * |
---|
1613 | * @since 2.0.0 bbPress (r2753) |
---|
1614 | * |
---|
1615 | * @uses bbp_is_topic_edit() To check if it's the topic edit page |
---|
1616 | * @uses wp_nonce_field() To generate hidden nonce fields |
---|
1617 | * @uses bbp_topic_id() To output the topic id |
---|
1618 | * @uses bbp_is_single_forum() To check if it's a forum page |
---|
1619 | * @uses bbp_forum_id() To output the forum id |
---|
1620 | */ |
---|
1621 | function bbp_topic_form_fields() { |
---|
1622 | |
---|
1623 | if ( bbp_is_topic_edit() ) : ?> |
---|
1624 | |
---|
1625 | <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-topic" /> |
---|
1626 | <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" /> |
---|
1627 | |
---|
1628 | <?php if ( current_user_can( 'unfiltered_html' ) ) : |
---|
1629 | wp_nonce_field( 'bbp-unfiltered-html-topic_' . bbp_get_topic_id(), '_bbp_unfiltered_html_topic', false ); |
---|
1630 | endif; ?> |
---|
1631 | |
---|
1632 | <?php wp_nonce_field( 'bbp-edit-topic_' . bbp_get_topic_id() ); |
---|
1633 | |
---|
1634 | else : |
---|
1635 | |
---|
1636 | if ( bbp_is_single_forum() ) : ?> |
---|
1637 | |
---|
1638 | <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" /> |
---|
1639 | |
---|
1640 | <?php endif; ?> |
---|
1641 | |
---|
1642 | <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-topic" /> |
---|
1643 | |
---|
1644 | <?php if ( current_user_can( 'unfiltered_html' ) ) : |
---|
1645 | wp_nonce_field( 'bbp-unfiltered-html-topic_new', '_bbp_unfiltered_html_topic', false ); |
---|
1646 | endif; ?> |
---|
1647 | |
---|
1648 | <?php wp_nonce_field( 'bbp-new-topic' ); |
---|
1649 | |
---|
1650 | endif; |
---|
1651 | } |
---|
1652 | |
---|
1653 | /** |
---|
1654 | * Output the required hidden fields when creating/editing a reply |
---|
1655 | * |
---|
1656 | * @since 2.0.0 bbPress (r2753) |
---|
1657 | * |
---|
1658 | * @uses bbp_is_reply_edit() To check if it's the reply edit page |
---|
1659 | * @uses wp_nonce_field() To generate hidden nonce fields |
---|
1660 | * @uses bbp_reply_id() To output the reply id |
---|
1661 | * @uses bbp_topic_id() To output the topic id |
---|
1662 | * @uses bbp_forum_id() To output the forum id |
---|
1663 | */ |
---|
1664 | function bbp_reply_form_fields() { |
---|
1665 | |
---|
1666 | if ( bbp_is_reply_edit() ) : ?> |
---|
1667 | |
---|
1668 | <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php bbp_reply_id(); ?>" /> |
---|
1669 | <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-reply" /> |
---|
1670 | |
---|
1671 | <?php if ( current_user_can( 'unfiltered_html' ) ) : |
---|
1672 | wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_reply_id(), '_bbp_unfiltered_html_reply', false ); |
---|
1673 | endif; ?> |
---|
1674 | |
---|
1675 | <?php wp_nonce_field( 'bbp-edit-reply_' . bbp_get_reply_id() ); |
---|
1676 | |
---|
1677 | else : ?> |
---|
1678 | |
---|
1679 | <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" /> |
---|
1680 | <input type="hidden" name="bbp_reply_to" id="bbp_reply_to" value="<?php bbp_form_reply_to(); ?>" /> |
---|
1681 | <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-reply" /> |
---|
1682 | |
---|
1683 | <?php if ( current_user_can( 'unfiltered_html' ) ) : |
---|
1684 | wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_topic_id(), '_bbp_unfiltered_html_reply', false ); |
---|
1685 | endif; ?> |
---|
1686 | |
---|
1687 | <?php wp_nonce_field( 'bbp-new-reply' ); |
---|
1688 | |
---|
1689 | // Show redirect field if not viewing a specific topic |
---|
1690 | if ( bbp_is_query_name( 'bbp_single_topic' ) ) : |
---|
1691 | bbp_redirect_to_field( get_permalink() ); |
---|
1692 | endif; |
---|
1693 | endif; |
---|
1694 | } |
---|
1695 | |
---|
1696 | /** |
---|
1697 | * Output the required hidden fields when editing a user |
---|
1698 | * |
---|
1699 | * @since 2.0.0 bbPress (r2690) |
---|
1700 | * |
---|
1701 | * @uses bbp_displayed_user_id() To output the displayed user id |
---|
1702 | * @uses wp_nonce_field() To generate a hidden referer field |
---|
1703 | */ |
---|
1704 | function bbp_edit_user_form_fields() { |
---|
1705 | ?> |
---|
1706 | |
---|
1707 | <input type="hidden" name="action" id="bbp_post_action" value="bbp-update-user" /> |
---|
1708 | <input type="hidden" name="user_id" id="user_id" value="<?php bbp_displayed_user_id(); ?>" /> |
---|
1709 | |
---|
1710 | <?php wp_nonce_field( 'update-user_' . bbp_get_displayed_user_id() ); |
---|
1711 | } |
---|
1712 | |
---|
1713 | /** |
---|
1714 | * Merge topic form fields |
---|
1715 | * |
---|
1716 | * Output the required hidden fields when merging a topic |
---|
1717 | * |
---|
1718 | * @since 2.0.0 bbPress (r2756) |
---|
1719 | * |
---|
1720 | * @uses wp_nonce_field() To generate a hidden nonce field |
---|
1721 | * @uses bbp_topic_id() To output the topic id |
---|
1722 | */ |
---|
1723 | function bbp_merge_topic_form_fields() { |
---|
1724 | ?> |
---|
1725 | |
---|
1726 | <input type="hidden" name="action" id="bbp_post_action" value="bbp-merge-topic" /> |
---|
1727 | <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" /> |
---|
1728 | |
---|
1729 | <?php wp_nonce_field( 'bbp-merge-topic_' . bbp_get_topic_id() ); |
---|
1730 | } |
---|
1731 | |
---|
1732 | /** |
---|
1733 | * Split topic form fields |
---|
1734 | * |
---|
1735 | * Output the required hidden fields when splitting a topic |
---|
1736 | * |
---|
1737 | * @since 2.0.0 bbPress (r2756) |
---|
1738 | * |
---|
1739 | * @uses wp_nonce_field() To generate a hidden nonce field |
---|
1740 | */ |
---|
1741 | function bbp_split_topic_form_fields() { |
---|
1742 | ?> |
---|
1743 | |
---|
1744 | <input type="hidden" name="action" id="bbp_post_action" value="bbp-split-topic" /> |
---|
1745 | <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo absint( $_GET['reply_id'] ); ?>" /> |
---|
1746 | |
---|
1747 | <?php wp_nonce_field( 'bbp-split-topic_' . bbp_get_topic_id() ); |
---|
1748 | } |
---|
1749 | |
---|
1750 | /** |
---|
1751 | * Move reply form fields |
---|
1752 | * |
---|
1753 | * Output the required hidden fields when moving a reply |
---|
1754 | * |
---|
1755 | * @uses wp_nonce_field() To generate a hidden nonce field |
---|
1756 | */ |
---|
1757 | function bbp_move_reply_form_fields() { |
---|
1758 | ?> |
---|
1759 | |
---|
1760 | <input type="hidden" name="action" id="bbp_post_action" value="bbp-move-reply" /> |
---|
1761 | <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo absint( $_GET['reply_id'] ); ?>" /> |
---|
1762 | |
---|
1763 | <?php wp_nonce_field( 'bbp-move-reply_' . bbp_get_reply_id() ); |
---|
1764 | } |
---|
1765 | |
---|
1766 | /** |
---|
1767 | * Output a textarea or TinyMCE if enabled |
---|
1768 | * |
---|
1769 | * @since 2.1.0 bbPress (r3586) |
---|
1770 | * |
---|
1771 | * @param array $args |
---|
1772 | * @uses bbp_get_the_content() To return the content to output |
---|
1773 | */ |
---|
1774 | function bbp_the_content( $args = array() ) { |
---|
1775 | echo bbp_get_the_content( $args ); |
---|
1776 | } |
---|
1777 | /** |
---|
1778 | * Return a textarea or TinyMCE if enabled |
---|
1779 | * |
---|
1780 | * @since 2.1.0 bbPress (r3586) |
---|
1781 | * |
---|
1782 | * @param array $args |
---|
1783 | * |
---|
1784 | * @uses apply_filter() To filter args and output |
---|
1785 | * @uses wp_parse_pargs() To compare args |
---|
1786 | * @uses bbp_use_wp_editor() To see if WP editor is in use |
---|
1787 | * @uses bbp_is_edit() To see if we are editing something |
---|
1788 | * @uses wp_editor() To output the WordPress editor |
---|
1789 | * |
---|
1790 | * @return string HTML from output buffer |
---|
1791 | */ |
---|
1792 | function bbp_get_the_content( $args = array() ) { |
---|
1793 | |
---|
1794 | // Parse arguments against default values |
---|
1795 | $r = bbp_parse_args( $args, array( |
---|
1796 | 'context' => 'topic', |
---|
1797 | 'before' => '<div class="bbp-the-content-wrapper">', |
---|
1798 | 'after' => '</div>', |
---|
1799 | 'wpautop' => true, |
---|
1800 | 'media_buttons' => false, |
---|
1801 | 'textarea_rows' => '12', |
---|
1802 | 'tabindex' => false, |
---|
1803 | 'tabfocus_elements' => 'bbp_topic_title,bbp_topic_tags', |
---|
1804 | 'editor_class' => 'bbp-the-content', |
---|
1805 | 'tinymce' => false, |
---|
1806 | 'teeny' => true, |
---|
1807 | 'quicktags' => true, |
---|
1808 | 'dfw' => false |
---|
1809 | ), 'get_the_content' ); |
---|
1810 | |
---|
1811 | // If using tinymce, remove our escaping and trust tinymce |
---|
1812 | if ( bbp_use_wp_editor() && ( false !== $r['tinymce'] ) ) { |
---|
1813 | remove_filter( 'bbp_get_form_forum_content', 'esc_textarea' ); |
---|
1814 | remove_filter( 'bbp_get_form_topic_content', 'esc_textarea' ); |
---|
1815 | remove_filter( 'bbp_get_form_reply_content', 'esc_textarea' ); |
---|
1816 | } |
---|
1817 | |
---|
1818 | // Assume we are not editing |
---|
1819 | $post_content = call_user_func( 'bbp_get_form_' . $r['context'] . '_content' ); |
---|
1820 | |
---|
1821 | // Start an output buffor |
---|
1822 | ob_start(); |
---|
1823 | |
---|
1824 | // Output something before the editor |
---|
1825 | if ( ! empty( $r['before'] ) ) { |
---|
1826 | echo $r['before']; |
---|
1827 | } |
---|
1828 | |
---|
1829 | // Use TinyMCE if available |
---|
1830 | if ( bbp_use_wp_editor() ) : |
---|
1831 | |
---|
1832 | // Enable additional TinyMCE plugins before outputting the editor |
---|
1833 | add_filter( 'tiny_mce_plugins', 'bbp_get_tiny_mce_plugins' ); |
---|
1834 | add_filter( 'teeny_mce_plugins', 'bbp_get_tiny_mce_plugins' ); |
---|
1835 | add_filter( 'teeny_mce_buttons', 'bbp_get_teeny_mce_buttons' ); |
---|
1836 | add_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' ); |
---|
1837 | |
---|
1838 | // Output the editor |
---|
1839 | wp_editor( $post_content, 'bbp_' . $r['context'] . '_content', array( |
---|
1840 | 'wpautop' => $r['wpautop'], |
---|
1841 | 'media_buttons' => $r['media_buttons'], |
---|
1842 | 'textarea_rows' => $r['textarea_rows'], |
---|
1843 | 'tabindex' => $r['tabindex'], |
---|
1844 | 'tabfocus_elements' => $r['tabfocus_elements'], |
---|
1845 | 'editor_class' => $r['editor_class'], |
---|
1846 | 'tinymce' => $r['tinymce'], |
---|
1847 | 'teeny' => $r['teeny'], |
---|
1848 | 'quicktags' => $r['quicktags'], |
---|
1849 | 'dfw' => $r['dfw'], |
---|
1850 | ) ); |
---|
1851 | |
---|
1852 | // Remove additional TinyMCE plugins after outputting the editor |
---|
1853 | remove_filter( 'tiny_mce_plugins', 'bbp_get_tiny_mce_plugins' ); |
---|
1854 | remove_filter( 'teeny_mce_plugins', 'bbp_get_tiny_mce_plugins' ); |
---|
1855 | remove_filter( 'teeny_mce_buttons', 'bbp_get_teeny_mce_buttons' ); |
---|
1856 | remove_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' ); |
---|
1857 | |
---|
1858 | /** |
---|
1859 | * Fallback to normal textarea. |
---|
1860 | * |
---|
1861 | * Note that we do not use esc_textarea() here to prevent double |
---|
1862 | * escaping the editable output, mucking up existing content. |
---|
1863 | */ |
---|
1864 | else : |
---|
1865 | |
---|
1866 | // Setup the tab index attribute |
---|
1867 | $tab = ! empty( $r['tab'] ) ? ' tabindex="' . intval( $r['tab'] ) . '"' : ''; ?> |
---|
1868 | |
---|
1869 | <textarea id="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" class="<?php echo esc_attr( $r['editor_class'] ); ?>" name="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" cols="60" rows="<?php echo esc_attr( $r['textarea_rows'] ); ?>" <?php echo $tab; ?>><?php echo $post_content; ?></textarea> |
---|
1870 | |
---|
1871 | <?php endif; |
---|
1872 | |
---|
1873 | // Output something after the editor |
---|
1874 | if ( ! empty( $r['after'] ) ) { |
---|
1875 | echo $r['after']; |
---|
1876 | } |
---|
1877 | |
---|
1878 | // Put the output into a usable variable |
---|
1879 | $output = ob_get_clean(); |
---|
1880 | |
---|
1881 | return apply_filters( 'bbp_get_the_content', $output, $args, $post_content ); |
---|
1882 | } |
---|
1883 | |
---|
1884 | /** |
---|
1885 | * Edit TinyMCE plugins to match core behaviour |
---|
1886 | * |
---|
1887 | * @since 2.3.0 bbPress (r4574) |
---|
1888 | * |
---|
1889 | * @param array $plugins |
---|
1890 | * @see tiny_mce_plugins, teeny_mce_plugins |
---|
1891 | * @return array |
---|
1892 | */ |
---|
1893 | function bbp_get_tiny_mce_plugins( $plugins = array() ) { |
---|
1894 | |
---|
1895 | // Unset fullscreen |
---|
1896 | foreach ( $plugins as $key => $value ) { |
---|
1897 | if ( 'fullscreen' === $value ) { |
---|
1898 | unset( $plugins[ $key ] ); |
---|
1899 | break; |
---|
1900 | } |
---|
1901 | } |
---|
1902 | |
---|
1903 | // Add the tabfocus plugin |
---|
1904 | $plugins[] = 'tabfocus'; |
---|
1905 | |
---|
1906 | return apply_filters( 'bbp_get_tiny_mce_plugins', $plugins ); |
---|
1907 | } |
---|
1908 | |
---|
1909 | /** |
---|
1910 | * Edit TeenyMCE buttons to match allowedtags |
---|
1911 | * |
---|
1912 | * @since 2.3.0 bbPress (r4605) |
---|
1913 | * |
---|
1914 | * @param array $buttons |
---|
1915 | * @see teeny_mce_buttons |
---|
1916 | * @return array |
---|
1917 | */ |
---|
1918 | function bbp_get_teeny_mce_buttons( $buttons = array() ) { |
---|
1919 | |
---|
1920 | // Remove some buttons from TeenyMCE |
---|
1921 | $buttons = array_diff( $buttons, array( |
---|
1922 | 'underline', |
---|
1923 | 'justifyleft', |
---|
1924 | 'justifycenter', |
---|
1925 | 'justifyright' |
---|
1926 | ) ); |
---|
1927 | |
---|
1928 | // Images |
---|
1929 | array_push( $buttons, 'image' ); |
---|
1930 | |
---|
1931 | return apply_filters( 'bbp_get_teeny_mce_buttons', $buttons ); |
---|
1932 | } |
---|
1933 | |
---|
1934 | /** |
---|
1935 | * Edit TinyMCE quicktags buttons to match allowedtags |
---|
1936 | * |
---|
1937 | * @since 2.3.0 bbPress (r4606) |
---|
1938 | * |
---|
1939 | * @param array $settings |
---|
1940 | * @see quicktags_settings |
---|
1941 | * @return array Quicktags settings |
---|
1942 | */ |
---|
1943 | function bbp_get_quicktags_settings( $settings = array() ) { |
---|
1944 | |
---|
1945 | // Get buttons out of settings |
---|
1946 | $buttons_array = explode( ',', $settings['buttons'] ); |
---|
1947 | |
---|
1948 | // Diff the ones we don't want out |
---|
1949 | $buttons = array_diff( $buttons_array, array( |
---|
1950 | 'ins', |
---|
1951 | 'more', |
---|
1952 | 'spell' |
---|
1953 | ) ); |
---|
1954 | |
---|
1955 | // Put them back into a string in the $settings array |
---|
1956 | $settings['buttons'] = implode( ',', $buttons ); |
---|
1957 | |
---|
1958 | return apply_filters( 'bbp_get_quicktags_settings', $settings ); |
---|
1959 | } |
---|
1960 | |
---|
1961 | /** Views *********************************************************************/ |
---|
1962 | |
---|
1963 | /** |
---|
1964 | * Output the view id |
---|
1965 | * |
---|
1966 | * @since 2.0.0 bbPress (r2789) |
---|
1967 | * |
---|
1968 | * @param string $view Optional. View id |
---|
1969 | * @uses bbp_get_view_id() To get the view id |
---|
1970 | */ |
---|
1971 | function bbp_view_id( $view = '' ) { |
---|
1972 | echo bbp_get_view_id( $view ); |
---|
1973 | } |
---|
1974 | |
---|
1975 | /** |
---|
1976 | * Get the view id |
---|
1977 | * |
---|
1978 | * Use view id if supplied, otherwise bbp_get_view_rewrite_id() query var. |
---|
1979 | * |
---|
1980 | * @since 2.0.0 bbPress (r2789) |
---|
1981 | * |
---|
1982 | * @param string $view Optional. View id. |
---|
1983 | * @uses sanitize_title() To sanitize the view id |
---|
1984 | * @uses get_query_var() To get the view id query variable |
---|
1985 | * @uses bbp_get_view_rewrite_id() To get the view rewrite ID |
---|
1986 | * @return bool|string ID on success, false on failure |
---|
1987 | */ |
---|
1988 | function bbp_get_view_id( $view = '' ) { |
---|
1989 | $bbp = bbpress(); |
---|
1990 | |
---|
1991 | if ( ! empty( $view ) ) { |
---|
1992 | $view = sanitize_title( $view ); |
---|
1993 | } elseif ( ! empty( $bbp->current_view_id ) ) { |
---|
1994 | $view = $bbp->current_view_id; |
---|
1995 | } else { |
---|
1996 | $view = get_query_var( bbp_get_view_rewrite_id() ); |
---|
1997 | } |
---|
1998 | |
---|
1999 | if ( array_key_exists( $view, $bbp->views ) ) { |
---|
2000 | return $view; |
---|
2001 | } |
---|
2002 | |
---|
2003 | return false; |
---|
2004 | } |
---|
2005 | |
---|
2006 | /** |
---|
2007 | * Output the view name aka title |
---|
2008 | * |
---|
2009 | * @since 2.0.0 bbPress (r2789) |
---|
2010 | * |
---|
2011 | * @param string $view Optional. View id |
---|
2012 | * @uses bbp_get_view_title() To get the view title |
---|
2013 | */ |
---|
2014 | function bbp_view_title( $view = '' ) { |
---|
2015 | echo bbp_get_view_title( $view ); |
---|
2016 | } |
---|
2017 | |
---|
2018 | /** |
---|
2019 | * Get the view name aka title |
---|
2020 | * |
---|
2021 | * If a view id is supplied, that is used. Otherwise the bbp_view |
---|
2022 | * query var is checked for. |
---|
2023 | * |
---|
2024 | * @since 2.0.0 bbPress (r2789) |
---|
2025 | * |
---|
2026 | * @param string $view Optional. View id |
---|
2027 | * @uses bbp_get_view_id() To get the view id |
---|
2028 | * @return bool|string Title on success, false on failure |
---|
2029 | */ |
---|
2030 | function bbp_get_view_title( $view = '' ) { |
---|
2031 | $bbp = bbpress(); |
---|
2032 | |
---|
2033 | $view = bbp_get_view_id( $view ); |
---|
2034 | if ( empty( $view ) ) { |
---|
2035 | return false; |
---|
2036 | } |
---|
2037 | |
---|
2038 | return $bbp->views[ $view ]['title']; |
---|
2039 | } |
---|
2040 | |
---|
2041 | /** |
---|
2042 | * Output the view url |
---|
2043 | * |
---|
2044 | * @since 2.0.0 bbPress (r2789) |
---|
2045 | * |
---|
2046 | * @param string $view Optional. View id |
---|
2047 | * @uses bbp_get_view_url() To get the view url |
---|
2048 | */ |
---|
2049 | function bbp_view_url( $view = false ) { |
---|
2050 | echo esc_url( bbp_get_view_url( $view ) ); |
---|
2051 | } |
---|
2052 | /** |
---|
2053 | * Return the view url |
---|
2054 | * |
---|
2055 | * @since 2.0.0 bbPress (r2789) |
---|
2056 | * |
---|
2057 | * @param string $view Optional. View id |
---|
2058 | * @uses sanitize_title() To sanitize the view id |
---|
2059 | * @uses home_url() To get blog home url |
---|
2060 | * @uses add_query_arg() To add custom args to the url |
---|
2061 | * @uses apply_filters() Calls 'bbp_get_view_url' with the view url, |
---|
2062 | * used view id |
---|
2063 | * @return string View url (or home url if the view was not found) |
---|
2064 | */ |
---|
2065 | function bbp_get_view_url( $view = false ) { |
---|
2066 | |
---|
2067 | $view = bbp_get_view_id( $view ); |
---|
2068 | if ( empty( $view ) ) { |
---|
2069 | return home_url(); |
---|
2070 | } |
---|
2071 | |
---|
2072 | // Pretty permalinks |
---|
2073 | if ( bbp_use_pretty_urls() ) { |
---|
2074 | $url = trailingslashit( bbp_get_root_url() . bbp_get_view_slug() ) . $view; |
---|
2075 | $url = user_trailingslashit( $url ); |
---|
2076 | $url = home_url( $url ); |
---|
2077 | |
---|
2078 | // Unpretty permalinks |
---|
2079 | } else { |
---|
2080 | $url = add_query_arg( array( |
---|
2081 | bbp_get_view_rewrite_id() => $view |
---|
2082 | ), home_url( '/' ) ); |
---|
2083 | } |
---|
2084 | |
---|
2085 | return apply_filters( 'bbp_get_view_link', $url, $view ); |
---|
2086 | } |
---|
2087 | |
---|
2088 | /** Query *********************************************************************/ |
---|
2089 | |
---|
2090 | /** |
---|
2091 | * Check the passed parameter against the current _bbp_query_name |
---|
2092 | * |
---|
2093 | * @since 2.0.0 bbPress (r2980) |
---|
2094 | * |
---|
2095 | * @uses bbp_get_query_name() Get the query var '_bbp_query_name' |
---|
2096 | * @return bool True if match, false if not |
---|
2097 | */ |
---|
2098 | function bbp_is_query_name( $name = '' ) { |
---|
2099 | return (bool) ( bbp_get_query_name() === $name ); |
---|
2100 | } |
---|
2101 | |
---|
2102 | /** |
---|
2103 | * Get the '_bbp_query_name' setting |
---|
2104 | * |
---|
2105 | * @since 2.0.0 bbPress (r2695) |
---|
2106 | * |
---|
2107 | * @uses get_query_var() To get the query var '_bbp_query_name' |
---|
2108 | * @return string To return the query var value |
---|
2109 | */ |
---|
2110 | function bbp_get_query_name() { |
---|
2111 | return get_query_var( '_bbp_query_name' ); |
---|
2112 | } |
---|
2113 | |
---|
2114 | /** |
---|
2115 | * Set the '_bbp_query_name' setting to $name |
---|
2116 | * |
---|
2117 | * @since 2.0.0 bbPress (r2692) |
---|
2118 | * |
---|
2119 | * @param string $name What to set the query var to |
---|
2120 | * @uses set_query_var() To set the query var '_bbp_query_name' |
---|
2121 | */ |
---|
2122 | function bbp_set_query_name( $name = '' ) { |
---|
2123 | set_query_var( '_bbp_query_name', $name ); |
---|
2124 | } |
---|
2125 | |
---|
2126 | /** |
---|
2127 | * Used to clear the '_bbp_query_name' setting |
---|
2128 | * |
---|
2129 | * @since 2.0.0 bbPress (r2692) |
---|
2130 | * |
---|
2131 | * @uses bbp_set_query_name() To set the query var '_bbp_query_name' value to '' |
---|
2132 | */ |
---|
2133 | function bbp_reset_query_name() { |
---|
2134 | bbp_set_query_name(); |
---|
2135 | } |
---|
2136 | |
---|
2137 | /** Breadcrumbs ***************************************************************/ |
---|
2138 | |
---|
2139 | /** |
---|
2140 | * Output the page title as a breadcrumb |
---|
2141 | * |
---|
2142 | * @since 2.0.0 bbPress (r2589) |
---|
2143 | * |
---|
2144 | * @param string $sep Separator. Defaults to '←' |
---|
2145 | * @param bool $current_page Include the current item |
---|
2146 | * @param bool $root Include the root page if one exists |
---|
2147 | * @uses bbp_get_breadcrumb() To get the breadcrumb |
---|
2148 | */ |
---|
2149 | function bbp_title_breadcrumb( $args = array() ) { |
---|
2150 | echo bbp_get_breadcrumb( $args ); |
---|
2151 | } |
---|
2152 | |
---|
2153 | /** |
---|
2154 | * Output a breadcrumb |
---|
2155 | * |
---|
2156 | * @since 2.0.0 bbPress (r2589) |
---|
2157 | * |
---|
2158 | * @param string $sep Separator. Defaults to '←' |
---|
2159 | * @param bool $current_page Include the current item |
---|
2160 | * @param bool $root Include the root page if one exists |
---|
2161 | * @uses bbp_get_breadcrumb() To get the breadcrumb |
---|
2162 | */ |
---|
2163 | function bbp_breadcrumb( $args = array() ) { |
---|
2164 | echo bbp_get_breadcrumb( $args ); |
---|
2165 | } |
---|
2166 | /** |
---|
2167 | * Return a breadcrumb ( forum -> topic -> reply ) |
---|
2168 | * |
---|
2169 | * @since 2.0.0 bbPress (r2589) |
---|
2170 | * |
---|
2171 | * @param string $sep Separator. Defaults to '←' |
---|
2172 | * @param bool $current_page Include the current item |
---|
2173 | * @param bool $root Include the root page if one exists |
---|
2174 | * |
---|
2175 | * @uses get_post() To get the post |
---|
2176 | * @uses bbp_get_forum_permalink() To get the forum link |
---|
2177 | * @uses bbp_get_topic_permalink() To get the topic link |
---|
2178 | * @uses bbp_get_reply_permalink() To get the reply link |
---|
2179 | * @uses get_permalink() To get the permalink |
---|
2180 | * @uses bbp_get_forum_post_type() To get the forum post type |
---|
2181 | * @uses bbp_get_topic_post_type() To get the topic post type |
---|
2182 | * @uses bbp_get_reply_post_type() To get the reply post type |
---|
2183 | * @uses bbp_get_forum_title() To get the forum title |
---|
2184 | * @uses bbp_get_topic_title() To get the topic title |
---|
2185 | * @uses bbp_get_reply_title() To get the reply title |
---|
2186 | * @uses get_the_title() To get the title |
---|
2187 | * @uses apply_filters() Calls 'bbp_get_breadcrumb' with the crumbs |
---|
2188 | * @return string Breadcrumbs |
---|
2189 | */ |
---|
2190 | function bbp_get_breadcrumb( $args = array() ) { |
---|
2191 | |
---|
2192 | // Turn off breadcrumbs |
---|
2193 | if ( apply_filters( 'bbp_no_breadcrumb', is_front_page() ) ) { |
---|
2194 | return; |
---|
2195 | } |
---|
2196 | |
---|
2197 | // Define variables |
---|
2198 | $front_id = $root_id = 0; |
---|
2199 | $ancestors = $crumbs = $tag_data = array(); |
---|
2200 | $pre_root_text = $pre_front_text = $pre_current_text = ''; |
---|
2201 | $pre_include_root = $pre_include_home = $pre_include_current = true; |
---|
2202 | |
---|
2203 | /** Home Text *********************************************************/ |
---|
2204 | |
---|
2205 | // No custom home text |
---|
2206 | if ( empty( $args['home_text'] ) ) { |
---|
2207 | |
---|
2208 | $front_id = get_option( 'page_on_front' ); |
---|
2209 | |
---|
2210 | // Set home text to page title |
---|
2211 | if ( ! empty( $front_id ) ) { |
---|
2212 | $pre_front_text = get_the_title( $front_id ); |
---|
2213 | |
---|
2214 | // Default to 'Home' |
---|
2215 | } else { |
---|
2216 | $pre_front_text = __( 'Home', 'bbpress' ); |
---|
2217 | } |
---|
2218 | } |
---|
2219 | |
---|
2220 | /** Root Text *********************************************************/ |
---|
2221 | |
---|
2222 | // No custom root text |
---|
2223 | if ( empty( $args['root_text'] ) ) { |
---|
2224 | $page = bbp_get_page_by_path( bbp_get_root_slug() ); |
---|
2225 | if ( ! empty( $page ) ) { |
---|
2226 | $root_id = $page->ID; |
---|
2227 | } |
---|
2228 | $pre_root_text = bbp_get_forum_archive_title(); |
---|
2229 | } |
---|
2230 | |
---|
2231 | /** Includes **********************************************************/ |
---|
2232 | |
---|
2233 | // Root slug is also the front page |
---|
2234 | if ( ! empty( $front_id ) && ( $front_id === $root_id ) ) { |
---|
2235 | $pre_include_root = false; |
---|
2236 | } |
---|
2237 | |
---|
2238 | // Don't show root if viewing forum archive |
---|
2239 | if ( bbp_is_forum_archive() ) { |
---|
2240 | $pre_include_root = false; |
---|
2241 | } |
---|
2242 | |
---|
2243 | // Don't show root if viewing page in place of forum archive |
---|
2244 | if ( ! empty( $root_id ) && ( ( is_single() || is_page() ) && ( $root_id === get_the_ID() ) ) ) { |
---|
2245 | $pre_include_root = false; |
---|
2246 | } |
---|
2247 | |
---|
2248 | /** Current Text ******************************************************/ |
---|
2249 | |
---|
2250 | // Search page |
---|
2251 | if ( bbp_is_search() ) { |
---|
2252 | $pre_current_text = bbp_get_search_title(); |
---|
2253 | |
---|
2254 | // Forum archive |
---|
2255 | } elseif ( bbp_is_forum_archive() ) { |
---|
2256 | $pre_current_text = bbp_get_forum_archive_title(); |
---|
2257 | |
---|
2258 | // Topic archive |
---|
2259 | } elseif ( bbp_is_topic_archive() ) { |
---|
2260 | $pre_current_text = bbp_get_topic_archive_title(); |
---|
2261 | |
---|
2262 | // View |
---|
2263 | } elseif ( bbp_is_single_view() ) { |
---|
2264 | $pre_current_text = bbp_get_view_title(); |
---|
2265 | |
---|
2266 | // Single Forum |
---|
2267 | } elseif ( bbp_is_single_forum() ) { |
---|
2268 | $pre_current_text = bbp_get_forum_title(); |
---|
2269 | |
---|
2270 | // Single Topic |
---|
2271 | } elseif ( bbp_is_single_topic() ) { |
---|
2272 | $pre_current_text = bbp_get_topic_title(); |
---|
2273 | |
---|
2274 | // Single Topic |
---|
2275 | } elseif ( bbp_is_single_reply() ) { |
---|
2276 | $pre_current_text = bbp_get_reply_title(); |
---|
2277 | |
---|
2278 | // Topic Tag (or theme compat topic tag) |
---|
2279 | } elseif ( bbp_is_topic_tag() || ( get_query_var( 'bbp_topic_tag' ) && ! bbp_is_topic_tag_edit() ) ) { |
---|
2280 | |
---|
2281 | // Always include the tag name |
---|
2282 | $tag_data[] = bbp_get_topic_tag_name(); |
---|
2283 | |
---|
2284 | // If capable, include a link to edit the tag |
---|
2285 | if ( current_user_can( 'manage_topic_tags' ) ) { |
---|
2286 | $tag_data[] = '<a href="' . esc_url( bbp_get_topic_tag_edit_link() ) . '" class="bbp-edit-topic-tag-link">' . esc_html__( '(Edit)', 'bbpress' ) . '</a>'; |
---|
2287 | } |
---|
2288 | |
---|
2289 | // Implode the results of the tag data |
---|
2290 | $pre_current_text = sprintf( __( 'Topic Tag: %s', 'bbpress' ), implode( ' ', $tag_data ) ); |
---|
2291 | |
---|
2292 | // Edit Topic Tag |
---|
2293 | } elseif ( bbp_is_topic_tag_edit() ) { |
---|
2294 | $pre_current_text = __( 'Edit', 'bbpress' ); |
---|
2295 | |
---|
2296 | // Single |
---|
2297 | } else { |
---|
2298 | $pre_current_text = get_the_title(); |
---|
2299 | } |
---|
2300 | |
---|
2301 | /** Parse Args ********************************************************/ |
---|
2302 | |
---|
2303 | // Parse args |
---|
2304 | $r = bbp_parse_args( $args, array( |
---|
2305 | |
---|
2306 | // HTML |
---|
2307 | 'before' => '<div class="bbp-breadcrumb"><p>', |
---|
2308 | 'after' => '</p></div>', |
---|
2309 | |
---|
2310 | // Separator |
---|
2311 | 'sep' => is_rtl() ? __( '‹', 'bbpress' ) : __( '›', 'bbpress' ), |
---|
2312 | 'pad_sep' => 1, |
---|
2313 | 'sep_before' => '<span class="bbp-breadcrumb-sep">', |
---|
2314 | 'sep_after' => '</span>', |
---|
2315 | |
---|
2316 | // Crumbs |
---|
2317 | 'crumb_before' => '', |
---|
2318 | 'crumb_after' => '', |
---|
2319 | |
---|
2320 | // Home |
---|
2321 | 'include_home' => $pre_include_home, |
---|
2322 | 'home_text' => $pre_front_text, |
---|
2323 | |
---|
2324 | // Forum root |
---|
2325 | 'include_root' => $pre_include_root, |
---|
2326 | 'root_text' => $pre_root_text, |
---|
2327 | |
---|
2328 | // Current |
---|
2329 | 'include_current' => $pre_include_current, |
---|
2330 | 'current_text' => $pre_current_text, |
---|
2331 | 'current_before' => '<span class="bbp-breadcrumb-current">', |
---|
2332 | 'current_after' => '</span>', |
---|
2333 | ), 'get_breadcrumb' ); |
---|
2334 | |
---|
2335 | /** Ancestors *********************************************************/ |
---|
2336 | |
---|
2337 | // Get post ancestors |
---|
2338 | if ( is_singular() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit() ) { |
---|
2339 | $ancestors = array_reverse( (array) get_post_ancestors( get_the_ID() ) ); |
---|
2340 | } |
---|
2341 | |
---|
2342 | // Do we want to include a link to home? |
---|
2343 | if ( ! empty( $r['include_home'] ) || empty( $r['home_text'] ) ) { |
---|
2344 | $crumbs[] = '<a href="' . trailingslashit( home_url() ) . '" class="bbp-breadcrumb-home">' . $r['home_text'] . '</a>'; |
---|
2345 | } |
---|
2346 | |
---|
2347 | // Do we want to include a link to the forum root? |
---|
2348 | if ( ! empty( $r['include_root'] ) || empty( $r['root_text'] ) ) { |
---|
2349 | |
---|
2350 | // Page exists at root slug path, so use its permalink |
---|
2351 | $page = bbp_get_page_by_path( bbp_get_root_slug() ); |
---|
2352 | if ( ! empty( $page ) ) { |
---|
2353 | $root_url = get_permalink( $page->ID ); |
---|
2354 | |
---|
2355 | // Use the root slug |
---|
2356 | } else { |
---|
2357 | $root_url = get_post_type_archive_link( bbp_get_forum_post_type() ); |
---|
2358 | } |
---|
2359 | |
---|
2360 | // Add the breadcrumb |
---|
2361 | $crumbs[] = '<a href="' . esc_url( $root_url ) . '" class="bbp-breadcrumb-root">' . $r['root_text'] . '</a>'; |
---|
2362 | } |
---|
2363 | |
---|
2364 | // Ancestors exist |
---|
2365 | if ( ! empty( $ancestors ) ) { |
---|
2366 | |
---|
2367 | // Loop through parents |
---|
2368 | foreach ( (array) $ancestors as $parent_id ) { |
---|
2369 | |
---|
2370 | // Parents |
---|
2371 | $parent = get_post( $parent_id ); |
---|
2372 | |
---|
2373 | // Skip parent if empty or error |
---|
2374 | if ( empty( $parent ) || is_wp_error( $parent ) ) { |
---|
2375 | continue; |
---|
2376 | } |
---|
2377 | |
---|
2378 | // Switch through post_type to ensure correct filters are applied |
---|
2379 | switch ( $parent->post_type ) { |
---|
2380 | |
---|
2381 | // Forum |
---|
2382 | case bbp_get_forum_post_type() : |
---|
2383 | $crumbs[] = '<a href="' . esc_url( bbp_get_forum_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title( $parent->ID ) . '</a>'; |
---|
2384 | break; |
---|
2385 | |
---|
2386 | // Topic |
---|
2387 | case bbp_get_topic_post_type() : |
---|
2388 | $crumbs[] = '<a href="' . esc_url( bbp_get_topic_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title( $parent->ID ) . '</a>'; |
---|
2389 | break; |
---|
2390 | |
---|
2391 | // Reply (Note: not in most themes) |
---|
2392 | case bbp_get_reply_post_type() : |
---|
2393 | $crumbs[] = '<a href="' . esc_url( bbp_get_reply_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title( $parent->ID ) . '</a>'; |
---|
2394 | break; |
---|
2395 | |
---|
2396 | // WordPress Post/Page/Other |
---|
2397 | default : |
---|
2398 | $crumbs[] = '<a href="' . esc_url( get_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-item">' . get_the_title( $parent->ID ) . '</a>'; |
---|
2399 | break; |
---|
2400 | } |
---|
2401 | } |
---|
2402 | |
---|
2403 | // Edit topic tag |
---|
2404 | } elseif ( bbp_is_topic_tag_edit() ) { |
---|
2405 | $crumbs[] = '<a href="' . esc_url( get_term_link( bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id() ) ) . '" class="bbp-breadcrumb-topic-tag">' . sprintf( __( 'Topic Tag: %s', 'bbpress' ), bbp_get_topic_tag_name() ) . '</a>'; |
---|
2406 | |
---|
2407 | // Search |
---|
2408 | } elseif ( bbp_is_search() && bbp_get_search_terms() ) { |
---|
2409 | $crumbs[] = '<a href="' . esc_url( bbp_get_search_url() ) . '" class="bbp-breadcrumb-search">' . esc_html__( 'Search', 'bbpress' ) . '</a>'; |
---|
2410 | } |
---|
2411 | |
---|
2412 | /** Current ***********************************************************/ |
---|
2413 | |
---|
2414 | // Add current page to breadcrumb |
---|
2415 | if ( ! empty( $r['include_current'] ) || empty( $r['current_text'] ) ) { |
---|
2416 | $crumbs[] = $r['current_before'] . $r['current_text'] . $r['current_after']; |
---|
2417 | } |
---|
2418 | |
---|
2419 | /** Separator *********************************************************/ |
---|
2420 | |
---|
2421 | // Wrap the separator in before/after before padding and filter |
---|
2422 | if ( ! empty( $r['sep'] ) ) { |
---|
2423 | $sep = $r['sep_before'] . $r['sep'] . $r['sep_after']; |
---|
2424 | } else { |
---|
2425 | $sep = ''; |
---|
2426 | } |
---|
2427 | |
---|
2428 | // Pad the separator |
---|
2429 | if ( ! empty( $r['pad_sep'] ) ) { |
---|
2430 | if ( function_exists( 'mb_strlen' ) ) { |
---|
2431 | $sep = str_pad( $sep, mb_strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH ); |
---|
2432 | } else { |
---|
2433 | $sep = str_pad( $sep, strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH ); |
---|
2434 | } |
---|
2435 | } |
---|
2436 | |
---|
2437 | /** Finish Up *********************************************************/ |
---|
2438 | |
---|
2439 | // Filter the separator and breadcrumb |
---|
2440 | $sep = apply_filters( 'bbp_breadcrumb_separator', $sep ); |
---|
2441 | $crumbs = apply_filters( 'bbp_breadcrumbs', $crumbs ); |
---|
2442 | |
---|
2443 | // Build the trail |
---|
2444 | $trail = ! empty( $crumbs ) ? ( $r['before'] . $r['crumb_before'] . implode( $sep . $r['crumb_after'] . $r['crumb_before'] , $crumbs ) . $r['crumb_after'] . $r['after'] ) : ''; |
---|
2445 | |
---|
2446 | return apply_filters( 'bbp_get_breadcrumb', $trail, $crumbs, $r ); |
---|
2447 | } |
---|
2448 | |
---|
2449 | /** Topic Tags ***************************************************************/ |
---|
2450 | |
---|
2451 | /** |
---|
2452 | * Output all of the allowed tags in HTML format with attributes. |
---|
2453 | * |
---|
2454 | * This is useful for displaying in the post area, which elements and |
---|
2455 | * attributes are supported. As well as any plugins which want to display it. |
---|
2456 | * |
---|
2457 | * @since 2.0.0 bbPress (r2780) |
---|
2458 | * |
---|
2459 | * @uses bbp_get_allowed_tags() |
---|
2460 | */ |
---|
2461 | function bbp_allowed_tags() { |
---|
2462 | echo bbp_get_allowed_tags(); |
---|
2463 | } |
---|
2464 | /** |
---|
2465 | * Display all of the allowed tags in HTML format with attributes. |
---|
2466 | * |
---|
2467 | * This is useful for displaying in the post area, which elements and |
---|
2468 | * attributes are supported. As well as any plugins which want to display it. |
---|
2469 | * |
---|
2470 | * @since 2.0.0 bbPress (r2780) |
---|
2471 | * |
---|
2472 | * @uses bbp_kses_allowed_tags() To get the allowed tags |
---|
2473 | * @uses apply_filters() Calls 'bbp_allowed_tags' with the tags |
---|
2474 | * @return string HTML allowed tags entity encoded. |
---|
2475 | */ |
---|
2476 | function bbp_get_allowed_tags() { |
---|
2477 | |
---|
2478 | $allowed = ''; |
---|
2479 | |
---|
2480 | foreach ( (array) bbp_kses_allowed_tags() as $tag => $attributes ) { |
---|
2481 | $allowed .= '<' . $tag; |
---|
2482 | if ( 0 < count( $attributes ) ) { |
---|
2483 | foreach ( array_keys( $attributes ) as $attribute ) { |
---|
2484 | $allowed .= ' ' . $attribute . '=""'; |
---|
2485 | } |
---|
2486 | } |
---|
2487 | $allowed .= '> '; |
---|
2488 | } |
---|
2489 | |
---|
2490 | return apply_filters( 'bbp_get_allowed_tags', htmlentities( $allowed ) ); |
---|
2491 | } |
---|
2492 | |
---|
2493 | /** Errors & Messages *********************************************************/ |
---|
2494 | |
---|
2495 | /** |
---|
2496 | * Display possible errors & messages inside a template file |
---|
2497 | * |
---|
2498 | * @since 2.0.0 bbPress (r2688) |
---|
2499 | * |
---|
2500 | * @uses WP_Error bbPress::errors::get_error_codes() To get the error codes |
---|
2501 | * @uses WP_Error bbPress::errors::get_error_data() To get the error data |
---|
2502 | * @uses WP_Error bbPress::errors::get_error_messages() To get the error |
---|
2503 | * messages |
---|
2504 | * @uses is_wp_error() To check if it's a {@link WP_Error} |
---|
2505 | */ |
---|
2506 | function bbp_template_notices() { |
---|
2507 | |
---|
2508 | // Bail if no notices or errors |
---|
2509 | if ( ! bbp_has_errors() ) { |
---|
2510 | return; |
---|
2511 | } |
---|
2512 | |
---|
2513 | // Define local variable(s) |
---|
2514 | $errors = $messages = array(); |
---|
2515 | |
---|
2516 | // Get bbPress |
---|
2517 | $bbp = bbpress(); |
---|
2518 | |
---|
2519 | // Loop through notices |
---|
2520 | foreach ( $bbp->errors->get_error_codes() as $code ) { |
---|
2521 | |
---|
2522 | // Get notice severity |
---|
2523 | $severity = $bbp->errors->get_error_data( $code ); |
---|
2524 | |
---|
2525 | // Loop through notices and separate errors from messages |
---|
2526 | foreach ( $bbp->errors->get_error_messages( $code ) as $error ) { |
---|
2527 | if ( 'message' === $severity ) { |
---|
2528 | $messages[] = $error; |
---|
2529 | } else { |
---|
2530 | $errors[] = $error; |
---|
2531 | } |
---|
2532 | } |
---|
2533 | } |
---|
2534 | |
---|
2535 | // Display errors first... |
---|
2536 | if ( ! empty( $errors ) ) : ?> |
---|
2537 | |
---|
2538 | <div class="bbp-template-notice error" role="alert" tabindex="-1"> |
---|
2539 | <ul> |
---|
2540 | <li><?php echo implode( "</li>\n<li>", $errors ); ?></li> |
---|
2541 | </ul> |
---|
2542 | </div> |
---|
2543 | |
---|
2544 | <?php endif; |
---|
2545 | |
---|
2546 | // ...and messages last |
---|
2547 | if ( ! empty( $messages ) ) : ?> |
---|
2548 | |
---|
2549 | <div class="bbp-template-notice"> |
---|
2550 | <ul> |
---|
2551 | <li><?php echo implode( "</li>\n<li>", $messages ); ?></li> |
---|
2552 | </ul> |
---|
2553 | </div> |
---|
2554 | |
---|
2555 | <?php endif; |
---|
2556 | } |
---|
2557 | |
---|
2558 | /** Login/logout/register/lost pass *******************************************/ |
---|
2559 | |
---|
2560 | /** |
---|
2561 | * Output the logout link |
---|
2562 | * |
---|
2563 | * @since 2.0.0 bbPress (r2827) |
---|
2564 | * |
---|
2565 | * @param string $redirect_to Redirect to url |
---|
2566 | * @uses bbp_get_logout_link() To get the logout link |
---|
2567 | */ |
---|
2568 | function bbp_logout_link( $redirect_to = '' ) { |
---|
2569 | echo bbp_get_logout_link( $redirect_to ); |
---|
2570 | } |
---|
2571 | /** |
---|
2572 | * Return the logout link |
---|
2573 | * |
---|
2574 | * @since 2.0.0 bbPress (r2827) |
---|
2575 | * |
---|
2576 | * @param string $redirect_to Redirect to url |
---|
2577 | * @uses wp_logout_url() To get the logout url |
---|
2578 | * @uses apply_filters() Calls 'bbp_get_logout_link' with the logout link and |
---|
2579 | * redirect to url |
---|
2580 | * @return string The logout link |
---|
2581 | */ |
---|
2582 | function bbp_get_logout_link( $redirect_to = '' ) { |
---|
2583 | return apply_filters( 'bbp_get_logout_link', '<a href="' . wp_logout_url( $redirect_to ) . '" class="button logout-link">' . esc_html__( 'Log Out', 'bbpress' ) . '</a>', $redirect_to ); |
---|
2584 | } |
---|
2585 | |
---|
2586 | /** Title *********************************************************************/ |
---|
2587 | |
---|
2588 | /** |
---|
2589 | * Custom page title for bbPress pages |
---|
2590 | * |
---|
2591 | * @since 2.0.0 bbPress (r2788) |
---|
2592 | * |
---|
2593 | * @param string $title Optional. The title (not used). |
---|
2594 | * @param string $sep Optional, default is '»'. How to separate the |
---|
2595 | * various items within the page title. |
---|
2596 | * @param string $seplocation Optional. Direction to display title, 'right'. |
---|
2597 | * @uses bbp_is_single_user() To check if it's a user profile page |
---|
2598 | * @uses bbp_is_single_user_edit() To check if it's a user profile edit page |
---|
2599 | * @uses bbp_is_user_home() To check if the profile page is of the current user |
---|
2600 | * @uses get_query_var() To get the user id |
---|
2601 | * @uses get_userdata() To get the user data |
---|
2602 | * @uses bbp_is_single_forum() To check if it's a forum |
---|
2603 | * @uses bbp_get_forum_title() To get the forum title |
---|
2604 | * @uses bbp_is_single_topic() To check if it's a topic |
---|
2605 | * @uses bbp_get_topic_title() To get the topic title |
---|
2606 | * @uses bbp_is_single_reply() To check if it's a reply |
---|
2607 | * @uses bbp_get_reply_title() To get the reply title |
---|
2608 | * @uses is_tax() To check if it's the tag page |
---|
2609 | * @uses get_queried_object() To get the queried object |
---|
2610 | * @uses bbp_is_single_view() To check if it's a view |
---|
2611 | * @uses bbp_get_view_title() To get the view title |
---|
2612 | * @uses apply_filters() Calls 'bbp_raw_title' with the title |
---|
2613 | * @uses apply_filters() Calls 'bbp_profile_page_wp_title' with the title, |
---|
2614 | * separator and separator location |
---|
2615 | * @return string The tite |
---|
2616 | */ |
---|
2617 | function bbp_title( $title = '', $sep = '»', $seplocation = '' ) { |
---|
2618 | |
---|
2619 | // Title array |
---|
2620 | $new_title = array(); |
---|
2621 | |
---|
2622 | /** Archives **************************************************************/ |
---|
2623 | |
---|
2624 | // Forum Archive |
---|
2625 | if ( bbp_is_forum_archive() ) { |
---|
2626 | $new_title['text'] = bbp_get_forum_archive_title(); |
---|
2627 | |
---|
2628 | // Topic Archive |
---|
2629 | } elseif ( bbp_is_topic_archive() ) { |
---|
2630 | $new_title['text'] = bbp_get_topic_archive_title(); |
---|
2631 | |
---|
2632 | /** Edit ******************************************************************/ |
---|
2633 | |
---|
2634 | // Forum edit page |
---|
2635 | } elseif ( bbp_is_forum_edit() ) { |
---|
2636 | $new_title['text'] = bbp_get_forum_title(); |
---|
2637 | $new_title['format'] = esc_attr__( 'Forum Edit: %s', 'bbpress' ); |
---|
2638 | |
---|
2639 | // Topic edit page |
---|
2640 | } elseif ( bbp_is_topic_edit() ) { |
---|
2641 | $new_title['text'] = bbp_get_topic_title(); |
---|
2642 | $new_title['format'] = esc_attr__( 'Topic Edit: %s', 'bbpress' ); |
---|
2643 | |
---|
2644 | // Reply edit page |
---|
2645 | } elseif ( bbp_is_reply_edit() ) { |
---|
2646 | $new_title['text'] = bbp_get_reply_title(); |
---|
2647 | $new_title['format'] = esc_attr__( 'Reply Edit: %s', 'bbpress' ); |
---|
2648 | |
---|
2649 | // Topic tag edit page |
---|
2650 | } elseif ( bbp_is_topic_tag_edit() ) { |
---|
2651 | $new_title['text'] = bbp_get_topic_tag_name(); |
---|
2652 | $new_title['format'] = esc_attr__( 'Topic Tag Edit: %s', 'bbpress' ); |
---|
2653 | |
---|
2654 | /** Singles ***************************************************************/ |
---|
2655 | |
---|
2656 | // Forum page |
---|
2657 | } elseif ( bbp_is_single_forum() ) { |
---|
2658 | $new_title['text'] = bbp_get_forum_title(); |
---|
2659 | $new_title['format'] = esc_attr__( 'Forum: %s', 'bbpress' ); |
---|
2660 | |
---|
2661 | // Topic page |
---|
2662 | } elseif ( bbp_is_single_topic() ) { |
---|
2663 | $new_title['text'] = bbp_get_topic_title(); |
---|
2664 | $new_title['format'] = esc_attr__( 'Topic: %s', 'bbpress' ); |
---|
2665 | |
---|
2666 | // Replies |
---|
2667 | } elseif ( bbp_is_single_reply() ) { |
---|
2668 | $new_title['text'] = bbp_get_reply_title(); |
---|
2669 | |
---|
2670 | // Topic tag page |
---|
2671 | } elseif ( bbp_is_topic_tag() || get_query_var( 'bbp_topic_tag' ) ) { |
---|
2672 | $new_title['text'] = bbp_get_topic_tag_name(); |
---|
2673 | $new_title['format'] = esc_attr__( 'Topic Tag: %s', 'bbpress' ); |
---|
2674 | |
---|
2675 | /** Users *****************************************************************/ |
---|
2676 | |
---|
2677 | // Profile page |
---|
2678 | } elseif ( bbp_is_single_user() ) { |
---|
2679 | |
---|
2680 | // Is user viewing their own profile? |
---|
2681 | $is_user_home = bbp_is_user_home(); |
---|
2682 | |
---|
2683 | // User topics created |
---|
2684 | if ( bbp_is_single_user_topics() ) { |
---|
2685 | if ( true === $is_user_home ) { |
---|
2686 | $new_title['text'] = esc_attr__( 'Your Topics', 'bbpress' ); |
---|
2687 | } else { |
---|
2688 | $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name; |
---|
2689 | /* translators: user's display name */ |
---|
2690 | $new_title['format'] = esc_attr__( "%s's Topics", 'bbpress' ); |
---|
2691 | } |
---|
2692 | |
---|
2693 | // User replies created |
---|
2694 | } elseif ( bbp_is_single_user_replies() ) { |
---|
2695 | if ( true === $is_user_home ) { |
---|
2696 | $new_title['text'] = esc_attr__( 'Your Replies', 'bbpress' ); |
---|
2697 | } else { |
---|
2698 | $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name; |
---|
2699 | /* translators: user's display name */ |
---|
2700 | $new_title['format'] = esc_attr__( "%s's Replies", 'bbpress' ); |
---|
2701 | } |
---|
2702 | |
---|
2703 | // User favorites |
---|
2704 | } elseif ( bbp_is_favorites() ) { |
---|
2705 | if ( true === $is_user_home ) { |
---|
2706 | $new_title['text'] = esc_attr__( 'Your Favorites', 'bbpress' ); |
---|
2707 | } else { |
---|
2708 | $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name; |
---|
2709 | /* translators: user's display name */ |
---|
2710 | $new_title['format'] = esc_attr__( "%s's Favorites", 'bbpress' ); |
---|
2711 | } |
---|
2712 | |
---|
2713 | // User subscriptions |
---|
2714 | } elseif ( bbp_is_subscriptions() ) { |
---|
2715 | if ( true === $is_user_home ) { |
---|
2716 | $new_title['text'] = esc_attr__( 'Your Subscriptions', 'bbpress' ); |
---|
2717 | } else { |
---|
2718 | $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name; |
---|
2719 | /* translators: user's display name */ |
---|
2720 | $new_title['format'] = esc_attr__( "%s's Subscriptions", 'bbpress' ); |
---|
2721 | } |
---|
2722 | |
---|
2723 | // User "home" |
---|
2724 | } else { |
---|
2725 | if ( true === $is_user_home ) { |
---|
2726 | $new_title['text'] = esc_attr__( 'Your Profile', 'bbpress' ); |
---|
2727 | } else { |
---|
2728 | $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name; |
---|
2729 | /* translators: user's display name */ |
---|
2730 | $new_title['format'] = esc_attr__( "%s's Profile", 'bbpress' ); |
---|
2731 | } |
---|
2732 | } |
---|
2733 | |
---|
2734 | // Profile edit page |
---|
2735 | } elseif ( bbp_is_single_user_edit() ) { |
---|
2736 | |
---|
2737 | // Current user |
---|
2738 | if ( bbp_is_user_home_edit() ) { |
---|
2739 | $new_title['text'] = esc_attr__( 'Edit Your Profile', 'bbpress' ); |
---|
2740 | |
---|
2741 | // Other user |
---|
2742 | } else { |
---|
2743 | $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name; |
---|
2744 | $new_title['format'] = esc_attr__( "Edit %s's Profile", 'bbpress' ); |
---|
2745 | } |
---|
2746 | |
---|
2747 | /** Views *****************************************************************/ |
---|
2748 | |
---|
2749 | // Views |
---|
2750 | } elseif ( bbp_is_single_view() ) { |
---|
2751 | $new_title['text'] = bbp_get_view_title(); |
---|
2752 | $new_title['format'] = esc_attr__( 'View: %s', 'bbpress' ); |
---|
2753 | |
---|
2754 | /** Search ****************************************************************/ |
---|
2755 | |
---|
2756 | // Search |
---|
2757 | } elseif ( bbp_is_search() ) { |
---|
2758 | $new_title['text'] = bbp_get_search_title(); |
---|
2759 | } |
---|
2760 | |
---|
2761 | // This filter is deprecated. Use 'bbp_before_title_parse_args' instead. |
---|
2762 | $new_title = apply_filters( 'bbp_raw_title_array', $new_title ); |
---|
2763 | |
---|
2764 | // Set title array defaults |
---|
2765 | $new_title = bbp_parse_args( $new_title, array( |
---|
2766 | 'text' => $title, |
---|
2767 | 'format' => '%s' |
---|
2768 | ), 'title' ); |
---|
2769 | |
---|
2770 | // Get the formatted raw title |
---|
2771 | $new_title = sprintf( $new_title['format'], $new_title['text'] ); |
---|
2772 | |
---|
2773 | // Filter the raw title |
---|
2774 | $new_title = apply_filters( 'bbp_raw_title', $new_title, $sep, $seplocation ); |
---|
2775 | |
---|
2776 | // Compare new title with original title |
---|
2777 | if ( $new_title === $title ) { |
---|
2778 | return $title; |
---|
2779 | } |
---|
2780 | |
---|
2781 | // Temporary separator, for accurate flipping, if necessary |
---|
2782 | $t_sep = '%WP_TITILE_SEP%'; |
---|
2783 | $prefix = ''; |
---|
2784 | |
---|
2785 | if ( ! empty( $new_title ) ) { |
---|
2786 | $prefix = " $sep "; |
---|
2787 | } |
---|
2788 | |
---|
2789 | // sep on right, so reverse the order |
---|
2790 | if ( 'right' === $seplocation ) { |
---|
2791 | $new_title_array = array_reverse( explode( $t_sep, $new_title ) ); |
---|
2792 | $new_title = implode( " $sep ", $new_title_array ) . $prefix; |
---|
2793 | |
---|
2794 | // sep on left, do not reverse |
---|
2795 | } else { |
---|
2796 | $new_title_array = explode( $t_sep, $new_title ); |
---|
2797 | $new_title = $prefix . implode( " $sep ", $new_title_array ); |
---|
2798 | } |
---|
2799 | |
---|
2800 | // Filter and return |
---|
2801 | return apply_filters( 'bbp_title', $new_title, $sep, $seplocation ); |
---|
2802 | } |
---|