| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* bbPress General Template Tags |
| 5 |
* |
| 6 |
* @package bbPress |
| 7 |
* @subpackage TemplateTags |
| 8 |
*/ |
| 9 |
|
| 10 |
// Redirect if accessed directly |
| 11 |
if ( !defined( 'ABSPATH' ) ) exit; |
| 12 |
|
| 13 |
/** Add-on Actions ************************************************************/ |
| 14 |
|
| 15 |
/** |
| 16 |
* Add our custom head action to wp_head |
| 17 |
* |
| 18 |
* @since bbPress (r2464) |
| 19 |
* |
| 20 |
* @uses do_action() Calls 'bbp_head' |
| 21 |
*/ |
| 22 |
function bbp_head() { |
| 23 |
do_action( 'bbp_head' ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Add our custom head action to wp_head |
| 28 |
* |
| 29 |
* @since bbPress (r2464) |
| 30 |
* |
| 31 |
* @uses do_action() Calls 'bbp_footer' |
| 32 |
*/ |
| 33 |
function bbp_footer() { |
| 34 |
do_action( 'bbp_footer' ); |
| 35 |
} |
| 36 |
|
| 37 |
/** is_ ***********************************************************************/ |
| 38 |
|
| 39 |
/** |
| 40 |
* Check if current page is a bbPress forum |
| 41 |
* |
| 42 |
* @since bbPress (r2549) |
| 43 |
* |
| 44 |
* @param int $post_id Possible post_id to check |
| 45 |
* @uses bbp_get_forum_post_type() To get the forum post type |
| 46 |
* @uses is_singular() To check if it's the single post page |
| 47 |
* @uses get_post_field() To get the post type of the post id |
| 48 |
* @return bool True if it's a forum page, false if not |
| 49 |
*/ |
| 50 |
function bbp_is_forum( $post_id = 0 ) { |
| 51 |
global $bbp, $wp_query; |
| 52 |
|
| 53 |
if ( empty( $post_id ) ) { |
| 54 |
|
| 55 |
if ( is_singular( bbp_get_forum_post_type() ) ) |
| 56 |
return true; |
| 57 |
|
| 58 |
if ( isset( $wp_query->query_vars['post_type'] ) && ( bbp_get_forum_post_type() === $wp_query->query_vars['post_type'] ) ) |
| 59 |
return true; |
| 60 |
|
| 61 |
if ( isset( $bbp->forum_query->post->post_type ) && ( bbp_get_forum_post_type() === $bbp->forum_query->post->post_type ) ) |
| 62 |
return true; |
| 63 |
|
| 64 |
if ( isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) && ( bbp_get_forum_post_type() === $_GET['post_type'] ) ) |
| 65 |
return true; |
| 66 |
|
| 67 |
} elseif ( !empty( $post_id ) && ( bbp_get_forum_post_type() == get_post_field( 'post_type', $post_id ) ) ) |
| 68 |
return true; |
| 69 |
|
| 70 |
return false; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Check if current page is a bbPress topic |
| 75 |
* |
| 76 |
* @since bbPress (r2549) |
| 77 |
* |
| 78 |
* @param int $post_id Possible post_id to check |
| 79 |
* @uses bbp_is_topic_edit() To return false if it's a topic edit page |
| 80 |
* @uses bbp_get_topic_post_type() To get the topic post type |
| 81 |
* @uses is_singular() To check if it's the single post page |
| 82 |
* @uses get_post_field() To get the post type of the post id |
| 83 |
* @return bool True if it's a topic page, false if not |
| 84 |
*/ |
| 85 |
function bbp_is_topic( $post_id = 0 ) { |
| 86 |
global $bbp, $wp_query; |
| 87 |
|
| 88 |
// Return false if it's a edit topic page |
| 89 |
if ( bbp_is_topic_edit() ) |
| 90 |
return false; |
| 91 |
|
| 92 |
if ( empty( $post_id ) ) { |
| 93 |
|
| 94 |
if ( is_singular( bbp_get_topic_post_type() ) ) |
| 95 |
return true; |
| 96 |
|
| 97 |
if ( isset( $wp_query->query_vars['post_type'] ) && ( bbp_get_topic_post_type() === $wp_query->query_vars['post_type'] ) ) |
| 98 |
return true; |
| 99 |
|
| 100 |
if ( isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) && ( bbp_get_topic_post_type() === $_GET['post_type'] ) ) |
| 101 |
return true; |
| 102 |
|
| 103 |
} elseif ( !empty( $post_id ) && ( bbp_get_topic_post_type() == get_post_field( 'post_type', $post_id ) ) ) |
| 104 |
return true; |
| 105 |
|
| 106 |
return false; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Check if current page is a topic edit page |
| 111 |
* |
| 112 |
* @since bbPress (r2753) |
| 113 |
* |
| 114 |
* @uses WP_Query Checks if WP_Query::bbp_is_topic_edit is true |
| 115 |
* @return bool True if it's the topic edit page, false if not |
| 116 |
*/ |
| 117 |
function bbp_is_topic_edit() { |
| 118 |
global $wp_query; |
| 119 |
|
| 120 |
if ( !empty( $wp_query->bbp_is_topic_edit ) && $wp_query->bbp_is_topic_edit == true ) |
| 121 |
return true; |
| 122 |
|
| 123 |
return false; |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Check if current page is a topic merge page |
| 128 |
* |
| 129 |
* @since bbPress (r2756) |
| 130 |
* |
| 131 |
* @uses bbp_is_topic_edit() To check if it's a topic edit page |
| 132 |
* @return bool True if it's the topic merge page, false if not |
| 133 |
*/ |
| 134 |
function bbp_is_topic_merge() { |
| 135 |
|
| 136 |
if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'merge' == $_GET['action'] ) ) |
| 137 |
return true; |
| 138 |
|
| 139 |
return false; |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Check if current page is a topic split page |
| 144 |
* |
| 145 |
* @since bbPress (r2756) |
| 146 |
* |
| 147 |
* @uses bbp_is_topic_edit() To check if it's a topic edit page |
| 148 |
* @return bool True if it's the topic split page, false if not |
| 149 |
*/ |
| 150 |
function bbp_is_topic_split() { |
| 151 |
|
| 152 |
if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'split' == $_GET['action'] ) ) |
| 153 |
return true; |
| 154 |
|
| 155 |
return false; |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* Check if current page is a bbPress reply |
| 160 |
* |
| 161 |
* @since bbPress (r2549) |
| 162 |
* |
| 163 |
* @param int $post_id Possible post_id to check |
| 164 |
* @uses bbp_is_reply_edit() To return false if it's a reply edit page |
| 165 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 166 |
* @uses is_singular() To check if it's the single post page |
| 167 |
* @uses get_post_field() To get the post type of the post id |
| 168 |
* @return bool True if it's a reply page, false if not |
| 169 |
*/ |
| 170 |
function bbp_is_reply( $post_id = 0 ) { |
| 171 |
global $bbp, $wp_query; |
| 172 |
|
| 173 |
// Return false if it's a edit reply page |
| 174 |
if ( bbp_is_reply_edit() ) |
| 175 |
return false; |
| 176 |
|
| 177 |
if ( empty( $post_id ) ) { |
| 178 |
|
| 179 |
if ( is_singular( bbp_get_reply_post_type() ) ) |
| 180 |
return true; |
| 181 |
|
| 182 |
if ( isset( $wp_query->query_vars['post_type'] ) && ( bbp_get_reply_post_type() === $wp_query->query_vars['post_type'] ) ) |
| 183 |
return true; |
| 184 |
|
| 185 |
if ( isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) && ( bbp_get_reply_post_type() === $_GET['post_type'] ) ) |
| 186 |
return true; |
| 187 |
|
| 188 |
} elseif ( !empty( $post_id ) && ( bbp_get_reply_post_type() == get_post_field( 'post_type', $post_id ) ) ) |
| 189 |
return true; |
| 190 |
|
| 191 |
return false; |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Check if current page is a reply edit page |
| 196 |
* |
| 197 |
* @since bbPress (r2753) |
| 198 |
* |
| 199 |
* @uses WP_Query Checks if WP_Query::bbp_is_reply_edit is true |
| 200 |
* @return bool True if it's the reply edit page, false if not |
| 201 |
*/ |
| 202 |
function bbp_is_reply_edit() { |
| 203 |
global $wp_query; |
| 204 |
|
| 205 |
if ( !empty( $wp_query->bbp_is_reply_edit ) && ( true == $wp_query->bbp_is_reply_edit ) ) |
| 206 |
return true; |
| 207 |
|
| 208 |
return false; |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* Check if current page is a bbPress user's favorites page (profile page) |
| 213 |
* |
| 214 |
* @since bbPress (r2652) |
| 215 |
* |
| 216 |
* @param bool $query_name_check Optional. Check the query name |
| 217 |
* (_bbp_query_name query var), if it is |
| 218 |
* 'bbp_user_profile_favorites' or not. Defaults |
| 219 |
* to true. |
| 220 |
* @uses bbp_is_user_profile_page() To check if it's the user profile page |
| 221 |
* @uses bbp_get_query_name() To get the query name |
| 222 |
* @return bool True if it's the favorites page, false if not |
| 223 |
*/ |
| 224 |
function bbp_is_favorites( $query_name_check = true ) { |
| 225 |
if ( !bbp_is_user_profile_page() ) |
| 226 |
return false; |
| 227 |
|
| 228 |
if ( !empty( $query_name_check ) && ( !bbp_is_query_name( 'bbp_user_profile_favorites' ) ) ) |
| 229 |
return false; |
| 230 |
|
| 231 |
return true; |
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* Check if current page is a bbPress user's subscriptions page (profile page) |
| 236 |
* |
| 237 |
* @since bbPress (r2652) |
| 238 |
* |
| 239 |
* @param bool $query_name_check Optional. Check the query name |
| 240 |
* (_bbp_query_name query var), if it is |
| 241 |
* 'bbp_user_profile_favorites' or not. Defaults |
| 242 |
* to true. |
| 243 |
* @uses bbp_is_user_profile_page() To check if it's the user profile page |
| 244 |
* @uses bbp_get_query_name() To get the query name |
| 245 |
* @return bool True if it's the subscriptions page, false if not |
| 246 |
*/ |
| 247 |
function bbp_is_subscriptions( $query_name_check = true ) { |
| 248 |
if ( !bbp_is_user_profile_page() ) |
| 249 |
return false; |
| 250 |
|
| 251 |
if ( !empty( $query_name_check ) && ( !bbp_is_query_name( 'bbp_user_profile_subscriptions' ) ) ) |
| 252 |
return false; |
| 253 |
|
| 254 |
return true; |
| 255 |
} |
| 256 |
|
| 257 |
/** |
| 258 |
* Check if current page shows the topics created by a bbPress user (profile |
| 259 |
* page) |
| 260 |
* |
| 261 |
* @since bbPress (r2688) |
| 262 |
* |
| 263 |
* @param bool $query_name_check Optional. Check the query name |
| 264 |
* (_bbp_query_name query var), if it is |
| 265 |
* 'bbp_user_profile_favorites' or not. Defaults |
| 266 |
* to true. |
| 267 |
* @uses bbp_is_user_profile_page() To check if it's the user profile page |
| 268 |
* @uses bbp_get_query_name() To get the query name |
| 269 |
* @return bool True if it's the topics created page, false if not |
| 270 |
*/ |
| 271 |
function bbp_is_topics_created( $query_name_check = true ) { |
| 272 |
if ( !bbp_is_user_profile_page() ) |
| 273 |
return false; |
| 274 |
|
| 275 |
if ( !empty( $query_name_check ) && ( !bbp_is_query_name( 'bbp_user_profile_topics_created' ) ) ) |
| 276 |
return false; |
| 277 |
|
| 278 |
return true; |
| 279 |
} |
| 280 |
|
| 281 |
/** |
| 282 |
* Check if current page is the currently logged in users author page |
| 283 |
* |
| 284 |
* @since bbPress (r2688) |
| 285 |
* |
| 286 |
* @uses bbPres Checks if bbPress::displayed_user is set and if |
| 287 |
* bbPress::displayed_user::ID equals bbPress::current_user::ID |
| 288 |
* or not |
| 289 |
* @return bool True if it's the user's home, false if not |
| 290 |
*/ |
| 291 |
function bbp_is_user_home() { |
| 292 |
global $bbp; |
| 293 |
|
| 294 |
if ( !isset( $bbp->displayed_user ) ) |
| 295 |
return false; |
| 296 |
|
| 297 |
return $bbp->current_user->ID == $bbp->displayed_user->ID; |
| 298 |
} |
| 299 |
|
| 300 |
/** |
| 301 |
* Check if current page is a user profile page |
| 302 |
* |
| 303 |
* @since bbPress (r2688) |
| 304 |
* |
| 305 |
* @uses WP_Query Checks if WP_Query::bbp_is_user_profile_page is set to true |
| 306 |
* @return bool True if it's a user's profile page, false if not |
| 307 |
*/ |
| 308 |
function bbp_is_user_profile_page() { |
| 309 |
global $wp_query; |
| 310 |
|
| 311 |
if ( !empty( $wp_query->bbp_is_user_profile_page ) && ( true == $wp_query->bbp_is_user_profile_page ) ) |
| 312 |
return true; |
| 313 |
|
| 314 |
return false; |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* Check if current page is a user profile edit page |
| 319 |
* |
| 320 |
* @since bbPress (r2688) |
| 321 |
* |
| 322 |
* @uses WP_Query Checks if WP_Query::bbp_is_user_profile_edit is set to true |
| 323 |
* @return bool True if it's a user's profile edit page, false if not |
| 324 |
*/ |
| 325 |
function bbp_is_user_profile_edit() { |
| 326 |
global $wp_query; |
| 327 |
|
| 328 |
if ( !empty( $wp_query->bbp_is_user_profile_edit ) && ( true == $wp_query->bbp_is_user_profile_edit ) ) |
| 329 |
return true; |
| 330 |
|
| 331 |
return false; |
| 332 |
} |
| 333 |
|
| 334 |
/** |
| 335 |
* Check if current page is a view page |
| 336 |
* |
| 337 |
* @since bbPress (r2789) |
| 338 |
* |
| 339 |
* @uses WP_Query Checks if WP_Query::bbp_is_view is true |
| 340 |
* @return bool Is it a view page? |
| 341 |
*/ |
| 342 |
function bbp_is_view() { |
| 343 |
global $wp_query; |
| 344 |
|
| 345 |
if ( !empty( $wp_query->bbp_is_view ) && ( true == $wp_query->bbp_is_view ) ) |
| 346 |
return true; |
| 347 |
|
| 348 |
return false; |
| 349 |
} |
| 350 |
|
| 351 |
/** |
| 352 |
* Use the above is_() functions to output a body class for each scenario |
| 353 |
* |
| 354 |
* @since bbPress (r2926) |
| 355 |
* |
| 356 |
* @param array $wp_classes |
| 357 |
* @param array $custom_classes |
| 358 |
* @uses bbp_is_forum() |
| 359 |
* @uses bbp_is_topic() |
| 360 |
* @uses bbp_is_topic_edit() |
| 361 |
* @uses bbp_is_topic_merge() |
| 362 |
* @uses bbp_is_topic_split() |
| 363 |
* @uses bbp_is_reply() |
| 364 |
* @uses bbp_is_reply_edit() |
| 365 |
* @uses bbp_is_reply_edit() |
| 366 |
* @uses bbp_is_view() |
| 367 |
* @uses bbp_is_user_profile_edit() |
| 368 |
* @uses bbp_is_user_profile_page() |
| 369 |
* @uses bbp_is_user_home() |
| 370 |
* @uses bbp_is_subscriptions() |
| 371 |
* @uses bbp_is_favorites() |
| 372 |
* @uses bbp_is_topics_created() |
| 373 |
* @return array Body Classes |
| 374 |
*/ |
| 375 |
function bbp_body_class( $wp_classes, $custom_classes = false ) { |
| 376 |
|
| 377 |
$bbp_classes = array(); |
| 378 |
|
| 379 |
/** Components ********************************************************/ |
| 380 |
|
| 381 |
if ( bbp_is_forum() ) |
| 382 |
$bbp_classes[] = bbp_get_forum_post_type(); |
| 383 |
|
| 384 |
if ( bbp_is_topic() ) |
| 385 |
$bbp_classes[] = bbp_get_topic_post_type(); |
| 386 |
|
| 387 |
if ( bbp_is_topic_edit() ) |
| 388 |
$bbp_classes[] = bbp_get_topic_post_type() . '-edit'; |
| 389 |
|
| 390 |
if ( bbp_is_topic_merge() ) |
| 391 |
$bbp_classes[] = bbp_get_topic_post_type() . '-merge'; |
| 392 |
|
| 393 |
if ( bbp_is_topic_split() ) |
| 394 |
$bbp_classes[] = bbp_get_topic_post_type() . '-split'; |
| 395 |
|
| 396 |
if ( bbp_is_reply() ) |
| 397 |
$bbp_classes[] = bbp_get_reply_post_type(); |
| 398 |
|
| 399 |
if ( bbp_is_reply_edit() ) |
| 400 |
$bbp_classes[] = bbp_get_reply_post_type() . '-edit'; |
| 401 |
|
| 402 |
if ( bbp_is_view() ) |
| 403 |
$bbp_classes[] = 'bbp-view'; |
| 404 |
|
| 405 |
/** User **************************************************************/ |
| 406 |
|
| 407 |
if ( bbp_is_user_profile_edit() ) { |
| 408 |
$bbp_classes[] = 'bbp-user-edit'; |
| 409 |
$bbp_classes[] = 'single'; |
| 410 |
$bbp_classes[] = 'singular'; |
| 411 |
} |
| 412 |
|
| 413 |
if ( bbp_is_user_profile_page() ) { |
| 414 |
$bbp_classes[] = 'bbp-user-page'; |
| 415 |
$bbp_classes[] = 'single'; |
| 416 |
$bbp_classes[] = 'singular'; |
| 417 |
} |
| 418 |
|
| 419 |
if ( bbp_is_user_home() ) { |
| 420 |
$bbp_classes[] = 'bbp-user-home'; |
| 421 |
$bbp_classes[] = 'single'; |
| 422 |
$bbp_classes[] = 'singular'; |
| 423 |
} |
| 424 |
|
| 425 |
if ( bbp_is_topics_created() ) { |
| 426 |
$bbp_classes[] = 'bbp-topics-created'; |
| 427 |
$bbp_classes[] = 'single'; |
| 428 |
$bbp_classes[] = 'singular'; |
| 429 |
} |
| 430 |
|
| 431 |
if ( bbp_is_favorites() ) { |
| 432 |
$bbp_classes[] = 'bbp-favorites'; |
| 433 |
$bbp_classes[] = 'single'; |
| 434 |
$bbp_classes[] = 'singular'; |
| 435 |
} |
| 436 |
|
| 437 |
if ( bbp_is_subscriptions() ) { |
| 438 |
$bbp_classes[] = 'bbp-subscriptions'; |
| 439 |
$bbp_classes[] = 'single'; |
| 440 |
$bbp_classes[] = 'singular'; |
| 441 |
} |
| 442 |
|
| 443 |
/** Clean up **********************************************************/ |
| 444 |
|
| 445 |
// Add bbPress class if we are within a bbPress page |
| 446 |
if ( !empty( $bbp_classes ) ) |
| 447 |
$bbp_classes[] = 'bbPress'; |
| 448 |
|
| 449 |
// Merge WP classes with bbPress classes |
| 450 |
$classes = array_merge( (array) $bbp_classes, (array) $wp_classes ); |
| 451 |
|
| 452 |
// Remove any duplicates |
| 453 |
$classes = array_unique( $classes ); |
| 454 |
|
| 455 |
return apply_filters( 'bbp_get_the_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes ); |
| 456 |
} |
| 457 |
|
| 458 |
/** Forms *********************************************************************/ |
| 459 |
|
| 460 |
/** |
| 461 |
* Output the login form action url |
| 462 |
* |
| 463 |
* @since bbPress (r2815) |
| 464 |
* |
| 465 |
* @param string $url Pass a URL to redirect to |
| 466 |
* @uses add_query_arg() To add a arg to the url |
| 467 |
* @uses site_url() Toget the site url |
| 468 |
* @uses apply_filters() Calls 'bbp_wp_login_action' with the url and args |
| 469 |
*/ |
| 470 |
function bbp_wp_login_action( $args = '' ) { |
| 471 |
$defaults = array ( |
| 472 |
'action' => '', |
| 473 |
'context' => '' |
| 474 |
); |
| 475 |
$r = wp_parse_args( $args, $defaults ); |
| 476 |
extract( $r ); |
| 477 |
|
| 478 |
if ( !empty( $action ) ) |
| 479 |
$login_url = add_query_arg( array( 'action' => $action ), 'wp-login.php' ); |
| 480 |
else |
| 481 |
$login_url = 'wp-login.php'; |
| 482 |
|
| 483 |
$login_url = site_url( $login_url, $context ); |
| 484 |
|
| 485 |
echo apply_filters( 'bbp_wp_login_action', $login_url, $args ); |
| 486 |
} |
| 487 |
|
| 488 |
/** |
| 489 |
* Output hidden request URI field for user forms. |
| 490 |
* |
| 491 |
* The referer link is the current Request URI from the server super global. The |
| 492 |
* input name is '_wp_http_referer', in case you wanted to check manually. |
| 493 |
* |
| 494 |
* @since bbPress (r2815) |
| 495 |
* |
| 496 |
* @param string $url Pass a URL to redirect to |
| 497 |
* @uses wp_get_referer() To get the referer |
| 498 |
* @uses esc_attr() To escape the url |
| 499 |
* @uses apply_filters() Calls 'bbp_redirect_to_field' with the referer field |
| 500 |
* and url |
| 501 |
*/ |
| 502 |
function bbp_redirect_to_field( $url = '' ) { |
| 503 |
// If no URL is passed, try to get the referer and then the request uri |
| 504 |
if ( empty( $url ) && ( !$url = wp_get_referer() ) && ( !empty( $_SERVER['REQUEST_URI'] ) ) ) |
| 505 |
$url = $_SERVER['REQUEST_URI']; |
| 506 |
|
| 507 |
// Remove loggedout query arg if it's there |
| 508 |
$url = (string) esc_attr( remove_query_arg( 'loggedout', $url ) ); |
| 509 |
|
| 510 |
$referer_field = '<input type="hidden" name="redirect_to" value="' . $url . '" />'; |
| 511 |
|
| 512 |
echo apply_filters( 'bbp_redirect_to_field', $referer_field, $url ); |
| 513 |
} |
| 514 |
|
| 515 |
/** |
| 516 |
* Echo sanitized $_REQUEST value. |
| 517 |
* |
| 518 |
* Use the $input_type parameter to properly process the value. This |
| 519 |
* ensures correct sanitization of the value for the receiving input. |
| 520 |
* |
| 521 |
* @since bbPress (r2815) |
| 522 |
* |
| 523 |
* @param string $request Name of $_REQUEST to look for |
| 524 |
* @param string $input_type Type of input the value is for |
| 525 |
* @uses bbp_get_sanitize_val() To sanitize the value |
| 526 |
*/ |
| 527 |
function bbp_sanitize_val( $request = '', $input_type = 'text' ) { |
| 528 |
echo bbp_get_sanitize_val( $request, $input_type ); |
| 529 |
} |
| 530 |
/** |
| 531 |
* Return sanitized $_REQUEST value. |
| 532 |
* |
| 533 |
* Use the $input_type parameter to properly process the value. This |
| 534 |
* ensures correct sanitization of the value for the receiving input. |
| 535 |
* |
| 536 |
* @since bbPress (r2815) |
| 537 |
* |
| 538 |
* @param string $request Name of $_REQUEST to look for |
| 539 |
* @param string $input_type Type of input the value is for |
| 540 |
* @uses esc_attr() To escape the string |
| 541 |
* @uses apply_filters() Calls 'bbp_get_sanitize_val' with the sanitized |
| 542 |
* value, request and input type |
| 543 |
* @return string Sanitized value ready for screen display |
| 544 |
*/ |
| 545 |
function bbp_get_sanitize_val( $request = '', $input_type = 'text' ) { |
| 546 |
|
| 547 |
// Check that requested |
| 548 |
if ( empty( $_REQUEST[$request] ) ) |
| 549 |
return false; |
| 550 |
|
| 551 |
// Set request varaible |
| 552 |
$pre_ret_val = $_REQUEST[$request]; |
| 553 |
|
| 554 |
// Treat different kinds of fields in different ways |
| 555 |
switch ( $input_type ) { |
| 556 |
case 'text' : |
| 557 |
case 'textarea' : |
| 558 |
$retval = esc_attr( stripslashes( $pre_ret_val ) ); |
| 559 |
break; |
| 560 |
|
| 561 |
case 'password' : |
| 562 |
case 'select' : |
| 563 |
case 'radio' : |
| 564 |
case 'checkbox' : |
| 565 |
default : |
| 566 |
$retval = esc_attr( $pre_ret_val ); |
| 567 |
break; |
| 568 |
} |
| 569 |
|
| 570 |
return apply_filters( 'bbp_get_sanitize_val', $retval, $request, $input_type ); |
| 571 |
} |
| 572 |
|
| 573 |
/** |
| 574 |
* Output the current tab index of a given form |
| 575 |
* |
| 576 |
* Use this function to handle the tab indexing of user facing forms within a |
| 577 |
* template file. Calling this function will automatically increment the global |
| 578 |
* tab index by default. |
| 579 |
* |
| 580 |
* @since bbPress (r2810) |
| 581 |
* |
| 582 |
* @param int $auto_increment Optional. Default true. Set to false to prevent |
| 583 |
* increment |
| 584 |
*/ |
| 585 |
function bbp_tab_index( $auto_increment = true ) { |
| 586 |
echo bbp_get_tab_index( $auto_increment ); |
| 587 |
} |
| 588 |
|
| 589 |
/** |
| 590 |
* Output the current tab index of a given form |
| 591 |
* |
| 592 |
* Use this function to handle the tab indexing of user facing forms |
| 593 |
* within a template file. Calling this function will automatically |
| 594 |
* increment the global tab index by default. |
| 595 |
* |
| 596 |
* @since bbPress (r2810) |
| 597 |
* |
| 598 |
* @uses apply_filters Allows return value to be filtered |
| 599 |
* @param int $auto_increment Optional. Default true. Set to false to |
| 600 |
* prevent the increment |
| 601 |
* @return int $bbp->tab_index The global tab index |
| 602 |
*/ |
| 603 |
function bbp_get_tab_index( $auto_increment = true ) { |
| 604 |
global $bbp; |
| 605 |
|
| 606 |
if ( true === $auto_increment ) |
| 607 |
++$bbp->tab_index; |
| 608 |
|
| 609 |
return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index ); |
| 610 |
} |
| 611 |
|
| 612 |
/** |
| 613 |
* Output a select box allowing to pick which forum/topic a new topic/reply |
| 614 |
* belongs in. |
| 615 |
* |
| 616 |
* Can be used for any post type, but is mostly used for topics and forums. |
| 617 |
* |
| 618 |
* @since bbPress (r2746) |
| 619 |
* |
| 620 |
* @param mixed $args See {@link bbp_get_dropdown()} for arguments |
| 621 |
*/ |
| 622 |
function bbp_dropdown( $args = '' ) { |
| 623 |
echo bbp_get_dropdown( $args ); |
| 624 |
} |
| 625 |
/** |
| 626 |
* Output a select box allowing to pick which forum/topic a new |
| 627 |
* topic/reply belongs in. |
| 628 |
* |
| 629 |
* @since bbPress (r2746) |
| 630 |
* |
| 631 |
* @param mixed $args The function supports these args: |
| 632 |
* - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum) |
| 633 |
* - selected: Selected ID, to not have any value as selected, pass |
| 634 |
* anything smaller than 0 (due to the nature of select |
| 635 |
* box, the first value would of course be selected - |
| 636 |
* though you can have that as none (pass 'show_none' arg)) |
| 637 |
* - sort_column: Sort by? Defaults to 'menu_order, post_title' |
| 638 |
* - child_of: Child of. Defaults to 0 |
| 639 |
* - post_status: Which all post_statuses to find in? Can be an array |
| 640 |
* or CSV of publish, category, closed, private, spam, |
| 641 |
* trash (based on post type) - if not set, these are |
| 642 |
* automatically determined based on the post_type |
| 643 |
* - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get |
| 644 |
* all posts |
| 645 |
* - walker: Which walker to use? Defaults to |
| 646 |
* {@link BBP_Walker_Dropdown} |
| 647 |
* - select_id: ID of the select box. Defaults to 'bbp_forum_id' |
| 648 |
* - tab: Tabindex value. False or integer |
| 649 |
* - options_only: Show only <options>? No <select>? |
| 650 |
* - show_none: False or something like __( '(No Forum)', 'bbpress' ), |
| 651 |
* will have value="" |
| 652 |
* - none_found: False or something like |
| 653 |
* __( 'No forums to post to!', 'bbpress' ) |
| 654 |
* - disable_categories: Disable forum categories and closed forums? |
| 655 |
* Defaults to true. Only for forums and when |
| 656 |
* the category option is displayed. |
| 657 |
* @uses BBP_Walker_Dropdown() As the default walker to generate the |
| 658 |
* dropdown |
| 659 |
* @uses current_user_can() To check if the current user can read |
| 660 |
* private forums |
| 661 |
* @uses bbp_get_forum_post_type() To get the forum post type |
| 662 |
* @uses bbp_get_topic_post_type() To get the topic post type |
| 663 |
* @uses walk_page_dropdown_tree() To generate the dropdown using the |
| 664 |
* walker |
| 665 |
* @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown |
| 666 |
* and args |
| 667 |
* @return string The dropdown |
| 668 |
*/ |
| 669 |
function bbp_get_dropdown( $args = '' ) { |
| 670 |
global $bbp; |
| 671 |
|
| 672 |
$defaults = array ( |
| 673 |
'post_type' => bbp_get_forum_post_type(), |
| 674 |
'selected' => 0, |
| 675 |
'sort_column' => 'menu_order', |
| 676 |
'child_of' => '0', |
| 677 |
'post_status' => 'publish', |
| 678 |
'numberposts' => -1, |
| 679 |
'orderby' => 'menu_order', |
| 680 |
'walker' => '', |
| 681 |
|
| 682 |
// Output-related |
| 683 |
'select_id' => 'bbp_forum_id', |
| 684 |
'tab' => bbp_get_tab_index(), |
| 685 |
'options_only' => false, |
| 686 |
'show_none' => false, |
| 687 |
'none_found' => false, |
| 688 |
'disable_categories' => true |
| 689 |
); |
| 690 |
|
| 691 |
$r = wp_parse_args( $args, $defaults ); |
| 692 |
|
| 693 |
if ( empty( $r['walker'] ) ) { |
| 694 |
$r['walker'] = new BBP_Walker_Dropdown(); |
| 695 |
$r['walker']->tree_type = $r['post_type']; |
| 696 |
} |
| 697 |
|
| 698 |
// Force 0 |
| 699 |
if ( is_numeric( $r['selected'] ) && $r['selected'] < 0 ) |
| 700 |
$r['selected'] = 0; |
| 701 |
|
| 702 |
$r = bbp_exclude_forum_ids( $r ); |
| 703 |
|
| 704 |
extract( $r ); |
| 705 |
|
| 706 |
// Unset the args not needed for WP_Query to avoid any possible conflicts. |
| 707 |
// Note: walker and disable_categories are not unset |
| 708 |
unset( $r['select_id'], $r['tab'], $r['options_only'], $r['show_none'], $r['none_found'] ); |
| 709 |
|
| 710 |
// Setup variables |
| 711 |
$name = esc_attr( $select_id ); |
| 712 |
$select_id = $name; |
| 713 |
$tab = (int) $tab; |
| 714 |
$retval = ''; |
| 715 |
$posts = get_posts( $r ); |
| 716 |
|
| 717 |
// Make a drop down if we found posts |
| 718 |
if ( !empty( $posts ) ) { |
| 719 |
if ( empty( $options_only ) ) { |
| 720 |
$tab = !empty( $tab ) ? ' tabindex="' . $tab . '"' : ''; |
| 721 |
$retval .= '<select name="' . $name . '" id="' . $select_id . '"' . $tab . '>' . "\n"; |
| 722 |
} |
| 723 |
|
| 724 |
$retval .= !empty( $show_none ) ? "\t<option value=\"\" class=\"level-0\">" . $show_none . '</option>' : ''; |
| 725 |
$retval .= walk_page_dropdown_tree( $posts, 0, $r ); |
| 726 |
|
| 727 |
if ( empty( $options_only ) ) |
| 728 |
$retval .= '</select>'; |
| 729 |
|
| 730 |
// Display feedback if no custom message was passed |
| 731 |
} elseif ( empty( $none_found ) ) { |
| 732 |
|
| 733 |
// Switch the response based on post type |
| 734 |
switch ( $post_type ) { |
| 735 |
|
| 736 |
// Topics |
| 737 |
case bbp_get_topic_post_type() : |
| 738 |
$retval = __( 'No topics available', 'bbpress' ); |
| 739 |
break; |
| 740 |
|
| 741 |
// Forums |
| 742 |
case bbp_get_forum_post_type() : |
| 743 |
$retval = __( 'No forums available', 'bbpress' ); |
| 744 |
break; |
| 745 |
|
| 746 |
// Any other |
| 747 |
default : |
| 748 |
$retval = __( 'None available', 'bbpress' ); |
| 749 |
break; |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
return apply_filters( 'bbp_get_dropdown', $retval, $args ); |
| 754 |
} |
| 755 |
|
| 756 |
/** |
| 757 |
* Output the required hidden fields when creating/editing a topic |
| 758 |
* |
| 759 |
* @since bbPress (r2753) |
| 760 |
* |
| 761 |
* @uses bbp_is_topic_edit() To check if it's the topic edit page |
| 762 |
* @uses wp_nonce_field() To generate hidden nonce fields |
| 763 |
* @uses bbp_topic_id() To output the topic id |
| 764 |
* @uses bbp_is_forum() To check if it's a forum page |
| 765 |
* @uses bbp_forum_id() To output the forum id |
| 766 |
*/ |
| 767 |
function bbp_topic_form_fields() { |
| 768 |
|
| 769 |
if ( bbp_is_topic_edit() ) : ?> |
| 770 |
|
| 771 |
<input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-topic" /> |
| 772 |
<input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" /> |
| 773 |
|
| 774 |
<?php |
| 775 |
|
| 776 |
if ( current_user_can( 'unfiltered_html' ) ) |
| 777 |
wp_nonce_field( 'bbp-unfiltered-html-topic_' . bbp_get_topic_id(), '_bbp_unfiltered_html_topic', false ); |
| 778 |
|
| 779 |
?> |
| 780 |
|
| 781 |
<?php wp_nonce_field( 'bbp-edit-topic_' . bbp_get_topic_id() ); |
| 782 |
|
| 783 |
else : |
| 784 |
|
| 785 |
if ( bbp_is_forum() ) : ?> |
| 786 |
|
| 787 |
<input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" /> |
| 788 |
|
| 789 |
<?php endif; ?> |
| 790 |
|
| 791 |
<input type="hidden" name="action" id="bbp_post_action" value="bbp-new-topic" /> |
| 792 |
|
| 793 |
<?php |
| 794 |
|
| 795 |
if ( current_user_can( 'unfiltered_html' ) ) |
| 796 |
wp_nonce_field( 'bbp-unfiltered-html-topic_new', '_bbp_unfiltered_html_topic', false ); |
| 797 |
|
| 798 |
?> |
| 799 |
|
| 800 |
<?php wp_nonce_field( 'bbp-new-topic' ); |
| 801 |
|
| 802 |
endif; |
| 803 |
} |
| 804 |
|
| 805 |
/** |
| 806 |
* Output the required hidden fields when creating/editing a reply |
| 807 |
* |
| 808 |
* @since bbPress (r2753) |
| 809 |
* |
| 810 |
* @uses bbp_is_reply_edit() To check if it's the reply edit page |
| 811 |
* @uses wp_nonce_field() To generate hidden nonce fields |
| 812 |
* @uses bbp_reply_id() To output the reply id |
| 813 |
* @uses bbp_topic_id() To output the topic id |
| 814 |
* @uses bbp_forum_id() To output the forum id |
| 815 |
*/ |
| 816 |
function bbp_reply_form_fields() { |
| 817 |
|
| 818 |
if ( bbp_is_reply_edit() ) { ?> |
| 819 |
|
| 820 |
<input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?>" /> |
| 821 |
<input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php bbp_reply_id(); ?>" /> |
| 822 |
<input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-reply" /> |
| 823 |
|
| 824 |
<?php |
| 825 |
|
| 826 |
if ( current_user_can( 'unfiltered_html' ) ) |
| 827 |
wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_reply_id(), '_bbp_unfiltered_html_reply', false ); |
| 828 |
|
| 829 |
?> |
| 830 |
|
| 831 |
<?php wp_nonce_field( 'bbp-edit-reply_' . bbp_get_reply_id() ); |
| 832 |
|
| 833 |
} else { |
| 834 |
|
| 835 |
?> |
| 836 |
|
| 837 |
<input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?>" /> |
| 838 |
<input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" /> |
| 839 |
<input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" /> |
| 840 |
<input type="hidden" name="action" id="bbp_post_action" value="bbp-new-reply" /> |
| 841 |
|
| 842 |
<?php |
| 843 |
|
| 844 |
if ( current_user_can( 'unfiltered_html' ) ) |
| 845 |
wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_topic_id(), '_bbp_unfiltered_html_reply', false ); |
| 846 |
|
| 847 |
?> |
| 848 |
|
| 849 |
<?php wp_nonce_field( 'bbp-new-reply' ); |
| 850 |
} |
| 851 |
} |
| 852 |
|
| 853 |
/** |
| 854 |
* Output the required hidden fields when editing a user |
| 855 |
* |
| 856 |
* @since bbPress (r2690) |
| 857 |
* |
| 858 |
* @uses bbp_displayed_user_id() To output the displayed user id |
| 859 |
* @uses wp_nonce_field() To generate a hidden nonce field |
| 860 |
* @uses wp_referer_field() To generate a hidden referer field |
| 861 |
*/ |
| 862 |
function bbp_edit_user_form_fields() { |
| 863 |
?> |
| 864 |
|
| 865 |
<input type="hidden" name="action" id="bbp_post_action" value="bbp-update-user" /> |
| 866 |
<input type="hidden" name="user_id" id="user_id" value="<?php bbp_displayed_user_id(); ?>" /> |
| 867 |
|
| 868 |
<?php wp_nonce_field( 'update-user_' . bbp_get_displayed_user_id() ); |
| 869 |
} |
| 870 |
|
| 871 |
/** |
| 872 |
* Merge topic form fields |
| 873 |
* |
| 874 |
* Output the required hidden fields when merging a topic |
| 875 |
* |
| 876 |
* @since bbPress (r2756) |
| 877 |
* |
| 878 |
* @uses wp_nonce_field() To generate a hidden nonce field |
| 879 |
* @uses bbp_topic_id() To output the topic id |
| 880 |
*/ |
| 881 |
function bbp_merge_topic_form_fields() { |
| 882 |
?> |
| 883 |
|
| 884 |
<input type="hidden" name="action" id="bbp_post_action" value="bbp-merge-topic" /> |
| 885 |
<input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" /> |
| 886 |
|
| 887 |
<?php wp_nonce_field( 'bbp-merge-topic_' . bbp_get_topic_id() ); |
| 888 |
} |
| 889 |
|
| 890 |
/** |
| 891 |
* Split topic form fields |
| 892 |
* |
| 893 |
* Output the required hidden fields when splitting a topic |
| 894 |
* |
| 895 |
* @since bbPress (r2756) |
| 896 |
* |
| 897 |
* @uses wp_nonce_field() To generete a hidden nonce field |
| 898 |
*/ |
| 899 |
function bbp_split_topic_form_fields() { |
| 900 |
?> |
| 901 |
|
| 902 |
<input type="hidden" name="action" id="bbp_post_action" value="bbp-split-topic" /> |
| 903 |
<input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo absint( $_GET['reply_id'] ); ?>" /> |
| 904 |
|
| 905 |
<?php wp_nonce_field( 'bbp-split-topic_' . bbp_get_topic_id() ); |
| 906 |
} |
| 907 |
|
| 908 |
/** Views *********************************************************************/ |
| 909 |
|
| 910 |
/** |
| 911 |
* Output the view id |
| 912 |
* |
| 913 |
* @since bbPress (r2789) |
| 914 |
* |
| 915 |
* @param string $view Optional. View id |
| 916 |
* @uses bbp_get_view_id() To get the view id |
| 917 |
*/ |
| 918 |
function bbp_view_id( $view = '' ) { |
| 919 |
echo bbp_get_view_id( $view ); |
| 920 |
} |
| 921 |
|
| 922 |
/** |
| 923 |
* Get the view id |
| 924 |
* |
| 925 |
* If a view id is supplied, that is used. Otherwise the 'bbp_view' |
| 926 |
* query var is checked for. |
| 927 |
* |
| 928 |
* @since bbPress (r2789) |
| 929 |
* |
| 930 |
* @param string $view Optional. View id. |
| 931 |
* @uses sanitize_title() To sanitize the view id |
| 932 |
* @uses get_query_var() To get the view id from query var 'bbp_view' |
| 933 |
* @return bool|string ID on success, false on failure |
| 934 |
*/ |
| 935 |
function bbp_get_view_id( $view = '' ) { |
| 936 |
global $bbp; |
| 937 |
|
| 938 |
$view = !empty( $view ) ? sanitize_title( $view ) : get_query_var( 'bbp_view' ); |
| 939 |
|
| 940 |
if ( array_key_exists( $view, $bbp->views ) ) |
| 941 |
return $view; |
| 942 |
|
| 943 |
return false; |
| 944 |
} |
| 945 |
|
| 946 |
/** |
| 947 |
* Output the view name aka title |
| 948 |
* |
| 949 |
* @since bbPress (r2789) |
| 950 |
* |
| 951 |
* @param string $view Optional. View id |
| 952 |
* @uses bbp_get_view_title() To get the view title |
| 953 |
*/ |
| 954 |
function bbp_view_title( $view = '' ) { |
| 955 |
echo bbp_get_view_title( $view ); |
| 956 |
} |
| 957 |
|
| 958 |
/** |
| 959 |
* Get the view name aka title |
| 960 |
* |
| 961 |
* If a view id is supplied, that is used. Otherwise the bbp_view |
| 962 |
* query var is checked for. |
| 963 |
* |
| 964 |
* @since bbPress (r2789) |
| 965 |
* |
| 966 |
* @param string $view Optional. View id |
| 967 |
* @uses bbp_get_view_id() To get the view id |
| 968 |
* @return bool|string Title on success, false on failure |
| 969 |
*/ |
| 970 |
function bbp_get_view_title( $view = '' ) { |
| 971 |
global $bbp; |
| 972 |
|
| 973 |
if ( !$view = bbp_get_view_id( $view ) ) |
| 974 |
return false; |
| 975 |
|
| 976 |
return $bbp->views[$view]['title']; |
| 977 |
} |
| 978 |
|
| 979 |
/** |
| 980 |
* Output the view url |
| 981 |
* |
| 982 |
* @since bbPress (r2789) |
| 983 |
* |
| 984 |
* @param string $view Optional. View id |
| 985 |
* @uses bbp_get_view_url() To get the view url |
| 986 |
*/ |
| 987 |
function bbp_view_url( $view = false ) { |
| 988 |
echo bbp_get_view_url( $view ); |
| 989 |
} |
| 990 |
/** |
| 991 |
* Return the view url |
| 992 |
* |
| 993 |
* @since bbPress (r2789) |
| 994 |
* |
| 995 |
* @param string $view Optional. View id |
| 996 |
* @uses sanitize_title() To sanitize the view id |
| 997 |
* @uses home_url() To get blog home url |
| 998 |
* @uses add_query_arg() To add custom args to the url |
| 999 |
* @uses apply_filters() Calls 'bbp_get_view_url' with the view url, |
| 1000 |
* used view id |
| 1001 |
* @return string View url (or home url if the view was not found) |
| 1002 |
*/ |
| 1003 |
function bbp_get_view_url( $view = false ) { |
| 1004 |
global $bbp, $wp_rewrite; |
| 1005 |
|
| 1006 |
if ( !$view = bbp_get_view_id( $view ) ) |
| 1007 |
return home_url(); |
| 1008 |
|
| 1009 |
// Pretty permalinks |
| 1010 |
if ( $wp_rewrite->using_permalinks() ) { |
| 1011 |
$url = $wp_rewrite->root . $bbp->view_slug . '/' . $view; |
| 1012 |
$url = home_url( user_trailingslashit( $url ) ); |
| 1013 |
|
| 1014 |
// Unpretty permalinks |
| 1015 |
} else { |
| 1016 |
$url = add_query_arg( array( 'bbp_view' => $view ), home_url( '/' ) ); |
| 1017 |
} |
| 1018 |
|
| 1019 |
return apply_filters( 'bbp_get_view_link', $url, $view ); |
| 1020 |
} |
| 1021 |
|
| 1022 |
/** Query *********************************************************************/ |
| 1023 |
|
| 1024 |
/** |
| 1025 |
* Check the passed parameter against the current _bbp_query_name |
| 1026 |
* |
| 1027 |
* @since bbPress (r2980) |
| 1028 |
* |
| 1029 |
* @uses bbp_get_query_name() Get the query var '_bbp_query_name' |
| 1030 |
* @return bool True if match, false if not |
| 1031 |
*/ |
| 1032 |
function bbp_is_query_name( $query_name ) { |
| 1033 |
|
| 1034 |
// No empties |
| 1035 |
if ( empty( $query_name ) ) |
| 1036 |
return false; |
| 1037 |
|
| 1038 |
// Check if query var matches |
| 1039 |
if ( bbp_get_query_name() == $query_name ) |
| 1040 |
return true; |
| 1041 |
|
| 1042 |
// No match |
| 1043 |
return false; |
| 1044 |
} |
| 1045 |
|
| 1046 |
/** |
| 1047 |
* Get the '_bbp_query_name' setting |
| 1048 |
* |
| 1049 |
* @since bbPress (r2695) |
| 1050 |
* |
| 1051 |
* @uses get_query_var() To get the query var '_bbp_query_name' |
| 1052 |
* @return string To return the query var value |
| 1053 |
*/ |
| 1054 |
function bbp_get_query_name() { |
| 1055 |
return get_query_var( '_bbp_query_name' ); |
| 1056 |
} |
| 1057 |
|
| 1058 |
/** |
| 1059 |
* Set the '_bbp_query_name' setting to $name |
| 1060 |
* |
| 1061 |
* @since bbPress (r2692) |
| 1062 |
* |
| 1063 |
* @param string $name What to set the query var to |
| 1064 |
* @uses set_query_var() To set the query var '_bbp_query_name' |
| 1065 |
*/ |
| 1066 |
function bbp_set_query_name( $name = '' ) { |
| 1067 |
set_query_var( '_bbp_query_name', $name ); |
| 1068 |
} |
| 1069 |
|
| 1070 |
/** |
| 1071 |
* Used to clear the '_bbp_query_name' setting |
| 1072 |
* |
| 1073 |
* @since bbPress (r2692) |
| 1074 |
* |
| 1075 |
* @uses bbp_set_query_name() To set the query var '_bbp_query_name' value to '' |
| 1076 |
*/ |
| 1077 |
function bbp_reset_query_name() { |
| 1078 |
bbp_set_query_name(); |
| 1079 |
} |
| 1080 |
|
| 1081 |
/** Breadcrumbs ***************************************************************/ |
| 1082 |
|
| 1083 |
/** |
| 1084 |
* Output the page title as a breadcrumb |
| 1085 |
* |
| 1086 |
* @since bbPress (r2589) |
| 1087 |
* |
| 1088 |
* @param string $sep Separator. Defaults to '←' |
| 1089 |
* @param bool $current_page Include the current item |
| 1090 |
* @param bool $root Include the root page if one exists |
| 1091 |
* @uses bbp_get_breadcrumb() To get the breadcrumb |
| 1092 |
*/ |
| 1093 |
function bbp_title_breadcrumb( $sep = ' › ' ) { |
| 1094 |
echo bbp_get_breadcrumb( $sep ); |
| 1095 |
} |
| 1096 |
|
| 1097 |
/** |
| 1098 |
* Output a breadcrumb |
| 1099 |
* |
| 1100 |
* @since bbPress (r2589) |
| 1101 |
* |
| 1102 |
* @param string $sep Separator. Defaults to '←' |
| 1103 |
* @param bool $current_page Include the current item |
| 1104 |
* @param bool $root Include the root page if one exists |
| 1105 |
* @uses bbp_get_breadcrumb() To get the breadcrumb |
| 1106 |
*/ |
| 1107 |
function bbp_breadcrumb( $sep = ' › ', $current_page = true, $root = true ) { |
| 1108 |
echo bbp_get_breadcrumb( $sep, $current_page, $root ); |
| 1109 |
} |
| 1110 |
/** |
| 1111 |
* Return a breadcrumb ( forum -> topic -> reply ) |
| 1112 |
* |
| 1113 |
* @since bbPress (r2589) |
| 1114 |
* |
| 1115 |
* @param string $sep Separator. Defaults to '←' |
| 1116 |
* @param bool $current_page Include the current item |
| 1117 |
* @param bool $root Include the root page if one exists |
| 1118 |
* |
| 1119 |
* @uses get_post() To get the post |
| 1120 |
* @uses bbp_get_forum_permalink() To get the forum link |
| 1121 |
* @uses bbp_get_topic_permalink() To get the topic link |
| 1122 |
* @uses bbp_get_reply_permalink() To get the reply link |
| 1123 |
* @uses get_permalink() To get the permalink |
| 1124 |
* @uses bbp_get_forum_post_type() To get the forum post type |
| 1125 |
* @uses bbp_get_topic_post_type() To get the topic post type |
| 1126 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 1127 |
* @uses bbp_get_forum_title() To get the forum title |
| 1128 |
* @uses bbp_get_topic_title() To get the topic title |
| 1129 |
* @uses bbp_get_reply_title() To get the reply title |
| 1130 |
* @uses get_the_title() To get the title |
| 1131 |
* @uses apply_filters() Calls 'bbp_get_breadcrumb' with the crumbs |
| 1132 |
* @return string Breadcrumbs |
| 1133 |
*/ |
| 1134 |
function bbp_get_breadcrumb( $sep = ' › ', $current_page = true, $root = true ) { |
| 1135 |
global $post, $bbp; |
| 1136 |
|
| 1137 |
// No post, no breadcrumb |
| 1138 |
if ( empty( $post ) ) |
| 1139 |
return; |
| 1140 |
|
| 1141 |
// Get post ancestors |
| 1142 |
$ancestors = array_reverse( get_post_ancestors( $post->ID ) ); |
| 1143 |
|
| 1144 |
// Do we want to include the forum root? |
| 1145 |
if ( !empty( $root ) && ( get_option( '_bbp_include_root' ) ) && ( $root_slug = get_option( '_bbp_root_slug' ) ) ) { |
| 1146 |
|
| 1147 |
// Page exists at the root slug location, so add it to the breadcrumb |
| 1148 |
if ( $page = get_page_by_path( $root_slug ) ) |
| 1149 |
$title = get_the_title( $page->ID ); |
| 1150 |
|
| 1151 |
// Use generic root title |
| 1152 |
else |
| 1153 |
$title = __( 'Forums', 'bbpress' ); |
| 1154 |
|
| 1155 |
// Add root slug |
| 1156 |
$breadcrumbs[] = '<a href="' . trailingslashit( home_url( $root_slug ) ) . '">' . $title . '</a>'; |
| 1157 |
} |
| 1158 |
|
| 1159 |
// Loop through parents |
| 1160 |
foreach( $ancestors as $parent_id ) { |
| 1161 |
|
| 1162 |
// Parents |
| 1163 |
$parent = get_post( $parent_id ); |
| 1164 |
|
| 1165 |
// Switch through post_type to ensure correct filters are applied |
| 1166 |
switch ( $parent->post_type ) { |
| 1167 |
// Forum |
| 1168 |
case bbp_get_forum_post_type() : |
| 1169 |
$breadcrumbs[] = '<a href="' . bbp_get_forum_permalink( $parent->ID ) . '">' . bbp_get_forum_title( $parent->ID ) . '</a>'; |
| 1170 |
break; |
| 1171 |
|
| 1172 |
// Topic |
| 1173 |
case bbp_get_topic_post_type() : |
| 1174 |
$breadcrumbs[] = '<a href="' . bbp_get_topic_permalink( $parent->ID ) . '">' . bbp_get_topic_title( $parent->ID ) . '</a>'; |
| 1175 |
break; |
| 1176 |
|
| 1177 |
// Reply (Note: not in most themes) |
| 1178 |
case bbp_get_reply_post_type() : |
| 1179 |
$breadcrumbs[] = '<a href="' . bbp_get_reply_permalink( $parent->ID ) . '">' . bbp_get_reply_title( $parent->ID ) . '</a>'; |
| 1180 |
break; |
| 1181 |
|
| 1182 |
// WordPress Post/Page/Other |
| 1183 |
default : |
| 1184 |
$breadcrumbs[] = '<a href="' . get_permalink( $parent->ID ) . '">' . get_the_title( $parent->ID ) . '</a>'; |
| 1185 |
break; |
| 1186 |
} |
| 1187 |
} |
| 1188 |
|
| 1189 |
// Add current page to breadcrumb |
| 1190 |
if ( true == $current_page ) |
| 1191 |
$breadcrumbs[] = get_the_title(); |
| 1192 |
|
| 1193 |
// Allow the separator of the breadcrumb to be easily changed |
| 1194 |
$sep = apply_filters( 'bbp_breadcrumb_separator', $sep ); |
| 1195 |
|
| 1196 |
// Build the trail |
| 1197 |
$trail = !empty( $breadcrumbs ) ? implode( $sep, $breadcrumbs ) : ''; |
| 1198 |
|
| 1199 |
return apply_filters( 'bbp_get_breadcrumb', $trail ); |
| 1200 |
} |
| 1201 |
|
| 1202 |
/** Topic Tags ***************************************************************/ |
| 1203 |
|
| 1204 |
/** |
| 1205 |
* Output all of the allowed tags in HTML format with attributes. |
| 1206 |
* |
| 1207 |
* This is useful for displaying in the post area, which elements and |
| 1208 |
* attributes are supported. As well as any plugins which want to display it. |
| 1209 |
* |
| 1210 |
* @since bbPress (r2780) |
| 1211 |
* |
| 1212 |
* @uses bbp_get_allowed_tags() |
| 1213 |
*/ |
| 1214 |
function bbp_allowed_tags() { |
| 1215 |
echo bbp_get_allowed_tags(); |
| 1216 |
} |
| 1217 |
/** |
| 1218 |
* Display all of the allowed tags in HTML format with attributes. |
| 1219 |
* |
| 1220 |
* This is useful for displaying in the post area, which elements and |
| 1221 |
* attributes are supported. As well as any plugins which want to display it. |
| 1222 |
* |
| 1223 |
* @since bbPress (r2780) |
| 1224 |
* |
| 1225 |
* @uses allowed_tags() To get the allowed tags |
| 1226 |
* @uses apply_filters() Calls 'bbp_allowed_tags' with the tags |
| 1227 |
* @return string HTML allowed tags entity encoded. |
| 1228 |
*/ |
| 1229 |
function bbp_get_allowed_tags() { |
| 1230 |
return apply_filters( 'bbp_get_allowed_tags', allowed_tags() ); |
| 1231 |
} |
| 1232 |
|
| 1233 |
/** Errors & Messages *********************************************************/ |
| 1234 |
|
| 1235 |
/** |
| 1236 |
* Display possible errors & messages inside a template file |
| 1237 |
* |
| 1238 |
* @since bbPress (r2688) |
| 1239 |
* |
| 1240 |
* @uses WP_Error bbPress::errors::get_error_codes() To get the error codes |
| 1241 |
* @uses WP_Error bbPress::errors::get_error_data() To get the error data |
| 1242 |
* @uses WP_Error bbPress::errors::get_error_messages() To get the error |
| 1243 |
* messages |
| 1244 |
* @uses is_wp_error() To check if it's a {@link WP_Error} |
| 1245 |
*/ |
| 1246 |
function bbp_template_notices() { |
| 1247 |
global $bbp; |
| 1248 |
|
| 1249 |
// Bail if no notices or errors |
| 1250 |
if ( !isset( $bbp->errors ) || !is_wp_error( $bbp->errors ) || !$bbp->errors->get_error_codes() ) |
| 1251 |
return; |
| 1252 |
|
| 1253 |
// Prevent debug notices |
| 1254 |
$errors = $messages = array(); |
| 1255 |
|
| 1256 |
// Loop through notices |
| 1257 |
foreach ( $bbp->errors->get_error_codes() as $code ) { |
| 1258 |
|
| 1259 |
// Get notice severity |
| 1260 |
$severity = $bbp->errors->get_error_data( $code ); |
| 1261 |
|
| 1262 |
// Loop through notices and separate errors from messages |
| 1263 |
foreach ( $bbp->errors->get_error_messages( $code ) as $error ) { |
| 1264 |
if ( 'message' == $severity ) { |
| 1265 |
$messages[] = $error; |
| 1266 |
} else { |
| 1267 |
$errors[] = $error; |
| 1268 |
} |
| 1269 |
} |
| 1270 |
} |
| 1271 |
|
| 1272 |
// Display errors first... |
| 1273 |
if ( !empty( $errors ) ) : ?> |
| 1274 |
|
| 1275 |
<div class="bbp-template-notice error"> |
| 1276 |
<p> |
| 1277 |
<?php echo implode( "</p>\n<p>", $errors ); ?> |
| 1278 |
</p> |
| 1279 |
</div> |
| 1280 |
|
| 1281 |
<?php endif; |
| 1282 |
|
| 1283 |
// ...and messages last |
| 1284 |
if ( !empty( $messages ) ) : ?> |
| 1285 |
|
| 1286 |
<div class="bbp-template-notice"> |
| 1287 |
<p> |
| 1288 |
<?php echo implode( "</p>\n<p>", $messages ); ?> |
| 1289 |
</p> |
| 1290 |
</div> |
| 1291 |
|
| 1292 |
<?php endif; |
| 1293 |
} |
| 1294 |
|
| 1295 |
/** Login/logout/register/lost pass *******************************************/ |
| 1296 |
|
| 1297 |
/** |
| 1298 |
* Output the logout link |
| 1299 |
* |
| 1300 |
* @since bbPress (r2827) |
| 1301 |
* |
| 1302 |
* @param string $redirect_to Redirect to url |
| 1303 |
* @uses bbp_get_logout_link() To get the logout link |
| 1304 |
*/ |
| 1305 |
function bbp_logout_link( $redirect_to = '' ) { |
| 1306 |
echo bbp_get_logout_link( $redirect_to ); |
| 1307 |
} |
| 1308 |
/** |
| 1309 |
* Return the logout link |
| 1310 |
* |
| 1311 |
* @since bbPress (r2827) |
| 1312 |
* |
| 1313 |
* @param string $redirect_to Redirect to url |
| 1314 |
* @uses wp_logout_url() To get the logout url |
| 1315 |
* @uses apply_filters() Calls 'bbp_get_logout_link' with the logout link and |
| 1316 |
* redirect to url |
| 1317 |
* @return string The logout link |
| 1318 |
*/ |
| 1319 |
function bbp_get_logout_link( $redirect_to = '' ) { |
| 1320 |
return apply_filters( 'bbp_get_logout_link', '<a href="' . wp_logout_url( $redirect_to ) . '" class="button logout-link">' . __( 'Log Out', 'bbpress' ) . '</a>', $redirect_to ); |
| 1321 |
} |
| 1322 |
|
| 1323 |
/** Title *********************************************************************/ |
| 1324 |
|
| 1325 |
/** |
| 1326 |
* Custom page title for bbPress pages |
| 1327 |
* |
| 1328 |
* @since bbPress (r2788) |
| 1329 |
* |
| 1330 |
* @param string $title Optional. The title (not used). |
| 1331 |
* @param string $sep Optional, default is '»'. How to separate the |
| 1332 |
* various items within the page title. |
| 1333 |
* @param string $seplocation Optional. Direction to display title, 'right'. |
| 1334 |
* @uses bbp_is_user_profile_page() To check if it's a user profile page |
| 1335 |
* @uses bbp_is_user_profile_edit() To check if it's a user profile edit page |
| 1336 |
* @uses bbp_is_user_home() To check if the profile page is of the current user |
| 1337 |
* @uses get_query_var() To get the user id |
| 1338 |
* @uses get_userdata() To get the user data |
| 1339 |
* @uses bbp_is_forum() To check if it's a forum |
| 1340 |
* @uses bbp_get_forum_title() To get the forum title |
| 1341 |
* @uses bbp_is_topic() To check if it's a topic |
| 1342 |
* @uses bbp_get_topic_title() To get the topic title |
| 1343 |
* @uses bbp_is_reply() To check if it's a reply |
| 1344 |
* @uses bbp_get_reply_title() To get the reply title |
| 1345 |
* @uses is_tax() To check if it's the tag page |
| 1346 |
* @uses get_queried_object() To get the queried object |
| 1347 |
* @uses bbp_is_view() To check if it's a view |
| 1348 |
* @uses bbp_get_view_title() To get the view title |
| 1349 |
* @uses apply_filters() Calls 'bbp_raw_title' with the title |
| 1350 |
* @uses apply_filters() Calls 'bbp_profile_page_wp_title' with the title, |
| 1351 |
* separator and separator location |
| 1352 |
* @return string The tite |
| 1353 |
*/ |
| 1354 |
function bbp_title( $title = '', $sep = '»', $seplocation = '' ) { |
| 1355 |
global $bbp; |
| 1356 |
|
| 1357 |
$_title = $title; |
| 1358 |
|
| 1359 |
// Profile page |
| 1360 |
if ( bbp_is_user_profile_page() ) { |
| 1361 |
|
| 1362 |
if ( bbp_is_user_home() ) { |
| 1363 |
$title = __( 'Your Profile', 'bbpress' ); |
| 1364 |
} else { |
| 1365 |
$userdata = get_userdata( get_query_var( 'bbp_user_id' ) ); |
| 1366 |
$title = sprintf( __( '%s\'s Profile', 'bbpress' ), $userdata->display_name ); |
| 1367 |
} |
| 1368 |
|
| 1369 |
// Profile edit page |
| 1370 |
} elseif ( bbp_is_user_profile_edit() ) { |
| 1371 |
|
| 1372 |
if ( bbp_is_user_home() ) { |
| 1373 |
$title = __( 'Edit Your Profile', 'bbpress' ); |
| 1374 |
} else { |
| 1375 |
$userdata = get_userdata( get_query_var( 'bbp_user_id' ) ); |
| 1376 |
$title = sprintf( __( 'Edit %s\'s Profile', 'bbpress' ), $userdata->display_name ); |
| 1377 |
} |
| 1378 |
|
| 1379 |
// Forum page |
| 1380 |
} elseif ( bbp_is_forum() ) { |
| 1381 |
|
| 1382 |
$title = sprintf( __( 'Forum: %s', 'bbpress' ), bbp_get_forum_title() ); |
| 1383 |
|
| 1384 |
// Topic page |
| 1385 |
} elseif ( bbp_is_topic() ) { |
| 1386 |
|
| 1387 |
$title = sprintf( __( 'Topic: %s', 'bbpress' ), bbp_get_topic_title() ); |
| 1388 |
|
| 1389 |
// Replies |
| 1390 |
} elseif ( bbp_is_reply() ) { |
| 1391 |
|
| 1392 |
// Normal reply titles already have "Reply To: ", so we shouldn't add our own |
| 1393 |
$title = bbp_get_reply_title(); |
| 1394 |
|
| 1395 |
// Topic tag page |
| 1396 |
} elseif ( is_tax( $bbp->topic_tag_id ) ) { |
| 1397 |
|
| 1398 |
if ( function_exists( 'get_queried_object' ) ) { |
| 1399 |
$term = get_queried_object(); |
| 1400 |
$title = sprintf( __( 'Topic Tag: %s', 'bbpress' ), $term->name ); |
| 1401 |
} |
| 1402 |
|
| 1403 |
// Views |
| 1404 |
} elseif ( bbp_is_view() ) { |
| 1405 |
|
| 1406 |
$title = sprintf( __( 'View: %s', 'bbpress' ), bbp_get_view_title() ); |
| 1407 |
|
| 1408 |
} |
| 1409 |
|
| 1410 |
$title = apply_filters( 'bbp_raw_title', $title, $sep, $seplocation ); |
| 1411 |
|
| 1412 |
if ( $title == $_title ) |
| 1413 |
return $title; |
| 1414 |
|
| 1415 |
// Temporary separator, for accurate flipping, if necessary |
| 1416 |
$t_sep = '%WP_TITILE_SEP%'; |
| 1417 |
$prefix = ''; |
| 1418 |
|
| 1419 |
if ( !empty( $title ) ) |
| 1420 |
$prefix = " $sep "; |
| 1421 |
|
| 1422 |
// Determines position of the separator and direction of the breadcrumb |
| 1423 |
if ( 'right' == $seplocation ) { // sep on right, so reverse the order |
| 1424 |
$title_array = explode( $t_sep, $title ); |
| 1425 |
$title_array = array_reverse( $title_array ); |
| 1426 |
$title = implode( " $sep ", $title_array ) . $prefix; |
| 1427 |
} else { |
| 1428 |
$title_array = explode( $t_sep, $title ); |
| 1429 |
$title = $prefix . implode( " $sep ", $title_array ); |
| 1430 |
} |
| 1431 |
|
| 1432 |
// Filter and return |
| 1433 |
return apply_filters( 'bbp_title', $title, $sep, $seplocation ); |
| 1434 |
} |
| 1435 |
|
| 1436 |
?> |
| 1437 |
|