PluginProbe
bbPress / 2.6.6
bbPress v2.6.6
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
← All changes | includes/forums/template.php +1346 -1479 trunk2.6.6 View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2
3 3 /**
4 - * bbPress Forum Template Tags.
4 + * bbPress Forum Template Tags
5 5 *
6 6 * @package bbPress
7 7 * @subpackage TemplateTags
8 8 */
@@ -12,9 +12,9 @@
12 12
13 13 /** Post Type *****************************************************************/
14 14
15 15 /**
16 - * Output the unique id of the custom post type for forums.
16 + * Output the unique id of the custom post type for forums
17 17 *
18 18 * @since 2.0.0 bbPress (r2857)
19 19 */
20 20 function bbp_forum_post_type() {
@@ -19,24 +19,24 @@
19 19 */
20 20 function bbp_forum_post_type() {
21 21 echo bbp_get_forum_post_type();
22 22 }
23 + /**
24 + * Return the unique id of the custom post type for forums
25 + *
26 + * @since 2.0.0 bbPress (r2857)
27 + *
28 + * @return string The unique forum post type id
29 + */
30 + function bbp_get_forum_post_type() {
23 31
24 -/**
25 - * Return the unique id of the custom post type for forums.
26 - *
27 - * @since 2.0.0 bbPress (r2857)
28 - *
29 - * @return string The unique forum post type id.
30 - */
31 -function bbp_get_forum_post_type() {
32 + // Filter & return
33 + return apply_filters( 'bbp_get_forum_post_type', bbpress()->forum_post_type );
34 + }
32 35
33 - // Filter & return
34 - return apply_filters( 'bbp_get_forum_post_type', bbpress()->forum_post_type );
35 -}
36 36
37 37 /**
38 - * Return array of labels used by the forum post type.
38 + * Return array of labels used by the forum post type
39 39 *
40 40 * @since 2.5.0 bbPress (r5129)
41 41 *
42 42 * @return array
@@ -43,49 +43,46 @@
43 43 */
44 44 function bbp_get_forum_post_type_labels() {
45 45
46 46 // Filter & return
47 - return (array) apply_filters(
48 - 'bbp_get_forum_post_type_labels',
49 - array(
50 - 'name' => esc_attr__( 'Forums', 'bbpress' ),
51 - 'menu_name' => esc_attr__( 'Forums', 'bbpress' ),
52 - 'singular_name' => esc_attr__( 'Forum', 'bbpress' ),
53 - 'all_items' => esc_attr__( 'All Forums', 'bbpress' ),
54 - 'add_new' => esc_attr__( 'Add New', 'bbpress' ),
55 - 'add_new_item' => esc_attr__( 'Add Forum', 'bbpress' ),
56 - 'edit' => esc_attr__( 'Edit', 'bbpress' ),
57 - 'edit_item' => esc_attr__( 'Edit Forum', 'bbpress' ),
58 - 'new_item' => esc_attr__( 'New Forum', 'bbpress' ),
59 - 'view' => esc_attr__( 'View Forum', 'bbpress' ),
60 - 'view_item' => esc_attr__( 'View Forum', 'bbpress' ),
61 - 'view_items' => esc_attr__( 'View Forums', 'bbpress' ),
62 - 'search_items' => esc_attr__( 'Search Forums', 'bbpress' ),
63 - 'not_found' => esc_attr__( 'No forums found', 'bbpress' ),
64 - 'not_found_in_trash' => esc_attr__( 'No forums found in Trash', 'bbpress' ),
65 - 'filter_items_list' => esc_attr__( 'Filter forums list', 'bbpress' ),
66 - 'items_list' => esc_attr__( 'Forums list', 'bbpress' ),
67 - 'items_list_navigation' => esc_attr__( 'Forums list navigation', 'bbpress' ),
68 - 'parent_item_colon' => esc_attr__( 'Parent Forum:', 'bbpress' ),
69 - 'archives' => esc_attr__( 'Forums', 'bbpress' ),
70 - 'attributes' => esc_attr__( 'Forum Attributes', 'bbpress' ),
71 - 'insert_into_item' => esc_attr__( 'Insert into forum', 'bbpress' ),
72 - 'uploaded_to_this_item' => esc_attr__( 'Uploaded to this forum', 'bbpress' ),
73 - 'featured_image' => esc_attr__( 'Forum Image', 'bbpress' ),
74 - 'set_featured_image' => esc_attr__( 'Set forum image', 'bbpress' ),
75 - 'remove_featured_image' => esc_attr__( 'Remove forum image', 'bbpress' ),
76 - 'use_featured_image' => esc_attr__( 'Use as forum image', 'bbpress' ),
77 - 'item_published' => esc_attr__( 'Forum published.', 'bbpress' ),
78 - 'item_published_privately' => esc_attr__( 'Forum published privately.', 'bbpress' ),
79 - 'item_reverted_to_draft' => esc_attr__( 'Forum reverted to draft.', 'bbpress' ),
80 - 'item_scheduled' => esc_attr__( 'Forum scheduled.', 'bbpress' ),
81 - 'item_updated' => esc_attr__( 'Forum updated.', 'bbpress' )
82 - )
83 - );
47 + return (array) apply_filters( 'bbp_get_forum_post_type_labels', array(
48 + 'name' => esc_attr__( 'Forums', 'bbpress' ),
49 + 'menu_name' => esc_attr__( 'Forums', 'bbpress' ),
50 + 'singular_name' => esc_attr__( 'Forum', 'bbpress' ),
51 + 'all_items' => esc_attr__( 'All Forums', 'bbpress' ),
52 + 'add_new' => esc_attr__( 'Add New', 'bbpress' ),
53 + 'add_new_item' => esc_attr__( 'Create New Forum', 'bbpress' ),
54 + 'edit' => esc_attr__( 'Edit', 'bbpress' ),
55 + 'edit_item' => esc_attr__( 'Edit Forum', 'bbpress' ),
56 + 'new_item' => esc_attr__( 'New Forum', 'bbpress' ),
57 + 'view' => esc_attr__( 'View Forum', 'bbpress' ),
58 + 'view_item' => esc_attr__( 'View Forum', 'bbpress' ),
59 + 'view_items' => esc_attr__( 'View Forums', 'bbpress' ),
60 + 'search_items' => esc_attr__( 'Search Forums', 'bbpress' ),
61 + 'not_found' => esc_attr__( 'No forums found', 'bbpress' ),
62 + 'not_found_in_trash' => esc_attr__( 'No forums found in Trash', 'bbpress' ),
63 + 'filter_items_list' => esc_attr__( 'Filter forums list', 'bbpress' ),
64 + 'items_list' => esc_attr__( 'Forums list', 'bbpress' ),
65 + 'items_list_navigation' => esc_attr__( 'Forums list navigation', 'bbpress' ),
66 + 'parent_item_colon' => esc_attr__( 'Parent Forum:', 'bbpress' ),
67 + 'archives' => esc_attr__( 'Forums', 'bbpress' ),
68 + 'attributes' => esc_attr__( 'Forum Attributes', 'bbpress' ),
69 + 'insert_into_item' => esc_attr__( 'Insert into forum', 'bbpress' ),
70 + 'uploaded_to_this_item' => esc_attr__( 'Uploaded to this forum', 'bbpress' ),
71 + 'featured_image' => esc_attr__( 'Forum Image', 'bbpress' ),
72 + 'set_featured_image' => esc_attr__( 'Set forum image', 'bbpress' ),
73 + 'remove_featured_image' => esc_attr__( 'Remove forum image', 'bbpress' ),
74 + 'use_featured_image' => esc_attr__( 'Use as forum image', 'bbpress' ),
75 + 'item_published' => esc_attr__( 'Forum published.', 'bbpress' ),
76 + 'item_published_privately' => esc_attr__( 'Forum published privately.', 'bbpress' ),
77 + 'item_reverted_to_draft' => esc_attr__( 'Forum reverted to draft.', 'bbpress' ),
78 + 'item_scheduled' => esc_attr__( 'Forum scheduled.', 'bbpress' ),
79 + 'item_updated' => esc_attr__( 'Forum updated.', 'bbpress' )
80 + ) );
84 81 }
85 82
86 83 /**
87 - * Return array of forum post type rewrite settings.
84 + * Return array of forum post type rewrite settings
88 85 *
89 86 * @since 2.5.0 bbPress (r5129)
90 87 *
91 88 * @return array
@@ -92,19 +89,16 @@
92 89 */
93 90 function bbp_get_forum_post_type_rewrite() {
94 91
95 92 // Filter & return
96 - return (array) apply_filters(
97 - 'bbp_get_forum_post_type_rewrite',
98 - array(
99 - 'slug' => bbp_get_forum_slug(),
100 - 'with_front' => false
101 - )
102 - );
93 + return (array) apply_filters( 'bbp_get_forum_post_type_rewrite', array(
94 + 'slug' => bbp_get_forum_slug(),
95 + 'with_front' => false
96 + ) );
103 97 }
104 98
105 99 /**
106 - * Return array of features the forum post type supports.
100 + * Return array of features the forum post type supports
107 101 *
108 102 * @since 2.5.0 bbPress (r5129)
109 103 *
110 104 * @return array
@@ -111,16 +105,13 @@
111 105 */
112 106 function bbp_get_forum_post_type_supports() {
113 107
114 108 // Filter & return
115 - return (array) apply_filters(
116 - 'bbp_get_forum_post_type_supports',
117 - array(
118 - 'title',
119 - 'editor',
120 - 'revisions'
121 - )
122 - );
109 + return (array) apply_filters( 'bbp_get_forum_post_type_supports', array(
110 + 'title',
111 + 'editor',
112 + 'revisions'
113 + ) );
123 114 }
124 115
125 116 /** Forum Loop ****************************************************************/
126 117
@@ -132,9 +123,9 @@
132 123 * @since 2.0.0 bbPress (r2464)
133 124 *
134 125 * @param array $args All the arguments supported by {@link WP_Query}
135 126 *
136 - * @return object Multidimensional array of forum information.
127 + * @return object Multidimensional array of forum information
137 128 */
138 129 function bbp_has_forums( $args = array() ) {
139 130
140 131 // Forum archive only shows root
@@ -189,13 +180,13 @@
189 180 return apply_filters( 'bbp_has_forums', $bbp->forum_query->have_posts(), $bbp->forum_query );
190 181 }
191 182
192 183 /**
193 - * Whether there are more forums available in the loop.
184 + * Whether there are more forums available in the loop
194 185 *
195 186 * @since 2.0.0 bbPress (r2464)
196 187 *
197 - * @return object Forum information.
188 + * @return object Forum information
198 189 */
199 190 function bbp_forums() {
200 191
201 192 // Put into variable to check against next
@@ -209,13 +200,13 @@
209 200 return $have_posts;
210 201 }
211 202
212 203 /**
213 - * Loads up the current forum in the loop.
204 + * Loads up the current forum in the loop
214 205 *
215 206 * @since 2.0.0 bbPress (r2464)
216 207 *
217 - * @return object Forum information.
208 + * @return object Forum information
218 209 */
219 210 function bbp_the_forum() {
220 211 return bbpress()->forum_query->the_post();
221 212 }
@@ -222,73 +213,72 @@
222 213
223 214 /** Forum *********************************************************************/
224 215
225 216 /**
226 - * Output forum id.
217 + * Output forum id
227 218 *
228 219 * @since 2.0.0 bbPress (r2464)
229 220 *
230 - * @param $forum_id Optional. Used to check emptiness.
221 + * @param $forum_id Optional. Used to check emptiness
231 222 */
232 223 function bbp_forum_id( $forum_id = 0 ) {
233 224 echo bbp_get_forum_id( $forum_id );
234 225 }
226 + /**
227 + * Return the forum id
228 + *
229 + * @since 2.0.0 bbPress (r2464)
230 + *
231 + * @param $forum_id Optional. Used to check emptiness
232 + * @return int The forum id
233 + */
234 + function bbp_get_forum_id( $forum_id = 0 ) {
235 + $bbp = bbpress();
236 + $wp_query = bbp_get_wp_query();
235 237
236 -/**
237 - * Return the forum id.
238 - *
239 - * @since 2.0.0 bbPress (r2464)
240 - *
241 - * @param $forum_id Optional. Used to check emptiness.
242 - * @return int The forum id.
243 - */
244 -function bbp_get_forum_id( $forum_id = 0 ) {
245 - $bbp = bbpress();
246 - $wp_query = bbp_get_wp_query();
238 + // Easy empty checking
239 + if ( ! empty( $forum_id ) && is_numeric( $forum_id ) ) {
240 + $bbp_forum_id = $forum_id;
247 241
248 - // Easy empty checking
249 - if ( ! empty( $forum_id ) && is_numeric( $forum_id ) ) {
250 - $bbp_forum_id = $forum_id;
242 + // Currently inside a forum loop
243 + } elseif ( ! empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) ) {
244 + $bbp_forum_id = $bbp->forum_query->post->ID;
251 245
252 - // Currently inside a forum loop
253 - } elseif ( ! empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) ) {
254 - $bbp_forum_id = $bbp->forum_query->post->ID;
246 + // Currently inside a search loop
247 + } elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_forum( $bbp->search_query->post->ID ) ) {
248 + $bbp_forum_id = $bbp->search_query->post->ID;
255 249
256 - // Currently inside a search loop
257 - } elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_forum( $bbp->search_query->post->ID ) ) {
258 - $bbp_forum_id = $bbp->search_query->post->ID;
250 + // Currently viewing a forum
251 + } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && ! empty( $bbp->current_forum_id ) ) {
252 + $bbp_forum_id = $bbp->current_forum_id;
259 253
260 - // Currently viewing a forum
261 - } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && ! empty( $bbp->current_forum_id ) ) {
262 - $bbp_forum_id = $bbp->current_forum_id;
254 + // Currently viewing a forum
255 + } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && isset( $wp_query->post->ID ) ) {
256 + $bbp_forum_id = $wp_query->post->ID;
263 257
264 - // Currently viewing a forum
265 - } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && isset( $wp_query->post->ID ) ) {
266 - $bbp_forum_id = $wp_query->post->ID;
258 + // Currently viewing a topic
259 + } elseif ( bbp_is_single_topic() ) {
260 + $bbp_forum_id = bbp_get_topic_forum_id();
267 261
268 - // Currently viewing a topic
269 - } elseif ( bbp_is_single_topic() ) {
270 - $bbp_forum_id = bbp_get_topic_forum_id();
262 + // Fallback
263 + } else {
264 + $bbp_forum_id = 0;
265 + }
271 266
272 - // Fallback
273 - } else {
274 - $bbp_forum_id = 0;
267 + // Filter & return
268 + return (int) apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id );
275 269 }
276 270
277 - // Filter & return
278 - return (int) apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id );
279 -}
280 -
281 271 /**
282 - * Gets a forum.
272 + * Gets a forum
283 273 *
284 274 * @since 2.0.0 bbPress (r2787)
285 275 *
286 - * @param int|object $forum forum id or forum object.
287 - * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT.
288 - * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}.
276 + * @param int|object $forum forum id or forum object
277 + * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
278 + * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
289 279 *
290 - * @return mixed Null if error or forum (in specified form) if success.
280 + * @return mixed Null if error or forum (in specified form) if success
291 281 */
292 282 function bbp_get_forum( $forum, $output = OBJECT, $filter = 'raw' ) {
293 283
294 284 // Maybe get ID from empty or int
@@ -302,9 +292,9 @@
302 292 return $forum;
303 293 }
304 294
305 295 // Bail if not correct post type
306 - if ( bbp_get_forum_post_type() !== $forum->post_type ) {
296 + if ( $forum->post_type !== bbp_get_forum_post_type() ) {
307 297 return null;
308 298 }
309 299
310 300 // Default return value is OBJECT
@@ -310,13 +300,13 @@
310 300 // Default return value is OBJECT
311 301 $retval = $forum;
312 302
313 303 // Array A
314 - if ( ARRAY_A === $output ) {
304 + if ( $output === ARRAY_A ) {
315 305 $retval = get_object_vars( $forum );
316 306
317 307 // Array N
318 - } elseif ( ARRAY_N === $output ) {
308 + } elseif ( $output === ARRAY_N ) {
319 309 $retval = array_values( get_object_vars( $forum ) );
320 310 }
321 311
322 312 // Filter & return
@@ -323,13 +313,13 @@
323 313 return apply_filters( 'bbp_get_forum', $retval, $forum, $output, $filter );
324 314 }
325 315
326 316 /**
327 - * Output the link to the forum.
317 + * Output the link to the forum
328 318 *
329 319 * @since 2.0.0 bbPress (r2464)
330 320 *
331 - * @param int $forum_id Optional. Forum id.
321 + * @param int $forum_id Optional. Forum id
332 322 * @param string $redirect_to Optional. Pass a redirect value for use with
333 323 * shortcodes and other fun things.
334 324 */
335 325 function bbp_forum_permalink( $forum_id = 0, $redirect_to = '' ) {
@@ -334,178 +324,140 @@
334 324 */
335 325 function bbp_forum_permalink( $forum_id = 0, $redirect_to = '' ) {
336 326 echo esc_url( bbp_get_forum_permalink( $forum_id, $redirect_to ) );
337 327 }
328 + /**
329 + * Return the link to the forum
330 + *
331 + * @since 2.0.0 bbPress (r2464)
332 + *
333 + * @param int $forum_id Optional. Forum id
334 + * @param string $redirect_to Optional. Pass a redirect value for use with
335 + * shortcodes and other fun things.
336 + *
337 + * @return string Permanent link to forum
338 + */
339 + function bbp_get_forum_permalink( $forum_id = 0, $redirect_to = '' ) {
340 + $forum_id = bbp_get_forum_id( $forum_id );
338 341
339 -/**
340 - * Return the link to the forum.
341 - *
342 - * @since 2.0.0 bbPress (r2464)
343 - *
344 - * @param int $forum_id Optional. Forum id.
345 - * @param string $redirect_to Optional. Pass a redirect value for use with
346 - * shortcodes and other fun things.
347 - *
348 - * @return string Permanent link to forum.
349 - */
350 -function bbp_get_forum_permalink( $forum_id = 0, $redirect_to = '' ) {
351 - $forum_id = bbp_get_forum_id( $forum_id );
342 + // Use the redirect address
343 + if ( ! empty( $redirect_to ) ) {
344 + $forum_permalink = esc_url_raw( $redirect_to );
352 345
353 - // Default return value
354 - $forum_permalink = '';
355 -
356 - // Use the redirect address
357 - if ( ! empty( $redirect_to ) ) {
358 - $forum_permalink = esc_url_raw( $redirect_to );
359 -
360 - // Plain permalinks: maybe build a slug-based URL using the forum query_var
361 - } elseif ( ! get_option( 'permalink_structure' ) ) {
362 -
363 - // Get the forum object
364 - $forum = bbp_get_forum( $forum_id );
365 -
366 - // Forum exists
367 - if ( ! empty( $forum ) ) {
368 -
369 - // Get the post type object from the forum
370 - $post_type = get_post_type_object( $forum->post_type );
371 -
372 - // Publicly queryable by var
373 - if ( ! empty( $post_type->query_var ) ) {
374 -
375 - // Use hierarchical path (parent/child/...) when applicable
376 - $path = ! empty( $post_type->hierarchical )
377 - ? get_page_uri( $forum_id )
378 - : $forum->post_name;
379 -
380 - // Add path to query var
381 - $forum_permalink = add_query_arg(
382 - $post_type->query_var,
383 - $path,
384 - home_url( '/' )
385 - );
386 - }
346 + // Use the topic permalink
347 + } else {
348 + $forum_permalink = get_permalink( $forum_id );
387 349 }
388 - }
389 350
390 - // Fallback to forum permalink
391 - if ( empty( $forum_permalink ) ) {
392 - $forum_permalink = get_permalink( $forum_id );
351 + // Filter & return
352 + return apply_filters( 'bbp_get_forum_permalink', $forum_permalink, $forum_id );
393 353 }
394 354
395 - // Filter & return
396 - return apply_filters( 'bbp_get_forum_permalink', $forum_permalink, $forum_id );
397 -}
398 -
399 355 /**
400 - * Output the title of the forum.
356 + * Output the title of the forum
401 357 *
402 358 * @since 2.0.0 bbPress (r2464)
403 359 *
404 - * @param int $forum_id Optional. Forum id.
360 + * @param int $forum_id Optional. Forum id
405 361 */
406 362 function bbp_forum_title( $forum_id = 0 ) {
407 363 echo bbp_get_forum_title( $forum_id );
408 364 }
365 + /**
366 + * Return the title of the forum
367 + *
368 + * @since 2.0.0 bbPress (r2464)
369 + *
370 + * @param int $forum_id Optional. Forum id
371 + * @return string Title of forum
372 + */
373 + function bbp_get_forum_title( $forum_id = 0 ) {
374 + $forum_id = bbp_get_forum_id( $forum_id );
375 + $title = get_the_title( $forum_id );
409 376
410 -/**
411 - * Return the title of the forum.
412 - *
413 - * @since 2.0.0 bbPress (r2464)
414 - *
415 - * @param int $forum_id Optional. Forum id.
416 - * @return string Title of forum.
417 - */
418 -function bbp_get_forum_title( $forum_id = 0 ) {
419 - $forum_id = bbp_get_forum_id( $forum_id );
420 - $title = get_post_field( 'post_title', $forum_id );
421 - $title = apply_filters( 'the_title', $title, $forum_id );
377 + // Filter & return
378 + return apply_filters( 'bbp_get_forum_title', $title, $forum_id );
379 + }
422 380
423 - // Filter & return
424 - return apply_filters( 'bbp_get_forum_title', $title, $forum_id );
425 -}
426 -
427 381 /**
428 - * Output the forum archive title.
382 + * Output the forum archive title
429 383 *
430 384 * @since 2.0.0 bbPress (r3249)
431 385 *
432 - * @param string $title Default text to use as title.
386 + * @param string $title Default text to use as title
433 387 */
434 388 function bbp_forum_archive_title( $title = '' ) {
435 389 echo bbp_get_forum_archive_title( $title );
436 390 }
391 + /**
392 + * Return the forum archive title
393 + *
394 + * @since 2.0.0 bbPress (r3249)
395 + *
396 + * @param string $title Default text to use as title
397 + *
398 + * @return string The forum archive title
399 + */
400 + function bbp_get_forum_archive_title( $title = '' ) {
437 401
438 -/**
439 - * Return the forum archive title.
440 - *
441 - * @since 2.0.0 bbPress (r3249)
442 - *
443 - * @param string $title Default text to use as title.
444 - *
445 - * @return string The forum archive title.
446 - */
447 -function bbp_get_forum_archive_title( $title = '' ) {
402 + // If no title was passed
403 + if ( empty( $title ) ) {
448 404
449 - // If no title was passed
450 - if ( empty( $title ) ) {
405 + // Set root text to page title
406 + $page = bbp_get_page_by_path( bbp_get_root_slug() );
407 + if ( ! empty( $page ) ) {
408 + $title = get_the_title( $page->ID );
451 409
452 - // Set root text to page title
453 - $page = bbp_get_page_by_path( bbp_get_root_slug() );
454 - if ( ! empty( $page ) ) {
455 - $title = get_the_title( $page->ID );
410 + // Default to forum post type name label
411 + } else {
412 + $fto = get_post_type_object( bbp_get_forum_post_type() );
413 + $title = $fto->labels->name;
414 + }
415 + }
456 416
457 - // Default to forum post type name label
458 - } else {
459 - $fto = get_post_type_object( bbp_get_forum_post_type() );
460 - $title = $fto->labels->name;
461 - }
417 + // Filter & return
418 + return apply_filters( 'bbp_get_forum_archive_title', $title );
462 419 }
463 420
464 - // Filter & return
465 - return apply_filters( 'bbp_get_forum_archive_title', $title );
466 -}
467 -
468 421 /**
469 - * Output the content of the forum.
422 + * Output the content of the forum
470 423 *
471 424 * @since 2.0.0 bbPress (r2780)
472 425 *
473 - * @param int $forum_id Optional. Topic id.
426 + * @param int $forum_id Optional. Topic id
474 427 */
475 428 function bbp_forum_content( $forum_id = 0 ) {
476 429 echo bbp_get_forum_content( $forum_id );
477 430 }
431 + /**
432 + * Return the content of the forum
433 + *
434 + * @since 2.0.0 bbPress (r2780)
435 + *
436 + * @param int $forum_id Optional. Topic id
437 + *
438 + * @return string Content of the forum
439 + */
440 + function bbp_get_forum_content( $forum_id = 0 ) {
441 + $forum_id = bbp_get_forum_id( $forum_id );
478 442
479 -/**
480 - * Return the content of the forum.
481 - *
482 - * @since 2.0.0 bbPress (r2780)
483 - *
484 - * @param int $forum_id Optional. Topic id.
485 - *
486 - * @return string Content of the forum.
487 - */
488 -function bbp_get_forum_content( $forum_id = 0 ) {
489 - $forum_id = bbp_get_forum_id( $forum_id );
443 + // Check if password is required
444 + if ( post_password_required( $forum_id ) ) {
445 + return get_the_password_form();
446 + }
490 447
491 - // Check if password is required
492 - if ( post_password_required( $forum_id ) ) {
493 - return get_the_password_form();
448 + $content = get_post_field( 'post_content', $forum_id );
449 +
450 + // Filter & return
451 + return apply_filters( 'bbp_get_forum_content', $content, $forum_id );
494 452 }
495 453
496 - $content = get_post_field( 'post_content', $forum_id );
497 -
498 - // Filter & return
499 - return apply_filters( 'bbp_get_forum_content', $content, $forum_id );
500 -}
501 -
502 454 /**
503 - * Allow forum rows to have administrative actions.
455 + * Allow forum rows to have administrative actions
504 456 *
505 457 * @since 2.1.0 bbPress (r3653)
506 458 *
507 - * @todo Links and filter.
459 + * @todo Links and filter
508 460 */
509 461 function bbp_forum_row_actions() {
510 462 do_action( 'bbp_forum_row_actions' );
511 463 }
@@ -510,80 +462,75 @@
510 462 do_action( 'bbp_forum_row_actions' );
511 463 }
512 464
513 465 /**
514 - * Output the forums last active ID.
466 + * Output the forums last active ID
515 467 *
516 468 * @since 2.0.0 bbPress (r2860)
517 469 *
518 - * @param int $forum_id Optional. Forum id.
470 + * @param int $forum_id Optional. Forum id
519 471 */
520 472 function bbp_forum_last_active_id( $forum_id = 0 ) {
521 473 echo bbp_get_forum_last_active_id( $forum_id );
522 474 }
475 + /**
476 + * Return the forums last active ID
477 + *
478 + * @since 2.0.0 bbPress (r2860)
479 + *
480 + * @param int $forum_id Optional. Forum id
481 + * the last active id and forum id
482 + * @return int Forum's last active id
483 + */
484 + function bbp_get_forum_last_active_id( $forum_id = 0 ) {
485 + $forum_id = bbp_get_forum_id( $forum_id );
486 + $active_id = (int) get_post_meta( $forum_id, '_bbp_last_active_id', true );
523 487
524 -/**
525 - * Return the forums last active ID.
526 - *
527 - * @since 2.0.0 bbPress (r2860)
528 - *
529 - * @param int $forum_id Optional. Forum id.
530 - * the last active id and forum id.
531 - * @return int Forum's last active id.
532 - */
533 -function bbp_get_forum_last_active_id( $forum_id = 0 ) {
534 - $forum_id = bbp_get_forum_id( $forum_id );
535 - $active_id = (int) get_post_meta( $forum_id, '_bbp_last_active_id', true );
488 + // Filter & return
489 + return (int) apply_filters( 'bbp_get_forum_last_active_id', $active_id, $forum_id );
490 + }
536 491
537 - // Filter & return
538 - return (int) apply_filters( 'bbp_get_forum_last_active_id', $active_id, $forum_id );
539 -}
540 -
541 492 /**
542 - * Output the forums last update date/time (aka freshness).
493 + * Output the forums last update date/time (aka freshness)
543 494 *
544 495 * @since 2.0.0 bbPress (r2464)
545 496 *
546 - * @param int $forum_id Optional. Forum id.
497 + * @param int $forum_id Optional. Forum id
547 498 */
548 499 function bbp_forum_last_active_time( $forum_id = 0 ) {
549 500 echo bbp_get_forum_last_active_time( $forum_id );
550 501 }
502 + /**
503 + * Return the forums last update date/time (aka freshness)
504 + *
505 + * @since 2.0.0 bbPress (r2464)
506 + *
507 + * @param int $forum_id Optional. Forum id
508 + * @return string Forum last update date/time (freshness)
509 + */
510 + function bbp_get_forum_last_active_time( $forum_id = 0 ) {
551 511
552 -/**
553 - * Return the forums last update date/time (aka freshness).
554 - *
555 - * @since 2.0.0 bbPress (r2464)
556 - *
557 - * @param int $forum_id Optional. Forum id.
558 - * @return string Forum last update date/time (freshness).
559 - */
560 -function bbp_get_forum_last_active_time( $forum_id = 0 ) {
512 + // Verify forum and get last active meta
513 + $forum_id = bbp_get_forum_id( $forum_id );
514 + $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true );
561 515
562 - // Verify forum and get last active meta
563 - $forum_id = bbp_get_forum_id( $forum_id );
564 - $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true );
565 -
566 - if ( empty( $last_active ) ) {
567 - $reply_id = bbp_get_forum_last_reply_id( $forum_id );
568 -
569 - if ( ! empty( $reply_id ) ) {
570 - $last_active = get_post_field( 'post_date', $reply_id );
571 - } else {
572 - $topic_id = bbp_get_forum_last_topic_id( $forum_id );
573 - if ( ! empty( $topic_id ) ) {
574 - $last_active = bbp_get_topic_last_active_time( $topic_id );
516 + if ( empty( $last_active ) ) {
517 + $reply_id = bbp_get_forum_last_reply_id( $forum_id );
518 + if ( ! empty( $reply_id ) ) {
519 + $last_active = get_post_field( 'post_date', $reply_id );
520 + } else {
521 + $topic_id = bbp_get_forum_last_topic_id( $forum_id );
522 + if ( ! empty( $topic_id ) ) {
523 + $last_active = bbp_get_topic_last_active_time( $topic_id );
524 + }
575 525 }
576 526 }
577 - }
578 527
579 - $active_time = ! empty( $last_active )
580 - ? bbp_get_time_since( bbp_convert_date( $last_active ) )
581 - : '';
528 + $active_time = ! empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
582 529
583 - // Filter & return
584 - return apply_filters( 'bbp_get_forum_last_active', $active_time, $forum_id );
585 -}
530 + // Filter & return
531 + return apply_filters( 'bbp_get_forum_last_active', $active_time, $forum_id );
532 + }
586 533
587 534 /**
588 535 * Output link to the most recent activity inside a forum.
589 536 *
@@ -592,98 +539,96 @@
592 539 * @since 2.0.0 bbPress (r2625)
593 540 *
594 541 * @param int $forum_id Optional. Forum id
595 542 */
596 -function bbp_forum_freshness_link( $forum_id = 0 ) {
543 +function bbp_forum_freshness_link( $forum_id = 0) {
597 544 echo bbp_get_forum_freshness_link( $forum_id );
598 545 }
546 + /**
547 + * Returns link to the most recent activity inside a forum.
548 + *
549 + * Returns a complete link with attributes and content.
550 + *
551 + * @since 2.0.0 bbPress (r2625)
552 + *
553 + * @param int $forum_id Optional. Forum id
554 + */
555 + function bbp_get_forum_freshness_link( $forum_id = 0 ) {
556 + $forum_id = bbp_get_forum_id( $forum_id );
557 + $active_id = bbp_get_forum_last_active_id( $forum_id );
558 + $link_url = $title = '';
599 559
600 -/**
601 - * Returns link to the most recent activity inside a forum.
602 - *
603 - * Returns a complete link with attributes and content.
604 - *
605 - * @since 2.0.0 bbPress (r2625)
606 - *
607 - * @param int $forum_id Optional. Forum id.
608 - */
609 -function bbp_get_forum_freshness_link( $forum_id = 0 ) {
610 - $forum_id = bbp_get_forum_id( $forum_id );
611 - $active_id = bbp_get_forum_last_active_id( $forum_id );
612 - $link_url = $title = '';
560 + if ( empty( $active_id ) ) {
561 + $active_id = bbp_get_forum_last_reply_id( $forum_id );
562 + }
613 563
614 - if ( empty( $active_id ) ) {
615 - $active_id = bbp_get_forum_last_reply_id( $forum_id );
616 - }
564 + if ( empty( $active_id ) ) {
565 + $active_id = bbp_get_forum_last_topic_id( $forum_id );
566 + }
617 567
618 - if ( empty( $active_id ) ) {
619 - $active_id = bbp_get_forum_last_topic_id( $forum_id );
620 - }
568 + if ( bbp_is_topic( $active_id ) ) {
569 + $link_url = bbp_get_forum_last_topic_permalink( $forum_id );
570 + $title = bbp_get_forum_last_topic_title( $forum_id );
571 + } elseif ( bbp_is_reply( $active_id ) ) {
572 + $link_url = bbp_get_forum_last_reply_url( $forum_id );
573 + $title = bbp_get_forum_last_reply_title( $forum_id );
574 + }
621 575
622 - if ( bbp_is_topic( $active_id ) ) {
623 - $link_url = bbp_get_forum_last_topic_permalink( $forum_id );
624 - $title = bbp_get_forum_last_topic_title( $forum_id );
625 - } elseif ( bbp_is_reply( $active_id ) ) {
626 - $link_url = bbp_get_forum_last_reply_url( $forum_id );
627 - $title = bbp_get_forum_last_reply_title( $forum_id );
628 - }
576 + $time_since = bbp_get_forum_last_active_time( $forum_id );
629 577
630 - $time_since = bbp_get_forum_last_active_time( $forum_id );
578 + if ( ! empty( $time_since ) && ! empty( $link_url ) ) {
579 + $anchor = '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>';
580 + } else {
581 + $anchor = esc_html__( 'No Topics', 'bbpress' );
582 + }
631 583
632 - if ( ! empty( $time_since ) && ! empty( $link_url ) ) {
633 - $anchor = '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>';
634 - } else {
635 - $anchor = esc_html__( 'No Topics', 'bbpress' );
584 + // Filter & return
585 + return apply_filters( 'bbp_get_forum_freshness_link', $anchor, $forum_id, $time_since, $link_url, $title, $active_id );
636 586 }
637 587
638 - // Filter & return
639 - return apply_filters( 'bbp_get_forum_freshness_link', $anchor, $forum_id, $time_since, $link_url, $title, $active_id );
640 -}
641 -
642 588 /**
643 - * Output parent ID of a forum, if exists.
589 + * Output parent ID of a forum, if exists
644 590 *
645 591 * @since 2.1.0 bbPress (r3675)
646 592 *
647 - * @param int $forum_id Forum ID.
593 + * @param int $forum_id Forum ID
648 594 */
649 595 function bbp_forum_parent_id( $forum_id = 0 ) {
650 596 echo bbp_get_forum_parent_id( $forum_id );
651 597 }
598 + /**
599 + * Return ID of forum parent, if exists
600 + *
601 + * @since 2.1.0 bbPress (r3675)
602 + *
603 + * @param int $forum_id Optional. Forum id
604 + * @return int Forum parent
605 + */
606 + function bbp_get_forum_parent_id( $forum_id = 0 ) {
607 + $forum_id = bbp_get_forum_id( $forum_id );
608 + $parent_id = (int) get_post_field( 'post_parent', $forum_id );
652 609
653 -/**
654 - * Return ID of forum parent, if exists.
655 - *
656 - * @since 2.1.0 bbPress (r3675)
657 - *
658 - * @param int $forum_id Optional. Forum id.
659 - * @return int Forum parent id.
660 - */
661 -function bbp_get_forum_parent_id( $forum_id = 0 ) {
662 - $forum_id = bbp_get_forum_id( $forum_id );
663 - $parent_id = (int) get_post_field( 'post_parent', $forum_id );
610 + // Meta-data fallback
611 + if ( empty( $parent_id ) ) {
612 + $parent_id = (int) get_post_meta( $forum_id, '_bbp_forum_id', true );
613 + }
664 614
665 - // Meta-data fallback
666 - if ( empty( $parent_id ) ) {
667 - $parent_id = (int) get_post_meta( $forum_id, '_bbp_forum_id', true );
668 - }
615 + // Filter
616 + if ( ! empty( $parent_id ) ) {
617 + $parent_id = (int) bbp_get_forum_id( $parent_id );
618 + }
669 619
670 - // Filter
671 - if ( ! empty( $parent_id ) ) {
672 - $parent_id = (int) bbp_get_forum_id( $parent_id );
620 + // Filter & return
621 + return (int) apply_filters( 'bbp_get_forum_parent_id', $parent_id, $forum_id );
673 622 }
674 623
675 - // Filter & return
676 - return (int) apply_filters( 'bbp_get_forum_parent_id', $parent_id, $forum_id );
677 -}
678 -
679 624 /**
680 - * Return array of parent forums.
625 + * Return array of parent forums
681 626 *
682 627 * @since 2.0.0 bbPress (r2625)
683 628 *
684 - * @param int $forum_id Optional. Forum id.
685 - * @return array Forum ancestors.
629 + * @param int $forum_id Optional. Forum id
630 + * @return array Forum ancestors
686 631 */
687 632 function bbp_get_forum_ancestors( $forum_id = 0 ) {
688 633 $forum_id = bbp_get_forum_id( $forum_id );
689 634 $ancestors = array();
@@ -700,14 +645,14 @@
700 645 return apply_filters( 'bbp_get_forum_ancestors', $ancestors, $forum_id );
701 646 }
702 647
703 648 /**
704 - * Return subforums of given forum.
649 + * Return subforums of given forum
705 650 *
706 651 * @since 2.0.0 bbPress (r2747)
707 652 *
708 - * @param array $args All the arguments supported by {@link WP_Query}.
709 - * @return mixed false if none, array of subs if yes.
653 + * @param array $args All the arguments supported by {@link WP_Query}
654 + * @return mixed false if none, array of subs if yes
710 655 */
711 656 function bbp_forum_get_subforums( $args = array() ) {
712 657
713 658 // Default return value
@@ -718,21 +663,17 @@
718 663 $args = array( 'post_parent' => bbp_get_forum_id( $args ) );
719 664 }
720 665
721 666 // Parse arguments against default values
722 - $r = bbp_parse_args(
723 - $args,
724 - array(
725 - 'post_parent' => 0,
726 - 'post_type' => bbp_get_forum_post_type(),
727 - 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
728 - 'orderby' => 'menu_order title',
729 - 'order' => 'ASC',
730 - 'ignore_sticky_posts' => true,
731 - 'no_found_rows' => true
732 - ),
733 - 'forum_get_subforums'
734 - );
667 + $r = bbp_parse_args( $args, array(
668 + 'post_parent' => 0,
669 + 'post_type' => bbp_get_forum_post_type(),
670 + 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
671 + 'orderby' => 'menu_order title',
672 + 'order' => 'ASC',
673 + 'ignore_sticky_posts' => true,
674 + 'no_found_rows' => true
675 + ), 'forum_get_subforums' );
735 676
736 677 // Ensure post_parent is properly set
737 678 $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] );
738 679
@@ -746,9 +687,9 @@
746 687 return (array) apply_filters( 'bbp_forum_get_subforums', $retval, $r, $args );
747 688 }
748 689
749 690 /**
750 - * Output a list of forums (can be used to list subforums).
691 + * Output a list of forums (can be used to list subforums)
751 692 *
752 693 * @since 2.0.0 bbPress (r2708)
753 694 *
754 695 * @param array $args The function supports these args:
@@ -766,29 +707,25 @@
766 707 */
767 708 function bbp_list_forums( $args = array() ) {
768 709
769 710 // Parse arguments against default values
770 - $r = bbp_parse_args(
771 - $args,
772 - array(
773 - 'before' => '<ul class="bbp-forums-list">',
774 - 'after' => '</ul>',
775 - 'link_before' => '<li class="bbp-forum css-sep">',
776 - 'link_after' => '</li>',
777 - 'sep' => '',
778 - 'count_before' => ' (',
779 - 'count_after' => ')',
780 - 'count_sep' => ', ',
781 - 'forum_id' => bbp_get_forum_id(),
782 - 'show_topic_count' => true,
783 - 'show_reply_count' => true,
784 - 'echo' => true,
711 + $r = bbp_parse_args( $args, array(
712 + 'before' => '<ul class="bbp-forums-list">',
713 + 'after' => '</ul>',
714 + 'link_before' => '<li class="bbp-forum css-sep">',
715 + 'link_after' => '</li>',
716 + 'sep' => '',
717 + 'count_before' => ' (',
718 + 'count_after' => ')',
719 + 'count_sep' => ', ',
720 + 'forum_id' => bbp_get_forum_id(),
721 + 'show_topic_count' => true,
722 + 'show_reply_count' => true,
723 + 'echo' => true,
785 724
786 - // Retired, use 'sep' instead
787 - 'separator' => false
788 - ),
789 - 'list_forums'
790 - );
725 + // Retired, use 'sep' instead
726 + 'separator' => false
727 + ), 'list_forums' );
791 728
792 729 /**
793 730 * Necessary for backwards compatibility
794 731 * @see https://bbpress.trac.wordpress.org/ticket/2900
@@ -860,9 +797,9 @@
860 797
861 798 /** Forum Subscriptions *******************************************************/
862 799
863 800 /**
864 - * Output the forum subscription link.
801 + * Output the forum subscription link
865 802 *
866 803 * @since 2.5.0 bbPress (r5156)
867 804 * @since 2.6.0 bbPress (r6308) Add 'redirect_to' support
868 805 */
@@ -869,28 +806,26 @@
869 806 function bbp_forum_subscription_link( $args = array() ) {
870 807 echo bbp_get_forum_subscription_link( $args );
871 808 }
872 809
873 -/**
874 - * Get the forum subscription link.
875 - *
876 - * A custom wrapper for bbp_get_user_subscribe_link().
877 - *
878 - * @since 2.5.0 bbPress (r5156)
879 - * @since 2.6.0 bbPress (r6308) Add 'redirect_to' support
880 - */
881 -function bbp_get_forum_subscription_link( $args = array() ) {
810 + /**
811 + * Get the forum subscription link
812 + *
813 + * A custom wrapper for bbp_get_user_subscribe_link()
814 + *
815 + * @since 2.5.0 bbPress (r5156)
816 + * @since 2.6.0 bbPress (r6308) Add 'redirect_to' support
817 + */
818 + function bbp_get_forum_subscription_link( $args = array() ) {
882 819
883 - // Defaults
884 - $retval = false;
885 - $redirect_to = bbp_is_subscriptions()
886 - ? bbp_get_subscriptions_permalink()
887 - : '';
820 + // Defaults
821 + $retval = false;
822 + $redirect_to = bbp_is_subscriptions()
823 + ? bbp_get_subscriptions_permalink()
824 + : '';
888 825
889 - // Parse the arguments
890 - $r = bbp_parse_args(
891 - $args,
892 - array(
826 + // Parse the arguments
827 + $r = bbp_parse_args( $args, array(
893 828 'user_id' => bbp_get_current_user_id(),
894 829 'object_id' => bbp_get_forum_id(),
895 830 'object_type' => 'post',
896 831 'before' => '',
@@ -897,116 +832,109 @@
897 832 'after' => '',
898 833 'subscribe' => esc_html__( 'Subscribe', 'bbpress' ),
899 834 'unsubscribe' => esc_html__( 'Unsubscribe', 'bbpress' ),
900 835 'redirect_to' => $redirect_to
901 - ),
902 - 'get_forum_subscribe_link'
903 - );
836 + ), 'get_forum_subscribe_link' );
904 837
905 - // No link for categories until we support subscription hierarchy
906 - // @see https://bbpress.trac.wordpress.org/ticket/2475
907 - if ( ! bbp_is_forum_category() ) {
908 - $retval = bbp_get_user_subscribe_link( $r );
838 + // No link for categories until we support subscription hierarchy
839 + // @see https://bbpress.trac.wordpress.org/ticket/2475
840 + if ( ! bbp_is_forum_category() ) {
841 + $retval = bbp_get_user_subscribe_link( $r );
842 + }
843 +
844 + // Filter & return
845 + return apply_filters( 'bbp_get_forum_subscribe_link', $retval, $r, $args );
909 846 }
910 847
911 - // Filter & return
912 - return apply_filters( 'bbp_get_forum_subscribe_link', $retval, $r, $args );
913 -}
914 -
915 848 /** Forum Last Topic **********************************************************/
916 849
917 850 /**
918 - * Output the forum's last topic id.
851 + * Output the forum's last topic id
919 852 *
920 853 * @since 2.0.0 bbPress (r2464)
921 854 *
922 - * @param int $forum_id Optional. Forum id.
855 + * @param int $forum_id Optional. Forum id
923 856 */
924 857 function bbp_forum_last_topic_id( $forum_id = 0 ) {
925 858 echo bbp_get_forum_last_topic_id( $forum_id );
926 859 }
860 + /**
861 + * Return the forum's last topic id
862 + *
863 + * @since 2.0.0 bbPress (r2464)
864 + *
865 + * @param int $forum_id Optional. Forum id
866 + * @return int Forum's last topic id
867 + */
868 + function bbp_get_forum_last_topic_id( $forum_id = 0 ) {
869 + $forum_id = bbp_get_forum_id( $forum_id );
870 + $topic_id = (int) get_post_meta( $forum_id, '_bbp_last_topic_id', true );
927 871
928 -/**
929 - * Return the forum's last topic id.
930 - *
931 - * @since 2.0.0 bbPress (r2464)
932 - *
933 - * @param int $forum_id Optional. Forum id.
934 - * @return int Forum's last topic id.
935 - */
936 -function bbp_get_forum_last_topic_id( $forum_id = 0 ) {
937 - $forum_id = bbp_get_forum_id( $forum_id );
938 - $topic_id = (int) get_post_meta( $forum_id, '_bbp_last_topic_id', true );
872 + // Filter & return
873 + return (int) apply_filters( 'bbp_get_forum_last_topic_id', $topic_id, $forum_id );
874 + }
939 875
940 - // Filter & return
941 - return (int) apply_filters( 'bbp_get_forum_last_topic_id', $topic_id, $forum_id );
942 -}
943 -
944 876 /**
945 - * Output the title of the last topic inside a forum.
877 + * Output the title of the last topic inside a forum
946 878 *
947 879 * @since 2.0.0 bbPress (r2625)
948 880 *
949 - * @param int $forum_id Optional. Forum id.
881 + * @param int $forum_id Optional. Forum id
950 882 */
951 883 function bbp_forum_last_topic_title( $forum_id = 0 ) {
952 884 echo bbp_get_forum_last_topic_title( $forum_id );
953 885 }
886 + /**
887 + * Return the title of the last topic inside a forum
888 + *
889 + * @since 2.0.0 bbPress (r2625)
890 + *
891 + * @param int $forum_id Optional. Forum id
892 + * @return string Forum's last topic's title
893 + */
894 + function bbp_get_forum_last_topic_title( $forum_id = 0 ) {
895 + $forum_id = bbp_get_forum_id( $forum_id );
896 + $topic_id = bbp_get_forum_last_topic_id( $forum_id );
897 + $title = ! empty( $topic_id ) ? bbp_get_topic_title( $topic_id ) : '';
954 898
955 -/**
956 - * Return the title of the last topic inside a forum.
957 - *
958 - * @since 2.0.0 bbPress (r2625)
959 - *
960 - * @param int $forum_id Optional. Forum id.
961 - * @return string Forum's last topic's title.
962 - */
963 -function bbp_get_forum_last_topic_title( $forum_id = 0 ) {
964 - $forum_id = bbp_get_forum_id( $forum_id );
965 - $topic_id = bbp_get_forum_last_topic_id( $forum_id );
966 - $title = ! empty( $topic_id )
967 - ? bbp_get_topic_title( $topic_id )
968 - : '';
899 + // Filter & return
900 + return apply_filters( 'bbp_get_forum_last_topic_title', $title, $forum_id );
901 + }
969 902
970 - // Filter & return
971 - return apply_filters( 'bbp_get_forum_last_topic_title', $title, $forum_id );
972 -}
973 -
974 903 /**
975 - * Output the link to the last topic in a forum.
904 + * Output the link to the last topic in a forum
976 905 *
977 906 * @since 2.0.0 bbPress (r2464)
978 907 *
979 - * @param int $forum_id Optional. Forum id.
908 + * @param int $forum_id Optional. Forum id
980 909 */
981 910 function bbp_forum_last_topic_permalink( $forum_id = 0 ) {
982 911 echo esc_url( bbp_get_forum_last_topic_permalink( $forum_id ) );
983 912 }
913 + /**
914 + * Return the link to the last topic in a forum
915 + *
916 + * @since 2.0.0 bbPress (r2464)
917 + *
918 + * @param int $forum_id Optional. Forum id
919 + * @return string Permanent link to topic
920 + */
921 + function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) {
922 + $forum_id = bbp_get_forum_id( $forum_id );
923 + $topic_id = bbp_get_forum_last_topic_id( $forum_id );
924 + $link = bbp_get_topic_permalink( $topic_id );
984 925
985 -/**
986 - * Return the link to the last topic in a forum.
987 - *
988 - * @since 2.0.0 bbPress (r2464)
989 - *
990 - * @param int $forum_id Optional. Forum id.
991 - * @return string Permanent link to topic.
992 - */
993 -function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) {
994 - $forum_id = bbp_get_forum_id( $forum_id );
995 - $topic_id = bbp_get_forum_last_topic_id( $forum_id );
996 - $link = bbp_get_topic_permalink( $topic_id );
926 + // Filter & return
927 + return apply_filters( 'bbp_get_forum_last_topic_permalink', $link, $forum_id, $topic_id );
928 + }
997 929
998 - // Filter & return
999 - return apply_filters( 'bbp_get_forum_last_topic_permalink', $link, $forum_id, $topic_id );
1000 -}
1001 -
1002 930 /**
1003 - * Return the author ID of the last topic of a forum.
931 + * Return the author ID of the last topic of a forum
1004 932 *
1005 933 * @since 2.0.0 bbPress (r2625)
1006 934 *
1007 - * @param int $forum_id Optional. Forum id.
1008 - * @return int Forum's last topic's author id.
935 + * @param int $forum_id Optional. Forum id
936 + * @return int Forum's last topic's author id
1009 937 */
1010 938 function bbp_get_forum_last_topic_author_id( $forum_id = 0 ) {
1011 939 $forum_id = bbp_get_forum_id( $forum_id );
1012 940 $topic_id = bbp_get_forum_last_topic_id( $forum_id );
@@ -1016,574 +944,556 @@
1016 944 return (int) apply_filters( 'bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id, $topic_id );
1017 945 }
1018 946
1019 947 /**
1020 - * Output link to author of last topic of forum.
948 + * Output link to author of last topic of forum
1021 949 *
1022 950 * @since 2.0.0 bbPress (r2625)
1023 951 *
1024 - * @param int $forum_id Optional. Forum id.
952 + * @param int $forum_id Optional. Forum id
1025 953 */
1026 954 function bbp_forum_last_topic_author_link( $forum_id = 0 ) {
1027 955 echo bbp_get_forum_last_topic_author_link( $forum_id );
1028 956 }
957 + /**
958 + * Return link to author of last topic of forum
959 + *
960 + * @since 2.0.0 bbPress (r2625)
961 + *
962 + * @param int $forum_id Optional. Forum id
963 + * @return string Forum's last topic's author link
964 + */
965 + function bbp_get_forum_last_topic_author_link( $forum_id = 0 ) {
966 + $forum_id = bbp_get_forum_id( $forum_id );
967 + $author_id = bbp_get_forum_last_topic_author_id( $forum_id );
968 + $author_link = bbp_get_user_profile_link( $author_id );
1029 969
1030 -/**
1031 - * Return link to author of last topic of forum.
1032 - *
1033 - * @since 2.0.0 bbPress (r2625)
1034 - *
1035 - * @param int $forum_id Optional. Forum id.
1036 - * @return string Forum's last topic's author link.
1037 - */
1038 -function bbp_get_forum_last_topic_author_link( $forum_id = 0 ) {
1039 - $forum_id = bbp_get_forum_id( $forum_id );
1040 - $author_id = bbp_get_forum_last_topic_author_id( $forum_id );
1041 - $author_link = bbp_get_user_profile_link( $author_id );
970 + // Filter & return
971 + return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id );
972 + }
1042 973
1043 - // Filter & return
1044 - return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id );
1045 -}
1046 -
1047 974 /** Forum Last Reply **********************************************************/
1048 975
1049 976 /**
1050 - * Output the forums last reply id.
977 + * Output the forums last reply id
1051 978 *
1052 979 * @since 2.0.0 bbPress (r2464)
1053 980 *
1054 - * @param int $forum_id Optional. Forum id.
981 + * @param int $forum_id Optional. Forum id
1055 982 */
1056 983 function bbp_forum_last_reply_id( $forum_id = 0 ) {
1057 984 echo bbp_get_forum_last_reply_id( $forum_id );
1058 985 }
986 + /**
987 + * Return the forums last reply id
988 + *
989 + * @since 2.0.0 bbPress (r2464)
990 + *
991 + * @param int $forum_id Optional. Forum id
992 + * @return int Forum's last reply id
993 + */
994 + function bbp_get_forum_last_reply_id( $forum_id = 0 ) {
995 + $forum_id = bbp_get_forum_id( $forum_id );
996 + $reply_id = (int) get_post_meta( $forum_id, '_bbp_last_reply_id', true );
1059 997
1060 -/**
1061 - * Return the forums last reply id.
1062 - *
1063 - * @since 2.0.0 bbPress (r2464)
1064 - *
1065 - * @param int $forum_id Optional. Forum id.
1066 - * @return int Forum's last reply id.
1067 - */
1068 -function bbp_get_forum_last_reply_id( $forum_id = 0 ) {
1069 - $forum_id = bbp_get_forum_id( $forum_id );
1070 - $reply_id = (int) get_post_meta( $forum_id, '_bbp_last_reply_id', true );
998 + // Filter & return
999 + return (int) apply_filters( 'bbp_get_forum_last_reply_id', $reply_id, $forum_id );
1000 + }
1071 1001
1072 - // Filter & return
1073 - return (int) apply_filters( 'bbp_get_forum_last_reply_id', $reply_id, $forum_id );
1074 -}
1075 -
1076 1002 /**
1077 - * Output the title of the last reply inside a forum.
1003 + * Output the title of the last reply inside a forum
1078 1004 *
1079 - * @param int $forum_id Optional. Forum id.
1005 + * @param int $forum_id Optional. Forum id
1080 1006 */
1081 1007 function bbp_forum_last_reply_title( $forum_id = 0 ) {
1082 1008 echo bbp_get_forum_last_reply_title( $forum_id );
1083 1009 }
1010 + /**
1011 + * Return the title of the last reply inside a forum
1012 + *
1013 + * @param int $forum_id Optional. Forum id
1014 + * @return string
1015 + */
1016 + function bbp_get_forum_last_reply_title( $forum_id = 0 ) {
1017 + $forum_id = bbp_get_forum_id( $forum_id );
1018 + $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1019 + $title = bbp_get_reply_title( $reply_id );
1084 1020
1085 -/**
1086 - * Return the title of the last reply inside a forum.
1087 - *
1088 - * @param int $forum_id Optional. Forum id.
1089 - * @return string
1090 - */
1091 -function bbp_get_forum_last_reply_title( $forum_id = 0 ) {
1092 - $forum_id = bbp_get_forum_id( $forum_id );
1093 - $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1094 - $title = bbp_get_reply_title( $reply_id );
1021 + // Filter & return
1022 + return apply_filters( 'bbp_get_forum_last_reply_title', $title, $forum_id, $reply_id );
1023 + }
1095 1024
1096 - // Filter & return
1097 - return apply_filters( 'bbp_get_forum_last_reply_title', $title, $forum_id, $reply_id );
1098 -}
1099 -
1100 1025 /**
1101 - * Output the link to the last reply in a forum.
1026 + * Output the link to the last reply in a forum
1102 1027 *
1103 1028 * @since 2.0.0 bbPress (r2464)
1104 1029 *
1105 - * @param int $forum_id Optional. Forum id.
1030 + * @param int $forum_id Optional. Forum id
1106 1031 */
1107 1032 function bbp_forum_last_reply_permalink( $forum_id = 0 ) {
1108 1033 echo esc_url( bbp_get_forum_last_reply_permalink( $forum_id ) );
1109 1034 }
1035 + /**
1036 + * Return the link to the last reply in a forum
1037 + *
1038 + * @since 2.0.0 bbPress (r2464)
1039 + *
1040 + * @param int $forum_id Optional. Forum id
1041 + *
1042 + * @return string Permanent link to the forum's last reply
1043 + */
1044 + function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) {
1045 + $forum_id = bbp_get_forum_id( $forum_id );
1046 + $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1047 + $link = bbp_get_reply_permalink( $reply_id );
1110 1048
1111 -/**
1112 - * Return the link to the last reply in a forum.
1113 - *
1114 - * @since 2.0.0 bbPress (r2464)
1115 - *
1116 - * @param int $forum_id Optional. Forum id.
1117 - *
1118 - * @return string Permanent link to the forum's last reply.
1119 - */
1120 -function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) {
1121 - $forum_id = bbp_get_forum_id( $forum_id );
1122 - $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1123 - $link = bbp_get_reply_permalink( $reply_id );
1049 + // Filter & return
1050 + return apply_filters( 'bbp_get_forum_last_reply_permalink', $link, $forum_id, $reply_id );
1051 + }
1124 1052
1125 - // Filter & return
1126 - return apply_filters( 'bbp_get_forum_last_reply_permalink', $link, $forum_id, $reply_id );
1127 -}
1128 -
1129 1053 /**
1130 - * Output the url to the last reply in a forum.
1054 + * Output the url to the last reply in a forum
1131 1055 *
1132 1056 * @since 2.0.0 bbPress (r2683)
1133 1057 *
1134 - * @param int $forum_id Optional. Forum id.
1058 + * @param int $forum_id Optional. Forum id
1135 1059 */
1136 1060 function bbp_forum_last_reply_url( $forum_id = 0 ) {
1137 1061 echo esc_url( bbp_get_forum_last_reply_url( $forum_id ) );
1138 1062 }
1063 + /**
1064 + * Return the url to the last reply in a forum
1065 + *
1066 + * @since 2.0.0 bbPress (r2683)
1067 + *
1068 + * @param int $forum_id Optional. Forum id
1069 + * @return string Paginated URL to latest reply
1070 + */
1071 + function bbp_get_forum_last_reply_url( $forum_id = 0 ) {
1072 + $forum_id = bbp_get_forum_id( $forum_id );
1139 1073
1140 -/**
1141 - * Return the url to the last reply in a forum.
1142 - *
1143 - * @since 2.0.0 bbPress (r2683)
1144 - *
1145 - * @param int $forum_id Optional. Forum id.
1146 - * @return string Paginated URL to latest reply.
1147 - */
1148 -function bbp_get_forum_last_reply_url( $forum_id = 0 ) {
1149 - $forum_id = bbp_get_forum_id( $forum_id );
1074 + // If forum has replies, get the last reply and use its url
1075 + $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1076 + if ( ! empty( $reply_id ) ) {
1077 + $reply_url = bbp_get_reply_url( $reply_id );
1150 1078
1151 - // If forum has replies, get the last reply and use its url
1152 - $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1153 - if ( ! empty( $reply_id ) ) {
1154 - $reply_url = bbp_get_reply_url( $reply_id );
1079 + // No replies, so look for topics and use last permalink
1080 + } else {
1081 + $reply_url = bbp_get_forum_last_topic_permalink( $forum_id );
1155 1082
1156 - // No replies, so look for topics and use last permalink
1157 - } else {
1158 - $reply_url = bbp_get_forum_last_topic_permalink( $forum_id );
1083 + // No topics either, so set $reply_url as empty string
1084 + if ( empty( $reply_url ) ) {
1085 + $reply_url = '';
1086 + }
1087 + }
1159 1088
1160 - // No topics either, so set $reply_url as empty string
1161 - if ( empty( $reply_url ) ) {
1162 - $reply_url = '';
1163 - }
1089 + // Filter & return
1090 + return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id, $reply_id );
1164 1091 }
1165 1092
1166 - // Filter & return
1167 - return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id, $reply_id );
1168 -}
1169 -
1170 1093 /**
1171 - * Output author ID of last reply of forum.
1094 + * Output author ID of last reply of forum
1172 1095 *
1173 1096 * @since 2.0.0 bbPress (r2625)
1174 1097 *
1175 - * @param int $forum_id Optional. Forum id.
1098 + * @param int $forum_id Optional. Forum id
1176 1099 */
1177 1100 function bbp_forum_last_reply_author_id( $forum_id = 0 ) {
1178 1101 echo bbp_get_forum_last_reply_author_id( $forum_id );
1179 1102 }
1103 + /**
1104 + * Return author ID of last reply of forum
1105 + *
1106 + * @since 2.0.0 bbPress (r2625)
1107 + *
1108 + * @param int $forum_id Optional. Forum id
1109 + * @return int Forum's last reply author id
1110 + */
1111 + function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) {
1112 + $forum_id = bbp_get_forum_id( $forum_id );
1113 + $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1114 + $author_id = bbp_get_reply_author_id( $reply_id );
1180 1115
1181 -/**
1182 - * Return author ID of last reply of forum.
1183 - *
1184 - * @since 2.0.0 bbPress (r2625)
1185 - *
1186 - * @param int $forum_id Optional. Forum id.
1187 - * @return int Forum's last reply author id.
1188 - */
1189 -function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) {
1190 - $forum_id = bbp_get_forum_id( $forum_id );
1191 - $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1192 - $author_id = bbp_get_reply_author_id( $reply_id );
1116 + // Filter & return
1117 + return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id, $reply_id );
1118 + }
1193 1119
1194 - // Filter & return
1195 - return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id, $reply_id );
1196 -}
1197 -
1198 1120 /**
1199 - * Output link to author of last reply of forum.
1121 + * Output link to author of last reply of forum
1200 1122 *
1201 1123 * @since 2.0.0 bbPress (r2625)
1202 1124 *
1203 - * @param int $forum_id Optional. Forum id.
1125 + * @param int $forum_id Optional. Forum id
1204 1126 */
1205 1127 function bbp_forum_last_reply_author_link( $forum_id = 0 ) {
1206 1128 echo bbp_get_forum_last_reply_author_link( $forum_id );
1207 1129 }
1130 + /**
1131 + * Return link to author of last reply of forum
1132 + *
1133 + * @since 2.0.0 bbPress (r2625)
1134 + *
1135 + * @param int $forum_id Optional. Forum id
1136 + * @return string Link to author of last reply of forum
1137 + */
1138 + function bbp_get_forum_last_reply_author_link( $forum_id = 0 ) {
1139 + $forum_id = bbp_get_forum_id( $forum_id );
1140 + $author_id = bbp_get_forum_last_reply_author_id( $forum_id );
1141 + $author_link = bbp_get_user_profile_link( $author_id );
1208 1142
1209 -/**
1210 - * Return link to author of last reply of forum.
1211 - *
1212 - * @since 2.0.0 bbPress (r2625)
1213 - *
1214 - * @param int $forum_id Optional. Forum id.
1215 - * @return string Link to author of last reply of forum.
1216 - */
1217 -function bbp_get_forum_last_reply_author_link( $forum_id = 0 ) {
1218 - $forum_id = bbp_get_forum_id( $forum_id );
1219 - $author_id = bbp_get_forum_last_reply_author_id( $forum_id );
1220 - $author_link = bbp_get_user_profile_link( $author_id );
1143 + // Filter & return
1144 + return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id, $author_id );
1145 + }
1221 1146
1222 - // Filter & return
1223 - return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id, $author_id );
1224 -}
1225 -
1226 1147 /** Forum Counts **************************************************************/
1227 1148
1228 1149 /**
1229 - * Output the topics link of the forum.
1150 + * Output the topics link of the forum
1230 1151 *
1231 1152 * @since 2.0.0 bbPress (r2883)
1232 1153 *
1233 - * @param int $forum_id Optional. Topic id.
1154 + * @param int $forum_id Optional. Topic id
1234 1155 */
1235 1156 function bbp_forum_topics_link( $forum_id = 0 ) {
1236 1157 echo bbp_get_forum_topics_link( $forum_id );
1237 1158 }
1238 1159
1239 -/**
1240 - * Return the topics link of the forum.
1241 - *
1242 - * @since 2.0.0 bbPress (r2883)
1243 - *
1244 - * @param int $forum_id Optional. Topic id.
1245 - */
1246 -function bbp_get_forum_topics_link( $forum_id = 0 ) {
1247 - $forum_id = bbp_get_forum_id( $forum_id );
1248 - $link = bbp_get_forum_permalink( $forum_id );
1249 - /* translators: %s: Number of topics */
1250 - $topics = sprintf( _n( '%s topic', '%s topics', bbp_get_forum_topic_count( $forum_id, true, true ), 'bbpress' ), bbp_get_forum_topic_count( $forum_id, true, false ) );
1160 + /**
1161 + * Return the topics link of the forum
1162 + *
1163 + * @since 2.0.0 bbPress (r2883)
1164 + *
1165 + * @param int $forum_id Optional. Topic id
1166 + */
1167 + function bbp_get_forum_topics_link( $forum_id = 0 ) {
1168 + $forum_id = bbp_get_forum_id( $forum_id );
1169 + $link = bbp_get_forum_permalink( $forum_id );
1170 + $topics = sprintf( _n( '%s topic', '%s topics', bbp_get_forum_topic_count( $forum_id, true, true ), 'bbpress' ), bbp_get_forum_topic_count( $forum_id, true, false ) );
1251 1171
1252 - // First link never has view=all
1253 - $retval = bbp_get_view_all( 'edit_others_topics' )
1254 - ? "<a href='" . esc_url( bbp_remove_view_all( $link ) ) . "'>" . esc_html( $topics ) . '</a>'
1255 - : esc_html( $topics );
1172 + // First link never has view=all
1173 + $retval = bbp_get_view_all( 'edit_others_topics' )
1174 + ? "<a href='" . esc_url( bbp_remove_view_all( $link ) ) . "'>" . esc_html( $topics ) . "</a>"
1175 + : esc_html( $topics );
1256 1176
1257 - // Get deleted topics
1258 - $deleted_int = bbp_get_forum_topic_count_hidden( $forum_id, false, true );
1177 + // Get deleted topics
1178 + $deleted_int = bbp_get_forum_topic_count_hidden( $forum_id, false, true );
1259 1179
1260 - // This forum has hidden topics
1261 - if ( ! empty( $deleted_int ) && current_user_can( 'edit_others_topics' ) ) {
1180 + // This forum has hidden topics
1181 + if ( ! empty( $deleted_int ) && current_user_can( 'edit_others_topics' ) ) {
1262 1182
1263 - // Hidden text
1264 - $deleted_num = bbp_get_forum_topic_count_hidden( $forum_id, false, false );
1265 - /* translators: %s: Number of hidden topics */
1266 - $extra = ' ' . sprintf( _n( '(+%s hidden)', '(+%s hidden)', $deleted_int, 'bbpress' ), $deleted_num );
1183 + // Hidden text
1184 + $deleted_num = bbp_get_forum_topic_count_hidden( $forum_id, false, false );
1185 + $extra = ' ' . sprintf( _n( '(+%s hidden)', '(+%s hidden)', $deleted_int, 'bbpress' ), $deleted_num );
1267 1186
1268 - // Hidden link
1269 - $retval .= ! bbp_get_view_all( 'edit_others_topics' )
1270 - ? " <a href='" . esc_url( bbp_add_view_all( $link, true ) ) . "'>" . esc_html( $extra ) . '</a>'
1271 - : " {$extra}";
1187 + // Hidden link
1188 + $retval .= ! bbp_get_view_all( 'edit_others_topics' )
1189 + ? " <a href='" . esc_url( bbp_add_view_all( $link, true ) ) . "'>" . esc_html( $extra ) . "</a>"
1190 + : " {$extra}";
1191 + }
1192 +
1193 + // Filter & return
1194 + return apply_filters( 'bbp_get_forum_topics_link', $retval, $forum_id );
1272 1195 }
1273 1196
1274 - // Filter & return
1275 - return apply_filters( 'bbp_get_forum_topics_link', $retval, $forum_id );
1276 -}
1277 -
1278 1197 /**
1279 - * Output total sub-forum count of a forum.
1198 + * Output total sub-forum count of a forum
1280 1199 *
1281 1200 * @since 2.0.0 bbPress (r2464)
1282 1201 *
1283 - * @param int $forum_id Optional. Forum id to check.
1284 - * @param boolean $integer Optional. Whether or not to format the result.
1202 + * @param int $forum_id Optional. Forum id to check
1203 + * @param boolean $integer Optional. Whether or not to format the result
1285 1204 */
1286 1205 function bbp_forum_subforum_count( $forum_id = 0, $integer = false ) {
1287 1206 echo bbp_get_forum_subforum_count( $forum_id, $integer );
1288 1207 }
1208 + /**
1209 + * Return total subforum count of a forum
1210 + *
1211 + * @since 2.0.0 bbPress (r2464)
1212 + *
1213 + * @param int $forum_id Optional. Forum id
1214 + * @param boolean $integer Optional. Whether or not to format the result
1215 + * @return int Forum's subforum count
1216 + */
1217 + function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) {
1218 + $forum_id = bbp_get_forum_id( $forum_id );
1219 + $forum_count = (int) get_post_meta( $forum_id, '_bbp_forum_subforum_count', true );
1220 + $filter = ( true === $integer )
1221 + ? 'bbp_get_forum_subforum_count_int'
1222 + : 'bbp_get_forum_subforum_count';
1289 1223
1290 -/**
1291 - * Return total subforum count of a forum.
1292 - *
1293 - * @since 2.0.0 bbPress (r2464)
1294 - *
1295 - * @param int $forum_id Optional. Forum id.
1296 - * @param boolean $integer Optional. Whether or not to format the result.
1297 - * @return int Forum's subforum count.
1298 - */
1299 -function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) {
1300 - $forum_id = bbp_get_forum_id( $forum_id );
1301 - $forum_count = (int) get_post_meta( $forum_id, '_bbp_forum_subforum_count', true );
1302 - $filter = ( true === $integer )
1303 - ? 'bbp_get_forum_subforum_count_int'
1304 - : 'bbp_get_forum_subforum_count';
1224 + return apply_filters( $filter, $forum_count, $forum_id );
1225 + }
1305 1226
1306 - return apply_filters( $filter, $forum_count, $forum_id );
1307 -}
1308 -
1309 1227 /**
1310 - * Output total topic count of a forum.
1228 + * Output total topic count of a forum
1311 1229 *
1312 1230 * @since 2.0.0 bbPress (r2464)
1313 1231 *
1314 - * @param int $forum_id Optional. Forum id.
1232 + * @param int $forum_id Optional. Forum id
1315 1233 * @param bool $total_count Optional. To get the total count or normal count?
1316 - * @param boolean $integer Optional. Whether or not to format the result.
1234 + * @param boolean $integer Optional. Whether or not to format the result
1317 1235 */
1318 1236 function bbp_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
1319 1237 echo bbp_get_forum_topic_count( $forum_id, $total_count, $integer );
1320 1238 }
1239 + /**
1240 + * Return total topic count of a forum
1241 + *
1242 + * @since 2.0.0 bbPress (r2464)
1243 + *
1244 + * @param int $forum_id Optional. Forum id
1245 + * @param bool $total_count Optional. To get the total count or normal
1246 + * count? Defaults to total.
1247 + * @param boolean $integer Optional. Whether or not to format the result
1248 + * @return int Forum topic count
1249 + */
1250 + function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
1251 + $forum_id = bbp_get_forum_id( $forum_id );
1252 + $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count';
1253 + $topics = (int) get_post_meta( $forum_id, $meta_key, true );
1254 + $filter = ( true === $integer )
1255 + ? 'bbp_get_forum_topic_count_int'
1256 + : 'bbp_get_forum_topic_count';
1321 1257
1322 -/**
1323 - * Return total topic count of a forum.
1324 - *
1325 - * @since 2.0.0 bbPress (r2464)
1326 - *
1327 - * @param int $forum_id Optional. Forum id.
1328 - * @param bool $total_count Optional. To get the total count or normal
1329 - * count? Defaults to total.
1330 - * @param boolean $integer Optional. Whether or not to format the result.
1331 - * @return int Forum topic count.
1332 - */
1333 -function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
1334 - $forum_id = bbp_get_forum_id( $forum_id );
1335 - $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count';
1336 - $topics = (int) get_post_meta( $forum_id, $meta_key, true );
1337 - $filter = ( true === $integer )
1338 - ? 'bbp_get_forum_topic_count_int'
1339 - : 'bbp_get_forum_topic_count';
1258 + return apply_filters( $filter, $topics, $forum_id );
1259 + }
1340 1260
1341 - return apply_filters( $filter, $topics, $forum_id );
1342 -}
1343 -
1344 1261 /**
1345 - * Output total reply count of a forum.
1262 + * Output total reply count of a forum
1346 1263 *
1347 1264 * @since 2.0.0 bbPress (r2464)
1348 1265 *
1349 - * @param int $forum_id Optional. Forum id.
1266 + * @param int $forum_id Optional. Forum id
1350 1267 * @param bool $total_count Optional. To get the total count or normal count?
1351 - * @param boolean $integer Optional. Whether or not to format the result.
1268 + * @param boolean $integer Optional. Whether or not to format the result
1352 1269 */
1353 1270 function bbp_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
1354 1271 echo bbp_get_forum_reply_count( $forum_id, $total_count, $integer );
1355 1272 }
1273 + /**
1274 + * Return total post count of a forum
1275 + *
1276 + * @since 2.0.0 bbPress (r2464)
1277 + *
1278 + * @param int $forum_id Optional. Forum id
1279 + * @param bool $total_count Optional. To get the total count or normal
1280 + * count?
1281 + * @param boolean $integer Optional. Whether or not to format the result
1282 + * @return int Forum reply count
1283 + */
1284 + function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
1285 + $forum_id = bbp_get_forum_id( $forum_id );
1286 + $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count';
1287 + $replies = (int) get_post_meta( $forum_id, $meta_key, true );
1288 + $filter = ( true === $integer )
1289 + ? 'bbp_get_forum_reply_count_int'
1290 + : 'bbp_get_forum_reply_count';
1356 1291
1357 -/**
1358 - * Return total post count of a forum.
1359 - *
1360 - * @since 2.0.0 bbPress (r2464)
1361 - *
1362 - * @param int $forum_id Optional. Forum id.
1363 - * @param bool $total_count Optional. To get the total count or normal
1364 - * count?
1365 - * @param boolean $integer Optional. Whether or not to format the result.
1366 - * @return int Forum reply count.
1367 - */
1368 -function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
1369 - $forum_id = bbp_get_forum_id( $forum_id );
1370 - $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count';
1371 - $replies = (int) get_post_meta( $forum_id, $meta_key, true );
1372 - $filter = ( true === $integer )
1373 - ? 'bbp_get_forum_reply_count_int'
1374 - : 'bbp_get_forum_reply_count';
1292 + return apply_filters( $filter, $replies, $forum_id );
1293 + }
1375 1294
1376 - return apply_filters( $filter, $replies, $forum_id );
1377 -}
1378 -
1379 1295 /**
1380 - * Output total post count of a forum.
1296 + * Output total post count of a forum
1381 1297 *
1382 1298 * @since 2.0.0 bbPress (r2954)
1383 1299 *
1384 - * @param int $forum_id Optional. Forum id.
1300 + * @param int $forum_id Optional. Forum id
1385 1301 * @param bool $total_count Optional. To get the total count or normal count?
1386 - * @param boolean $integer Optional. Whether or not to format the result.
1302 + * @param boolean $integer Optional. Whether or not to format the result
1387 1303 */
1388 1304 function bbp_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
1389 1305 echo bbp_get_forum_post_count( $forum_id, $total_count, $integer );
1390 1306 }
1307 + /**
1308 + * Return total post count of a forum
1309 + *
1310 + * @since 2.0.0 bbPress (r2954)
1311 + *
1312 + * @param int $forum_id Optional. Forum id
1313 + * @param bool $total_count Optional. To get the total count or normal
1314 + * count?
1315 + * @param boolean $integer Optional. Whether or not to format the result
1316 + * @return int Forum post count
1317 + */
1318 + function bbp_get_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
1319 + $forum_id = bbp_get_forum_id( $forum_id );
1320 + $topics = bbp_get_forum_topic_count( $forum_id, $total_count, true );
1321 + $replies = bbp_get_forum_reply_count( $forum_id, $total_count, true );
1322 + $retval = ( $replies + $topics );
1323 + $filter = ( true === $integer )
1324 + ? 'bbp_get_forum_post_count_int'
1325 + : 'bbp_get_forum_post_count';
1391 1326
1392 -/**
1393 - * Return total post count of a forum.
1394 - *
1395 - * @since 2.0.0 bbPress (r2954)
1396 - *
1397 - * @param int $forum_id Optional. Forum id.
1398 - * @param bool $total_count Optional. To get the total count or normal
1399 - * count?
1400 - * @param boolean $integer Optional. Whether or not to format the result.
1401 - * @return int Forum post count.
1402 - */
1403 -function bbp_get_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
1404 - $forum_id = bbp_get_forum_id( $forum_id );
1405 - $topics = bbp_get_forum_topic_count( $forum_id, $total_count, true );
1406 - $replies = bbp_get_forum_reply_count( $forum_id, $total_count, true );
1407 - $retval = ( $replies + $topics );
1408 - $filter = ( true === $integer )
1409 - ? 'bbp_get_forum_post_count_int'
1410 - : 'bbp_get_forum_post_count';
1327 + return apply_filters( $filter, $retval, $forum_id );
1328 + }
1411 1329
1412 - return apply_filters( $filter, $retval, $forum_id );
1413 -}
1414 -
1415 1330 /**
1416 1331 * Output total hidden topic count of a forum (hidden includes trashed, spammed,
1417 - * and pending topics).
1332 + * and pending topics)
1418 1333 *
1419 1334 * @since 2.0.0 bbPress (r2883)
1420 1335 * @since 2.6.0 bbPress (r6922) Changed function signature to add total counts
1421 1336 *
1422 - * @param int $forum_id Optional. Forum id.
1337 + * @param int $forum_id Optional. Forum id
1423 1338 * @param bool $total_count Optional. To get the total count or normal count?
1424 - * @param boolean $integer Optional. Whether or not to format the result.
1339 + * @param boolean $integer Optional. Whether or not to format the result
1425 1340 */
1426 1341 function bbp_forum_topic_count_hidden( $forum_id = 0, $total_count = true, $integer = null ) {
1427 1342 echo bbp_get_forum_topic_count_hidden( $forum_id, $total_count, $integer );
1428 1343 }
1344 + /**
1345 + * Return total hidden topic count of a forum (hidden includes trashed,
1346 + * spammed and pending topics)
1347 + *
1348 + * @since 2.0.0 bbPress (r2883)
1349 + * @since 2.6.0 bbPress (r6922) Changed function signature to add total counts
1350 + *
1351 + * @param int $forum_id Optional. Forum id
1352 + * @param bool $total_count Optional. To get the total count or normal count?
1353 + * @param boolean $integer Optional. Whether or not to format the result
1354 + * @return int Topic hidden topic count
1355 + */
1356 + function bbp_get_forum_topic_count_hidden( $forum_id = 0, $total_count = true, $integer = null ) {
1357 + $forum_id = bbp_get_forum_id( $forum_id );
1358 + $meta_key = empty( $total_count ) ? '_bbp_topic_count_hidden' : '_bbp_topic_reply_count_hidden';
1359 + $topics = (int) get_post_meta( $forum_id, $meta_key, true );
1360 + $filter = ( true === $integer )
1361 + ? 'bbp_get_forum_topic_count_hidden_int'
1362 + : 'bbp_get_forum_topic_count_hidden';
1429 1363
1430 -/**
1431 - * Return total hidden topic count of a forum (hidden includes trashed,
1432 - * spammed and pending topics).
1433 - *
1434 - * @since 2.0.0 bbPress (r2883)
1435 - * @since 2.6.0 bbPress (r6922) Changed function signature to add total counts
1436 - *
1437 - * @param int $forum_id Optional. Forum id.
1438 - * @param bool $total_count Optional. To get the total count or normal count?
1439 - * @param boolean $integer Optional. Whether or not to format the result.
1440 - * @return int Topic hidden topic count.
1441 - */
1442 -function bbp_get_forum_topic_count_hidden( $forum_id = 0, $total_count = true, $integer = null ) {
1443 - $forum_id = bbp_get_forum_id( $forum_id );
1444 - $meta_key = empty( $total_count ) ? '_bbp_topic_count_hidden' : '_bbp_total_topic_count_hidden';
1445 - $topics = (int) get_post_meta( $forum_id, $meta_key, true );
1446 - $filter = ( true === $integer )
1447 - ? 'bbp_get_forum_topic_count_hidden_int'
1448 - : 'bbp_get_forum_topic_count_hidden';
1364 + return apply_filters( $filter, $topics, $forum_id );
1365 + }
1449 1366
1450 - return apply_filters( $filter, $topics, $forum_id );
1451 -}
1452 -
1453 1367 /**
1454 1368 * Output total hidden reply count of a forum (hidden includes trashed, spammed,
1455 - * and pending replies).
1369 + * and pending replies)
1456 1370 *
1457 1371 * @since 2.6.0 bbPress (r6922)
1458 1372 *
1459 - * @param int $forum_id Optional. Forum id.
1373 + * @param int $forum_id Optional. Forum id
1460 1374 * @param bool $total_count Optional. To get the total count or normal count?
1461 - * @param boolean $integer Optional. Whether or not to format the result.
1375 + * @param boolean $integer Optional. Whether or not to format the result
1462 1376 */
1463 1377 function bbp_forum_reply_count_hidden( $forum_id = 0, $total_count = true, $integer = false ) {
1464 1378 echo bbp_get_forum_reply_count_hidden( $forum_id, $total_count, $integer );
1465 1379 }
1380 + /**
1381 + * Return total hidden reply count of a forum (hidden includes trashed,
1382 + * spammed and pending replies)
1383 + *
1384 + * @since 2.6.0 bbPress (r6922)
1385 + *
1386 + * @param int $forum_id Optional. Forum id
1387 + * @param bool $total_count Optional. To get the total count or normal
1388 + * count?
1389 + * @param boolean $integer Optional. Whether or not to format the result
1390 + * @return int Forum reply count
1391 + */
1392 + function bbp_get_forum_reply_count_hidden( $forum_id = 0, $total_count = true, $integer = false ) {
1393 + $forum_id = bbp_get_forum_id( $forum_id );
1394 + $meta_key = empty( $total_count ) ? '_bbp_reply_count_hidden' : '_bbp_total_reply_count_hidden';
1395 + $replies = (int) get_post_meta( $forum_id, $meta_key, true );
1396 + $filter = ( true === $integer )
1397 + ? 'bbp_get_forum_reply_count_hidden_int'
1398 + : 'bbp_get_forum_reply_count_hidden';
1466 1399
1467 -/**
1468 - * Return total hidden reply count of a forum (hidden includes trashed,
1469 - * spammed and pending replies).
1470 - *
1471 - * @since 2.6.0 bbPress (r6922)
1472 - *
1473 - * @param int $forum_id Optional. Forum id.
1474 - * @param bool $total_count Optional. To get the total count or normal
1475 - * count?
1476 - * @param boolean $integer Optional. Whether or not to format the result.
1477 - * @return int Forum reply count.
1478 - */
1479 -function bbp_get_forum_reply_count_hidden( $forum_id = 0, $total_count = true, $integer = false ) {
1480 - $forum_id = bbp_get_forum_id( $forum_id );
1481 - $meta_key = empty( $total_count ) ? '_bbp_reply_count_hidden' : '_bbp_total_reply_count_hidden';
1482 - $replies = (int) get_post_meta( $forum_id, $meta_key, true );
1483 - $filter = ( true === $integer )
1484 - ? 'bbp_get_forum_reply_count_hidden_int'
1485 - : 'bbp_get_forum_reply_count_hidden';
1400 + return apply_filters( $filter, $replies, $forum_id );
1401 + }
1486 1402
1487 - return apply_filters( $filter, $replies, $forum_id );
1488 -}
1489 -
1490 1403 /**
1491 - * Output the status of the forum.
1404 + * Output the status of the forum
1492 1405 *
1493 1406 * @since 2.0.0 bbPress (r2667)
1494 1407 *
1495 - * @param int $forum_id Optional. Forum id.
1408 + * @param int $forum_id Optional. Forum id
1496 1409 */
1497 1410 function bbp_forum_status( $forum_id = 0 ) {
1498 1411 echo bbp_get_forum_status( $forum_id );
1499 1412 }
1413 + /**
1414 + * Return the status of the forum
1415 + *
1416 + * @since 2.0.0 bbPress (r2667)
1417 + *
1418 + * @param int $forum_id Optional. Forum id
1419 + * @return string Status of forum
1420 + */
1421 + function bbp_get_forum_status( $forum_id = 0 ) {
1422 + $forum_id = bbp_get_forum_id( $forum_id );
1423 + $status = get_post_meta( $forum_id, '_bbp_status', true );
1500 1424
1501 -/**
1502 - * Return the status of the forum.
1503 - *
1504 - * @since 2.0.0 bbPress (r2667)
1505 - *
1506 - * @param int $forum_id Optional. Forum id.
1507 - * @return string Status of forum.
1508 - */
1509 -function bbp_get_forum_status( $forum_id = 0 ) {
1510 - $forum_id = bbp_get_forum_id( $forum_id );
1511 - $status = get_post_meta( $forum_id, '_bbp_status', true );
1425 + if ( empty( $status ) ) {
1426 + $status = 'open';
1427 + }
1512 1428
1513 - if ( empty( $status ) ) {
1514 - $status = 'open';
1429 + // Filter & return
1430 + return apply_filters( 'bbp_get_forum_status', $status, $forum_id );
1515 1431 }
1516 1432
1517 - // Filter & return
1518 - return apply_filters( 'bbp_get_forum_status', $status, $forum_id );
1519 -}
1520 -
1521 1433 /**
1522 - * Output the visibility of the forum.
1434 + * Output the visibility of the forum
1523 1435 *
1524 1436 * @since 2.0.0 bbPress (r2997)
1525 1437 *
1526 - * @param int $forum_id Optional. Forum id.
1438 + * @param int $forum_id Optional. Forum id
1527 1439 */
1528 1440 function bbp_forum_visibility( $forum_id = 0 ) {
1529 1441 echo bbp_get_forum_visibility( $forum_id );
1530 1442 }
1443 + /**
1444 + * Return the visibility of the forum
1445 + *
1446 + * @since 2.0.0 bbPress (r2997)
1447 + *
1448 + * @param int $forum_id Optional. Forum id
1449 + * @return string Status of forum
1450 + */
1451 + function bbp_get_forum_visibility( $forum_id = 0 ) {
1452 + $forum_id = bbp_get_forum_id( $forum_id );
1453 + $visibility = get_post_status( $forum_id );
1531 1454
1532 -/**
1533 - * Return the visibility of the forum.
1534 - *
1535 - * @since 2.0.0 bbPress (r2997)
1536 - *
1537 - * @param int $forum_id Optional. Forum id.
1538 - * @return string Status of forum.
1539 - */
1540 -function bbp_get_forum_visibility( $forum_id = 0 ) {
1541 - $forum_id = bbp_get_forum_id( $forum_id );
1542 - $visibility = get_post_status( $forum_id );
1455 + // Filter & return
1456 + return apply_filters( 'bbp_get_forum_visibility', $visibility, $forum_id );
1457 + }
1543 1458
1544 - // Filter & return
1545 - return apply_filters( 'bbp_get_forum_visibility', $visibility, $forum_id );
1546 -}
1547 -
1548 1459 /**
1549 - * Output the type of the forum.
1460 + * Output the type of the forum
1550 1461 *
1551 1462 * @since 2.1.0 bbPress (r3563)
1552 1463 *
1553 - * @param int $forum_id Optional. Forum id.
1464 + * @param int $forum_id Optional. Forum id
1554 1465 */
1555 1466 function bbp_forum_type( $forum_id = 0 ) {
1556 1467 echo bbp_get_forum_type( $forum_id );
1557 1468 }
1469 + /**
1470 + * Return the type of forum (category/forum/etc...)
1471 + *
1472 + * @since 2.1.0 bbPress (r3563)
1473 + *
1474 + * @param int $forum_id Optional. Forum id
1475 + * @return bool Whether the forum is a category or not
1476 + */
1477 + function bbp_get_forum_type( $forum_id = 0 ) {
1478 + $forum_id = bbp_get_forum_id( $forum_id );
1479 + $retval = get_post_meta( $forum_id, '_bbp_forum_type', true );
1558 1480
1559 -/**
1560 - * Return the type of forum (category/forum/etc...)
1561 - *
1562 - * @since 2.1.0 bbPress (r3563)
1563 - *
1564 - * @param int $forum_id Optional. Forum id.
1565 - * @return bool Whether the forum is a category or not.
1566 - */
1567 -function bbp_get_forum_type( $forum_id = 0 ) {
1568 - $forum_id = bbp_get_forum_id( $forum_id );
1569 - $retval = get_post_meta( $forum_id, '_bbp_forum_type', true );
1481 + if ( empty( $retval ) ) {
1482 + $retval = 'forum';
1483 + }
1570 1484
1571 - if ( empty( $retval ) ) {
1572 - $retval = 'forum';
1485 + // Filter & return
1486 + return apply_filters( 'bbp_get_forum_type', $retval, $forum_id );
1573 1487 }
1574 1488
1575 - // Filter & return
1576 - return apply_filters( 'bbp_get_forum_type', $retval, $forum_id );
1577 -}
1578 -
1579 1489 /**
1580 1490 * Is the forum a category?
1581 1491 *
1582 1492 * @since 2.0.0 bbPress (r2746)
1583 1493 *
1584 - * @param int $forum_id Optional. Forum id.
1585 - * @return bool Whether the forum is a category or not.
1494 + * @param int $forum_id Optional. Forum id
1495 + * @return bool Whether the forum is a category or not
1586 1496 */
1587 1497 function bbp_is_forum_category( $forum_id = 0 ) {
1588 1498 $forum_id = bbp_get_forum_id( $forum_id );
1589 1499 $type = bbp_get_forum_type( $forum_id );
@@ -1597,12 +1507,12 @@
1597 1507 * Is the forum open?
1598 1508 *
1599 1509 * @since 2.0.0 bbPress (r2746)
1600 1510 *
1601 - * @param int $forum_id Optional. Forum id.
1511 + * @param int $forum_id Optional. Forum id
1602 1512 * @param bool $check_ancestors Check if the ancestors are open (only
1603 - * if they're a category).
1604 - * @return bool Whether the forum is open or not.
1513 + * if they're a category)
1514 + * @return bool Whether the forum is open or not
1605 1515 */
1606 1516 function bbp_is_forum_open( $forum_id = 0, $check_ancestors = true ) {
1607 1517 return ! bbp_is_forum_closed( $forum_id, $check_ancestors );
1608 1518 }
@@ -1611,12 +1521,12 @@
1611 1521 * Is the forum closed?
1612 1522 *
1613 1523 * @since 2.0.0 bbPress (r2746)
1614 1524 *
1615 - * @param int $forum_id Optional. Forum id.
1525 + * @param int $forum_id Optional. Forum id
1616 1526 * @param bool $check_ancestors Check if the ancestors are closed (only
1617 - * if they're a category).
1618 - * @return bool True if closed, false if not.
1527 + * if they're a category)
1528 + * @return bool True if closed, false if not
1619 1529 */
1620 1530 function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) {
1621 1531
1622 1532 // Get the forum ID
@@ -1629,18 +1539,18 @@
1629 1539 return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
1630 1540 }
1631 1541
1632 1542 /**
1633 - * Check if the forum status is a specific one, also maybe checking ancestors.
1543 + * Check if the forum status is a specific one, also maybe checking ancestors
1634 1544 *
1635 1545 * @since 2.6.0 bbPress (r5499)
1636 1546 *
1637 - * @param bool $status_name The forum status name to check.
1638 - * @param bool $check_ancestors Check the forum ancestors.
1547 + * @param bool $status_name The forum status name to check
1548 + * @param bool $check_ancestors Check the forum ancestors
1639 1549 * @param string $operator The logical operation to perform.
1640 1550 * 'OR' means only one forum from the tree needs to match;
1641 1551 * 'AND' means all forums must match. The default is 'AND'.
1642 - * @return bool True if match, false if not.
1552 + * @return bool True if match, false if not
1643 1553 */
1644 1554 function bbp_is_forum_status( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) {
1645 1555
1646 1556 // Setup some default variables
@@ -1652,9 +1562,9 @@
1652 1562
1653 1563 // Quickly compare statuses of first forum ID
1654 1564 if ( $status_name === $forum_status ) {
1655 1565 $retval = true;
1656 - ++$count;
1566 + $count++;
1657 1567 }
1658 1568
1659 1569 // Let's check the forum's ancestors too
1660 1570 if ( ! empty( $check_ancestors ) ) {
@@ -1659,9 +1569,9 @@
1659 1569 // Let's check the forum's ancestors too
1660 1570 if ( ! empty( $check_ancestors ) ) {
1661 1571
1662 1572 // Adjust the ancestor check based on the count
1663 - switch ( $operator ) {
1573 + switch( $operator ) {
1664 1574 default:
1665 1575 case 'AND':
1666 1576 $check_ancestors = ( $count > 0 );
1667 1577 break;
@@ -1682,14 +1592,14 @@
1682 1592
1683 1593 // Check the ancestor forum status
1684 1594 $retval = bbp_is_forum_status( $ancestor, $status_name, false );
1685 1595 if ( true === $retval ) {
1686 - ++$count;
1596 + $count++;
1687 1597 }
1688 1598 }
1689 1599
1690 1600 // Break when it reach the max count
1691 - if ( ( 'OR' === $operator ) && ( $count >= 1 ) ) {
1601 + if ( ( $operator === 'OR' ) && ( $count >= 1 ) ) {
1692 1602 break;
1693 1603 }
1694 1604 }
1695 1605 }
@@ -1703,11 +1613,11 @@
1703 1613 * Is the forum public?
1704 1614 *
1705 1615 * @since 2.0.0 bbPress (r2997)
1706 1616 *
1707 - * @param int $forum_id Optional. Forum id.
1708 - * @param bool $check_ancestors Check if the ancestors are public.
1709 - * @return bool True if closed, false if not.
1617 + * @param int $forum_id Optional. Forum id
1618 + * @param bool $check_ancestors Check if the ancestors are public
1619 + * @return bool True if closed, false if not
1710 1620 */
1711 1621 function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) {
1712 1622
1713 1623 // Get the forum ID
@@ -1724,11 +1634,11 @@
1724 1634 * Is the forum private?
1725 1635 *
1726 1636 * @since 2.0.0 bbPress (r2746)
1727 1637 *
1728 - * @param int $forum_id Optional. Forum id.
1729 - * @param bool $check_ancestors Check if the ancestors are private.
1730 - * @return bool True if private, false if not.
1638 + * @param int $forum_id Optional. Forum id
1639 + * @param bool $check_ancestors Check if the ancestors are private
1640 + * @return bool True if private, false if not
1731 1641 */
1732 1642 function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) {
1733 1643
1734 1644 // Get the forum ID
@@ -1745,12 +1655,12 @@
1745 1655 * Is the forum hidden?
1746 1656 *
1747 1657 * @since 2.0.0 bbPress (r2997)
1748 1658 *
1749 - * @param int $forum_id Optional. Forum id.
1659 + * @param int $forum_id Optional. Forum id
1750 1660 * @param bool $check_ancestors Check if the ancestors are private (only if
1751 - * they're a category).
1752 - * @return bool True if hidden, false if not.
1661 + * they're a category)
1662 + * @return bool True if hidden, false if not
1753 1663 */
1754 1664 function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) {
1755 1665
1756 1666 // Get the forum ID
@@ -1763,19 +1673,19 @@
1763 1673 return (bool) apply_filters( 'bbp_is_forum_hidden', $retval, $forum_id, $check_ancestors );
1764 1674 }
1765 1675
1766 1676 /**
1767 - * Check the forum visibility ID.
1677 + * Check the forum visibility ID
1768 1678 *
1769 1679 * @since 2.6.0 bbPress (r5499)
1770 1680 *
1771 - * @param int $forum_id Optional. Forum id.
1772 - * @param bool $status_name The post status name to check.
1773 - * @param bool $check_ancestors Check the forum ancestors.
1681 + * @param int $forum_id Optional. Forum id
1682 + * @param bool $status_name The post status name to check
1683 + * @param bool $check_ancestors Check the forum ancestors
1774 1684 * @param string $operator The logical operation to perform.
1775 1685 * 'OR' means only one forum from the tree needs to match;
1776 1686 * 'AND' means all forums must match. The default is 'AND'.
1777 - * @return bool True if match, false if not.
1687 + * @return bool True if match, false if not
1778 1688 */
1779 1689 function bbp_is_forum_visibility( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) {
1780 1690
1781 1691 // Setup some default variables
@@ -1787,9 +1697,9 @@
1787 1697
1788 1698 // Quickly compare visibility of first forum ID
1789 1699 if ( $status_name === $visibility ) {
1790 1700 $retval = true;
1791 - ++$count;
1701 + $count++;
1792 1702 }
1793 1703
1794 1704 // Let's check the forum's ancestors too
1795 1705 if ( ! empty( $check_ancestors ) ) {
@@ -1819,14 +1729,14 @@
1819 1729
1820 1730 // Check the forum visibility
1821 1731 $retval = bbp_is_forum_visibility( $ancestor, $status_name, false );
1822 1732 if ( true === $retval ) {
1823 - ++$count;
1733 + $count++;
1824 1734 }
1825 1735 }
1826 1736
1827 1737 // Break when it reach the max count
1828 - if ( ( 'OR' === $operator ) && ( $count >= 1 ) ) {
1738 + if ( ( $operator === 'OR' ) && ( $count >= 1 ) ) {
1829 1739 break;
1830 1740 }
1831 1741 }
1832 1742 }
@@ -1836,63 +1746,61 @@
1836 1746 return (bool) apply_filters( 'bbp_is_forum_visibility', $retval, $count, $forum_id, $status_name, $check_ancestors, $operator );
1837 1747 }
1838 1748
1839 1749 /**
1840 - * Output the author ID of the forum.
1750 + * Output the author ID of the forum
1841 1751 *
1842 1752 * @since 2.1.0 bbPress (r3675)
1843 1753 *
1844 - * @param int $forum_id Optional. Forum id.
1754 + * @param int $forum_id Optional. Forum id
1845 1755 */
1846 1756 function bbp_forum_author_id( $forum_id = 0 ) {
1847 1757 echo bbp_get_forum_author_id( $forum_id );
1848 1758 }
1759 + /**
1760 + * Return the author ID of the forum
1761 + *
1762 + * @since 2.1.0 bbPress (r3675)
1763 + *
1764 + * @param int $forum_id Optional. Forum id
1765 + * id and forum id
1766 + * @return string Author of forum
1767 + */
1768 + function bbp_get_forum_author_id( $forum_id = 0 ) {
1769 + $forum_id = bbp_get_forum_id( $forum_id );
1770 + $author_id = get_post_field( 'post_author', $forum_id );
1849 1771
1850 -/**
1851 - * Return the author ID of the forum.
1852 - *
1853 - * @since 2.1.0 bbPress (r3675)
1854 - *
1855 - * @param int $forum_id Optional. Forum id.
1856 - *
1857 - * @return string Author of forum.
1858 - */
1859 -function bbp_get_forum_author_id( $forum_id = 0 ) {
1860 - $forum_id = bbp_get_forum_id( $forum_id );
1861 - $author_id = get_post_field( 'post_author', $forum_id );
1772 + // Filter & return
1773 + return (int) apply_filters( 'bbp_get_forum_author_id', (int) $author_id, $forum_id );
1774 + }
1862 1775
1863 - // Filter & return
1864 - return (int) apply_filters( 'bbp_get_forum_author_id', (int) $author_id, $forum_id );
1865 -}
1866 -
1867 1776 /**
1868 - * Output the author of the forum.
1777 + * Output the author of the forum
1869 1778 *
1870 1779 * @since 2.1.0 bbPress (r3675)
1871 1780 *
1872 - * @param int $forum_id Optional. Forum id.
1781 + * @param int $forum_id Optional. Forum id
1873 1782 */
1874 1783 function bbp_forum_author_display_name( $forum_id = 0 ) {
1875 1784 echo bbp_get_forum_author_display_name( $forum_id );
1876 1785 }
1786 + /**
1787 + * Return the author of the forum
1788 + *
1789 + * @since 2.1.0 bbPress (r3675)
1790 + *
1791 + * @param int $forum_id Optional. Forum id
1792 + * @return string Author of forum
1793 + */
1794 + function bbp_get_forum_author_display_name( $forum_id = 0 ) {
1795 + $forum_id = bbp_get_forum_id( $forum_id );
1796 + $author_id = bbp_get_forum_author_id( $forum_id );
1797 + $author = get_the_author_meta( 'display_name', $author_id );
1877 1798
1878 -/**
1879 - * Return the author of the forum.
1880 - *
1881 - * @since 2.1.0 bbPress (r3675)
1882 - *
1883 - * @param int $forum_id Optional. Forum id.
1884 - * @return string Author of forum.
1885 - */
1886 -function bbp_get_forum_author_display_name( $forum_id = 0 ) {
1887 - $forum_id = bbp_get_forum_id( $forum_id );
1888 - $author_id = bbp_get_forum_author_id( $forum_id );
1889 - $author = get_the_author_meta( 'display_name', $author_id );
1799 + // Filter & return
1800 + return apply_filters( 'bbp_get_forum_author_display_name', $author, $forum_id, $author_id );
1801 + }
1890 1802
1891 - // Filter & return
1892 - return apply_filters( 'bbp_get_forum_author_display_name', $author, $forum_id, $author_id );
1893 -}
1894 -
1895 1803 /**
1896 1804 * Replace forum meta details for users that cannot view them.
1897 1805 *
1898 1806 * @since 2.0.0 bbPress (r3162)
@@ -1958,88 +1866,87 @@
1958 1866 return apply_filters( 'bbp_suppress_private_author_link', $retval, $author_link, $args );
1959 1867 }
1960 1868
1961 1869 /**
1962 - * Output the row class of a forum.
1870 + * Output the row class of a forum
1963 1871 *
1964 1872 * @since 2.0.0 bbPress (r2667)
1965 1873 *
1966 1874 * @param int $forum_id Optional. Forum ID.
1967 - * @param array Extra classes you can pass when calling this function.
1875 + * @param array Extra classes you can pass when calling this function
1968 1876 */
1969 1877 function bbp_forum_class( $forum_id = 0, $classes = array() ) {
1970 1878 echo bbp_get_forum_class( $forum_id, $classes );
1971 1879 }
1880 + /**
1881 + * Return the row class of a forum
1882 + *
1883 + * @since 2.0.0 bbPress (r2667)
1884 + *
1885 + * @param int $forum_id Optional. Forum ID
1886 + * @param array Extra classes you can pass when calling this function
1887 + * @return string Row class of the forum
1888 + */
1889 + function bbp_get_forum_class( $forum_id = 0, $classes = array() ) {
1890 + $bbp = bbpress();
1891 + $forum_id = bbp_get_forum_id( $forum_id );
1892 + $parent_id = bbp_get_forum_parent_id( $forum_id );
1893 + $author_id = bbp_get_forum_author_id( $forum_id );
1894 + $status = bbp_get_forum_status( $forum_id );
1895 + $visibility = bbp_get_forum_visibility( $forum_id );
1896 + $classes = array_filter( (array) $classes );
1897 + $count = isset( $bbp->forum_query->current_post )
1898 + ? (int) $bbp->forum_query->current_post
1899 + : 1;
1972 1900
1973 -/**
1974 - * Return the row class of a forum.
1975 - *
1976 - * @since 2.0.0 bbPress (r2667)
1977 - *
1978 - * @param int $forum_id Optional. Forum ID.
1979 - * @param array Extra classes you can pass when calling this function.
1980 - * @return string Row class of the forum.
1981 - */
1982 -function bbp_get_forum_class( $forum_id = 0, $classes = array() ) {
1983 - $bbp = bbpress();
1984 - $forum_id = bbp_get_forum_id( $forum_id );
1985 - $parent_id = bbp_get_forum_parent_id( $forum_id );
1986 - $author_id = bbp_get_forum_author_id( $forum_id );
1987 - $status = bbp_get_forum_status( $forum_id );
1988 - $visibility = bbp_get_forum_visibility( $forum_id );
1989 - $classes = array_filter( (array) $classes );
1990 - $count = isset( $bbp->forum_query->current_post )
1991 - ? (int) $bbp->forum_query->current_post
1992 - : 1;
1901 + // Stripes
1902 + $even_odd = ( $count % 2 )
1903 + ? 'even'
1904 + : 'odd';
1993 1905
1994 - // Stripes
1995 - $even_odd = ( $count % 2 )
1996 - ? 'even'
1997 - : 'odd';
1906 + // User is moderator of forum
1907 + $forum_moderator = ( bbp_is_user_forum_moderator( $author_id, $forum_id ) === $author_id )
1908 + ? 'forum-mod'
1909 + : '';
1998 1910
1999 - // User is moderator of forum
2000 - $forum_moderator = ( bbp_is_user_forum_moderator( $author_id, $forum_id ) === $author_id )
2001 - ? 'forum-mod'
2002 - : '';
1911 + // Is forum a non-postable category?
1912 + $category = bbp_is_forum_category( $forum_id )
1913 + ? 'status-category'
1914 + : '';
2003 1915
2004 - // Is forum a non-postable category?
2005 - $category = bbp_is_forum_category( $forum_id )
2006 - ? 'status-category'
2007 - : '';
1916 + // Forum has children?
1917 + $subs = bbp_get_forum_subforum_count( $forum_id )
1918 + ? 'bbp-has-subforums'
1919 + : '';
2008 1920
2009 - // Forum has children?
2010 - $subs = bbp_get_forum_subforum_count( $forum_id )
2011 - ? 'bbp-has-subforums'
2012 - : '';
1921 + // Forum has parent?
1922 + $parent = ! empty( $parent_id )
1923 + ? 'bbp-parent-forum-' . $parent_id
1924 + : '';
2013 1925
2014 - // Forum has parent?
2015 - $parent = ! empty( $parent_id )
2016 - ? 'bbp-parent-forum-' . $parent_id
2017 - : '';
1926 + // Get forum classes
1927 + $forum_classes = array(
1928 + 'loop-item-' . $count,
1929 + 'bbp-forum-status-' . $status,
1930 + 'bbp-forum-visibility-' . $visibility,
1931 + $even_odd,
1932 + $forum_moderator,
1933 + $category,
1934 + $subs,
1935 + $parent
1936 + );
2018 1937
2019 - // Get forum classes
2020 - $forum_classes = array(
2021 - 'loop-item-' . $count,
2022 - 'bbp-forum-status-' . $status,
2023 - 'bbp-forum-visibility-' . $visibility,
2024 - $even_odd,
2025 - $forum_moderator,
2026 - $category,
2027 - $subs,
2028 - $parent
2029 - );
1938 + // Run the topic classes through the post-class filters, which also
1939 + // handles the escaping of each individual class.
1940 + $post_classes = get_post_class( array_merge( $classes, $forum_classes ), $forum_id );
2030 1941
2031 - // Run the topic classes through the post-class filters, which also
2032 - // handles the escaping of each individual class.
2033 - $post_classes = get_post_class( array_merge( $classes, $forum_classes ), $forum_id );
1942 + // Filter
1943 + $new_classes = apply_filters( 'bbp_get_forum_class', $post_classes, $forum_id, $classes );
2034 1944
2035 - // Filter
2036 - $new_classes = apply_filters( 'bbp_get_forum_class', $post_classes, $forum_id, $classes );
1945 + // Return
1946 + return 'class="' . implode( ' ', $new_classes ) . '"';
1947 + }
2037 1948
2038 - // Return
2039 - return 'class="' . implode( ' ', $new_classes ) . '"';
2040 -}
2041 -
2042 1949 /** Single Forum **************************************************************/
2043 1950
2044 1951 /**
2045 1952 * Output a fancy description of the current forum, including total topics,
@@ -2046,133 +1953,113 @@
2046 1953 * total replies, and last activity.
2047 1954 *
2048 1955 * @since 2.0.0 bbPress (r2860)
2049 1956 *
2050 - * @param array $args Arguments passed to alter output.
1957 + * @param array $args Arguments passed to alter output
2051 1958 */
2052 1959 function bbp_single_forum_description( $args = array() ) {
2053 1960 echo bbp_get_single_forum_description( $args );
2054 1961 }
1962 + /**
1963 + * Return a fancy description of the current forum, including total
1964 + * topics, total replies, and last activity.
1965 + *
1966 + * @since 2.0.0 bbPress (r2860)
1967 + *
1968 + * @param array $args This function supports these arguments:
1969 + * - forum_id: Forum id
1970 + * - before: Before the text
1971 + * - after: After the text
1972 + * - size: Size of the avatar
1973 + * @return string Filtered forum description
1974 + */
1975 + function bbp_get_single_forum_description( $args = array() ) {
2055 1976
2056 -/**
2057 - * Return a fancy description of the current forum, including total
2058 - * topics, total replies, and last activity.
2059 - *
2060 - * @since 2.0.0 bbPress (r2860)
2061 - *
2062 - * @param array $args This function supports these arguments:
2063 - * - forum_id: Forum id
2064 - * - before: Before the text
2065 - * - after: After the text
2066 - * - size: Size of the avatar
2067 - * @return string Filtered forum description.
2068 - */
2069 -function bbp_get_single_forum_description( $args = array() ) {
2070 -
2071 - // Parse arguments against default values
2072 - $r = bbp_parse_args(
2073 - $args,
2074 - array(
1977 + // Parse arguments against default values
1978 + $r = bbp_parse_args( $args, array(
2075 1979 'forum_id' => 0,
2076 1980 'before' => '<div class="bbp-template-notice info"><ul><li class="bbp-forum-description">',
2077 1981 'after' => '</li></ul></div>',
2078 1982 'size' => 14,
2079 1983 'feed' => true
2080 - ),
2081 - 'get_single_forum_description'
2082 - );
1984 + ), 'get_single_forum_description' );
2083 1985
2084 - // Validate forum_id
2085 - $forum_id = bbp_get_forum_id( $r['forum_id'] );
1986 + // Validate forum_id
1987 + $forum_id = bbp_get_forum_id( $r['forum_id'] );
2086 1988
2087 - // Unhook the 'view all' query var adder
2088 - remove_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
1989 + // Unhook the 'view all' query var adder
1990 + remove_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
2089 1991
2090 - // Get some forum data
2091 - $tc_int = bbp_get_forum_topic_count( $forum_id, true, true );
2092 - $rc_int = bbp_get_forum_reply_count( $forum_id, true, true );
2093 - $topic_count = bbp_get_forum_topic_count( $forum_id, true, false );
2094 - $reply_count = bbp_get_forum_reply_count( $forum_id, true, false );
2095 - $last_active = bbp_get_forum_last_active_id( $forum_id );
1992 + // Get some forum data
1993 + $tc_int = bbp_get_forum_topic_count( $forum_id, true, true );
1994 + $rc_int = bbp_get_forum_reply_count( $forum_id, true, true );
1995 + $topic_count = bbp_get_forum_topic_count( $forum_id, true, false );
1996 + $reply_count = bbp_get_forum_reply_count( $forum_id, true, false );
1997 + $last_active = bbp_get_forum_last_active_id( $forum_id );
2096 1998
2097 - // Has replies
2098 - if ( ! empty( $reply_count ) ) {
2099 - /* translators: %s: Number of replies */
2100 - $reply_text = sprintf( _n( '%s reply', '%s replies', $rc_int, 'bbpress' ), $reply_count );
2101 - }
1999 + // Has replies
2000 + if ( ! empty( $reply_count ) ) {
2001 + $reply_text = sprintf( _n( '%s reply', '%s replies', $rc_int, 'bbpress' ), $reply_count );
2002 + }
2102 2003
2103 - // Forum has active data
2104 - if ( ! empty( $last_active ) ) {
2105 - $topic_text = bbp_get_forum_topics_link( $forum_id );
2106 - $time_since = bbp_get_forum_freshness_link( $forum_id );
2107 - $last_updated_by = bbp_get_author_link(
2108 - array(
2109 - 'post_id' => $last_active,
2110 - 'size' => $r['size']
2111 - )
2112 - );
2004 + // Forum has active data
2005 + if ( ! empty( $last_active ) ) {
2006 + $topic_text = bbp_get_forum_topics_link( $forum_id );
2007 + $time_since = bbp_get_forum_freshness_link( $forum_id );
2008 + $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_active, 'size' => $r['size'] ) );
2113 2009
2114 - // Forum has no last active data
2115 - } else {
2116 - /* translators: %s: Number of topics */
2117 - $topic_text = sprintf( _n( '%s topic', '%s topics', $tc_int, 'bbpress' ), $topic_count );
2118 - }
2010 + // Forum has no last active data
2011 + } else {
2012 + $topic_text = sprintf( _n( '%s topic', '%s topics', $tc_int, 'bbpress' ), $topic_count );
2013 + }
2119 2014
2120 - // Forum has active data
2121 - if ( ! empty( $last_active ) ) {
2015 + // Forum has active data
2016 + if ( ! empty( $last_active ) ) {
2122 2017
2123 - // Has replies
2124 - if ( ! empty( $reply_count ) ) {
2018 + // Has replies
2019 + if ( ! empty( $reply_count ) ) {
2020 + $retstr = bbp_is_forum_category( $forum_id )
2021 + ? sprintf( esc_html__( 'This category has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $topic_text, $reply_text, $time_since, $last_updated_by )
2022 + : sprintf( esc_html__( 'This forum has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $topic_text, $reply_text, $time_since, $last_updated_by );
2023 +
2024 + // Only has topics
2025 + } else {
2026 + $retstr = bbp_is_forum_category( $forum_id )
2027 + ? sprintf( esc_html__( 'This category has %1$s, and was last updated %2$s by %3$s.', 'bbpress' ), $topic_text, $time_since, $last_updated_by )
2028 + : sprintf( esc_html__( 'This forum has %1$s, and was last updated %2$s by %3$s.', 'bbpress' ), $topic_text, $time_since, $last_updated_by );
2029 + }
2030 +
2031 + // Forum has no last active data (but does have topics & replies)
2032 + } elseif ( ! empty( $reply_count ) ) {
2125 2033 $retstr = bbp_is_forum_category( $forum_id )
2126 - /* translators: 1: Topics link, 2: Replies text, 3: Last update time, 4: Author link */
2127 - ? sprintf( esc_html__( 'This category has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $topic_text, $reply_text, $time_since, $last_updated_by )
2128 - /* translators: 1: Topics link, 2: Replies text, 3: Last update time, 4: Author link */
2129 - : sprintf( esc_html__( 'This forum has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $topic_text, $reply_text, $time_since, $last_updated_by );
2034 + ? sprintf( esc_html__( 'This category has %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text )
2035 + : sprintf( esc_html__( 'This forum has %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text );
2130 2036
2131 - // Only has topics
2037 + // Forum has no last active data or replies (but does have topics)
2038 + } elseif ( ! empty( $topic_count ) ) {
2039 + $retstr = bbp_is_forum_category( $forum_id )
2040 + ? sprintf( esc_html__( 'This category has %1$s.', 'bbpress' ), $topic_text )
2041 + : sprintf( esc_html__( 'This forum has %1$s.', 'bbpress' ), $topic_text );
2042 +
2043 + // Forum is empty
2132 2044 } else {
2133 - $retstr = bbp_is_forum_category( $forum_id )
2134 - /* translators: 1: Topics link, 2: Last update time, 3: Author link */
2135 - ? sprintf( esc_html__( 'This category has %1$s, and was last updated %2$s by %3$s.', 'bbpress' ), $topic_text, $time_since, $last_updated_by )
2136 - /* translators: 1: Topics link, 2: Last update time, 3: Author link */
2137 - : sprintf( esc_html__( 'This forum has %1$s, and was last updated %2$s by %3$s.', 'bbpress' ), $topic_text, $time_since, $last_updated_by );
2045 + $retstr = esc_html__( 'This forum is empty.', 'bbpress' );
2138 2046 }
2139 2047
2140 - // Forum has no last active data (but does have topics & replies)
2141 - } elseif ( ! empty( $reply_count ) ) {
2142 - $retstr = bbp_is_forum_category( $forum_id )
2143 - /* translators: 1: Topics link, 2: Replies text */
2144 - ? sprintf( esc_html__( 'This category has %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text )
2145 - /* translators: 1: Topics link, 2: Replies text */
2146 - : sprintf( esc_html__( 'This forum has %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text );
2048 + // Add the 'view all' filter back
2049 + add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
2147 2050
2148 - // Forum has no last active data or replies (but does have topics)
2149 - } elseif ( ! empty( $topic_count ) ) {
2150 - $retstr = bbp_is_forum_category( $forum_id )
2151 - /* translators: 1: Topics link */
2152 - ? sprintf( esc_html__( 'This category has %1$s.', 'bbpress' ), $topic_text )
2153 - /* translators: 1: Topics link */
2154 - : sprintf( esc_html__( 'This forum has %1$s.', 'bbpress' ), $topic_text );
2051 + // Combine the elements together
2052 + $retstr = $r['before'] . $retstr . $r['after'];
2155 2053
2156 - // Forum is empty
2157 - } else {
2158 - $retstr = esc_html__( 'This forum is empty.', 'bbpress' );
2054 + // Filter & return
2055 + return apply_filters( 'bbp_get_single_forum_description', $retstr, $r, $args );
2159 2056 }
2160 2057
2161 - // Add the 'view all' filter back
2162 - add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
2163 -
2164 - // Combine the elements together
2165 - $retstr = $r['before'] . $retstr . $r['after'];
2166 -
2167 - // Filter & return
2168 - return apply_filters( 'bbp_get_single_forum_description', $retstr, $r, $args );
2169 -}
2170 -
2171 2058 /** Forms *********************************************************************/
2172 2059
2173 2060 /**
2174 - * Output the value of forum title field.
2061 + * Output the value of forum title field
2175 2062 *
2176 2063 * @since 2.1.0 bbPress (r3551)
2177 2064 */
2178 2065 function bbp_form_forum_title() {
@@ -2177,37 +2064,36 @@
2177 2064 */
2178 2065 function bbp_form_forum_title() {
2179 2066 echo bbp_get_form_forum_title();
2180 2067 }
2068 + /**
2069 + * Return the value of forum title field
2070 + *
2071 + * @since 2.1.0 bbPress (r3551)
2072 + *
2073 + * @return string Value of forum title field
2074 + */
2075 + function bbp_get_form_forum_title() {
2181 2076
2182 -/**
2183 - * Return the value of forum title field.
2184 - *
2185 - * @since 2.1.0 bbPress (r3551)
2186 - *
2187 - * @return string Value of forum title field.
2188 - */
2189 -function bbp_get_form_forum_title() {
2077 + // Get _POST data
2078 + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_title'] ) ) {
2079 + $forum_title = wp_unslash( $_POST['bbp_forum_title'] );
2190 2080
2191 - // Get _POST data
2192 - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_title'] ) ) {
2193 - $forum_title = wp_unslash( $_POST['bbp_forum_title'] );
2081 + // Get edit data
2082 + } elseif ( bbp_is_forum_edit() ) {
2083 + $forum_title = bbp_get_global_post_field( 'post_title', 'raw' );
2194 2084
2195 - // Get edit data
2196 - } elseif ( bbp_is_forum_edit() ) {
2197 - $forum_title = bbp_get_global_post_field( 'post_title', 'raw' );
2085 + // No data
2086 + } else {
2087 + $forum_title = '';
2088 + }
2198 2089
2199 - // No data
2200 - } else {
2201 - $forum_title = '';
2090 + // Filter & return
2091 + return apply_filters( 'bbp_get_form_forum_title', $forum_title );
2202 2092 }
2203 2093
2204 - // Filter & return
2205 - return apply_filters( 'bbp_get_form_forum_title', $forum_title );
2206 -}
2207 -
2208 2094 /**
2209 - * Output the value of forum content field.
2095 + * Output the value of forum content field
2210 2096 *
2211 2097 * @since 2.1.0 bbPress (r3551)
2212 2098 */
2213 2099 function bbp_form_forum_content() {
@@ -2212,37 +2098,36 @@
2212 2098 */
2213 2099 function bbp_form_forum_content() {
2214 2100 echo bbp_get_form_forum_content();
2215 2101 }
2102 + /**
2103 + * Return the value of forum content field
2104 + *
2105 + * @since 2.1.0 bbPress (r3551)
2106 + *
2107 + * @return string Value of forum content field
2108 + */
2109 + function bbp_get_form_forum_content() {
2216 2110
2217 -/**
2218 - * Return the value of forum content field.
2219 - *
2220 - * @since 2.1.0 bbPress (r3551)
2221 - *
2222 - * @return string Value of forum content field.
2223 - */
2224 -function bbp_get_form_forum_content() {
2111 + // Get _POST data
2112 + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_content'] ) ) {
2113 + $forum_content = wp_unslash( $_POST['bbp_forum_content'] );
2225 2114
2226 - // Get _POST data
2227 - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_content'] ) ) {
2228 - $forum_content = wp_unslash( $_POST['bbp_forum_content'] );
2115 + // Get edit data
2116 + } elseif ( bbp_is_forum_edit() ) {
2117 + $forum_content = bbp_get_global_post_field( 'post_content', 'raw' );
2229 2118
2230 - // Get edit data
2231 - } elseif ( bbp_is_forum_edit() ) {
2232 - $forum_content = bbp_get_global_post_field( 'post_content', 'raw' );
2119 + // No data
2120 + } else {
2121 + $forum_content = '';
2122 + }
2233 2123
2234 - // No data
2235 - } else {
2236 - $forum_content = '';
2124 + // Filter & return
2125 + return apply_filters( 'bbp_get_form_forum_content', $forum_content );
2237 2126 }
2238 2127
2239 - // Filter & return
2240 - return apply_filters( 'bbp_get_form_forum_content', $forum_content );
2241 -}
2242 -
2243 2128 /**
2244 - * Output value of forum moderators field.
2129 + * Output value of forum moderators field
2245 2130 *
2246 2131 * @since 2.6.0 bbPress (r5837)
2247 2132 */
2248 2133 function bbp_form_forum_moderators() {
@@ -2247,53 +2132,52 @@
2247 2132 */
2248 2133 function bbp_form_forum_moderators() {
2249 2134 echo bbp_get_form_forum_moderators();
2250 2135 }
2136 + /**
2137 + * Return value of forum moderators field
2138 + *
2139 + * @since 2.6.0 bbPress (r5837)
2140 + *
2141 + * @return string Value of forum mods field
2142 + */
2143 + function bbp_get_form_forum_moderators() {
2251 2144
2252 -/**
2253 - * Return value of forum moderators field.
2254 - *
2255 - * @since 2.6.0 bbPress (r5837)
2256 - *
2257 - * @return string Value of forum mods field.
2258 - */
2259 -function bbp_get_form_forum_moderators() {
2145 + // Default return value
2146 + $forum_mods = '';
2260 2147
2261 - // Default return value
2262 - $forum_mods = '';
2148 + // Get _POST data
2149 + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_moderators'] ) ) {
2150 + $forum_mods = wp_unslash( $_POST['bbp_moderators'] );
2263 2151
2264 - // Get _POST data
2265 - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_moderators'] ) ) {
2266 - $forum_mods = wp_unslash( $_POST['bbp_moderators'] );
2152 + // Get edit data
2153 + } elseif ( bbp_is_single_forum() || bbp_is_forum_edit() ) {
2267 2154
2268 - // Get edit data
2269 - } elseif ( bbp_is_single_forum() || bbp_is_forum_edit() ) {
2155 + // Get the forum ID
2156 + $forum_id = bbp_get_forum_id( get_the_ID() );
2270 2157
2271 - // Get the forum ID
2272 - $forum_id = bbp_get_forum_id( get_the_ID() );
2158 + // Forum exists
2159 + if ( ! empty( $forum_id ) ) {
2273 2160
2274 - // Forum exists
2275 - if ( ! empty( $forum_id ) ) {
2161 + // Get moderator IDs
2162 + $user_ids = bbp_get_moderator_ids( $forum_id );
2163 + if ( ! empty( $user_ids ) ) {
2164 + $user_nicenames = bbp_get_user_nicenames_from_ids( $user_ids );
2276 2165
2277 - // Get moderator IDs
2278 - $user_ids = bbp_get_moderator_ids( $forum_id );
2279 - if ( ! empty( $user_ids ) ) {
2280 - $user_nicenames = bbp_get_user_nicenames_from_ids( $user_ids );
2281 -
2282 - // Comma separate user nicenames
2283 - if ( ! empty( $user_nicenames ) ) {
2284 - $forum_mods = implode( ', ', wp_list_pluck( $user_nicenames, 'user_nicename' ) );
2166 + // Comma separate user nicenames
2167 + if ( ! empty( $user_nicenames ) ) {
2168 + $forum_mods = implode( ', ', wp_list_pluck( $user_nicenames, 'user_nicename' ) );
2169 + }
2285 2170 }
2286 2171 }
2287 2172 }
2173 +
2174 + // Filter & return
2175 + return apply_filters( 'bbp_get_form_forum_moderators', $forum_mods );
2288 2176 }
2289 2177
2290 - // Filter & return
2291 - return apply_filters( 'bbp_get_form_forum_moderators', $forum_mods );
2292 -}
2293 -
2294 2178 /**
2295 - * Output value of forum parent.
2179 + * Output value of forum parent
2296 2180 *
2297 2181 * @since 2.1.0 bbPress (r3551)
2298 2182 */
2299 2183 function bbp_form_forum_parent() {
@@ -2298,37 +2182,36 @@
2298 2182 */
2299 2183 function bbp_form_forum_parent() {
2300 2184 echo bbp_get_form_forum_parent();
2301 2185 }
2186 + /**
2187 + * Return value of forum parent
2188 + *
2189 + * @since 2.1.0 bbPress (r3551)
2190 + *
2191 + * @return string Value of topic content field
2192 + */
2193 + function bbp_get_form_forum_parent() {
2302 2194
2303 -/**
2304 - * Return value of forum parent.
2305 - *
2306 - * @since 2.1.0 bbPress (r3551)
2307 - *
2308 - * @return string Value of topic content field.
2309 - */
2310 -function bbp_get_form_forum_parent() {
2195 + // Get _POST data
2196 + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_id'] ) ) {
2197 + $forum_parent = (int) $_POST['bbp_forum_id'];
2311 2198
2312 - // Get _POST data
2313 - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_id'] ) ) {
2314 - $forum_parent = (int) $_POST['bbp_forum_id'];
2199 + // Get edit data
2200 + } elseif ( bbp_is_forum_edit() ) {
2201 + $forum_parent = bbp_get_forum_parent_id();
2315 2202
2316 - // Get edit data
2317 - } elseif ( bbp_is_forum_edit() ) {
2318 - $forum_parent = bbp_get_forum_parent_id();
2203 + // No data
2204 + } else {
2205 + $forum_parent = 0;
2206 + }
2319 2207
2320 - // No data
2321 - } else {
2322 - $forum_parent = 0;
2208 + // Filter & return
2209 + return apply_filters( 'bbp_get_form_forum_parent', $forum_parent );
2323 2210 }
2324 2211
2325 - // Filter & return
2326 - return apply_filters( 'bbp_get_form_forum_parent', $forum_parent );
2327 -}
2328 -
2329 2212 /**
2330 - * Output value of forum type.
2213 + * Output value of forum type
2331 2214 *
2332 2215 * @since 2.1.0 bbPress (r3563)
2333 2216 */
2334 2217 function bbp_form_forum_type() {
@@ -2333,37 +2216,36 @@
2333 2216 */
2334 2217 function bbp_form_forum_type() {
2335 2218 echo bbp_get_form_forum_type();
2336 2219 }
2220 + /**
2221 + * Return value of forum type
2222 + *
2223 + * @since 2.1.0 bbPress (r3563)
2224 + *
2225 + * @return string Value of topic content field
2226 + */
2227 + function bbp_get_form_forum_type() {
2337 2228
2338 -/**
2339 - * Return value of forum type.
2340 - *
2341 - * @since 2.1.0 bbPress (r3563)
2342 - *
2343 - * @return string Value of topic content field.
2344 - */
2345 -function bbp_get_form_forum_type() {
2229 + // Get _POST data
2230 + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_type'] ) ) {
2231 + $forum_type = sanitize_key( $_POST['bbp_forum_type'] );
2346 2232
2347 - // Get _POST data
2348 - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_type'] ) ) {
2349 - $forum_type = sanitize_key( $_POST['bbp_forum_type'] );
2233 + // Get edit data
2234 + } elseif ( bbp_is_forum_edit() ) {
2235 + $forum_type = bbp_get_forum_type();
2350 2236
2351 - // Get edit data
2352 - } elseif ( bbp_is_forum_edit() ) {
2353 - $forum_type = bbp_get_forum_type();
2237 + // No data
2238 + } else {
2239 + $forum_type = 'forum';
2240 + }
2354 2241
2355 - // No data
2356 - } else {
2357 - $forum_type = 'forum';
2242 + // Filter & return
2243 + return apply_filters( 'bbp_get_form_forum_type', $forum_type );
2358 2244 }
2359 2245
2360 - // Filter & return
2361 - return apply_filters( 'bbp_get_form_forum_type', $forum_type );
2362 -}
2363 -
2364 2246 /**
2365 - * Output value of forum visibility.
2247 + * Output value of forum visibility
2366 2248 *
2367 2249 * @since 2.1.0 bbPress (r3563)
2368 2250 */
2369 2251 function bbp_form_forum_visibility() {
@@ -2368,37 +2250,36 @@
2368 2250 */
2369 2251 function bbp_form_forum_visibility() {
2370 2252 echo bbp_get_form_forum_visibility();
2371 2253 }
2254 + /**
2255 + * Return value of forum visibility
2256 + *
2257 + * @since 2.1.0 bbPress (r3563)
2258 + *
2259 + * @return string Value of topic content field
2260 + */
2261 + function bbp_get_form_forum_visibility() {
2372 2262
2373 -/**
2374 - * Return value of forum visibility.
2375 - *
2376 - * @since 2.1.0 bbPress (r3563)
2377 - *
2378 - * @return string Value of topic content field.
2379 - */
2380 -function bbp_get_form_forum_visibility() {
2263 + // Get _POST data
2264 + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_visibility'] ) ) {
2265 + $forum_visibility = sanitize_key( $_POST['bbp_forum_visibility'] );
2381 2266
2382 - // Get _POST data
2383 - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_visibility'] ) ) {
2384 - $forum_visibility = sanitize_key( $_POST['bbp_forum_visibility'] );
2267 + // Get edit data
2268 + } elseif ( bbp_is_forum_edit() ) {
2269 + $forum_visibility = bbp_get_forum_visibility();
2385 2270
2386 - // Get edit data
2387 - } elseif ( bbp_is_forum_edit() ) {
2388 - $forum_visibility = bbp_get_forum_visibility();
2271 + // No data
2272 + } else {
2273 + $forum_visibility = bbpress()->public_status_id;
2274 + }
2389 2275
2390 - // No data
2391 - } else {
2392 - $forum_visibility = bbpress()->public_status_id;
2276 + // Filter & return
2277 + return apply_filters( 'bbp_get_form_forum_visibility', $forum_visibility );
2393 2278 }
2394 2279
2395 - // Filter & return
2396 - return apply_filters( 'bbp_get_form_forum_visibility', $forum_visibility );
2397 -}
2398 -
2399 2280 /**
2400 - * Output checked value of forum subscription.
2281 + * Output checked value of forum subscription
2401 2282 *
2402 2283 * @since 2.5.0 bbPress (r5156)
2403 2284 */
2404 2285 function bbp_form_forum_subscribed() {
@@ -2403,46 +2284,45 @@
2403 2284 */
2404 2285 function bbp_form_forum_subscribed() {
2405 2286 echo bbp_get_form_forum_subscribed();
2406 2287 }
2288 + /**
2289 + * Return checked value of forum subscription
2290 + *
2291 + * @since 2.5.0 bbPress (r5156)
2292 + *
2293 + * @return string Checked value of forum subscription
2294 + */
2295 + function bbp_get_form_forum_subscribed() {
2407 2296
2408 -/**
2409 - * Return checked value of forum subscription.
2410 - *
2411 - * @since 2.5.0 bbPress (r5156)
2412 - *
2413 - * @return string Checked value of forum subscription.
2414 - */
2415 -function bbp_get_form_forum_subscribed() {
2297 + // Default value
2298 + $forum_subscribed = false;
2416 2299
2417 - // Default value
2418 - $forum_subscribed = false;
2300 + // Get _POST data
2301 + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_subscription'] ) ) {
2302 + $forum_subscribed = (bool) $_POST['bbp_forum_subscription'];
2419 2303
2420 - // Get _POST data
2421 - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_subscription'] ) ) {
2422 - $forum_subscribed = (bool) $_POST['bbp_forum_subscription'];
2304 + // Get edit data
2305 + } elseif ( bbp_is_forum_edit() || bbp_is_reply_edit() ) {
2306 + $post_author = (int) bbp_get_global_post_field( 'post_author', 'raw' );
2307 + $forum_subscribed = bbp_is_user_subscribed( $post_author, bbp_get_forum_id() );
2423 2308
2424 - // Get edit data
2425 - } elseif ( bbp_is_forum_edit() || bbp_is_reply_edit() ) {
2426 - $post_author = (int) bbp_get_global_post_field( 'post_author', 'raw' );
2427 - $forum_subscribed = bbp_is_user_subscribed( $post_author, bbp_get_forum_id() );
2309 + // Get current status
2310 + } elseif ( bbp_is_single_forum() ) {
2311 + $forum_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_forum_id() );
2312 + }
2428 2313
2429 - // Get current status
2430 - } elseif ( bbp_is_single_forum() ) {
2431 - $forum_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_forum_id() );
2314 + // Get checked output
2315 + $checked = checked( $forum_subscribed, true, false );
2316 +
2317 + // Filter & return
2318 + return apply_filters( 'bbp_get_form_forum_subscribed', $checked, $forum_subscribed );
2432 2319 }
2433 2320
2434 - // Get checked output
2435 - $checked = checked( $forum_subscribed, true, false );
2436 -
2437 - // Filter & return
2438 - return apply_filters( 'bbp_get_form_forum_subscribed', $checked, $forum_subscribed );
2439 -}
2440 -
2441 2321 /** Form Dropdowns ************************************************************/
2442 2322
2443 2323 /**
2444 - * Output value forum type dropdown.
2324 + * Output value forum type dropdown
2445 2325 *
2446 2326 * @since 2.1.0 bbPress (r3563)
2447 2327 *
2448 2328 * @param $args This function supports these arguments:
@@ -2453,83 +2333,82 @@
2453 2333 */
2454 2334 function bbp_form_forum_type_dropdown( $args = array() ) {
2455 2335 echo bbp_get_form_forum_type_dropdown( $args );
2456 2336 }
2337 + /**
2338 + * Return the forum type dropdown
2339 + *
2340 + * @since 2.1.0 bbPress (r3563)
2341 + *
2342 + * @param $args This function supports these arguments:
2343 + * - select_id: Select id. Defaults to bbp_forum_type
2344 + * - tab: Deprecated. Tabindex
2345 + * - forum_id: Forum id
2346 + * - selected: Override the selected option
2347 + * @return string HTML select list for selecting forum type
2348 + */
2349 + function bbp_get_form_forum_type_dropdown( $args = array() ) {
2457 2350
2458 -/**
2459 - * Return the forum type dropdown.
2460 - *
2461 - * @since 2.1.0 bbPress (r3563)
2462 - *
2463 - * @param $args This function supports these arguments:
2464 - * - select_id: Select id. Defaults to bbp_forum_type
2465 - * - tab: Deprecated. Tabindex
2466 - * - forum_id: Forum id
2467 - * - selected: Override the selected option
2468 - * @return string HTML select list for selecting forum type
2469 - */
2470 -function bbp_get_form_forum_type_dropdown( $args = array() ) {
2351 + // Backpat for handling passing of a forum ID as integer
2352 + if ( is_int( $args ) ) {
2353 + $forum_id = (int) $args;
2354 + $args = array();
2355 + } else {
2356 + $forum_id = 0;
2357 + }
2471 2358
2472 - // Backpat for handling passing of a forum ID as integer
2473 - if ( is_int( $args ) ) {
2474 - $forum_id = (int) $args;
2475 - $args = array();
2476 - } else {
2477 - $forum_id = 0;
2478 - }
2479 -
2480 - // Parse arguments against default values
2481 - $r = bbp_parse_args(
2482 - $args,
2483 - array(
2359 + // Parse arguments against default values
2360 + $r = bbp_parse_args( $args, array(
2484 2361 'select_id' => 'bbp_forum_type',
2485 2362 'select_class' => 'bbp_dropdown',
2486 2363 'tab' => false,
2487 2364 'forum_id' => $forum_id,
2488 2365 'selected' => false
2489 - ),
2490 - 'forum_type_select'
2491 - );
2366 + ), 'forum_type_select' );
2492 2367
2493 - // No specific selected value passed
2494 - if ( empty( $r['selected'] ) ) {
2368 + // No specific selected value passed
2369 + if ( empty( $r['selected'] ) ) {
2495 2370
2496 - // Post value is passed
2497 - if ( bbp_is_forum_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
2498 - $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );
2371 + // Post value is passed
2372 + if ( bbp_is_forum_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
2373 + $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );
2499 2374
2500 - // Edit topic
2501 - } elseif ( bbp_is_forum_edit() ) {
2502 - $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
2503 - $r['selected'] = bbp_get_forum_type( $r['forum_id'] );
2375 + // No Post value was passed
2376 + } else {
2504 2377
2505 - // New topic
2506 - } else {
2507 - $r['selected'] = bbp_get_public_status_id();
2378 + // Edit topic
2379 + if ( bbp_is_forum_edit() ) {
2380 + $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
2381 + $r['selected'] = bbp_get_forum_type( $r['forum_id'] );
2382 +
2383 + // New topic
2384 + } else {
2385 + $r['selected'] = bbp_get_public_status_id();
2386 + }
2387 + }
2508 2388 }
2509 - }
2510 2389
2511 - // Start an output buffer, we'll finish it after the select loop
2512 - ob_start(); ?>
2390 + // Start an output buffer, we'll finish it after the select loop
2391 + ob_start(); ?>
2513 2392
2514 - <select name="<?php echo esc_attr( $r['select_id'] ); ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
2393 + <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
2515 2394
2516 - <?php foreach ( bbp_get_forum_types( $r['forum_id'] ) as $key => $label ) : ?>
2395 + <?php foreach ( bbp_get_forum_types( $r['forum_id'] ) as $key => $label ) : ?>
2517 2396
2518 - <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
2397 + <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
2519 2398
2520 - <?php endforeach; ?>
2399 + <?php endforeach; ?>
2521 2400
2522 - </select>
2401 + </select>
2523 2402
2524 - <?php
2403 + <?php
2525 2404
2526 - // Filter & return
2527 - return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args );
2528 -}
2405 + // Filter & return
2406 + return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args );
2407 + }
2529 2408
2530 2409 /**
2531 - * Output value forum status dropdown.
2410 + * Output value forum status dropdown
2532 2411 *
2533 2412 * @since 2.1.0 bbPress (r3563)
2534 2413 *
2535 2414 * @param $args This function supports these arguments:
@@ -2540,83 +2419,82 @@
2540 2419 */
2541 2420 function bbp_form_forum_status_dropdown( $args = array() ) {
2542 2421 echo bbp_get_form_forum_status_dropdown( $args );
2543 2422 }
2423 + /**
2424 + * Return the forum status dropdown
2425 + *
2426 + * @since 2.1.0 bbPress (r3563)
2427 + *
2428 + * @param $args This function supports these arguments:
2429 + * - select_id: Select id. Defaults to bbp_forum_status
2430 + * - tab: Deprecated. Tabindex
2431 + * - forum_id: Forum id
2432 + * - selected: Override the selected option
2433 + * @return string HTML select list for selecting forum status
2434 + */
2435 + function bbp_get_form_forum_status_dropdown( $args = array() ) {
2544 2436
2545 -/**
2546 - * Return the forum status dropdown.
2547 - *
2548 - * @since 2.1.0 bbPress (r3563)
2549 - *
2550 - * @param $args This function supports these arguments:
2551 - * - select_id: Select id. Defaults to bbp_forum_status
2552 - * - tab: Deprecated. Tabindex
2553 - * - forum_id: Forum id
2554 - * - selected: Override the selected option
2555 - * @return string HTML select list for selecting forum status.
2556 - */
2557 -function bbp_get_form_forum_status_dropdown( $args = array() ) {
2437 + // Backpat for handling passing of a forum ID
2438 + if ( is_int( $args ) ) {
2439 + $forum_id = (int) $args;
2440 + $args = array();
2441 + } else {
2442 + $forum_id = 0;
2443 + }
2558 2444
2559 - // Backpat for handling passing of a forum ID
2560 - if ( is_int( $args ) ) {
2561 - $forum_id = (int) $args;
2562 - $args = array();
2563 - } else {
2564 - $forum_id = 0;
2565 - }
2566 -
2567 - // Parse arguments against default values
2568 - $r = bbp_parse_args(
2569 - $args,
2570 - array(
2445 + // Parse arguments against default values
2446 + $r = bbp_parse_args( $args, array(
2571 2447 'select_id' => 'bbp_forum_status',
2572 2448 'select_class' => 'bbp_dropdown',
2573 2449 'tab' => false,
2574 2450 'forum_id' => $forum_id,
2575 2451 'selected' => false
2576 - ),
2577 - 'forum_status_select'
2578 - );
2452 + ), 'forum_status_select' );
2579 2453
2580 - // No specific selected value passed
2581 - if ( empty( $r['selected'] ) ) {
2454 + // No specific selected value passed
2455 + if ( empty( $r['selected'] ) ) {
2582 2456
2583 - // Post value is passed
2584 - if ( bbp_is_forum_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
2585 - $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );
2457 + // Post value is passed
2458 + if ( bbp_is_forum_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
2459 + $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );
2586 2460
2587 - // Edit topic
2588 - } elseif ( bbp_is_forum_edit() ) {
2589 - $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
2590 - $r['selected'] = bbp_get_forum_status( $r['forum_id'] );
2461 + // No Post value was passed
2462 + } else {
2591 2463
2592 - // New topic
2593 - } else {
2594 - $r['selected'] = bbp_get_public_status_id();
2464 + // Edit topic
2465 + if ( bbp_is_forum_edit() ) {
2466 + $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
2467 + $r['selected'] = bbp_get_forum_status( $r['forum_id'] );
2468 +
2469 + // New topic
2470 + } else {
2471 + $r['selected'] = bbp_get_public_status_id();
2472 + }
2473 + }
2595 2474 }
2596 - }
2597 2475
2598 - // Start an output buffer, we'll finish it after the select loop
2599 - ob_start(); ?>
2476 + // Start an output buffer, we'll finish it after the select loop
2477 + ob_start(); ?>
2600 2478
2601 - <select name="<?php echo esc_attr( $r['select_id'] ); ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
2479 + <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
2602 2480
2603 - <?php foreach ( bbp_get_forum_statuses( $r['forum_id'] ) as $key => $label ) : ?>
2481 + <?php foreach ( bbp_get_forum_statuses( $r['forum_id'] ) as $key => $label ) : ?>
2604 2482
2605 - <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
2483 + <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
2606 2484
2607 - <?php endforeach; ?>
2485 + <?php endforeach; ?>
2608 2486
2609 - </select>
2487 + </select>
2610 2488
2611 - <?php
2489 + <?php
2612 2490
2613 - // Filter & return
2614 - return apply_filters( 'bbp_get_form_forum_status_dropdown', ob_get_clean(), $r, $args );
2615 -}
2491 + // Filter & return
2492 + return apply_filters( 'bbp_get_form_forum_status_dropdown', ob_get_clean(), $r, $args );
2493 + }
2616 2494
2617 2495 /**
2618 - * Output value forum visibility dropdown.
2496 + * Output value forum visibility dropdown
2619 2497 *
2620 2498 * @since 2.1.0 bbPress (r3563)
2621 2499 *
2622 2500 * @param $args This function supports these arguments:
@@ -2627,80 +2505,79 @@
2627 2505 */
2628 2506 function bbp_form_forum_visibility_dropdown( $args = array() ) {
2629 2507 echo bbp_get_form_forum_visibility_dropdown( $args );
2630 2508 }
2509 + /**
2510 + * Return the forum visibility dropdown
2511 + *
2512 + * @since 2.1.0 bbPress (r3563)
2513 + *
2514 + * @param $args This function supports these arguments:
2515 + * - select_id: Select id. Defaults to bbp_forum_visibility
2516 + * - tab: Deprecated. Tabindex
2517 + * - forum_id: Forum id
2518 + * - selected: Override the selected option
2519 + * @return string HTML select list for selecting forum visibility
2520 + */
2521 + function bbp_get_form_forum_visibility_dropdown( $args = array() ) {
2631 2522
2632 -/**
2633 - * Return the forum visibility dropdown.
2634 - *
2635 - * @since 2.1.0 bbPress (r3563)
2636 - *
2637 - * @param $args This function supports these arguments:
2638 - * - select_id: Select id. Defaults to bbp_forum_visibility
2639 - * - tab: Deprecated. Tabindex
2640 - * - forum_id: Forum id
2641 - * - selected: Override the selected option
2642 - * @return string HTML select list for selecting forum visibility.
2643 - */
2644 -function bbp_get_form_forum_visibility_dropdown( $args = array() ) {
2523 + // Backpat for handling passing of a forum ID
2524 + if ( is_int( $args ) ) {
2525 + $forum_id = (int) $args;
2526 + $args = array();
2527 + } else {
2528 + $forum_id = 0;
2529 + }
2645 2530
2646 - // Backpat for handling passing of a forum ID
2647 - if ( is_int( $args ) ) {
2648 - $forum_id = (int) $args;
2649 - $args = array();
2650 - } else {
2651 - $forum_id = 0;
2652 - }
2653 -
2654 - // Parse arguments against default values
2655 - $r = bbp_parse_args(
2656 - $args,
2657 - array(
2531 + // Parse arguments against default values
2532 + $r = bbp_parse_args( $args, array(
2658 2533 'select_id' => 'bbp_forum_visibility',
2659 2534 'select_class' => 'bbp_dropdown',
2660 2535 'tab' => false,
2661 2536 'forum_id' => $forum_id,
2662 2537 'selected' => false
2663 - ),
2664 - 'forum_type_select'
2665 - );
2538 + ), 'forum_type_select' );
2666 2539
2667 - // No specific selected value passed
2668 - if ( empty( $r['selected'] ) ) {
2540 + // No specific selected value passed
2541 + if ( empty( $r['selected'] ) ) {
2669 2542
2670 - // Post value is passed
2671 - if ( bbp_is_forum_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
2672 - $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );
2543 + // Post value is passed
2544 + if ( bbp_is_forum_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
2545 + $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );
2673 2546
2674 - // Edit topic
2675 - } elseif ( bbp_is_forum_edit() ) {
2676 - $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
2677 - $r['selected'] = bbp_get_forum_visibility( $r['forum_id'] );
2547 + // No Post value was passed
2548 + } else {
2678 2549
2679 - // New topic
2680 - } else {
2681 - $r['selected'] = bbp_get_public_status_id();
2550 + // Edit topic
2551 + if ( bbp_is_forum_edit() ) {
2552 + $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
2553 + $r['selected'] = bbp_get_forum_visibility( $r['forum_id'] );
2554 +
2555 + // New topic
2556 + } else {
2557 + $r['selected'] = bbp_get_public_status_id();
2558 + }
2559 + }
2682 2560 }
2683 - }
2684 2561
2685 - // Start an output buffer, we'll finish it after the select loop
2686 - ob_start(); ?>
2562 + // Start an output buffer, we'll finish it after the select loop
2563 + ob_start(); ?>
2687 2564
2688 - <select name="<?php echo esc_attr( $r['select_id'] ); ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
2565 + <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
2689 2566
2690 - <?php foreach ( bbp_get_forum_visibilities( $r['forum_id'] ) as $key => $label ) : ?>
2567 + <?php foreach ( bbp_get_forum_visibilities( $r['forum_id'] ) as $key => $label ) : ?>
2691 2568
2692 - <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
2569 + <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
2693 2570
2694 - <?php endforeach; ?>
2571 + <?php endforeach; ?>
2695 2572
2696 - </select>
2573 + </select>
2697 2574
2698 - <?php
2575 + <?php
2699 2576
2700 - // Filter & return
2701 - return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args );
2702 -}
2577 + // Filter & return
2578 + return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args );
2579 + }
2703 2580
2704 2581 /**
2705 2582 * Verify if a POST request came from a failed forum attempt.
2706 2583 *
@@ -2710,9 +2587,9 @@
2710 2587 * @see bbp_forum_form_fields()
2711 2588 *
2712 2589 * @since 2.6.0 bbPress (r5558)
2713 2590 *
2714 - * @return boolean True if is a post request with valid nonce.
2591 + * @return boolean True if is a post request with valid nonce
2715 2592 */
2716 2593 function bbp_is_forum_form_post_request() {
2717 2594
2718 2595 // Bail if not a post request
@@ -2735,9 +2612,9 @@
2735 2612
2736 2613 /** Feeds *********************************************************************/
2737 2614
2738 2615 /**
2739 - * Output the link for the forum feed.
2616 + * Output the link for the forum feed
2740 2617 *
2741 2618 * @since 2.0.0 bbPress (r3172)
2742 2619 *
2743 2620 * @param int $forum_id Optional. Forum ID.
@@ -2744,57 +2621,52 @@
2744 2621 */
2745 2622 function bbp_forum_topics_feed_link( $forum_id = 0 ) {
2746 2623 echo bbp_get_forum_topics_feed_link( $forum_id );
2747 2624 }
2625 + /**
2626 + * Retrieve the link for the forum feed
2627 + *
2628 + * @since 2.0.0 bbPress (r3172)
2629 + *
2630 + * @param int $forum_id Optional. Forum ID.
2631 + *
2632 + * @return string
2633 + */
2634 + function bbp_get_forum_topics_feed_link( $forum_id = 0 ) {
2748 2635
2749 -/**
2750 - * Retrieve the link for the forum feed.
2751 - *
2752 - * @since 2.0.0 bbPress (r3172)
2753 - *
2754 - * @param int $forum_id Optional. Forum ID.
2755 - *
2756 - * @return string
2757 - */
2758 -function bbp_get_forum_topics_feed_link( $forum_id = 0 ) {
2636 + // Validate forum id
2637 + $forum_id = bbp_get_forum_id( $forum_id );
2759 2638
2760 - // Validate forum id
2761 - $forum_id = bbp_get_forum_id( $forum_id );
2639 + // Forum is valid
2640 + if ( ! empty( $forum_id ) ) {
2762 2641
2763 - // Forum is valid
2764 - if ( ! empty( $forum_id ) ) {
2642 + // Define local variable(s)
2643 + $link = '';
2765 2644
2766 - // Define local variable(s)
2767 - $link = '';
2645 + // Pretty permalinks
2646 + if ( get_option( 'permalink_structure' ) ) {
2768 2647
2769 - // Pretty permalinks
2770 - if ( get_option( 'permalink_structure' ) ) {
2648 + // Forum link
2649 + $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
2650 + $url = user_trailingslashit( $url, 'single_feed' );
2771 2651
2772 - // Forum link
2773 - $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
2774 - $url = user_trailingslashit( $url, 'single_feed' );
2652 + // Unpretty permalinks
2653 + } else {
2654 + $url = home_url( add_query_arg( array(
2655 + 'feed' => 'rss2',
2656 + bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
2657 + ) ) );
2658 + }
2775 2659
2776 - // Unpretty permalinks
2777 - } else {
2778 - $url = home_url(
2779 - add_query_arg(
2780 - array(
2781 - 'feed' => 'rss2',
2782 - bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
2783 - )
2784 - )
2785 - );
2660 + $link = '<a href="' . esc_url( $url ) . '" class="bbp-forum-rss-link topics"><span>' . esc_attr__( 'Topics', 'bbpress' ) . '</span></a>';
2786 2661 }
2787 2662
2788 - $link = '<a href="' . esc_url( $url ) . '" class="bbp-forum-rss-link topics"><span>' . esc_attr__( 'Topics', 'bbpress' ) . '</span></a>';
2663 + // Filter & return
2664 + return apply_filters( 'bbp_get_forum_topics_feed_link', $link, $url, $forum_id );
2789 2665 }
2790 2666
2791 - // Filter & return
2792 - return apply_filters( 'bbp_get_forum_topics_feed_link', $link, $url, $forum_id );
2793 -}
2794 -
2795 2667 /**
2796 - * Output the link for the forum replies feed.
2668 + * Output the link for the forum replies feed
2797 2669 *
2798 2670 * @since 2.0.0 bbPress (r3172)
2799 2671 *
2800 2672 * @param int $forum_id Optional. Forum ID.
@@ -2801,52 +2673,47 @@
2801 2673 */
2802 2674 function bbp_forum_replies_feed_link( $forum_id = 0 ) {
2803 2675 echo bbp_get_forum_replies_feed_link( $forum_id );
2804 2676 }
2677 + /**
2678 + * Retrieve the link for the forum replies feed
2679 + *
2680 + * @since 2.0.0 bbPress (r3172)
2681 + *
2682 + * @param int $forum_id Optional. Forum ID.
2683 + *
2684 + * @return string
2685 + */
2686 + function bbp_get_forum_replies_feed_link( $forum_id = 0 ) {
2805 2687
2806 -/**
2807 - * Retrieve the link for the forum replies feed.
2808 - *
2809 - * @since 2.0.0 bbPress (r3172)
2810 - *
2811 - * @param int $forum_id Optional. Forum ID.
2812 - *
2813 - * @return string
2814 - */
2815 -function bbp_get_forum_replies_feed_link( $forum_id = 0 ) {
2688 + // Validate forum id
2689 + $forum_id = bbp_get_forum_id( $forum_id );
2816 2690
2817 - // Validate forum id
2818 - $forum_id = bbp_get_forum_id( $forum_id );
2691 + // Forum is valid
2692 + if ( ! empty( $forum_id ) ) {
2819 2693
2820 - // Forum is valid
2821 - if ( ! empty( $forum_id ) ) {
2694 + // Define local variable(s)
2695 + $link = '';
2822 2696
2823 - // Define local variable(s)
2824 - $link = '';
2697 + // Pretty permalinks
2698 + if ( get_option( 'permalink_structure' ) ) {
2825 2699
2826 - // Pretty permalinks
2827 - if ( get_option( 'permalink_structure' ) ) {
2700 + // Forum link
2701 + $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
2702 + $url = user_trailingslashit( $url, 'single_feed' );
2703 + $url = add_query_arg( array( 'type' => 'reply' ), $url );
2828 2704
2829 - // Forum link
2830 - $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
2831 - $url = user_trailingslashit( $url, 'single_feed' );
2832 - $url = add_query_arg( array( 'type' => 'reply' ), $url );
2705 + // Unpretty permalinks
2706 + } else {
2707 + $url = home_url( add_query_arg( array(
2708 + 'type' => 'reply',
2709 + 'feed' => 'rss2',
2710 + bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
2711 + ) ) );
2712 + }
2833 2713
2834 - // Unpretty permalinks
2835 - } else {
2836 - $url = home_url(
2837 - add_query_arg(
2838 - array(
2839 - 'type' => 'reply',
2840 - 'feed' => 'rss2',
2841 - bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
2842 - )
2843 - )
2844 - );
2714 + $link = '<a href="' . esc_url( $url ) . '" class="bbp-forum-rss-link replies"><span>' . esc_html__( 'Replies', 'bbpress' ) . '</span></a>';
2845 2715 }
2846 2716
2847 - $link = '<a href="' . esc_url( $url ) . '" class="bbp-forum-rss-link replies"><span>' . esc_html__( 'Replies', 'bbpress' ) . '</span></a>';
2717 + // Filter & return
2718 + return apply_filters( 'bbp_get_forum_replies_feed_link', $link, $url, $forum_id );
2848 2719 }
2849 -
2850 - // Filter & return
2851 - return apply_filters( 'bbp_get_forum_replies_feed_link', $link, $url, $forum_id );
2852 -}