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