| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* bbPress Reply Template Tags |
| 5 |
* |
| 6 |
* @package bbPress |
| 7 |
* @subpackage TemplateTags |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly |
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
|
| 13 |
/** Post Type *****************************************************************/ |
| 14 |
|
| 15 |
/** |
| 16 |
* Return the unique id of the custom post type for replies |
| 17 |
* |
| 18 |
* @since 2.0.0 bbPress (r2857) |
| 19 |
* |
| 20 |
*/ |
| 21 |
function bbp_reply_post_type() { |
| 22 |
echo bbp_get_reply_post_type(); |
| 23 |
} |
| 24 |
/** |
| 25 |
* Return the unique id of the custom post type for replies |
| 26 |
* |
| 27 |
* @since 2.0.0 bbPress (r2857) |
| 28 |
* |
| 29 |
* post type id |
| 30 |
* @return string The unique reply post type id |
| 31 |
*/ |
| 32 |
function bbp_get_reply_post_type() { |
| 33 |
|
| 34 |
// Filter & return |
| 35 |
return apply_filters( 'bbp_get_reply_post_type', bbpress()->reply_post_type ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Return array of labels used by the reply post type |
| 40 |
* |
| 41 |
* @since 2.5.0 bbPress (r5129) |
| 42 |
* |
| 43 |
* @return array |
| 44 |
*/ |
| 45 |
function bbp_get_reply_post_type_labels() { |
| 46 |
|
| 47 |
// Filter & return |
| 48 |
return (array) apply_filters( 'bbp_get_reply_post_type_labels', array( |
| 49 |
'name' => esc_attr__( 'Replies', 'bbpress' ), |
| 50 |
'menu_name' => esc_attr__( 'Replies', 'bbpress' ), |
| 51 |
'singular_name' => esc_attr_x( 'Reply', 'noun', 'bbpress' ), |
| 52 |
'all_items' => esc_attr__( 'All Replies', 'bbpress' ), |
| 53 |
'add_new' => esc_attr__( 'Add New', 'bbpress' ), |
| 54 |
'add_new_item' => esc_attr__( 'Create New Reply', 'bbpress' ), |
| 55 |
'edit' => esc_attr__( 'Edit', 'bbpress' ), |
| 56 |
'edit_item' => esc_attr__( 'Edit Reply', 'bbpress' ), |
| 57 |
'new_item' => esc_attr__( 'New Reply', 'bbpress' ), |
| 58 |
'view' => esc_attr__( 'View Reply', 'bbpress' ), |
| 59 |
'view_item' => esc_attr__( 'View Reply', 'bbpress' ), |
| 60 |
'view_items' => esc_attr__( 'View Replies', 'bbpress' ), |
| 61 |
'search_items' => esc_attr__( 'Search Replies', 'bbpress' ), |
| 62 |
'not_found' => esc_attr__( 'No replies found', 'bbpress' ), |
| 63 |
'not_found_in_trash' => esc_attr__( 'No replies found in Trash', 'bbpress' ), |
| 64 |
'filter_items_list' => esc_attr__( 'Filter replies list', 'bbpress' ), |
| 65 |
'items_list' => esc_attr__( 'Replies list', 'bbpress' ), |
| 66 |
'items_list_navigation' => esc_attr__( 'Replies list navigation', 'bbpress' ), |
| 67 |
'parent_item_colon' => esc_attr__( 'Parent Topic:', 'bbpress' ), |
| 68 |
'archives' => esc_attr__( 'Forum Replies', 'bbpress' ), |
| 69 |
'attributes' => esc_attr__( 'Reply Attributes', 'bbpress' ), |
| 70 |
'insert_into_item' => esc_attr__( 'Insert into reply', 'bbpress' ), |
| 71 |
'uploaded_to_this_item' => esc_attr__( 'Uploaded to this reply', 'bbpress' ), |
| 72 |
'featured_image' => esc_attr__( 'Reply Image', 'bbpress' ), |
| 73 |
'set_featured_image' => esc_attr__( 'Set reply image', 'bbpress' ), |
| 74 |
'remove_featured_image' => esc_attr__( 'Remove reply image', 'bbpress' ), |
| 75 |
'use_featured_image' => esc_attr__( 'Use as reply image', 'bbpress' ), |
| 76 |
'item_published' => esc_attr__( 'Reply published.', 'bbpress' ), |
| 77 |
'item_published_privately' => esc_attr__( 'Reply published privately.', 'bbpress' ), |
| 78 |
'item_reverted_to_draft' => esc_attr__( 'Reply reverted to draft.', 'bbpress' ), |
| 79 |
'item_scheduled' => esc_attr__( 'Reply scheduled.', 'bbpress' ), |
| 80 |
'item_updated' => esc_attr__( 'Reply updated.', 'bbpress' ) |
| 81 |
) ); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Return array of reply post type rewrite settings |
| 86 |
* |
| 87 |
* @since 2.5.0 bbPress (r5129) |
| 88 |
* |
| 89 |
* @return array |
| 90 |
*/ |
| 91 |
function bbp_get_reply_post_type_rewrite() { |
| 92 |
|
| 93 |
// Filter & return |
| 94 |
return (array) apply_filters( 'bbp_get_reply_post_type_rewrite', array( |
| 95 |
'slug' => bbp_get_reply_slug(), |
| 96 |
'with_front' => false |
| 97 |
) ); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Return array of features the reply post type supports |
| 102 |
* |
| 103 |
* @since 2.5.0 bbPress (r5129) |
| 104 |
* |
| 105 |
* @return array |
| 106 |
*/ |
| 107 |
function bbp_get_reply_post_type_supports() { |
| 108 |
|
| 109 |
// Filter & return |
| 110 |
return (array) apply_filters( 'bbp_get_reply_post_type_supports', array( |
| 111 |
'title', |
| 112 |
'editor', |
| 113 |
'revisions' |
| 114 |
) ); |
| 115 |
} |
| 116 |
|
| 117 |
/** Reply Loop Functions ******************************************************/ |
| 118 |
|
| 119 |
/** |
| 120 |
* The main reply loop. WordPress makes this easy for us |
| 121 |
* |
| 122 |
* @since 2.0.0 bbPress (r2553) |
| 123 |
* |
| 124 |
* @param array $args All the arguments supported by {@link WP_Query} |
| 125 |
* @return object Multidimensional array of reply information |
| 126 |
*/ |
| 127 |
function bbp_has_replies( $args = array() ) { |
| 128 |
|
| 129 |
/** Defaults **************************************************************/ |
| 130 |
|
| 131 |
// Other defaults |
| 132 |
$default_reply_search = bbp_sanitize_search_request( 'rs' ); |
| 133 |
$default_post_parent = ( bbp_is_single_topic() ) ? bbp_get_topic_id() : 'any'; |
| 134 |
$default_post_type = ( bbp_is_single_topic() && bbp_show_lead_topic() ) ? bbp_get_reply_post_type() : array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ); |
| 135 |
$default_thread_replies = (bool) ( bbp_is_single_topic() && bbp_thread_replies() ); |
| 136 |
|
| 137 |
// Default query args |
| 138 |
$default = array( |
| 139 |
'post_type' => $default_post_type, // Only replies |
| 140 |
'post_parent' => $default_post_parent, // Of this topic |
| 141 |
'posts_per_page' => bbp_get_replies_per_page(), // This many |
| 142 |
'paged' => bbp_get_paged(), // On this page |
| 143 |
'orderby' => 'date', // Sorted by date |
| 144 |
'order' => 'ASC', // Oldest to newest |
| 145 |
'hierarchical' => $default_thread_replies, // Hierarchical replies |
| 146 |
'ignore_sticky_posts' => true, // Stickies not supported |
| 147 |
'update_post_term_cache' => false, // No terms to cache |
| 148 |
|
| 149 |
// Conditionally prime the cache for all related posts |
| 150 |
'update_post_family_cache' => true |
| 151 |
); |
| 152 |
|
| 153 |
// Only add 's' arg if searching for replies |
| 154 |
// See https://bbpress.trac.wordpress.org/ticket/2607 |
| 155 |
if ( ! empty( $default_reply_search ) ) { |
| 156 |
$default['s'] = $default_reply_search; |
| 157 |
} |
| 158 |
|
| 159 |
// What are the default allowed statuses (based on user caps) |
| 160 |
if ( bbp_get_view_all( 'edit_others_replies' ) ) { |
| 161 |
|
| 162 |
// Default view=all statuses |
| 163 |
$post_statuses = array_keys( bbp_get_topic_statuses() ); |
| 164 |
|
| 165 |
// Add support for private status |
| 166 |
if ( current_user_can( 'read_private_replies' ) ) { |
| 167 |
$post_statuses[] = bbp_get_private_status_id(); |
| 168 |
} |
| 169 |
|
| 170 |
// Join post statuses together |
| 171 |
$default['post_status'] = $post_statuses; |
| 172 |
|
| 173 |
// Lean on the 'perm' query var value of 'readable' to provide statuses |
| 174 |
} else { |
| 175 |
$default['perm'] = 'readable'; |
| 176 |
} |
| 177 |
|
| 178 |
/** Setup *****************************************************************/ |
| 179 |
|
| 180 |
// Parse arguments against default values |
| 181 |
$r = bbp_parse_args( $args, $default, 'has_replies' ); |
| 182 |
|
| 183 |
// Set posts_per_page value if replies are threaded |
| 184 |
$replies_per_page = (int) $r['posts_per_page']; |
| 185 |
if ( true === $r['hierarchical'] ) { |
| 186 |
$r['posts_per_page'] = -1; |
| 187 |
} |
| 188 |
|
| 189 |
// Get bbPress |
| 190 |
$bbp = bbpress(); |
| 191 |
|
| 192 |
// Call the query |
| 193 |
$bbp->reply_query = new WP_Query( $r ); |
| 194 |
|
| 195 |
// Maybe prime the post author caches |
| 196 |
if ( ! empty( $r['update_post_family_cache'] ) ) { |
| 197 |
bbp_update_post_family_caches( $bbp->reply_query->posts ); |
| 198 |
} |
| 199 |
|
| 200 |
// Add pagination values to query object |
| 201 |
$bbp->reply_query->posts_per_page = (int) $replies_per_page; |
| 202 |
$bbp->reply_query->paged = (int) $r['paged']; |
| 203 |
|
| 204 |
// Never home, regardless of what parse_query says |
| 205 |
$bbp->reply_query->is_home = false; |
| 206 |
|
| 207 |
// Reset is_single if single topic |
| 208 |
if ( bbp_is_single_topic() ) { |
| 209 |
$bbp->reply_query->is_single = true; |
| 210 |
} |
| 211 |
|
| 212 |
// Only add reply to if query returned results |
| 213 |
if ( ! empty( $bbp->reply_query->found_posts ) ) { |
| 214 |
|
| 215 |
// Get reply to for each reply |
| 216 |
foreach ( $bbp->reply_query->posts as &$post ) { |
| 217 |
|
| 218 |
// Check for reply post type |
| 219 |
if ( bbp_get_reply_post_type() === $post->post_type ) { |
| 220 |
$reply_to = bbp_get_reply_to( $post->ID ); |
| 221 |
|
| 222 |
// Make sure it's a reply to a reply |
| 223 |
if ( empty( $reply_to ) || ( bbp_get_reply_topic_id( $post->ID ) === $reply_to ) ) { |
| 224 |
$reply_to = 0; |
| 225 |
} |
| 226 |
|
| 227 |
// Add reply_to to the post object so we can walk it later |
| 228 |
$post->reply_to = $reply_to; |
| 229 |
} |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
// Only add pagination if query returned results |
| 234 |
if ( ! empty( $bbp->reply_query->found_posts ) && ! empty( $bbp->reply_query->posts_per_page ) ) { |
| 235 |
|
| 236 |
// Figure out total pages |
| 237 |
if ( true === $r['hierarchical'] ) { |
| 238 |
$walker = new BBP_Walker_Reply(); |
| 239 |
$total_pages = ceil( $walker->get_number_of_root_elements( $bbp->reply_query->posts ) / $bbp->reply_query->posts_per_page ); |
| 240 |
} else { |
| 241 |
|
| 242 |
// Total for pagination boundaries |
| 243 |
$total_pages = ( $bbp->reply_query->posts_per_page === $bbp->reply_query->found_posts ) |
| 244 |
? 1 |
| 245 |
: ceil( $bbp->reply_query->found_posts / $bbp->reply_query->posts_per_page ); |
| 246 |
|
| 247 |
// Pagination settings with filter |
| 248 |
$bbp_replies_pagination = apply_filters( 'bbp_replies_pagination', array( |
| 249 |
'base' => bbp_get_replies_pagination_base( bbp_get_topic_id() ), |
| 250 |
'total' => $total_pages, |
| 251 |
'current' => $bbp->reply_query->paged |
| 252 |
) ); |
| 253 |
|
| 254 |
// Add pagination to query object |
| 255 |
$bbp->reply_query->pagination_links = bbp_paginate_links( $bbp_replies_pagination ); |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
// Filter & return |
| 260 |
return apply_filters( 'bbp_has_replies', $bbp->reply_query->have_posts(), $bbp->reply_query ); |
| 261 |
} |
| 262 |
|
| 263 |
/** |
| 264 |
* Whether there are more replies available in the loop |
| 265 |
* |
| 266 |
* @since 2.0.0 bbPress (r2553) |
| 267 |
* |
| 268 |
* @return object Replies information |
| 269 |
*/ |
| 270 |
function bbp_replies() { |
| 271 |
|
| 272 |
// Put into variable to check against next |
| 273 |
$have_posts = bbpress()->reply_query->have_posts(); |
| 274 |
|
| 275 |
// Reset the post data when finished |
| 276 |
if ( empty( $have_posts ) ) { |
| 277 |
wp_reset_postdata(); |
| 278 |
} |
| 279 |
|
| 280 |
return $have_posts; |
| 281 |
} |
| 282 |
|
| 283 |
/** |
| 284 |
* Loads up the current reply in the loop |
| 285 |
* |
| 286 |
* @since 2.0.0 bbPress (r2553) |
| 287 |
* |
| 288 |
* @return object Reply information |
| 289 |
*/ |
| 290 |
function bbp_the_reply() { |
| 291 |
return bbpress()->reply_query->the_post(); |
| 292 |
} |
| 293 |
|
| 294 |
/** |
| 295 |
* Output reply id |
| 296 |
* |
| 297 |
* @since 2.0.0 bbPress (r2553) |
| 298 |
* |
| 299 |
* @param $reply_id Optional. Used to check emptiness |
| 300 |
*/ |
| 301 |
function bbp_reply_id( $reply_id = 0 ) { |
| 302 |
echo bbp_get_reply_id( $reply_id ); |
| 303 |
} |
| 304 |
/** |
| 305 |
* Return the id of the reply in a replies loop |
| 306 |
* |
| 307 |
* @since 2.0.0 bbPress (r2553) |
| 308 |
* |
| 309 |
* @param $reply_id Optional. Used to check emptiness |
| 310 |
* @return int The reply id |
| 311 |
*/ |
| 312 |
function bbp_get_reply_id( $reply_id = 0 ) { |
| 313 |
$bbp = bbpress(); |
| 314 |
$wp_query = bbp_get_wp_query(); |
| 315 |
|
| 316 |
// Easy empty checking |
| 317 |
if ( ! empty( $reply_id ) && is_numeric( $reply_id ) ) { |
| 318 |
$bbp_reply_id = $reply_id; |
| 319 |
|
| 320 |
// Currently inside a replies loop |
| 321 |
} elseif ( ! empty( $bbp->reply_query->in_the_loop ) && isset( $bbp->reply_query->post->ID ) ) { |
| 322 |
$bbp_reply_id = $bbp->reply_query->post->ID; |
| 323 |
|
| 324 |
// Currently inside a search loop |
| 325 |
} elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_reply( $bbp->search_query->post->ID ) ) { |
| 326 |
$bbp_reply_id = $bbp->search_query->post->ID; |
| 327 |
|
| 328 |
// Currently viewing a forum |
| 329 |
} elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && ! empty( $bbp->current_reply_id ) ) { |
| 330 |
$bbp_reply_id = $bbp->current_reply_id; |
| 331 |
|
| 332 |
// Currently viewing a reply |
| 333 |
} elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && isset( $wp_query->post->ID ) ) { |
| 334 |
$bbp_reply_id = $wp_query->post->ID; |
| 335 |
|
| 336 |
// Fallback |
| 337 |
} else { |
| 338 |
$bbp_reply_id = 0; |
| 339 |
} |
| 340 |
|
| 341 |
// Filter & return |
| 342 |
return (int) apply_filters( 'bbp_get_reply_id', $bbp_reply_id, $reply_id ); |
| 343 |
} |
| 344 |
|
| 345 |
/** |
| 346 |
* Gets a reply |
| 347 |
* |
| 348 |
* @since 2.0.0 bbPress (r2787) |
| 349 |
* |
| 350 |
* @param int|object $reply reply id or reply object |
| 351 |
* @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT |
| 352 |
* @param string $filter Optional Sanitation filter. See {@link sanitize_post()} |
| 353 |
* @return mixed Null if error or reply (in specified form) if success |
| 354 |
*/ |
| 355 |
function bbp_get_reply( $reply, $output = OBJECT, $filter = 'raw' ) { |
| 356 |
|
| 357 |
// Maybe get ID from empty or int |
| 358 |
if ( empty( $reply ) || is_numeric( $reply ) ) { |
| 359 |
$reply = bbp_get_reply_id( $reply ); |
| 360 |
} |
| 361 |
|
| 362 |
// Bail if no post object |
| 363 |
$reply = get_post( $reply, OBJECT, $filter ); |
| 364 |
if ( empty( $reply ) ) { |
| 365 |
return $reply; |
| 366 |
} |
| 367 |
|
| 368 |
// Bail if not correct post type |
| 369 |
if ( $reply->post_type !== bbp_get_reply_post_type() ) { |
| 370 |
return null; |
| 371 |
} |
| 372 |
|
| 373 |
// Default return value is OBJECT |
| 374 |
$retval = $reply; |
| 375 |
|
| 376 |
// Array A |
| 377 |
if ( $output === ARRAY_A ) { |
| 378 |
$retval = get_object_vars( $reply ); |
| 379 |
|
| 380 |
// Array N |
| 381 |
} elseif ( $output === ARRAY_N ) { |
| 382 |
$retval = array_values( get_object_vars( $reply ) ); |
| 383 |
} |
| 384 |
|
| 385 |
// Filter & return |
| 386 |
return apply_filters( 'bbp_get_reply', $retval, $reply, $output, $filter ); |
| 387 |
} |
| 388 |
|
| 389 |
/** |
| 390 |
* Output the link to the reply in the reply loop |
| 391 |
* |
| 392 |
* @since 2.0.0 bbPress (r2553) |
| 393 |
* |
| 394 |
* @param int $reply_id Optional. Reply id |
| 395 |
*/ |
| 396 |
function bbp_reply_permalink( $reply_id = 0 ) { |
| 397 |
echo esc_url( bbp_get_reply_permalink( $reply_id ) ); |
| 398 |
} |
| 399 |
/** |
| 400 |
* Return the link to the reply |
| 401 |
* |
| 402 |
* @since 2.0.0 bbPress (r2553) |
| 403 |
* |
| 404 |
* @param int $reply_id Optional. Reply id |
| 405 |
* |
| 406 |
* @return string Permanent link to reply |
| 407 |
*/ |
| 408 |
function bbp_get_reply_permalink( $reply_id = 0 ) { |
| 409 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 410 |
|
| 411 |
// Filter & return |
| 412 |
return apply_filters( 'bbp_get_reply_permalink', get_permalink( $reply_id ), $reply_id ); |
| 413 |
} |
| 414 |
|
| 415 |
/** |
| 416 |
* Output the paginated url to the reply in the reply loop |
| 417 |
* |
| 418 |
* @since 2.0.0 bbPress (r2679) |
| 419 |
* |
| 420 |
* @param int $reply_id Optional. Reply id |
| 421 |
*/ |
| 422 |
function bbp_reply_url( $reply_id = 0 ) { |
| 423 |
echo esc_url( bbp_get_reply_url( $reply_id ) ); |
| 424 |
} |
| 425 |
/** |
| 426 |
* Return the paginated url to the reply in the reply loop |
| 427 |
* |
| 428 |
* @since 2.0.0 bbPress (r2679) |
| 429 |
* |
| 430 |
* @param int $reply_id Optional. Reply id |
| 431 |
* @param string $redirect_to Optional. Pass a redirect value for use with |
| 432 |
* shortcodes and other fun things. |
| 433 |
* @return string Link to reply relative to paginated topic |
| 434 |
*/ |
| 435 |
function bbp_get_reply_url( $reply_id = 0, $redirect_to = '' ) { |
| 436 |
|
| 437 |
// Set needed variables |
| 438 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 439 |
$topic_id = 0; |
| 440 |
|
| 441 |
// Juggle reply & topic IDs for unpretty URL formatting |
| 442 |
if ( bbp_is_reply( $reply_id ) ) { |
| 443 |
$topic_id = bbp_get_reply_topic_id( $reply_id ); |
| 444 |
$topic = bbp_get_topic( $topic_id ); |
| 445 |
} elseif ( bbp_is_topic( $reply_id ) ) { |
| 446 |
$topic_id = bbp_get_topic_id( $reply_id ); |
| 447 |
$topic = bbp_get_topic( $topic_id ); |
| 448 |
$reply_id = $topic_id; |
| 449 |
} |
| 450 |
|
| 451 |
// Hierarchical reply page |
| 452 |
if ( bbp_thread_replies() ) { |
| 453 |
$reply_page = 1; |
| 454 |
|
| 455 |
// Standard reply page |
| 456 |
} else { |
| 457 |
$reply_page = ceil( (int) bbp_get_reply_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() ); |
| 458 |
} |
| 459 |
|
| 460 |
// Get links & URLS |
| 461 |
$reply_hash = '#post-' . $reply_id; |
| 462 |
$topic_link = bbp_get_topic_permalink( $topic_id, $redirect_to ); |
| 463 |
$topic_url = remove_query_arg( 'view', $topic_link ); |
| 464 |
|
| 465 |
// Get vars needed to support pending topics with unpretty links |
| 466 |
$has_slug = ! empty( $topic ) ? $topic->post_name : ''; |
| 467 |
$pretty = bbp_use_pretty_urls(); |
| 468 |
$published = bbp_is_topic_public( $topic_id ); |
| 469 |
|
| 470 |
// Don't include pagination if on first page |
| 471 |
if ( 1 >= $reply_page ) { |
| 472 |
|
| 473 |
// Pretty permalinks |
| 474 |
if ( ! empty( $has_slug ) && ! empty( $pretty ) && ! empty( $published ) ) { |
| 475 |
$url = user_trailingslashit( $topic_url ) . $reply_hash; |
| 476 |
|
| 477 |
// Unpretty links |
| 478 |
} else { |
| 479 |
$url = $topic_url . $reply_hash; |
| 480 |
} |
| 481 |
|
| 482 |
// Include pagination |
| 483 |
} else { |
| 484 |
|
| 485 |
// Pretty permalinks |
| 486 |
if ( ! empty( $has_slug ) && ! empty( $pretty ) && ! empty( $published ) ) { |
| 487 |
$url = trailingslashit( $topic_url ) . trailingslashit( bbp_get_paged_slug() ) . $reply_page; |
| 488 |
$url = user_trailingslashit( $url ) . $reply_hash; |
| 489 |
|
| 490 |
// Unpretty links |
| 491 |
} else { |
| 492 |
$url = add_query_arg( 'paged', $reply_page, $topic_url ) . $reply_hash; |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
// Add topic view query arg back to end if it is set |
| 497 |
if ( bbp_get_view_all() ) { |
| 498 |
$url = bbp_add_view_all( $url ); |
| 499 |
} |
| 500 |
|
| 501 |
// Filter & return |
| 502 |
return apply_filters( 'bbp_get_reply_url', $url, $reply_id, $redirect_to ); |
| 503 |
} |
| 504 |
|
| 505 |
/** |
| 506 |
* Output the title of the reply |
| 507 |
* |
| 508 |
* @since 2.0.0 bbPress (r2553) |
| 509 |
* |
| 510 |
* @param int $reply_id Optional. Reply id |
| 511 |
*/ |
| 512 |
function bbp_reply_title( $reply_id = 0 ) { |
| 513 |
echo bbp_get_reply_title( $reply_id ); |
| 514 |
} |
| 515 |
|
| 516 |
/** |
| 517 |
* Return the title of the reply |
| 518 |
* |
| 519 |
* @since 2.0.0 bbPress (r2553) |
| 520 |
* |
| 521 |
* @param int $reply_id Optional. Reply id |
| 522 |
* @return string Title of reply |
| 523 |
*/ |
| 524 |
function bbp_get_reply_title( $reply_id = 0 ) { |
| 525 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 526 |
$title = get_the_title( $reply_id ); |
| 527 |
|
| 528 |
// Filter & return |
| 529 |
return apply_filters( 'bbp_get_reply_title', $title, $reply_id ); |
| 530 |
} |
| 531 |
|
| 532 |
/** |
| 533 |
* Get empty reply title fallback. |
| 534 |
* |
| 535 |
* @since 2.5.0 bbPress (r5177) |
| 536 |
* |
| 537 |
* @param string $post_title Required. Reply Title |
| 538 |
* @param int $post_id Required. Reply ID |
| 539 |
* @return string Title of reply |
| 540 |
*/ |
| 541 |
function bbp_get_reply_title_fallback( $post_title = '', $post_id = 0 ) { |
| 542 |
|
| 543 |
// Bail if title not empty, or post is not a reply |
| 544 |
if ( ! empty( $post_title ) || ! bbp_is_reply( $post_id ) ) { |
| 545 |
return $post_title; |
| 546 |
} |
| 547 |
|
| 548 |
// Get reply topic title. |
| 549 |
$topic_title = bbp_get_reply_topic_title( $post_id ); |
| 550 |
|
| 551 |
// Get empty reply title fallback. |
| 552 |
$reply_title = sprintf( esc_html__( 'Reply To: %s', 'bbpress' ), $topic_title ); |
| 553 |
|
| 554 |
// Filter & return |
| 555 |
return apply_filters( 'bbp_get_reply_title_fallback', $reply_title, $post_id, $topic_title ); |
| 556 |
} |
| 557 |
|
| 558 |
/** |
| 559 |
* Output the content of the reply |
| 560 |
* |
| 561 |
* @since 2.0.0 bbPress (r2553) |
| 562 |
* |
| 563 |
* @param int $reply_id Optional. reply id |
| 564 |
*/ |
| 565 |
function bbp_reply_content( $reply_id = 0 ) { |
| 566 |
echo bbp_get_reply_content( $reply_id ); |
| 567 |
} |
| 568 |
/** |
| 569 |
* Return the content of the reply |
| 570 |
* |
| 571 |
* @since 2.0.0 bbPress (r2780) |
| 572 |
* |
| 573 |
* @param int $reply_id Optional. reply id |
| 574 |
* @return string Content of the reply |
| 575 |
*/ |
| 576 |
function bbp_get_reply_content( $reply_id = 0 ) { |
| 577 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 578 |
|
| 579 |
// Check if password is required |
| 580 |
if ( post_password_required( $reply_id ) ) { |
| 581 |
return get_the_password_form(); |
| 582 |
} |
| 583 |
|
| 584 |
$content = get_post_field( 'post_content', $reply_id ); |
| 585 |
|
| 586 |
// Filter & return |
| 587 |
return apply_filters( 'bbp_get_reply_content', $content, $reply_id ); |
| 588 |
} |
| 589 |
|
| 590 |
/** |
| 591 |
* Output the excerpt of the reply |
| 592 |
* |
| 593 |
* @since 2.0.0 bbPress (r2751) |
| 594 |
* |
| 595 |
* @param int $reply_id Optional. Reply id |
| 596 |
* @param int $length Optional. Length of the excerpt. Defaults to 100 letters |
| 597 |
*/ |
| 598 |
function bbp_reply_excerpt( $reply_id = 0, $length = 100 ) { |
| 599 |
echo bbp_get_reply_excerpt( $reply_id, $length ); |
| 600 |
} |
| 601 |
/** |
| 602 |
* Return the excerpt of the reply |
| 603 |
* |
| 604 |
* @since 2.0.0 bbPress (r2751) |
| 605 |
* |
| 606 |
* @param int $reply_id Optional. Reply id |
| 607 |
* @param int $length Optional. Length of the excerpt. Defaults to 100 |
| 608 |
* letters |
| 609 |
* @return string Reply Excerpt |
| 610 |
*/ |
| 611 |
function bbp_get_reply_excerpt( $reply_id = 0, $length = 100 ) { |
| 612 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 613 |
$length = (int) $length; |
| 614 |
$excerpt = get_post_field( 'post_excerpt', $reply_id ); |
| 615 |
|
| 616 |
if ( empty( $excerpt ) ) { |
| 617 |
$excerpt = bbp_get_reply_content( $reply_id ); |
| 618 |
} |
| 619 |
|
| 620 |
$excerpt = trim ( strip_tags( $excerpt ) ); |
| 621 |
|
| 622 |
// Multibyte support |
| 623 |
if ( function_exists( 'mb_strlen' ) ) { |
| 624 |
$excerpt_length = mb_strlen( $excerpt ); |
| 625 |
} else { |
| 626 |
$excerpt_length = strlen( $excerpt ); |
| 627 |
} |
| 628 |
|
| 629 |
if ( ! empty( $length ) && ( $excerpt_length > $length ) ) { |
| 630 |
$excerpt = mb_substr( $excerpt, 0, $length - 1 ); |
| 631 |
$excerpt .= '…'; |
| 632 |
} |
| 633 |
|
| 634 |
// Filter & return |
| 635 |
return apply_filters( 'bbp_get_reply_excerpt', $excerpt, $reply_id, $length ); |
| 636 |
} |
| 637 |
|
| 638 |
/** |
| 639 |
* Output the post date and time of a reply |
| 640 |
* |
| 641 |
* @since 2.2.0 bbPress (r4155) |
| 642 |
* |
| 643 |
* @param int $reply_id Optional. Reply id. |
| 644 |
* @param bool $humanize Optional. Humanize output using time_since |
| 645 |
* @param bool $gmt Optional. Use GMT |
| 646 |
*/ |
| 647 |
function bbp_reply_post_date( $reply_id = 0, $humanize = false, $gmt = false ) { |
| 648 |
echo bbp_get_reply_post_date( $reply_id, $humanize, $gmt ); |
| 649 |
} |
| 650 |
/** |
| 651 |
* Return the post date and time of a reply |
| 652 |
* |
| 653 |
* @since 2.2.0 bbPress (r4155) |
| 654 |
* |
| 655 |
* @param int $reply_id Optional. Reply id. |
| 656 |
* @param bool $humanize Optional. Humanize output using time_since |
| 657 |
* @param bool $gmt Optional. Use GMT |
| 658 |
* @return string |
| 659 |
*/ |
| 660 |
function bbp_get_reply_post_date( $reply_id = 0, $humanize = false, $gmt = false ) { |
| 661 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 662 |
|
| 663 |
// 4 days, 4 hours ago |
| 664 |
if ( ! empty( $humanize ) ) { |
| 665 |
$gmt_s = ! empty( $gmt ) ? 'G' : 'U'; |
| 666 |
$date = get_post_time( $gmt_s, $gmt, $reply_id ); |
| 667 |
$time = false; // For filter below |
| 668 |
$result = bbp_get_time_since( $date ); |
| 669 |
|
| 670 |
// August 4, 2012 at 2:37 pm |
| 671 |
} else { |
| 672 |
$date = get_post_time( get_option( 'date_format' ), $gmt, $reply_id, true ); |
| 673 |
$time = get_post_time( get_option( 'time_format' ), $gmt, $reply_id, true ); |
| 674 |
$result = sprintf( _x( '%1$s at %2$s', 'date at time', 'bbpress' ), $date, $time ); |
| 675 |
} |
| 676 |
|
| 677 |
// Filter & return |
| 678 |
return apply_filters( 'bbp_get_reply_post_date', $result, $reply_id, $humanize, $gmt, $date, $time ); |
| 679 |
} |
| 680 |
|
| 681 |
/** |
| 682 |
* Append revisions to the reply content |
| 683 |
* |
| 684 |
* @since 2.0.0 bbPress (r2782) |
| 685 |
* |
| 686 |
* @param string $content Optional. Content to which we need to append the revisions to |
| 687 |
* @param int $reply_id Optional. Reply id |
| 688 |
* @return string Content with the revisions appended |
| 689 |
*/ |
| 690 |
function bbp_reply_content_append_revisions( $content = '', $reply_id = 0 ) { |
| 691 |
|
| 692 |
// Bail if in admin or feed |
| 693 |
if ( is_admin() || is_feed() ) { |
| 694 |
return $content; |
| 695 |
} |
| 696 |
|
| 697 |
// Validate the ID |
| 698 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 699 |
|
| 700 |
// Filter & return |
| 701 |
return apply_filters( 'bbp_reply_append_revisions', $content . bbp_get_reply_revision_log( $reply_id ), $content, $reply_id ); |
| 702 |
} |
| 703 |
|
| 704 |
/** |
| 705 |
* Output the revision log of the reply |
| 706 |
* |
| 707 |
* @since 2.0.0 bbPress (r2782) |
| 708 |
* |
| 709 |
* @param int $reply_id Optional. Reply id |
| 710 |
*/ |
| 711 |
function bbp_reply_revision_log( $reply_id = 0 ) { |
| 712 |
echo bbp_get_reply_revision_log( $reply_id ); |
| 713 |
} |
| 714 |
/** |
| 715 |
* Return the formatted revision log of the reply |
| 716 |
* |
| 717 |
* @since 2.0.0 bbPress (r2782) |
| 718 |
* |
| 719 |
* @param int $reply_id Optional. Reply id |
| 720 |
* @return string Revision log of the reply |
| 721 |
*/ |
| 722 |
function bbp_get_reply_revision_log( $reply_id = 0 ) { |
| 723 |
|
| 724 |
// Create necessary variables |
| 725 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 726 |
|
| 727 |
// Show the topic reply log if this is a topic in a reply loop |
| 728 |
if ( bbp_is_topic( $reply_id ) ) { |
| 729 |
return bbp_get_topic_revision_log( $reply_id ); |
| 730 |
} |
| 731 |
|
| 732 |
// Get the reply revision log (out of post meta |
| 733 |
$revision_log = bbp_get_reply_raw_revision_log( $reply_id ); |
| 734 |
|
| 735 |
// Check reply and revision log exist |
| 736 |
if ( empty( $reply_id ) || empty( $revision_log ) || ! is_array( $revision_log ) ) { |
| 737 |
return false; |
| 738 |
} |
| 739 |
|
| 740 |
// Get the actual revisions |
| 741 |
$revisions = bbp_get_reply_revisions( $reply_id ); |
| 742 |
if ( empty( $revisions ) ) { |
| 743 |
return false; |
| 744 |
} |
| 745 |
|
| 746 |
$r = "\n\n" . '<ul id="bbp-reply-revision-log-' . esc_attr( $reply_id ) . '" class="bbp-reply-revision-log">' . "\n\n"; |
| 747 |
|
| 748 |
// Loop through revisions |
| 749 |
foreach ( (array) $revisions as $revision ) { |
| 750 |
|
| 751 |
if ( empty( $revision_log[ $revision->ID ] ) ) { |
| 752 |
$author_id = $revision->post_author; |
| 753 |
$reason = ''; |
| 754 |
} else { |
| 755 |
$author_id = $revision_log[ $revision->ID ]['author']; |
| 756 |
$reason = $revision_log[ $revision->ID ]['reason']; |
| 757 |
} |
| 758 |
|
| 759 |
$author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_reply_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) ); |
| 760 |
$since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) ); |
| 761 |
|
| 762 |
$r .= "\t" . '<li id="bbp-reply-revision-log-' . esc_attr( $reply_id ) . '-item-' . esc_attr( $revision->ID ) . '" class="bbp-reply-revision-log-item">' . "\n"; |
| 763 |
if ( ! empty( $reason ) ) { |
| 764 |
$r .= "\t\t" . sprintf( esc_html__( 'This reply was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), esc_html( $since ), $author, esc_html( $reason ) ) . "\n"; |
| 765 |
} else { |
| 766 |
$r .= "\t\t" . sprintf( esc_html__( 'This reply was modified %1$s by %2$s.', 'bbpress' ), esc_html( $since ), $author ) . "\n"; |
| 767 |
} |
| 768 |
$r .= "\t" . '</li>' . "\n"; |
| 769 |
|
| 770 |
} |
| 771 |
|
| 772 |
$r .= "\n" . '</ul>' . "\n\n"; |
| 773 |
|
| 774 |
// Filter & return |
| 775 |
return apply_filters( 'bbp_get_reply_revision_log', $r, $reply_id ); |
| 776 |
} |
| 777 |
/** |
| 778 |
* Return the raw revision log of the reply |
| 779 |
* |
| 780 |
* @since 2.0.0 bbPress (r2782) |
| 781 |
* |
| 782 |
* @param int $reply_id Optional. Reply id |
| 783 |
* @return string Raw revision log of the reply |
| 784 |
*/ |
| 785 |
function bbp_get_reply_raw_revision_log( $reply_id = 0 ) { |
| 786 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 787 |
$revision_log = get_post_meta( $reply_id, '_bbp_revision_log', true ); |
| 788 |
$revision_log = ! empty( $revision_log ) |
| 789 |
? $revision_log |
| 790 |
: array(); |
| 791 |
|
| 792 |
// Filter & return |
| 793 |
return apply_filters( 'bbp_get_reply_raw_revision_log', $revision_log, $reply_id ); |
| 794 |
} |
| 795 |
|
| 796 |
/** |
| 797 |
* Return the revisions of the reply |
| 798 |
* |
| 799 |
* @since 2.0.0 bbPress (r2782) |
| 800 |
* |
| 801 |
* @param int $reply_id Optional. Reply id |
| 802 |
* @return WP_Post[]|int[] reply revisions |
| 803 |
*/ |
| 804 |
function bbp_get_reply_revisions( $reply_id = 0 ) { |
| 805 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 806 |
$revisions = wp_get_post_revisions( $reply_id, array( 'order' => 'ASC' ) ); |
| 807 |
|
| 808 |
// Filter & return |
| 809 |
return apply_filters( 'bbp_get_reply_revisions', $revisions, $reply_id ); |
| 810 |
} |
| 811 |
|
| 812 |
/** |
| 813 |
* Return the revision count of the reply |
| 814 |
* |
| 815 |
* @since 2.0.0 bbPress (r2782) |
| 816 |
* |
| 817 |
* @param int $reply_id Optional. Reply id |
| 818 |
* @param boolean $integer Optional. Whether or not to format the result |
| 819 |
* @return string reply revision count |
| 820 |
*/ |
| 821 |
function bbp_get_reply_revision_count( $reply_id = 0, $integer = false ) { |
| 822 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 823 |
$count = count( bbp_get_reply_revisions( $reply_id ) ); |
| 824 |
$filter = ( true === $integer ) |
| 825 |
? 'bbp_get_reply_revision_count_int' |
| 826 |
: 'bbp_get_reply_revision_count'; |
| 827 |
|
| 828 |
return apply_filters( $filter, $count, $reply_id ); |
| 829 |
} |
| 830 |
|
| 831 |
/** |
| 832 |
* Output the status of the reply |
| 833 |
* |
| 834 |
* @since 2.0.0 bbPress (r2667) |
| 835 |
* |
| 836 |
* @param int $reply_id Optional. Reply id |
| 837 |
*/ |
| 838 |
function bbp_reply_status( $reply_id = 0 ) { |
| 839 |
echo bbp_get_reply_status( $reply_id ); |
| 840 |
} |
| 841 |
/** |
| 842 |
* Return the status of the reply |
| 843 |
* |
| 844 |
* @since 2.0.0 bbPress (r2667) |
| 845 |
* |
| 846 |
* @param int $reply_id Optional. Reply id |
| 847 |
* @return string Status of reply |
| 848 |
*/ |
| 849 |
function bbp_get_reply_status( $reply_id = 0 ) { |
| 850 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 851 |
|
| 852 |
// Filter & return |
| 853 |
return apply_filters( 'bbp_get_reply_status', get_post_status( $reply_id ), $reply_id ); |
| 854 |
} |
| 855 |
|
| 856 |
/** |
| 857 |
* Is the reply publicly viewable? |
| 858 |
* |
| 859 |
* See bbp_get_public_reply_statuses() for public statuses. |
| 860 |
* |
| 861 |
* @since 2.6.0 bbPress (r6391) |
| 862 |
* |
| 863 |
* @param int $reply_id Optional. Reply id |
| 864 |
* @return bool True if public, false if not. |
| 865 |
*/ |
| 866 |
function bbp_is_reply_public( $reply_id = 0 ) { |
| 867 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 868 |
$status = bbp_get_reply_status( $reply_id ); |
| 869 |
$public = bbp_get_public_reply_statuses(); |
| 870 |
$is_public = in_array( $status, $public, true ); |
| 871 |
|
| 872 |
// Filter & return |
| 873 |
return (bool) apply_filters( 'bbp_is_reply_public', $is_public, $reply_id ); |
| 874 |
} |
| 875 |
|
| 876 |
/** |
| 877 |
* Is the reply not spam or deleted? |
| 878 |
* |
| 879 |
* @since 2.0.0 bbPress (r3496) |
| 880 |
* @since 2.6.0 bbPress (r6922) Returns false if topic is also not published |
| 881 |
* |
| 882 |
* @param int $reply_id Optional. Topic id |
| 883 |
* @return bool True if published, false if not. |
| 884 |
*/ |
| 885 |
function bbp_is_reply_published( $reply_id = 0 ) { |
| 886 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 887 |
$topic_id = bbp_get_reply_topic_id( $reply_id ); |
| 888 |
$status = bbp_get_public_status_id(); |
| 889 |
$topic_status = bbp_is_topic_published( $topic_id ); |
| 890 |
$reply_status = ( bbp_get_reply_status( $reply_id ) === $status ); |
| 891 |
$retval = ( $reply_status && $topic_status ); |
| 892 |
|
| 893 |
// Filter & return |
| 894 |
return (bool) apply_filters( 'bbp_is_reply_published', (bool) $retval, $reply_id ); |
| 895 |
} |
| 896 |
|
| 897 |
/** |
| 898 |
* Is the reply marked as spam? |
| 899 |
* |
| 900 |
* @since 2.0.0 bbPress (r2740) |
| 901 |
* |
| 902 |
* @param int $reply_id Optional. Reply id |
| 903 |
* @return bool True if spam, false if not. |
| 904 |
*/ |
| 905 |
function bbp_is_reply_spam( $reply_id = 0 ) { |
| 906 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 907 |
$status = bbp_get_spam_status_id(); |
| 908 |
$reply_status = bbp_get_reply_status( $reply_id ) === $status; |
| 909 |
|
| 910 |
// Filter & return |
| 911 |
return (bool) apply_filters( 'bbp_is_reply_spam', (bool) $reply_status, $reply_id ); |
| 912 |
} |
| 913 |
|
| 914 |
/** |
| 915 |
* Is the reply trashed? |
| 916 |
* |
| 917 |
* @since 2.0.0 bbPress (r2884) |
| 918 |
* |
| 919 |
* @param int $reply_id Optional. Topic id |
| 920 |
* @return bool True if spam, false if not. |
| 921 |
*/ |
| 922 |
function bbp_is_reply_trash( $reply_id = 0 ) { |
| 923 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 924 |
$status = bbp_get_trash_status_id(); |
| 925 |
$reply_status = bbp_get_reply_status( $reply_id ) === $status; |
| 926 |
|
| 927 |
// Filter & return |
| 928 |
return (bool) apply_filters( 'bbp_is_reply_trash', (bool) $reply_status, $reply_id ); |
| 929 |
} |
| 930 |
|
| 931 |
/** |
| 932 |
* Is the reply pending? |
| 933 |
* |
| 934 |
* @since 2.6.0 bbPress (r5507) |
| 935 |
* |
| 936 |
* @param int $reply_id Optional. Topic id |
| 937 |
* @return bool True if pending, false if not. |
| 938 |
*/ |
| 939 |
function bbp_is_reply_pending( $reply_id = 0 ) { |
| 940 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 941 |
$status = bbp_get_pending_status_id(); |
| 942 |
$reply_status = bbp_get_reply_status( $reply_id ) === $status; |
| 943 |
|
| 944 |
// Filter & return |
| 945 |
return (bool) apply_filters( 'bbp_is_reply_pending', (bool) $reply_status, $reply_id ); |
| 946 |
} |
| 947 |
|
| 948 |
/** |
| 949 |
* Is the reply private? |
| 950 |
* |
| 951 |
* @since 2.6.0 bbPress (r5507) |
| 952 |
* |
| 953 |
* @param int $reply_id Optional. Topic id |
| 954 |
* @return bool True if private, false if not. |
| 955 |
*/ |
| 956 |
function bbp_is_reply_private( $reply_id = 0 ) { |
| 957 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 958 |
$status = bbp_get_private_status_id(); |
| 959 |
$reply_status = bbp_get_reply_status( $reply_id ) === $status; |
| 960 |
|
| 961 |
// Filter & return |
| 962 |
return (bool) apply_filters( 'bbp_is_reply_private', (bool) $reply_status, $reply_id ); |
| 963 |
} |
| 964 |
|
| 965 |
/** |
| 966 |
* Is the reply by an anonymous user? |
| 967 |
* |
| 968 |
* @since 2.0.0 bbPress (r2753) |
| 969 |
* |
| 970 |
* @param int $reply_id Optional. Reply id |
| 971 |
* @return bool True if the post is by an anonymous user, false if not. |
| 972 |
*/ |
| 973 |
function bbp_is_reply_anonymous( $reply_id = 0 ) { |
| 974 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 975 |
$retval = false; |
| 976 |
|
| 977 |
if ( ! bbp_get_reply_author_id( $reply_id ) ) { |
| 978 |
$retval = true; |
| 979 |
|
| 980 |
} elseif ( get_post_meta( $reply_id, '_bbp_anonymous_name', true ) ) { |
| 981 |
$retval = true; |
| 982 |
|
| 983 |
} elseif ( get_post_meta( $reply_id, '_bbp_anonymous_email', true ) ) { |
| 984 |
$retval = true; |
| 985 |
} |
| 986 |
|
| 987 |
// Filter & return |
| 988 |
return (bool) apply_filters( 'bbp_is_reply_anonymous', $retval, $reply_id ); |
| 989 |
} |
| 990 |
|
| 991 |
/** |
| 992 |
* Deprecated. Use bbp_reply_author_display_name() instead. |
| 993 |
* |
| 994 |
* Output the author of the reply |
| 995 |
* |
| 996 |
* @since 2.0.0 bbPress (r2667) |
| 997 |
* |
| 998 |
* @deprecated 2.5.0 bbPress (r5119) |
| 999 |
* |
| 1000 |
* @param int $reply_id Optional. Reply id |
| 1001 |
*/ |
| 1002 |
function bbp_reply_author( $reply_id = 0 ) { |
| 1003 |
echo bbp_get_reply_author( $reply_id ); |
| 1004 |
} |
| 1005 |
/** |
| 1006 |
* Deprecated. Use bbp_get_reply_author_display_name() instead. |
| 1007 |
* |
| 1008 |
* Return the author of the reply |
| 1009 |
* |
| 1010 |
* @since 2.0.0 bbPress (r2667) |
| 1011 |
* |
| 1012 |
* @deprecated 2.5.0 bbPress (r5119) |
| 1013 |
* |
| 1014 |
* @param int $reply_id Optional. Reply id |
| 1015 |
* @return string Author of reply |
| 1016 |
*/ |
| 1017 |
function bbp_get_reply_author( $reply_id = 0 ) { |
| 1018 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1019 |
|
| 1020 |
if ( ! bbp_is_reply_anonymous( $reply_id ) ) { |
| 1021 |
$author = get_the_author_meta( 'display_name', bbp_get_reply_author_id( $reply_id ) ); |
| 1022 |
} else { |
| 1023 |
$author = get_post_meta( $reply_id, '_bbp_anonymous_name', true ); |
| 1024 |
} |
| 1025 |
|
| 1026 |
// Filter & return |
| 1027 |
return apply_filters( 'bbp_get_reply_author', $author, $reply_id ); |
| 1028 |
} |
| 1029 |
|
| 1030 |
/** |
| 1031 |
* Output the author ID of the reply |
| 1032 |
* |
| 1033 |
* @since 2.0.0 bbPress (r2667) |
| 1034 |
* |
| 1035 |
* @param int $reply_id Optional. Reply id |
| 1036 |
*/ |
| 1037 |
function bbp_reply_author_id( $reply_id = 0 ) { |
| 1038 |
echo bbp_get_reply_author_id( $reply_id ); |
| 1039 |
} |
| 1040 |
/** |
| 1041 |
* Return the author ID of the reply |
| 1042 |
* |
| 1043 |
* @since 2.0.0 bbPress (r2667) |
| 1044 |
* |
| 1045 |
* @param int $reply_id Optional. Reply id |
| 1046 |
* @return string Author id of reply |
| 1047 |
*/ |
| 1048 |
function bbp_get_reply_author_id( $reply_id = 0 ) { |
| 1049 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1050 |
$author_id = get_post_field( 'post_author', $reply_id ); |
| 1051 |
|
| 1052 |
// Filter & return |
| 1053 |
return (int) apply_filters( 'bbp_get_reply_author_id', $author_id, $reply_id ); |
| 1054 |
} |
| 1055 |
|
| 1056 |
/** |
| 1057 |
* Output the author display_name of the reply |
| 1058 |
* |
| 1059 |
* @since 2.0.0 bbPress (r2667) |
| 1060 |
* |
| 1061 |
* @param int $reply_id Optional. Reply id |
| 1062 |
*/ |
| 1063 |
function bbp_reply_author_display_name( $reply_id = 0 ) { |
| 1064 |
echo bbp_get_reply_author_display_name( $reply_id ); |
| 1065 |
} |
| 1066 |
/** |
| 1067 |
* Return the author display_name of the reply |
| 1068 |
* |
| 1069 |
* @since 2.0.0 bbPress (r2667) |
| 1070 |
* |
| 1071 |
* @param int $reply_id Optional. Reply id |
| 1072 |
* @return string The display name of the author of the reply |
| 1073 |
*/ |
| 1074 |
function bbp_get_reply_author_display_name( $reply_id = 0 ) { |
| 1075 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1076 |
|
| 1077 |
// User is not a guest |
| 1078 |
if ( ! bbp_is_reply_anonymous( $reply_id ) ) { |
| 1079 |
|
| 1080 |
// Get the author ID |
| 1081 |
$author_id = bbp_get_reply_author_id( $reply_id ); |
| 1082 |
|
| 1083 |
// Try to get a display name |
| 1084 |
$author_name = get_the_author_meta( 'display_name', $author_id ); |
| 1085 |
|
| 1086 |
// Fall back to user login |
| 1087 |
if ( empty( $author_name ) ) { |
| 1088 |
$author_name = get_the_author_meta( 'user_login', $author_id ); |
| 1089 |
} |
| 1090 |
|
| 1091 |
// User does not have an account |
| 1092 |
} else { |
| 1093 |
$author_name = get_post_meta( $reply_id, '_bbp_anonymous_name', true ); |
| 1094 |
} |
| 1095 |
|
| 1096 |
// Fallback if nothing could be found |
| 1097 |
if ( empty( $author_name ) ) { |
| 1098 |
$author_name = bbp_get_fallback_display_name( $reply_id ); |
| 1099 |
} |
| 1100 |
|
| 1101 |
// Filter & return |
| 1102 |
return apply_filters( 'bbp_get_reply_author_display_name', $author_name, $reply_id ); |
| 1103 |
} |
| 1104 |
|
| 1105 |
/** |
| 1106 |
* Output the author avatar of the reply |
| 1107 |
* |
| 1108 |
* @since 2.0.0 bbPress (r2667) |
| 1109 |
* |
| 1110 |
* @param int $reply_id Optional. Reply id |
| 1111 |
* @param int $size Optional. Size of the avatar. Defaults to 40 |
| 1112 |
*/ |
| 1113 |
function bbp_reply_author_avatar( $reply_id = 0, $size = 40 ) { |
| 1114 |
echo bbp_get_reply_author_avatar( $reply_id, $size ); |
| 1115 |
} |
| 1116 |
/** |
| 1117 |
* Return the author avatar of the reply |
| 1118 |
* |
| 1119 |
* @since 2.0.0 bbPress (r2667) |
| 1120 |
* |
| 1121 |
* @param int $reply_id Optional. Reply id |
| 1122 |
* @param int $size Optional. Size of the avatar. Defaults to 40 |
| 1123 |
* @return string Avatar of author of the reply |
| 1124 |
*/ |
| 1125 |
function bbp_get_reply_author_avatar( $reply_id = 0, $size = 40 ) { |
| 1126 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1127 |
if ( ! empty( $reply_id ) ) { |
| 1128 |
// Check for anonymous user |
| 1129 |
if ( ! bbp_is_reply_anonymous( $reply_id ) ) { |
| 1130 |
$author_avatar = get_avatar( bbp_get_reply_author_id( $reply_id ), $size ); |
| 1131 |
} else { |
| 1132 |
$author_avatar = get_avatar( get_post_meta( $reply_id, '_bbp_anonymous_email', true ), $size ); |
| 1133 |
} |
| 1134 |
} else { |
| 1135 |
$author_avatar = ''; |
| 1136 |
} |
| 1137 |
|
| 1138 |
// Filter & return |
| 1139 |
return apply_filters( 'bbp_get_reply_author_avatar', $author_avatar, $reply_id, $size ); |
| 1140 |
} |
| 1141 |
|
| 1142 |
/** |
| 1143 |
* Output the author link of the reply |
| 1144 |
* |
| 1145 |
* @since 2.0.0 bbPress (r2717) |
| 1146 |
* |
| 1147 |
* @param array $args Optional. If it is an integer, it is used as reply id. |
| 1148 |
*/ |
| 1149 |
function bbp_reply_author_link( $args = array() ) { |
| 1150 |
echo bbp_get_reply_author_link( $args ); |
| 1151 |
} |
| 1152 |
/** |
| 1153 |
* Return the author link of the reply |
| 1154 |
* |
| 1155 |
* @since 2.0.0 bbPress (r2717) |
| 1156 |
* |
| 1157 |
* @param array $args Optional. If an integer, it is used as reply id. |
| 1158 |
* @return string Author link of reply |
| 1159 |
*/ |
| 1160 |
function bbp_get_reply_author_link( $args = array() ) { |
| 1161 |
|
| 1162 |
// Parse arguments against default values |
| 1163 |
$r = bbp_parse_args( $args, array( |
| 1164 |
'post_id' => 0, |
| 1165 |
'link_title' => '', |
| 1166 |
'type' => 'both', |
| 1167 |
'size' => 80, |
| 1168 |
'sep' => '', |
| 1169 |
'show_role' => false |
| 1170 |
), 'get_reply_author_link' ); |
| 1171 |
|
| 1172 |
// Default return value |
| 1173 |
$author_link = ''; |
| 1174 |
|
| 1175 |
// Used as reply_id |
| 1176 |
$reply_id = is_numeric( $args ) |
| 1177 |
? bbp_get_reply_id( $args ) |
| 1178 |
: bbp_get_reply_id( $r['post_id'] ); |
| 1179 |
|
| 1180 |
// Reply ID is good |
| 1181 |
if ( ! empty( $reply_id ) ) { |
| 1182 |
|
| 1183 |
// Get some useful reply information |
| 1184 |
$author_url = bbp_get_reply_author_url( $reply_id ); |
| 1185 |
$anonymous = bbp_is_reply_anonymous( $reply_id ); |
| 1186 |
|
| 1187 |
// Tweak link title if empty |
| 1188 |
if ( empty( $r['link_title'] ) ) { |
| 1189 |
$author = bbp_get_reply_author_display_name( $reply_id ); |
| 1190 |
$title = empty( $anonymous ) |
| 1191 |
? esc_attr__( "View %s's profile", 'bbpress' ) |
| 1192 |
: esc_attr__( "Visit %s's website", 'bbpress' ); |
| 1193 |
|
| 1194 |
$link_title = sprintf( $title, $author ); |
| 1195 |
|
| 1196 |
// Use what was passed if not |
| 1197 |
} else { |
| 1198 |
$link_title = $r['link_title']; |
| 1199 |
} |
| 1200 |
|
| 1201 |
// Setup title and author_links array |
| 1202 |
$author_links = array(); |
| 1203 |
$link_title = ! empty( $link_title ) |
| 1204 |
? ' title="' . esc_attr( $link_title ) . '"' |
| 1205 |
: ''; |
| 1206 |
|
| 1207 |
// Get avatar (unescaped, because HTML) |
| 1208 |
if ( ( 'avatar' === $r['type'] ) || ( 'both' === $r['type'] ) ) { |
| 1209 |
$author_links['avatar'] = bbp_get_reply_author_avatar( $reply_id, $r['size'] ); |
| 1210 |
} |
| 1211 |
|
| 1212 |
// Get display name (escaped, because never HTML) |
| 1213 |
if ( ( 'name' === $r['type'] ) || ( 'both' === $r['type'] ) ) { |
| 1214 |
$author_links['name'] = esc_html( bbp_get_reply_author_display_name( $reply_id ) ); |
| 1215 |
} |
| 1216 |
|
| 1217 |
// Empty array |
| 1218 |
$links = array(); |
| 1219 |
$sprint = '<span %1$s>%2$s</span>'; |
| 1220 |
|
| 1221 |
// Wrap each link |
| 1222 |
foreach ( $author_links as $link => $link_text ) { |
| 1223 |
$link_class = ' class="bbp-author-' . esc_attr( $link ) . '"'; |
| 1224 |
$links[] = sprintf( $sprint, $link_class, $link_text ); |
| 1225 |
} |
| 1226 |
|
| 1227 |
// Juggle |
| 1228 |
$author_links = $links; |
| 1229 |
unset( $links ); |
| 1230 |
|
| 1231 |
// Filter sections |
| 1232 |
$sections = apply_filters( 'bbp_get_reply_author_links', $author_links, $r, $args ); |
| 1233 |
|
| 1234 |
// Assemble sections into author link |
| 1235 |
$author_link = implode( $r['sep'], $sections ); |
| 1236 |
|
| 1237 |
// Only wrap in link if profile exists |
| 1238 |
if ( empty( $anonymous ) && bbp_user_has_profile( bbp_get_reply_author_id( $reply_id ) ) ) { |
| 1239 |
$author_link = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, ' class="bbp-author-link"', $author_link ); |
| 1240 |
} |
| 1241 |
|
| 1242 |
// Role is not linked |
| 1243 |
if ( true === $r['show_role'] ) { |
| 1244 |
$author_link .= bbp_get_reply_author_role( array( 'reply_id' => $reply_id ) ); |
| 1245 |
} |
| 1246 |
} |
| 1247 |
|
| 1248 |
// Filter & return |
| 1249 |
return apply_filters( 'bbp_get_reply_author_link', $author_link, $r, $args ); |
| 1250 |
} |
| 1251 |
|
| 1252 |
/** |
| 1253 |
* Output the author url of the reply |
| 1254 |
* |
| 1255 |
* @since 2.0.0 bbPress (r2667) |
| 1256 |
* |
| 1257 |
* @param int $reply_id Optional. Reply id |
| 1258 |
*/ |
| 1259 |
function bbp_reply_author_url( $reply_id = 0 ) { |
| 1260 |
echo esc_url( bbp_get_reply_author_url( $reply_id ) ); |
| 1261 |
} |
| 1262 |
/** |
| 1263 |
* Return the author url of the reply |
| 1264 |
* |
| 1265 |
* @since 2.0.0 bbPress (r2667) |
| 1266 |
* |
| 1267 |
* @param int $reply_id Optional. Reply id |
| 1268 |
* @return string Author URL of the reply |
| 1269 |
*/ |
| 1270 |
function bbp_get_reply_author_url( $reply_id = 0 ) { |
| 1271 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1272 |
|
| 1273 |
// Check for anonymous user or non-existant user |
| 1274 |
if ( ! bbp_is_reply_anonymous( $reply_id ) && bbp_user_has_profile( bbp_get_reply_author_id( $reply_id ) ) ) { |
| 1275 |
$author_url = bbp_get_user_profile_url( bbp_get_reply_author_id( $reply_id ) ); |
| 1276 |
} else { |
| 1277 |
$author_url = get_post_meta( $reply_id, '_bbp_anonymous_website', true ); |
| 1278 |
if ( empty( $author_url ) ) { |
| 1279 |
$author_url = ''; |
| 1280 |
} |
| 1281 |
} |
| 1282 |
|
| 1283 |
// Filter & return |
| 1284 |
return apply_filters( 'bbp_get_reply_author_url', $author_url, $reply_id ); |
| 1285 |
} |
| 1286 |
|
| 1287 |
/** |
| 1288 |
* Output the reply author email address |
| 1289 |
* |
| 1290 |
* @since 2.0.0 bbPress (r3445) |
| 1291 |
* |
| 1292 |
* @param int $reply_id Optional. Reply id |
| 1293 |
*/ |
| 1294 |
function bbp_reply_author_email( $reply_id = 0 ) { |
| 1295 |
echo bbp_get_reply_author_email( $reply_id ); |
| 1296 |
} |
| 1297 |
/** |
| 1298 |
* Return the reply author email address |
| 1299 |
* |
| 1300 |
* @since 2.0.0 bbPress (r3445) |
| 1301 |
* |
| 1302 |
* @param int $reply_id Optional. Reply id |
| 1303 |
* @return string Reply author email address |
| 1304 |
*/ |
| 1305 |
function bbp_get_reply_author_email( $reply_id = 0 ) { |
| 1306 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1307 |
|
| 1308 |
// Not anonymous |
| 1309 |
if ( ! bbp_is_reply_anonymous( $reply_id ) ) { |
| 1310 |
|
| 1311 |
// Use reply author email address |
| 1312 |
$user_id = bbp_get_reply_author_id( $reply_id ); |
| 1313 |
$user = get_userdata( $user_id ); |
| 1314 |
$author_email = ! empty( $user->user_email ) ? $user->user_email : ''; |
| 1315 |
|
| 1316 |
// Anonymous |
| 1317 |
} else { |
| 1318 |
|
| 1319 |
// Get email from post meta |
| 1320 |
$author_email = get_post_meta( $reply_id, '_bbp_anonymous_email', true ); |
| 1321 |
|
| 1322 |
// Sanity check for missing email address |
| 1323 |
if ( empty( $author_email ) ) { |
| 1324 |
$author_email = ''; |
| 1325 |
} |
| 1326 |
} |
| 1327 |
|
| 1328 |
// Filter & return |
| 1329 |
return apply_filters( 'bbp_get_reply_author_email', $author_email, $reply_id ); |
| 1330 |
} |
| 1331 |
|
| 1332 |
/** |
| 1333 |
* Output the reply author role |
| 1334 |
* |
| 1335 |
* @since 2.1.0 bbPress (r3860) |
| 1336 |
* |
| 1337 |
* @param array $args Optional. |
| 1338 |
*/ |
| 1339 |
function bbp_reply_author_role( $args = array() ) { |
| 1340 |
echo bbp_get_reply_author_role( $args ); |
| 1341 |
} |
| 1342 |
/** |
| 1343 |
* Return the reply author role |
| 1344 |
* |
| 1345 |
* @since 2.1.0 bbPress (r3860) |
| 1346 |
* |
| 1347 |
* @param array $args Optional. |
| 1348 |
* @return string Reply author role |
| 1349 |
*/ |
| 1350 |
function bbp_get_reply_author_role( $args = array() ) { |
| 1351 |
|
| 1352 |
// Parse arguments against default values |
| 1353 |
$r = bbp_parse_args( $args, array( |
| 1354 |
'reply_id' => 0, |
| 1355 |
'class' => false, |
| 1356 |
'before' => '<div class="bbp-author-role">', |
| 1357 |
'after' => '</div>' |
| 1358 |
), 'get_reply_author_role' ); |
| 1359 |
|
| 1360 |
$reply_id = bbp_get_reply_id( $r['reply_id'] ); |
| 1361 |
$role = bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) ); |
| 1362 |
|
| 1363 |
// Backwards compatibilty with old 'class' argument |
| 1364 |
if ( ! empty( $r['class'] ) ) { |
| 1365 |
$author_role = sprintf( '%1$s<div class="%2$s">%3$s</div>%4$s', $r['before'], esc_attr( $r['class'] ), esc_html( $role ), $r['after'] ); |
| 1366 |
|
| 1367 |
// Simpler before & after arguments |
| 1368 |
// https://bbpress.trac.wordpress.org/ticket/2557 |
| 1369 |
} else { |
| 1370 |
$author_role = $r['before'] . $role . $r['after']; |
| 1371 |
} |
| 1372 |
|
| 1373 |
// Filter & return |
| 1374 |
return apply_filters( 'bbp_get_reply_author_role', $author_role, $r, $args ); |
| 1375 |
} |
| 1376 |
|
| 1377 |
/** |
| 1378 |
* Output the topic title a reply belongs to |
| 1379 |
* |
| 1380 |
* @since 2.0.0 bbPress (r2553) |
| 1381 |
* |
| 1382 |
* @param int $reply_id Optional. Reply id |
| 1383 |
*/ |
| 1384 |
function bbp_reply_topic_title( $reply_id = 0 ) { |
| 1385 |
echo bbp_get_reply_topic_title( $reply_id ); |
| 1386 |
} |
| 1387 |
/** |
| 1388 |
* Return the topic title a reply belongs to |
| 1389 |
* |
| 1390 |
* @since 2.0.0 bbPress (r2553) |
| 1391 |
* |
| 1392 |
* @param int $reply_id Optional. Reply id |
| 1393 |
* @return string The topic title of the reply |
| 1394 |
*/ |
| 1395 |
function bbp_get_reply_topic_title( $reply_id = 0 ) { |
| 1396 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1397 |
$topic_id = bbp_get_reply_topic_id( $reply_id ); |
| 1398 |
|
| 1399 |
// Filter & return |
| 1400 |
return apply_filters( 'bbp_get_reply_topic_title', bbp_get_topic_title( $topic_id ), $reply_id ); |
| 1401 |
} |
| 1402 |
|
| 1403 |
/** |
| 1404 |
* Output the topic id a reply belongs to |
| 1405 |
* |
| 1406 |
* @since 2.0.0 bbPress (r2553) |
| 1407 |
* |
| 1408 |
* @param int $reply_id Optional. Reply id |
| 1409 |
*/ |
| 1410 |
function bbp_reply_topic_id( $reply_id = 0 ) { |
| 1411 |
echo bbp_get_reply_topic_id( $reply_id ); |
| 1412 |
} |
| 1413 |
/** |
| 1414 |
* Return the topic id a reply belongs to |
| 1415 |
* |
| 1416 |
* @since 2.0.0 bbPress (r2553) |
| 1417 |
* |
| 1418 |
* @param int $reply_id Optional. Reply id |
| 1419 |
* @return int The topic id of the reply |
| 1420 |
*/ |
| 1421 |
function bbp_get_reply_topic_id( $reply_id = 0 ) { |
| 1422 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1423 |
$topic_id = (int) get_post_field( 'post_parent', $reply_id ); |
| 1424 |
|
| 1425 |
// Meta-data fallback |
| 1426 |
if ( empty( $topic_id ) ) { |
| 1427 |
$topic_id = (int) get_post_meta( $reply_id, '_bbp_topic_id', true ); |
| 1428 |
} |
| 1429 |
|
| 1430 |
// Filter |
| 1431 |
if ( ! empty( $topic_id ) ) { |
| 1432 |
$topic_id = (int) bbp_get_topic_id( $topic_id ); |
| 1433 |
} |
| 1434 |
|
| 1435 |
// Filter & return |
| 1436 |
return (int) apply_filters( 'bbp_get_reply_topic_id', $topic_id, $reply_id ); |
| 1437 |
} |
| 1438 |
|
| 1439 |
/** |
| 1440 |
* Output the forum id a reply belongs to |
| 1441 |
* |
| 1442 |
* @since 2.0.0 bbPress (r2679) |
| 1443 |
* |
| 1444 |
* @param int $reply_id Optional. Reply id |
| 1445 |
*/ |
| 1446 |
function bbp_reply_forum_id( $reply_id = 0 ) { |
| 1447 |
echo bbp_get_reply_forum_id( $reply_id ); |
| 1448 |
} |
| 1449 |
/** |
| 1450 |
* Return the forum id a reply belongs to |
| 1451 |
* |
| 1452 |
* @since 2.0.0 bbPress (r2679) |
| 1453 |
* |
| 1454 |
* @param int $reply_id Optional. Reply id |
| 1455 |
* |
| 1456 |
* @return int The forum id of the reply |
| 1457 |
*/ |
| 1458 |
function bbp_get_reply_forum_id( $reply_id = 0 ) { |
| 1459 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1460 |
$topic_id = bbp_get_reply_topic_id( $reply_id ); |
| 1461 |
$forum_id = (int) get_post_field( 'post_parent', $topic_id ); |
| 1462 |
|
| 1463 |
// Meta-data fallback |
| 1464 |
if ( empty( $forum_id ) ) { |
| 1465 |
$forum_id = (int) get_post_meta( $reply_id, '_bbp_forum_id', true ); |
| 1466 |
} |
| 1467 |
|
| 1468 |
// Filter |
| 1469 |
if ( ! empty( $forum_id ) ) { |
| 1470 |
$forum_id = (int) bbp_get_forum_id( $forum_id ); |
| 1471 |
} |
| 1472 |
|
| 1473 |
// Filter & return |
| 1474 |
return (int) apply_filters( 'bbp_get_reply_forum_id', $forum_id, $reply_id ); |
| 1475 |
} |
| 1476 |
|
| 1477 |
/** |
| 1478 |
* Output the ancestor reply id of a reply |
| 1479 |
* |
| 1480 |
* @since 2.4.0 bbPress (r4944) |
| 1481 |
* |
| 1482 |
* @param int $reply_id Optional. Reply id |
| 1483 |
*/ |
| 1484 |
function bbp_reply_ancestor_id( $reply_id = 0 ) { |
| 1485 |
echo bbp_get_reply_ancestor_id( $reply_id ); |
| 1486 |
} |
| 1487 |
/** |
| 1488 |
* Return the ancestor reply id of a reply |
| 1489 |
* |
| 1490 |
* @since 2.4.0 bbPress (r4944) |
| 1491 |
* |
| 1492 |
* @param in $reply_id Reply id |
| 1493 |
*/ |
| 1494 |
function bbp_get_reply_ancestor_id( $reply_id = 0 ) { |
| 1495 |
|
| 1496 |
// Validation |
| 1497 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1498 |
if ( empty( $reply_id ) ) { |
| 1499 |
return false; |
| 1500 |
} |
| 1501 |
|
| 1502 |
// Find highest reply ancestor |
| 1503 |
$ancestor_id = $reply_id; |
| 1504 |
while ( $parent_id = bbp_get_reply_to( $ancestor_id ) ) { |
| 1505 |
if ( empty( $parent_id ) || ( $parent_id === $ancestor_id ) || ( bbp_get_reply_topic_id( $reply_id ) === $parent_id ) || ( $parent_id === $reply_id ) ) { |
| 1506 |
break; |
| 1507 |
} |
| 1508 |
$ancestor_id = $parent_id; |
| 1509 |
} |
| 1510 |
|
| 1511 |
return (int) $ancestor_id; |
| 1512 |
} |
| 1513 |
|
| 1514 |
/** |
| 1515 |
* Output the reply to id of a reply |
| 1516 |
* |
| 1517 |
* @since 2.4.0 bbPress (r4944) |
| 1518 |
* |
| 1519 |
* @param int $reply_id Optional. Reply id |
| 1520 |
*/ |
| 1521 |
function bbp_reply_to( $reply_id = 0 ) { |
| 1522 |
echo bbp_get_reply_to( $reply_id ); |
| 1523 |
} |
| 1524 |
/** |
| 1525 |
* Return the reply to id of a reply |
| 1526 |
* |
| 1527 |
* @since 2.4.0 bbPress (r4944) |
| 1528 |
* |
| 1529 |
* @param int $reply_id Optional. Reply id |
| 1530 |
* @return int The parent reply id of the reply |
| 1531 |
*/ |
| 1532 |
function bbp_get_reply_to( $reply_id = 0 ) { |
| 1533 |
|
| 1534 |
// Assume there is no reply_to set |
| 1535 |
$reply_to = 0; |
| 1536 |
|
| 1537 |
// Check that reply_id is valid |
| 1538 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1539 |
|
| 1540 |
// Get reply_to value |
| 1541 |
if ( ! empty( $reply_id ) ) { |
| 1542 |
$reply_to = (int) get_post_meta( $reply_id, '_bbp_reply_to', true ); |
| 1543 |
} |
| 1544 |
|
| 1545 |
// Filter & return |
| 1546 |
return (int) apply_filters( 'bbp_get_reply_to', $reply_to, $reply_id ); |
| 1547 |
} |
| 1548 |
|
| 1549 |
/** |
| 1550 |
* Output the link for the reply to |
| 1551 |
* |
| 1552 |
* @since 2.4.0 bbPress (r4944) |
| 1553 |
* |
| 1554 |
* @param array $args |
| 1555 |
*/ |
| 1556 |
function bbp_reply_to_link( $args = array() ) { |
| 1557 |
echo bbp_get_reply_to_link( $args ); |
| 1558 |
} |
| 1559 |
|
| 1560 |
/** |
| 1561 |
* Return the link for a reply to a reply |
| 1562 |
* |
| 1563 |
* @since 2.4.0 bbPress (r4944) |
| 1564 |
* |
| 1565 |
* @param array $args Arguments |
| 1566 |
* @return string Link for a reply to a reply |
| 1567 |
*/ |
| 1568 |
function bbp_get_reply_to_link( $args = array() ) { |
| 1569 |
|
| 1570 |
// Parse arguments against default values |
| 1571 |
$r = bbp_parse_args( $args, array( |
| 1572 |
'id' => 0, |
| 1573 |
'link_before' => '', |
| 1574 |
'link_after' => '', |
| 1575 |
'reply_text' => esc_html_x( 'Reply', 'verb', 'bbpress' ), |
| 1576 |
'depth' => 0, |
| 1577 |
'add_below' => 'post', |
| 1578 |
'respond_id' => 'new-reply-' . bbp_get_topic_id(), |
| 1579 |
), 'get_reply_to_link' ); |
| 1580 |
|
| 1581 |
// Get the reply to use it's ID and post_parent |
| 1582 |
$reply = bbp_get_reply( $r['id'] ); |
| 1583 |
$topic_id = bbp_get_reply_topic_id( $reply->ID ); |
| 1584 |
|
| 1585 |
// Bail if no reply or user cannot reply |
| 1586 |
if ( empty( $reply ) || empty( $topic_id ) || bbp_is_single_reply() || ! bbp_current_user_can_access_create_reply_form() ) { |
| 1587 |
return; |
| 1588 |
} |
| 1589 |
|
| 1590 |
// Build the URI and return value |
| 1591 |
$uri = bbp_get_reply_url( $reply->ID ); |
| 1592 |
$uri = strtok( $uri, "#" ); |
| 1593 |
$uri = add_query_arg( array( 'bbp_reply_to' => $reply->ID ), $uri ); |
| 1594 |
$uri = wp_nonce_url( $uri, 'respond_id_' . $reply->ID ); |
| 1595 |
$uri = $uri . '#new-post'; |
| 1596 |
|
| 1597 |
// Only add onclick if replies are threaded |
| 1598 |
if ( bbp_thread_replies() ) { |
| 1599 |
|
| 1600 |
// Array of classes to pass to moveForm |
| 1601 |
$move_form = array( |
| 1602 |
$r['add_below'] . '-' . $reply->ID, |
| 1603 |
$reply->ID, |
| 1604 |
$r['respond_id'], |
| 1605 |
$reply->post_parent |
| 1606 |
); |
| 1607 |
|
| 1608 |
// Build the onclick |
| 1609 |
$onclick = ' onclick="return addReply.moveForm(\'' . implode( "','", $move_form ) . '\');"'; |
| 1610 |
|
| 1611 |
// No onclick if replies are not threaded |
| 1612 |
} else { |
| 1613 |
$onclick = ''; |
| 1614 |
} |
| 1615 |
|
| 1616 |
// Add $uri to the array, to be passed through the filter |
| 1617 |
$r['uri'] = $uri; |
| 1618 |
$retval = $r['link_before'] . '<a role="button" href="' . esc_url( $r['uri'] ) . '" class="bbp-reply-to-link"' . $onclick . '>' . $r['reply_text'] . '</a>' . $r['link_after']; |
| 1619 |
|
| 1620 |
// Filter & return |
| 1621 |
return apply_filters( 'bbp_get_reply_to_link', $retval, $r, $args ); |
| 1622 |
} |
| 1623 |
|
| 1624 |
/** |
| 1625 |
* Output the reply to a reply cancellation link |
| 1626 |
* |
| 1627 |
* @since 2.4.0 bbPress (r4944) |
| 1628 |
*/ |
| 1629 |
function bbp_cancel_reply_to_link( $text = '' ) { |
| 1630 |
echo bbp_get_cancel_reply_to_link( $text ); |
| 1631 |
} |
| 1632 |
/** |
| 1633 |
* Return the cancellation link for a reply to a reply |
| 1634 |
* |
| 1635 |
* @since 2.4.0 bbPress (r4944) |
| 1636 |
* |
| 1637 |
* @param string $text The cancel text |
| 1638 |
* @return string The cancellation link |
| 1639 |
*/ |
| 1640 |
function bbp_get_cancel_reply_to_link( $text = '' ) { |
| 1641 |
|
| 1642 |
// Bail if not hierarchical or editing a reply |
| 1643 |
if ( ! bbp_thread_replies() || bbp_is_reply_edit() ) { |
| 1644 |
return; |
| 1645 |
} |
| 1646 |
|
| 1647 |
// Set default text |
| 1648 |
if ( empty( $text ) ) { |
| 1649 |
$text = esc_html__( 'Cancel', 'bbpress' ); |
| 1650 |
} |
| 1651 |
|
| 1652 |
// Replying to... |
| 1653 |
$reply_to = isset( $_GET['bbp_reply_to'] ) |
| 1654 |
? (int) $_GET['bbp_reply_to'] |
| 1655 |
: 0; |
| 1656 |
|
| 1657 |
// Set visibility |
| 1658 |
$style = ! empty( $reply_to ) ? '' : ' style="display:none;"'; |
| 1659 |
$link = remove_query_arg( array( 'bbp_reply_to', '_wpnonce' ) ) . "#post-{$reply_to}"; |
| 1660 |
$retval = sprintf( '<a href="%1$s" id="bbp-cancel-reply-to-link"%2$s>%3$s</a>', esc_url( $link ), $style, esc_html( $text ) ); |
| 1661 |
|
| 1662 |
// Filter & return |
| 1663 |
return apply_filters( 'bbp_get_cancel_reply_to_link', $retval, $link, $text ); |
| 1664 |
} |
| 1665 |
|
| 1666 |
/** |
| 1667 |
* Output the numeric position of a reply within a topic |
| 1668 |
* |
| 1669 |
* @since 2.0.0 bbPress (r2984) |
| 1670 |
* |
| 1671 |
* @param int $reply_id Optional. Reply id |
| 1672 |
* @param int $topic_id Optional. Topic id |
| 1673 |
*/ |
| 1674 |
function bbp_reply_position( $reply_id = 0, $topic_id = 0 ) { |
| 1675 |
echo bbp_get_reply_position( $reply_id, $topic_id ); |
| 1676 |
} |
| 1677 |
/** |
| 1678 |
* Return the numeric position of a reply within a topic |
| 1679 |
* |
| 1680 |
* @since 2.0.0 bbPress (r2984) |
| 1681 |
* |
| 1682 |
* @param int $reply_id Optional. Reply id |
| 1683 |
* @param int $topic_id Optional. Topic id |
| 1684 |
* @return int Reply position |
| 1685 |
*/ |
| 1686 |
function bbp_get_reply_position( $reply_id = 0, $topic_id = 0 ) { |
| 1687 |
|
| 1688 |
// Get required data |
| 1689 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1690 |
$reply_position = get_post_field( 'menu_order', $reply_id ); |
| 1691 |
|
| 1692 |
// Reply doesn't have a position so get the raw value |
| 1693 |
if ( empty( $reply_position ) ) { |
| 1694 |
|
| 1695 |
// Get topic ID |
| 1696 |
$topic_id = ! empty( $topic_id ) |
| 1697 |
? bbp_get_topic_id( $topic_id ) |
| 1698 |
: bbp_get_reply_topic_id( $reply_id ); |
| 1699 |
|
| 1700 |
// Post is not the topic |
| 1701 |
if ( $reply_id !== $topic_id ) { |
| 1702 |
$reply_position = bbp_get_reply_position_raw( $reply_id, $topic_id ); |
| 1703 |
|
| 1704 |
// Update the reply position in the posts table so we'll never have |
| 1705 |
// to hit the DB again. |
| 1706 |
if ( ! empty( $reply_position ) ) { |
| 1707 |
bbp_update_reply_position( $reply_id, $reply_position ); |
| 1708 |
} |
| 1709 |
|
| 1710 |
// Topic's position is always 0 |
| 1711 |
} else { |
| 1712 |
$reply_position = 0; |
| 1713 |
} |
| 1714 |
} |
| 1715 |
|
| 1716 |
// Bump the position by one if the topic is included in the reply loop |
| 1717 |
if ( ! bbp_show_lead_topic() ) { |
| 1718 |
$reply_position++; |
| 1719 |
} |
| 1720 |
|
| 1721 |
// Filter & return |
| 1722 |
return (int) apply_filters( 'bbp_get_reply_position', $reply_position, $reply_id, $topic_id ); |
| 1723 |
} |
| 1724 |
|
| 1725 |
/** Reply Admin Links *********************************************************/ |
| 1726 |
|
| 1727 |
/** |
| 1728 |
* Output admin links for reply |
| 1729 |
* |
| 1730 |
* @since 2.0.0 bbPress (r2667) |
| 1731 |
* |
| 1732 |
* @param array $args See {@link bbp_get_reply_admin_links()} |
| 1733 |
*/ |
| 1734 |
function bbp_reply_admin_links( $args = array() ) { |
| 1735 |
echo bbp_get_reply_admin_links( $args ); |
| 1736 |
} |
| 1737 |
/** |
| 1738 |
* Return admin links for reply |
| 1739 |
* |
| 1740 |
* @since 2.0.0 bbPress (r2667) |
| 1741 |
* |
| 1742 |
* @param array $args This function supports these arguments: |
| 1743 |
* - id: Optional. Reply id |
| 1744 |
* - before: HTML before the links. Defaults to |
| 1745 |
* '<span class="bbp-admin-links">' |
| 1746 |
* - after: HTML after the links. Defaults to '</span>' |
| 1747 |
* - sep: Separator. Defaults to ' | ' |
| 1748 |
* - links: Array of the links to display. By default, edit, trash, |
| 1749 |
* spam, reply move, and topic split links are displayed |
| 1750 |
* @return string Reply admin links |
| 1751 |
*/ |
| 1752 |
function bbp_get_reply_admin_links( $args = array() ) { |
| 1753 |
|
| 1754 |
// Parse arguments against default values |
| 1755 |
$r = bbp_parse_args( $args, array( |
| 1756 |
'id' => 0, |
| 1757 |
'before' => '<span class="bbp-admin-links">', |
| 1758 |
'after' => '</span>', |
| 1759 |
'sep' => ' | ', |
| 1760 |
'links' => array() |
| 1761 |
), 'get_reply_admin_links' ); |
| 1762 |
|
| 1763 |
$r['id'] = bbp_get_reply_id( $r['id'] ); |
| 1764 |
|
| 1765 |
// If post is a topic, return the topic admin links instead |
| 1766 |
if ( bbp_is_topic( $r['id'] ) ) { |
| 1767 |
return bbp_get_topic_admin_links( $args ); |
| 1768 |
} |
| 1769 |
|
| 1770 |
// If post is not a reply, return |
| 1771 |
if ( ! bbp_is_reply( $r['id'] ) ) { |
| 1772 |
return; |
| 1773 |
} |
| 1774 |
|
| 1775 |
// If topic is trashed, do not show admin links |
| 1776 |
if ( bbp_is_topic_trash( bbp_get_reply_topic_id( $r['id'] ) ) ) { |
| 1777 |
return; |
| 1778 |
} |
| 1779 |
|
| 1780 |
// If no links were passed, default to the standard |
| 1781 |
if ( empty( $r['links'] ) ) { |
| 1782 |
$r['links'] = apply_filters( 'bbp_reply_admin_links', array( |
| 1783 |
'edit' => bbp_get_reply_edit_link ( $r ), |
| 1784 |
'move' => bbp_get_reply_move_link ( $r ), |
| 1785 |
'split' => bbp_get_topic_split_link ( $r ), |
| 1786 |
'trash' => bbp_get_reply_trash_link ( $r ), |
| 1787 |
'spam' => bbp_get_reply_spam_link ( $r ), |
| 1788 |
'approve' => bbp_get_reply_approve_link( $r ), |
| 1789 |
'reply' => bbp_get_reply_to_link ( $r ) |
| 1790 |
), $r['id'] ); |
| 1791 |
} |
| 1792 |
|
| 1793 |
// See if links need to be unset |
| 1794 |
$reply_status = bbp_get_reply_status( $r['id'] ); |
| 1795 |
if ( in_array( $reply_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id() ), true ) ) { |
| 1796 |
|
| 1797 |
// Spam link shouldn't be visible on trashed topics |
| 1798 |
if ( bbp_get_trash_status_id() === $reply_status ) { |
| 1799 |
unset( $r['links']['spam'] ); |
| 1800 |
|
| 1801 |
// Trash link shouldn't be visible on spam topics |
| 1802 |
} elseif ( bbp_get_spam_status_id() === $reply_status ) { |
| 1803 |
unset( $r['links']['trash'] ); |
| 1804 |
} |
| 1805 |
} |
| 1806 |
|
| 1807 |
// Process the admin links |
| 1808 |
$links = implode( $r['sep'], array_filter( $r['links'] ) ); |
| 1809 |
$retval = $r['before'] . $links . $r['after']; |
| 1810 |
|
| 1811 |
// Filter & return |
| 1812 |
return apply_filters( 'bbp_get_reply_admin_links', $retval, $r, $args ); |
| 1813 |
} |
| 1814 |
|
| 1815 |
/** |
| 1816 |
* Output the edit link of the reply |
| 1817 |
* |
| 1818 |
* @since 2.0.0 bbPress (r2740) |
| 1819 |
* |
| 1820 |
* @param array $args See {@link bbp_get_reply_edit_link()} |
| 1821 |
*/ |
| 1822 |
function bbp_reply_edit_link( $args = array() ) { |
| 1823 |
echo bbp_get_reply_edit_link( $args ); |
| 1824 |
} |
| 1825 |
|
| 1826 |
/** |
| 1827 |
* Return the edit link of the reply |
| 1828 |
* |
| 1829 |
* @since 2.0.0 bbPress (r2740) |
| 1830 |
* |
| 1831 |
* @param array $args This function supports these arguments: |
| 1832 |
* - id: Reply id |
| 1833 |
* - link_before: HTML before the link |
| 1834 |
* - link_after: HTML after the link |
| 1835 |
* - edit_text: Edit text. Defaults to 'Edit' |
| 1836 |
* @return string Reply edit link |
| 1837 |
*/ |
| 1838 |
function bbp_get_reply_edit_link( $args = array() ) { |
| 1839 |
|
| 1840 |
// Parse arguments against default values |
| 1841 |
$r = bbp_parse_args( $args, array( |
| 1842 |
'id' => 0, |
| 1843 |
'link_before' => '', |
| 1844 |
'link_after' => '', |
| 1845 |
'edit_text' => esc_html__( 'Edit', 'bbpress' ) |
| 1846 |
), 'get_reply_edit_link' ); |
| 1847 |
|
| 1848 |
// Get reply |
| 1849 |
$reply = bbp_get_reply( $r['id'] ); |
| 1850 |
|
| 1851 |
// Bypass check if user has caps |
| 1852 |
if ( ! current_user_can( 'edit_others_replies' ) ) { |
| 1853 |
|
| 1854 |
// User cannot edit or it is past the lock time |
| 1855 |
if ( empty( $reply ) || ! current_user_can( 'edit_reply', $reply->ID ) || bbp_past_edit_lock( $reply->post_date_gmt ) ) { |
| 1856 |
return; |
| 1857 |
} |
| 1858 |
} |
| 1859 |
|
| 1860 |
// Get uri |
| 1861 |
$uri = bbp_get_reply_edit_url( $r['id'] ); |
| 1862 |
|
| 1863 |
// Bail if no uri |
| 1864 |
if ( empty( $uri ) ) { |
| 1865 |
return; |
| 1866 |
} |
| 1867 |
|
| 1868 |
$retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-reply-edit-link">' . $r['edit_text'] . '</a>' . $r['link_after']; |
| 1869 |
|
| 1870 |
// Filter & return |
| 1871 |
return apply_filters( 'bbp_get_reply_edit_link', $retval, $r, $args ); |
| 1872 |
} |
| 1873 |
|
| 1874 |
/** |
| 1875 |
* Output URL to the reply edit page |
| 1876 |
* |
| 1877 |
* @since 2.0.0 bbPress (r2753) |
| 1878 |
* |
| 1879 |
* @param int $reply_id Optional. Reply id |
| 1880 |
*/ |
| 1881 |
function bbp_reply_edit_url( $reply_id = 0 ) { |
| 1882 |
echo esc_url( bbp_get_reply_edit_url( $reply_id ) ); |
| 1883 |
} |
| 1884 |
/** |
| 1885 |
* Return URL to the reply edit page |
| 1886 |
* |
| 1887 |
* @since 2.0.0 bbPress (r2753) |
| 1888 |
* |
| 1889 |
* @param int $reply_id Optional. Reply id |
| 1890 |
* @return string Reply edit url |
| 1891 |
*/ |
| 1892 |
function bbp_get_reply_edit_url( $reply_id = 0 ) { |
| 1893 |
|
| 1894 |
// Bail if no reply |
| 1895 |
$reply = bbp_get_reply( $reply_id ); |
| 1896 |
if ( empty( $reply ) ) { |
| 1897 |
return; |
| 1898 |
} |
| 1899 |
|
| 1900 |
$reply_link = bbp_remove_view_all( bbp_get_reply_permalink( $reply_id ) ); |
| 1901 |
|
| 1902 |
// Pretty permalinks, previously used `bbp_use_pretty_urls()` |
| 1903 |
// https://bbpress.trac.wordpress.org/ticket/3054 |
| 1904 |
if ( false === strpos( $reply_link, '?' ) ) { |
| 1905 |
$url = trailingslashit( $reply_link ) . bbp_get_edit_slug(); |
| 1906 |
$url = user_trailingslashit( $url ); |
| 1907 |
|
| 1908 |
// Unpretty permalinks |
| 1909 |
} else { |
| 1910 |
$url = add_query_arg( array( |
| 1911 |
bbp_get_reply_post_type() => $reply->post_name, |
| 1912 |
bbp_get_edit_rewrite_id() => '1' |
| 1913 |
), $reply_link ); |
| 1914 |
} |
| 1915 |
|
| 1916 |
// Maybe add view all |
| 1917 |
$url = bbp_add_view_all( $url ); |
| 1918 |
|
| 1919 |
// Filter & return |
| 1920 |
return apply_filters( 'bbp_get_reply_edit_url', $url, $reply_id ); |
| 1921 |
} |
| 1922 |
|
| 1923 |
/** |
| 1924 |
* Output the trash link of the reply |
| 1925 |
* |
| 1926 |
* @since 2.0.0 bbPress (r2740) |
| 1927 |
* |
| 1928 |
* @param array $args See {@link bbp_get_reply_trash_link()} |
| 1929 |
*/ |
| 1930 |
function bbp_reply_trash_link( $args = array() ) { |
| 1931 |
echo bbp_get_reply_trash_link( $args ); |
| 1932 |
} |
| 1933 |
|
| 1934 |
/** |
| 1935 |
* Return the trash link of the reply |
| 1936 |
* |
| 1937 |
* @since 2.0.0 bbPress (r2740) |
| 1938 |
* |
| 1939 |
* @param array $args This function supports these arguments: |
| 1940 |
* - id: Reply id |
| 1941 |
* - link_before: HTML before the link |
| 1942 |
* - link_after: HTML after the link |
| 1943 |
* - sep: Separator |
| 1944 |
* - trash_text: Trash text |
| 1945 |
* - restore_text: Restore text |
| 1946 |
* - delete_text: Delete text |
| 1947 |
* @return string Reply trash link |
| 1948 |
*/ |
| 1949 |
function bbp_get_reply_trash_link( $args = array() ) { |
| 1950 |
|
| 1951 |
// Parse arguments against default values |
| 1952 |
$r = bbp_parse_args( $args, array( |
| 1953 |
'id' => 0, |
| 1954 |
'link_before' => '', |
| 1955 |
'link_after' => '', |
| 1956 |
'sep' => ' | ', |
| 1957 |
'trash_text' => esc_html__( 'Trash', 'bbpress' ), |
| 1958 |
'restore_text' => esc_html__( 'Restore', 'bbpress' ), |
| 1959 |
'delete_text' => esc_html__( 'Delete', 'bbpress' ) |
| 1960 |
), 'get_reply_trash_link' ); |
| 1961 |
|
| 1962 |
// Get reply |
| 1963 |
$reply = bbp_get_reply( $r['id'] ); |
| 1964 |
|
| 1965 |
// Bail if no reply or current user cannot delete |
| 1966 |
if ( empty( $reply ) || ! current_user_can( 'delete_reply', $reply->ID ) ) { |
| 1967 |
return; |
| 1968 |
} |
| 1969 |
|
| 1970 |
$actions = array(); |
| 1971 |
$trash_days = bbp_get_trash_days( bbp_get_reply_post_type() ); |
| 1972 |
|
| 1973 |
// Trashed |
| 1974 |
if ( bbp_is_reply_trash( $reply->ID ) ) { |
| 1975 |
$actions['untrash'] = '<a title="' . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'untrash', 'reply_id' => $reply->ID ) ), 'untrash-' . $reply->post_type . '_' . $reply->ID ) ) . '" class="bbp-reply-restore-link">' . $r['restore_text'] . '</a>'; |
| 1976 |
|
| 1977 |
// Trash |
| 1978 |
} elseif ( ! empty( $trash_days ) ) { |
| 1979 |
$actions['trash'] = '<a title="' . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'trash', 'reply_id' => $reply->ID ) ), 'trash-' . $reply->post_type . '_' . $reply->ID ) ) . '" class="bbp-reply-trash-link">' . $r['trash_text'] . '</a>'; |
| 1980 |
} |
| 1981 |
|
| 1982 |
// No trash |
| 1983 |
if ( bbp_is_reply_trash( $reply->ID ) || empty( $trash_days ) ) { |
| 1984 |
$actions['delete'] = '<a title="' . esc_attr__( 'Delete this item permanently', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'delete', 'reply_id' => $reply->ID ) ), 'delete-' . $reply->post_type . '_' . $reply->ID ) ) . '" onclick="return confirm(\'' . esc_js( __( 'Are you sure you want to delete that permanently?', 'bbpress' ) ) . '\' );" class="bbp-reply-delete-link">' . $r['delete_text'] . '</a>'; |
| 1985 |
} |
| 1986 |
|
| 1987 |
// Process the admin links |
| 1988 |
$retval = $r['link_before'] . implode( $r['sep'], $actions ) . $r['link_after']; |
| 1989 |
|
| 1990 |
// Filter & return |
| 1991 |
return apply_filters( 'bbp_get_reply_trash_link', $retval, $r, $args ); |
| 1992 |
} |
| 1993 |
|
| 1994 |
/** |
| 1995 |
* Output the spam link of the reply |
| 1996 |
* |
| 1997 |
* @since 2.0.0 bbPress (r2740) |
| 1998 |
* |
| 1999 |
* @param array $args See {@link bbp_get_reply_spam_link()} |
| 2000 |
*/ |
| 2001 |
function bbp_reply_spam_link( $args = array() ) { |
| 2002 |
echo bbp_get_reply_spam_link( $args ); |
| 2003 |
} |
| 2004 |
|
| 2005 |
/** |
| 2006 |
* Return the spam link of the reply |
| 2007 |
* |
| 2008 |
* @since 2.0.0 bbPress (r2740) |
| 2009 |
* |
| 2010 |
* @param array $args This function supports these arguments: |
| 2011 |
* - id: Reply id |
| 2012 |
* - link_before: HTML before the link |
| 2013 |
* - link_after: HTML after the link |
| 2014 |
* - spam_text: Spam text |
| 2015 |
* - unspam_text: Unspam text |
| 2016 |
* @return string Reply spam link |
| 2017 |
*/ |
| 2018 |
function bbp_get_reply_spam_link( $args = array() ) { |
| 2019 |
|
| 2020 |
// Parse arguments against default values |
| 2021 |
$r = bbp_parse_args( $args, array( |
| 2022 |
'id' => 0, |
| 2023 |
'link_before' => '', |
| 2024 |
'link_after' => '', |
| 2025 |
'spam_text' => esc_html__( 'Spam', 'bbpress' ), |
| 2026 |
'unspam_text' => esc_html__( 'Unspam', 'bbpress' ) |
| 2027 |
), 'get_reply_spam_link' ); |
| 2028 |
|
| 2029 |
// Get reply |
| 2030 |
$reply = bbp_get_reply( $r['id'] ); |
| 2031 |
|
| 2032 |
// Bail if no reply or current user cannot moderate |
| 2033 |
if ( empty( $reply ) || ! current_user_can( 'moderate', $reply->ID ) ) { |
| 2034 |
return; |
| 2035 |
} |
| 2036 |
|
| 2037 |
$display = bbp_is_reply_spam( $reply->ID ) ? $r['unspam_text'] : $r['spam_text']; |
| 2038 |
$uri = add_query_arg( array( 'action' => 'bbp_toggle_reply_spam', 'reply_id' => $reply->ID ) ); |
| 2039 |
$uri = wp_nonce_url( $uri, 'spam-reply_' . $reply->ID ); |
| 2040 |
$retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-reply-spam-link">' . $display . '</a>' . $r['link_after']; |
| 2041 |
|
| 2042 |
// Filter & return |
| 2043 |
return apply_filters( 'bbp_get_reply_spam_link', $retval, $r, $args ); |
| 2044 |
} |
| 2045 |
|
| 2046 |
/** |
| 2047 |
* Move reply link |
| 2048 |
* |
| 2049 |
* Output the move link of the reply |
| 2050 |
* |
| 2051 |
* @since 2.3.0 bbPress (r4521) |
| 2052 |
* |
| 2053 |
* @param array $args See {@link bbp_get_reply_move_link()} |
| 2054 |
*/ |
| 2055 |
function bbp_reply_move_link( $args = array() ) { |
| 2056 |
echo bbp_get_reply_move_link( $args ); |
| 2057 |
} |
| 2058 |
|
| 2059 |
/** |
| 2060 |
* Get move reply link |
| 2061 |
* |
| 2062 |
* Return the move link of the reply |
| 2063 |
* |
| 2064 |
* @since 2.3.0 bbPress (r4521) |
| 2065 |
* |
| 2066 |
* @param array $args This function supports these arguments: |
| 2067 |
* - id: Reply id |
| 2068 |
* - link_before: HTML before the link |
| 2069 |
* - link_after: HTML after the link |
| 2070 |
* - move_text: Move text |
| 2071 |
* - move_title: Move title attribute |
| 2072 |
* @return string Reply move link |
| 2073 |
*/ |
| 2074 |
function bbp_get_reply_move_link( $args = array() ) { |
| 2075 |
|
| 2076 |
// Parse arguments against default values |
| 2077 |
$r = bbp_parse_args( $args, array( |
| 2078 |
'id' => 0, |
| 2079 |
'link_before' => '', |
| 2080 |
'link_after' => '', |
| 2081 |
'split_text' => esc_html__( 'Move', 'bbpress' ), |
| 2082 |
'split_title' => esc_attr__( 'Move this reply', 'bbpress' ) |
| 2083 |
), 'get_reply_move_link' ); |
| 2084 |
|
| 2085 |
// Get IDs |
| 2086 |
$reply_id = bbp_get_reply_id( $r['id'] ); |
| 2087 |
$topic_id = bbp_get_reply_topic_id( $reply_id ); |
| 2088 |
|
| 2089 |
// Bail if no reply ID or user cannot moderate |
| 2090 |
if ( empty( $reply_id ) || ! current_user_can( 'moderate', $topic_id ) ) { |
| 2091 |
return; |
| 2092 |
} |
| 2093 |
|
| 2094 |
$uri = add_query_arg( array( |
| 2095 |
'action' => 'move', |
| 2096 |
'reply_id' => $reply_id |
| 2097 |
), bbp_get_reply_edit_url( $reply_id ) ); |
| 2098 |
|
| 2099 |
$retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" title="' . $r['split_title'] . '" class="bbp-reply-move-link">' . $r['split_text'] . '</a>' . $r['link_after']; |
| 2100 |
|
| 2101 |
// Filter & return |
| 2102 |
return apply_filters( 'bbp_get_reply_move_link', $retval, $r, $args ); |
| 2103 |
} |
| 2104 |
|
| 2105 |
/** |
| 2106 |
* Split topic link |
| 2107 |
* |
| 2108 |
* Output the split link of the topic (but is bundled with each reply) |
| 2109 |
* |
| 2110 |
* @since 2.0.0 bbPress (r2756) |
| 2111 |
* |
| 2112 |
* @param array $args See {@link bbp_get_topic_split_link()} |
| 2113 |
*/ |
| 2114 |
function bbp_topic_split_link( $args = array() ) { |
| 2115 |
echo bbp_get_topic_split_link( $args ); |
| 2116 |
} |
| 2117 |
|
| 2118 |
/** |
| 2119 |
* Get split topic link |
| 2120 |
* |
| 2121 |
* Return the split link of the topic (but is bundled with each reply) |
| 2122 |
* |
| 2123 |
* @since 2.0.0 bbPress (r2756) |
| 2124 |
* |
| 2125 |
* @param array $args This function supports these arguments: |
| 2126 |
* - id: Reply id |
| 2127 |
* - link_before: HTML before the link |
| 2128 |
* - link_after: HTML after the link |
| 2129 |
* - split_text: Split text |
| 2130 |
* - split_title: Split title attribute |
| 2131 |
* @return string Topic split link |
| 2132 |
*/ |
| 2133 |
function bbp_get_topic_split_link( $args = array() ) { |
| 2134 |
|
| 2135 |
// Parse arguments against default values |
| 2136 |
$r = bbp_parse_args( $args, array( |
| 2137 |
'id' => 0, |
| 2138 |
'link_before' => '', |
| 2139 |
'link_after' => '', |
| 2140 |
'split_text' => esc_html__( 'Split', 'bbpress' ), |
| 2141 |
'split_title' => esc_attr__( 'Split the topic from this reply', 'bbpress' ) |
| 2142 |
), 'get_topic_split_link' ); |
| 2143 |
|
| 2144 |
// Get IDs |
| 2145 |
$reply_id = bbp_get_reply_id( $r['id'] ); |
| 2146 |
$topic_id = bbp_get_reply_topic_id( $reply_id ); |
| 2147 |
|
| 2148 |
// Bail if no reply/topic ID, or user cannot moderate |
| 2149 |
if ( empty( $reply_id ) || empty( $topic_id ) || ! current_user_can( 'moderate', $topic_id ) ) { |
| 2150 |
return; |
| 2151 |
} |
| 2152 |
|
| 2153 |
$uri = add_query_arg( array( |
| 2154 |
'action' => 'split', |
| 2155 |
'reply_id' => $reply_id |
| 2156 |
), bbp_get_topic_edit_url( $topic_id ) ); |
| 2157 |
|
| 2158 |
$retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" title="' . $r['split_title'] . '" class="bbp-topic-split-link">' . $r['split_text'] . '</a>' . $r['link_after']; |
| 2159 |
|
| 2160 |
// Filter & return |
| 2161 |
return apply_filters( 'bbp_get_topic_split_link', $retval, $r, $args ); |
| 2162 |
} |
| 2163 |
|
| 2164 |
/** |
| 2165 |
* Output the approve link of the reply |
| 2166 |
* |
| 2167 |
* @since 2.6.0 bbPress (r5507) |
| 2168 |
* |
| 2169 |
* @param array $args See {@link bbp_get_reply_approve_link()} |
| 2170 |
*/ |
| 2171 |
function bbp_reply_approve_link( $args = array() ) { |
| 2172 |
echo bbp_get_reply_approve_link( $args ); |
| 2173 |
} |
| 2174 |
|
| 2175 |
/** |
| 2176 |
* Return the approve link of the reply |
| 2177 |
* |
| 2178 |
* @since 2.6.0 bbPress (r5507) |
| 2179 |
* |
| 2180 |
* @param array $args This function supports these args: |
| 2181 |
* - id: Optional. Reply id |
| 2182 |
* - link_before: Before the link |
| 2183 |
* - link_after: After the link |
| 2184 |
* - sep: Separator between links |
| 2185 |
* - approve_text: Approve text |
| 2186 |
* - unapprove_text: Unapprove text |
| 2187 |
* @return string Reply approve link |
| 2188 |
*/ |
| 2189 |
function bbp_get_reply_approve_link( $args = array() ) { |
| 2190 |
|
| 2191 |
// Parse arguments against default values |
| 2192 |
$r = bbp_parse_args( $args, array( |
| 2193 |
'id' => 0, |
| 2194 |
'link_before' => '', |
| 2195 |
'link_after' => '', |
| 2196 |
'sep' => ' | ', |
| 2197 |
'approve_text' => _x( 'Approve', 'Pending Status', 'bbpress' ), |
| 2198 |
'unapprove_text' => _x( 'Unapprove', 'Pending Status', 'bbpress' ) |
| 2199 |
), 'get_reply_approve_link' ); |
| 2200 |
|
| 2201 |
// Get reply |
| 2202 |
$reply = bbp_get_reply( $r['id'] ); |
| 2203 |
|
| 2204 |
// Bail if no reply or current user cannot moderate |
| 2205 |
if ( empty( $reply ) || ! current_user_can( 'moderate', $reply->ID ) ) { |
| 2206 |
return; |
| 2207 |
} |
| 2208 |
|
| 2209 |
$display = bbp_is_reply_pending( $reply->ID ) ? $r['approve_text'] : $r['unapprove_text']; |
| 2210 |
$uri = add_query_arg( array( 'action' => 'bbp_toggle_reply_approve', 'reply_id' => $reply->ID ) ); |
| 2211 |
$uri = wp_nonce_url( $uri, 'approve-reply_' . $reply->ID ); |
| 2212 |
$retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-reply-approve-link">' . $display . '</a>' . $r['link_after']; |
| 2213 |
|
| 2214 |
// Filter & return |
| 2215 |
return apply_filters( 'bbp_get_reply_approve_link', $retval, $r, $args ); |
| 2216 |
} |
| 2217 |
|
| 2218 |
/** |
| 2219 |
* Output the row class of a reply |
| 2220 |
* |
| 2221 |
* @since 2.0.0 bbPress (r2678) |
| 2222 |
* |
| 2223 |
* @param int $reply_id Optional. Reply ID |
| 2224 |
* @param array Extra classes you can pass when calling this function |
| 2225 |
*/ |
| 2226 |
function bbp_reply_class( $reply_id = 0, $classes = array() ) { |
| 2227 |
echo bbp_get_reply_class( $reply_id, $classes ); |
| 2228 |
} |
| 2229 |
/** |
| 2230 |
* Return the row class of a reply |
| 2231 |
* |
| 2232 |
* @since 2.0.0 bbPress (r2678) |
| 2233 |
* |
| 2234 |
* @param int $reply_id Optional. Reply ID |
| 2235 |
* @param array Extra classes you can pass when calling this function |
| 2236 |
* @return string Row class of the reply |
| 2237 |
*/ |
| 2238 |
function bbp_get_reply_class( $reply_id = 0, $classes = array() ) { |
| 2239 |
$bbp = bbpress(); |
| 2240 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 2241 |
$topic_id = bbp_get_reply_topic_id( $reply_id ); |
| 2242 |
$forum_id = bbp_get_reply_forum_id( $reply_id ); |
| 2243 |
$author_id = bbp_get_reply_author_id( $reply_id ); |
| 2244 |
$reply_pos = bbp_get_reply_position( $reply_id, true ); |
| 2245 |
$classes = array_filter( (array) $classes ); |
| 2246 |
$count = isset( $bbp->reply_query->current_post ) |
| 2247 |
? (int) $bbp->reply_query->current_post |
| 2248 |
: 1; |
| 2249 |
|
| 2250 |
// Stripes |
| 2251 |
$even_odd = ( $count % 2 ) |
| 2252 |
? 'even' |
| 2253 |
: 'odd'; |
| 2254 |
|
| 2255 |
// Forum moderator replied to topic |
| 2256 |
$forum_moderator = ( bbp_is_user_forum_moderator( $author_id, $forum_id ) === $author_id ) |
| 2257 |
? 'forum-mod' |
| 2258 |
: ''; |
| 2259 |
|
| 2260 |
// Topic author replied to others |
| 2261 |
$topic_author = ( bbp_get_topic_author_id( $topic_id ) === $author_id ) |
| 2262 |
? 'topic-author' |
| 2263 |
: ''; |
| 2264 |
|
| 2265 |
// Get reply classes |
| 2266 |
$reply_classes = array( |
| 2267 |
'loop-item-' . $count, |
| 2268 |
'user-id-' . $author_id, |
| 2269 |
'bbp-parent-forum-' . $forum_id, |
| 2270 |
'bbp-parent-topic-' . $topic_id, |
| 2271 |
'bbp-reply-position-' . $reply_pos, |
| 2272 |
$even_odd, |
| 2273 |
$topic_author, |
| 2274 |
$forum_moderator |
| 2275 |
); |
| 2276 |
|
| 2277 |
// Run the topic classes through the post-class filters, which also |
| 2278 |
// handles the escaping of each individual class. |
| 2279 |
$post_classes = get_post_class( array_merge( $classes, $reply_classes ), $reply_id ); |
| 2280 |
|
| 2281 |
// Filter |
| 2282 |
$new_classes = apply_filters( 'bbp_get_reply_class', $post_classes, $reply_id, $classes ); |
| 2283 |
|
| 2284 |
// Return |
| 2285 |
return 'class="' . implode( ' ', $new_classes ) . '"'; |
| 2286 |
} |
| 2287 |
|
| 2288 |
/** Pagination ****************************************************************/ |
| 2289 |
|
| 2290 |
/** |
| 2291 |
* Return the base URL used inside of pagination links |
| 2292 |
* |
| 2293 |
* @since 2.6.0 bbPress (r6679) |
| 2294 |
* |
| 2295 |
* @param int $topic_id |
| 2296 |
* @return string |
| 2297 |
*/ |
| 2298 |
function bbp_get_replies_pagination_base( $topic_id = 0 ) { |
| 2299 |
|
| 2300 |
// If pretty permalinks are enabled, make our pagination pretty |
| 2301 |
if ( bbp_use_pretty_urls() && ! bbp_is_topic_pending( $topic_id )) { |
| 2302 |
|
| 2303 |
// User's replies |
| 2304 |
if ( bbp_is_single_user_replies() ) { |
| 2305 |
$base = bbp_get_user_replies_created_url( bbp_get_displayed_user_id() ); |
| 2306 |
|
| 2307 |
// Root profile page |
| 2308 |
} elseif ( bbp_is_single_user() ) { |
| 2309 |
$base = bbp_get_user_profile_url( bbp_get_displayed_user_id() ); |
| 2310 |
|
| 2311 |
// Any single post (for shortcodes) |
| 2312 |
} elseif ( is_singular() ) { |
| 2313 |
$base = get_permalink(); |
| 2314 |
|
| 2315 |
// Single topic |
| 2316 |
} else { |
| 2317 |
$base = get_permalink( $topic_id ); |
| 2318 |
} |
| 2319 |
|
| 2320 |
$base = trailingslashit( $base ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' ); |
| 2321 |
|
| 2322 |
// Unpretty permalinks |
| 2323 |
} else { |
| 2324 |
$base = add_query_arg( 'paged', '%#%' ); |
| 2325 |
} |
| 2326 |
|
| 2327 |
// Filter & return |
| 2328 |
return apply_filters( 'bbp_get_replies_pagination_base', $base, $topic_id ); |
| 2329 |
} |
| 2330 |
|
| 2331 |
/** |
| 2332 |
* Output the topic pagination count |
| 2333 |
* |
| 2334 |
* The results are unescaped by design, to allow them to be filtered freely via |
| 2335 |
* the 'bbp_get_topic_pagination_count' filter. |
| 2336 |
* |
| 2337 |
* @since 2.0.0 bbPress (r2519) |
| 2338 |
* |
| 2339 |
*/ |
| 2340 |
function bbp_topic_pagination_count() { |
| 2341 |
echo bbp_get_topic_pagination_count(); |
| 2342 |
} |
| 2343 |
/** |
| 2344 |
* Return the topic pagination count |
| 2345 |
* |
| 2346 |
* @since 2.0.0 bbPress (r2519) |
| 2347 |
* |
| 2348 |
* @return string Topic pagination count |
| 2349 |
*/ |
| 2350 |
function bbp_get_topic_pagination_count() { |
| 2351 |
$bbp = bbpress(); |
| 2352 |
|
| 2353 |
// Define local variable(s) |
| 2354 |
$retstr = ''; |
| 2355 |
|
| 2356 |
// Set pagination values |
| 2357 |
$count_int = intval( $bbp->reply_query->post_count ); |
| 2358 |
$total_int = intval( $bbp->reply_query->found_posts ); |
| 2359 |
$ppp_int = intval( $bbp->reply_query->posts_per_page ); |
| 2360 |
$start_int = intval( ( $bbp->reply_query->paged - 1 ) * $ppp_int ) + 1; |
| 2361 |
$to_int = intval( ( $start_int + ( $ppp_int - 1 ) > $total_int ) |
| 2362 |
? $total_int |
| 2363 |
: $start_int + ( $ppp_int - 1 ) ); |
| 2364 |
|
| 2365 |
// Format numbers for display |
| 2366 |
$count_num = bbp_number_format( $count_int ); |
| 2367 |
$total_num = bbp_number_format( $total_int ); |
| 2368 |
$from_num = bbp_number_format( $start_int ); |
| 2369 |
$to_num = bbp_number_format( $to_int ); |
| 2370 |
|
| 2371 |
// We are threading replies |
| 2372 |
if ( bbp_thread_replies() ) { |
| 2373 |
$walker = new BBP_Walker_Reply(); |
| 2374 |
$threads = absint( $walker->get_number_of_root_elements( $bbp->reply_query->posts ) - 1 ); |
| 2375 |
$retstr = sprintf( _n( 'Viewing %1$s reply thread', 'Viewing %1$s reply threads', $threads, 'bbpress' ), bbp_number_format( $threads ) ); |
| 2376 |
|
| 2377 |
// We are not including the lead topic |
| 2378 |
} elseif ( bbp_show_lead_topic() ) { |
| 2379 |
|
| 2380 |
// Several replies in a topic with a single page |
| 2381 |
if ( empty( $to_num ) ) { |
| 2382 |
$retstr = sprintf( _n( 'Viewing %1$s reply', 'Viewing %1$s replies', $total_int, 'bbpress' ), $total_num ); |
| 2383 |
|
| 2384 |
// Several replies in a topic with several pages |
| 2385 |
} else { |
| 2386 |
$retstr = sprintf( _n( 'Viewing %2$s replies (of %4$s total)', 'Viewing %1$s replies - %2$s through %3$s (of %4$s total)', $count_int, 'bbpress' ), $count_num, $from_num, $to_num, $total_num ); |
| 2387 |
} |
| 2388 |
|
| 2389 |
// We are including the lead topic |
| 2390 |
} else { |
| 2391 |
|
| 2392 |
// Several posts in a topic with a single page |
| 2393 |
if ( empty( $to_num ) ) { |
| 2394 |
$retstr = sprintf( _n( 'Viewing %1$s post', 'Viewing %1$s posts', $total_int, 'bbpress' ), $total_num ); |
| 2395 |
|
| 2396 |
// Several posts in a topic with several pages |
| 2397 |
} else { |
| 2398 |
$retstr = sprintf( _n( 'Viewing %2$s post (of %4$s total)', 'Viewing %1$s posts - %2$s through %3$s (of %4$s total)', $count_int, 'bbpress' ), $count_num, $from_num, $to_num, $total_num ); |
| 2399 |
} |
| 2400 |
} |
| 2401 |
|
| 2402 |
// Escape results of _n() |
| 2403 |
$retstr = esc_html( $retstr ); |
| 2404 |
|
| 2405 |
// Filter & return |
| 2406 |
return apply_filters( 'bbp_get_topic_pagination_count', $retstr ); |
| 2407 |
} |
| 2408 |
|
| 2409 |
/** |
| 2410 |
* Output topic pagination links |
| 2411 |
* |
| 2412 |
* @since 2.0.0 bbPress (r2519) |
| 2413 |
*/ |
| 2414 |
function bbp_topic_pagination_links() { |
| 2415 |
echo bbp_get_topic_pagination_links(); |
| 2416 |
} |
| 2417 |
/** |
| 2418 |
* Return topic pagination links |
| 2419 |
* |
| 2420 |
* @since 2.0.0 bbPress (r2519) |
| 2421 |
* |
| 2422 |
* @return string Topic pagination links |
| 2423 |
*/ |
| 2424 |
function bbp_get_topic_pagination_links() { |
| 2425 |
$bbp = bbpress(); |
| 2426 |
|
| 2427 |
if ( ! isset( $bbp->reply_query->pagination_links ) || empty( $bbp->reply_query->pagination_links ) ) { |
| 2428 |
return false; |
| 2429 |
} |
| 2430 |
|
| 2431 |
// Filter & return |
| 2432 |
return apply_filters( 'bbp_get_topic_pagination_links', $bbp->reply_query->pagination_links ); |
| 2433 |
} |
| 2434 |
|
| 2435 |
/** Forms *********************************************************************/ |
| 2436 |
|
| 2437 |
/** |
| 2438 |
* Output the value of reply content field |
| 2439 |
* |
| 2440 |
* @since 2.0.0 bbPress (r3130) |
| 2441 |
*/ |
| 2442 |
function bbp_form_reply_content() { |
| 2443 |
echo bbp_get_form_reply_content(); |
| 2444 |
} |
| 2445 |
/** |
| 2446 |
* Return the value of reply content field |
| 2447 |
* |
| 2448 |
* @since 2.0.0 bbPress (r3130) |
| 2449 |
* |
| 2450 |
* @return string Value of reply content field |
| 2451 |
*/ |
| 2452 |
function bbp_get_form_reply_content() { |
| 2453 |
|
| 2454 |
// Get _POST data |
| 2455 |
if ( bbp_is_reply_form_post_request() && isset( $_POST['bbp_reply_content'] ) ) { |
| 2456 |
$reply_content = wp_unslash( $_POST['bbp_reply_content'] ); |
| 2457 |
|
| 2458 |
// Get edit data |
| 2459 |
} elseif ( bbp_is_reply_edit() ) { |
| 2460 |
$reply_content = bbp_get_global_post_field( 'post_content', 'raw' ); |
| 2461 |
|
| 2462 |
// No data |
| 2463 |
} else { |
| 2464 |
$reply_content = ''; |
| 2465 |
} |
| 2466 |
|
| 2467 |
// Filter & return |
| 2468 |
return apply_filters( 'bbp_get_form_reply_content', $reply_content ); |
| 2469 |
} |
| 2470 |
|
| 2471 |
/** |
| 2472 |
* Output the value of the reply to field |
| 2473 |
* |
| 2474 |
* @since 2.4.0 bbPress (r4944) |
| 2475 |
*/ |
| 2476 |
function bbp_form_reply_to() { |
| 2477 |
echo bbp_get_form_reply_to(); |
| 2478 |
} |
| 2479 |
|
| 2480 |
/** |
| 2481 |
* Return the value of reply to field |
| 2482 |
* |
| 2483 |
* @since 2.4.0 bbPress (r4944) |
| 2484 |
* |
| 2485 |
* @return string Value of reply to field |
| 2486 |
*/ |
| 2487 |
function bbp_get_form_reply_to() { |
| 2488 |
|
| 2489 |
// Set initial value |
| 2490 |
$reply_to = 0; |
| 2491 |
|
| 2492 |
// Get $_REQUEST data |
| 2493 |
if ( isset( $_REQUEST['bbp_reply_to'] ) ) { |
| 2494 |
$reply_to = bbp_validate_reply_to( $_REQUEST['bbp_reply_to'] ); |
| 2495 |
} |
| 2496 |
|
| 2497 |
// If empty, get from meta |
| 2498 |
if ( empty( $reply_to ) ) { |
| 2499 |
$reply_to = bbp_get_reply_to(); |
| 2500 |
} |
| 2501 |
|
| 2502 |
// Filter & return |
| 2503 |
return apply_filters( 'bbp_get_form_reply_to', $reply_to ); |
| 2504 |
} |
| 2505 |
|
| 2506 |
/** |
| 2507 |
* Output a select box allowing to pick which reply an existing hierarchical |
| 2508 |
* reply belongs to. |
| 2509 |
* |
| 2510 |
* @since 2.6.0 bbPress (r5387) |
| 2511 |
* |
| 2512 |
* @param int $reply_id |
| 2513 |
*/ |
| 2514 |
function bbp_reply_to_dropdown( $reply_id = 0 ) { |
| 2515 |
echo bbp_get_reply_to_dropdown( $reply_id ); |
| 2516 |
} |
| 2517 |
/** |
| 2518 |
* Return a select box allowing to pick which topic/reply a reply belongs. |
| 2519 |
* |
| 2520 |
* @since 2.6.0 bbPress (r5387) |
| 2521 |
* |
| 2522 |
* @param int $reply_id |
| 2523 |
* |
| 2524 |
* @return string The dropdown |
| 2525 |
*/ |
| 2526 |
function bbp_get_reply_to_dropdown( $reply_id = 0 ) { |
| 2527 |
|
| 2528 |
// Validate the reply data |
| 2529 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 2530 |
$reply_to = bbp_get_reply_to( $reply_id ); |
| 2531 |
$topic_id = bbp_get_reply_topic_id( $reply_id ); |
| 2532 |
|
| 2533 |
// Get the replies |
| 2534 |
$posts = get_posts( array( |
| 2535 |
'post_type' => bbp_get_reply_post_type(), |
| 2536 |
'post_status' => bbp_get_public_status_id(), |
| 2537 |
'post_parent' => $topic_id, |
| 2538 |
'numberposts' => -1, |
| 2539 |
'orderby' => 'menu_order', |
| 2540 |
'order' => 'ASC', |
| 2541 |
) ); |
| 2542 |
|
| 2543 |
// Append `reply_to` for each reply so it can be walked |
| 2544 |
foreach ( $posts as &$post ) { |
| 2545 |
|
| 2546 |
// Check for reply post type |
| 2547 |
$_reply_to = bbp_get_reply_to( $post->ID ); |
| 2548 |
|
| 2549 |
// Make sure it's a reply to a reply |
| 2550 |
if ( empty( $_reply_to ) || ( $topic_id === $_reply_to ) ) { |
| 2551 |
$_reply_to = 0; |
| 2552 |
} |
| 2553 |
|
| 2554 |
// Add reply_to to the post object so we can walk it later |
| 2555 |
$post->reply_to = $_reply_to; |
| 2556 |
} |
| 2557 |
|
| 2558 |
// Default "None" text |
| 2559 |
$show_none = ( 0 === $reply_id ) |
| 2560 |
? esc_attr_x( 'None', 'Default reply to dropdown text', 'bbpress' ) |
| 2561 |
: sprintf( esc_attr__( '%1$s - %2$s', 'bbpress' ), $topic_id, bbp_get_topic_title( $topic_id ) ); |
| 2562 |
|
| 2563 |
// Get the dropdown and return it |
| 2564 |
$retval = bbp_get_dropdown( array( |
| 2565 |
'show_none' => $show_none, |
| 2566 |
'select_id' => 'bbp_reply_to', |
| 2567 |
'select_class' => 'bbp_dropdown', |
| 2568 |
'exclude' => $reply_id, |
| 2569 |
'selected' => $reply_to, |
| 2570 |
'post_parent' => $topic_id, |
| 2571 |
'post_type' => bbp_get_reply_post_type(), |
| 2572 |
'max_depth' => bbp_thread_replies_depth(), |
| 2573 |
'page' => 1, |
| 2574 |
'per_page' => -1, |
| 2575 |
'walker' => new BBP_Walker_Reply_Dropdown(), |
| 2576 |
'posts' => $posts |
| 2577 |
) ); |
| 2578 |
|
| 2579 |
// Filter & return |
| 2580 |
return apply_filters( 'bbp_get_reply_to_dropdown', $retval, $reply_id, $reply_to, $topic_id ); |
| 2581 |
} |
| 2582 |
|
| 2583 |
/** |
| 2584 |
* Output checked value of reply log edit field |
| 2585 |
* |
| 2586 |
* @since 2.0.0 bbPress (r3130) |
| 2587 |
*/ |
| 2588 |
function bbp_form_reply_log_edit() { |
| 2589 |
echo bbp_get_form_reply_log_edit(); |
| 2590 |
} |
| 2591 |
/** |
| 2592 |
* Return checked value of reply log edit field |
| 2593 |
* |
| 2594 |
* @since 2.0.0 bbPress (r3130) |
| 2595 |
* |
| 2596 |
* @return string Reply log edit checked value |
| 2597 |
*/ |
| 2598 |
function bbp_get_form_reply_log_edit() { |
| 2599 |
|
| 2600 |
// Get _POST data |
| 2601 |
if ( bbp_is_reply_form_post_request() && isset( $_POST['bbp_log_reply_edit'] ) ) { |
| 2602 |
$reply_revision = (bool) $_POST['bbp_log_reply_edit']; |
| 2603 |
|
| 2604 |
// No data |
| 2605 |
} else { |
| 2606 |
$reply_revision = true; |
| 2607 |
} |
| 2608 |
|
| 2609 |
// Get checked output |
| 2610 |
$checked = checked( $reply_revision, true, false ); |
| 2611 |
|
| 2612 |
// Filter & return |
| 2613 |
return apply_filters( 'bbp_get_form_reply_log_edit', $checked, $reply_revision ); |
| 2614 |
} |
| 2615 |
|
| 2616 |
/** |
| 2617 |
* Output the value of the reply edit reason |
| 2618 |
* |
| 2619 |
* @since 2.0.0 bbPress (r3130) |
| 2620 |
*/ |
| 2621 |
function bbp_form_reply_edit_reason() { |
| 2622 |
echo bbp_get_form_reply_edit_reason(); |
| 2623 |
} |
| 2624 |
/** |
| 2625 |
* Return the value of the reply edit reason |
| 2626 |
* |
| 2627 |
* @since 2.0.0 bbPress (r3130) |
| 2628 |
* |
| 2629 |
* @return string Reply edit reason value |
| 2630 |
*/ |
| 2631 |
function bbp_get_form_reply_edit_reason() { |
| 2632 |
|
| 2633 |
// Get _POST data |
| 2634 |
if ( bbp_is_reply_form_post_request() && isset( $_POST['bbp_reply_edit_reason'] ) ) { |
| 2635 |
$reply_edit_reason = wp_unslash( $_POST['bbp_reply_edit_reason'] ); |
| 2636 |
|
| 2637 |
// No data |
| 2638 |
} else { |
| 2639 |
$reply_edit_reason = ''; |
| 2640 |
} |
| 2641 |
|
| 2642 |
// Filter & return |
| 2643 |
return apply_filters( 'bbp_get_form_reply_edit_reason', $reply_edit_reason ); |
| 2644 |
} |
| 2645 |
|
| 2646 |
/** |
| 2647 |
* Output value reply status dropdown |
| 2648 |
* |
| 2649 |
* @since 2.6.0 bbPress (r5399) |
| 2650 |
* |
| 2651 |
* @param $args This function supports these arguments: |
| 2652 |
* - select_id: Select id. Defaults to bbp_reply_status |
| 2653 |
* - tab: Deprecated. Tabindex |
| 2654 |
* - reply_id: Reply id |
| 2655 |
* - selected: Override the selected option |
| 2656 |
*/ |
| 2657 |
function bbp_form_reply_status_dropdown( $args = array() ) { |
| 2658 |
echo bbp_get_form_reply_status_dropdown( $args ); |
| 2659 |
} |
| 2660 |
/** |
| 2661 |
* Returns reply status dropdown |
| 2662 |
* |
| 2663 |
* This dropdown is only intended to be seen by users with the 'moderate' |
| 2664 |
* capability. Because of this, no additional capability checks are performed |
| 2665 |
* within this function to check available reply statuses. |
| 2666 |
* |
| 2667 |
* @since 2.6.0 bbPress (r5399) |
| 2668 |
* |
| 2669 |
* @param $args This function supports these arguments: |
| 2670 |
* - select_id: Select id. Defaults to bbp_reply_status |
| 2671 |
* - tab: Deprecated. Tabindex |
| 2672 |
* - reply_id: Reply id |
| 2673 |
* - selected: Override the selected option |
| 2674 |
*/ |
| 2675 |
function bbp_get_form_reply_status_dropdown( $args = array() ) { |
| 2676 |
|
| 2677 |
// Parse arguments against default values |
| 2678 |
$r = bbp_parse_args( $args, array( |
| 2679 |
'select_id' => 'bbp_reply_status', |
| 2680 |
'select_class' => 'bbp_dropdown', |
| 2681 |
'tab' => false, |
| 2682 |
'reply_id' => 0, |
| 2683 |
'selected' => false |
| 2684 |
), 'reply_status_dropdown' ); |
| 2685 |
|
| 2686 |
// No specific selected value passed |
| 2687 |
if ( empty( $r['selected'] ) ) { |
| 2688 |
|
| 2689 |
// Post value is passed |
| 2690 |
if ( bbp_is_reply_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) { |
| 2691 |
$r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] ); |
| 2692 |
|
| 2693 |
// No Post value was passed |
| 2694 |
} else { |
| 2695 |
|
| 2696 |
// Edit reply |
| 2697 |
if ( bbp_is_reply_edit() ) { |
| 2698 |
$r['reply_id'] = bbp_get_reply_id( $r['reply_id'] ); |
| 2699 |
$r['selected'] = bbp_get_reply_status( $r['reply_id'] ); |
| 2700 |
|
| 2701 |
// New reply |
| 2702 |
} else { |
| 2703 |
$r['selected'] = bbp_get_public_status_id(); |
| 2704 |
} |
| 2705 |
} |
| 2706 |
} |
| 2707 |
|
| 2708 |
// Start an output buffer, we'll finish it after the select loop |
| 2709 |
ob_start(); ?> |
| 2710 |
|
| 2711 |
<select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>> |
| 2712 |
|
| 2713 |
<?php foreach ( bbp_get_reply_statuses( $r['reply_id'] ) as $key => $label ) : ?> |
| 2714 |
|
| 2715 |
<option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option> |
| 2716 |
|
| 2717 |
<?php endforeach; ?> |
| 2718 |
|
| 2719 |
</select> |
| 2720 |
|
| 2721 |
<?php |
| 2722 |
|
| 2723 |
// Filter & return |
| 2724 |
return apply_filters( 'bbp_get_form_reply_status_dropdown', ob_get_clean(), $r, $args ); |
| 2725 |
} |
| 2726 |
|
| 2727 |
/** |
| 2728 |
* Verify if a POST request came from a failed reply attempt. |
| 2729 |
* |
| 2730 |
* Used to avoid cross-site request forgeries when checking posted reply form |
| 2731 |
* content. |
| 2732 |
* |
| 2733 |
* @see bbp_reply_form_fields() |
| 2734 |
* |
| 2735 |
* @since 2.6.0 bbPress (r5558) |
| 2736 |
* |
| 2737 |
* @return boolean True if is a post request with valid nonce |
| 2738 |
*/ |
| 2739 |
function bbp_is_reply_form_post_request() { |
| 2740 |
|
| 2741 |
// Bail if not a post request |
| 2742 |
if ( ! bbp_is_post_request() ) { |
| 2743 |
return false; |
| 2744 |
} |
| 2745 |
|
| 2746 |
// Creating a new reply |
| 2747 |
if ( bbp_verify_nonce_request( 'bbp-new-reply' ) ) { |
| 2748 |
return true; |
| 2749 |
} |
| 2750 |
|
| 2751 |
// Editing an existing reply |
| 2752 |
if ( bbp_verify_nonce_request( 'bbp-edit-reply' ) ) { |
| 2753 |
return true; |
| 2754 |
} |
| 2755 |
|
| 2756 |
return false; |
| 2757 |
} |
| 2758 |
|