| @@ -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 (r2858) |
| 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 (r2858) | |
| 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 (r2858) | |
| 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 (r5130) |
| 41 | 41 | * |
| 42 | 42 | * @return array |
| @@ -51,9 +51,9 @@ | ||
| 51 | 51 | 'menu_name' => esc_attr__( 'Forums', 'bbpress' ), |
| 52 | 52 | 'singular_name' => esc_attr__( 'Forum', 'bbpress' ), |
| 53 | 53 | 'all_items' => esc_attr__( 'All Forums', 'bbpress' ), |
| 54 | 54 | 'add_new' => esc_attr__( 'Add New', 'bbpress' ), |
| 55 | - 'add_new_item' => esc_attr__( 'Add Forum', 'bbpress' ), | |
| 55 | + 'add_new_item' => esc_attr__( 'Create New Forum', 'bbpress' ), | |
| 56 | 56 | 'edit' => esc_attr__( 'Edit', 'bbpress' ), |
| 57 | 57 | 'edit_item' => esc_attr__( 'Edit Forum', 'bbpress' ), |
| 58 | 58 | 'new_item' => esc_attr__( 'New Forum', 'bbpress' ), |
| 59 | 59 | 'view' => esc_attr__( 'View Forum', 'bbpress' ), |
| @@ -83,9 +83,9 @@ | ||
| 83 | 83 | ); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | - * Return array of forum post type rewrite settings. | |
| 87 | + * Return array of forum post type rewrite settings | |
| 88 | 88 | * |
| 89 | 89 | * @since 2.5.0 bbPress (r5130) |
| 90 | 90 | * |
| 91 | 91 | * @return array |
| @@ -102,9 +102,9 @@ | ||
| 102 | 102 | ); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | - * Return array of features the forum post type supports. | |
| 106 | + * Return array of features the forum post type supports | |
| 107 | 107 | * |
| 108 | 108 | * @since 2.5.0 bbPress (r5130) |
| 109 | 109 | * |
| 110 | 110 | * @return array |
| @@ -132,9 +132,9 @@ | ||
| 132 | 132 | * @since 2.0.0 bbPress (r2464) |
| 133 | 133 | * |
| 134 | 134 | * @param array $args All the arguments supported by {@link WP_Query} |
| 135 | 135 | * |
| 136 | - * @return object Multidimensional array of forum information. | |
| 136 | + * @return object Multidimensional array of forum information | |
| 137 | 137 | */ |
| 138 | 138 | function bbp_has_forums( $args = array() ) { |
| 139 | 139 | |
| 140 | 140 | // Forum archive only shows root |
| @@ -189,13 +189,13 @@ | ||
| 189 | 189 | return apply_filters( 'bbp_has_forums', $bbp->forum_query->have_posts(), $bbp->forum_query ); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
| 193 | - * Whether there are more forums available in the loop. | |
| 193 | + * Whether there are more forums available in the loop | |
| 194 | 194 | * |
| 195 | 195 | * @since 2.0.0 bbPress (r2464) |
| 196 | 196 | * |
| 197 | - * @return object Forum information. | |
| 197 | + * @return object Forum information | |
| 198 | 198 | */ |
| 199 | 199 | function bbp_forums() { |
| 200 | 200 | |
| 201 | 201 | // Put into variable to check against next |
| @@ -209,13 +209,13 @@ | ||
| 209 | 209 | return $have_posts; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
| 213 | - * Loads up the current forum in the loop. | |
| 213 | + * Loads up the current forum in the loop | |
| 214 | 214 | * |
| 215 | 215 | * @since 2.0.0 bbPress (r2464) |
| 216 | 216 | * |
| 217 | - * @return object Forum information. | |
| 217 | + * @return object Forum information | |
| 218 | 218 | */ |
| 219 | 219 | function bbp_the_forum() { |
| 220 | 220 | return bbpress()->forum_query->the_post(); |
| 221 | 221 | } |
| @@ -222,73 +222,72 @@ | ||
| 222 | 222 | |
| 223 | 223 | /** Forum *********************************************************************/ |
| 224 | 224 | |
| 225 | 225 | /** |
| 226 | - * Output forum id. | |
| 226 | + * Output forum id | |
| 227 | 227 | * |
| 228 | 228 | * @since 2.0.0 bbPress (r2464) |
| 229 | 229 | * |
| 230 | - * @param $forum_id Optional. Used to check emptiness. | |
| 230 | + * @param $forum_id Optional. Used to check emptiness | |
| 231 | 231 | */ |
| 232 | 232 | function bbp_forum_id( $forum_id = 0 ) { |
| 233 | 233 | echo bbp_get_forum_id( $forum_id ); |
| 234 | 234 | } |
| 235 | + /** | |
| 236 | + * Return the forum id | |
| 237 | + * | |
| 238 | + * @since 2.0.0 bbPress (r2464) | |
| 239 | + * | |
| 240 | + * @param $forum_id Optional. Used to check emptiness | |
| 241 | + * @return int The forum id | |
| 242 | + */ | |
| 243 | + function bbp_get_forum_id( $forum_id = 0 ) { | |
| 244 | + $bbp = bbpress(); | |
| 245 | + $wp_query = bbp_get_wp_query(); | |
| 235 | 246 | |
| 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(); | |
| 247 | + // Easy empty checking | |
| 248 | + if ( ! empty( $forum_id ) && is_numeric( $forum_id ) ) { | |
| 249 | + $bbp_forum_id = $forum_id; | |
| 247 | 250 | |
| 248 | - // Easy empty checking | |
| 249 | - if ( ! empty( $forum_id ) && is_numeric( $forum_id ) ) { | |
| 250 | - $bbp_forum_id = $forum_id; | |
| 251 | + // Currently inside a forum loop | |
| 252 | + } elseif ( ! empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) ) { | |
| 253 | + $bbp_forum_id = $bbp->forum_query->post->ID; | |
| 251 | 254 | |
| 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; | |
| 255 | + // Currently inside a search loop | |
| 256 | + } elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_forum( $bbp->search_query->post->ID ) ) { | |
| 257 | + $bbp_forum_id = $bbp->search_query->post->ID; | |
| 255 | 258 | |
| 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; | |
| 259 | + // Currently viewing a forum | |
| 260 | + } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && ! empty( $bbp->current_forum_id ) ) { | |
| 261 | + $bbp_forum_id = $bbp->current_forum_id; | |
| 259 | 262 | |
| 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; | |
| 263 | + // Currently viewing a forum | |
| 264 | + } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && isset( $wp_query->post->ID ) ) { | |
| 265 | + $bbp_forum_id = $wp_query->post->ID; | |
| 263 | 266 | |
| 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; | |
| 267 | + // Currently viewing a topic | |
| 268 | + } elseif ( bbp_is_single_topic() ) { | |
| 269 | + $bbp_forum_id = bbp_get_topic_forum_id(); | |
| 267 | 270 | |
| 268 | - // Currently viewing a topic | |
| 269 | - } elseif ( bbp_is_single_topic() ) { | |
| 270 | - $bbp_forum_id = bbp_get_topic_forum_id(); | |
| 271 | + // Fallback | |
| 272 | + } else { | |
| 273 | + $bbp_forum_id = 0; | |
| 274 | + } | |
| 271 | 275 | |
| 272 | - // Fallback | |
| 273 | - } else { | |
| 274 | - $bbp_forum_id = 0; | |
| 276 | + // Filter & return | |
| 277 | + return (int) apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id ); | |
| 275 | 278 | } |
| 276 | 279 | |
| 277 | - // Filter & return | |
| 278 | - return (int) apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id ); | |
| 279 | -} | |
| 280 | - | |
| 281 | 280 | /** |
| 282 | - * Gets a forum. | |
| 281 | + * Gets a forum | |
| 283 | 282 | * |
| 284 | 283 | * @since 2.0.0 bbPress (r2787) |
| 285 | 284 | * |
| 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()}. | |
| 285 | + * @param int|object $forum forum id or forum object | |
| 286 | + * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT | |
| 287 | + * @param string $filter Optional Sanitation filter. See {@link sanitize_post()} | |
| 289 | 288 | * |
| 290 | - * @return mixed Null if error or forum (in specified form) if success. | |
| 289 | + * @return mixed Null if error or forum (in specified form) if success | |
| 291 | 290 | */ |
| 292 | 291 | function bbp_get_forum( $forum, $output = OBJECT, $filter = 'raw' ) { |
| 293 | 292 | |
| 294 | 293 | // Maybe get ID from empty or int |
| @@ -323,13 +322,13 @@ | ||
| 323 | 322 | return apply_filters( 'bbp_get_forum', $retval, $forum, $output, $filter ); |
| 324 | 323 | } |
| 325 | 324 | |
| 326 | 325 | /** |
| 327 | - * Output the link to the forum. | |
| 326 | + * Output the link to the forum | |
| 328 | 327 | * |
| 329 | 328 | * @since 2.0.0 bbPress (r2464) |
| 330 | 329 | * |
| 331 | - * @param int $forum_id Optional. Forum id. | |
| 330 | + * @param int $forum_id Optional. Forum id | |
| 332 | 331 | * @param string $redirect_to Optional. Pass a redirect value for use with |
| 333 | 332 | * shortcodes and other fun things. |
| 334 | 333 | */ |
| 335 | 334 | function bbp_forum_permalink( $forum_id = 0, $redirect_to = '' ) { |
| @@ -334,179 +333,141 @@ | ||
| 334 | 333 | */ |
| 335 | 334 | function bbp_forum_permalink( $forum_id = 0, $redirect_to = '' ) { |
| 336 | 335 | echo esc_url( bbp_get_forum_permalink( $forum_id, $redirect_to ) ); |
| 337 | 336 | } |
| 337 | + /** | |
| 338 | + * Return the link to the forum | |
| 339 | + * | |
| 340 | + * @since 2.0.0 bbPress (r2464) | |
| 341 | + * | |
| 342 | + * @param int $forum_id Optional. Forum id | |
| 343 | + * @param string $redirect_to Optional. Pass a redirect value for use with | |
| 344 | + * shortcodes and other fun things. | |
| 345 | + * | |
| 346 | + * @return string Permanent link to forum | |
| 347 | + */ | |
| 348 | + function bbp_get_forum_permalink( $forum_id = 0, $redirect_to = '' ) { | |
| 349 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 338 | 350 | |
| 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 ); | |
| 351 | + // Use the redirect address | |
| 352 | + if ( ! empty( $redirect_to ) ) { | |
| 353 | + $forum_permalink = esc_url_raw( $redirect_to ); | |
| 352 | 354 | |
| 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 | - } | |
| 355 | + // Use the topic permalink | |
| 356 | + } else { | |
| 357 | + $forum_permalink = get_permalink( $forum_id ); | |
| 387 | 358 | } |
| 388 | - } | |
| 389 | 359 | |
| 390 | - // Fallback to forum permalink | |
| 391 | - if ( empty( $forum_permalink ) ) { | |
| 392 | - $forum_permalink = get_permalink( $forum_id ); | |
| 360 | + // Filter & return | |
| 361 | + return apply_filters( 'bbp_get_forum_permalink', $forum_permalink, $forum_id ); | |
| 393 | 362 | } |
| 394 | 363 | |
| 395 | - // Filter & return | |
| 396 | - return apply_filters( 'bbp_get_forum_permalink', $forum_permalink, $forum_id ); | |
| 397 | -} | |
| 398 | - | |
| 399 | 364 | /** |
| 400 | - * Output the title of the forum. | |
| 365 | + * Output the title of the forum | |
| 401 | 366 | * |
| 402 | 367 | * @since 2.0.0 bbPress (r2464) |
| 403 | 368 | * |
| 404 | - * @param int $forum_id Optional. Forum id. | |
| 369 | + * @param int $forum_id Optional. Forum id | |
| 405 | 370 | */ |
| 406 | 371 | function bbp_forum_title( $forum_id = 0 ) { |
| 407 | 372 | echo bbp_get_forum_title( $forum_id ); |
| 408 | 373 | } |
| 374 | + /** | |
| 375 | + * Return the title of the forum | |
| 376 | + * | |
| 377 | + * @since 2.0.0 bbPress (r2464) | |
| 378 | + * | |
| 379 | + * @param int $forum_id Optional. Forum id | |
| 380 | + * @return string Title of forum | |
| 381 | + */ | |
| 382 | + function bbp_get_forum_title( $forum_id = 0 ) { | |
| 383 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 384 | + $title = get_the_title( $forum_id ); | |
| 409 | 385 | |
| 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 ); | |
| 386 | + // Filter & return | |
| 387 | + return apply_filters( 'bbp_get_forum_title', $title, $forum_id ); | |
| 388 | + } | |
| 422 | 389 | |
| 423 | - // Filter & return | |
| 424 | - return apply_filters( 'bbp_get_forum_title', $title, $forum_id ); | |
| 425 | -} | |
| 426 | - | |
| 427 | 390 | /** |
| 428 | - * Output the forum archive title. | |
| 391 | + * Output the forum archive title | |
| 429 | 392 | * |
| 430 | 393 | * @since 2.0.0 bbPress (r3250) |
| 431 | 394 | * |
| 432 | - * @param string $title Default text to use as title. | |
| 395 | + * @param string $title Default text to use as title | |
| 433 | 396 | */ |
| 434 | 397 | function bbp_forum_archive_title( $title = '' ) { |
| 435 | 398 | echo bbp_get_forum_archive_title( $title ); |
| 436 | 399 | } |
| 400 | + /** | |
| 401 | + * Return the forum archive title | |
| 402 | + * | |
| 403 | + * @since 2.0.0 bbPress (r3250) | |
| 404 | + * | |
| 405 | + * @param string $title Default text to use as title | |
| 406 | + * | |
| 407 | + * @return string The forum archive title | |
| 408 | + */ | |
| 409 | + function bbp_get_forum_archive_title( $title = '' ) { | |
| 437 | 410 | |
| 438 | -/** | |
| 439 | - * Return the forum archive title. | |
| 440 | - * | |
| 441 | - * @since 2.0.0 bbPress (r3250) | |
| 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 = '' ) { | |
| 411 | + // If no title was passed | |
| 412 | + if ( empty( $title ) ) { | |
| 448 | 413 | |
| 449 | - // If no title was passed | |
| 450 | - if ( empty( $title ) ) { | |
| 414 | + // Set root text to page title | |
| 415 | + $page = bbp_get_page_by_path( bbp_get_root_slug() ); | |
| 416 | + if ( ! empty( $page ) ) { | |
| 417 | + $title = get_the_title( $page->ID ); | |
| 451 | 418 | |
| 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 ); | |
| 419 | + // Default to forum post type name label | |
| 420 | + } else { | |
| 421 | + $fto = get_post_type_object( bbp_get_forum_post_type() ); | |
| 422 | + $title = $fto->labels->name; | |
| 423 | + } | |
| 424 | + } | |
| 456 | 425 | |
| 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 | - } | |
| 426 | + // Filter & return | |
| 427 | + return apply_filters( 'bbp_get_forum_archive_title', $title ); | |
| 462 | 428 | } |
| 463 | 429 | |
| 464 | - // Filter & return | |
| 465 | - return apply_filters( 'bbp_get_forum_archive_title', $title ); | |
| 466 | -} | |
| 467 | - | |
| 468 | 430 | /** |
| 469 | - * Output the content of the forum. | |
| 431 | + * Output the content of the forum | |
| 470 | 432 | * |
| 471 | 433 | * @since 2.0.0 bbPress (r2794) |
| 472 | 434 | * |
| 473 | - * @param int $forum_id Optional. Topic id. | |
| 435 | + * @param int $forum_id Optional. Topic id | |
| 474 | 436 | */ |
| 475 | 437 | function bbp_forum_content( $forum_id = 0 ) { |
| 476 | 438 | echo bbp_get_forum_content( $forum_id ); |
| 477 | 439 | } |
| 440 | + /** | |
| 441 | + * Return the content of the forum | |
| 442 | + * | |
| 443 | + * @since 2.0.0 bbPress (r2794) | |
| 444 | + * | |
| 445 | + * @param int $forum_id Optional. Topic id | |
| 446 | + * | |
| 447 | + * @return string Content of the forum | |
| 448 | + */ | |
| 449 | + function bbp_get_forum_content( $forum_id = 0 ) { | |
| 450 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 478 | 451 | |
| 479 | -/** | |
| 480 | - * Return the content of the forum. | |
| 481 | - * | |
| 482 | - * @since 2.0.0 bbPress (r2794) | |
| 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 ); | |
| 452 | + // Check the forum and its ancestors. | |
| 453 | + $password_id = bbp_get_password_required_id( $forum_id ); | |
| 454 | + if ( ! empty( $password_id ) ) { | |
| 455 | + return get_the_password_form( $password_id ); | |
| 456 | + } | |
| 490 | 457 | |
| 491 | - // Check the forum and its ancestors. | |
| 492 | - $password_id = bbp_get_password_required_id( $forum_id ); | |
| 493 | - if ( ! empty( $password_id ) ) { | |
| 494 | - return get_the_password_form( $password_id ); | |
| 458 | + $content = get_post_field( 'post_content', $forum_id ); | |
| 459 | + | |
| 460 | + // Filter & return | |
| 461 | + return apply_filters( 'bbp_get_forum_content', $content, $forum_id ); | |
| 495 | 462 | } |
| 496 | 463 | |
| 497 | - $content = get_post_field( 'post_content', $forum_id ); | |
| 498 | - | |
| 499 | - // Filter & return | |
| 500 | - return apply_filters( 'bbp_get_forum_content', $content, $forum_id ); | |
| 501 | -} | |
| 502 | - | |
| 503 | 464 | /** |
| 504 | - * Allow forum rows to have administrative actions. | |
| 465 | + * Allow forum rows to have administrative actions | |
| 505 | 466 | * |
| 506 | 467 | * @since 2.1.0 bbPress (r3654) |
| 507 | 468 | * |
| 508 | - * @todo Links and filter. | |
| 469 | + * @todo Links and filter | |
| 509 | 470 | */ |
| 510 | 471 | function bbp_forum_row_actions() { |
| 511 | 472 | do_action( 'bbp_forum_row_actions' ); |
| 512 | 473 | } |
| @@ -511,90 +472,85 @@ | ||
| 511 | 472 | do_action( 'bbp_forum_row_actions' ); |
| 512 | 473 | } |
| 513 | 474 | |
| 514 | 475 | /** |
| 515 | - * Output the forums last active ID. | |
| 476 | + * Output the forums last active ID | |
| 516 | 477 | * |
| 517 | 478 | * @since 2.0.0 bbPress (r2876) |
| 518 | 479 | * |
| 519 | - * @param int $forum_id Optional. Forum id. | |
| 480 | + * @param int $forum_id Optional. Forum id | |
| 520 | 481 | */ |
| 521 | 482 | function bbp_forum_last_active_id( $forum_id = 0 ) { |
| 522 | 483 | echo bbp_get_forum_last_active_id( $forum_id ); |
| 523 | 484 | } |
| 485 | + /** | |
| 486 | + * Return the forums last active ID | |
| 487 | + * | |
| 488 | + * @since 2.0.0 bbPress (r2876) | |
| 489 | + * | |
| 490 | + * @param int $forum_id Optional. Forum id | |
| 491 | + * the last active id and forum id | |
| 492 | + * @return int Forum's last active id | |
| 493 | + */ | |
| 494 | + function bbp_get_forum_last_active_id( $forum_id = 0 ) { | |
| 495 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 496 | + $active_id = (int) get_post_meta( $forum_id, '_bbp_last_active_id', true ); | |
| 524 | 497 | |
| 525 | -/** | |
| 526 | - * Return the forums last active ID. | |
| 527 | - * | |
| 528 | - * @since 2.0.0 bbPress (r2876) | |
| 529 | - * | |
| 530 | - * @param int $forum_id Optional. Forum id. | |
| 531 | - * the last active id and forum id. | |
| 532 | - * @return int Forum's last active id. | |
| 533 | - */ | |
| 534 | -function bbp_get_forum_last_active_id( $forum_id = 0 ) { | |
| 535 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 536 | - $active_id = (int) get_post_meta( $forum_id, '_bbp_last_active_id', true ); | |
| 498 | + // Filter & return | |
| 499 | + return (int) apply_filters( 'bbp_get_forum_last_active_id', $active_id, $forum_id ); | |
| 500 | + } | |
| 537 | 501 | |
| 538 | - // Filter & return | |
| 539 | - return (int) apply_filters( 'bbp_get_forum_last_active_id', $active_id, $forum_id ); | |
| 540 | -} | |
| 541 | - | |
| 542 | 502 | /** |
| 543 | - * Output the forums last update date/time (aka freshness). | |
| 503 | + * Output the forums last update date/time (aka freshness) | |
| 544 | 504 | * |
| 545 | 505 | * @since 2.0.0 bbPress (r2876) |
| 546 | 506 | * |
| 547 | - * @param int $forum_id Optional. Forum id. | |
| 507 | + * @param int $forum_id Optional. Forum id | |
| 548 | 508 | */ |
| 549 | 509 | function bbp_forum_last_active_time( $forum_id = 0 ) { |
| 550 | 510 | echo bbp_get_forum_last_active_time( $forum_id ); |
| 551 | 511 | } |
| 512 | + /** | |
| 513 | + * Return the forums last update date/time (aka freshness) | |
| 514 | + * | |
| 515 | + * @since 2.0.0 bbPress (r2876) | |
| 516 | + * | |
| 517 | + * @param int $forum_id Optional. Forum id | |
| 518 | + * @return string Forum last update date/time (freshness) | |
| 519 | + */ | |
| 520 | + function bbp_get_forum_last_active_time( $forum_id = 0 ) { | |
| 552 | 521 | |
| 553 | -/** | |
| 554 | - * Return the forums last update date/time (aka freshness). | |
| 555 | - * | |
| 556 | - * @since 2.0.0 bbPress (r2876) | |
| 557 | - * | |
| 558 | - * @param int $forum_id Optional. Forum id. | |
| 559 | - * @return string Forum last update date/time (freshness). | |
| 560 | - */ | |
| 561 | -function bbp_get_forum_last_active_time( $forum_id = 0 ) { | |
| 522 | + // Verify forum and get last active meta | |
| 523 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 524 | + $active_id = bbp_get_forum_last_active_id( $forum_id ); | |
| 525 | + if ( empty( $active_id ) ) { | |
| 526 | + $active_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 527 | + } | |
| 528 | + if ( empty( $active_id ) ) { | |
| 529 | + $active_id = bbp_get_forum_last_topic_id( $forum_id ); | |
| 530 | + } | |
| 531 | + if ( ! empty( $active_id ) && ! bbp_is_forum_activity_public( $active_id ) ) { | |
| 532 | + return apply_filters( 'bbp_get_forum_last_active', '', $forum_id ); | |
| 533 | + } | |
| 534 | + $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true ); | |
| 562 | 535 | |
| 563 | - // Verify forum and get last active meta | |
| 564 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 565 | - $active_id = bbp_get_forum_last_active_id( $forum_id ); | |
| 566 | - if ( empty( $active_id ) ) { | |
| 567 | - $active_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 568 | - } | |
| 569 | - if ( empty( $active_id ) ) { | |
| 570 | - $active_id = bbp_get_forum_last_topic_id( $forum_id ); | |
| 571 | - } | |
| 572 | - if ( ! empty( $active_id ) && ! bbp_is_forum_activity_public( $active_id ) ) { | |
| 573 | - return apply_filters( 'bbp_get_forum_last_active', '', $forum_id ); | |
| 574 | - } | |
| 575 | - $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true ); | |
| 576 | - | |
| 577 | - if ( empty( $last_active ) ) { | |
| 578 | - $reply_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 579 | - | |
| 580 | - if ( ! empty( $reply_id ) ) { | |
| 581 | - $last_active = get_post_field( 'post_date', $reply_id ); | |
| 582 | - } else { | |
| 583 | - $topic_id = bbp_get_forum_last_topic_id( $forum_id ); | |
| 584 | - if ( ! empty( $topic_id ) ) { | |
| 585 | - $last_active = bbp_get_topic_last_active_time( $topic_id ); | |
| 536 | + if ( empty( $last_active ) ) { | |
| 537 | + $reply_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 538 | + if ( ! empty( $reply_id ) ) { | |
| 539 | + $last_active = get_post_field( 'post_date', $reply_id ); | |
| 540 | + } else { | |
| 541 | + $topic_id = bbp_get_forum_last_topic_id( $forum_id ); | |
| 542 | + if ( ! empty( $topic_id ) ) { | |
| 543 | + $last_active = bbp_get_topic_last_active_time( $topic_id ); | |
| 544 | + } | |
| 586 | 545 | } |
| 587 | 546 | } |
| 588 | - } | |
| 589 | 547 | |
| 590 | - $active_time = ! empty( $last_active ) | |
| 591 | - ? bbp_get_time_since( bbp_convert_date( $last_active ) ) | |
| 592 | - : ''; | |
| 548 | + $active_time = ! empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : ''; | |
| 593 | 549 | |
| 594 | - // Filter & return | |
| 595 | - return apply_filters( 'bbp_get_forum_last_active', $active_time, $forum_id ); | |
| 596 | -} | |
| 550 | + // Filter & return | |
| 551 | + return apply_filters( 'bbp_get_forum_last_active', $active_time, $forum_id ); | |
| 552 | + } | |
| 597 | 553 | |
| 598 | 554 | /** |
| 599 | 555 | * Output link to the most recent activity inside a forum. |
| 600 | 556 | * |
| @@ -610,9 +566,9 @@ | ||
| 610 | 566 | |
| 611 | 567 | /** |
| 612 | 568 | * Is a topic or reply eligible for public forum activity? |
| 613 | 569 | * |
| 614 | - * @since 2.6.19 bbPress (r7631) | |
| 570 | + * @since 2.6.19 bbPress (r7630) | |
| 615 | 571 | * |
| 616 | 572 | * @param int $post_id Topic or reply ID. |
| 617 | 573 | * @return bool Whether the activity is public. |
| 618 | 574 | */ |
| @@ -632,99 +588,98 @@ | ||
| 632 | 588 | |
| 633 | 589 | return false; |
| 634 | 590 | } |
| 635 | 591 | |
| 636 | -/** | |
| 637 | - * Returns link to the most recent activity inside a forum. | |
| 638 | - * | |
| 639 | - * Returns a complete link with attributes and content. | |
| 640 | - * | |
| 641 | - * @since 2.0.0 bbPress (r2627) | |
| 642 | - * | |
| 643 | - * @param int $forum_id Optional. Forum id. | |
| 644 | - */ | |
| 645 | -function bbp_get_forum_freshness_link( $forum_id = 0 ) { | |
| 646 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 647 | - $active_id = bbp_get_forum_last_active_id( $forum_id ); | |
| 648 | - $link_url = $title = ''; | |
| 592 | + /** | |
| 593 | + * Returns link to the most recent activity inside a forum. | |
| 594 | + * | |
| 595 | + * Returns a complete link with attributes and content. | |
| 596 | + * | |
| 597 | + * @since 2.0.0 bbPress (r2627) | |
| 598 | + * | |
| 599 | + * @param int $forum_id Optional. Forum id | |
| 600 | + */ | |
| 601 | + function bbp_get_forum_freshness_link( $forum_id = 0 ) { | |
| 602 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 603 | + $active_id = bbp_get_forum_last_active_id( $forum_id ); | |
| 604 | + $link_url = $title = ''; | |
| 649 | 605 | |
| 650 | - if ( empty( $active_id ) ) { | |
| 651 | - $active_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 652 | - } | |
| 606 | + if ( empty( $active_id ) ) { | |
| 607 | + $active_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 608 | + } | |
| 653 | 609 | |
| 654 | - if ( empty( $active_id ) ) { | |
| 655 | - $active_id = bbp_get_forum_last_topic_id( $forum_id ); | |
| 656 | - } | |
| 610 | + if ( empty( $active_id ) ) { | |
| 611 | + $active_id = bbp_get_forum_last_topic_id( $forum_id ); | |
| 612 | + } | |
| 657 | 613 | |
| 658 | - // Existing forum metadata may still point to non-public content | |
| 659 | - if ( ! empty( $active_id ) && ! bbp_is_forum_activity_public( $active_id ) ) { | |
| 660 | - return apply_filters( 'bbp_get_forum_freshness_link', '-', $forum_id, '', '', '', $active_id ); | |
| 661 | - } | |
| 614 | + // Existing forum metadata may still point to non-public content | |
| 615 | + if ( ! empty( $active_id ) && ! bbp_is_forum_activity_public( $active_id ) ) { | |
| 616 | + return apply_filters( 'bbp_get_forum_freshness_link', '-', $forum_id, '', '', '', $active_id ); | |
| 617 | + } | |
| 662 | 618 | |
| 663 | - if ( bbp_is_topic( $active_id ) ) { | |
| 664 | - $link_url = bbp_get_forum_last_topic_permalink( $forum_id ); | |
| 665 | - $title = bbp_get_forum_last_topic_title( $forum_id ); | |
| 666 | - } elseif ( bbp_is_reply( $active_id ) ) { | |
| 667 | - $link_url = bbp_get_forum_last_reply_url( $forum_id ); | |
| 668 | - $title = bbp_get_forum_last_reply_title( $forum_id ); | |
| 669 | - } | |
| 619 | + if ( bbp_is_topic( $active_id ) ) { | |
| 620 | + $link_url = bbp_get_forum_last_topic_permalink( $forum_id ); | |
| 621 | + $title = bbp_get_forum_last_topic_title( $forum_id ); | |
| 622 | + } elseif ( bbp_is_reply( $active_id ) ) { | |
| 623 | + $link_url = bbp_get_forum_last_reply_url( $forum_id ); | |
| 624 | + $title = bbp_get_forum_last_reply_title( $forum_id ); | |
| 625 | + } | |
| 670 | 626 | |
| 671 | - $time_since = bbp_get_forum_last_active_time( $forum_id ); | |
| 627 | + $time_since = bbp_get_forum_last_active_time( $forum_id ); | |
| 672 | 628 | |
| 673 | - if ( ! empty( $time_since ) && ! empty( $link_url ) ) { | |
| 674 | - $anchor = '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>'; | |
| 675 | - } else { | |
| 676 | - $anchor = esc_html__( 'No Topics', 'bbpress' ); | |
| 629 | + if ( ! empty( $time_since ) && ! empty( $link_url ) ) { | |
| 630 | + $anchor = '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>'; | |
| 631 | + } else { | |
| 632 | + $anchor = esc_html__( 'No Topics', 'bbpress' ); | |
| 633 | + } | |
| 634 | + | |
| 635 | + // Filter & return | |
| 636 | + return apply_filters( 'bbp_get_forum_freshness_link', $anchor, $forum_id, $time_since, $link_url, $title, $active_id ); | |
| 677 | 637 | } |
| 678 | 638 | |
| 679 | - // Filter & return | |
| 680 | - return apply_filters( 'bbp_get_forum_freshness_link', $anchor, $forum_id, $time_since, $link_url, $title, $active_id ); | |
| 681 | -} | |
| 682 | - | |
| 683 | 639 | /** |
| 684 | - * Output parent ID of a forum, if exists. | |
| 640 | + * Output parent ID of a forum, if exists | |
| 685 | 641 | * |
| 686 | 642 | * @since 2.1.0 bbPress (r3678) |
| 687 | 643 | * |
| 688 | - * @param int $forum_id Forum ID. | |
| 644 | + * @param int $forum_id Forum ID | |
| 689 | 645 | */ |
| 690 | 646 | function bbp_forum_parent_id( $forum_id = 0 ) { |
| 691 | 647 | echo bbp_get_forum_parent_id( $forum_id ); |
| 692 | 648 | } |
| 649 | + /** | |
| 650 | + * Return ID of forum parent, if exists | |
| 651 | + * | |
| 652 | + * @since 2.1.0 bbPress (r3678) | |
| 653 | + * | |
| 654 | + * @param int $forum_id Optional. Forum id | |
| 655 | + * @return int Forum parent | |
| 656 | + */ | |
| 657 | + function bbp_get_forum_parent_id( $forum_id = 0 ) { | |
| 658 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 659 | + $parent_id = (int) get_post_field( 'post_parent', $forum_id ); | |
| 693 | 660 | |
| 694 | -/** | |
| 695 | - * Return ID of forum parent, if exists. | |
| 696 | - * | |
| 697 | - * @since 2.1.0 bbPress (r3678) | |
| 698 | - * | |
| 699 | - * @param int $forum_id Optional. Forum id. | |
| 700 | - * @return int Forum parent id. | |
| 701 | - */ | |
| 702 | -function bbp_get_forum_parent_id( $forum_id = 0 ) { | |
| 703 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 704 | - $parent_id = (int) get_post_field( 'post_parent', $forum_id ); | |
| 661 | + // Meta-data fallback | |
| 662 | + if ( empty( $parent_id ) ) { | |
| 663 | + $parent_id = (int) get_post_meta( $forum_id, '_bbp_forum_id', true ); | |
| 664 | + } | |
| 705 | 665 | |
| 706 | - // Meta-data fallback | |
| 707 | - if ( empty( $parent_id ) ) { | |
| 708 | - $parent_id = (int) get_post_meta( $forum_id, '_bbp_forum_id', true ); | |
| 709 | - } | |
| 666 | + // Filter | |
| 667 | + if ( ! empty( $parent_id ) ) { | |
| 668 | + $parent_id = (int) bbp_get_forum_id( $parent_id ); | |
| 669 | + } | |
| 710 | 670 | |
| 711 | - // Filter | |
| 712 | - if ( ! empty( $parent_id ) ) { | |
| 713 | - $parent_id = (int) bbp_get_forum_id( $parent_id ); | |
| 671 | + // Filter & return | |
| 672 | + return (int) apply_filters( 'bbp_get_forum_parent_id', $parent_id, $forum_id ); | |
| 714 | 673 | } |
| 715 | 674 | |
| 716 | - // Filter & return | |
| 717 | - return (int) apply_filters( 'bbp_get_forum_parent_id', $parent_id, $forum_id ); | |
| 718 | -} | |
| 719 | - | |
| 720 | 675 | /** |
| 721 | - * Return array of parent forums. | |
| 676 | + * Return array of parent forums | |
| 722 | 677 | * |
| 723 | 678 | * @since 2.0.0 bbPress (r2627) |
| 724 | 679 | * |
| 725 | - * @param int $forum_id Optional. Forum id. | |
| 726 | - * @return array Forum ancestors. | |
| 680 | + * @param int $forum_id Optional. Forum id | |
| 681 | + * @return array Forum ancestors | |
| 727 | 682 | */ |
| 728 | 683 | function bbp_get_forum_ancestors( $forum_id = 0 ) { |
| 729 | 684 | $forum_id = bbp_get_forum_id( $forum_id ); |
| 730 | 685 | $ancestors = array(); |
| @@ -741,14 +696,14 @@ | ||
| 741 | 696 | return apply_filters( 'bbp_get_forum_ancestors', $ancestors, $forum_id ); |
| 742 | 697 | } |
| 743 | 698 | |
| 744 | 699 | /** |
| 745 | - * Return subforums of given forum. | |
| 700 | + * Return subforums of given forum | |
| 746 | 701 | * |
| 747 | 702 | * @since 2.0.0 bbPress (r2914) |
| 748 | 703 | * |
| 749 | - * @param array $args All the arguments supported by {@link WP_Query}. | |
| 750 | - * @return mixed false if none, array of subs if yes. | |
| 704 | + * @param array $args All the arguments supported by {@link WP_Query} | |
| 705 | + * @return mixed false if none, array of subs if yes | |
| 751 | 706 | */ |
| 752 | 707 | function bbp_forum_get_subforums( $args = array() ) { |
| 753 | 708 | |
| 754 | 709 | // Default return value |
| @@ -787,9 +742,9 @@ | ||
| 787 | 742 | return (array) apply_filters( 'bbp_forum_get_subforums', $retval, $r, $args ); |
| 788 | 743 | } |
| 789 | 744 | |
| 790 | 745 | /** |
| 791 | - * Output a list of forums (can be used to list subforums). | |
| 746 | + * Output a list of forums (can be used to list subforums) | |
| 792 | 747 | * |
| 793 | 748 | * @since 2.0.0 bbPress (r2708) |
| 794 | 749 | * |
| 795 | 750 | * @param array $args The function supports these args: |
| @@ -901,9 +856,9 @@ | ||
| 901 | 856 | |
| 902 | 857 | /** Forum Subscriptions *******************************************************/ |
| 903 | 858 | |
| 904 | 859 | /** |
| 905 | - * Output the forum subscription link. | |
| 860 | + * Output the forum subscription link | |
| 906 | 861 | * |
| 907 | 862 | * @since 2.5.0 bbPress (r5156) |
| 908 | 863 | * @since 2.6.0 bbPress (r6307) Add 'redirect_to' support |
| 909 | 864 | */ |
| @@ -910,16 +865,16 @@ | ||
| 910 | 865 | function bbp_forum_subscription_link( $args = array() ) { |
| 911 | 866 | echo bbp_get_forum_subscription_link( $args ); |
| 912 | 867 | } |
| 913 | 868 | |
| 914 | -/** | |
| 915 | - * Get the forum subscription link. | |
| 916 | - * | |
| 917 | - * A custom wrapper for bbp_get_user_subscribe_link(). | |
| 918 | - * | |
| 919 | - * @since 2.5.0 bbPress (r5156) | |
| 920 | - * @since 2.6.0 bbPress (r6307) Add 'redirect_to' support | |
| 921 | - */ | |
| 869 | + /** | |
| 870 | + * Get the forum subscription link | |
| 871 | + * | |
| 872 | + * A custom wrapper for bbp_get_user_subscribe_link() | |
| 873 | + * | |
| 874 | + * @since 2.5.0 bbPress (r5156) | |
| 875 | + * @since 2.6.0 bbPress (r6307) Add 'redirect_to' support | |
| 876 | + */ | |
| 922 | 877 | function bbp_get_forum_subscription_link( $args = array() ) { |
| 923 | 878 | |
| 924 | 879 | // Defaults |
| 925 | 880 | $retval = false; |
| @@ -955,99 +910,94 @@ | ||
| 955 | 910 | |
| 956 | 911 | /** Forum Last Topic **********************************************************/ |
| 957 | 912 | |
| 958 | 913 | /** |
| 959 | - * Output the forum's last topic id. | |
| 914 | + * Output the forum's last topic id | |
| 960 | 915 | * |
| 961 | 916 | * @since 2.0.0 bbPress (r2627) |
| 962 | 917 | * |
| 963 | - * @param int $forum_id Optional. Forum id. | |
| 918 | + * @param int $forum_id Optional. Forum id | |
| 964 | 919 | */ |
| 965 | 920 | function bbp_forum_last_topic_id( $forum_id = 0 ) { |
| 966 | 921 | echo bbp_get_forum_last_topic_id( $forum_id ); |
| 967 | 922 | } |
| 923 | + /** | |
| 924 | + * Return the forum's last topic id | |
| 925 | + * | |
| 926 | + * @since 2.0.0 bbPress (r2627) | |
| 927 | + * | |
| 928 | + * @param int $forum_id Optional. Forum id | |
| 929 | + * @return int Forum's last topic id | |
| 930 | + */ | |
| 931 | + function bbp_get_forum_last_topic_id( $forum_id = 0 ) { | |
| 932 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 933 | + $topic_id = (int) get_post_meta( $forum_id, '_bbp_last_topic_id', true ); | |
| 968 | 934 | |
| 969 | -/** | |
| 970 | - * Return the forum's last topic id. | |
| 971 | - * | |
| 972 | - * @since 2.0.0 bbPress (r2627) | |
| 973 | - * | |
| 974 | - * @param int $forum_id Optional. Forum id. | |
| 975 | - * @return int Forum's last topic id. | |
| 976 | - */ | |
| 977 | -function bbp_get_forum_last_topic_id( $forum_id = 0 ) { | |
| 978 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 979 | - $topic_id = (int) get_post_meta( $forum_id, '_bbp_last_topic_id', true ); | |
| 935 | + // Filter & return | |
| 936 | + return (int) apply_filters( 'bbp_get_forum_last_topic_id', $topic_id, $forum_id ); | |
| 937 | + } | |
| 980 | 938 | |
| 981 | - // Filter & return | |
| 982 | - return (int) apply_filters( 'bbp_get_forum_last_topic_id', $topic_id, $forum_id ); | |
| 983 | -} | |
| 984 | - | |
| 985 | 939 | /** |
| 986 | - * Output the title of the last topic inside a forum. | |
| 940 | + * Output the title of the last topic inside a forum | |
| 987 | 941 | * |
| 988 | 942 | * @since 2.0.0 bbPress (r2627) |
| 989 | 943 | * |
| 990 | - * @param int $forum_id Optional. Forum id. | |
| 944 | + * @param int $forum_id Optional. Forum id | |
| 991 | 945 | */ |
| 992 | 946 | function bbp_forum_last_topic_title( $forum_id = 0 ) { |
| 993 | 947 | echo bbp_get_forum_last_topic_title( $forum_id ); |
| 994 | 948 | } |
| 949 | + /** | |
| 950 | + * Return the title of the last topic inside a forum | |
| 951 | + * | |
| 952 | + * @since 2.0.0 bbPress (r2627) | |
| 953 | + * | |
| 954 | + * @param int $forum_id Optional. Forum id | |
| 955 | + * @return string Forum's last topic's title | |
| 956 | + */ | |
| 957 | + function bbp_get_forum_last_topic_title( $forum_id = 0 ) { | |
| 958 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 959 | + $topic_id = bbp_get_forum_last_topic_id( $forum_id ); | |
| 960 | + $title = ! empty( $topic_id ) ? bbp_get_topic_title( $topic_id ) : ''; | |
| 995 | 961 | |
| 996 | -/** | |
| 997 | - * Return the title of the last topic inside a forum. | |
| 998 | - * | |
| 999 | - * @since 2.0.0 bbPress (r2627) | |
| 1000 | - * | |
| 1001 | - * @param int $forum_id Optional. Forum id. | |
| 1002 | - * @return string Forum's last topic's title. | |
| 1003 | - */ | |
| 1004 | -function bbp_get_forum_last_topic_title( $forum_id = 0 ) { | |
| 1005 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1006 | - $topic_id = bbp_get_forum_last_topic_id( $forum_id ); | |
| 1007 | - $title = ! empty( $topic_id ) | |
| 1008 | - ? bbp_get_topic_title( $topic_id ) | |
| 1009 | - : ''; | |
| 962 | + // Filter & return | |
| 963 | + return apply_filters( 'bbp_get_forum_last_topic_title', $title, $forum_id ); | |
| 964 | + } | |
| 1010 | 965 | |
| 1011 | - // Filter & return | |
| 1012 | - return apply_filters( 'bbp_get_forum_last_topic_title', $title, $forum_id ); | |
| 1013 | -} | |
| 1014 | - | |
| 1015 | 966 | /** |
| 1016 | - * Output the link to the last topic in a forum. | |
| 967 | + * Output the link to the last topic in a forum | |
| 1017 | 968 | * |
| 1018 | 969 | * @since 2.0.0 bbPress (r2627) |
| 1019 | 970 | * |
| 1020 | - * @param int $forum_id Optional. Forum id. | |
| 971 | + * @param int $forum_id Optional. Forum id | |
| 1021 | 972 | */ |
| 1022 | 973 | function bbp_forum_last_topic_permalink( $forum_id = 0 ) { |
| 1023 | 974 | echo esc_url( bbp_get_forum_last_topic_permalink( $forum_id ) ); |
| 1024 | 975 | } |
| 976 | + /** | |
| 977 | + * Return the link to the last topic in a forum | |
| 978 | + * | |
| 979 | + * @since 2.0.0 bbPress (r2627) | |
| 980 | + * | |
| 981 | + * @param int $forum_id Optional. Forum id | |
| 982 | + * @return string Permanent link to topic | |
| 983 | + */ | |
| 984 | + function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) { | |
| 985 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 986 | + $topic_id = bbp_get_forum_last_topic_id( $forum_id ); | |
| 987 | + $link = bbp_get_topic_permalink( $topic_id ); | |
| 1025 | 988 | |
| 1026 | -/** | |
| 1027 | - * Return the link to the last topic in a forum. | |
| 1028 | - * | |
| 1029 | - * @since 2.0.0 bbPress (r2627) | |
| 1030 | - * | |
| 1031 | - * @param int $forum_id Optional. Forum id. | |
| 1032 | - * @return string Permanent link to topic. | |
| 1033 | - */ | |
| 1034 | -function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) { | |
| 1035 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1036 | - $topic_id = bbp_get_forum_last_topic_id( $forum_id ); | |
| 1037 | - $link = bbp_get_topic_permalink( $topic_id ); | |
| 989 | + // Filter & return | |
| 990 | + return apply_filters( 'bbp_get_forum_last_topic_permalink', $link, $forum_id, $topic_id ); | |
| 991 | + } | |
| 1038 | 992 | |
| 1039 | - // Filter & return | |
| 1040 | - return apply_filters( 'bbp_get_forum_last_topic_permalink', $link, $forum_id, $topic_id ); | |
| 1041 | -} | |
| 1042 | - | |
| 1043 | 993 | /** |
| 1044 | - * Return the author ID of the last topic of a forum. | |
| 994 | + * Return the author ID of the last topic of a forum | |
| 1045 | 995 | * |
| 1046 | 996 | * @since 2.0.0 bbPress (r2627) |
| 1047 | 997 | * |
| 1048 | - * @param int $forum_id Optional. Forum id. | |
| 1049 | - * @return int Forum's last topic's author id. | |
| 998 | + * @param int $forum_id Optional. Forum id | |
| 999 | + * @return int Forum's last topic's author id | |
| 1050 | 1000 | */ |
| 1051 | 1001 | function bbp_get_forum_last_topic_author_id( $forum_id = 0 ) { |
| 1052 | 1002 | $forum_id = bbp_get_forum_id( $forum_id ); |
| 1053 | 1003 | $topic_id = bbp_get_forum_last_topic_id( $forum_id ); |
| @@ -1057,234 +1007,227 @@ | ||
| 1057 | 1007 | return (int) apply_filters( 'bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id, $topic_id ); |
| 1058 | 1008 | } |
| 1059 | 1009 | |
| 1060 | 1010 | /** |
| 1061 | - * Output link to author of last topic of forum. | |
| 1011 | + * Output link to author of last topic of forum | |
| 1062 | 1012 | * |
| 1063 | 1013 | * @since 2.0.0 bbPress (r2627) |
| 1064 | 1014 | * |
| 1065 | - * @param int $forum_id Optional. Forum id. | |
| 1015 | + * @param int $forum_id Optional. Forum id | |
| 1066 | 1016 | */ |
| 1067 | 1017 | function bbp_forum_last_topic_author_link( $forum_id = 0 ) { |
| 1068 | 1018 | echo bbp_get_forum_last_topic_author_link( $forum_id ); |
| 1069 | 1019 | } |
| 1020 | + /** | |
| 1021 | + * Return link to author of last topic of forum | |
| 1022 | + * | |
| 1023 | + * @since 2.0.0 bbPress (r2627) | |
| 1024 | + * | |
| 1025 | + * @param int $forum_id Optional. Forum id | |
| 1026 | + * @return string Forum's last topic's author link | |
| 1027 | + */ | |
| 1028 | + function bbp_get_forum_last_topic_author_link( $forum_id = 0 ) { | |
| 1029 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1030 | + $author_id = bbp_get_forum_last_topic_author_id( $forum_id ); | |
| 1031 | + $author_link = bbp_get_user_profile_link( $author_id ); | |
| 1070 | 1032 | |
| 1071 | -/** | |
| 1072 | - * Return link to author of last topic of forum. | |
| 1073 | - * | |
| 1074 | - * @since 2.0.0 bbPress (r2627) | |
| 1075 | - * | |
| 1076 | - * @param int $forum_id Optional. Forum id. | |
| 1077 | - * @return string Forum's last topic's author link. | |
| 1078 | - */ | |
| 1079 | -function bbp_get_forum_last_topic_author_link( $forum_id = 0 ) { | |
| 1080 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1081 | - $author_id = bbp_get_forum_last_topic_author_id( $forum_id ); | |
| 1082 | - $author_link = bbp_get_user_profile_link( $author_id ); | |
| 1033 | + // Filter & return | |
| 1034 | + return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id ); | |
| 1035 | + } | |
| 1083 | 1036 | |
| 1084 | - // Filter & return | |
| 1085 | - return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id ); | |
| 1086 | -} | |
| 1087 | - | |
| 1088 | 1037 | /** Forum Last Reply **********************************************************/ |
| 1089 | 1038 | |
| 1090 | 1039 | /** |
| 1091 | - * Output the forums last reply id. | |
| 1040 | + * Output the forums last reply id | |
| 1092 | 1041 | * |
| 1093 | 1042 | * @since 2.0.0 bbPress (r2627) |
| 1094 | 1043 | * |
| 1095 | - * @param int $forum_id Optional. Forum id. | |
| 1044 | + * @param int $forum_id Optional. Forum id | |
| 1096 | 1045 | */ |
| 1097 | 1046 | function bbp_forum_last_reply_id( $forum_id = 0 ) { |
| 1098 | 1047 | echo bbp_get_forum_last_reply_id( $forum_id ); |
| 1099 | 1048 | } |
| 1049 | + /** | |
| 1050 | + * Return the forums last reply id | |
| 1051 | + * | |
| 1052 | + * @since 2.0.0 bbPress (r2627) | |
| 1053 | + * | |
| 1054 | + * @param int $forum_id Optional. Forum id | |
| 1055 | + * @return int Forum's last reply id | |
| 1056 | + */ | |
| 1057 | + function bbp_get_forum_last_reply_id( $forum_id = 0 ) { | |
| 1058 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1059 | + $reply_id = (int) get_post_meta( $forum_id, '_bbp_last_reply_id', true ); | |
| 1100 | 1060 | |
| 1101 | -/** | |
| 1102 | - * Return the forums last reply id. | |
| 1103 | - * | |
| 1104 | - * @since 2.0.0 bbPress (r2627) | |
| 1105 | - * | |
| 1106 | - * @param int $forum_id Optional. Forum id. | |
| 1107 | - * @return int Forum's last reply id. | |
| 1108 | - */ | |
| 1109 | -function bbp_get_forum_last_reply_id( $forum_id = 0 ) { | |
| 1110 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1111 | - $reply_id = (int) get_post_meta( $forum_id, '_bbp_last_reply_id', true ); | |
| 1061 | + // Filter & return | |
| 1062 | + return (int) apply_filters( 'bbp_get_forum_last_reply_id', $reply_id, $forum_id ); | |
| 1063 | + } | |
| 1112 | 1064 | |
| 1113 | - // Filter & return | |
| 1114 | - return (int) apply_filters( 'bbp_get_forum_last_reply_id', $reply_id, $forum_id ); | |
| 1115 | -} | |
| 1116 | - | |
| 1117 | 1065 | /** |
| 1118 | - * Output the title of the last reply inside a forum. | |
| 1066 | + * Output the title of the last reply inside a forum | |
| 1119 | 1067 | * |
| 1120 | - * @param int $forum_id Optional. Forum id. | |
| 1068 | + * @param int $forum_id Optional. Forum id | |
| 1121 | 1069 | */ |
| 1122 | 1070 | function bbp_forum_last_reply_title( $forum_id = 0 ) { |
| 1123 | 1071 | echo bbp_get_forum_last_reply_title( $forum_id ); |
| 1124 | 1072 | } |
| 1073 | + /** | |
| 1074 | + * Return the title of the last reply inside a forum | |
| 1075 | + * | |
| 1076 | + * @param int $forum_id Optional. Forum id | |
| 1077 | + * @return string | |
| 1078 | + */ | |
| 1079 | + function bbp_get_forum_last_reply_title( $forum_id = 0 ) { | |
| 1080 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1081 | + $reply_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 1082 | + $title = bbp_get_reply_title( $reply_id ); | |
| 1125 | 1083 | |
| 1126 | -/** | |
| 1127 | - * Return the title of the last reply inside a forum. | |
| 1128 | - * | |
| 1129 | - * @param int $forum_id Optional. Forum id. | |
| 1130 | - * @return string | |
| 1131 | - */ | |
| 1132 | -function bbp_get_forum_last_reply_title( $forum_id = 0 ) { | |
| 1133 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1134 | - $reply_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 1135 | - $title = bbp_get_reply_title( $reply_id ); | |
| 1084 | + // Filter & return | |
| 1085 | + return apply_filters( 'bbp_get_forum_last_reply_title', $title, $forum_id, $reply_id ); | |
| 1086 | + } | |
| 1136 | 1087 | |
| 1137 | - // Filter & return | |
| 1138 | - return apply_filters( 'bbp_get_forum_last_reply_title', $title, $forum_id, $reply_id ); | |
| 1139 | -} | |
| 1140 | - | |
| 1141 | 1088 | /** |
| 1142 | - * Output the link to the last reply in a forum. | |
| 1089 | + * Output the link to the last reply in a forum | |
| 1143 | 1090 | * |
| 1144 | 1091 | * @since 2.0.0 bbPress (r2627) |
| 1145 | 1092 | * |
| 1146 | - * @param int $forum_id Optional. Forum id. | |
| 1093 | + * @param int $forum_id Optional. Forum id | |
| 1147 | 1094 | */ |
| 1148 | 1095 | function bbp_forum_last_reply_permalink( $forum_id = 0 ) { |
| 1149 | 1096 | echo esc_url( bbp_get_forum_last_reply_permalink( $forum_id ) ); |
| 1150 | 1097 | } |
| 1098 | + /** | |
| 1099 | + * Return the link to the last reply in a forum | |
| 1100 | + * | |
| 1101 | + * @since 2.0.0 bbPress (r2627) | |
| 1102 | + * | |
| 1103 | + * @param int $forum_id Optional. Forum id | |
| 1104 | + * | |
| 1105 | + * @return string Permanent link to the forum's last reply | |
| 1106 | + */ | |
| 1107 | + function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) { | |
| 1108 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1109 | + $reply_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 1110 | + $link = bbp_get_reply_permalink( $reply_id ); | |
| 1151 | 1111 | |
| 1152 | -/** | |
| 1153 | - * Return the link to the last reply in a forum. | |
| 1154 | - * | |
| 1155 | - * @since 2.0.0 bbPress (r2627) | |
| 1156 | - * | |
| 1157 | - * @param int $forum_id Optional. Forum id. | |
| 1158 | - * | |
| 1159 | - * @return string Permanent link to the forum's last reply. | |
| 1160 | - */ | |
| 1161 | -function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) { | |
| 1162 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1163 | - $reply_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 1164 | - $link = bbp_get_reply_permalink( $reply_id ); | |
| 1112 | + // Filter & return | |
| 1113 | + return apply_filters( 'bbp_get_forum_last_reply_permalink', $link, $forum_id, $reply_id ); | |
| 1114 | + } | |
| 1165 | 1115 | |
| 1166 | - // Filter & return | |
| 1167 | - return apply_filters( 'bbp_get_forum_last_reply_permalink', $link, $forum_id, $reply_id ); | |
| 1168 | -} | |
| 1169 | - | |
| 1170 | 1116 | /** |
| 1171 | - * Output the url to the last reply in a forum. | |
| 1117 | + * Output the url to the last reply in a forum | |
| 1172 | 1118 | * |
| 1173 | 1119 | * @since 2.0.0 bbPress (r2684) |
| 1174 | 1120 | * |
| 1175 | - * @param int $forum_id Optional. Forum id. | |
| 1121 | + * @param int $forum_id Optional. Forum id | |
| 1176 | 1122 | */ |
| 1177 | 1123 | function bbp_forum_last_reply_url( $forum_id = 0 ) { |
| 1178 | 1124 | echo esc_url( bbp_get_forum_last_reply_url( $forum_id ) ); |
| 1179 | 1125 | } |
| 1126 | + /** | |
| 1127 | + * Return the url to the last reply in a forum | |
| 1128 | + * | |
| 1129 | + * @since 2.0.0 bbPress (r2684) | |
| 1130 | + * | |
| 1131 | + * @param int $forum_id Optional. Forum id | |
| 1132 | + * @return string Paginated URL to latest reply | |
| 1133 | + */ | |
| 1134 | + function bbp_get_forum_last_reply_url( $forum_id = 0 ) { | |
| 1135 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1180 | 1136 | |
| 1181 | -/** | |
| 1182 | - * Return the url to the last reply in a forum. | |
| 1183 | - * | |
| 1184 | - * @since 2.0.0 bbPress (r2684) | |
| 1185 | - * | |
| 1186 | - * @param int $forum_id Optional. Forum id. | |
| 1187 | - * @return string Paginated URL to latest reply. | |
| 1188 | - */ | |
| 1189 | -function bbp_get_forum_last_reply_url( $forum_id = 0 ) { | |
| 1190 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1137 | + // If forum has replies, get the last reply and use its url | |
| 1138 | + $reply_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 1139 | + if ( ! empty( $reply_id ) ) { | |
| 1140 | + $reply_url = bbp_get_reply_url( $reply_id ); | |
| 1191 | 1141 | |
| 1192 | - // If forum has replies, get the last reply and use its url | |
| 1193 | - $reply_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 1194 | - if ( ! empty( $reply_id ) ) { | |
| 1195 | - $reply_url = bbp_get_reply_url( $reply_id ); | |
| 1142 | + // No replies, so look for topics and use last permalink | |
| 1143 | + } else { | |
| 1144 | + $reply_url = bbp_get_forum_last_topic_permalink( $forum_id ); | |
| 1196 | 1145 | |
| 1197 | - // No replies, so look for topics and use last permalink | |
| 1198 | - } else { | |
| 1199 | - $reply_url = bbp_get_forum_last_topic_permalink( $forum_id ); | |
| 1146 | + // No topics either, so set $reply_url as empty string | |
| 1147 | + if ( empty( $reply_url ) ) { | |
| 1148 | + $reply_url = ''; | |
| 1149 | + } | |
| 1150 | + } | |
| 1200 | 1151 | |
| 1201 | - // No topics either, so set $reply_url as empty string | |
| 1202 | - if ( empty( $reply_url ) ) { | |
| 1203 | - $reply_url = ''; | |
| 1204 | - } | |
| 1152 | + // Filter & return | |
| 1153 | + return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id, $reply_id ); | |
| 1205 | 1154 | } |
| 1206 | 1155 | |
| 1207 | - // Filter & return | |
| 1208 | - return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id, $reply_id ); | |
| 1209 | -} | |
| 1210 | - | |
| 1211 | 1156 | /** |
| 1212 | - * Output author ID of last reply of forum. | |
| 1157 | + * Output author ID of last reply of forum | |
| 1213 | 1158 | * |
| 1214 | 1159 | * @since 2.0.0 bbPress (r2627) |
| 1215 | 1160 | * |
| 1216 | - * @param int $forum_id Optional. Forum id. | |
| 1161 | + * @param int $forum_id Optional. Forum id | |
| 1217 | 1162 | */ |
| 1218 | 1163 | function bbp_forum_last_reply_author_id( $forum_id = 0 ) { |
| 1219 | 1164 | echo bbp_get_forum_last_reply_author_id( $forum_id ); |
| 1220 | 1165 | } |
| 1166 | + /** | |
| 1167 | + * Return author ID of last reply of forum | |
| 1168 | + * | |
| 1169 | + * @since 2.0.0 bbPress (r2627) | |
| 1170 | + * | |
| 1171 | + * @param int $forum_id Optional. Forum id | |
| 1172 | + * @return int Forum's last reply author id | |
| 1173 | + */ | |
| 1174 | + function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) { | |
| 1175 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1176 | + $reply_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 1177 | + $author_id = bbp_get_reply_author_id( $reply_id ); | |
| 1221 | 1178 | |
| 1222 | -/** | |
| 1223 | - * Return author ID of last reply of forum. | |
| 1224 | - * | |
| 1225 | - * @since 2.0.0 bbPress (r2627) | |
| 1226 | - * | |
| 1227 | - * @param int $forum_id Optional. Forum id. | |
| 1228 | - * @return int Forum's last reply author id. | |
| 1229 | - */ | |
| 1230 | -function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) { | |
| 1231 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1232 | - $reply_id = bbp_get_forum_last_reply_id( $forum_id ); | |
| 1233 | - $author_id = bbp_get_reply_author_id( $reply_id ); | |
| 1179 | + // Filter & return | |
| 1180 | + return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id, $reply_id ); | |
| 1181 | + } | |
| 1234 | 1182 | |
| 1235 | - // Filter & return | |
| 1236 | - return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id, $reply_id ); | |
| 1237 | -} | |
| 1238 | - | |
| 1239 | 1183 | /** |
| 1240 | - * Output link to author of last reply of forum. | |
| 1184 | + * Output link to author of last reply of forum | |
| 1241 | 1185 | * |
| 1242 | 1186 | * @since 2.0.0 bbPress (r2627) |
| 1243 | 1187 | * |
| 1244 | - * @param int $forum_id Optional. Forum id. | |
| 1188 | + * @param int $forum_id Optional. Forum id | |
| 1245 | 1189 | */ |
| 1246 | 1190 | function bbp_forum_last_reply_author_link( $forum_id = 0 ) { |
| 1247 | 1191 | echo bbp_get_forum_last_reply_author_link( $forum_id ); |
| 1248 | 1192 | } |
| 1193 | + /** | |
| 1194 | + * Return link to author of last reply of forum | |
| 1195 | + * | |
| 1196 | + * @since 2.0.0 bbPress (r2627) | |
| 1197 | + * | |
| 1198 | + * @param int $forum_id Optional. Forum id | |
| 1199 | + * @return string Link to author of last reply of forum | |
| 1200 | + */ | |
| 1201 | + function bbp_get_forum_last_reply_author_link( $forum_id = 0 ) { | |
| 1202 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1203 | + $author_id = bbp_get_forum_last_reply_author_id( $forum_id ); | |
| 1204 | + $author_link = bbp_get_user_profile_link( $author_id ); | |
| 1249 | 1205 | |
| 1250 | -/** | |
| 1251 | - * Return link to author of last reply of forum. | |
| 1252 | - * | |
| 1253 | - * @since 2.0.0 bbPress (r2627) | |
| 1254 | - * | |
| 1255 | - * @param int $forum_id Optional. Forum id. | |
| 1256 | - * @return string Link to author of last reply of forum. | |
| 1257 | - */ | |
| 1258 | -function bbp_get_forum_last_reply_author_link( $forum_id = 0 ) { | |
| 1259 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1260 | - $author_id = bbp_get_forum_last_reply_author_id( $forum_id ); | |
| 1261 | - $author_link = bbp_get_user_profile_link( $author_id ); | |
| 1206 | + // Filter & return | |
| 1207 | + return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id, $author_id ); | |
| 1208 | + } | |
| 1262 | 1209 | |
| 1263 | - // Filter & return | |
| 1264 | - return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id, $author_id ); | |
| 1265 | -} | |
| 1266 | - | |
| 1267 | 1210 | /** Forum Counts **************************************************************/ |
| 1268 | 1211 | |
| 1269 | 1212 | /** |
| 1270 | - * Output the topics link of the forum. | |
| 1213 | + * Output the topics link of the forum | |
| 1271 | 1214 | * |
| 1272 | 1215 | * @since 2.0.0 bbPress (r2889) |
| 1273 | 1216 | * |
| 1274 | - * @param int $forum_id Optional. Topic id. | |
| 1217 | + * @param int $forum_id Optional. Topic id | |
| 1275 | 1218 | */ |
| 1276 | 1219 | function bbp_forum_topics_link( $forum_id = 0 ) { |
| 1277 | 1220 | echo bbp_get_forum_topics_link( $forum_id ); |
| 1278 | 1221 | } |
| 1279 | 1222 | |
| 1280 | -/** | |
| 1281 | - * Return the topics link of the forum. | |
| 1282 | - * | |
| 1283 | - * @since 2.0.0 bbPress (r2889) | |
| 1284 | - * | |
| 1285 | - * @param int $forum_id Optional. Topic id. | |
| 1286 | - */ | |
| 1223 | + /** | |
| 1224 | + * Return the topics link of the forum | |
| 1225 | + * | |
| 1226 | + * @since 2.0.0 bbPress (r2889) | |
| 1227 | + * | |
| 1228 | + * @param int $forum_id Optional. Topic id | |
| 1229 | + */ | |
| 1287 | 1230 | function bbp_get_forum_topics_link( $forum_id = 0 ) { |
| 1288 | 1231 | $forum_id = bbp_get_forum_id( $forum_id ); |
| 1289 | 1232 | $link = bbp_get_forum_permalink( $forum_id ); |
| 1290 | 1233 | /* translators: %s: Number of topics */ |
| @@ -1316,315 +1259,306 @@ | ||
| 1316 | 1259 | return apply_filters( 'bbp_get_forum_topics_link', $retval, $forum_id ); |
| 1317 | 1260 | } |
| 1318 | 1261 | |
| 1319 | 1262 | /** |
| 1320 | - * Output total sub-forum count of a forum. | |
| 1263 | + * Output total sub-forum count of a forum | |
| 1321 | 1264 | * |
| 1322 | 1265 | * @since 2.0.0 bbPress (r2627) |
| 1323 | 1266 | * |
| 1324 | - * @param int $forum_id Optional. Forum id to check. | |
| 1325 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 1267 | + * @param int $forum_id Optional. Forum id to check | |
| 1268 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 1326 | 1269 | */ |
| 1327 | 1270 | function bbp_forum_subforum_count( $forum_id = 0, $integer = false ) { |
| 1328 | 1271 | echo bbp_get_forum_subforum_count( $forum_id, $integer ); |
| 1329 | 1272 | } |
| 1273 | + /** | |
| 1274 | + * Return total subforum count of a forum | |
| 1275 | + * | |
| 1276 | + * @since 2.0.0 bbPress (r2627) | |
| 1277 | + * | |
| 1278 | + * @param int $forum_id Optional. Forum id | |
| 1279 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 1280 | + * @return int Forum's subforum count | |
| 1281 | + */ | |
| 1282 | + function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) { | |
| 1283 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1284 | + $forum_count = (int) get_post_meta( $forum_id, '_bbp_forum_subforum_count', true ); | |
| 1285 | + $filter = ( true === $integer ) | |
| 1286 | + ? 'bbp_get_forum_subforum_count_int' | |
| 1287 | + : 'bbp_get_forum_subforum_count'; | |
| 1330 | 1288 | |
| 1331 | -/** | |
| 1332 | - * Return total subforum count of a forum. | |
| 1333 | - * | |
| 1334 | - * @since 2.0.0 bbPress (r2627) | |
| 1335 | - * | |
| 1336 | - * @param int $forum_id Optional. Forum id. | |
| 1337 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 1338 | - * @return int Forum's subforum count. | |
| 1339 | - */ | |
| 1340 | -function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) { | |
| 1341 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1342 | - $forum_count = (int) get_post_meta( $forum_id, '_bbp_forum_subforum_count', true ); | |
| 1343 | - $filter = ( true === $integer ) | |
| 1344 | - ? 'bbp_get_forum_subforum_count_int' | |
| 1345 | - : 'bbp_get_forum_subforum_count'; | |
| 1289 | + return apply_filters( $filter, $forum_count, $forum_id ); | |
| 1290 | + } | |
| 1346 | 1291 | |
| 1347 | - return apply_filters( $filter, $forum_count, $forum_id ); | |
| 1348 | -} | |
| 1349 | - | |
| 1350 | 1292 | /** |
| 1351 | - * Output total topic count of a forum. | |
| 1293 | + * Output total topic count of a forum | |
| 1352 | 1294 | * |
| 1353 | 1295 | * @since 2.0.0 bbPress (r2464) |
| 1354 | 1296 | * |
| 1355 | - * @param int $forum_id Optional. Forum id. | |
| 1297 | + * @param int $forum_id Optional. Forum id | |
| 1356 | 1298 | * @param bool $total_count Optional. To get the total count or normal count? |
| 1357 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 1299 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 1358 | 1300 | */ |
| 1359 | 1301 | function bbp_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) { |
| 1360 | 1302 | echo bbp_get_forum_topic_count( $forum_id, $total_count, $integer ); |
| 1361 | 1303 | } |
| 1304 | + /** | |
| 1305 | + * Return total topic count of a forum | |
| 1306 | + * | |
| 1307 | + * @since 2.0.0 bbPress (r2464) | |
| 1308 | + * | |
| 1309 | + * @param int $forum_id Optional. Forum id | |
| 1310 | + * @param bool $total_count Optional. To get the total count or normal | |
| 1311 | + * count? Defaults to total. | |
| 1312 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 1313 | + * @return int Forum topic count | |
| 1314 | + */ | |
| 1315 | + function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) { | |
| 1316 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1317 | + $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count'; | |
| 1318 | + $topics = (int) get_post_meta( $forum_id, $meta_key, true ); | |
| 1319 | + $filter = ( true === $integer ) | |
| 1320 | + ? 'bbp_get_forum_topic_count_int' | |
| 1321 | + : 'bbp_get_forum_topic_count'; | |
| 1362 | 1322 | |
| 1363 | -/** | |
| 1364 | - * Return total topic count of a forum. | |
| 1365 | - * | |
| 1366 | - * @since 2.0.0 bbPress (r2464) | |
| 1367 | - * | |
| 1368 | - * @param int $forum_id Optional. Forum id. | |
| 1369 | - * @param bool $total_count Optional. To get the total count or normal | |
| 1370 | - * count? Defaults to total. | |
| 1371 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 1372 | - * @return int Forum topic count. | |
| 1373 | - */ | |
| 1374 | -function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) { | |
| 1375 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1376 | - $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count'; | |
| 1377 | - $topics = (int) get_post_meta( $forum_id, $meta_key, true ); | |
| 1378 | - $filter = ( true === $integer ) | |
| 1379 | - ? 'bbp_get_forum_topic_count_int' | |
| 1380 | - : 'bbp_get_forum_topic_count'; | |
| 1323 | + return apply_filters( $filter, $topics, $forum_id ); | |
| 1324 | + } | |
| 1381 | 1325 | |
| 1382 | - return apply_filters( $filter, $topics, $forum_id ); | |
| 1383 | -} | |
| 1384 | - | |
| 1385 | 1326 | /** |
| 1386 | - * Output total reply count of a forum. | |
| 1327 | + * Output total reply count of a forum | |
| 1387 | 1328 | * |
| 1388 | 1329 | * @since 2.0.0 bbPress (r2615) |
| 1389 | 1330 | * |
| 1390 | - * @param int $forum_id Optional. Forum id. | |
| 1331 | + * @param int $forum_id Optional. Forum id | |
| 1391 | 1332 | * @param bool $total_count Optional. To get the total count or normal count? |
| 1392 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 1333 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 1393 | 1334 | */ |
| 1394 | 1335 | function bbp_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) { |
| 1395 | 1336 | echo bbp_get_forum_reply_count( $forum_id, $total_count, $integer ); |
| 1396 | 1337 | } |
| 1338 | + /** | |
| 1339 | + * Return total post count of a forum | |
| 1340 | + * | |
| 1341 | + * @since 2.0.0 bbPress (r2615) | |
| 1342 | + * | |
| 1343 | + * @param int $forum_id Optional. Forum id | |
| 1344 | + * @param bool $total_count Optional. To get the total count or normal | |
| 1345 | + * count? | |
| 1346 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 1347 | + * @return int Forum reply count | |
| 1348 | + */ | |
| 1349 | + function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) { | |
| 1350 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1351 | + $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count'; | |
| 1352 | + $replies = (int) get_post_meta( $forum_id, $meta_key, true ); | |
| 1353 | + $filter = ( true === $integer ) | |
| 1354 | + ? 'bbp_get_forum_reply_count_int' | |
| 1355 | + : 'bbp_get_forum_reply_count'; | |
| 1397 | 1356 | |
| 1398 | -/** | |
| 1399 | - * Return total post count of a forum. | |
| 1400 | - * | |
| 1401 | - * @since 2.0.0 bbPress (r2615) | |
| 1402 | - * | |
| 1403 | - * @param int $forum_id Optional. Forum id. | |
| 1404 | - * @param bool $total_count Optional. To get the total count or normal | |
| 1405 | - * count? | |
| 1406 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 1407 | - * @return int Forum reply count. | |
| 1408 | - */ | |
| 1409 | -function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) { | |
| 1410 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1411 | - $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count'; | |
| 1412 | - $replies = (int) get_post_meta( $forum_id, $meta_key, true ); | |
| 1413 | - $filter = ( true === $integer ) | |
| 1414 | - ? 'bbp_get_forum_reply_count_int' | |
| 1415 | - : 'bbp_get_forum_reply_count'; | |
| 1357 | + return apply_filters( $filter, $replies, $forum_id ); | |
| 1358 | + } | |
| 1416 | 1359 | |
| 1417 | - return apply_filters( $filter, $replies, $forum_id ); | |
| 1418 | -} | |
| 1419 | - | |
| 1420 | 1360 | /** |
| 1421 | - * Output total post count of a forum. | |
| 1361 | + * Output total post count of a forum | |
| 1422 | 1362 | * |
| 1423 | 1363 | * @since 2.0.0 bbPress (r2464) |
| 1424 | 1364 | * |
| 1425 | - * @param int $forum_id Optional. Forum id. | |
| 1365 | + * @param int $forum_id Optional. Forum id | |
| 1426 | 1366 | * @param bool $total_count Optional. To get the total count or normal count? |
| 1427 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 1367 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 1428 | 1368 | */ |
| 1429 | 1369 | function bbp_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) { |
| 1430 | 1370 | echo bbp_get_forum_post_count( $forum_id, $total_count, $integer ); |
| 1431 | 1371 | } |
| 1372 | + /** | |
| 1373 | + * Return total post count of a forum | |
| 1374 | + * | |
| 1375 | + * @since 2.0.0 bbPress (r2464) | |
| 1376 | + * | |
| 1377 | + * @param int $forum_id Optional. Forum id | |
| 1378 | + * @param bool $total_count Optional. To get the total count or normal | |
| 1379 | + * count? | |
| 1380 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 1381 | + * @return int Forum post count | |
| 1382 | + */ | |
| 1383 | + function bbp_get_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) { | |
| 1384 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1385 | + $topics = bbp_get_forum_topic_count( $forum_id, $total_count, true ); | |
| 1386 | + $replies = bbp_get_forum_reply_count( $forum_id, $total_count, true ); | |
| 1387 | + $retval = ( $replies + $topics ); | |
| 1388 | + $filter = ( true === $integer ) | |
| 1389 | + ? 'bbp_get_forum_post_count_int' | |
| 1390 | + : 'bbp_get_forum_post_count'; | |
| 1432 | 1391 | |
| 1433 | -/** | |
| 1434 | - * Return total post count of a forum. | |
| 1435 | - * | |
| 1436 | - * @since 2.0.0 bbPress (r2464) | |
| 1437 | - * | |
| 1438 | - * @param int $forum_id Optional. Forum id. | |
| 1439 | - * @param bool $total_count Optional. To get the total count or normal | |
| 1440 | - * count? | |
| 1441 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 1442 | - * @return int Forum post count. | |
| 1443 | - */ | |
| 1444 | -function bbp_get_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) { | |
| 1445 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1446 | - $topics = bbp_get_forum_topic_count( $forum_id, $total_count, true ); | |
| 1447 | - $replies = bbp_get_forum_reply_count( $forum_id, $total_count, true ); | |
| 1448 | - $retval = ( $replies + $topics ); | |
| 1449 | - $filter = ( true === $integer ) | |
| 1450 | - ? 'bbp_get_forum_post_count_int' | |
| 1451 | - : 'bbp_get_forum_post_count'; | |
| 1392 | + return apply_filters( $filter, $retval, $forum_id ); | |
| 1393 | + } | |
| 1452 | 1394 | |
| 1453 | - return apply_filters( $filter, $retval, $forum_id ); | |
| 1454 | -} | |
| 1455 | - | |
| 1456 | 1395 | /** |
| 1457 | 1396 | * Output total hidden topic count of a forum (hidden includes trashed, spammed, |
| 1458 | - * and pending topics). | |
| 1397 | + * and pending topics) | |
| 1459 | 1398 | * |
| 1460 | 1399 | * @since 2.0.0 bbPress (r3349) |
| 1461 | 1400 | * @since 2.6.0 bbPress (r6922) Changed function signature to add total counts |
| 1462 | 1401 | * |
| 1463 | - * @param int $forum_id Optional. Forum id. | |
| 1402 | + * @param int $forum_id Optional. Forum id | |
| 1464 | 1403 | * @param bool $total_count Optional. To get the total count or normal count? |
| 1465 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 1404 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 1466 | 1405 | */ |
| 1467 | 1406 | function bbp_forum_topic_count_hidden( $forum_id = 0, $total_count = true, $integer = null ) { |
| 1468 | 1407 | echo bbp_get_forum_topic_count_hidden( $forum_id, $total_count, $integer ); |
| 1469 | 1408 | } |
| 1409 | + /** | |
| 1410 | + * Return total hidden topic count of a forum (hidden includes trashed, | |
| 1411 | + * spammed and pending topics) | |
| 1412 | + * | |
| 1413 | + * @since 2.0.0 bbPress (r3349) | |
| 1414 | + * @since 2.6.0 bbPress (r6922) Changed function signature to add total counts | |
| 1415 | + * | |
| 1416 | + * @param int $forum_id Optional. Forum id | |
| 1417 | + * @param bool $total_count Optional. To get the total count or normal count? | |
| 1418 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 1419 | + * @return int Topic hidden topic count | |
| 1420 | + */ | |
| 1421 | + function bbp_get_forum_topic_count_hidden( $forum_id = 0, $total_count = true, $integer = null ) { | |
| 1422 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1423 | + $meta_key = empty( $total_count ) ? '_bbp_topic_count_hidden' : '_bbp_total_topic_count_hidden'; | |
| 1424 | + $topics = (int) get_post_meta( $forum_id, $meta_key, true ); | |
| 1425 | + $filter = ( true === $integer ) | |
| 1426 | + ? 'bbp_get_forum_topic_count_hidden_int' | |
| 1427 | + : 'bbp_get_forum_topic_count_hidden'; | |
| 1470 | 1428 | |
| 1471 | -/** | |
| 1472 | - * Return total hidden topic count of a forum (hidden includes trashed, | |
| 1473 | - * spammed and pending topics). | |
| 1474 | - * | |
| 1475 | - * @since 2.0.0 bbPress (r3349) | |
| 1476 | - * @since 2.6.0 bbPress (r6922) Changed function signature to add total counts | |
| 1477 | - * | |
| 1478 | - * @param int $forum_id Optional. Forum id. | |
| 1479 | - * @param bool $total_count Optional. To get the total count or normal count? | |
| 1480 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 1481 | - * @return int Topic hidden topic count. | |
| 1482 | - */ | |
| 1483 | -function bbp_get_forum_topic_count_hidden( $forum_id = 0, $total_count = true, $integer = null ) { | |
| 1484 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1485 | - $meta_key = empty( $total_count ) ? '_bbp_topic_count_hidden' : '_bbp_total_topic_count_hidden'; | |
| 1486 | - $topics = (int) get_post_meta( $forum_id, $meta_key, true ); | |
| 1487 | - $filter = ( true === $integer ) | |
| 1488 | - ? 'bbp_get_forum_topic_count_hidden_int' | |
| 1489 | - : 'bbp_get_forum_topic_count_hidden'; | |
| 1429 | + return apply_filters( $filter, $topics, $forum_id ); | |
| 1430 | + } | |
| 1490 | 1431 | |
| 1491 | - return apply_filters( $filter, $topics, $forum_id ); | |
| 1492 | -} | |
| 1493 | - | |
| 1494 | 1432 | /** |
| 1495 | 1433 | * Output total hidden reply count of a forum (hidden includes trashed, spammed, |
| 1496 | - * and pending replies). | |
| 1434 | + * and pending replies) | |
| 1497 | 1435 | * |
| 1498 | 1436 | * @since 2.6.0 bbPress (r6923) |
| 1499 | 1437 | * |
| 1500 | - * @param int $forum_id Optional. Forum id. | |
| 1438 | + * @param int $forum_id Optional. Forum id | |
| 1501 | 1439 | * @param bool $total_count Optional. To get the total count or normal count? |
| 1502 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 1440 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 1503 | 1441 | */ |
| 1504 | 1442 | function bbp_forum_reply_count_hidden( $forum_id = 0, $total_count = true, $integer = false ) { |
| 1505 | 1443 | echo bbp_get_forum_reply_count_hidden( $forum_id, $total_count, $integer ); |
| 1506 | 1444 | } |
| 1445 | + /** | |
| 1446 | + * Return total hidden reply count of a forum (hidden includes trashed, | |
| 1447 | + * spammed and pending replies) | |
| 1448 | + * | |
| 1449 | + * @since 2.6.0 bbPress (r6923) | |
| 1450 | + * | |
| 1451 | + * @param int $forum_id Optional. Forum id | |
| 1452 | + * @param bool $total_count Optional. To get the total count or normal | |
| 1453 | + * count? | |
| 1454 | + * @param boolean $integer Optional. Whether or not to format the result | |
| 1455 | + * @return int Forum reply count | |
| 1456 | + */ | |
| 1457 | + function bbp_get_forum_reply_count_hidden( $forum_id = 0, $total_count = true, $integer = false ) { | |
| 1458 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1459 | + $meta_key = empty( $total_count ) ? '_bbp_reply_count_hidden' : '_bbp_total_reply_count_hidden'; | |
| 1460 | + $replies = (int) get_post_meta( $forum_id, $meta_key, true ); | |
| 1461 | + $filter = ( true === $integer ) | |
| 1462 | + ? 'bbp_get_forum_reply_count_hidden_int' | |
| 1463 | + : 'bbp_get_forum_reply_count_hidden'; | |
| 1507 | 1464 | |
| 1508 | -/** | |
| 1509 | - * Return total hidden reply count of a forum (hidden includes trashed, | |
| 1510 | - * spammed and pending replies). | |
| 1511 | - * | |
| 1512 | - * @since 2.6.0 bbPress (r6923) | |
| 1513 | - * | |
| 1514 | - * @param int $forum_id Optional. Forum id. | |
| 1515 | - * @param bool $total_count Optional. To get the total count or normal | |
| 1516 | - * count? | |
| 1517 | - * @param boolean $integer Optional. Whether or not to format the result. | |
| 1518 | - * @return int Forum reply count. | |
| 1519 | - */ | |
| 1520 | -function bbp_get_forum_reply_count_hidden( $forum_id = 0, $total_count = true, $integer = false ) { | |
| 1521 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1522 | - $meta_key = empty( $total_count ) ? '_bbp_reply_count_hidden' : '_bbp_total_reply_count_hidden'; | |
| 1523 | - $replies = (int) get_post_meta( $forum_id, $meta_key, true ); | |
| 1524 | - $filter = ( true === $integer ) | |
| 1525 | - ? 'bbp_get_forum_reply_count_hidden_int' | |
| 1526 | - : 'bbp_get_forum_reply_count_hidden'; | |
| 1465 | + return apply_filters( $filter, $replies, $forum_id ); | |
| 1466 | + } | |
| 1527 | 1467 | |
| 1528 | - return apply_filters( $filter, $replies, $forum_id ); | |
| 1529 | -} | |
| 1530 | - | |
| 1531 | 1468 | /** |
| 1532 | - * Output the status of the forum. | |
| 1469 | + * Output the status of the forum | |
| 1533 | 1470 | * |
| 1534 | 1471 | * @since 2.0.0 bbPress (r2678) |
| 1535 | 1472 | * |
| 1536 | - * @param int $forum_id Optional. Forum id. | |
| 1473 | + * @param int $forum_id Optional. Forum id | |
| 1537 | 1474 | */ |
| 1538 | 1475 | function bbp_forum_status( $forum_id = 0 ) { |
| 1539 | 1476 | echo bbp_get_forum_status( $forum_id ); |
| 1540 | 1477 | } |
| 1478 | + /** | |
| 1479 | + * Return the status of the forum | |
| 1480 | + * | |
| 1481 | + * @since 2.0.0 bbPress (r2678) | |
| 1482 | + * | |
| 1483 | + * @param int $forum_id Optional. Forum id | |
| 1484 | + * @return string Status of forum | |
| 1485 | + */ | |
| 1486 | + function bbp_get_forum_status( $forum_id = 0 ) { | |
| 1487 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1488 | + $status = get_post_meta( $forum_id, '_bbp_status', true ); | |
| 1541 | 1489 | |
| 1542 | -/** | |
| 1543 | - * Return the status of the forum. | |
| 1544 | - * | |
| 1545 | - * @since 2.0.0 bbPress (r2678) | |
| 1546 | - * | |
| 1547 | - * @param int $forum_id Optional. Forum id. | |
| 1548 | - * @return string Status of forum. | |
| 1549 | - */ | |
| 1550 | -function bbp_get_forum_status( $forum_id = 0 ) { | |
| 1551 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1552 | - $status = get_post_meta( $forum_id, '_bbp_status', true ); | |
| 1490 | + if ( empty( $status ) ) { | |
| 1491 | + $status = 'open'; | |
| 1492 | + } | |
| 1553 | 1493 | |
| 1554 | - if ( empty( $status ) ) { | |
| 1555 | - $status = 'open'; | |
| 1494 | + // Filter & return | |
| 1495 | + return apply_filters( 'bbp_get_forum_status', $status, $forum_id ); | |
| 1556 | 1496 | } |
| 1557 | 1497 | |
| 1558 | - // Filter & return | |
| 1559 | - return apply_filters( 'bbp_get_forum_status', $status, $forum_id ); | |
| 1560 | -} | |
| 1561 | - | |
| 1562 | 1498 | /** |
| 1563 | - * Output the visibility of the forum. | |
| 1499 | + * Output the visibility of the forum | |
| 1564 | 1500 | * |
| 1565 | 1501 | * @since 2.0.0 bbPress (r2998) |
| 1566 | 1502 | * |
| 1567 | - * @param int $forum_id Optional. Forum id. | |
| 1503 | + * @param int $forum_id Optional. Forum id | |
| 1568 | 1504 | */ |
| 1569 | 1505 | function bbp_forum_visibility( $forum_id = 0 ) { |
| 1570 | 1506 | echo bbp_get_forum_visibility( $forum_id ); |
| 1571 | 1507 | } |
| 1508 | + /** | |
| 1509 | + * Return the visibility of the forum | |
| 1510 | + * | |
| 1511 | + * @since 2.0.0 bbPress (r2998) | |
| 1512 | + * | |
| 1513 | + * @param int $forum_id Optional. Forum id | |
| 1514 | + * @return string Status of forum | |
| 1515 | + */ | |
| 1516 | + function bbp_get_forum_visibility( $forum_id = 0 ) { | |
| 1517 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1518 | + $visibility = get_post_status( $forum_id ); | |
| 1572 | 1519 | |
| 1573 | -/** | |
| 1574 | - * Return the visibility of the forum. | |
| 1575 | - * | |
| 1576 | - * @since 2.0.0 bbPress (r2998) | |
| 1577 | - * | |
| 1578 | - * @param int $forum_id Optional. Forum id. | |
| 1579 | - * @return string Status of forum. | |
| 1580 | - */ | |
| 1581 | -function bbp_get_forum_visibility( $forum_id = 0 ) { | |
| 1582 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1583 | - $visibility = get_post_status( $forum_id ); | |
| 1520 | + // Filter & return | |
| 1521 | + return apply_filters( 'bbp_get_forum_visibility', $visibility, $forum_id ); | |
| 1522 | + } | |
| 1584 | 1523 | |
| 1585 | - // Filter & return | |
| 1586 | - return apply_filters( 'bbp_get_forum_visibility', $visibility, $forum_id ); | |
| 1587 | -} | |
| 1588 | - | |
| 1589 | 1524 | /** |
| 1590 | - * Output the type of the forum. | |
| 1525 | + * Output the type of the forum | |
| 1591 | 1526 | * |
| 1592 | 1527 | * @since 2.1.0 bbPress (r3563) |
| 1593 | 1528 | * |
| 1594 | - * @param int $forum_id Optional. Forum id. | |
| 1529 | + * @param int $forum_id Optional. Forum id | |
| 1595 | 1530 | */ |
| 1596 | 1531 | function bbp_forum_type( $forum_id = 0 ) { |
| 1597 | 1532 | echo bbp_get_forum_type( $forum_id ); |
| 1598 | 1533 | } |
| 1534 | + /** | |
| 1535 | + * Return the type of forum (category/forum/etc...) | |
| 1536 | + * | |
| 1537 | + * @since 2.1.0 bbPress (r3563) | |
| 1538 | + * | |
| 1539 | + * @param int $forum_id Optional. Forum id | |
| 1540 | + * @return bool Whether the forum is a category or not | |
| 1541 | + */ | |
| 1542 | + function bbp_get_forum_type( $forum_id = 0 ) { | |
| 1543 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1544 | + $retval = get_post_meta( $forum_id, '_bbp_forum_type', true ); | |
| 1599 | 1545 | |
| 1600 | -/** | |
| 1601 | - * Return the type of forum (category/forum/etc...) | |
| 1602 | - * | |
| 1603 | - * @since 2.1.0 bbPress (r3563) | |
| 1604 | - * | |
| 1605 | - * @param int $forum_id Optional. Forum id. | |
| 1606 | - * @return bool Whether the forum is a category or not. | |
| 1607 | - */ | |
| 1608 | -function bbp_get_forum_type( $forum_id = 0 ) { | |
| 1609 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1610 | - $retval = get_post_meta( $forum_id, '_bbp_forum_type', true ); | |
| 1546 | + if ( empty( $retval ) ) { | |
| 1547 | + $retval = 'forum'; | |
| 1548 | + } | |
| 1611 | 1549 | |
| 1612 | - if ( empty( $retval ) ) { | |
| 1613 | - $retval = 'forum'; | |
| 1550 | + // Filter & return | |
| 1551 | + return apply_filters( 'bbp_get_forum_type', $retval, $forum_id ); | |
| 1614 | 1552 | } |
| 1615 | 1553 | |
| 1616 | - // Filter & return | |
| 1617 | - return apply_filters( 'bbp_get_forum_type', $retval, $forum_id ); | |
| 1618 | -} | |
| 1619 | - | |
| 1620 | 1554 | /** |
| 1621 | 1555 | * Is the forum a category? |
| 1622 | 1556 | * |
| 1623 | 1557 | * @since 2.0.0 bbPress (r2746) |
| 1624 | 1558 | * |
| 1625 | - * @param int $forum_id Optional. Forum id. | |
| 1626 | - * @return bool Whether the forum is a category or not. | |
| 1559 | + * @param int $forum_id Optional. Forum id | |
| 1560 | + * @return bool Whether the forum is a category or not | |
| 1627 | 1561 | */ |
| 1628 | 1562 | function bbp_is_forum_category( $forum_id = 0 ) { |
| 1629 | 1563 | $forum_id = bbp_get_forum_id( $forum_id ); |
| 1630 | 1564 | $type = bbp_get_forum_type( $forum_id ); |
| @@ -1638,12 +1572,12 @@ | ||
| 1638 | 1572 | * Is the forum open? |
| 1639 | 1573 | * |
| 1640 | 1574 | * @since 2.0.0 bbPress (r2746) |
| 1641 | 1575 | * |
| 1642 | - * @param int $forum_id Optional. Forum id. | |
| 1576 | + * @param int $forum_id Optional. Forum id | |
| 1643 | 1577 | * @param bool $check_ancestors Check if the ancestors are open (only |
| 1644 | - * if they're a category). | |
| 1645 | - * @return bool Whether the forum is open or not. | |
| 1578 | + * if they're a category) | |
| 1579 | + * @return bool Whether the forum is open or not | |
| 1646 | 1580 | */ |
| 1647 | 1581 | function bbp_is_forum_open( $forum_id = 0, $check_ancestors = true ) { |
| 1648 | 1582 | return ! bbp_is_forum_closed( $forum_id, $check_ancestors ); |
| 1649 | 1583 | } |
| @@ -1652,12 +1586,12 @@ | ||
| 1652 | 1586 | * Is the forum closed? |
| 1653 | 1587 | * |
| 1654 | 1588 | * @since 2.0.0 bbPress (r2746) |
| 1655 | 1589 | * |
| 1656 | - * @param int $forum_id Optional. Forum id. | |
| 1590 | + * @param int $forum_id Optional. Forum id | |
| 1657 | 1591 | * @param bool $check_ancestors Check if the ancestors are closed (only |
| 1658 | - * if they're a category). | |
| 1659 | - * @return bool True if closed, false if not. | |
| 1592 | + * if they're a category) | |
| 1593 | + * @return bool True if closed, false if not | |
| 1660 | 1594 | */ |
| 1661 | 1595 | function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) { |
| 1662 | 1596 | |
| 1663 | 1597 | // Get the forum ID |
| @@ -1670,18 +1604,18 @@ | ||
| 1670 | 1604 | return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors ); |
| 1671 | 1605 | } |
| 1672 | 1606 | |
| 1673 | 1607 | /** |
| 1674 | - * Check if the forum status is a specific one, also maybe checking ancestors. | |
| 1608 | + * Check if the forum status is a specific one, also maybe checking ancestors | |
| 1675 | 1609 | * |
| 1676 | 1610 | * @since 2.6.0 bbPress (r5499) |
| 1677 | 1611 | * |
| 1678 | - * @param bool $status_name The forum status name to check. | |
| 1679 | - * @param bool $check_ancestors Check the forum ancestors. | |
| 1612 | + * @param bool $status_name The forum status name to check | |
| 1613 | + * @param bool $check_ancestors Check the forum ancestors | |
| 1680 | 1614 | * @param string $operator The logical operation to perform. |
| 1681 | 1615 | * 'OR' means only one forum from the tree needs to match; |
| 1682 | 1616 | * 'AND' means all forums must match. The default is 'AND'. |
| 1683 | - * @return bool True if match, false if not. | |
| 1617 | + * @return bool True if match, false if not | |
| 1684 | 1618 | */ |
| 1685 | 1619 | function bbp_is_forum_status( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) { |
| 1686 | 1620 | |
| 1687 | 1621 | // Setup some default variables |
| @@ -1693,9 +1627,9 @@ | ||
| 1693 | 1627 | |
| 1694 | 1628 | // Quickly compare statuses of first forum ID |
| 1695 | 1629 | if ( $status_name === $forum_status ) { |
| 1696 | 1630 | $retval = true; |
| 1697 | - ++$count; | |
| 1631 | + $count++; | |
| 1698 | 1632 | } |
| 1699 | 1633 | |
| 1700 | 1634 | // Let's check the forum's ancestors too |
| 1701 | 1635 | if ( ! empty( $check_ancestors ) ) { |
| @@ -1744,11 +1678,11 @@ | ||
| 1744 | 1678 | * Is the forum public? |
| 1745 | 1679 | * |
| 1746 | 1680 | * @since 2.0.0 bbPress (r2998) |
| 1747 | 1681 | * |
| 1748 | - * @param int $forum_id Optional. Forum id. | |
| 1749 | - * @param bool $check_ancestors Check if the ancestors are public. | |
| 1750 | - * @return bool True if closed, false if not. | |
| 1682 | + * @param int $forum_id Optional. Forum id | |
| 1683 | + * @param bool $check_ancestors Check if the ancestors are public | |
| 1684 | + * @return bool True if closed, false if not | |
| 1751 | 1685 | */ |
| 1752 | 1686 | function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) { |
| 1753 | 1687 | |
| 1754 | 1688 | // Get the forum ID |
| @@ -1765,11 +1699,11 @@ | ||
| 1765 | 1699 | * Is the forum private? |
| 1766 | 1700 | * |
| 1767 | 1701 | * @since 2.0.0 bbPress (r2746) |
| 1768 | 1702 | * |
| 1769 | - * @param int $forum_id Optional. Forum id. | |
| 1770 | - * @param bool $check_ancestors Check if the ancestors are private. | |
| 1771 | - * @return bool True if private, false if not. | |
| 1703 | + * @param int $forum_id Optional. Forum id | |
| 1704 | + * @param bool $check_ancestors Check if the ancestors are private | |
| 1705 | + * @return bool True if private, false if not | |
| 1772 | 1706 | */ |
| 1773 | 1707 | function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) { |
| 1774 | 1708 | |
| 1775 | 1709 | // Get the forum ID |
| @@ -1786,12 +1720,12 @@ | ||
| 1786 | 1720 | * Is the forum hidden? |
| 1787 | 1721 | * |
| 1788 | 1722 | * @since 2.0.0 bbPress (r2998) |
| 1789 | 1723 | * |
| 1790 | - * @param int $forum_id Optional. Forum id. | |
| 1724 | + * @param int $forum_id Optional. Forum id | |
| 1791 | 1725 | * @param bool $check_ancestors Check if the ancestors are private (only if |
| 1792 | - * they're a category). | |
| 1793 | - * @return bool True if hidden, false if not. | |
| 1726 | + * they're a category) | |
| 1727 | + * @return bool True if hidden, false if not | |
| 1794 | 1728 | */ |
| 1795 | 1729 | function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) { |
| 1796 | 1730 | |
| 1797 | 1731 | // Get the forum ID |
| @@ -1806,9 +1740,9 @@ | ||
| 1806 | 1740 | |
| 1807 | 1741 | /** |
| 1808 | 1742 | * Is the forum private or hidden? |
| 1809 | 1743 | * |
| 1810 | - * @since 2.6.17 bbPress (r7473) | |
| 1744 | + * @since 2.6.17 bbPress (r7474) | |
| 1811 | 1745 | * |
| 1812 | 1746 | * @param int $forum_id Optional. Forum id. |
| 1813 | 1747 | * @param bool $check_ancestors Whether to check the forum ancestors. |
| 1814 | 1748 | * @return bool True if private or hidden, false if not. |
| @@ -1826,9 +1760,9 @@ | ||
| 1826 | 1760 | * |
| 1827 | 1761 | * Checks the forum and its ancestors for private or hidden visibility, and |
| 1828 | 1762 | * whether the user is a forum moderator or can otherwise read the forum. |
| 1829 | 1763 | * |
| 1830 | - * @since 2.6.17 bbPress (r7503) | |
| 1764 | + * @since 2.6.17 bbPress (r7504) | |
| 1831 | 1765 | * |
| 1832 | 1766 | * @param int $forum_id Optional. Forum ID. |
| 1833 | 1767 | * @param int $user_id Optional. User ID. Defaults to 0. |
| 1834 | 1768 | * @return bool True if the forum is restricted from the user, false if not. |
| @@ -1847,19 +1781,19 @@ | ||
| 1847 | 1781 | return (bool) apply_filters( 'bbp_is_forum_restricted_for_user', $retval, $forum_id, $user_id ); |
| 1848 | 1782 | } |
| 1849 | 1783 | |
| 1850 | 1784 | /** |
| 1851 | - * Check the forum visibility ID. | |
| 1785 | + * Check the forum visibility ID | |
| 1852 | 1786 | * |
| 1853 | 1787 | * @since 2.6.0 bbPress (r5499) |
| 1854 | 1788 | * |
| 1855 | - * @param int $forum_id Optional. Forum id. | |
| 1856 | - * @param bool $status_name The post status name to check. | |
| 1857 | - * @param bool $check_ancestors Check the forum ancestors. | |
| 1789 | + * @param int $forum_id Optional. Forum id | |
| 1790 | + * @param bool $status_name The post status name to check | |
| 1791 | + * @param bool $check_ancestors Check the forum ancestors | |
| 1858 | 1792 | * @param string $operator The logical operation to perform. |
| 1859 | 1793 | * 'OR' means only one forum from the tree needs to match; |
| 1860 | 1794 | * 'AND' means all forums must match. The default is 'AND'. |
| 1861 | - * @return bool True if match, false if not. | |
| 1795 | + * @return bool True if match, false if not | |
| 1862 | 1796 | */ |
| 1863 | 1797 | function bbp_is_forum_visibility( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) { |
| 1864 | 1798 | |
| 1865 | 1799 | // Setup some default variables |
| @@ -1871,9 +1805,9 @@ | ||
| 1871 | 1805 | |
| 1872 | 1806 | // Quickly compare visibility of first forum ID |
| 1873 | 1807 | if ( $status_name === $visibility ) { |
| 1874 | 1808 | $retval = true; |
| 1875 | - ++$count; | |
| 1809 | + $count++; | |
| 1876 | 1810 | } |
| 1877 | 1811 | |
| 1878 | 1812 | // Let's check the forum's ancestors too |
| 1879 | 1813 | if ( ! empty( $check_ancestors ) ) { |
| @@ -1925,63 +1859,61 @@ | ||
| 1925 | 1859 | return (bool) apply_filters( 'bbp_is_forum_visibility', $retval, $count, $forum_id, $status_name, $check_ancestors, $operator ); |
| 1926 | 1860 | } |
| 1927 | 1861 | |
| 1928 | 1862 | /** |
| 1929 | - * Output the author ID of the forum. | |
| 1863 | + * Output the author ID of the forum | |
| 1930 | 1864 | * |
| 1931 | 1865 | * @since 2.1.0 bbPress (r3678) |
| 1932 | 1866 | * |
| 1933 | - * @param int $forum_id Optional. Forum id. | |
| 1867 | + * @param int $forum_id Optional. Forum id | |
| 1934 | 1868 | */ |
| 1935 | 1869 | function bbp_forum_author_id( $forum_id = 0 ) { |
| 1936 | 1870 | echo bbp_get_forum_author_id( $forum_id ); |
| 1937 | 1871 | } |
| 1872 | + /** | |
| 1873 | + * Return the author ID of the forum | |
| 1874 | + * | |
| 1875 | + * @since 2.1.0 bbPress (r3678) | |
| 1876 | + * | |
| 1877 | + * @param int $forum_id Optional. Forum id | |
| 1878 | + * | |
| 1879 | + * @return string Author of forum | |
| 1880 | + */ | |
| 1881 | + function bbp_get_forum_author_id( $forum_id = 0 ) { | |
| 1882 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1883 | + $author_id = get_post_field( 'post_author', $forum_id ); | |
| 1938 | 1884 | |
| 1939 | -/** | |
| 1940 | - * Return the author ID of the forum. | |
| 1941 | - * | |
| 1942 | - * @since 2.1.0 bbPress (r3678) | |
| 1943 | - * | |
| 1944 | - * @param int $forum_id Optional. Forum id. | |
| 1945 | - * | |
| 1946 | - * @return string Author of forum. | |
| 1947 | - */ | |
| 1948 | -function bbp_get_forum_author_id( $forum_id = 0 ) { | |
| 1949 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1950 | - $author_id = get_post_field( 'post_author', $forum_id ); | |
| 1885 | + // Filter & return | |
| 1886 | + return (int) apply_filters( 'bbp_get_forum_author_id', (int) $author_id, $forum_id ); | |
| 1887 | + } | |
| 1951 | 1888 | |
| 1952 | - // Filter & return | |
| 1953 | - return (int) apply_filters( 'bbp_get_forum_author_id', (int) $author_id, $forum_id ); | |
| 1954 | -} | |
| 1955 | - | |
| 1956 | 1889 | /** |
| 1957 | - * Output the author of the forum. | |
| 1890 | + * Output the author of the forum | |
| 1958 | 1891 | * |
| 1959 | 1892 | * @since 2.1.0 bbPress (r3678) |
| 1960 | 1893 | * |
| 1961 | - * @param int $forum_id Optional. Forum id. | |
| 1894 | + * @param int $forum_id Optional. Forum id | |
| 1962 | 1895 | */ |
| 1963 | 1896 | function bbp_forum_author_display_name( $forum_id = 0 ) { |
| 1964 | 1897 | echo bbp_get_forum_author_display_name( $forum_id ); |
| 1965 | 1898 | } |
| 1899 | + /** | |
| 1900 | + * Return the author of the forum | |
| 1901 | + * | |
| 1902 | + * @since 2.1.0 bbPress (r3678) | |
| 1903 | + * | |
| 1904 | + * @param int $forum_id Optional. Forum id | |
| 1905 | + * @return string Author of forum | |
| 1906 | + */ | |
| 1907 | + function bbp_get_forum_author_display_name( $forum_id = 0 ) { | |
| 1908 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1909 | + $author_id = bbp_get_forum_author_id( $forum_id ); | |
| 1910 | + $author = get_the_author_meta( 'display_name', $author_id ); | |
| 1966 | 1911 | |
| 1967 | -/** | |
| 1968 | - * Return the author of the forum. | |
| 1969 | - * | |
| 1970 | - * @since 2.1.0 bbPress (r3678) | |
| 1971 | - * | |
| 1972 | - * @param int $forum_id Optional. Forum id. | |
| 1973 | - * @return string Author of forum. | |
| 1974 | - */ | |
| 1975 | -function bbp_get_forum_author_display_name( $forum_id = 0 ) { | |
| 1976 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 1977 | - $author_id = bbp_get_forum_author_id( $forum_id ); | |
| 1978 | - $author = get_the_author_meta( 'display_name', $author_id ); | |
| 1912 | + // Filter & return | |
| 1913 | + return apply_filters( 'bbp_get_forum_author_display_name', $author, $forum_id, $author_id ); | |
| 1914 | + } | |
| 1979 | 1915 | |
| 1980 | - // Filter & return | |
| 1981 | - return apply_filters( 'bbp_get_forum_author_display_name', $author, $forum_id, $author_id ); | |
| 1982 | -} | |
| 1983 | - | |
| 1984 | 1916 | /** |
| 1985 | 1917 | * Replace forum meta details for users that cannot view them. |
| 1986 | 1918 | * |
| 1987 | 1919 | * Forum visibility is inherited from every ancestor. A public descendant of a |
| @@ -2076,88 +2008,87 @@ | ||
| 2076 | 2008 | return apply_filters( 'bbp_suppress_private_author_link', $retval, $author_link, $args ); |
| 2077 | 2009 | } |
| 2078 | 2010 | |
| 2079 | 2011 | /** |
| 2080 | - * Output the row class of a forum. | |
| 2012 | + * Output the row class of a forum | |
| 2081 | 2013 | * |
| 2082 | 2014 | * @since 2.0.0 bbPress (r2678) |
| 2083 | 2015 | * |
| 2084 | 2016 | * @param int $forum_id Optional. Forum ID. |
| 2085 | - * @param array Extra classes you can pass when calling this function. | |
| 2017 | + * @param array Extra classes you can pass when calling this function | |
| 2086 | 2018 | */ |
| 2087 | 2019 | function bbp_forum_class( $forum_id = 0, $classes = array() ) { |
| 2088 | 2020 | echo bbp_get_forum_class( $forum_id, $classes ); |
| 2089 | 2021 | } |
| 2022 | + /** | |
| 2023 | + * Return the row class of a forum | |
| 2024 | + * | |
| 2025 | + * @since 2.0.0 bbPress (r2678) | |
| 2026 | + * | |
| 2027 | + * @param int $forum_id Optional. Forum ID | |
| 2028 | + * @param array Extra classes you can pass when calling this function | |
| 2029 | + * @return string Row class of the forum | |
| 2030 | + */ | |
| 2031 | + function bbp_get_forum_class( $forum_id = 0, $classes = array() ) { | |
| 2032 | + $bbp = bbpress(); | |
| 2033 | + $forum_id = bbp_get_forum_id( $forum_id ); | |
| 2034 | + $parent_id = bbp_get_forum_parent_id( $forum_id ); | |
| 2035 | + $author_id = bbp_get_forum_author_id( $forum_id ); | |
| 2036 | + $status = bbp_get_forum_status( $forum_id ); | |
| 2037 | + $visibility = bbp_get_forum_visibility( $forum_id ); | |
| 2038 | + $classes = array_filter( (array) $classes ); | |
| 2039 | + $count = isset( $bbp->forum_query->current_post ) | |
| 2040 | + ? (int) $bbp->forum_query->current_post | |
| 2041 | + : 1; | |
| 2090 | 2042 | |
| 2091 | -/** | |
| 2092 | - * Return the row class of a forum. | |
| 2093 | - * | |
| 2094 | - * @since 2.0.0 bbPress (r2678) | |
| 2095 | - * | |
| 2096 | - * @param int $forum_id Optional. Forum ID. | |
| 2097 | - * @param array Extra classes you can pass when calling this function. | |
| 2098 | - * @return string Row class of the forum. | |
| 2099 | - */ | |
| 2100 | -function bbp_get_forum_class( $forum_id = 0, $classes = array() ) { | |
| 2101 | - $bbp = bbpress(); | |
| 2102 | - $forum_id = bbp_get_forum_id( $forum_id ); | |
| 2103 | - $parent_id = bbp_get_forum_parent_id( $forum_id ); | |
| 2104 | - $author_id = bbp_get_forum_author_id( $forum_id ); | |
| 2105 | - $status = bbp_get_forum_status( $forum_id ); | |
| 2106 | - $visibility = bbp_get_forum_visibility( $forum_id ); | |
| 2107 | - $classes = array_filter( (array) $classes ); | |
| 2108 | - $count = isset( $bbp->forum_query->current_post ) | |
| 2109 | - ? (int) $bbp->forum_query->current_post | |
| 2110 | - : 1; | |
| 2043 | + // Stripes | |
| 2044 | + $even_odd = ( $count % 2 ) | |
| 2045 | + ? 'even' | |
| 2046 | + : 'odd'; | |
| 2111 | 2047 | |
| 2112 | - // Stripes | |
| 2113 | - $even_odd = ( $count % 2 ) | |
| 2114 | - ? 'even' | |
| 2115 | - : 'odd'; | |
| 2048 | + // User is moderator of forum | |
| 2049 | + $forum_moderator = ( bbp_is_user_forum_moderator( $author_id, $forum_id ) === $author_id ) | |
| 2050 | + ? 'forum-mod' | |
| 2051 | + : ''; | |
| 2116 | 2052 | |
| 2117 | - // User is moderator of forum | |
| 2118 | - $forum_moderator = ( bbp_is_user_forum_moderator( $author_id, $forum_id ) === $author_id ) | |
| 2119 | - ? 'forum-mod' | |
| 2120 | - : ''; | |
| 2053 | + // Is forum a non-postable category? | |
| 2054 | + $category = bbp_is_forum_category( $forum_id ) | |
| 2055 | + ? 'status-category' | |
| 2056 | + : ''; | |
| 2121 | 2057 | |
| 2122 | - // Is forum a non-postable category? | |
| 2123 | - $category = bbp_is_forum_category( $forum_id ) | |
| 2124 | - ? 'status-category' | |
| 2125 | - : ''; | |
| 2058 | + // Forum has children? | |
| 2059 | + $subs = bbp_get_forum_subforum_count( $forum_id ) | |
| 2060 | + ? 'bbp-has-subforums' | |
| 2061 | + : ''; | |
| 2126 | 2062 | |
| 2127 | - // Forum has children? | |
| 2128 | - $subs = bbp_get_forum_subforum_count( $forum_id ) | |
| 2129 | - ? 'bbp-has-subforums' | |
| 2130 | - : ''; | |
| 2063 | + // Forum has parent? | |
| 2064 | + $parent = ! empty( $parent_id ) | |
| 2065 | + ? 'bbp-parent-forum-' . $parent_id | |
| 2066 | + : ''; | |
| 2131 | 2067 | |
| 2132 | - // Forum has parent? | |
| 2133 | - $parent = ! empty( $parent_id ) | |
| 2134 | - ? 'bbp-parent-forum-' . $parent_id | |
| 2135 | - : ''; | |
| 2068 | + // Get forum classes | |
| 2069 | + $forum_classes = array( | |
| 2070 | + 'loop-item-' . $count, | |
| 2071 | + 'bbp-forum-status-' . $status, | |
| 2072 | + 'bbp-forum-visibility-' . $visibility, | |
| 2073 | + $even_odd, | |
| 2074 | + $forum_moderator, | |
| 2075 | + $category, | |
| 2076 | + $subs, | |
| 2077 | + $parent | |
| 2078 | + ); | |
| 2136 | 2079 | |
| 2137 | - // Get forum classes | |
| 2138 | - $forum_classes = array( | |
| 2139 | - 'loop-item-' . $count, | |
| 2140 | - 'bbp-forum-status-' . $status, | |
| 2141 | - 'bbp-forum-visibility-' . $visibility, | |
| 2142 | - $even_odd, | |
| 2143 | - $forum_moderator, | |
| 2144 | - $category, | |
| 2145 | - $subs, | |
| 2146 | - $parent | |
| 2147 | - ); | |
| 2080 | + // Run the topic classes through the post-class filters, which also | |
| 2081 | + // handles the escaping of each individual class. | |
| 2082 | + $post_classes = get_post_class( array_merge( $classes, $forum_classes ), $forum_id ); | |
| 2148 | 2083 | |
| 2149 | - // Run the topic classes through the post-class filters, which also | |
| 2150 | - // handles the escaping of each individual class. | |
| 2151 | - $post_classes = get_post_class( array_merge( $classes, $forum_classes ), $forum_id ); | |
| 2084 | + // Filter | |
| 2085 | + $new_classes = apply_filters( 'bbp_get_forum_class', $post_classes, $forum_id, $classes ); | |
| 2152 | 2086 | |
| 2153 | - // Filter | |
| 2154 | - $new_classes = apply_filters( 'bbp_get_forum_class', $post_classes, $forum_id, $classes ); | |
| 2087 | + // Return | |
| 2088 | + return 'class="' . implode( ' ', $new_classes ) . '"'; | |
| 2089 | + } | |
| 2155 | 2090 | |
| 2156 | - // Return | |
| 2157 | - return 'class="' . implode( ' ', $new_classes ) . '"'; | |
| 2158 | -} | |
| 2159 | - | |
| 2160 | 2091 | /** Single Forum **************************************************************/ |
| 2161 | 2092 | |
| 2162 | 2093 | /** |
| 2163 | 2094 | * Output a fancy description of the current forum, including total topics, |
| @@ -2164,27 +2095,26 @@ | ||
| 2164 | 2095 | * total replies, and last activity. |
| 2165 | 2096 | * |
| 2166 | 2097 | * @since 2.0.0 bbPress (r2876) |
| 2167 | 2098 | * |
| 2168 | - * @param array $args Arguments passed to alter output. | |
| 2099 | + * @param array $args Arguments passed to alter output | |
| 2169 | 2100 | */ |
| 2170 | 2101 | function bbp_single_forum_description( $args = array() ) { |
| 2171 | 2102 | echo bbp_get_single_forum_description( $args ); |
| 2172 | 2103 | } |
| 2173 | - | |
| 2174 | -/** | |
| 2175 | - * Return a fancy description of the current forum, including total | |
| 2176 | - * topics, total replies, and last activity. | |
| 2177 | - * | |
| 2178 | - * @since 2.0.0 bbPress (r2876) | |
| 2179 | - * | |
| 2180 | - * @param array $args This function supports these arguments: | |
| 2181 | - * - forum_id: Forum id | |
| 2182 | - * - before: Before the text | |
| 2183 | - * - after: After the text | |
| 2184 | - * - size: Size of the avatar | |
| 2185 | - * @return string Filtered forum description. | |
| 2186 | - */ | |
| 2104 | + /** | |
| 2105 | + * Return a fancy description of the current forum, including total | |
| 2106 | + * topics, total replies, and last activity. | |
| 2107 | + * | |
| 2108 | + * @since 2.0.0 bbPress (r2876) | |
| 2109 | + * | |
| 2110 | + * @param array $args This function supports these arguments: | |
| 2111 | + * - forum_id: Forum id | |
| 2112 | + * - before: Before the text | |
| 2113 | + * - after: After the text | |
| 2114 | + * - size: Size of the avatar | |
| 2115 | + * @return string Filtered forum description | |
| 2116 | + */ | |
| 2187 | 2117 | function bbp_get_single_forum_description( $args = array() ) { |
| 2188 | 2118 | |
| 2189 | 2119 | // Parse arguments against default values |
| 2190 | 2120 | $r = bbp_parse_args( |
| @@ -2291,9 +2221,9 @@ | ||
| 2291 | 2221 | |
| 2292 | 2222 | /** Forms *********************************************************************/ |
| 2293 | 2223 | |
| 2294 | 2224 | /** |
| 2295 | - * Output the value of forum title field. | |
| 2225 | + * Output the value of forum title field | |
| 2296 | 2226 | * |
| 2297 | 2227 | * @since 2.1.0 bbPress (r3551) |
| 2298 | 2228 | */ |
| 2299 | 2229 | function bbp_form_forum_title() { |
| @@ -2298,37 +2228,36 @@ | ||
| 2298 | 2228 | */ |
| 2299 | 2229 | function bbp_form_forum_title() { |
| 2300 | 2230 | echo bbp_get_form_forum_title(); |
| 2301 | 2231 | } |
| 2232 | + /** | |
| 2233 | + * Return the value of forum title field | |
| 2234 | + * | |
| 2235 | + * @since 2.1.0 bbPress (r3551) | |
| 2236 | + * | |
| 2237 | + * @return string Value of forum title field | |
| 2238 | + */ | |
| 2239 | + function bbp_get_form_forum_title() { | |
| 2302 | 2240 | |
| 2303 | -/** | |
| 2304 | - * Return the value of forum title field. | |
| 2305 | - * | |
| 2306 | - * @since 2.1.0 bbPress (r3551) | |
| 2307 | - * | |
| 2308 | - * @return string Value of forum title field. | |
| 2309 | - */ | |
| 2310 | -function bbp_get_form_forum_title() { | |
| 2241 | + // Get _POST data | |
| 2242 | + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_title'] ) ) { | |
| 2243 | + $forum_title = wp_unslash( $_POST['bbp_forum_title'] ); | |
| 2311 | 2244 | |
| 2312 | - // Get _POST data | |
| 2313 | - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_title'] ) ) { | |
| 2314 | - $forum_title = wp_unslash( $_POST['bbp_forum_title'] ); | |
| 2245 | + // Get edit data | |
| 2246 | + } elseif ( bbp_is_forum_edit() ) { | |
| 2247 | + $forum_title = bbp_get_global_post_field( 'post_title', 'raw' ); | |
| 2315 | 2248 | |
| 2316 | - // Get edit data | |
| 2317 | - } elseif ( bbp_is_forum_edit() ) { | |
| 2318 | - $forum_title = bbp_get_global_post_field( 'post_title', 'raw' ); | |
| 2249 | + // No data | |
| 2250 | + } else { | |
| 2251 | + $forum_title = ''; | |
| 2252 | + } | |
| 2319 | 2253 | |
| 2320 | - // No data | |
| 2321 | - } else { | |
| 2322 | - $forum_title = ''; | |
| 2254 | + // Filter & return | |
| 2255 | + return apply_filters( 'bbp_get_form_forum_title', $forum_title ); | |
| 2323 | 2256 | } |
| 2324 | 2257 | |
| 2325 | - // Filter & return | |
| 2326 | - return apply_filters( 'bbp_get_form_forum_title', $forum_title ); | |
| 2327 | -} | |
| 2328 | - | |
| 2329 | 2258 | /** |
| 2330 | - * Output the value of forum content field. | |
| 2259 | + * Output the value of forum content field | |
| 2331 | 2260 | * |
| 2332 | 2261 | * @since 2.1.0 bbPress (r3551) |
| 2333 | 2262 | */ |
| 2334 | 2263 | function bbp_form_forum_content() { |
| @@ -2333,37 +2262,36 @@ | ||
| 2333 | 2262 | */ |
| 2334 | 2263 | function bbp_form_forum_content() { |
| 2335 | 2264 | echo bbp_get_form_forum_content(); |
| 2336 | 2265 | } |
| 2266 | + /** | |
| 2267 | + * Return the value of forum content field | |
| 2268 | + * | |
| 2269 | + * @since 2.1.0 bbPress (r3551) | |
| 2270 | + * | |
| 2271 | + * @return string Value of forum content field | |
| 2272 | + */ | |
| 2273 | + function bbp_get_form_forum_content() { | |
| 2337 | 2274 | |
| 2338 | -/** | |
| 2339 | - * Return the value of forum content field. | |
| 2340 | - * | |
| 2341 | - * @since 2.1.0 bbPress (r3551) | |
| 2342 | - * | |
| 2343 | - * @return string Value of forum content field. | |
| 2344 | - */ | |
| 2345 | -function bbp_get_form_forum_content() { | |
| 2275 | + // Get _POST data | |
| 2276 | + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_content'] ) ) { | |
| 2277 | + $forum_content = wp_unslash( $_POST['bbp_forum_content'] ); | |
| 2346 | 2278 | |
| 2347 | - // Get _POST data | |
| 2348 | - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_content'] ) ) { | |
| 2349 | - $forum_content = wp_unslash( $_POST['bbp_forum_content'] ); | |
| 2279 | + // Get edit data | |
| 2280 | + } elseif ( bbp_is_forum_edit() ) { | |
| 2281 | + $forum_content = bbp_get_global_post_field( 'post_content', 'raw' ); | |
| 2350 | 2282 | |
| 2351 | - // Get edit data | |
| 2352 | - } elseif ( bbp_is_forum_edit() ) { | |
| 2353 | - $forum_content = bbp_get_global_post_field( 'post_content', 'raw' ); | |
| 2283 | + // No data | |
| 2284 | + } else { | |
| 2285 | + $forum_content = ''; | |
| 2286 | + } | |
| 2354 | 2287 | |
| 2355 | - // No data | |
| 2356 | - } else { | |
| 2357 | - $forum_content = ''; | |
| 2288 | + // Filter & return | |
| 2289 | + return apply_filters( 'bbp_get_form_forum_content', $forum_content ); | |
| 2358 | 2290 | } |
| 2359 | 2291 | |
| 2360 | - // Filter & return | |
| 2361 | - return apply_filters( 'bbp_get_form_forum_content', $forum_content ); | |
| 2362 | -} | |
| 2363 | - | |
| 2364 | 2292 | /** |
| 2365 | - * Output value of forum moderators field. | |
| 2293 | + * Output value of forum moderators field | |
| 2366 | 2294 | * |
| 2367 | 2295 | * @since 2.6.0 bbPress (r6056) |
| 2368 | 2296 | */ |
| 2369 | 2297 | function bbp_form_forum_moderators() { |
| @@ -2368,53 +2296,52 @@ | ||
| 2368 | 2296 | */ |
| 2369 | 2297 | function bbp_form_forum_moderators() { |
| 2370 | 2298 | echo bbp_get_form_forum_moderators(); |
| 2371 | 2299 | } |
| 2300 | + /** | |
| 2301 | + * Return value of forum moderators field | |
| 2302 | + * | |
| 2303 | + * @since 2.6.0 bbPress (r6056) | |
| 2304 | + * | |
| 2305 | + * @return string Value of forum mods field | |
| 2306 | + */ | |
| 2307 | + function bbp_get_form_forum_moderators() { | |
| 2372 | 2308 | |
| 2373 | -/** | |
| 2374 | - * Return value of forum moderators field. | |
| 2375 | - * | |
| 2376 | - * @since 2.6.0 bbPress (r6056) | |
| 2377 | - * | |
| 2378 | - * @return string Value of forum mods field. | |
| 2379 | - */ | |
| 2380 | -function bbp_get_form_forum_moderators() { | |
| 2309 | + // Default return value | |
| 2310 | + $forum_mods = ''; | |
| 2381 | 2311 | |
| 2382 | - // Default return value | |
| 2383 | - $forum_mods = ''; | |
| 2312 | + // Get _POST data | |
| 2313 | + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_moderators'] ) ) { | |
| 2314 | + $forum_mods = wp_unslash( $_POST['bbp_moderators'] ); | |
| 2384 | 2315 | |
| 2385 | - // Get _POST data | |
| 2386 | - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_moderators'] ) ) { | |
| 2387 | - $forum_mods = wp_unslash( $_POST['bbp_moderators'] ); | |
| 2316 | + // Get edit data | |
| 2317 | + } elseif ( bbp_is_single_forum() || bbp_is_forum_edit() ) { | |
| 2388 | 2318 | |
| 2389 | - // Get edit data | |
| 2390 | - } elseif ( bbp_is_single_forum() || bbp_is_forum_edit() ) { | |
| 2319 | + // Get the forum ID | |
| 2320 | + $forum_id = bbp_get_forum_id( get_the_ID() ); | |
| 2391 | 2321 | |
| 2392 | - // Get the forum ID | |
| 2393 | - $forum_id = bbp_get_forum_id( get_the_ID() ); | |
| 2322 | + // Forum exists | |
| 2323 | + if ( ! empty( $forum_id ) ) { | |
| 2394 | 2324 | |
| 2395 | - // Forum exists | |
| 2396 | - if ( ! empty( $forum_id ) ) { | |
| 2325 | + // Get moderator IDs | |
| 2326 | + $user_ids = bbp_get_moderator_ids( $forum_id ); | |
| 2327 | + if ( ! empty( $user_ids ) ) { | |
| 2328 | + $user_nicenames = bbp_get_user_nicenames_from_ids( $user_ids ); | |
| 2397 | 2329 | |
| 2398 | - // Get moderator IDs | |
| 2399 | - $user_ids = bbp_get_moderator_ids( $forum_id ); | |
| 2400 | - if ( ! empty( $user_ids ) ) { | |
| 2401 | - $user_nicenames = bbp_get_user_nicenames_from_ids( $user_ids ); | |
| 2402 | - | |
| 2403 | - // Comma separate user nicenames | |
| 2404 | - if ( ! empty( $user_nicenames ) ) { | |
| 2405 | - $forum_mods = implode( ', ', wp_list_pluck( $user_nicenames, 'user_nicename' ) ); | |
| 2330 | + // Comma separate user nicenames | |
| 2331 | + if ( ! empty( $user_nicenames ) ) { | |
| 2332 | + $forum_mods = implode( ', ', wp_list_pluck( $user_nicenames, 'user_nicename' ) ); | |
| 2333 | + } | |
| 2406 | 2334 | } |
| 2407 | 2335 | } |
| 2408 | 2336 | } |
| 2337 | + | |
| 2338 | + // Filter & return | |
| 2339 | + return apply_filters( 'bbp_get_form_forum_moderators', $forum_mods ); | |
| 2409 | 2340 | } |
| 2410 | 2341 | |
| 2411 | - // Filter & return | |
| 2412 | - return apply_filters( 'bbp_get_form_forum_moderators', $forum_mods ); | |
| 2413 | -} | |
| 2414 | - | |
| 2415 | 2342 | /** |
| 2416 | - * Output value of forum parent. | |
| 2343 | + * Output value of forum parent | |
| 2417 | 2344 | * |
| 2418 | 2345 | * @since 2.1.0 bbPress (r3551) |
| 2419 | 2346 | */ |
| 2420 | 2347 | function bbp_form_forum_parent() { |
| @@ -2419,37 +2346,36 @@ | ||
| 2419 | 2346 | */ |
| 2420 | 2347 | function bbp_form_forum_parent() { |
| 2421 | 2348 | echo bbp_get_form_forum_parent(); |
| 2422 | 2349 | } |
| 2350 | + /** | |
| 2351 | + * Return value of forum parent | |
| 2352 | + * | |
| 2353 | + * @since 2.1.0 bbPress (r3551) | |
| 2354 | + * | |
| 2355 | + * @return string Value of topic content field | |
| 2356 | + */ | |
| 2357 | + function bbp_get_form_forum_parent() { | |
| 2423 | 2358 | |
| 2424 | -/** | |
| 2425 | - * Return value of forum parent. | |
| 2426 | - * | |
| 2427 | - * @since 2.1.0 bbPress (r3551) | |
| 2428 | - * | |
| 2429 | - * @return string Value of topic content field. | |
| 2430 | - */ | |
| 2431 | -function bbp_get_form_forum_parent() { | |
| 2359 | + // Get _POST data | |
| 2360 | + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_id'] ) ) { | |
| 2361 | + $forum_parent = (int) $_POST['bbp_forum_id']; | |
| 2432 | 2362 | |
| 2433 | - // Get _POST data | |
| 2434 | - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_id'] ) ) { | |
| 2435 | - $forum_parent = (int) $_POST['bbp_forum_id']; | |
| 2363 | + // Get edit data | |
| 2364 | + } elseif ( bbp_is_forum_edit() ) { | |
| 2365 | + $forum_parent = bbp_get_forum_parent_id(); | |
| 2436 | 2366 | |
| 2437 | - // Get edit data | |
| 2438 | - } elseif ( bbp_is_forum_edit() ) { | |
| 2439 | - $forum_parent = bbp_get_forum_parent_id(); | |
| 2367 | + // No data | |
| 2368 | + } else { | |
| 2369 | + $forum_parent = 0; | |
| 2370 | + } | |
| 2440 | 2371 | |
| 2441 | - // No data | |
| 2442 | - } else { | |
| 2443 | - $forum_parent = 0; | |
| 2372 | + // Filter & return | |
| 2373 | + return apply_filters( 'bbp_get_form_forum_parent', $forum_parent ); | |
| 2444 | 2374 | } |
| 2445 | 2375 | |
| 2446 | - // Filter & return | |
| 2447 | - return apply_filters( 'bbp_get_form_forum_parent', $forum_parent ); | |
| 2448 | -} | |
| 2449 | - | |
| 2450 | 2376 | /** |
| 2451 | - * Output value of forum type. | |
| 2377 | + * Output value of forum type | |
| 2452 | 2378 | * |
| 2453 | 2379 | * @since 2.1.0 bbPress (r3563) |
| 2454 | 2380 | */ |
| 2455 | 2381 | function bbp_form_forum_type() { |
| @@ -2454,37 +2380,36 @@ | ||
| 2454 | 2380 | */ |
| 2455 | 2381 | function bbp_form_forum_type() { |
| 2456 | 2382 | echo bbp_get_form_forum_type(); |
| 2457 | 2383 | } |
| 2384 | + /** | |
| 2385 | + * Return value of forum type | |
| 2386 | + * | |
| 2387 | + * @since 2.1.0 bbPress (r3563) | |
| 2388 | + * | |
| 2389 | + * @return string Value of topic content field | |
| 2390 | + */ | |
| 2391 | + function bbp_get_form_forum_type() { | |
| 2458 | 2392 | |
| 2459 | -/** | |
| 2460 | - * Return value of forum type. | |
| 2461 | - * | |
| 2462 | - * @since 2.1.0 bbPress (r3563) | |
| 2463 | - * | |
| 2464 | - * @return string Value of topic content field. | |
| 2465 | - */ | |
| 2466 | -function bbp_get_form_forum_type() { | |
| 2393 | + // Get _POST data | |
| 2394 | + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_type'] ) ) { | |
| 2395 | + $forum_type = sanitize_key( $_POST['bbp_forum_type'] ); | |
| 2467 | 2396 | |
| 2468 | - // Get _POST data | |
| 2469 | - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_type'] ) ) { | |
| 2470 | - $forum_type = sanitize_key( $_POST['bbp_forum_type'] ); | |
| 2397 | + // Get edit data | |
| 2398 | + } elseif ( bbp_is_forum_edit() ) { | |
| 2399 | + $forum_type = bbp_get_forum_type(); | |
| 2471 | 2400 | |
| 2472 | - // Get edit data | |
| 2473 | - } elseif ( bbp_is_forum_edit() ) { | |
| 2474 | - $forum_type = bbp_get_forum_type(); | |
| 2401 | + // No data | |
| 2402 | + } else { | |
| 2403 | + $forum_type = 'forum'; | |
| 2404 | + } | |
| 2475 | 2405 | |
| 2476 | - // No data | |
| 2477 | - } else { | |
| 2478 | - $forum_type = 'forum'; | |
| 2406 | + // Filter & return | |
| 2407 | + return apply_filters( 'bbp_get_form_forum_type', $forum_type ); | |
| 2479 | 2408 | } |
| 2480 | 2409 | |
| 2481 | - // Filter & return | |
| 2482 | - return apply_filters( 'bbp_get_form_forum_type', $forum_type ); | |
| 2483 | -} | |
| 2484 | - | |
| 2485 | 2410 | /** |
| 2486 | - * Output value of forum visibility. | |
| 2411 | + * Output value of forum visibility | |
| 2487 | 2412 | * |
| 2488 | 2413 | * @since 2.1.0 bbPress (r3563) |
| 2489 | 2414 | */ |
| 2490 | 2415 | function bbp_form_forum_visibility() { |
| @@ -2489,37 +2414,36 @@ | ||
| 2489 | 2414 | */ |
| 2490 | 2415 | function bbp_form_forum_visibility() { |
| 2491 | 2416 | echo bbp_get_form_forum_visibility(); |
| 2492 | 2417 | } |
| 2418 | + /** | |
| 2419 | + * Return value of forum visibility | |
| 2420 | + * | |
| 2421 | + * @since 2.1.0 bbPress (r3563) | |
| 2422 | + * | |
| 2423 | + * @return string Value of topic content field | |
| 2424 | + */ | |
| 2425 | + function bbp_get_form_forum_visibility() { | |
| 2493 | 2426 | |
| 2494 | -/** | |
| 2495 | - * Return value of forum visibility. | |
| 2496 | - * | |
| 2497 | - * @since 2.1.0 bbPress (r3563) | |
| 2498 | - * | |
| 2499 | - * @return string Value of topic content field. | |
| 2500 | - */ | |
| 2501 | -function bbp_get_form_forum_visibility() { | |
| 2427 | + // Get _POST data | |
| 2428 | + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_visibility'] ) ) { | |
| 2429 | + $forum_visibility = sanitize_key( $_POST['bbp_forum_visibility'] ); | |
| 2502 | 2430 | |
| 2503 | - // Get _POST data | |
| 2504 | - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_visibility'] ) ) { | |
| 2505 | - $forum_visibility = sanitize_key( $_POST['bbp_forum_visibility'] ); | |
| 2431 | + // Get edit data | |
| 2432 | + } elseif ( bbp_is_forum_edit() ) { | |
| 2433 | + $forum_visibility = bbp_get_forum_visibility(); | |
| 2506 | 2434 | |
| 2507 | - // Get edit data | |
| 2508 | - } elseif ( bbp_is_forum_edit() ) { | |
| 2509 | - $forum_visibility = bbp_get_forum_visibility(); | |
| 2435 | + // No data | |
| 2436 | + } else { | |
| 2437 | + $forum_visibility = bbpress()->public_status_id; | |
| 2438 | + } | |
| 2510 | 2439 | |
| 2511 | - // No data | |
| 2512 | - } else { | |
| 2513 | - $forum_visibility = bbpress()->public_status_id; | |
| 2440 | + // Filter & return | |
| 2441 | + return apply_filters( 'bbp_get_form_forum_visibility', $forum_visibility ); | |
| 2514 | 2442 | } |
| 2515 | 2443 | |
| 2516 | - // Filter & return | |
| 2517 | - return apply_filters( 'bbp_get_form_forum_visibility', $forum_visibility ); | |
| 2518 | -} | |
| 2519 | - | |
| 2520 | 2444 | /** |
| 2521 | - * Output checked value of forum subscription. | |
| 2445 | + * Output checked value of forum subscription | |
| 2522 | 2446 | * |
| 2523 | 2447 | * @since 2.5.0 bbPress (r5156) |
| 2524 | 2448 | */ |
| 2525 | 2449 | function bbp_form_forum_subscribed() { |
| @@ -2524,46 +2448,45 @@ | ||
| 2524 | 2448 | */ |
| 2525 | 2449 | function bbp_form_forum_subscribed() { |
| 2526 | 2450 | echo bbp_get_form_forum_subscribed(); |
| 2527 | 2451 | } |
| 2452 | + /** | |
| 2453 | + * Return checked value of forum subscription | |
| 2454 | + * | |
| 2455 | + * @since 2.5.0 bbPress (r5156) | |
| 2456 | + * | |
| 2457 | + * @return string Checked value of forum subscription | |
| 2458 | + */ | |
| 2459 | + function bbp_get_form_forum_subscribed() { | |
| 2528 | 2460 | |
| 2529 | -/** | |
| 2530 | - * Return checked value of forum subscription. | |
| 2531 | - * | |
| 2532 | - * @since 2.5.0 bbPress (r5156) | |
| 2533 | - * | |
| 2534 | - * @return string Checked value of forum subscription. | |
| 2535 | - */ | |
| 2536 | -function bbp_get_form_forum_subscribed() { | |
| 2461 | + // Default value | |
| 2462 | + $forum_subscribed = false; | |
| 2537 | 2463 | |
| 2538 | - // Default value | |
| 2539 | - $forum_subscribed = false; | |
| 2464 | + // Get _POST data | |
| 2465 | + if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_subscription'] ) ) { | |
| 2466 | + $forum_subscribed = (bool) $_POST['bbp_forum_subscription']; | |
| 2540 | 2467 | |
| 2541 | - // Get _POST data | |
| 2542 | - if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_subscription'] ) ) { | |
| 2543 | - $forum_subscribed = (bool) $_POST['bbp_forum_subscription']; | |
| 2468 | + // Get edit data | |
| 2469 | + } elseif ( bbp_is_forum_edit() || bbp_is_reply_edit() ) { | |
| 2470 | + $post_author = (int) bbp_get_global_post_field( 'post_author', 'raw' ); | |
| 2471 | + $forum_subscribed = bbp_is_user_subscribed( $post_author, bbp_get_forum_id() ); | |
| 2544 | 2472 | |
| 2545 | - // Get edit data | |
| 2546 | - } elseif ( bbp_is_forum_edit() || bbp_is_reply_edit() ) { | |
| 2547 | - $post_author = (int) bbp_get_global_post_field( 'post_author', 'raw' ); | |
| 2548 | - $forum_subscribed = bbp_is_user_subscribed( $post_author, bbp_get_forum_id() ); | |
| 2473 | + // Get current status | |
| 2474 | + } elseif ( bbp_is_single_forum() ) { | |
| 2475 | + $forum_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_forum_id() ); | |
| 2476 | + } | |
| 2549 | 2477 | |
| 2550 | - // Get current status | |
| 2551 | - } elseif ( bbp_is_single_forum() ) { | |
| 2552 | - $forum_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_forum_id() ); | |
| 2478 | + // Get checked output | |
| 2479 | + $checked = checked( $forum_subscribed, true, false ); | |
| 2480 | + | |
| 2481 | + // Filter & return | |
| 2482 | + return apply_filters( 'bbp_get_form_forum_subscribed', $checked, $forum_subscribed ); | |
| 2553 | 2483 | } |
| 2554 | 2484 | |
| 2555 | - // Get checked output | |
| 2556 | - $checked = checked( $forum_subscribed, true, false ); | |
| 2557 | - | |
| 2558 | - // Filter & return | |
| 2559 | - return apply_filters( 'bbp_get_form_forum_subscribed', $checked, $forum_subscribed ); | |
| 2560 | -} | |
| 2561 | - | |
| 2562 | 2485 | /** Form Dropdowns ************************************************************/ |
| 2563 | 2486 | |
| 2564 | 2487 | /** |
| 2565 | - * Output value forum type dropdown. | |
| 2488 | + * Output value forum type dropdown | |
| 2566 | 2489 | * |
| 2567 | 2490 | * @since 2.1.0 bbPress (r3563) |
| 2568 | 2491 | * |
| 2569 | 2492 | * @param $args This function supports these arguments: |
| @@ -2574,21 +2497,20 @@ | ||
| 2574 | 2497 | */ |
| 2575 | 2498 | function bbp_form_forum_type_dropdown( $args = array() ) { |
| 2576 | 2499 | echo bbp_get_form_forum_type_dropdown( $args ); |
| 2577 | 2500 | } |
| 2578 | - | |
| 2579 | -/** | |
| 2580 | - * Return the forum type dropdown. | |
| 2581 | - * | |
| 2582 | - * @since 2.1.0 bbPress (r3563) | |
| 2583 | - * | |
| 2584 | - * @param $args This function supports these arguments: | |
| 2585 | - * - select_id: Select id. Defaults to bbp_forum_type | |
| 2586 | - * - tab: Deprecated. Tabindex | |
| 2587 | - * - forum_id: Forum id | |
| 2588 | - * - selected: Override the selected option | |
| 2589 | - * @return string HTML select list for selecting forum type | |
| 2590 | - */ | |
| 2501 | + /** | |
| 2502 | + * Return the forum type dropdown | |
| 2503 | + * | |
| 2504 | + * @since 2.1.0 bbPress (r3563) | |
| 2505 | + * | |
| 2506 | + * @param $args This function supports these arguments: | |
| 2507 | + * - select_id: Select id. Defaults to bbp_forum_type | |
| 2508 | + * - tab: Deprecated. Tabindex | |
| 2509 | + * - forum_id: Forum id | |
| 2510 | + * - selected: Override the selected option | |
| 2511 | + * @return string HTML select list for selecting forum type | |
| 2512 | + */ | |
| 2591 | 2513 | function bbp_get_form_forum_type_dropdown( $args = array() ) { |
| 2592 | 2514 | |
| 2593 | 2515 | // Backpat for handling passing of a forum ID as integer |
| 2594 | 2516 | if ( is_int( $args ) ) { |
| @@ -2648,9 +2570,9 @@ | ||
| 2648 | 2570 | return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args ); |
| 2649 | 2571 | } |
| 2650 | 2572 | |
| 2651 | 2573 | /** |
| 2652 | - * Output value forum status dropdown. | |
| 2574 | + * Output value forum status dropdown | |
| 2653 | 2575 | * |
| 2654 | 2576 | * @since 2.1.0 bbPress (r3563) |
| 2655 | 2577 | * |
| 2656 | 2578 | * @param $args This function supports these arguments: |
| @@ -2661,21 +2583,20 @@ | ||
| 2661 | 2583 | */ |
| 2662 | 2584 | function bbp_form_forum_status_dropdown( $args = array() ) { |
| 2663 | 2585 | echo bbp_get_form_forum_status_dropdown( $args ); |
| 2664 | 2586 | } |
| 2665 | - | |
| 2666 | -/** | |
| 2667 | - * Return the forum status dropdown. | |
| 2668 | - * | |
| 2669 | - * @since 2.1.0 bbPress (r3563) | |
| 2670 | - * | |
| 2671 | - * @param $args This function supports these arguments: | |
| 2672 | - * - select_id: Select id. Defaults to bbp_forum_status | |
| 2673 | - * - tab: Deprecated. Tabindex | |
| 2674 | - * - forum_id: Forum id | |
| 2675 | - * - selected: Override the selected option | |
| 2676 | - * @return string HTML select list for selecting forum status. | |
| 2677 | - */ | |
| 2587 | + /** | |
| 2588 | + * Return the forum status dropdown | |
| 2589 | + * | |
| 2590 | + * @since 2.1.0 bbPress (r3563) | |
| 2591 | + * | |
| 2592 | + * @param $args This function supports these arguments: | |
| 2593 | + * - select_id: Select id. Defaults to bbp_forum_status | |
| 2594 | + * - tab: Deprecated. Tabindex | |
| 2595 | + * - forum_id: Forum id | |
| 2596 | + * - selected: Override the selected option | |
| 2597 | + * @return string HTML select list for selecting forum status | |
| 2598 | + */ | |
| 2678 | 2599 | function bbp_get_form_forum_status_dropdown( $args = array() ) { |
| 2679 | 2600 | |
| 2680 | 2601 | // Backpat for handling passing of a forum ID |
| 2681 | 2602 | if ( is_int( $args ) ) { |
| @@ -2735,9 +2656,9 @@ | ||
| 2735 | 2656 | return apply_filters( 'bbp_get_form_forum_status_dropdown', ob_get_clean(), $r, $args ); |
| 2736 | 2657 | } |
| 2737 | 2658 | |
| 2738 | 2659 | /** |
| 2739 | - * Output value forum visibility dropdown. | |
| 2660 | + * Output value forum visibility dropdown | |
| 2740 | 2661 | * |
| 2741 | 2662 | * @since 2.1.0 bbPress (r3563) |
| 2742 | 2663 | * |
| 2743 | 2664 | * @param $args This function supports these arguments: |
| @@ -2748,21 +2669,20 @@ | ||
| 2748 | 2669 | */ |
| 2749 | 2670 | function bbp_form_forum_visibility_dropdown( $args = array() ) { |
| 2750 | 2671 | echo bbp_get_form_forum_visibility_dropdown( $args ); |
| 2751 | 2672 | } |
| 2752 | - | |
| 2753 | -/** | |
| 2754 | - * Return the forum visibility dropdown. | |
| 2755 | - * | |
| 2756 | - * @since 2.1.0 bbPress (r3563) | |
| 2757 | - * | |
| 2758 | - * @param $args This function supports these arguments: | |
| 2759 | - * - select_id: Select id. Defaults to bbp_forum_visibility | |
| 2760 | - * - tab: Deprecated. Tabindex | |
| 2761 | - * - forum_id: Forum id | |
| 2762 | - * - selected: Override the selected option | |
| 2763 | - * @return string HTML select list for selecting forum visibility. | |
| 2764 | - */ | |
| 2673 | + /** | |
| 2674 | + * Return the forum visibility dropdown | |
| 2675 | + * | |
| 2676 | + * @since 2.1.0 bbPress (r3563) | |
| 2677 | + * | |
| 2678 | + * @param $args This function supports these arguments: | |
| 2679 | + * - select_id: Select id. Defaults to bbp_forum_visibility | |
| 2680 | + * - tab: Deprecated. Tabindex | |
| 2681 | + * - forum_id: Forum id | |
| 2682 | + * - selected: Override the selected option | |
| 2683 | + * @return string HTML select list for selecting forum visibility | |
| 2684 | + */ | |
| 2765 | 2685 | function bbp_get_form_forum_visibility_dropdown( $args = array() ) { |
| 2766 | 2686 | |
| 2767 | 2687 | // Backpat for handling passing of a forum ID |
| 2768 | 2688 | if ( is_int( $args ) ) { |
| @@ -2831,9 +2751,9 @@ | ||
| 2831 | 2751 | * @see bbp_forum_form_fields() |
| 2832 | 2752 | * |
| 2833 | 2753 | * @since 2.6.0 bbPress (r5558) |
| 2834 | 2754 | * |
| 2835 | - * @return boolean True if is a post request with valid nonce. | |
| 2755 | + * @return boolean True if is a post request with valid nonce | |
| 2836 | 2756 | */ |
| 2837 | 2757 | function bbp_is_forum_form_post_request() { |
| 2838 | 2758 | |
| 2839 | 2759 | // Bail if not a post request |
| @@ -2856,9 +2776,9 @@ | ||
| 2856 | 2776 | |
| 2857 | 2777 | /** Feeds *********************************************************************/ |
| 2858 | 2778 | |
| 2859 | 2779 | /** |
| 2860 | - * Output the link for the forum feed. | |
| 2780 | + * Output the link for the forum feed | |
| 2861 | 2781 | * |
| 2862 | 2782 | * @since 2.0.0 bbPress (r3172) |
| 2863 | 2783 | * |
| 2864 | 2784 | * @param int $forum_id Optional. Forum ID. |
| @@ -2865,18 +2785,17 @@ | ||
| 2865 | 2785 | */ |
| 2866 | 2786 | function bbp_forum_topics_feed_link( $forum_id = 0 ) { |
| 2867 | 2787 | echo bbp_get_forum_topics_feed_link( $forum_id ); |
| 2868 | 2788 | } |
| 2869 | - | |
| 2870 | -/** | |
| 2871 | - * Retrieve the link for the forum feed. | |
| 2872 | - * | |
| 2873 | - * @since 2.0.0 bbPress (r3172) | |
| 2874 | - * | |
| 2875 | - * @param int $forum_id Optional. Forum ID. | |
| 2876 | - * | |
| 2877 | - * @return string | |
| 2878 | - */ | |
| 2789 | + /** | |
| 2790 | + * Retrieve the link for the forum feed | |
| 2791 | + * | |
| 2792 | + * @since 2.0.0 bbPress (r3172) | |
| 2793 | + * | |
| 2794 | + * @param int $forum_id Optional. Forum ID. | |
| 2795 | + * | |
| 2796 | + * @return string | |
| 2797 | + */ | |
| 2879 | 2798 | function bbp_get_forum_topics_feed_link( $forum_id = 0 ) { |
| 2880 | 2799 | |
| 2881 | 2800 | // Validate forum id |
| 2882 | 2801 | $forum_id = bbp_get_forum_id( $forum_id ); |
| @@ -2913,9 +2832,9 @@ | ||
| 2913 | 2832 | return apply_filters( 'bbp_get_forum_topics_feed_link', $link, $url, $forum_id ); |
| 2914 | 2833 | } |
| 2915 | 2834 | |
| 2916 | 2835 | /** |
| 2917 | - * Output the link for the forum replies feed. | |
| 2836 | + * Output the link for the forum replies feed | |
| 2918 | 2837 | * |
| 2919 | 2838 | * @since 2.0.0 bbPress (r3172) |
| 2920 | 2839 | * |
| 2921 | 2840 | * @param int $forum_id Optional. Forum ID. |
| @@ -2922,18 +2841,17 @@ | ||
| 2922 | 2841 | */ |
| 2923 | 2842 | function bbp_forum_replies_feed_link( $forum_id = 0 ) { |
| 2924 | 2843 | echo bbp_get_forum_replies_feed_link( $forum_id ); |
| 2925 | 2844 | } |
| 2926 | - | |
| 2927 | -/** | |
| 2928 | - * Retrieve the link for the forum replies feed. | |
| 2929 | - * | |
| 2930 | - * @since 2.0.0 bbPress (r3172) | |
| 2931 | - * | |
| 2932 | - * @param int $forum_id Optional. Forum ID. | |
| 2933 | - * | |
| 2934 | - * @return string | |
| 2935 | - */ | |
| 2845 | + /** | |
| 2846 | + * Retrieve the link for the forum replies feed | |
| 2847 | + * | |
| 2848 | + * @since 2.0.0 bbPress (r3172) | |
| 2849 | + * | |
| 2850 | + * @param int $forum_id Optional. Forum ID. | |
| 2851 | + * | |
| 2852 | + * @return string | |
| 2853 | + */ | |
| 2936 | 2854 | function bbp_get_forum_replies_feed_link( $forum_id = 0 ) { |
| 2937 | 2855 | |
| 2938 | 2856 | // Validate forum id |
| 2939 | 2857 | $forum_id = bbp_get_forum_id( $forum_id ); |