1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * bbPress Forum Template Tags |
---|
5 | * |
---|
6 | * @package bbPress |
---|
7 | * @subpackage TemplateTags |
---|
8 | */ |
---|
9 | |
---|
10 | // Exit if accessed directly |
---|
11 | if ( !defined( 'ABSPATH' ) ) exit; |
---|
12 | |
---|
13 | /** Post Type *****************************************************************/ |
---|
14 | |
---|
15 | /** |
---|
16 | * Output the unique id of the custom post type for forums |
---|
17 | * |
---|
18 | * @since bbPress (r2857) |
---|
19 | * @uses bbp_get_forum_post_type() To get the forum post type |
---|
20 | */ |
---|
21 | function bbp_forum_post_type() { |
---|
22 | echo bbp_get_forum_post_type(); |
---|
23 | } |
---|
24 | /** |
---|
25 | * Return the unique id of the custom post type for forums |
---|
26 | * |
---|
27 | * @since bbPress (r2857) |
---|
28 | * |
---|
29 | * @uses apply_filters() Calls 'bbp_get_forum_post_type' with the forum |
---|
30 | * post type id |
---|
31 | * @return string The unique forum post type id |
---|
32 | */ |
---|
33 | function bbp_get_forum_post_type() { |
---|
34 | return apply_filters( 'bbp_get_forum_post_type', bbpress()->forum_post_type ); |
---|
35 | } |
---|
36 | |
---|
37 | /** Forum Loop ****************************************************************/ |
---|
38 | |
---|
39 | /** |
---|
40 | * The main forum loop. |
---|
41 | * |
---|
42 | * WordPress makes this easy for us. |
---|
43 | * |
---|
44 | * @since bbPress (r2464) |
---|
45 | * |
---|
46 | * @param mixed $args All the arguments supported by {@link WP_Query} |
---|
47 | * @uses WP_Query To make query and get the forums |
---|
48 | * @uses bbp_get_forum_post_type() To get the forum post type id |
---|
49 | * @uses bbp_get_forum_id() To get the forum id |
---|
50 | * @uses get_option() To get the forums per page option |
---|
51 | * @uses current_user_can() To check if the current user is capable of editing |
---|
52 | * others' forums |
---|
53 | * @uses apply_filters() Calls 'bbp_has_forums' with |
---|
54 | * bbPres::forum_query::have_posts() |
---|
55 | * and bbPres::forum_query |
---|
56 | * @return object Multidimensional array of forum information |
---|
57 | */ |
---|
58 | function bbp_has_forums( $args = '' ) { |
---|
59 | $bbp = bbpress(); |
---|
60 | |
---|
61 | // Setup possible post__not_in array |
---|
62 | $post_stati[] = bbp_get_public_status_id(); |
---|
63 | |
---|
64 | // Super admin get whitelisted post statuses |
---|
65 | if ( is_super_admin() ) { |
---|
66 | $post_stati = array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() ); |
---|
67 | |
---|
68 | // Not a super admin, so check caps |
---|
69 | } else { |
---|
70 | |
---|
71 | // Check if user can read private forums |
---|
72 | if ( current_user_can( 'read_private_forums' ) ) |
---|
73 | $post_stati[] = bbp_get_private_status_id(); |
---|
74 | |
---|
75 | // Check if user can read hidden forums |
---|
76 | if ( current_user_can( 'read_hidden_forums' ) ) |
---|
77 | $post_stati[] = bbp_get_hidden_status_id(); |
---|
78 | } |
---|
79 | |
---|
80 | // The default forum query for most circumstances |
---|
81 | $default = array ( |
---|
82 | 'post_type' => bbp_get_forum_post_type(), |
---|
83 | 'post_parent' => bbp_is_forum_archive() ? 0 : bbp_get_forum_id() , |
---|
84 | 'post_status' => implode( ',', $post_stati ), |
---|
85 | 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ), |
---|
86 | 'orderby' => 'menu_order', |
---|
87 | 'order' => 'ASC' |
---|
88 | ); |
---|
89 | |
---|
90 | // Filter the default arguments |
---|
91 | $args = apply_filters( 'bbp_pre_has_forums_query', $args ); |
---|
92 | |
---|
93 | // Parse the default against what is requested |
---|
94 | $bbp_f = wp_parse_args( $args, $default ); |
---|
95 | |
---|
96 | // Filter the forums query to allow just-in-time modifications |
---|
97 | $bbp_f = apply_filters( 'bbp_has_forums_query', $bbp_f ); |
---|
98 | |
---|
99 | // Run the query |
---|
100 | $bbp->forum_query = new WP_Query( $bbp_f ); |
---|
101 | |
---|
102 | return apply_filters( 'bbp_has_forums', $bbp->forum_query->have_posts(), $bbp->forum_query ); |
---|
103 | } |
---|
104 | |
---|
105 | /** |
---|
106 | * Whether there are more forums available in the loop |
---|
107 | * |
---|
108 | * @since bbPress (r2464) |
---|
109 | * |
---|
110 | * @uses bbPress:forum_query::have_posts() To check if there are more forums |
---|
111 | * available |
---|
112 | * @return object Forum information |
---|
113 | */ |
---|
114 | function bbp_forums() { |
---|
115 | |
---|
116 | // Put into variable to check against next |
---|
117 | $have_posts = bbpress()->forum_query->have_posts(); |
---|
118 | |
---|
119 | // Reset the post data when finished |
---|
120 | if ( empty( $have_posts ) ) |
---|
121 | wp_reset_postdata(); |
---|
122 | |
---|
123 | return $have_posts; |
---|
124 | } |
---|
125 | |
---|
126 | /** |
---|
127 | * Loads up the current forum in the loop |
---|
128 | * |
---|
129 | * @since bbPress (r2464) |
---|
130 | * |
---|
131 | * @uses bbPress:forum_query::the_post() To get the current forum |
---|
132 | * @return object Forum information |
---|
133 | */ |
---|
134 | function bbp_the_forum() { |
---|
135 | return bbpress()->forum_query->the_post(); |
---|
136 | } |
---|
137 | |
---|
138 | /** Forum *********************************************************************/ |
---|
139 | |
---|
140 | /** |
---|
141 | * Output forum id |
---|
142 | * |
---|
143 | * @since bbPress (r2464) |
---|
144 | * |
---|
145 | * @param $forum_id Optional. Used to check emptiness |
---|
146 | * @uses bbp_get_forum_id() To get the forum id |
---|
147 | */ |
---|
148 | function bbp_forum_id( $forum_id = 0 ) { |
---|
149 | echo bbp_get_forum_id( $forum_id ); |
---|
150 | } |
---|
151 | /** |
---|
152 | * Return the forum id |
---|
153 | * |
---|
154 | * @since bbPress (r2464) |
---|
155 | * |
---|
156 | * @param $forum_id Optional. Used to check emptiness |
---|
157 | * @uses bbPress::forum_query::in_the_loop To check if we're in the loop |
---|
158 | * @uses bbPress::forum_query::post::ID To get the forum id |
---|
159 | * @uses WP_Query::post::ID To get the forum id |
---|
160 | * @uses bbp_is_single_forum() To check if it's a forum page |
---|
161 | * @uses bbp_is_single_topic() To check if it's a topic page |
---|
162 | * @uses bbp_get_topic_forum_id() To get the topic forum id |
---|
163 | * @uses get_post_field() To get the post's post type |
---|
164 | * @uses apply_filters() Calls 'bbp_get_forum_id' with the forum id and |
---|
165 | * supplied forum id |
---|
166 | * @return int The forum id |
---|
167 | */ |
---|
168 | function bbp_get_forum_id( $forum_id = 0 ) { |
---|
169 | global $wp_query; |
---|
170 | |
---|
171 | $bbp = bbpress(); |
---|
172 | |
---|
173 | // Easy empty checking |
---|
174 | if ( !empty( $forum_id ) && is_numeric( $forum_id ) ) |
---|
175 | $bbp_forum_id = $forum_id; |
---|
176 | |
---|
177 | // Currently inside a forum loop |
---|
178 | elseif ( !empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) ) |
---|
179 | $bbp_forum_id = $bbp->forum_query->post->ID; |
---|
180 | |
---|
181 | // Currently viewing a forum |
---|
182 | elseif ( bbp_is_single_forum() && !empty( $bbp->current_forum_id ) ) |
---|
183 | $bbp_forum_id = $bbp->current_forum_id; |
---|
184 | |
---|
185 | // Currently viewing a forum |
---|
186 | elseif ( bbp_is_single_forum() && isset( $wp_query->post->ID ) ) |
---|
187 | $bbp_forum_id = $wp_query->post->ID; |
---|
188 | |
---|
189 | // Currently viewing a topic |
---|
190 | elseif ( bbp_is_single_topic() ) |
---|
191 | $bbp_forum_id = bbp_get_topic_forum_id(); |
---|
192 | |
---|
193 | // Fallback |
---|
194 | else |
---|
195 | $bbp_forum_id = 0; |
---|
196 | |
---|
197 | return (int) apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id ); |
---|
198 | } |
---|
199 | |
---|
200 | /** |
---|
201 | * Gets a forum |
---|
202 | * |
---|
203 | * @since bbPress (r2787) |
---|
204 | * |
---|
205 | * @param int|object $forum forum id or forum object |
---|
206 | * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT |
---|
207 | * @param string $filter Optional Sanitation filter. See {@link sanitize_post()} |
---|
208 | * @uses get_post() To get the forum |
---|
209 | * @uses apply_filters() Calls 'bbp_get_forum' with the forum, output type and |
---|
210 | * sanitation filter |
---|
211 | * @return mixed Null if error or forum (in specified form) if success |
---|
212 | */ |
---|
213 | function bbp_get_forum( $forum, $output = OBJECT, $filter = 'raw' ) { |
---|
214 | |
---|
215 | // Use forum ID |
---|
216 | if ( empty( $forum ) || is_numeric( $forum ) ) |
---|
217 | $forum = bbp_get_forum_id( $forum ); |
---|
218 | |
---|
219 | // Attempt to load the forum |
---|
220 | $forum = get_post( $forum, OBJECT, $filter ); |
---|
221 | if ( empty( $forum ) ) |
---|
222 | return $forum; |
---|
223 | |
---|
224 | // Bail if post_type is not a forum |
---|
225 | if ( $forum->post_type !== bbp_get_forum_post_type() ) |
---|
226 | return null; |
---|
227 | |
---|
228 | // Tweak the data type to return |
---|
229 | if ( $output == OBJECT ) { |
---|
230 | return $forum; |
---|
231 | |
---|
232 | } elseif ( $output == ARRAY_A ) { |
---|
233 | $_forum = get_object_vars( $forum ); |
---|
234 | return $_forum; |
---|
235 | |
---|
236 | } elseif ( $output == ARRAY_N ) { |
---|
237 | $_forum = array_values( get_object_vars( $forum ) ); |
---|
238 | return $_forum; |
---|
239 | |
---|
240 | } |
---|
241 | |
---|
242 | return apply_filters( 'bbp_get_forum', $forum, $output, $filter ); |
---|
243 | } |
---|
244 | |
---|
245 | /** |
---|
246 | * Output the link to the forum |
---|
247 | * |
---|
248 | * @since bbPress (r2464) |
---|
249 | * |
---|
250 | * @param int $forum_id Optional. Forum id |
---|
251 | * @uses bbp_get_forum_permalink() To get the permalink |
---|
252 | */ |
---|
253 | function bbp_forum_permalink( $forum_id = 0 ) { |
---|
254 | echo bbp_get_forum_permalink( $forum_id ); |
---|
255 | } |
---|
256 | /** |
---|
257 | * Return the link to the forum |
---|
258 | * |
---|
259 | * @since bbPress (r2464) |
---|
260 | * |
---|
261 | * @param int $forum_id Optional. Forum id |
---|
262 | * @param $string $redirect_to Optional. Pass a redirect value for use with |
---|
263 | * shortcodes and other fun things. |
---|
264 | * @uses bbp_get_forum_id() To get the forum id |
---|
265 | * @uses get_permalink() Get the permalink of the forum |
---|
266 | * @uses apply_filters() Calls 'bbp_get_forum_permalink' with the forum |
---|
267 | * link |
---|
268 | * @return string Permanent link to forum |
---|
269 | */ |
---|
270 | function bbp_get_forum_permalink( $forum_id = 0, $redirect_to = '' ) { |
---|
271 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
272 | |
---|
273 | // Use the redirect address |
---|
274 | if ( !empty( $redirect_to ) ) { |
---|
275 | $forum_permalink = esc_url_raw( $redirect_to ); |
---|
276 | |
---|
277 | // Use the topic permalink |
---|
278 | } else { |
---|
279 | $forum_permalink = get_permalink( $forum_id ); |
---|
280 | } |
---|
281 | |
---|
282 | return apply_filters( 'bbp_get_forum_permalink', $forum_permalink, $forum_id ); |
---|
283 | } |
---|
284 | |
---|
285 | /** |
---|
286 | * Output the title of the forum |
---|
287 | * |
---|
288 | * @since bbPress (r2464) |
---|
289 | * |
---|
290 | * @param int $forum_id Optional. Forum id |
---|
291 | * @uses bbp_get_forum_title() To get the forum title |
---|
292 | */ |
---|
293 | function bbp_forum_title( $forum_id = 0 ) { |
---|
294 | echo bbp_get_forum_title( $forum_id ); |
---|
295 | } |
---|
296 | /** |
---|
297 | * Return the title of the forum |
---|
298 | * |
---|
299 | * @since bbPress (r2464) |
---|
300 | * |
---|
301 | * @param int $forum_id Optional. Forum id |
---|
302 | * @uses bbp_get_forum_id() To get the forum id |
---|
303 | * @uses get_the_title() To get the forum title |
---|
304 | * @uses apply_filters() Calls 'bbp_get_forum_title' with the title |
---|
305 | * @return string Title of forum |
---|
306 | */ |
---|
307 | function bbp_get_forum_title( $forum_id = 0 ) { |
---|
308 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
309 | $title = get_the_title( $forum_id ); |
---|
310 | |
---|
311 | return apply_filters( 'bbp_get_forum_title', $title, $forum_id ); |
---|
312 | } |
---|
313 | |
---|
314 | /** |
---|
315 | * Output the forum archive title |
---|
316 | * |
---|
317 | * @since bbPress (r3249) |
---|
318 | * |
---|
319 | * @param string $title Default text to use as title |
---|
320 | */ |
---|
321 | function bbp_forum_archive_title( $title = '' ) { |
---|
322 | echo bbp_get_forum_archive_title( $title ); |
---|
323 | } |
---|
324 | /** |
---|
325 | * Return the forum archive title |
---|
326 | * |
---|
327 | * @since bbPress (r3249) |
---|
328 | * |
---|
329 | * @param string $title Default text to use as title |
---|
330 | * |
---|
331 | * @uses bbp_get_page_by_path() Check if page exists at root path |
---|
332 | * @uses get_the_title() Use the page title at the root path |
---|
333 | * @uses get_post_type_object() Load the post type object |
---|
334 | * @uses bbp_get_forum_post_type() Get the forum post type ID |
---|
335 | * @uses get_post_type_labels() Get labels for forum post type |
---|
336 | * @uses apply_filters() Allow output to be manipulated |
---|
337 | * |
---|
338 | * @return string The forum archive title |
---|
339 | */ |
---|
340 | function bbp_get_forum_archive_title( $title = '' ) { |
---|
341 | |
---|
342 | // If no title was passed |
---|
343 | if ( empty( $title ) ) { |
---|
344 | |
---|
345 | // Set root text to page title |
---|
346 | $page = bbp_get_page_by_path( bbp_get_root_slug() ); |
---|
347 | if ( !empty( $page ) ) { |
---|
348 | $title = get_the_title( $page->ID ); |
---|
349 | |
---|
350 | // Default to forum post type name label |
---|
351 | } else { |
---|
352 | $fto = get_post_type_object( bbp_get_forum_post_type() ); |
---|
353 | $title = $fto->labels->name; |
---|
354 | } |
---|
355 | } |
---|
356 | |
---|
357 | return apply_filters( 'bbp_get_forum_archive_title', $title ); |
---|
358 | } |
---|
359 | |
---|
360 | /** |
---|
361 | * Output the content of the forum |
---|
362 | * |
---|
363 | * @since bbPress (r2780) |
---|
364 | * |
---|
365 | * @param int $forum_id Optional. Topic id |
---|
366 | * @uses bbp_get_forum_content() To get the forum content |
---|
367 | */ |
---|
368 | function bbp_forum_content( $forum_id = 0 ) { |
---|
369 | echo bbp_get_forum_content( $forum_id ); |
---|
370 | } |
---|
371 | /** |
---|
372 | * Return the content of the forum |
---|
373 | * |
---|
374 | * @since bbPress (r2780) |
---|
375 | * |
---|
376 | * @param int $forum_id Optional. Topic id |
---|
377 | * @uses bbp_get_forum_id() To get the forum id |
---|
378 | * @uses post_password_required() To check if the forum requires pass |
---|
379 | * @uses get_the_password_form() To get the password form |
---|
380 | * @uses get_post_field() To get the content post field |
---|
381 | * @uses apply_filters() Calls 'bbp_get_forum_content' with the content |
---|
382 | * and forum id |
---|
383 | * @return string Content of the forum |
---|
384 | */ |
---|
385 | function bbp_get_forum_content( $forum_id = 0 ) { |
---|
386 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
387 | |
---|
388 | // Check if password is required |
---|
389 | if ( post_password_required( $forum_id ) ) |
---|
390 | return get_the_password_form(); |
---|
391 | |
---|
392 | $content = get_post_field( 'post_content', $forum_id ); |
---|
393 | |
---|
394 | return apply_filters( 'bbp_get_forum_content', $content, $forum_id ); |
---|
395 | } |
---|
396 | |
---|
397 | /** |
---|
398 | * Allow topic rows to have adminstrative actions |
---|
399 | * |
---|
400 | * @since bbPress (r3653) |
---|
401 | * @uses do_action() |
---|
402 | * @todo Links and filter |
---|
403 | */ |
---|
404 | function bbp_forum_row_actions() { |
---|
405 | do_action( 'bbp_forum_row_actions' ); |
---|
406 | } |
---|
407 | |
---|
408 | /** |
---|
409 | * Output the forums last active ID |
---|
410 | * |
---|
411 | * @since bbPress (r2860) |
---|
412 | * |
---|
413 | * @uses bbp_get_forum_last_active_id() To get the forum's last active id |
---|
414 | * @param int $forum_id Optional. Forum id |
---|
415 | */ |
---|
416 | function bbp_forum_last_active_id( $forum_id = 0 ) { |
---|
417 | echo bbp_get_forum_last_active_id( $forum_id ); |
---|
418 | } |
---|
419 | /** |
---|
420 | * Return the forums last active ID |
---|
421 | * |
---|
422 | * @since bbPress (r2860) |
---|
423 | * |
---|
424 | * @param int $forum_id Optional. Forum id |
---|
425 | * @uses bbp_get_forum_id() To get the forum id |
---|
426 | * @uses get_post_meta() To get the forum's last active id |
---|
427 | * @uses apply_filters() Calls 'bbp_get_forum_last_active_id' with |
---|
428 | * the last active id and forum id |
---|
429 | * @return int Forum's last active id |
---|
430 | */ |
---|
431 | function bbp_get_forum_last_active_id( $forum_id = 0 ) { |
---|
432 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
433 | $active_id = get_post_meta( $forum_id, '_bbp_last_active_id', true ); |
---|
434 | |
---|
435 | return (int) apply_filters( 'bbp_get_forum_last_active_id', (int) $active_id, $forum_id ); |
---|
436 | } |
---|
437 | |
---|
438 | /** |
---|
439 | * Output the forums last update date/time (aka freshness) |
---|
440 | * |
---|
441 | * @since bbPress (r2464) |
---|
442 | * |
---|
443 | * @uses bbp_get_forum_last_active_time() To get the forum freshness |
---|
444 | * @param int $forum_id Optional. Forum id |
---|
445 | */ |
---|
446 | function bbp_forum_last_active_time( $forum_id = 0 ) { |
---|
447 | echo bbp_get_forum_last_active_time( $forum_id ); |
---|
448 | } |
---|
449 | /** |
---|
450 | * Return the forums last update date/time (aka freshness) |
---|
451 | * |
---|
452 | * @since bbPress (r2464) |
---|
453 | * |
---|
454 | * @param int $forum_id Optional. Forum id |
---|
455 | * @uses bbp_get_forum_id() To get the forum id |
---|
456 | * @uses get_post_meta() To retrieve forum last active meta |
---|
457 | * @uses bbp_get_forum_last_reply_id() To get forum's last reply id |
---|
458 | * @uses get_post_field() To get the post date of the reply |
---|
459 | * @uses bbp_get_forum_last_topic_id() To get forum's last topic id |
---|
460 | * @uses bbp_get_topic_last_active_time() To get time when the topic was |
---|
461 | * last active |
---|
462 | * @uses bbp_convert_date() To convert the date |
---|
463 | * @uses bbp_get_time_since() To get time in since format |
---|
464 | * @uses apply_filters() Calls 'bbp_get_forum_last_active' with last |
---|
465 | * active time and forum id |
---|
466 | * @return string Forum last update date/time (freshness) |
---|
467 | */ |
---|
468 | function bbp_get_forum_last_active_time( $forum_id = 0 ) { |
---|
469 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
470 | |
---|
471 | $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true ); |
---|
472 | if ( empty( $last_active ) ) { |
---|
473 | $reply_id = bbp_get_forum_last_reply_id( $forum_id ); |
---|
474 | if ( !empty( $reply_id ) ) { |
---|
475 | $last_active = get_post_field( 'post_date', $reply_id ); |
---|
476 | } else { |
---|
477 | $topic_id = bbp_get_forum_last_topic_id( $forum_id ); |
---|
478 | if ( !empty( $topic_id ) ) { |
---|
479 | $last_active = bbp_get_topic_last_active_time( $topic_id ); |
---|
480 | } |
---|
481 | } |
---|
482 | } |
---|
483 | |
---|
484 | $last_active = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : ''; |
---|
485 | |
---|
486 | return apply_filters( 'bbp_get_forum_last_active', $last_active, $forum_id ); |
---|
487 | } |
---|
488 | |
---|
489 | /** |
---|
490 | * Output link to the most recent activity inside a forum. |
---|
491 | * |
---|
492 | * Outputs a complete link with attributes and content. |
---|
493 | * |
---|
494 | * @since bbPress (r2625) |
---|
495 | * |
---|
496 | * @param int $forum_id Optional. Forum id |
---|
497 | * @uses bbp_get_forum_freshness_link() To get the forum freshness link |
---|
498 | */ |
---|
499 | function bbp_forum_freshness_link( $forum_id = 0) { |
---|
500 | echo bbp_get_forum_freshness_link( $forum_id ); |
---|
501 | } |
---|
502 | /** |
---|
503 | * Returns link to the most recent activity inside a forum. |
---|
504 | * |
---|
505 | * Returns a complete link with attributes and content. |
---|
506 | * |
---|
507 | * @since bbPress (r2625) |
---|
508 | * |
---|
509 | * @param int $forum_id Optional. Forum id |
---|
510 | * @uses bbp_get_forum_id() To get the forum id |
---|
511 | * @uses bbp_get_forum_last_active_id() To get the forum last active id |
---|
512 | * @uses bbp_get_forum_last_reply_id() To get the forum last reply id |
---|
513 | * @uses bbp_get_forum_last_topic_id() To get the forum last topic id |
---|
514 | * @uses bbp_get_forum_last_reply_url() To get the forum last reply url |
---|
515 | * @uses bbp_get_forum_last_reply_title() To get the forum last reply |
---|
516 | * title |
---|
517 | * @uses bbp_get_forum_last_topic_permalink() To get the forum last |
---|
518 | * topic permalink |
---|
519 | * @uses bbp_get_forum_last_topic_title() To get the forum last topic |
---|
520 | * title |
---|
521 | * @uses bbp_get_forum_last_active_time() To get the time when the forum |
---|
522 | * was last active |
---|
523 | * @uses apply_filters() Calls 'bbp_get_forum_freshness_link' with the |
---|
524 | * link and forum id |
---|
525 | */ |
---|
526 | function bbp_get_forum_freshness_link( $forum_id = 0 ) { |
---|
527 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
528 | $active_id = bbp_get_forum_last_active_id( $forum_id ); |
---|
529 | |
---|
530 | if ( empty( $active_id ) ) |
---|
531 | $active_id = bbp_get_forum_last_reply_id( $forum_id ); |
---|
532 | |
---|
533 | if ( empty( $active_id ) ) |
---|
534 | $active_id = bbp_get_forum_last_topic_id( $forum_id ); |
---|
535 | |
---|
536 | if ( bbp_is_topic( $active_id ) ) { |
---|
537 | $link_url = bbp_get_forum_last_topic_permalink( $forum_id ); |
---|
538 | $title = bbp_get_forum_last_topic_title( $forum_id ); |
---|
539 | } elseif ( bbp_is_reply( $active_id ) ) { |
---|
540 | $link_url = bbp_get_forum_last_reply_url( $forum_id ); |
---|
541 | $title = bbp_get_forum_last_reply_title( $forum_id ); |
---|
542 | } |
---|
543 | |
---|
544 | $time_since = bbp_get_forum_last_active_time( $forum_id ); |
---|
545 | |
---|
546 | if ( !empty( $time_since ) && !empty( $link_url ) ) |
---|
547 | $anchor = '<a href="' . $link_url . '" title="' . esc_attr( $title ) . '">' . $time_since . '</a>'; |
---|
548 | else |
---|
549 | $anchor = __( 'No Topics', 'bbpress' ); |
---|
550 | |
---|
551 | return apply_filters( 'bbp_get_forum_freshness_link', $anchor, $forum_id ); |
---|
552 | } |
---|
553 | |
---|
554 | /** |
---|
555 | * Output parent ID of a forum, if exists |
---|
556 | * |
---|
557 | * @since bbPress (r3675) |
---|
558 | * |
---|
559 | * @param int $forum_id Forum ID |
---|
560 | * @uses bbp_get_forum_parent_id() To get the forum's parent ID |
---|
561 | */ |
---|
562 | function bbp_forum_parent_id( $forum_id = 0 ) { |
---|
563 | echo bbp_get_forum_parent_id( $forum_id ); |
---|
564 | } |
---|
565 | /** |
---|
566 | * Return ID of forum parent, if exists |
---|
567 | * |
---|
568 | * @since bbPress (r3675) |
---|
569 | * |
---|
570 | * @param int $forum_id Optional. Forum id |
---|
571 | * @uses bbp_get_forum_id() To get the forum id |
---|
572 | * @uses get_post_field() To get the forum parent |
---|
573 | * @uses apply_filters() Calls 'bbp_get_forum_parent' with the parent & forum id |
---|
574 | * @return int Forum parent |
---|
575 | */ |
---|
576 | function bbp_get_forum_parent_id( $forum_id = 0 ) { |
---|
577 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
578 | $parent_id = get_post_field( 'post_parent', $forum_id ); |
---|
579 | |
---|
580 | return (int) apply_filters( 'bbp_get_forum_parent_id', (int) $parent_id, $forum_id ); |
---|
581 | } |
---|
582 | |
---|
583 | /** |
---|
584 | * Return array of parent forums |
---|
585 | * |
---|
586 | * @since bbPress (r2625) |
---|
587 | * |
---|
588 | * @param int $forum_id Optional. Forum id |
---|
589 | * @uses bbp_get_forum_id() To get the forum id |
---|
590 | * @uses bbp_get_forum() To get the forum |
---|
591 | * @uses apply_filters() Calls 'bbp_get_forum_ancestors' with the ancestors |
---|
592 | * and forum id |
---|
593 | * @return array Forum ancestors |
---|
594 | */ |
---|
595 | function bbp_get_forum_ancestors( $forum_id = 0 ) { |
---|
596 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
597 | $ancestors = array(); |
---|
598 | $forum = bbp_get_forum( $forum_id ); |
---|
599 | |
---|
600 | if ( !empty( $forum ) ) { |
---|
601 | while ( 0 !== (int) $forum->post_parent ) { |
---|
602 | $ancestors[] = $forum->post_parent; |
---|
603 | $forum = bbp_get_forum( $forum->post_parent ); |
---|
604 | } |
---|
605 | } |
---|
606 | |
---|
607 | return apply_filters( 'bbp_get_forum_ancestors', $ancestors, $forum_id ); |
---|
608 | } |
---|
609 | |
---|
610 | /** |
---|
611 | * Return subforums of given forum |
---|
612 | * |
---|
613 | * @since bbPress (r2747) |
---|
614 | * |
---|
615 | * @param mixed $args All the arguments supported by {@link WP_Query} |
---|
616 | * @uses bbp_get_forum_id() To get the forum id |
---|
617 | * @uses current_user_can() To check if the current user is capable of |
---|
618 | * reading private forums |
---|
619 | * @uses get_posts() To get the subforums |
---|
620 | * @uses apply_filters() Calls 'bbp_forum_get_subforums' with the subforums |
---|
621 | * and the args |
---|
622 | * @return mixed false if none, array of subs if yes |
---|
623 | */ |
---|
624 | function bbp_forum_get_subforums( $args = '' ) { |
---|
625 | |
---|
626 | // Use passed integer as post_parent |
---|
627 | if ( is_numeric( $args ) ) |
---|
628 | $args = array( 'post_parent' => $args ); |
---|
629 | |
---|
630 | // Setup possible post__not_in array |
---|
631 | $post_stati[] = bbp_get_public_status_id(); |
---|
632 | |
---|
633 | // Super admin get whitelisted post statuses |
---|
634 | if ( is_super_admin() ) { |
---|
635 | $post_stati = array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() ); |
---|
636 | |
---|
637 | // Not a super admin, so check caps |
---|
638 | } else { |
---|
639 | |
---|
640 | // Check if user can read private forums |
---|
641 | if ( current_user_can( 'read_private_forums' ) ) |
---|
642 | $post_stati[] = bbp_get_private_status_id(); |
---|
643 | |
---|
644 | // Check if user can read hidden forums |
---|
645 | if ( current_user_can( 'read_hidden_forums' ) ) |
---|
646 | $post_stati[] = bbp_get_hidden_status_id(); |
---|
647 | } |
---|
648 | |
---|
649 | $default = array( |
---|
650 | 'post_parent' => 0, |
---|
651 | 'post_type' => bbp_get_forum_post_type(), |
---|
652 | 'post_status' => implode( ',', $post_stati ), |
---|
653 | 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ), |
---|
654 | 'orderby' => 'menu_order', |
---|
655 | 'order' => 'ASC' |
---|
656 | ); |
---|
657 | |
---|
658 | $r = wp_parse_args( $args, $default ); |
---|
659 | $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] ); |
---|
660 | |
---|
661 | // No forum passed |
---|
662 | $sub_forums = !empty( $r['post_parent'] ) ? get_posts( $r ) : ''; |
---|
663 | |
---|
664 | return apply_filters( 'bbp_forum_get_sub_forums', (array) $sub_forums, $args ); |
---|
665 | } |
---|
666 | |
---|
667 | /** |
---|
668 | * Output a list of forums (can be used to list subforums) |
---|
669 | * |
---|
670 | * @param mixed $args The function supports these args: |
---|
671 | * - before: To put before the output. Defaults to '<ul class="bbp-forums">' |
---|
672 | * - after: To put after the output. Defaults to '</ul>' |
---|
673 | * - link_before: To put before every link. Defaults to '<li class="bbp-forum">' |
---|
674 | * - link_after: To put after every link. Defaults to '</li>' |
---|
675 | * - separator: Separator. Defaults to ', ' |
---|
676 | * - forum_id: Forum id. Defaults to '' |
---|
677 | * - show_topic_count - To show forum topic count or not. Defaults to true |
---|
678 | * - show_reply_count - To show forum reply count or not. Defaults to true |
---|
679 | * @uses bbp_forum_get_subforums() To check if the forum has subforums or not |
---|
680 | * @uses bbp_get_forum_permalink() To get forum permalink |
---|
681 | * @uses bbp_get_forum_title() To get forum title |
---|
682 | * @uses bbp_is_forum_category() To check if a forum is a category |
---|
683 | * @uses bbp_get_forum_topic_count() To get forum topic count |
---|
684 | * @uses bbp_get_forum_reply_count() To get forum reply count |
---|
685 | */ |
---|
686 | function bbp_list_forums( $args = '' ) { |
---|
687 | |
---|
688 | // Define used variables |
---|
689 | $output = $sub_forums = $topic_count = $reply_count = $counts = ''; |
---|
690 | $i = 0; |
---|
691 | $count = array(); |
---|
692 | |
---|
693 | // Defaults and arguments |
---|
694 | $defaults = array ( |
---|
695 | 'before' => '<ul class="bbp-forums-list">', |
---|
696 | 'after' => '</ul>', |
---|
697 | 'link_before' => '<li class="bbp-forum">', |
---|
698 | 'link_after' => '</li>', |
---|
699 | 'count_before' => ' (', |
---|
700 | 'count_after' => ')', |
---|
701 | 'count_sep' => ', ', |
---|
702 | 'separator' => ', ', |
---|
703 | 'forum_id' => '', |
---|
704 | 'show_topic_count' => true, |
---|
705 | 'show_reply_count' => true, |
---|
706 | ); |
---|
707 | $r = wp_parse_args( $args, $defaults ); |
---|
708 | extract( $r, EXTR_SKIP ); |
---|
709 | |
---|
710 | // Bail if there are no subforums |
---|
711 | if ( !bbp_get_forum_subforum_count( $forum_id ) ) |
---|
712 | return; |
---|
713 | |
---|
714 | // Loop through forums and create a list |
---|
715 | $sub_forums = bbp_forum_get_subforums( $forum_id ); |
---|
716 | if ( !empty( $sub_forums ) ) { |
---|
717 | |
---|
718 | // Total count (for separator) |
---|
719 | $total_subs = count( $sub_forums ); |
---|
720 | foreach ( $sub_forums as $sub_forum ) { |
---|
721 | $i++; // Separator count |
---|
722 | |
---|
723 | // Get forum details |
---|
724 | $count = array(); |
---|
725 | $show_sep = $total_subs > $i ? $separator : ''; |
---|
726 | $permalink = bbp_get_forum_permalink( $sub_forum->ID ); |
---|
727 | $title = bbp_get_forum_title( $sub_forum->ID ); |
---|
728 | |
---|
729 | // Show topic count |
---|
730 | if ( !empty( $show_topic_count ) && !bbp_is_forum_category( $sub_forum->ID ) ) { |
---|
731 | $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID ); |
---|
732 | } |
---|
733 | |
---|
734 | // Show reply count |
---|
735 | if ( !empty( $show_reply_count ) && !bbp_is_forum_category( $sub_forum->ID ) ) { |
---|
736 | $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID ); |
---|
737 | } |
---|
738 | |
---|
739 | // Counts to show |
---|
740 | if ( !empty( $count ) ) { |
---|
741 | $counts = $count_before . implode( $count_sep, $count ) . $count_after; |
---|
742 | } |
---|
743 | |
---|
744 | // Build this sub forums link |
---|
745 | $output .= $link_before . '<a href="' . $permalink . '" class="bbp-forum-link">' . $title . $counts . '</a>' . $show_sep . $link_after; |
---|
746 | } |
---|
747 | |
---|
748 | // Output the list |
---|
749 | echo apply_filters( 'bbp_list_forums', $before . $output . $after, $args ); |
---|
750 | } |
---|
751 | } |
---|
752 | |
---|
753 | /** Forum Last Topic **********************************************************/ |
---|
754 | |
---|
755 | /** |
---|
756 | * Output the forum's last topic id |
---|
757 | * |
---|
758 | * @since bbPress (r2464) |
---|
759 | * |
---|
760 | * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id |
---|
761 | * @param int $forum_id Optional. Forum id |
---|
762 | */ |
---|
763 | function bbp_forum_last_topic_id( $forum_id = 0 ) { |
---|
764 | echo bbp_get_forum_last_topic_id( $forum_id ); |
---|
765 | } |
---|
766 | /** |
---|
767 | * Return the forum's last topic id |
---|
768 | * |
---|
769 | * @since bbPress (r2464) |
---|
770 | * |
---|
771 | * @param int $forum_id Optional. Forum id |
---|
772 | * @uses bbp_get_forum_id() To get the forum id |
---|
773 | * @uses get_post_meta() To get the forum's last topic id |
---|
774 | * @uses apply_filters() Calls 'bbp_get_forum_last_topic_id' with the |
---|
775 | * forum and topic id |
---|
776 | * @return int Forum's last topic id |
---|
777 | */ |
---|
778 | function bbp_get_forum_last_topic_id( $forum_id = 0 ) { |
---|
779 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
780 | $topic_id = get_post_meta( $forum_id, '_bbp_last_topic_id', true ); |
---|
781 | |
---|
782 | return (int) apply_filters( 'bbp_get_forum_last_topic_id', (int) $topic_id, $forum_id ); |
---|
783 | } |
---|
784 | |
---|
785 | /** |
---|
786 | * Output the title of the last topic inside a forum |
---|
787 | * |
---|
788 | * @since bbPress (r2625) |
---|
789 | * |
---|
790 | * @param int $forum_id Optional. Forum id |
---|
791 | * @uses bbp_get_forum_last_topic_title() To get the forum's last topic's title |
---|
792 | */ |
---|
793 | function bbp_forum_last_topic_title( $forum_id = 0 ) { |
---|
794 | echo bbp_get_forum_last_topic_title( $forum_id ); |
---|
795 | } |
---|
796 | /** |
---|
797 | * Return the title of the last topic inside a forum |
---|
798 | * |
---|
799 | * @since bbPress (r2625) |
---|
800 | * |
---|
801 | * @param int $forum_id Optional. Forum id |
---|
802 | * @uses bbp_get_forum_id() To get the forum id |
---|
803 | * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id |
---|
804 | * @uses bbp_get_topic_title() To get the topic's title |
---|
805 | * @uses apply_filters() Calls 'bbp_get_forum_last_topic_title' with the |
---|
806 | * topic title and forum id |
---|
807 | * @return string Forum's last topic's title |
---|
808 | */ |
---|
809 | function bbp_get_forum_last_topic_title( $forum_id = 0 ) { |
---|
810 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
811 | return apply_filters( 'bbp_get_forum_last_topic_title', bbp_get_topic_title( bbp_get_forum_last_topic_id( $forum_id ) ), $forum_id ); |
---|
812 | } |
---|
813 | |
---|
814 | /** |
---|
815 | * Output the link to the last topic in a forum |
---|
816 | * |
---|
817 | * @since bbPress (r2464) |
---|
818 | * |
---|
819 | * @param int $forum_id Optional. Forum id |
---|
820 | * @uses bbp_get_forum_last_topic_permalink() To get the forum's last topic's |
---|
821 | * permanent link |
---|
822 | */ |
---|
823 | function bbp_forum_last_topic_permalink( $forum_id = 0 ) { |
---|
824 | echo bbp_get_forum_last_topic_permalink( $forum_id ); |
---|
825 | } |
---|
826 | /** |
---|
827 | * Return the link to the last topic in a forum |
---|
828 | * |
---|
829 | * @since bbPress (r2464) |
---|
830 | * |
---|
831 | * @param int $forum_id Optional. Forum id |
---|
832 | * @uses bbp_get_forum_id() To get the forum id |
---|
833 | * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id |
---|
834 | * @uses bbp_get_topic_permalink() To get the topic's permalink |
---|
835 | * @uses apply_filters() Calls 'bbp_get_forum_last_topic_permalink' with |
---|
836 | * the topic link and forum id |
---|
837 | * @return string Permanent link to topic |
---|
838 | */ |
---|
839 | function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) { |
---|
840 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
841 | return apply_filters( 'bbp_get_forum_last_topic_permalink', bbp_get_topic_permalink( bbp_get_forum_last_topic_id( $forum_id ) ), $forum_id ); |
---|
842 | } |
---|
843 | |
---|
844 | /** |
---|
845 | * Return the author ID of the last topic of a forum |
---|
846 | * |
---|
847 | * @since bbPress (r2625) |
---|
848 | * |
---|
849 | * @param int $forum_id Optional. Forum id |
---|
850 | * @uses bbp_get_forum_id() To get the forum id |
---|
851 | * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id |
---|
852 | * @uses bbp_get_topic_author_id() To get the topic's author id |
---|
853 | * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author' with the author |
---|
854 | * id and forum id |
---|
855 | * @return int Forum's last topic's author id |
---|
856 | */ |
---|
857 | function bbp_get_forum_last_topic_author_id( $forum_id = 0 ) { |
---|
858 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
859 | $author_id = bbp_get_topic_author_id( bbp_get_forum_last_topic_id( $forum_id ) ); |
---|
860 | return (int) apply_filters( 'bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id ); |
---|
861 | } |
---|
862 | |
---|
863 | /** |
---|
864 | * Output link to author of last topic of forum |
---|
865 | * |
---|
866 | * @since bbPress (r2625) |
---|
867 | * |
---|
868 | * @param int $forum_id Optional. Forum id |
---|
869 | * @uses bbp_get_forum_last_topic_author_link() To get the forum's last topic's |
---|
870 | * author link |
---|
871 | */ |
---|
872 | function bbp_forum_last_topic_author_link( $forum_id = 0 ) { |
---|
873 | echo bbp_get_forum_last_topic_author_link( $forum_id ); |
---|
874 | } |
---|
875 | /** |
---|
876 | * Return link to author of last topic of forum |
---|
877 | * |
---|
878 | * @since bbPress (r2625) |
---|
879 | * |
---|
880 | * @param int $forum_id Optional. Forum id |
---|
881 | * @uses bbp_get_forum_id() To get the forum id |
---|
882 | * @uses bbp_get_forum_last_topic_author_id() To get the forum's last |
---|
883 | * topic's author id |
---|
884 | * @uses bbp_get_user_profile_link() To get the author's profile link |
---|
885 | * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author_link' |
---|
886 | * with the author link and forum id |
---|
887 | * @return string Forum's last topic's author link |
---|
888 | */ |
---|
889 | function bbp_get_forum_last_topic_author_link( $forum_id = 0 ) { |
---|
890 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
891 | $author_id = bbp_get_forum_last_topic_author_id( $forum_id ); |
---|
892 | $author_link = bbp_get_user_profile_link( $author_id ); |
---|
893 | return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id ); |
---|
894 | } |
---|
895 | |
---|
896 | /** Forum Last Reply **********************************************************/ |
---|
897 | |
---|
898 | /** |
---|
899 | * Output the forums last reply id |
---|
900 | * |
---|
901 | * @since bbPress (r2464) |
---|
902 | * |
---|
903 | * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id |
---|
904 | * @param int $forum_id Optional. Forum id |
---|
905 | */ |
---|
906 | function bbp_forum_last_reply_id( $forum_id = 0 ) { |
---|
907 | echo bbp_get_forum_last_reply_id( $forum_id ); |
---|
908 | } |
---|
909 | /** |
---|
910 | * Return the forums last reply id |
---|
911 | * |
---|
912 | * @since bbPress (r2464) |
---|
913 | * |
---|
914 | * @param int $forum_id Optional. Forum id |
---|
915 | * @uses bbp_get_forum_id() To get the forum id |
---|
916 | * @uses get_post_meta() To get the forum's last reply id |
---|
917 | * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id |
---|
918 | * @uses apply_filters() Calls 'bbp_get_forum_last_reply_id' with |
---|
919 | * the last reply id and forum id |
---|
920 | * @return int Forum's last reply id |
---|
921 | */ |
---|
922 | function bbp_get_forum_last_reply_id( $forum_id = 0 ) { |
---|
923 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
924 | $reply_id = get_post_meta( $forum_id, '_bbp_last_reply_id', true ); |
---|
925 | |
---|
926 | if ( empty( $reply_id ) ) |
---|
927 | $reply_id = bbp_get_forum_last_topic_id( $forum_id ); |
---|
928 | |
---|
929 | return (int) apply_filters( 'bbp_get_forum_last_reply_id', (int) $reply_id, $forum_id ); |
---|
930 | } |
---|
931 | |
---|
932 | /** |
---|
933 | * Output the title of the last reply inside a forum |
---|
934 | * |
---|
935 | * @param int $forum_id Optional. Forum id |
---|
936 | * @uses bbp_get_forum_last_reply_title() To get the forum's last reply's title |
---|
937 | */ |
---|
938 | function bbp_forum_last_reply_title( $forum_id = 0 ) { |
---|
939 | echo bbp_get_forum_last_reply_title( $forum_id ); |
---|
940 | } |
---|
941 | /** |
---|
942 | * Return the title of the last reply inside a forum |
---|
943 | * |
---|
944 | * @param int $forum_id Optional. Forum id |
---|
945 | * @uses bbp_get_forum_id() To get the forum id |
---|
946 | * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id |
---|
947 | * @uses bbp_get_reply_title() To get the reply title |
---|
948 | * @uses apply_filters() Calls 'bbp_get_forum_last_reply_title' with the |
---|
949 | * reply title and forum id |
---|
950 | * @return string |
---|
951 | */ |
---|
952 | function bbp_get_forum_last_reply_title( $forum_id = 0 ) { |
---|
953 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
954 | return apply_filters( 'bbp_get_forum_last_reply_title', bbp_get_reply_title( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id ); |
---|
955 | } |
---|
956 | |
---|
957 | /** |
---|
958 | * Output the link to the last reply in a forum |
---|
959 | * |
---|
960 | * @since bbPress (r2464) |
---|
961 | * |
---|
962 | * @param int $forum_id Optional. Forum id |
---|
963 | * @uses bbp_get_forum_last_reply_permalink() To get the forum last reply link |
---|
964 | */ |
---|
965 | function bbp_forum_last_reply_permalink( $forum_id = 0 ) { |
---|
966 | echo bbp_get_forum_last_reply_permalink( $forum_id ); |
---|
967 | } |
---|
968 | /** |
---|
969 | * Return the link to the last reply in a forum |
---|
970 | * |
---|
971 | * @since bbPress (r2464) |
---|
972 | * |
---|
973 | * @param int $forum_id Optional. Forum id |
---|
974 | * @uses bbp_get_forum_id() To get the forum id |
---|
975 | * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id |
---|
976 | * @uses bbp_get_reply_permalink() To get the reply permalink |
---|
977 | * @uses apply_filters() Calls 'bbp_get_forum_last_reply_permalink' with |
---|
978 | * the reply link and forum id |
---|
979 | * @return string Permanent link to the forum's last reply |
---|
980 | */ |
---|
981 | function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) { |
---|
982 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
983 | return apply_filters( 'bbp_get_forum_last_reply_permalink', bbp_get_reply_permalink( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id ); |
---|
984 | } |
---|
985 | |
---|
986 | /** |
---|
987 | * Output the url to the last reply in a forum |
---|
988 | * |
---|
989 | * @since bbPress (r2683) |
---|
990 | * |
---|
991 | * @param int $forum_id Optional. Forum id |
---|
992 | * @uses bbp_get_forum_last_reply_url() To get the forum last reply url |
---|
993 | */ |
---|
994 | function bbp_forum_last_reply_url( $forum_id = 0 ) { |
---|
995 | echo bbp_get_forum_last_reply_url( $forum_id ); |
---|
996 | } |
---|
997 | /** |
---|
998 | * Return the url to the last reply in a forum |
---|
999 | * |
---|
1000 | * @since bbPress (r2683) |
---|
1001 | * |
---|
1002 | * @param int $forum_id Optional. Forum id |
---|
1003 | * @uses bbp_get_forum_id() To get the forum id |
---|
1004 | * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id |
---|
1005 | * @uses bbp_get_reply_url() To get the reply url |
---|
1006 | * @uses bbp_get_forum_last_topic_permalink() To get the forum's last |
---|
1007 | * topic's permalink |
---|
1008 | * @uses apply_filters() Calls 'bbp_get_forum_last_reply_url' with the |
---|
1009 | * reply url and forum id |
---|
1010 | * @return string Paginated URL to latest reply |
---|
1011 | */ |
---|
1012 | function bbp_get_forum_last_reply_url( $forum_id = 0 ) { |
---|
1013 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1014 | |
---|
1015 | // If forum has replies, get the last reply and use its url |
---|
1016 | $reply_id = bbp_get_forum_last_reply_id( $forum_id ); |
---|
1017 | if ( !empty( $reply_id ) ) { |
---|
1018 | $reply_url = bbp_get_reply_url( $reply_id ); |
---|
1019 | |
---|
1020 | // No replies, so look for topics and use last permalink |
---|
1021 | } else { |
---|
1022 | $reply_url = bbp_get_forum_last_topic_permalink( $forum_id ); |
---|
1023 | |
---|
1024 | // No topics either, so set $reply_url as empty string |
---|
1025 | if ( empty( $reply_url ) ) { |
---|
1026 | $reply_url = ''; |
---|
1027 | } |
---|
1028 | } |
---|
1029 | |
---|
1030 | // Filter and return |
---|
1031 | return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id ); |
---|
1032 | } |
---|
1033 | |
---|
1034 | /** |
---|
1035 | * Output author ID of last reply of forum |
---|
1036 | * |
---|
1037 | * @since bbPress (r2625) |
---|
1038 | * |
---|
1039 | * @param int $forum_id Optional. Forum id |
---|
1040 | * @uses bbp_get_forum_last_reply_author_id() To get the forum's last reply |
---|
1041 | * author id |
---|
1042 | */ |
---|
1043 | function bbp_forum_last_reply_author_id( $forum_id = 0 ) { |
---|
1044 | echo bbp_get_forum_last_reply_author_id( $forum_id ); |
---|
1045 | } |
---|
1046 | /** |
---|
1047 | * Return author ID of last reply of forum |
---|
1048 | * |
---|
1049 | * @since bbPress (r2625) |
---|
1050 | * |
---|
1051 | * @param int $forum_id Optional. Forum id |
---|
1052 | * @uses bbp_get_forum_id() To get the forum id |
---|
1053 | * @uses bbp_get_forum_last_reply_author_id() To get the forum's last |
---|
1054 | * reply's author id |
---|
1055 | * @uses bbp_get_reply_author_id() To get the reply's author id |
---|
1056 | * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_id' with |
---|
1057 | * the author id and forum id |
---|
1058 | * @return int Forum's last reply author id |
---|
1059 | */ |
---|
1060 | function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) { |
---|
1061 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1062 | $author_id = bbp_get_reply_author_id( bbp_get_forum_last_reply_id( $forum_id ) ); |
---|
1063 | return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id ); |
---|
1064 | } |
---|
1065 | |
---|
1066 | /** |
---|
1067 | * Output link to author of last reply of forum |
---|
1068 | * |
---|
1069 | * @since bbPress (r2625) |
---|
1070 | * |
---|
1071 | * @param int $forum_id Optional. Forum id |
---|
1072 | * @uses bbp_get_forum_last_reply_author_link() To get the forum's last reply's |
---|
1073 | * author link |
---|
1074 | */ |
---|
1075 | function bbp_forum_last_reply_author_link( $forum_id = 0 ) { |
---|
1076 | echo bbp_get_forum_last_reply_author_link( $forum_id ); |
---|
1077 | } |
---|
1078 | /** |
---|
1079 | * Return link to author of last reply of forum |
---|
1080 | * |
---|
1081 | * @since bbPress (r2625) |
---|
1082 | * |
---|
1083 | * @param int $forum_id Optional. Forum id |
---|
1084 | * @uses bbp_get_forum_id() To get the forum id |
---|
1085 | * @uses bbp_get_forum_last_reply_author_id() To get the forum's last |
---|
1086 | * reply's author id |
---|
1087 | * @uses bbp_get_user_profile_link() To get the reply's author's profile |
---|
1088 | * link |
---|
1089 | * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_link' |
---|
1090 | * with the author link and forum id |
---|
1091 | * @return string Link to author of last reply of forum |
---|
1092 | */ |
---|
1093 | function bbp_get_forum_last_reply_author_link( $forum_id = 0 ) { |
---|
1094 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1095 | $author_id = bbp_get_forum_last_reply_author_id( $forum_id ); |
---|
1096 | $author_link = bbp_get_user_profile_link( $author_id ); |
---|
1097 | return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id ); |
---|
1098 | } |
---|
1099 | |
---|
1100 | /** Forum Counts **************************************************************/ |
---|
1101 | |
---|
1102 | /** |
---|
1103 | * Output the topics link of the forum |
---|
1104 | * |
---|
1105 | * @since bbPress (r2883) |
---|
1106 | * |
---|
1107 | * @param int $forum_id Optional. Topic id |
---|
1108 | * @uses bbp_get_forum_topics_link() To get the forum topics link |
---|
1109 | */ |
---|
1110 | function bbp_forum_topics_link( $forum_id = 0 ) { |
---|
1111 | echo bbp_get_forum_topics_link( $forum_id ); |
---|
1112 | } |
---|
1113 | |
---|
1114 | /** |
---|
1115 | * Return the topics link of the forum |
---|
1116 | * |
---|
1117 | * @since bbPress (r2883) |
---|
1118 | * |
---|
1119 | * @param int $forum_id Optional. Topic id |
---|
1120 | * @uses bbp_get_forum_id() To get the forum id |
---|
1121 | * @uses bbp_get_forum() To get the forum |
---|
1122 | * @uses bbp_get_forum_topic_count() To get the forum topic count |
---|
1123 | * @uses bbp_get_forum_permalink() To get the forum permalink |
---|
1124 | * @uses remove_query_arg() To remove args from the url |
---|
1125 | * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden |
---|
1126 | * topic count |
---|
1127 | * @uses current_user_can() To check if the current user can edit others |
---|
1128 | * topics |
---|
1129 | * @uses add_query_arg() To add custom args to the url |
---|
1130 | * @uses apply_filters() Calls 'bbp_get_forum_topics_link' with the |
---|
1131 | * topics link and forum id |
---|
1132 | */ |
---|
1133 | function bbp_get_forum_topics_link( $forum_id = 0 ) { |
---|
1134 | |
---|
1135 | $forum = bbp_get_forum( $forum_id ); |
---|
1136 | $forum_id = $forum->ID; |
---|
1137 | $topics = bbp_get_forum_topic_count( $forum_id ); |
---|
1138 | $topics = sprintf( _n( '%s topic', '%s topics', $topics, 'bbpress' ), $topics ); |
---|
1139 | $retval = ''; |
---|
1140 | |
---|
1141 | // First link never has view=all |
---|
1142 | if ( bbp_get_view_all( 'edit_others_topics' ) ) |
---|
1143 | $retval .= "<a href='" . esc_url( bbp_remove_view_all( bbp_get_forum_permalink( $forum_id ) ) ) . "'>$topics</a>"; |
---|
1144 | else |
---|
1145 | $retval .= $topics; |
---|
1146 | |
---|
1147 | // Get deleted topics |
---|
1148 | $deleted = bbp_get_forum_topic_count_hidden( $forum_id ); |
---|
1149 | |
---|
1150 | // This forum has hidden topics |
---|
1151 | if ( !empty( $deleted ) && current_user_can( 'edit_others_topics' ) ) { |
---|
1152 | |
---|
1153 | // Extra text |
---|
1154 | $extra = sprintf( __( ' (+ %d hidden)', 'bbpress' ), $deleted ); |
---|
1155 | |
---|
1156 | // No link |
---|
1157 | if ( bbp_get_view_all() ) { |
---|
1158 | $retval .= " $extra"; |
---|
1159 | |
---|
1160 | // Link |
---|
1161 | } else { |
---|
1162 | $retval .= " <a href='" . esc_url( bbp_add_view_all( bbp_get_forum_permalink( $forum_id ), true ) ) . "'>$extra</a>"; |
---|
1163 | } |
---|
1164 | } |
---|
1165 | |
---|
1166 | return apply_filters( 'bbp_get_forum_topics_link', $retval, $forum_id ); |
---|
1167 | } |
---|
1168 | |
---|
1169 | /** |
---|
1170 | * Output total sub-forum count of a forum |
---|
1171 | * |
---|
1172 | * @since bbPress (r2464) |
---|
1173 | * |
---|
1174 | * @uses bbp_get_forum_subforum_count() To get the forum's subforum count |
---|
1175 | * @param int $forum_id Optional. Forum id to check |
---|
1176 | */ |
---|
1177 | function bbp_forum_subforum_count( $forum_id = 0 ) { |
---|
1178 | echo bbp_get_forum_subforum_count( $forum_id ); |
---|
1179 | } |
---|
1180 | /** |
---|
1181 | * Return total subforum count of a forum |
---|
1182 | * |
---|
1183 | * @since bbPress (r2464) |
---|
1184 | * |
---|
1185 | * @param int $forum_id Optional. Forum id |
---|
1186 | * @uses bbp_get_forum_id() To get the forum id |
---|
1187 | * @uses get_post_meta() To get the subforum count |
---|
1188 | * @uses apply_filters() Calls 'bbp_get_forum_subforum_count' with the |
---|
1189 | * subforum count and forum id |
---|
1190 | * @return int Forum's subforum count |
---|
1191 | */ |
---|
1192 | function bbp_get_forum_subforum_count( $forum_id = 0 ) { |
---|
1193 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1194 | $forum_count = get_post_meta( $forum_id, '_bbp_forum_subforum_count', true ); |
---|
1195 | |
---|
1196 | return (int) apply_filters( 'bbp_get_forum_subforum_count', (int) $forum_count, $forum_id ); |
---|
1197 | } |
---|
1198 | |
---|
1199 | /** |
---|
1200 | * Output total topic count of a forum |
---|
1201 | * |
---|
1202 | * @since bbPress (r2464) |
---|
1203 | * |
---|
1204 | * @param int $forum_id Optional. Forum id |
---|
1205 | * @param bool $total_count Optional. To get the total count or normal count? |
---|
1206 | * @uses bbp_get_forum_topic_count() To get the forum topic count |
---|
1207 | */ |
---|
1208 | function bbp_forum_topic_count( $forum_id = 0, $total_count = true ) { |
---|
1209 | echo bbp_get_forum_topic_count( $forum_id, $total_count ); |
---|
1210 | } |
---|
1211 | /** |
---|
1212 | * Return total topic count of a forum |
---|
1213 | * |
---|
1214 | * @since bbPress (r2464) |
---|
1215 | * |
---|
1216 | * @param int $forum_id Optional. Forum id |
---|
1217 | * @param bool $total_count Optional. To get the total count or normal |
---|
1218 | * count? Defaults to total. |
---|
1219 | * @uses bbp_get_forum_id() To get the forum id |
---|
1220 | * @uses get_post_meta() To get the forum topic count |
---|
1221 | * @uses apply_filters() Calls 'bbp_get_forum_topic_count' with the |
---|
1222 | * topic count and forum id |
---|
1223 | * @return int Forum topic count |
---|
1224 | */ |
---|
1225 | function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true ) { |
---|
1226 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1227 | $topics = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count', true ); |
---|
1228 | |
---|
1229 | return (int) apply_filters( 'bbp_get_forum_topic_count', (int) $topics, $forum_id ); |
---|
1230 | } |
---|
1231 | |
---|
1232 | /** |
---|
1233 | * Output total reply count of a forum |
---|
1234 | * |
---|
1235 | * @since bbPress (r2464) |
---|
1236 | * |
---|
1237 | * @param int $forum_id Optional. Forum id |
---|
1238 | * @param bool $total_count Optional. To get the total count or normal count? |
---|
1239 | * @uses bbp_get_forum_reply_count() To get the forum reply count |
---|
1240 | */ |
---|
1241 | function bbp_forum_reply_count( $forum_id = 0, $total_count = true ) { |
---|
1242 | echo bbp_get_forum_reply_count( $forum_id, $total_count ); |
---|
1243 | } |
---|
1244 | /** |
---|
1245 | * Return total post count of a forum |
---|
1246 | * |
---|
1247 | * @since bbPress (r2464) |
---|
1248 | * |
---|
1249 | * @param int $forum_id Optional. Forum id |
---|
1250 | * @param bool $total_count Optional. To get the total count or normal |
---|
1251 | * count? |
---|
1252 | * @uses bbp_get_forum_id() To get the forum id |
---|
1253 | * @uses get_post_meta() To get the forum reply count |
---|
1254 | * @uses apply_filters() Calls 'bbp_get_forum_reply_count' with the |
---|
1255 | * reply count and forum id |
---|
1256 | * @return int Forum reply count |
---|
1257 | */ |
---|
1258 | function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true ) { |
---|
1259 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1260 | $replies = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count', true ); |
---|
1261 | |
---|
1262 | return (int) apply_filters( 'bbp_get_forum_reply_count', (int) $replies, $forum_id ); |
---|
1263 | } |
---|
1264 | |
---|
1265 | /** |
---|
1266 | * Output total post count of a forum |
---|
1267 | * |
---|
1268 | * @since bbPress (r2954) |
---|
1269 | * |
---|
1270 | * @param int $forum_id Optional. Forum id |
---|
1271 | * @param bool $total_count Optional. To get the total count or normal count? |
---|
1272 | * @uses bbp_get_forum_post_count() To get the forum post count |
---|
1273 | */ |
---|
1274 | function bbp_forum_post_count( $forum_id = 0, $total_count = true ) { |
---|
1275 | echo bbp_get_forum_post_count( $forum_id, $total_count ); |
---|
1276 | } |
---|
1277 | /** |
---|
1278 | * Return total post count of a forum |
---|
1279 | * |
---|
1280 | * @since bbPress (r2954) |
---|
1281 | * |
---|
1282 | * @param int $forum_id Optional. Forum id |
---|
1283 | * @param bool $total_count Optional. To get the total count or normal |
---|
1284 | * count? |
---|
1285 | * @uses bbp_get_forum_id() To get the forum id |
---|
1286 | * @uses get_post_meta() To get the forum post count |
---|
1287 | * @uses apply_filters() Calls 'bbp_get_forum_post_count' with the |
---|
1288 | * post count and forum id |
---|
1289 | * @return int Forum post count |
---|
1290 | */ |
---|
1291 | function bbp_get_forum_post_count( $forum_id = 0, $total_count = true ) { |
---|
1292 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1293 | $topics = bbp_get_forum_topic_count( $forum_id, $total_count ); |
---|
1294 | $replies = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count', true ); |
---|
1295 | |
---|
1296 | return (int) apply_filters( 'bbp_get_forum_post_count', (int) $replies + (int) $topics, $forum_id ); |
---|
1297 | } |
---|
1298 | |
---|
1299 | /** |
---|
1300 | * Output total hidden topic count of a forum (hidden includes trashed and |
---|
1301 | * spammed topics) |
---|
1302 | * |
---|
1303 | * @since bbPress (r2883) |
---|
1304 | * |
---|
1305 | * @param int $forum_id Optional. Topic id |
---|
1306 | * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden topic count |
---|
1307 | */ |
---|
1308 | function bbp_forum_topic_count_hidden( $forum_id = 0 ) { |
---|
1309 | echo bbp_get_forum_topic_count_hidden( $forum_id ); |
---|
1310 | } |
---|
1311 | /** |
---|
1312 | * Return total hidden topic count of a forum (hidden includes trashed |
---|
1313 | * and spammed topics) |
---|
1314 | * |
---|
1315 | * @since bbPress (r2883) |
---|
1316 | * |
---|
1317 | * @param int $forum_id Optional. Topic id |
---|
1318 | * @uses bbp_get_forum_id() To get the forum id |
---|
1319 | * @uses get_post_meta() To get the hidden topic count |
---|
1320 | * @uses apply_filters() Calls 'bbp_get_forum_topic_count_hidden' with |
---|
1321 | * the hidden topic count and forum id |
---|
1322 | * @return int Topic hidden topic count |
---|
1323 | */ |
---|
1324 | function bbp_get_forum_topic_count_hidden( $forum_id = 0 ) { |
---|
1325 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1326 | $topics = get_post_meta( $forum_id, '_bbp_topic_count_hidden', true ); |
---|
1327 | |
---|
1328 | return (int) apply_filters( 'bbp_get_forum_topic_count_hidden', (int) $topics, $forum_id ); |
---|
1329 | } |
---|
1330 | |
---|
1331 | /** |
---|
1332 | * Output the status of the forum |
---|
1333 | * |
---|
1334 | * @since bbPress (r2667) |
---|
1335 | * |
---|
1336 | * @param int $forum_id Optional. Forum id |
---|
1337 | * @uses bbp_get_forum_status() To get the forum status |
---|
1338 | */ |
---|
1339 | function bbp_forum_status( $forum_id = 0 ) { |
---|
1340 | echo bbp_get_forum_status( $forum_id ); |
---|
1341 | } |
---|
1342 | /** |
---|
1343 | * Return the status of the forum |
---|
1344 | * |
---|
1345 | * @since bbPress (r2667) |
---|
1346 | * |
---|
1347 | * @param int $forum_id Optional. Forum id |
---|
1348 | * @uses bbp_get_forum_id() To get the forum id |
---|
1349 | * @uses get_post_status() To get the forum's status |
---|
1350 | * @uses apply_filters() Calls 'bbp_get_forum_status' with the status |
---|
1351 | * and forum id |
---|
1352 | * @return string Status of forum |
---|
1353 | */ |
---|
1354 | function bbp_get_forum_status( $forum_id = 0 ) { |
---|
1355 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1356 | $status = get_post_meta( $forum_id, '_bbp_status', true ); |
---|
1357 | if ( empty( $status ) ) |
---|
1358 | $status = 'open'; |
---|
1359 | |
---|
1360 | return apply_filters( 'bbp_get_forum_status', $status, $forum_id ); |
---|
1361 | } |
---|
1362 | |
---|
1363 | /** |
---|
1364 | * Output the visibility of the forum |
---|
1365 | * |
---|
1366 | * @since bbPress (r2997) |
---|
1367 | * |
---|
1368 | * @param int $forum_id Optional. Forum id |
---|
1369 | * @uses bbp_get_forum_visibility() To get the forum visibility |
---|
1370 | */ |
---|
1371 | function bbp_forum_visibility( $forum_id = 0 ) { |
---|
1372 | echo bbp_get_forum_visibility( $forum_id ); |
---|
1373 | } |
---|
1374 | /** |
---|
1375 | * Return the visibility of the forum |
---|
1376 | * |
---|
1377 | * @since bbPress (r2997) |
---|
1378 | * |
---|
1379 | * @param int $forum_id Optional. Forum id |
---|
1380 | * @uses bbp_get_forum_id() To get the forum id |
---|
1381 | * @uses get_post_visibility() To get the forum's visibility |
---|
1382 | * @uses apply_filters() Calls 'bbp_get_forum_visibility' with the visibility |
---|
1383 | * and forum id |
---|
1384 | * @return string Status of forum |
---|
1385 | */ |
---|
1386 | function bbp_get_forum_visibility( $forum_id = 0 ) { |
---|
1387 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1388 | |
---|
1389 | return apply_filters( 'bbp_get_forum_visibility', get_post_status( $forum_id ), $forum_id ); |
---|
1390 | } |
---|
1391 | |
---|
1392 | /** |
---|
1393 | * Output the type of the forum |
---|
1394 | * |
---|
1395 | * @since bbPress (r3563) |
---|
1396 | * |
---|
1397 | * @param int $forum_id Optional. Forum id |
---|
1398 | * @uses bbp_get_forum_type() To get the forum type |
---|
1399 | */ |
---|
1400 | function bbp_forum_type( $forum_id = 0 ) { |
---|
1401 | echo bbp_get_forum_type( $forum_id ); |
---|
1402 | } |
---|
1403 | /** |
---|
1404 | * Return the type of forum (category/forum/etc...) |
---|
1405 | * |
---|
1406 | * @since bbPress (r3563) |
---|
1407 | * |
---|
1408 | * @param int $forum_id Optional. Forum id |
---|
1409 | * @uses get_post_meta() To get the forum category meta |
---|
1410 | * @return bool Whether the forum is a category or not |
---|
1411 | */ |
---|
1412 | function bbp_get_forum_type( $forum_id = 0 ) { |
---|
1413 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1414 | $retval = get_post_meta( $forum_id, '_bbp_forum_type', true ); |
---|
1415 | if ( empty( $retval ) ) |
---|
1416 | $retval = 'forum'; |
---|
1417 | |
---|
1418 | return apply_filters( 'bbp_get_forum_type', $retval, $forum_id ); |
---|
1419 | } |
---|
1420 | |
---|
1421 | /** |
---|
1422 | * Is the forum a category? |
---|
1423 | * |
---|
1424 | * @since bbPress (r2746) |
---|
1425 | * |
---|
1426 | * @param int $forum_id Optional. Forum id |
---|
1427 | * @uses bbp_get_forum_type() To get the forum type |
---|
1428 | * @return bool Whether the forum is a category or not |
---|
1429 | */ |
---|
1430 | function bbp_is_forum_category( $forum_id = 0 ) { |
---|
1431 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1432 | $type = bbp_get_forum_type( $forum_id ); |
---|
1433 | $retval = ( !empty( $type ) && 'category' == $type ); |
---|
1434 | |
---|
1435 | return (bool) apply_filters( 'bbp_is_forum_category', (bool) $retval, $forum_id ); |
---|
1436 | } |
---|
1437 | |
---|
1438 | /** |
---|
1439 | * Is the forum open? |
---|
1440 | * |
---|
1441 | * @since bbPress (r2746) |
---|
1442 | * @param int $forum_id Optional. Forum id |
---|
1443 | * |
---|
1444 | * @param int $forum_id Optional. Forum id |
---|
1445 | * @uses bbp_is_forum_closed() To check if the forum is closed or not |
---|
1446 | * @return bool Whether the forum is open or not |
---|
1447 | */ |
---|
1448 | function bbp_is_forum_open( $forum_id = 0 ) { |
---|
1449 | return !bbp_is_forum_closed( $forum_id ); |
---|
1450 | } |
---|
1451 | |
---|
1452 | /** |
---|
1453 | * Is the forum closed? |
---|
1454 | * |
---|
1455 | * @since bbPress (r2746) |
---|
1456 | * |
---|
1457 | * @param int $forum_id Optional. Forum id |
---|
1458 | * @param bool $check_ancestors Check if the ancestors are closed (only |
---|
1459 | * if they're a category) |
---|
1460 | * @uses bbp_get_forum_status() To get the forum status |
---|
1461 | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
---|
1462 | * @uses bbp_is_forum_category() To check if the forum is a category |
---|
1463 | * @uses bbp_is_forum_closed() To check if the forum is closed |
---|
1464 | * @return bool True if closed, false if not |
---|
1465 | */ |
---|
1466 | function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) { |
---|
1467 | |
---|
1468 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1469 | $retval = ( bbp_get_closed_status_id() == bbp_get_forum_status( $forum_id ) ); |
---|
1470 | |
---|
1471 | if ( !empty( $check_ancestors ) ) { |
---|
1472 | $ancestors = bbp_get_forum_ancestors( $forum_id ); |
---|
1473 | |
---|
1474 | foreach ( (array) $ancestors as $ancestor ) { |
---|
1475 | if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) ) { |
---|
1476 | $retval = true; |
---|
1477 | } |
---|
1478 | } |
---|
1479 | } |
---|
1480 | |
---|
1481 | return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors ); |
---|
1482 | } |
---|
1483 | |
---|
1484 | /** |
---|
1485 | * Is the forum public? |
---|
1486 | * |
---|
1487 | * @since bbPress (r2997) |
---|
1488 | * |
---|
1489 | * @param int $forum_id Optional. Forum id |
---|
1490 | * @param bool $check_ancestors Check if the ancestors are public (only if |
---|
1491 | * they're a category) |
---|
1492 | * @uses get_post_meta() To get the forum public meta |
---|
1493 | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
---|
1494 | * @uses bbp_is_forum_category() To check if the forum is a category |
---|
1495 | * @uses bbp_is_forum_closed() To check if the forum is closed |
---|
1496 | * @return bool True if closed, false if not |
---|
1497 | */ |
---|
1498 | function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) { |
---|
1499 | |
---|
1500 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1501 | $visibility = bbp_get_forum_visibility( $forum_id ); |
---|
1502 | |
---|
1503 | // If post status is public, return true |
---|
1504 | $retval = ( bbp_get_public_status_id() == $visibility ); |
---|
1505 | |
---|
1506 | // Check ancestors and inherit their privacy setting for display |
---|
1507 | if ( !empty( $check_ancestors ) ) { |
---|
1508 | $ancestors = bbp_get_forum_ancestors( $forum_id ); |
---|
1509 | |
---|
1510 | foreach ( (array) $ancestors as $ancestor ) { |
---|
1511 | if ( bbp_is_forum( $ancestor ) && bbp_is_forum_public( $ancestor, false ) ) { |
---|
1512 | $retval = true; |
---|
1513 | } |
---|
1514 | } |
---|
1515 | } |
---|
1516 | |
---|
1517 | return (bool) apply_filters( 'bbp_is_forum_public', (bool) $retval, $forum_id, $check_ancestors ); |
---|
1518 | } |
---|
1519 | |
---|
1520 | /** |
---|
1521 | * Is the forum private? |
---|
1522 | * |
---|
1523 | * @since bbPress (r2746) |
---|
1524 | * |
---|
1525 | * @param int $forum_id Optional. Forum id |
---|
1526 | * @param bool $check_ancestors Check if the ancestors are private (only if |
---|
1527 | * they're a category) |
---|
1528 | * @uses get_post_meta() To get the forum private meta |
---|
1529 | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
---|
1530 | * @uses bbp_is_forum_category() To check if the forum is a category |
---|
1531 | * @uses bbp_is_forum_closed() To check if the forum is closed |
---|
1532 | * @return bool True if closed, false if not |
---|
1533 | */ |
---|
1534 | function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) { |
---|
1535 | |
---|
1536 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1537 | $visibility = bbp_get_forum_visibility( $forum_id ); |
---|
1538 | |
---|
1539 | // If post status is private, return true |
---|
1540 | $retval = ( bbp_get_private_status_id() == $visibility ); |
---|
1541 | |
---|
1542 | // Check ancestors and inherit their privacy setting for display |
---|
1543 | if ( !empty( $check_ancestors ) ) { |
---|
1544 | $ancestors = bbp_get_forum_ancestors( $forum_id ); |
---|
1545 | |
---|
1546 | foreach ( (array) $ancestors as $ancestor ) { |
---|
1547 | if ( bbp_is_forum( $ancestor ) && bbp_is_forum_private( $ancestor, false ) ) { |
---|
1548 | $retval = true; |
---|
1549 | } |
---|
1550 | } |
---|
1551 | } |
---|
1552 | |
---|
1553 | return (bool) apply_filters( 'bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors ); |
---|
1554 | } |
---|
1555 | |
---|
1556 | /** |
---|
1557 | * Is the forum hidden? |
---|
1558 | * |
---|
1559 | * @since bbPress (r2997) |
---|
1560 | * |
---|
1561 | * @param int $forum_id Optional. Forum id |
---|
1562 | * @param bool $check_ancestors Check if the ancestors are private (only if |
---|
1563 | * they're a category) |
---|
1564 | * @uses get_post_meta() To get the forum private meta |
---|
1565 | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
---|
1566 | * @uses bbp_is_forum_category() To check if the forum is a category |
---|
1567 | * @uses bbp_is_forum_closed() To check if the forum is closed |
---|
1568 | * @return bool True if closed, false if not |
---|
1569 | */ |
---|
1570 | function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) { |
---|
1571 | |
---|
1572 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1573 | $visibility = bbp_get_forum_visibility( $forum_id ); |
---|
1574 | |
---|
1575 | // If post status is private, return true |
---|
1576 | $retval = ( bbp_get_hidden_status_id() == $visibility ); |
---|
1577 | |
---|
1578 | // Check ancestors and inherit their privacy setting for display |
---|
1579 | if ( !empty( $check_ancestors ) ) { |
---|
1580 | $ancestors = bbp_get_forum_ancestors( $forum_id ); |
---|
1581 | |
---|
1582 | foreach ( (array) $ancestors as $ancestor ) { |
---|
1583 | if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) { |
---|
1584 | $retval = true; |
---|
1585 | } |
---|
1586 | } |
---|
1587 | } |
---|
1588 | |
---|
1589 | return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors ); |
---|
1590 | } |
---|
1591 | |
---|
1592 | /** |
---|
1593 | * Output the author of the forum |
---|
1594 | * |
---|
1595 | * @since bbPress (r3675) |
---|
1596 | * |
---|
1597 | * @param int $forum_id Optional. Forum id |
---|
1598 | * @uses bbp_get_forum_author() To get the forum author |
---|
1599 | */ |
---|
1600 | function bbp_forum_author_display_name( $forum_id = 0 ) { |
---|
1601 | echo bbp_get_forum_author_display_name( $forum_id ); |
---|
1602 | } |
---|
1603 | /** |
---|
1604 | * Return the author of the forum |
---|
1605 | * |
---|
1606 | * @since bbPress (r3675) |
---|
1607 | * |
---|
1608 | * @param int $forum_id Optional. Forum id |
---|
1609 | * @uses bbp_get_forum_id() To get the forum id |
---|
1610 | * @uses bbp_get_forum_author_id() To get the forum author id |
---|
1611 | * @uses get_the_author_meta() To get the display name of the author |
---|
1612 | * @uses apply_filters() Calls 'bbp_get_forum_author' with the author |
---|
1613 | * and forum id |
---|
1614 | * @return string Author of forum |
---|
1615 | */ |
---|
1616 | function bbp_get_forum_author_display_name( $forum_id = 0 ) { |
---|
1617 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1618 | $author = get_the_author_meta( 'display_name', bbp_get_forum_author_id( $forum_id ) ); |
---|
1619 | |
---|
1620 | return apply_filters( 'bbp_get_forum_author_display_name', $author, $forum_id ); |
---|
1621 | } |
---|
1622 | |
---|
1623 | /** |
---|
1624 | * Output the author ID of the forum |
---|
1625 | * |
---|
1626 | * @since bbPress (r3675) |
---|
1627 | * |
---|
1628 | * @param int $forum_id Optional. Forum id |
---|
1629 | * @uses bbp_get_forum_author_id() To get the forum author id |
---|
1630 | */ |
---|
1631 | function bbp_forum_author_id( $forum_id = 0 ) { |
---|
1632 | echo bbp_get_forum_author_id( $forum_id ); |
---|
1633 | } |
---|
1634 | /** |
---|
1635 | * Return the author ID of the forum |
---|
1636 | * |
---|
1637 | * @since bbPress (r3675) |
---|
1638 | * |
---|
1639 | * @param int $forum_id Optional. Forum id |
---|
1640 | * @uses bbp_get_forum_id() To get the forum id |
---|
1641 | * @uses get_post_field() To get the forum author id |
---|
1642 | * @uses apply_filters() Calls 'bbp_get_forum_author_id' with the author |
---|
1643 | * id and forum id |
---|
1644 | * @return string Author of forum |
---|
1645 | */ |
---|
1646 | function bbp_get_forum_author_id( $forum_id = 0 ) { |
---|
1647 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1648 | $author_id = get_post_field( 'post_author', $forum_id ); |
---|
1649 | |
---|
1650 | return (int) apply_filters( 'bbp_get_forum_author_id', (int) $author_id, $forum_id ); |
---|
1651 | } |
---|
1652 | |
---|
1653 | /** |
---|
1654 | * Replace forum meta details for users that cannot view them. |
---|
1655 | * |
---|
1656 | * @since bbPress (r3162) |
---|
1657 | * |
---|
1658 | * @param string $retval |
---|
1659 | * @param int $forum_id |
---|
1660 | * |
---|
1661 | * @uses bbp_is_forum_private() |
---|
1662 | * @uses current_user_can() |
---|
1663 | * |
---|
1664 | * @return string |
---|
1665 | */ |
---|
1666 | function bbp_suppress_private_forum_meta( $retval, $forum_id ) { |
---|
1667 | if ( bbp_is_forum_private( $forum_id, false ) && !current_user_can( 'read_private_forums' ) ) |
---|
1668 | $retval = '-'; |
---|
1669 | |
---|
1670 | return apply_filters( 'bbp_suppress_private_forum_meta', $retval ); |
---|
1671 | } |
---|
1672 | |
---|
1673 | /** |
---|
1674 | * Replace forum author details for users that cannot view them. |
---|
1675 | * |
---|
1676 | * @since bbPress (r3162) |
---|
1677 | * |
---|
1678 | * @param string $retval |
---|
1679 | * @param int $forum_id |
---|
1680 | * |
---|
1681 | * @uses bbp_is_forum_private() |
---|
1682 | * @uses get_post_field() |
---|
1683 | * @uses bbp_get_topic_post_type() |
---|
1684 | * @uses bbp_is_forum_private() |
---|
1685 | * @uses bbp_get_topic_forum_id() |
---|
1686 | * @uses bbp_get_reply_post_type() |
---|
1687 | * @uses bbp_get_reply_forum_id() |
---|
1688 | * |
---|
1689 | * @return string |
---|
1690 | */ |
---|
1691 | function bbp_suppress_private_author_link( $author_link, $args ) { |
---|
1692 | |
---|
1693 | // Assume the author link is the return value |
---|
1694 | $retval = $author_link; |
---|
1695 | |
---|
1696 | // Show the normal author link |
---|
1697 | if ( !empty( $args['post_id'] ) && !current_user_can( 'read_private_forums' ) ) { |
---|
1698 | |
---|
1699 | // What post type are we looking at? |
---|
1700 | $post_type = get_post_field( 'post_type', $args['post_id'] ); |
---|
1701 | |
---|
1702 | switch ( $post_type ) { |
---|
1703 | |
---|
1704 | // Topic |
---|
1705 | case bbp_get_topic_post_type() : |
---|
1706 | if ( bbp_is_forum_private( bbp_get_topic_forum_id( $args['post_id'] ) ) ) |
---|
1707 | $retval = ''; |
---|
1708 | |
---|
1709 | break; |
---|
1710 | |
---|
1711 | // Reply |
---|
1712 | case bbp_get_reply_post_type() : |
---|
1713 | if ( bbp_is_forum_private( bbp_get_reply_forum_id( $args['post_id'] ) ) ) |
---|
1714 | $retval = ''; |
---|
1715 | |
---|
1716 | break; |
---|
1717 | |
---|
1718 | // Post |
---|
1719 | default : |
---|
1720 | if ( bbp_is_forum_private( $args['post_id'] ) ) |
---|
1721 | $retval = ''; |
---|
1722 | |
---|
1723 | break; |
---|
1724 | } |
---|
1725 | } |
---|
1726 | |
---|
1727 | return apply_filters( 'bbp_suppress_private_author_link', $retval ); |
---|
1728 | } |
---|
1729 | |
---|
1730 | /** |
---|
1731 | * Output the row class of a forum |
---|
1732 | * |
---|
1733 | * @since bbPress (r2667) |
---|
1734 | * |
---|
1735 | * @param int $forum_id Optional. Forum ID. |
---|
1736 | * @uses bbp_get_forum_class() To get the row class of the forum |
---|
1737 | */ |
---|
1738 | function bbp_forum_class( $forum_id = 0 ) { |
---|
1739 | echo bbp_get_forum_class( $forum_id ); |
---|
1740 | } |
---|
1741 | /** |
---|
1742 | * Return the row class of a forum |
---|
1743 | * |
---|
1744 | * @since bbPress (r2667) |
---|
1745 | * |
---|
1746 | * @param int $forum_id Optional. Forum ID |
---|
1747 | * @uses bbp_get_forum_id() To validate the forum id |
---|
1748 | * @uses bbp_is_forum_category() To see if forum is a category |
---|
1749 | * @uses bbp_get_forum_status() To get the forum status |
---|
1750 | * @uses bbp_get_forum_visibility() To get the forum visibility |
---|
1751 | * @uses bbp_get_forum_parent_id() To get the forum parent id |
---|
1752 | * @uses get_post_class() To get all the classes including ours |
---|
1753 | * @uses apply_filters() Calls 'bbp_get_forum_class' with the classes |
---|
1754 | * @return string Row class of the forum |
---|
1755 | */ |
---|
1756 | function bbp_get_forum_class( $forum_id = 0 ) { |
---|
1757 | $bbp = bbpress(); |
---|
1758 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1759 | $count = isset( $bbp->forum_query->current_post ) ? $bbp->forum_query->current_post : 1; |
---|
1760 | $classes = array(); |
---|
1761 | $classes[] = ( (int) $count % 2 ) ? 'even' : 'odd'; |
---|
1762 | $classes[] = bbp_is_forum_category( $forum_id ) ? 'status-category' : ''; |
---|
1763 | $classes[] = 'bbp-forum-status-' . bbp_get_forum_status( $forum_id ); |
---|
1764 | $classes[] = 'bbp-forum-visibility-' . bbp_get_forum_visibility( $forum_id ); |
---|
1765 | $classes[] = bbp_get_forum_parent_id( $forum_id ) ? 'bbp-parent-forum-' . bbp_get_forum_parent_id( $forum_id ) : ''; |
---|
1766 | $classes = array_filter( $classes ); |
---|
1767 | $classes = get_post_class( $classes, $forum_id ); |
---|
1768 | $classes = apply_filters( 'bbp_get_forum_class', $classes, $forum_id ); |
---|
1769 | $retval = 'class="' . join( ' ', $classes ) . '"'; |
---|
1770 | |
---|
1771 | return $retval; |
---|
1772 | } |
---|
1773 | |
---|
1774 | /** Single Forum **************************************************************/ |
---|
1775 | |
---|
1776 | /** |
---|
1777 | * Output a fancy description of the current forum, including total topics, |
---|
1778 | * total replies, and last activity. |
---|
1779 | * |
---|
1780 | * @since bbPress (r2860) |
---|
1781 | * |
---|
1782 | * @param array $args Arguments passed to alter output |
---|
1783 | * @uses bbp_get_single_forum_description() Return the eventual output |
---|
1784 | */ |
---|
1785 | function bbp_single_forum_description( $args = '' ) { |
---|
1786 | echo bbp_get_single_forum_description( $args ); |
---|
1787 | } |
---|
1788 | /** |
---|
1789 | * Return a fancy description of the current forum, including total |
---|
1790 | * topics, total replies, and last activity. |
---|
1791 | * |
---|
1792 | * @since bbPress (r2860) |
---|
1793 | * |
---|
1794 | * @param mixed $args This function supports these arguments: |
---|
1795 | * - forum_id: Forum id |
---|
1796 | * - before: Before the text |
---|
1797 | * - after: After the text |
---|
1798 | * - size: Size of the avatar |
---|
1799 | * @uses bbp_get_forum_id() To get the forum id |
---|
1800 | * @uses bbp_get_forum_topic_count() To get the forum topic count |
---|
1801 | * @uses bbp_get_forum_reply_count() To get the forum reply count |
---|
1802 | * @uses bbp_get_forum_subforum_count() To get the forum subforum count |
---|
1803 | * @uses bbp_get_forum_freshness_link() To get the forum freshness link |
---|
1804 | * @uses bbp_get_forum_last_active_id() To get the forum last active id |
---|
1805 | * @uses bbp_get_author_link() To get the author link |
---|
1806 | * @uses add_filter() To add the 'view all' filter back |
---|
1807 | * @uses apply_filters() Calls 'bbp_get_single_forum_description' with |
---|
1808 | * the description and args |
---|
1809 | * @return string Filtered forum description |
---|
1810 | */ |
---|
1811 | function bbp_get_single_forum_description( $args = '' ) { |
---|
1812 | |
---|
1813 | // Default arguments |
---|
1814 | $defaults = array ( |
---|
1815 | 'forum_id' => 0, |
---|
1816 | 'before' => '<div class="bbp-template-notice info"><p class="bbp-forum-content">', |
---|
1817 | 'after' => '</p></div>', |
---|
1818 | 'size' => 14, |
---|
1819 | 'feed' => true |
---|
1820 | ); |
---|
1821 | $r = wp_parse_args( $args, $defaults ); |
---|
1822 | extract( $r ); |
---|
1823 | |
---|
1824 | // Validate forum_id |
---|
1825 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
1826 | |
---|
1827 | // Unhook the 'view all' query var adder |
---|
1828 | remove_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' ); |
---|
1829 | |
---|
1830 | // Build the forum description |
---|
1831 | $topic_count = bbp_get_forum_topics_link ( $forum_id ); |
---|
1832 | $reply_count = bbp_get_forum_reply_count ( $forum_id ); |
---|
1833 | $time_since = bbp_get_forum_freshness_link( $forum_id ); |
---|
1834 | |
---|
1835 | // Singlular/Plural |
---|
1836 | $reply_count = sprintf( _n( '%s reply', '%s replies', $reply_count, 'bbpress' ), $reply_count ); |
---|
1837 | |
---|
1838 | // Forum has posts |
---|
1839 | $last_reply = bbp_get_forum_last_active_id( $forum_id ); |
---|
1840 | if ( !empty( $last_reply ) ) { |
---|
1841 | |
---|
1842 | // Freshness author |
---|
1843 | $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_reply, 'size' => $size ) ); |
---|
1844 | |
---|
1845 | // Category |
---|
1846 | if ( bbp_is_forum_category( $forum_id ) ) { |
---|
1847 | $retstr = sprintf( __( 'This category contains %1$s and %2$s, and was last updated by %3$s %4$s ago.', 'bbpress' ), $topic_count, $reply_count, $last_updated_by, $time_since ); |
---|
1848 | |
---|
1849 | // Forum |
---|
1850 | } else { |
---|
1851 | $retstr = sprintf( __( 'This forum contains %1$s and %2$s, and was last updated by %3$s %4$s ago.', 'bbpress' ), $topic_count, $reply_count, $last_updated_by, $time_since ); |
---|
1852 | } |
---|
1853 | |
---|
1854 | // Forum has no last active data |
---|
1855 | } else { |
---|
1856 | |
---|
1857 | // Category |
---|
1858 | if ( bbp_is_forum_category( $forum_id ) ) { |
---|
1859 | $retstr = sprintf( __( 'This category contains %1$s and %2$s.', 'bbpress' ), $topic_count, $reply_count ); |
---|
1860 | |
---|
1861 | // Forum |
---|
1862 | } else { |
---|
1863 | $retstr = sprintf( __( 'This forum contains %1$s and %2$s.', 'bbpress' ), $topic_count, $reply_count ); |
---|
1864 | } |
---|
1865 | } |
---|
1866 | |
---|
1867 | // Add feeds |
---|
1868 | //$feed_links = ( !empty( $feed ) ) ? bbp_get_forum_topics_feed_link ( $forum_id ) . bbp_get_forum_replies_feed_link( $forum_id ) : ''; |
---|
1869 | |
---|
1870 | // Add the 'view all' filter back |
---|
1871 | add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' ); |
---|
1872 | |
---|
1873 | // Combine the elements together |
---|
1874 | $retstr = $before . $retstr . $after; |
---|
1875 | |
---|
1876 | // Return filtered result |
---|
1877 | return apply_filters( 'bbp_get_single_forum_description', $retstr, $args ); |
---|
1878 | } |
---|
1879 | |
---|
1880 | /** Forms *********************************************************************/ |
---|
1881 | |
---|
1882 | /** |
---|
1883 | * Output the value of forum title field |
---|
1884 | * |
---|
1885 | * @since bbPress (r3551) |
---|
1886 | * |
---|
1887 | * @uses bbp_get_form_forum_title() To get the value of forum title field |
---|
1888 | */ |
---|
1889 | function bbp_form_forum_title() { |
---|
1890 | echo bbp_get_form_forum_title(); |
---|
1891 | } |
---|
1892 | /** |
---|
1893 | * Return the value of forum title field |
---|
1894 | * |
---|
1895 | * @since bbPress (r3551) |
---|
1896 | * |
---|
1897 | * @uses bbp_is_forum_edit() To check if it's forum edit page |
---|
1898 | * @uses apply_filters() Calls 'bbp_get_form_forum_title' with the title |
---|
1899 | * @return string Value of forum title field |
---|
1900 | */ |
---|
1901 | function bbp_get_form_forum_title() { |
---|
1902 | |
---|
1903 | // Get _POST data |
---|
1904 | if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_forum_title'] ) ) |
---|
1905 | $forum_title = $_POST['bbp_forum_title']; |
---|
1906 | |
---|
1907 | // Get edit data |
---|
1908 | elseif ( bbp_is_forum_edit() ) |
---|
1909 | $forum_title = bbp_get_global_post_field( 'post_title', 'raw' ); |
---|
1910 | |
---|
1911 | // No data |
---|
1912 | else |
---|
1913 | $forum_title = ''; |
---|
1914 | |
---|
1915 | return apply_filters( 'bbp_get_form_forum_title', esc_attr( $forum_title ) ); |
---|
1916 | } |
---|
1917 | |
---|
1918 | /** |
---|
1919 | * Output the value of forum content field |
---|
1920 | * |
---|
1921 | * @since bbPress (r3551) |
---|
1922 | * |
---|
1923 | * @uses bbp_get_form_forum_content() To get value of forum content field |
---|
1924 | */ |
---|
1925 | function bbp_form_forum_content() { |
---|
1926 | echo bbp_get_form_forum_content(); |
---|
1927 | } |
---|
1928 | /** |
---|
1929 | * Return the value of forum content field |
---|
1930 | * |
---|
1931 | * @since bbPress (r3551) |
---|
1932 | * |
---|
1933 | * @uses bbp_is_forum_edit() To check if it's the forum edit page |
---|
1934 | * @uses apply_filters() Calls 'bbp_get_form_forum_content' with the content |
---|
1935 | * @return string Value of forum content field |
---|
1936 | */ |
---|
1937 | function bbp_get_form_forum_content() { |
---|
1938 | |
---|
1939 | // Get _POST data |
---|
1940 | if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_forum_content'] ) ) |
---|
1941 | $forum_content = $_POST['bbp_forum_content']; |
---|
1942 | |
---|
1943 | // Get edit data |
---|
1944 | elseif ( bbp_is_forum_edit() ) |
---|
1945 | $forum_content = bbp_get_global_post_field( 'post_content', 'raw' ); |
---|
1946 | |
---|
1947 | // No data |
---|
1948 | else |
---|
1949 | $forum_content = ''; |
---|
1950 | |
---|
1951 | return apply_filters( 'bbp_get_form_forum_content', esc_textarea( $forum_content ) ); |
---|
1952 | } |
---|
1953 | |
---|
1954 | /** |
---|
1955 | * Output value of forum parent |
---|
1956 | * |
---|
1957 | * @since bbPress (r3551) |
---|
1958 | * |
---|
1959 | * @uses bbp_get_form_forum_parent() To get the topic's forum id |
---|
1960 | */ |
---|
1961 | function bbp_form_forum_parent() { |
---|
1962 | echo bbp_get_form_forum_parent(); |
---|
1963 | } |
---|
1964 | /** |
---|
1965 | * Return value of forum parent |
---|
1966 | * |
---|
1967 | * @since bbPress (r3551) |
---|
1968 | * |
---|
1969 | * @uses bbp_is_topic_edit() To check if it's the topic edit page |
---|
1970 | * @uses bbp_get_forum_parent_id() To get the topic forum id |
---|
1971 | * @uses apply_filters() Calls 'bbp_get_form_forum_parent' with the forum |
---|
1972 | * @return string Value of topic content field |
---|
1973 | */ |
---|
1974 | function bbp_get_form_forum_parent() { |
---|
1975 | |
---|
1976 | // Get _POST data |
---|
1977 | if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_forum_id'] ) ) |
---|
1978 | $forum_parent = $_POST['bbp_forum_id']; |
---|
1979 | |
---|
1980 | // Get edit data |
---|
1981 | elseif ( bbp_is_forum_edit() ) |
---|
1982 | $forum_parent = bbp_get_forum_parent_id(); |
---|
1983 | |
---|
1984 | // No data |
---|
1985 | else |
---|
1986 | $forum_parent = 0; |
---|
1987 | |
---|
1988 | return apply_filters( 'bbp_get_form_forum_parent', esc_attr( $forum_parent ) ); |
---|
1989 | } |
---|
1990 | |
---|
1991 | /** |
---|
1992 | * Output value of forum type |
---|
1993 | * |
---|
1994 | * @since bbPress (r3563) |
---|
1995 | * |
---|
1996 | * @uses bbp_get_form_forum_type() To get the topic's forum id |
---|
1997 | */ |
---|
1998 | function bbp_form_forum_type() { |
---|
1999 | echo bbp_get_form_forum_type(); |
---|
2000 | } |
---|
2001 | /** |
---|
2002 | * Return value of forum type |
---|
2003 | * |
---|
2004 | * @since bbPress (r3563) |
---|
2005 | * |
---|
2006 | * @uses bbp_is_topic_edit() To check if it's the topic edit page |
---|
2007 | * @uses bbp_get_forum_type_id() To get the topic forum id |
---|
2008 | * @uses apply_filters() Calls 'bbp_get_form_forum_type' with the forum |
---|
2009 | * @return string Value of topic content field |
---|
2010 | */ |
---|
2011 | function bbp_get_form_forum_type() { |
---|
2012 | |
---|
2013 | // Get _POST data |
---|
2014 | if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_forum_type'] ) ) |
---|
2015 | $forum_type = $_POST['bbp_forum_type']; |
---|
2016 | |
---|
2017 | // Get edit data |
---|
2018 | elseif ( bbp_is_forum_edit() ) |
---|
2019 | $forum_type = bbp_get_forum_type(); |
---|
2020 | |
---|
2021 | // No data |
---|
2022 | else |
---|
2023 | $forum_type = 'forum'; |
---|
2024 | |
---|
2025 | return apply_filters( 'bbp_get_form_forum_type', esc_attr( $forum_type ) ); |
---|
2026 | } |
---|
2027 | |
---|
2028 | /** |
---|
2029 | * Output value of forum visibility |
---|
2030 | * |
---|
2031 | * @since bbPress (r3563) |
---|
2032 | * |
---|
2033 | * @uses bbp_get_form_forum_visibility() To get the topic's forum id |
---|
2034 | */ |
---|
2035 | function bbp_form_forum_visibility() { |
---|
2036 | echo bbp_get_form_forum_visibility(); |
---|
2037 | } |
---|
2038 | /** |
---|
2039 | * Return value of forum visibility |
---|
2040 | * |
---|
2041 | * @since bbPress (r3563) |
---|
2042 | * |
---|
2043 | * @uses bbp_is_topic_edit() To check if it's the topic edit page |
---|
2044 | * @uses bbp_get_forum_visibility_id() To get the topic forum id |
---|
2045 | * @uses apply_filters() Calls 'bbp_get_form_forum_visibility' with the forum |
---|
2046 | * @return string Value of topic content field |
---|
2047 | */ |
---|
2048 | function bbp_get_form_forum_visibility() { |
---|
2049 | |
---|
2050 | // Get _POST data |
---|
2051 | if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_forum_visibility'] ) ) |
---|
2052 | $forum_visibility = $_POST['bbp_forum_visibility']; |
---|
2053 | |
---|
2054 | // Get edit data |
---|
2055 | elseif ( bbp_is_forum_edit() ) |
---|
2056 | $forum_visibility = bbp_get_forum_visibility(); |
---|
2057 | |
---|
2058 | // No data |
---|
2059 | else |
---|
2060 | $forum_visibility = bbpress()->public_status_id; |
---|
2061 | |
---|
2062 | return apply_filters( 'bbp_get_form_forum_visibility', esc_attr( $forum_visibility ) ); |
---|
2063 | } |
---|
2064 | |
---|
2065 | /** Form Dropdows *************************************************************/ |
---|
2066 | |
---|
2067 | /** |
---|
2068 | * Output value forum type dropdown |
---|
2069 | * |
---|
2070 | * @since bbPress (r3563) |
---|
2071 | * |
---|
2072 | * @param int $forum_id The forum id to use |
---|
2073 | * @uses bbp_get_form_forum_type() To get the topic's forum id |
---|
2074 | */ |
---|
2075 | function bbp_form_forum_type_dropdown( $forum_id = 0 ) { |
---|
2076 | echo bbp_get_form_forum_type_dropdown( $forum_id ); |
---|
2077 | } |
---|
2078 | /** |
---|
2079 | * Return the forum type dropdown |
---|
2080 | * |
---|
2081 | * @since bbPress (r3563) |
---|
2082 | * |
---|
2083 | * @param int $forum_id The forum id to use |
---|
2084 | * @uses bbp_is_topic_edit() To check if it's the topic edit page |
---|
2085 | * @uses bbp_get_forum_type() To get the forum type |
---|
2086 | * @uses apply_filters() |
---|
2087 | * @return string HTML select list for selecting forum type |
---|
2088 | */ |
---|
2089 | function bbp_get_form_forum_type_dropdown( $forum_id = 0 ) { |
---|
2090 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
2091 | $forum_attr = apply_filters( 'bbp_forum_types', array( |
---|
2092 | 'forum' => __( 'Forum', 'bbpress' ), |
---|
2093 | 'category' => __( 'Category', 'bbpress' ) |
---|
2094 | ) ); |
---|
2095 | $type_output = '<select name="bbp_forum_type" id="bbp_forum_type_select">' . "\n"; |
---|
2096 | |
---|
2097 | foreach( $forum_attr as $value => $label ) |
---|
2098 | $type_output .= "\t" . '<option value="' . $value . '"' . selected( bbp_get_forum_type( $forum_id ), $value, false ) . '>' . esc_html( $label ) . '</option>' . "\n"; |
---|
2099 | |
---|
2100 | $type_output .= '</select>'; |
---|
2101 | |
---|
2102 | return apply_filters( 'bbp_get_form_forum_type_dropdown', $type_output, $forum_id, $forum_attr ); |
---|
2103 | } |
---|
2104 | |
---|
2105 | /** |
---|
2106 | * Output value forum status dropdown |
---|
2107 | * |
---|
2108 | * @since bbPress (r3563) |
---|
2109 | * |
---|
2110 | * @param int $forum_id The forum id to use |
---|
2111 | * @uses bbp_get_form_forum_status() To get the topic's forum id |
---|
2112 | */ |
---|
2113 | function bbp_form_forum_status_dropdown( $forum_id = 0 ) { |
---|
2114 | echo bbp_get_form_forum_status_dropdown( $forum_id ); |
---|
2115 | } |
---|
2116 | /** |
---|
2117 | * Return the forum status dropdown |
---|
2118 | * |
---|
2119 | * @since bbPress (r3563) |
---|
2120 | * |
---|
2121 | * @param int $forum_id The forum id to use |
---|
2122 | * @uses bbp_is_topic_edit() To check if it's the topic edit page |
---|
2123 | * @uses bbp_get_forum_status() To get the forum status |
---|
2124 | * @uses apply_filters() |
---|
2125 | * @return string HTML select list for selecting forum status |
---|
2126 | */ |
---|
2127 | function bbp_get_form_forum_status_dropdown( $forum_id = 0 ) { |
---|
2128 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
2129 | $forum_attr = apply_filters( 'bbp_forum_statuses', array( |
---|
2130 | 'open' => _x( 'Open', 'Forum Status', 'bbpress' ), |
---|
2131 | 'closed' => _x( 'Closed', 'Forum Status', 'bbpress' ) |
---|
2132 | ) ); |
---|
2133 | $status_output = '<select name="bbp_forum_status" id="bbp_forum_status_select">' . "\n"; |
---|
2134 | |
---|
2135 | foreach( $forum_attr as $value => $label ) |
---|
2136 | $status_output .= "\t" . '<option value="' . $value . '"' . selected( bbp_get_forum_status( $forum_id ), $value, false ) . '>' . esc_html( $label ) . '</option>' . "\n"; |
---|
2137 | |
---|
2138 | $status_output .= '</select>'; |
---|
2139 | |
---|
2140 | return apply_filters( 'bbp_get_form_forum_status_dropdown', $status_output, $forum_id, $forum_attr ); |
---|
2141 | } |
---|
2142 | |
---|
2143 | /** |
---|
2144 | * Output value forum visibility dropdown |
---|
2145 | * |
---|
2146 | * @since bbPress (r3563) |
---|
2147 | * |
---|
2148 | * @param int $forum_id The forum id to use |
---|
2149 | * @uses bbp_get_form_forum_visibility() To get the topic's forum id |
---|
2150 | */ |
---|
2151 | function bbp_form_forum_visibility_dropdown( $forum_id = 0 ) { |
---|
2152 | echo bbp_get_form_forum_visibility_dropdown( $forum_id ); |
---|
2153 | } |
---|
2154 | /** |
---|
2155 | * Return the forum visibility dropdown |
---|
2156 | * |
---|
2157 | * @since bbPress (r3563) |
---|
2158 | * |
---|
2159 | * @param int $forum_id The forum id to use |
---|
2160 | * @uses bbp_is_topic_edit() To check if it's the topic edit page |
---|
2161 | * @uses bbp_get_forum_visibility() To get the forum visibility |
---|
2162 | * @uses apply_filters() |
---|
2163 | * @return string HTML select list for selecting forum visibility |
---|
2164 | */ |
---|
2165 | function bbp_get_form_forum_visibility_dropdown( $forum_id = 0 ) { |
---|
2166 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
2167 | $forum_attr = apply_filters( 'bbp_forum_visibilities', array( |
---|
2168 | bbp_get_public_status_id() => __( 'Public', 'bbpress' ), |
---|
2169 | bbp_get_private_status_id() => __( 'Private', 'bbpress' ), |
---|
2170 | bbp_get_hidden_status_id() => __( 'Hidden', 'bbpress' ) |
---|
2171 | ) ); |
---|
2172 | $visibility_output = '<select name="bbp_forum_visibility" id="bbp_forum_visibility_select">' . "\n"; |
---|
2173 | |
---|
2174 | foreach( $forum_attr as $value => $label ) |
---|
2175 | $visibility_output .= "\t" . '<option value="' . $value . '"' . selected( bbp_get_forum_visibility( $forum_id ), $value, false ) . '>' . esc_html( $label ) . '</option>' . "\n"; |
---|
2176 | |
---|
2177 | $visibility_output .= '</select>'; |
---|
2178 | |
---|
2179 | return apply_filters( 'bbp_get_form_forum_visibility_dropdown', $visibility_output, $forum_id, $forum_attr ); |
---|
2180 | } |
---|
2181 | |
---|
2182 | /** Feeds *********************************************************************/ |
---|
2183 | |
---|
2184 | /** |
---|
2185 | * Output the link for the forum feed |
---|
2186 | * |
---|
2187 | * @since bbPress (r3172) |
---|
2188 | * |
---|
2189 | * @param type $forum_id Optional. Forum ID. |
---|
2190 | * |
---|
2191 | * @uses bbp_get_forum_topics_feed_link() |
---|
2192 | */ |
---|
2193 | function bbp_forum_topics_feed_link( $forum_id = 0 ) { |
---|
2194 | echo bbp_get_forum_topics_feed_link( $forum_id ); |
---|
2195 | } |
---|
2196 | /** |
---|
2197 | * Retrieve the link for the forum feed |
---|
2198 | * |
---|
2199 | * @since bbPress (r3172) |
---|
2200 | * |
---|
2201 | * @param int $forum_id Optional. Forum ID. |
---|
2202 | * |
---|
2203 | * @uses bbp_get_forum_id() |
---|
2204 | * @uses get_option() |
---|
2205 | * @uses trailingslashit() |
---|
2206 | * @uses bbp_get_forum_permalink() |
---|
2207 | * @uses user_trailingslashit() |
---|
2208 | * @uses bbp_get_forum_post_type() |
---|
2209 | * @uses get_post_field() |
---|
2210 | * @uses apply_filters() |
---|
2211 | * |
---|
2212 | * @return string |
---|
2213 | */ |
---|
2214 | function bbp_get_forum_topics_feed_link( $forum_id = 0 ) { |
---|
2215 | |
---|
2216 | // Validate forum id |
---|
2217 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
2218 | |
---|
2219 | // Forum is valid |
---|
2220 | if ( !empty( $forum_id ) ) { |
---|
2221 | |
---|
2222 | // Define local variable(s) |
---|
2223 | $link = ''; |
---|
2224 | |
---|
2225 | // Pretty permalinks |
---|
2226 | if ( get_option( 'permalink_structure' ) ) { |
---|
2227 | |
---|
2228 | // Forum link |
---|
2229 | $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed'; |
---|
2230 | $url = user_trailingslashit( $url, 'single_feed' ); |
---|
2231 | |
---|
2232 | // Unpretty permalinks |
---|
2233 | } else { |
---|
2234 | $url = home_url( add_query_arg( array( |
---|
2235 | 'feed' => 'rss2', |
---|
2236 | bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id ) |
---|
2237 | ) ) ); |
---|
2238 | } |
---|
2239 | |
---|
2240 | $link = '<a href="' . $url . '" class="bbp-forum-rss-link topics"><span>' . __( 'Topics', 'bbpress' ) . '</span></a>'; |
---|
2241 | } |
---|
2242 | |
---|
2243 | return apply_filters( 'bbp_get_forum_topics_feed_link', $link, $url, $forum_id ); |
---|
2244 | } |
---|
2245 | |
---|
2246 | /** |
---|
2247 | * Output the link for the forum replies feed |
---|
2248 | * |
---|
2249 | * @since bbPress (r3172) |
---|
2250 | * |
---|
2251 | * @param type $forum_id Optional. Forum ID. |
---|
2252 | * |
---|
2253 | * @uses bbp_get_forum_replies_feed_link() |
---|
2254 | */ |
---|
2255 | function bbp_forum_replies_feed_link( $forum_id = 0 ) { |
---|
2256 | echo bbp_get_forum_replies_feed_link( $forum_id ); |
---|
2257 | } |
---|
2258 | /** |
---|
2259 | * Retrieve the link for the forum replies feed |
---|
2260 | * |
---|
2261 | * @since bbPress (r3172) |
---|
2262 | * |
---|
2263 | * @param int $forum_id Optional. Forum ID. |
---|
2264 | * |
---|
2265 | * @uses bbp_get_forum_id() |
---|
2266 | * @uses get_option() |
---|
2267 | * @uses trailingslashit() |
---|
2268 | * @uses bbp_get_forum_permalink() |
---|
2269 | * @uses user_trailingslashit() |
---|
2270 | * @uses bbp_get_forum_post_type() |
---|
2271 | * @uses get_post_field() |
---|
2272 | * @uses apply_filters() |
---|
2273 | * |
---|
2274 | * @return string |
---|
2275 | */ |
---|
2276 | function bbp_get_forum_replies_feed_link( $forum_id = 0 ) { |
---|
2277 | |
---|
2278 | // Validate forum id |
---|
2279 | $forum_id = bbp_get_forum_id( $forum_id ); |
---|
2280 | |
---|
2281 | // Forum is valid |
---|
2282 | if ( !empty( $forum_id ) ) { |
---|
2283 | |
---|
2284 | // Define local variable(s) |
---|
2285 | $link = ''; |
---|
2286 | |
---|
2287 | // Pretty permalinks |
---|
2288 | if ( get_option( 'permalink_structure' ) ) { |
---|
2289 | |
---|
2290 | // Forum link |
---|
2291 | $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed'; |
---|
2292 | $url = user_trailingslashit( $url, 'single_feed' ); |
---|
2293 | $url = add_query_arg( array( 'type' => 'reply' ), $url ); |
---|
2294 | |
---|
2295 | // Unpretty permalinks |
---|
2296 | } else { |
---|
2297 | $url = home_url( add_query_arg( array( |
---|
2298 | 'type' => 'reply', |
---|
2299 | 'feed' => 'rss2', |
---|
2300 | bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id ) |
---|
2301 | ) ) ); |
---|
2302 | } |
---|
2303 | |
---|
2304 | $link = '<a href="' . $url . '" class="bbp-forum-rss-link replies"><span>' . __( 'Replies', 'bbpress' ) . '</span></a>'; |
---|
2305 | } |
---|
2306 | |
---|
2307 | return apply_filters( 'bbp_get_forum_replies_feed_link', $link, $url, $forum_id ); |
---|
2308 | } |
---|
2309 | |
---|
2310 | ?> |
---|