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