| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* bbPress Reply Template Tags |
| 5 |
* |
| 6 |
* @package bbPress |
| 7 |
* @subpackage TemplateTags |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly |
| 11 |
if ( !defined( 'ABSPATH' ) ) exit; |
| 12 |
|
| 13 |
/** Post Type *****************************************************************/ |
| 14 |
|
| 15 |
/** |
| 16 |
* Return the unique id of the custom post type for replies |
| 17 |
* |
| 18 |
* @since bbPress (r2857) |
| 19 |
* |
| 20 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 21 |
*/ |
| 22 |
function bbp_reply_post_type() { |
| 23 |
echo bbp_get_reply_post_type(); |
| 24 |
} |
| 25 |
/** |
| 26 |
* Return the unique id of the custom post type for replies |
| 27 |
* |
| 28 |
* @since bbPress (r2857) |
| 29 |
* |
| 30 |
* @uses apply_filters() Calls 'bbp_get_forum_post_type' with the forum |
| 31 |
* post type id |
| 32 |
* @return string The unique reply post type id |
| 33 |
*/ |
| 34 |
function bbp_get_reply_post_type() { |
| 35 |
global $bbp; |
| 36 |
|
| 37 |
return apply_filters( 'bbp_get_reply_post_type', $bbp->reply_post_type ); |
| 38 |
} |
| 39 |
|
| 40 |
/** Reply Loop Functions ******************************************************/ |
| 41 |
|
| 42 |
/** |
| 43 |
* The main reply loop. WordPress makes this easy for us |
| 44 |
* |
| 45 |
* @since bbPress (r2553) |
| 46 |
* |
| 47 |
* @param mixed $args All the arguments supported by {@link WP_Query} |
| 48 |
* @uses bbp_show_lead_topic() Are we showing the topic as a lead? |
| 49 |
* @uses bbp_get_topic_id() To get the topic id |
| 50 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 51 |
* @uses bbp_get_topic_post_type() To get the topic post type |
| 52 |
* @uses bbp_is_query_name() To check if we are getting replies for a widget |
| 53 |
* @uses get_option() To get the replies per page option |
| 54 |
* @uses bbp_get_paged() To get the current page value |
| 55 |
* @uses current_user_can() To check if the current user is capable of editing |
| 56 |
* others' replies |
| 57 |
* @uses WP_Query To make query and get the replies |
| 58 |
* @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks |
| 59 |
* @uses get_permalink() To get the permalink |
| 60 |
* @uses add_query_arg() To add custom args to the url |
| 61 |
* @uses apply_filters() Calls 'bbp_replies_pagination' with the pagination args |
| 62 |
* @uses paginate_links() To paginate the links |
| 63 |
* @uses apply_filters() Calls 'bbp_has_replies' with |
| 64 |
* bbPres::reply_query::have_posts() |
| 65 |
* and bbPres::reply_query |
| 66 |
* @return object Multidimensional array of reply information |
| 67 |
*/ |
| 68 |
function bbp_has_replies( $args = '' ) { |
| 69 |
global $wp_rewrite, $bbp; |
| 70 |
|
| 71 |
// Default status |
| 72 |
$default_status = join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ); |
| 73 |
|
| 74 |
// Skip topic_id if in the replies widget query |
| 75 |
if ( !bbp_is_query_name( 'bbp_widget' ) ) { |
| 76 |
$parent_args['meta_query'] = array( |
| 77 |
array( |
| 78 |
'key' => '_bbp_topic_id', |
| 79 |
'value' => bbp_get_topic_id(), |
| 80 |
'compare' => '=' |
| 81 |
) |
| 82 |
); |
| 83 |
|
| 84 |
// What are the default allowed statuses (based on user caps) |
| 85 |
if ( bbp_get_view_all( 'edit_others_replies' ) ) { |
| 86 |
$default_status = join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
// Default query args |
| 91 |
$default = array( |
| 92 |
|
| 93 |
// Post type(s) depending on bbp_show_lead_topic() |
| 94 |
'post_type' => bbp_show_lead_topic() ? bbp_get_reply_post_type() : array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ), |
| 95 |
|
| 96 |
// 'author', 'date', 'title', 'modified', 'parent', rand', |
| 97 |
'orderby' => 'date', |
| 98 |
|
| 99 |
// 'ASC', 'DESC' |
| 100 |
'order' => 'ASC', |
| 101 |
|
| 102 |
// Max number |
| 103 |
'posts_per_page' => bbp_get_replies_per_page(), |
| 104 |
|
| 105 |
// Page Number |
| 106 |
'paged' => bbp_get_paged(), |
| 107 |
|
| 108 |
// Reply Search |
| 109 |
's' => !empty( $_REQUEST['rs'] ) ? $_REQUEST['rs'] : '', |
| 110 |
|
| 111 |
// Post Status |
| 112 |
'post_status' => $default_status |
| 113 |
); |
| 114 |
|
| 115 |
// Merge the default args and parent args together |
| 116 |
if ( isset( $parent_args ) ) |
| 117 |
$default = array_merge( $parent_args, $default ); |
| 118 |
|
| 119 |
// Set up topic variables |
| 120 |
$bbp_r = wp_parse_args( $args, $default ); |
| 121 |
|
| 122 |
// Filter the replies query to allow just-in-time modifications |
| 123 |
$bbp_r = apply_filters( 'bbp_has_replies_query', $bbp_r ); |
| 124 |
|
| 125 |
// Extract the query variables |
| 126 |
extract( $bbp_r ); |
| 127 |
|
| 128 |
// Call the query |
| 129 |
$bbp->reply_query = new WP_Query( $bbp_r ); |
| 130 |
|
| 131 |
// Add pagination values to query object |
| 132 |
$bbp->reply_query->posts_per_page = $posts_per_page; |
| 133 |
$bbp->reply_query->paged = $paged; |
| 134 |
|
| 135 |
// Only add pagination if query returned results |
| 136 |
if ( !bbp_is_query_name( 'bbp_widget' ) && (int) $bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page ) { |
| 137 |
|
| 138 |
// If pretty permalinks are enabled, make our pagination pretty |
| 139 |
if ( $wp_rewrite->using_permalinks() ) { |
| 140 |
|
| 141 |
// Page or single |
| 142 |
if ( is_page() || is_single() ) { |
| 143 |
$base = get_permalink(); |
| 144 |
|
| 145 |
// Topic |
| 146 |
} else { |
| 147 |
$base = get_permalink( bbp_get_topic_id() ); |
| 148 |
} |
| 149 |
|
| 150 |
$base = trailingslashit( $base ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' ); |
| 151 |
|
| 152 |
// Unpretty permalinks |
| 153 |
} else { |
| 154 |
$base = add_query_arg( 'paged', '%#%' ); |
| 155 |
} |
| 156 |
|
| 157 |
// Pagination settings with filter |
| 158 |
$bbp_replies_pagination = apply_filters( 'bbp_replies_pagination', array( |
| 159 |
'base' => $base, |
| 160 |
'format' => '', |
| 161 |
'total' => ceil( (int) $bbp->reply_query->found_posts / (int) $posts_per_page ), |
| 162 |
'current' => (int) $bbp->reply_query->paged, |
| 163 |
'prev_text' => '←', |
| 164 |
'next_text' => '→', |
| 165 |
'mid_size' => 1, |
| 166 |
'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false |
| 167 |
) ); |
| 168 |
|
| 169 |
// Add pagination to query object |
| 170 |
$bbp->reply_query->pagination_links = paginate_links( $bbp_replies_pagination ); |
| 171 |
|
| 172 |
// Remove first page from pagination |
| 173 |
if ( $wp_rewrite->using_permalinks() ) |
| 174 |
$bbp->reply_query->pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $bbp->reply_query->pagination_links ); |
| 175 |
else |
| 176 |
$bbp->reply_query->pagination_links = str_replace( '&paged=1', '', $bbp->reply_query->pagination_links ); |
| 177 |
} |
| 178 |
|
| 179 |
// Return object |
| 180 |
return apply_filters( 'bbp_has_replies', $bbp->reply_query->have_posts(), $bbp->reply_query ); |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* Whether there are more replies available in the loop |
| 185 |
* |
| 186 |
* @since bbPress (r2553) |
| 187 |
* |
| 188 |
* @uses WP_Query bbPress::reply_query::have_posts() To check if there are more |
| 189 |
* replies available |
| 190 |
* @return object Replies information |
| 191 |
*/ |
| 192 |
function bbp_replies() { |
| 193 |
global $bbp; |
| 194 |
|
| 195 |
// Put into variable to check against next |
| 196 |
$have_posts = $bbp->reply_query->have_posts(); |
| 197 |
|
| 198 |
// Reset the post data when finished |
| 199 |
if ( empty( $have_posts ) ) |
| 200 |
wp_reset_postdata(); |
| 201 |
|
| 202 |
return $have_posts; |
| 203 |
} |
| 204 |
|
| 205 |
/** |
| 206 |
* Loads up the current reply in the loop |
| 207 |
* |
| 208 |
* @since bbPress (r2553) |
| 209 |
* |
| 210 |
* @uses WP_Query bbPress::reply_query::the_post() To get the current reply |
| 211 |
* @return object Reply information |
| 212 |
*/ |
| 213 |
function bbp_the_reply() { |
| 214 |
global $bbp; |
| 215 |
return $bbp->reply_query->the_post(); |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* Output reply id |
| 220 |
* |
| 221 |
* @since bbPress (r2553) |
| 222 |
* |
| 223 |
* @param $reply_id Optional. Used to check emptiness |
| 224 |
* @uses bbp_get_reply_id() To get the reply id |
| 225 |
*/ |
| 226 |
function bbp_reply_id( $reply_id = 0 ) { |
| 227 |
echo bbp_get_reply_id( $reply_id ); |
| 228 |
} |
| 229 |
/** |
| 230 |
* Return the id of the reply in a replies loop |
| 231 |
* |
| 232 |
* @since bbPress (r2553) |
| 233 |
* |
| 234 |
* @param $reply_id Optional. Used to check emptiness |
| 235 |
* @uses bbPress::reply_query::post::ID To get the reply id |
| 236 |
* @uses bbp_is_reply() To check if it's a reply page |
| 237 |
* @uses bbp_is_reply_edit() To check if it's a reply edit page |
| 238 |
* @uses get_post_field() To get the post's post type |
| 239 |
* @uses WP_Query::post::ID To get the reply id |
| 240 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 241 |
* @uses apply_filters() Calls 'bbp_get_reply_id' with the reply id and |
| 242 |
* supplied reply id |
| 243 |
* @return int The reply id |
| 244 |
*/ |
| 245 |
function bbp_get_reply_id( $reply_id = 0 ) { |
| 246 |
global $bbp, $wp_query; |
| 247 |
|
| 248 |
// Easy empty checking |
| 249 |
if ( !empty( $reply_id ) && is_numeric( $reply_id ) ) |
| 250 |
$bbp_reply_id = $reply_id; |
| 251 |
|
| 252 |
// Currently inside a replies loop |
| 253 |
elseif ( isset( $bbp->reply_query->post->ID ) ) |
| 254 |
$bbp_reply_id = $bbp->current_reply_id = $bbp->reply_query->post->ID; |
| 255 |
|
| 256 |
// Currently viewing a reply |
| 257 |
elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && isset( $wp_query->post->ID ) ) |
| 258 |
$bbp_reply_id = $bbp->current_reply_id = $wp_query->post->ID; |
| 259 |
|
| 260 |
// Fallback |
| 261 |
else |
| 262 |
$bbp_reply_id = 0; |
| 263 |
|
| 264 |
// Check if current_reply_id is set, and check post_type if so |
| 265 |
if ( !empty( $bbp->current_reply_id ) && ( bbp_get_reply_post_type() != get_post_field( 'post_type', $bbp_reply_id ) ) ) |
| 266 |
$bbp->current_reply_id = null; |
| 267 |
|
| 268 |
return apply_filters( 'bbp_get_reply_id', (int) $bbp_reply_id, $reply_id ); |
| 269 |
} |
| 270 |
|
| 271 |
/** |
| 272 |
* Gets a reply |
| 273 |
* |
| 274 |
* @since bbPress (r2787) |
| 275 |
* |
| 276 |
* @param int|object $reply reply id or reply object |
| 277 |
* @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT |
| 278 |
* @param string $filter Optional Sanitation filter. See {@link sanitize_post()} |
| 279 |
* @uses get_post() To get the reply |
| 280 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 281 |
* @uses apply_filters() Calls 'bbp_get_reply' with the reply, output type and |
| 282 |
* sanitation filter |
| 283 |
* @return mixed Null if error or reply (in specified form) if success |
| 284 |
*/ |
| 285 |
function bbp_get_reply( $reply, $output = OBJECT, $filter = 'raw' ) { |
| 286 |
if ( empty( $reply ) || is_numeric( $reply ) ) |
| 287 |
$reply = bbp_get_reply_id( $reply ); |
| 288 |
|
| 289 |
if ( !$reply = get_post( $reply, OBJECT, $filter ) ) |
| 290 |
return $reply; |
| 291 |
|
| 292 |
if ( $reply->post_type !== bbp_get_reply_post_type() ) |
| 293 |
return null; |
| 294 |
|
| 295 |
if ( $output == OBJECT ) { |
| 296 |
return $reply; |
| 297 |
|
| 298 |
} elseif ( $output == ARRAY_A ) { |
| 299 |
$_reply = get_object_vars( $reply ); |
| 300 |
return $_reply; |
| 301 |
|
| 302 |
} elseif ( $output == ARRAY_N ) { |
| 303 |
$_reply = array_values( get_object_vars( $reply ) ); |
| 304 |
return $_reply; |
| 305 |
|
| 306 |
} |
| 307 |
|
| 308 |
return apply_filters( 'bbp_get_reply', $reply, $output, $filter ); |
| 309 |
} |
| 310 |
|
| 311 |
/** |
| 312 |
* Output the link to the reply in the reply loop |
| 313 |
* |
| 314 |
* @since bbPress (r2553) |
| 315 |
* |
| 316 |
* @param int $reply_id Optional. Reply id |
| 317 |
* @uses bbp_get_reply_permalink() To get the reply permalink |
| 318 |
*/ |
| 319 |
function bbp_reply_permalink( $reply_id = 0 ) { |
| 320 |
echo bbp_get_reply_permalink( $reply_id ); |
| 321 |
} |
| 322 |
/** |
| 323 |
* Return the link to the reply |
| 324 |
* |
| 325 |
* @since bbPress (r2553) |
| 326 |
* |
| 327 |
* @param int $reply_id Optional. Reply id |
| 328 |
* @uses bbp_get_reply_id() To get the reply id |
| 329 |
* @uses get_permalink() To get the permalink of the reply |
| 330 |
* @uses apply_filters() Calls 'bbp_get_reply_permalink' with the link |
| 331 |
* and reply id |
| 332 |
* @return string Permanent link to reply |
| 333 |
*/ |
| 334 |
function bbp_get_reply_permalink( $reply_id = 0 ) { |
| 335 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 336 |
|
| 337 |
return apply_filters( 'bbp_get_reply_permalink', get_permalink( $reply_id ), $reply_id ); |
| 338 |
} |
| 339 |
/** |
| 340 |
* Output the paginated url to the reply in the reply loop |
| 341 |
* |
| 342 |
* @since bbPress (r2679) |
| 343 |
* |
| 344 |
* @param int $reply_id Optional. Reply id |
| 345 |
* @uses bbp_get_reply_url() To get the reply url |
| 346 |
*/ |
| 347 |
function bbp_reply_url( $reply_id = 0 ) { |
| 348 |
echo bbp_get_reply_url( $reply_id ); |
| 349 |
} |
| 350 |
/** |
| 351 |
* Return the paginated url to the reply in the reply loop |
| 352 |
* |
| 353 |
* @since bbPress (r2679) |
| 354 |
* |
| 355 |
* @param int $reply_id Optional. Reply id |
| 356 |
* @param $string $redirect_to Optional. Pass a redirect value for use with |
| 357 |
* shortcodes and other fun things. |
| 358 |
* @uses bbp_get_reply_id() To get the reply id |
| 359 |
* @uses bbp_get_reply_topic_id() To get the reply topic id |
| 360 |
* @uses bbp_get_topic_permalink() To get the topic permalink |
| 361 |
* @uses bbp_get_reply_position() To get the reply position |
| 362 |
* @uses get_option() To get the replies per page option |
| 363 |
* @uses WP_Rewrite::using_permalinks() To check if the blog uses |
| 364 |
* permalinks |
| 365 |
* @uses add_query_arg() To add custom args to the url |
| 366 |
* @uses apply_filters() Calls 'bbp_get_reply_url' with the reply url, |
| 367 |
* reply id and bool count hidden |
| 368 |
* @return string Link to reply relative to paginated topic |
| 369 |
*/ |
| 370 |
function bbp_get_reply_url( $reply_id = 0, $redirect_to = '' ) { |
| 371 |
global $wp_rewrite; |
| 372 |
|
| 373 |
// Set needed variables |
| 374 |
$reply_id = bbp_get_reply_id ( $reply_id ); |
| 375 |
$topic_id = bbp_get_reply_topic_id ( $reply_id ); |
| 376 |
$topic_url = bbp_get_topic_permalink( $topic_id, $redirect_to ); |
| 377 |
$reply_position = bbp_get_reply_position ( $reply_id, $topic_id ); |
| 378 |
|
| 379 |
// Check if in query with pagination |
| 380 |
$reply_page = ceil( (int) $reply_position / (int) bbp_get_replies_per_page() ); |
| 381 |
|
| 382 |
// Hash to add to end of URL |
| 383 |
$reply_hash = '#post-' . $reply_id; |
| 384 |
|
| 385 |
// Remove the topic view query arg if its set |
| 386 |
$topic_url = remove_query_arg( 'view', $topic_url ); |
| 387 |
|
| 388 |
// Don't include pagination if on first page |
| 389 |
if ( 1 >= $reply_page ) { |
| 390 |
$url = trailingslashit( $topic_url ) . $reply_hash; |
| 391 |
|
| 392 |
// Include pagination |
| 393 |
} else { |
| 394 |
|
| 395 |
// Pretty permalinks |
| 396 |
if ( $wp_rewrite->using_permalinks() ) { |
| 397 |
$url = trailingslashit( $topic_url ) . trailingslashit( $wp_rewrite->pagination_base ) . trailingslashit( $reply_page ) . $reply_hash; |
| 398 |
|
| 399 |
// Yucky links |
| 400 |
} else { |
| 401 |
$url = add_query_arg( 'paged', $reply_page, $topic_url ) . $reply_hash; |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
// Add topic view query arg back to end if it is set |
| 406 |
if ( bbp_get_view_all() ) |
| 407 |
$url = bbp_add_view_all( $url ); |
| 408 |
|
| 409 |
return apply_filters( 'bbp_get_reply_url', $url, $reply_id, $redirect_to ); |
| 410 |
} |
| 411 |
|
| 412 |
/** |
| 413 |
* Output the title of the reply |
| 414 |
* |
| 415 |
* @since bbPress (r2553) |
| 416 |
* |
| 417 |
* @param int $reply_id Optional. Reply id |
| 418 |
* @uses bbp_get_reply_title() To get the reply title |
| 419 |
*/ |
| 420 |
function bbp_reply_title( $reply_id = 0 ) { |
| 421 |
echo bbp_get_reply_title( $reply_id ); |
| 422 |
} |
| 423 |
|
| 424 |
/** |
| 425 |
* Return the title of the reply |
| 426 |
* |
| 427 |
* @since bbPress (r2553) |
| 428 |
* |
| 429 |
* @param int $reply_id Optional. Reply id |
| 430 |
* @uses bbp_get_reply_id() To get the reply id |
| 431 |
* @uses get_the_title() To get the reply title |
| 432 |
* @uses apply_filters() Calls 'bbp_get_reply_title' with the title and |
| 433 |
* reply id |
| 434 |
* @return string Title of reply |
| 435 |
*/ |
| 436 |
function bbp_get_reply_title( $reply_id = 0 ) { |
| 437 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 438 |
|
| 439 |
return apply_filters( 'bbp_get_reply_title', get_the_title( $reply_id ), $reply_id ); |
| 440 |
} |
| 441 |
|
| 442 |
/** |
| 443 |
* Output the content of the reply |
| 444 |
* |
| 445 |
* @since bbPress (r2553) |
| 446 |
* |
| 447 |
* @param int $reply_id Optional. reply id |
| 448 |
* @uses bbp_get_reply_content() To get the reply content |
| 449 |
*/ |
| 450 |
function bbp_reply_content( $reply_id = 0 ) { |
| 451 |
echo bbp_get_reply_content( $reply_id ); |
| 452 |
} |
| 453 |
/** |
| 454 |
* Return the content of the reply |
| 455 |
* |
| 456 |
* @since bbPress (r2780) |
| 457 |
* |
| 458 |
* @param int $reply_id Optional. reply id |
| 459 |
* @uses bbp_get_reply_id() To get the reply id |
| 460 |
* @uses post_password_required() To check if the reply requires pass |
| 461 |
* @uses get_the_password_form() To get the password form |
| 462 |
* @uses get_post_field() To get the content post field |
| 463 |
* @uses apply_filters() Calls 'bbp_get_reply_content' with the content |
| 464 |
* and reply id |
| 465 |
* @return string Content of the reply |
| 466 |
*/ |
| 467 |
function bbp_get_reply_content( $reply_id = 0 ) { |
| 468 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 469 |
|
| 470 |
// Check if password is required |
| 471 |
if ( post_password_required( $reply_id ) ) |
| 472 |
return get_the_password_form(); |
| 473 |
|
| 474 |
$content = get_post_field( 'post_content', $reply_id ); |
| 475 |
|
| 476 |
return apply_filters( 'bbp_get_reply_content', $content, $reply_id ); |
| 477 |
} |
| 478 |
|
| 479 |
/** |
| 480 |
* Output the excerpt of the reply |
| 481 |
* |
| 482 |
* @since bbPress (r2751) |
| 483 |
* |
| 484 |
* @param int $reply_id Optional. Reply id |
| 485 |
* @param int $length Optional. Length of the excerpt. Defaults to 100 letters |
| 486 |
* @uses bbp_get_reply_excerpt() To get the reply excerpt |
| 487 |
*/ |
| 488 |
function bbp_reply_excerpt( $reply_id = 0, $length = 100 ) { |
| 489 |
echo bbp_get_reply_excerpt( $reply_id, $length ); |
| 490 |
} |
| 491 |
/** |
| 492 |
* Return the excerpt of the reply |
| 493 |
* |
| 494 |
* @since bbPress (r2751) |
| 495 |
* |
| 496 |
* @param int $reply_id Optional. Reply id |
| 497 |
* @param int $length Optional. Length of the excerpt. Defaults to 100 |
| 498 |
* letters |
| 499 |
* @uses bbp_get_reply_id() To get the reply id |
| 500 |
* @uses get_post_field() To get the excerpt |
| 501 |
* @uses bbp_get_reply_content() To get the reply content |
| 502 |
* @uses apply_filters() Calls 'bbp_get_reply_excerpt' with the excerpt, |
| 503 |
* reply id and length |
| 504 |
* @return string Reply Excerpt |
| 505 |
*/ |
| 506 |
function bbp_get_reply_excerpt( $reply_id = 0, $length = 100 ) { |
| 507 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 508 |
$length = (int) $length; |
| 509 |
$excerpt = get_post_field( $reply_id, 'post_excerpt' ); |
| 510 |
|
| 511 |
if ( empty( $excerpt ) ) |
| 512 |
$excerpt = bbp_get_reply_content( $reply_id ); |
| 513 |
|
| 514 |
$excerpt = trim ( strip_tags( $excerpt ) ); |
| 515 |
|
| 516 |
if ( !empty( $length ) && strlen( $excerpt ) > $length ) { |
| 517 |
$excerpt = substr( $excerpt, 0, $length - 1 ); |
| 518 |
$excerpt .= '…'; |
| 519 |
} |
| 520 |
|
| 521 |
return apply_filters( 'bbp_get_reply_excerpt', $excerpt, $reply_id, $length ); |
| 522 |
} |
| 523 |
|
| 524 |
/** |
| 525 |
* Append revisions to the reply content |
| 526 |
* |
| 527 |
* @since bbPress (r2782) |
| 528 |
* |
| 529 |
* @param string $content Optional. Content to which we need to append the revisions to |
| 530 |
* @param int $reply_id Optional. Reply id |
| 531 |
* @uses bbp_get_reply_revision_log() To get the reply revision log |
| 532 |
* @uses apply_filters() Calls 'bbp_reply_append_revisions' with the processed |
| 533 |
* content, original content and reply id |
| 534 |
* @return string Content with the revisions appended |
| 535 |
*/ |
| 536 |
function bbp_reply_content_append_revisions( $content = '', $reply_id = 0 ) { |
| 537 |
|
| 538 |
// Bail if in admin |
| 539 |
if ( is_admin() ) |
| 540 |
return; |
| 541 |
|
| 542 |
// Validate the ID |
| 543 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 544 |
|
| 545 |
return apply_filters( 'bbp_reply_append_revisions', $content . bbp_get_reply_revision_log( $reply_id ), $content, $reply_id ); |
| 546 |
} |
| 547 |
|
| 548 |
/** |
| 549 |
* Output the revision log of the reply |
| 550 |
* |
| 551 |
* @since bbPress (r2782) |
| 552 |
* |
| 553 |
* @param int $reply_id Optional. Reply id |
| 554 |
* @uses bbp_get_reply_revision_log() To get the reply revision log |
| 555 |
*/ |
| 556 |
function bbp_reply_revision_log( $reply_id = 0 ) { |
| 557 |
echo bbp_get_reply_revision_log( $reply_id ); |
| 558 |
} |
| 559 |
/** |
| 560 |
* Return the formatted revision log of the reply |
| 561 |
* |
| 562 |
* @since bbPress (r2782) |
| 563 |
* |
| 564 |
* @param int $reply_id Optional. Reply id |
| 565 |
* @uses bbp_get_reply_id() To get the reply id |
| 566 |
* @uses bbp_get_reply_revisions() To get the reply revisions |
| 567 |
* @uses bbp_get_reply_raw_revision_log() To get the raw revision log |
| 568 |
* @uses bbp_get_reply_author_display_name() To get the reply author |
| 569 |
* @uses bbp_get_reply_author_link() To get the reply author link |
| 570 |
* @uses bbp_convert_date() To convert the date |
| 571 |
* @uses bbp_get_time_since() To get the time in since format |
| 572 |
* @uses apply_filters() Calls 'bbp_get_reply_revision_log' with the |
| 573 |
* log and reply id |
| 574 |
* @return string Revision log of the reply |
| 575 |
*/ |
| 576 |
function bbp_get_reply_revision_log( $reply_id = 0 ) { |
| 577 |
|
| 578 |
// Create necessary variables |
| 579 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 580 |
$revision_log = bbp_get_reply_raw_revision_log( $reply_id ); |
| 581 |
|
| 582 |
// Check reply and revision log exist |
| 583 |
if ( empty( $reply_id ) || empty( $revision_log ) || !is_array( $revision_log ) ) |
| 584 |
return false; |
| 585 |
|
| 586 |
// Get the actual revisions |
| 587 |
if ( !$revisions = bbp_get_reply_revisions( $reply_id ) ) |
| 588 |
return false; |
| 589 |
|
| 590 |
$r = "\n\n" . '<ul id="bbp-reply-revision-log-' . $reply_id . '" class="bbp-reply-revision-log">' . "\n\n"; |
| 591 |
|
| 592 |
// Loop through revisions |
| 593 |
foreach ( (array) $revisions as $revision ) { |
| 594 |
|
| 595 |
if ( empty( $revision_log[$revision->ID] ) ) { |
| 596 |
$author_id = $revision->post_author; |
| 597 |
$reason = ''; |
| 598 |
} else { |
| 599 |
$author_id = $revision_log[$revision->ID]['author']; |
| 600 |
$reason = $revision_log[$revision->ID]['reason']; |
| 601 |
} |
| 602 |
|
| 603 |
$author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_reply_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) ); |
| 604 |
$since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) ); |
| 605 |
|
| 606 |
$r .= "\t" . '<li id="bbp-reply-revision-log-' . $reply_id . '-item-' . $revision->ID . '" class="bbp-reply-revision-log-item">' . "\n"; |
| 607 |
$r .= "\t\t" . sprintf( __( empty( $reason ) ? 'This reply was modified %1$s ago by %2$s.' : 'This reply was modified %1$s ago by %2$s. Reason: %3$s', 'bbpress' ), $since, $author, $reason ) . "\n"; |
| 608 |
$r .= "\t" . '</li>' . "\n"; |
| 609 |
|
| 610 |
} |
| 611 |
|
| 612 |
$r .= "\n" . '</ul>' . "\n\n"; |
| 613 |
|
| 614 |
return apply_filters( 'bbp_get_reply_revision_log', $r, $reply_id ); |
| 615 |
} |
| 616 |
/** |
| 617 |
* Return the raw revision log of the reply |
| 618 |
* |
| 619 |
* @since bbPress (r2782) |
| 620 |
* |
| 621 |
* @param int $reply_id Optional. Reply id |
| 622 |
* @uses bbp_get_reply_id() To get the reply id |
| 623 |
* @uses get_post_meta() To get the revision log meta |
| 624 |
* @uses apply_filters() Calls 'bbp_get_reply_raw_revision_log' |
| 625 |
* with the log and reply id |
| 626 |
* @return string Raw revision log of the reply |
| 627 |
*/ |
| 628 |
function bbp_get_reply_raw_revision_log( $reply_id = 0 ) { |
| 629 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 630 |
$revision_log = get_post_meta( $reply_id, '_bbp_revision_log', true ); |
| 631 |
$revision_log = empty( $revision_log ) ? array() : $revision_log; |
| 632 |
|
| 633 |
return apply_filters( 'bbp_get_reply_raw_revision_log', $revision_log, $reply_id ); |
| 634 |
} |
| 635 |
|
| 636 |
/** |
| 637 |
* Return the revisions of the reply |
| 638 |
* |
| 639 |
* @since bbPress (r2782) |
| 640 |
* |
| 641 |
* @param int $reply_id Optional. Reply id |
| 642 |
* @uses bbp_get_reply_id() To get the reply id |
| 643 |
* @uses wp_get_post_revisions() To get the reply revisions |
| 644 |
* @uses apply_filters() Calls 'bbp_get_reply_revisions' |
| 645 |
* with the revisions and reply id |
| 646 |
* @return string reply revisions |
| 647 |
*/ |
| 648 |
function bbp_get_reply_revisions( $reply_id = 0 ) { |
| 649 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 650 |
$revisions = wp_get_post_revisions( $reply_id, array( 'order' => 'ASC' ) ); |
| 651 |
|
| 652 |
return apply_filters( 'bbp_get_reply_revisions', $revisions, $reply_id ); |
| 653 |
} |
| 654 |
|
| 655 |
/** |
| 656 |
* Return the revision count of the reply |
| 657 |
* |
| 658 |
* @since bbPress (r2782) |
| 659 |
* |
| 660 |
* @param int $reply_id Optional. Reply id |
| 661 |
* @uses bbp_get_reply_revisions() To get the reply revisions |
| 662 |
* @uses apply_filters() Calls 'bbp_get_reply_revision_count' |
| 663 |
* with the revision count and reply id |
| 664 |
* @return string reply revision count |
| 665 |
*/ |
| 666 |
function bbp_get_reply_revision_count( $reply_id = 0 ) { |
| 667 |
return apply_filters( 'bbp_get_reply_revisions', count( bbp_get_reply_revisions( $reply_id ) ), $reply_id ); |
| 668 |
} |
| 669 |
|
| 670 |
/** |
| 671 |
* Output the status of the reply |
| 672 |
* |
| 673 |
* @since bbPress (r2667) |
| 674 |
* |
| 675 |
* @param int $reply_id Optional. Reply id |
| 676 |
* @uses bbp_get_reply_status() To get the reply status |
| 677 |
*/ |
| 678 |
function bbp_reply_status( $reply_id = 0 ) { |
| 679 |
echo bbp_get_reply_status( $reply_id ); |
| 680 |
} |
| 681 |
/** |
| 682 |
* Return the status of the reply |
| 683 |
* |
| 684 |
* @since bbPress (r2667) |
| 685 |
* |
| 686 |
* @param int $reply_id Optional. Reply id |
| 687 |
* @uses bbp_get_reply_id() To get the reply id |
| 688 |
* @uses get_post_status() To get the reply status |
| 689 |
* @uses apply_filters() Calls 'bbp_get_reply_status' with the reply id |
| 690 |
* @return string Status of reply |
| 691 |
*/ |
| 692 |
function bbp_get_reply_status( $reply_id = 0 ) { |
| 693 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 694 |
return apply_filters( 'bbp_get_reply_status', get_post_status( $reply_id ), $reply_id ); |
| 695 |
} |
| 696 |
|
| 697 |
/** |
| 698 |
* Is the reply not spam or deleted? |
| 699 |
* |
| 700 |
* @since bbPress (r3496) |
| 701 |
* |
| 702 |
* @param int $reply_id Optional. Topic id |
| 703 |
* @uses bbp_get_reply_id() To get the reply id |
| 704 |
* @uses bbp_get_reply_status() To get the reply status |
| 705 |
* @return bool True if published, false if not. |
| 706 |
*/ |
| 707 |
function bbp_is_reply_published( $reply_id = 0 ) { |
| 708 |
$reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ); |
| 709 |
return apply_filters( 'bbp_is_reply_published', bbp_get_public_status_id() == $reply_status, $reply_id ); |
| 710 |
} |
| 711 |
|
| 712 |
/** |
| 713 |
* Is the reply marked as spam? |
| 714 |
* |
| 715 |
* @since bbPress (r2740) |
| 716 |
* |
| 717 |
* @param int $reply_id Optional. Reply id |
| 718 |
* @uses bbp_get_reply_id() To get the reply id |
| 719 |
* @uses bbp_get_reply_status() To get the reply status |
| 720 |
* @return bool True if spam, false if not. |
| 721 |
*/ |
| 722 |
function bbp_is_reply_spam( $reply_id = 0 ) { |
| 723 |
$reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ); |
| 724 |
return apply_filters( 'bbp_is_reply_spam', bbp_get_spam_status_id() == $reply_status, $reply_id ); |
| 725 |
} |
| 726 |
|
| 727 |
/** |
| 728 |
* Is the reply trashed? |
| 729 |
* |
| 730 |
* @since bbPress (r2884) |
| 731 |
* |
| 732 |
* @param int $reply_id Optional. Topic id |
| 733 |
* @uses bbp_get_reply_id() To get the reply id |
| 734 |
* @uses bbp_get_reply_status() To get the reply status |
| 735 |
* @return bool True if spam, false if not. |
| 736 |
*/ |
| 737 |
function bbp_is_reply_trash( $reply_id = 0 ) { |
| 738 |
$reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ); |
| 739 |
return apply_filters( 'bbp_is_reply_trash', bbp_get_trash_status_id() == $reply_status, $reply_id ); |
| 740 |
} |
| 741 |
|
| 742 |
/** |
| 743 |
* Is the reply by an anonymous user? |
| 744 |
* |
| 745 |
* @since bbPress (r2753) |
| 746 |
* |
| 747 |
* @param int $reply_id Optional. Reply id |
| 748 |
* @uses bbp_get_reply_id() To get the reply id |
| 749 |
* @uses bbp_get_reply_author_id() To get the reply author id |
| 750 |
* @uses get_post_meta() To get the anonymous name and email metas |
| 751 |
* @return bool True if the post is by an anonymous user, false if not. |
| 752 |
*/ |
| 753 |
function bbp_is_reply_anonymous( $reply_id = 0 ) { |
| 754 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 755 |
|
| 756 |
$retval = false; |
| 757 |
|
| 758 |
if ( !bbp_get_reply_author_id( $reply_id ) ) |
| 759 |
$retval = true; |
| 760 |
|
| 761 |
elseif ( get_post_meta( $reply_id, '_bbp_anonymous_name', true ) ) |
| 762 |
$retval = true; |
| 763 |
|
| 764 |
elseif ( get_post_meta( $reply_id, '_bbp_anonymous_email', true ) ) |
| 765 |
$retval = true; |
| 766 |
|
| 767 |
return apply_filters( 'bbp_is_reply_anonymous', $retval ); |
| 768 |
} |
| 769 |
|
| 770 |
/** |
| 771 |
* Output the author of the reply |
| 772 |
* |
| 773 |
* @since bbPress (r2667) |
| 774 |
* |
| 775 |
* @param int $reply_id Optional. Reply id |
| 776 |
* @uses bbp_get_reply_author() To get the reply author |
| 777 |
*/ |
| 778 |
function bbp_reply_author( $reply_id = 0 ) { |
| 779 |
echo bbp_get_reply_author( $reply_id ); |
| 780 |
} |
| 781 |
/** |
| 782 |
* Return the author of the reply |
| 783 |
* |
| 784 |
* @since bbPress (r2667) |
| 785 |
* |
| 786 |
* @param int $reply_id Optional. Reply id |
| 787 |
* @uses bbp_get_reply_id() To get the reply id |
| 788 |
* @uses bbp_is_reply_anonymous() To check if the reply is by an |
| 789 |
* anonymous user |
| 790 |
* @uses get_the_author_meta() To get the reply author display name |
| 791 |
* @uses get_post_meta() To get the anonymous poster name |
| 792 |
* @uses apply_filters() Calls 'bbp_get_reply_author' with the reply |
| 793 |
* author and reply id |
| 794 |
* @return string Author of reply |
| 795 |
*/ |
| 796 |
function bbp_get_reply_author( $reply_id = 0 ) { |
| 797 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 798 |
|
| 799 |
if ( !bbp_is_reply_anonymous( $reply_id ) ) |
| 800 |
$author = get_the_author_meta( 'display_name', bbp_get_reply_author_id( $reply_id ) ); |
| 801 |
else |
| 802 |
$author = get_post_meta( $reply_id, '_bbp_anonymous_name', true ); |
| 803 |
|
| 804 |
return apply_filters( 'bbp_get_reply_author', $author, $reply_id ); |
| 805 |
} |
| 806 |
|
| 807 |
/** |
| 808 |
* Output the author ID of the reply |
| 809 |
* |
| 810 |
* @since bbPress (r2667) |
| 811 |
* |
| 812 |
* @param int $reply_id Optional. Reply id |
| 813 |
* @uses bbp_get_reply_author_id() To get the reply author id |
| 814 |
*/ |
| 815 |
function bbp_reply_author_id( $reply_id = 0 ) { |
| 816 |
echo bbp_get_reply_author_id( $reply_id ); |
| 817 |
} |
| 818 |
/** |
| 819 |
* Return the author ID of the reply |
| 820 |
* |
| 821 |
* @since bbPress (r2667) |
| 822 |
* |
| 823 |
* @param int $reply_id Optional. Reply id |
| 824 |
* @uses bbp_get_reply_id() To get the reply id |
| 825 |
* @uses get_post_field() To get the reply author id |
| 826 |
* @uses apply_filters() Calls 'bbp_get_reply_author_id' with the author |
| 827 |
* id and reply id |
| 828 |
* @return string Author id of reply |
| 829 |
*/ |
| 830 |
function bbp_get_reply_author_id( $reply_id = 0 ) { |
| 831 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 832 |
$author_id = get_post_field( 'post_author', $reply_id ); |
| 833 |
|
| 834 |
return apply_filters( 'bbp_get_reply_author_id', (int) $author_id, $reply_id ); |
| 835 |
} |
| 836 |
|
| 837 |
/** |
| 838 |
* Output the author display_name of the reply |
| 839 |
* |
| 840 |
* @since bbPress (r2667) |
| 841 |
* |
| 842 |
* @param int $reply_id Optional. Reply id |
| 843 |
* @uses bbp_get_reply_author_display_name() |
| 844 |
*/ |
| 845 |
function bbp_reply_author_display_name( $reply_id = 0 ) { |
| 846 |
echo bbp_get_reply_author_display_name( $reply_id ); |
| 847 |
} |
| 848 |
/** |
| 849 |
* Return the author display_name of the reply |
| 850 |
* |
| 851 |
* @since bbPress (r2667) |
| 852 |
* |
| 853 |
* @param int $reply_id Optional. Reply id |
| 854 |
* @uses bbp_get_reply_id() To get the reply id |
| 855 |
* @uses bbp_is_reply_anonymous() To check if the reply is by an |
| 856 |
* anonymous user |
| 857 |
* @uses bbp_get_reply_author_id() To get the reply author id |
| 858 |
* @uses get_the_author_meta() To get the reply author's display name |
| 859 |
* @uses get_post_meta() To get the anonymous poster's name |
| 860 |
* @uses apply_filters() Calls 'bbp_get_reply_author_display_name' with |
| 861 |
* the author display name and reply id |
| 862 |
* @return string Reply's author's display name |
| 863 |
*/ |
| 864 |
function bbp_get_reply_author_display_name( $reply_id = 0 ) { |
| 865 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 866 |
|
| 867 |
// Check for anonymous user |
| 868 |
if ( !bbp_is_reply_anonymous( $reply_id ) ) |
| 869 |
$author_name = get_the_author_meta( 'display_name', bbp_get_reply_author_id( $reply_id ) ); |
| 870 |
else |
| 871 |
$author_name = get_post_meta( $reply_id, '_bbp_anonymous_name', true ); |
| 872 |
|
| 873 |
return apply_filters( 'bbp_get_reply_author_display_name', esc_attr( $author_name ), $reply_id ); |
| 874 |
} |
| 875 |
|
| 876 |
/** |
| 877 |
* Output the author avatar of the reply |
| 878 |
* |
| 879 |
* @since bbPress (r2667) |
| 880 |
* |
| 881 |
* @param int $reply_id Optional. Reply id |
| 882 |
* @param int $size Optional. Size of the avatar. Defaults to 40 |
| 883 |
* @uses bbp_get_reply_author_avatar() To get the reply author id |
| 884 |
*/ |
| 885 |
function bbp_reply_author_avatar( $reply_id = 0, $size = 40 ) { |
| 886 |
echo bbp_get_reply_author_avatar( $reply_id, $size ); |
| 887 |
} |
| 888 |
/** |
| 889 |
* Return the author avatar of the reply |
| 890 |
* |
| 891 |
* @since bbPress (r2667) |
| 892 |
* |
| 893 |
* @param int $reply_id Optional. Reply id |
| 894 |
* @param int $size Optional. Size of the avatar. Defaults to 40 |
| 895 |
* @uses bbp_get_reply_id() To get the reply id |
| 896 |
* @uses bbp_is_reply_anonymous() To check if the reply is by an |
| 897 |
* anonymous user |
| 898 |
* @uses bbp_get_reply_author_id() To get the reply author id |
| 899 |
* @uses get_post_meta() To get the anonymous poster's email id |
| 900 |
* @uses get_avatar() To get the avatar |
| 901 |
* @uses apply_filters() Calls 'bbp_get_reply_author_avatar' with the |
| 902 |
* author avatar, reply id and size |
| 903 |
* @return string Avatar of author of the reply |
| 904 |
*/ |
| 905 |
function bbp_get_reply_author_avatar( $reply_id = 0, $size = 40 ) { |
| 906 |
if ( $reply_id = bbp_get_reply_id( $reply_id ) ) { |
| 907 |
// Check for anonymous user |
| 908 |
if ( !bbp_is_reply_anonymous( $reply_id ) ) |
| 909 |
$author_avatar = get_avatar( bbp_get_reply_author_id( $reply_id ), $size ); |
| 910 |
else |
| 911 |
$author_avatar = get_avatar( get_post_meta( $reply_id, '_bbp_anonymous_email', true ), $size ); |
| 912 |
} else { |
| 913 |
$author_avatar = ''; |
| 914 |
} |
| 915 |
|
| 916 |
return apply_filters( 'bbp_get_reply_author_avatar', $author_avatar, $reply_id, $size ); |
| 917 |
} |
| 918 |
|
| 919 |
/** |
| 920 |
* Output the author link of the reply |
| 921 |
* |
| 922 |
* @since bbPress (r2717) |
| 923 |
* |
| 924 |
* @param mixed $args Optional. If it is an integer, it is used as reply id. |
| 925 |
* @uses bbp_get_reply_author_link() To get the reply author link |
| 926 |
*/ |
| 927 |
function bbp_reply_author_link( $args = '' ) { |
| 928 |
echo bbp_get_reply_author_link( $args ); |
| 929 |
} |
| 930 |
/** |
| 931 |
* Return the author link of the reply |
| 932 |
* |
| 933 |
* @since bbPress (r2717) |
| 934 |
* |
| 935 |
* @param mixed $args Optional. If an integer, it is used as reply id. |
| 936 |
* @uses bbp_get_reply_id() To get the reply id |
| 937 |
* @uses bbp_is_reply_anonymous() To check if the reply is by an |
| 938 |
* anonymous user |
| 939 |
* @uses bbp_get_reply_author() To get the reply author name |
| 940 |
* @uses bbp_get_reply_author_url() To get the reply author url |
| 941 |
* @uses bbp_get_reply_author_avatar() To get the reply author avatar |
| 942 |
* bbp_get_reply_author_display_name() To get the reply author display |
| 943 |
* name |
| 944 |
* @uses apply_filters() Calls 'bbp_get_reply_author_link' with the |
| 945 |
* author link and args |
| 946 |
* @return string Author link of reply |
| 947 |
*/ |
| 948 |
function bbp_get_reply_author_link( $args = '' ) { |
| 949 |
$defaults = array ( |
| 950 |
'post_id' => 0, |
| 951 |
'link_title' => '', |
| 952 |
'type' => 'both', |
| 953 |
'size' => 80, |
| 954 |
'sep' => ' ' |
| 955 |
); |
| 956 |
|
| 957 |
$r = wp_parse_args( $args, $defaults ); |
| 958 |
extract( $r ); |
| 959 |
|
| 960 |
// Used as reply_id |
| 961 |
if ( is_numeric( $args ) ) |
| 962 |
$reply_id = bbp_get_reply_id( $args ); |
| 963 |
else |
| 964 |
$reply_id = bbp_get_reply_id( $post_id ); |
| 965 |
|
| 966 |
if ( !empty( $reply_id ) ) { |
| 967 |
if ( empty( $link_title ) ) |
| 968 |
$link_title = sprintf( !bbp_is_reply_anonymous( $reply_id ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), bbp_get_reply_author_display_name( $reply_id ) ); |
| 969 |
|
| 970 |
$link_title = !empty( $link_title ) ? ' title="' . $link_title . '"' : ''; |
| 971 |
$author_url = bbp_get_reply_author_url( $reply_id ); |
| 972 |
$anonymous = bbp_is_reply_anonymous( $reply_id ); |
| 973 |
|
| 974 |
// Get avatar |
| 975 |
if ( 'avatar' == $type || 'both' == $type ) |
| 976 |
$author_links['avatar'] = bbp_get_reply_author_avatar( $reply_id, $size ); |
| 977 |
|
| 978 |
// Get display name |
| 979 |
if ( 'name' == $type || 'both' == $type ) |
| 980 |
$author_links['name'] = bbp_get_reply_author_display_name( $reply_id ); |
| 981 |
|
| 982 |
// Add links if not anonymous |
| 983 |
if ( empty( $anonymous ) ) { |
| 984 |
foreach ( $author_links as $link => $link_text ) { |
| 985 |
$link_class = ' class="bbp-author-' . $link . '"'; |
| 986 |
$author_link[] = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', $author_url, $link_title, $link_class, $link_text ); |
| 987 |
} |
| 988 |
$author_link = join( $sep, $author_link ); |
| 989 |
|
| 990 |
// No links if anonymous |
| 991 |
} else { |
| 992 |
$author_link = join( $sep, $author_links ); |
| 993 |
} |
| 994 |
|
| 995 |
// No replies so link is empty |
| 996 |
} else { |
| 997 |
$author_link = ''; |
| 998 |
} |
| 999 |
|
| 1000 |
return apply_filters( 'bbp_get_reply_author_link', $author_link, $args ); |
| 1001 |
} |
| 1002 |
|
| 1003 |
/** |
| 1004 |
* Output the author url of the reply |
| 1005 |
* |
| 1006 |
* @since bbPress (r2667) |
| 1007 |
* |
| 1008 |
* @param int $reply_id Optional. Reply id |
| 1009 |
* @uses bbp_get_reply_author_url() To get the reply author url |
| 1010 |
*/ |
| 1011 |
function bbp_reply_author_url( $reply_id = 0 ) { |
| 1012 |
echo bbp_get_reply_author_url( $reply_id ); |
| 1013 |
} |
| 1014 |
/** |
| 1015 |
* Return the author url of the reply |
| 1016 |
* |
| 1017 |
* @since bbPress (r2667) |
| 1018 |
* |
| 1019 |
* @param int $reply_id Optional. Reply id |
| 1020 |
* @uses bbp_get_reply_id() To get the reply id |
| 1021 |
* @uses bbp_is_reply_anonymous() To check if the reply |
| 1022 |
* is by an anonymous |
| 1023 |
* user |
| 1024 |
* @uses bbp_get_reply_author_id() To get the reply |
| 1025 |
* author id |
| 1026 |
* @uses bbp_get_user_profile_url() To get the user |
| 1027 |
* profile url |
| 1028 |
* @uses get_post_meta() To get the anonymous poster's |
| 1029 |
* website url |
| 1030 |
* @uses apply_filters() Calls bbp_get_reply_author_url |
| 1031 |
* with the author url & reply id |
| 1032 |
* @return string Author URL of the reply |
| 1033 |
*/ |
| 1034 |
function bbp_get_reply_author_url( $reply_id = 0 ) { |
| 1035 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1036 |
|
| 1037 |
// Check for anonymous user |
| 1038 |
if ( !bbp_is_reply_anonymous( $reply_id ) ) { |
| 1039 |
$author_url = bbp_get_user_profile_url( bbp_get_reply_author_id( $reply_id ) ); |
| 1040 |
} else { |
| 1041 |
if ( !$author_url = get_post_meta( $reply_id, '_bbp_anonymous_website', true ) ) { |
| 1042 |
$author_url = ''; |
| 1043 |
} |
| 1044 |
} |
| 1045 |
|
| 1046 |
return apply_filters( 'bbp_get_reply_author_url', $author_url, $reply_id ); |
| 1047 |
} |
| 1048 |
|
| 1049 |
/** |
| 1050 |
* Output the reply author email address |
| 1051 |
* |
| 1052 |
* @since bbPress (r3445) |
| 1053 |
* |
| 1054 |
* @param int $reply_id Optional. Reply id |
| 1055 |
* @uses bbp_get_reply_author_email() To get the reply author email |
| 1056 |
*/ |
| 1057 |
function bbp_reply_author_email( $reply_id = 0 ) { |
| 1058 |
echo bbp_get_reply_author_email( $reply_id ); |
| 1059 |
} |
| 1060 |
/** |
| 1061 |
* Return the reply author email address |
| 1062 |
* |
| 1063 |
* @since bbPress (r3445) |
| 1064 |
* |
| 1065 |
* @param int $reply_id Optional. Reply id |
| 1066 |
* @uses bbp_get_reply_id() To get the reply id |
| 1067 |
* @uses bbp_is_reply_anonymous() To check if the reply is by an anonymous |
| 1068 |
* user |
| 1069 |
* @uses bbp_get_reply_author_id() To get the reply author id |
| 1070 |
* @uses get_userdata() To get the user data |
| 1071 |
* @uses get_post_meta() To get the anonymous poster's website email |
| 1072 |
* @uses apply_filters() Calls bbp_get_reply_author_email with the author |
| 1073 |
* email & reply id |
| 1074 |
* @return string Reply author email address |
| 1075 |
*/ |
| 1076 |
function bbp_get_reply_author_email( $reply_id = 0 ) { |
| 1077 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1078 |
|
| 1079 |
// Not anonymous |
| 1080 |
if ( !bbp_is_reply_anonymous( $reply_id ) ) { |
| 1081 |
|
| 1082 |
// Use reply author email address |
| 1083 |
$user_id = bbp_get_reply_author_id( $reply_id ); |
| 1084 |
$user = get_userdata( $user_id ); |
| 1085 |
$author_email = !empty( $user->user_email ) ? $user->user_email : ''; |
| 1086 |
|
| 1087 |
// Anonymous |
| 1088 |
} else { |
| 1089 |
|
| 1090 |
// Get email from post meta |
| 1091 |
$author_email = get_post_meta( $reply_id, '_bbp_anonymous_email', true ); |
| 1092 |
|
| 1093 |
// Sanity check for missing email address |
| 1094 |
if ( empty( $author_email ) ) { |
| 1095 |
$author_email = ''; |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
return apply_filters( 'bbp_get_reply_author_email', $author_email, $reply_id ); |
| 1100 |
} |
| 1101 |
|
| 1102 |
/** |
| 1103 |
* Output the topic title a reply belongs to |
| 1104 |
* |
| 1105 |
* @since bbPress (r2553) |
| 1106 |
* |
| 1107 |
* @param int $reply_id Optional. Reply id |
| 1108 |
* @uses bbp_get_reply_topic_title() To get the reply topic title |
| 1109 |
*/ |
| 1110 |
function bbp_reply_topic_title( $reply_id = 0 ) { |
| 1111 |
echo bbp_get_reply_topic_title( $reply_id ); |
| 1112 |
} |
| 1113 |
/** |
| 1114 |
* Return the topic title a reply belongs to |
| 1115 |
* |
| 1116 |
* @since bbPress (r2553) |
| 1117 |
* |
| 1118 |
* @param int $reply_id Optional. Reply id |
| 1119 |
* @uses bbp_get_reply_id() To get the reply id |
| 1120 |
* @uses bbp_get_reply_topic_id() To get the reply topic id |
| 1121 |
* @uses bbp_get_topic_title() To get the reply topic title |
| 1122 |
* @uses apply_filters() Calls 'bbp_get_reply_topic_title' with the |
| 1123 |
* topic title and reply id |
| 1124 |
* @return string Reply's topic's title |
| 1125 |
*/ |
| 1126 |
function bbp_get_reply_topic_title( $reply_id = 0 ) { |
| 1127 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1128 |
$topic_id = bbp_get_reply_topic_id( $reply_id ); |
| 1129 |
|
| 1130 |
return apply_filters( 'bbp_get_reply_topic_title', bbp_get_topic_title( $topic_id ), $reply_id ); |
| 1131 |
} |
| 1132 |
|
| 1133 |
/** |
| 1134 |
* Output the topic id a reply belongs to |
| 1135 |
* |
| 1136 |
* @since bbPress (r2553) |
| 1137 |
* |
| 1138 |
* @param int $reply_id Optional. Reply id |
| 1139 |
* @uses bbp_get_reply_topic_id() To get the reply topic id |
| 1140 |
*/ |
| 1141 |
function bbp_reply_topic_id( $reply_id = 0 ) { |
| 1142 |
echo bbp_get_reply_topic_id( $reply_id ); |
| 1143 |
} |
| 1144 |
/** |
| 1145 |
* Return the topic id a reply belongs to |
| 1146 |
* |
| 1147 |
* @since bbPress (r2553) |
| 1148 |
* |
| 1149 |
* @param int $reply_id Optional. Reply id |
| 1150 |
* @uses bbp_get_reply_id() To get the reply id |
| 1151 |
* @uses get_post_meta() To get the reply topic id from meta |
| 1152 |
* @uses get_post_ancestors() To get the reply's ancestors |
| 1153 |
* @uses get_post_field() To get the ancestor's post type |
| 1154 |
* @uses bbp_get_topic_post_type() To get the topic post type |
| 1155 |
* @uses bbp_update_reply_topic_id() To update the reply topic id |
| 1156 |
* @uses bbp_get_topic_id() To get the topic id |
| 1157 |
* @uses apply_filters() Calls 'bbp_get_reply_topic_id' with the topic |
| 1158 |
* id and reply id |
| 1159 |
* @return int Reply's topic id |
| 1160 |
*/ |
| 1161 |
function bbp_get_reply_topic_id( $reply_id = 0 ) { |
| 1162 |
|
| 1163 |
// Assume there is no topic id |
| 1164 |
$topic_id = 0; |
| 1165 |
|
| 1166 |
// Check that reply_id is valid |
| 1167 |
if ( $reply_id = bbp_get_reply_id( $reply_id ) ) |
| 1168 |
|
| 1169 |
// Get topic_id from reply |
| 1170 |
if ( $topic_id = get_post_meta( $reply_id, '_bbp_topic_id', true ) ) |
| 1171 |
|
| 1172 |
// Validate the topic_id |
| 1173 |
$topic_id = bbp_get_topic_id( $topic_id ); |
| 1174 |
|
| 1175 |
return apply_filters( 'bbp_get_reply_topic_id', (int) $topic_id, $reply_id ); |
| 1176 |
} |
| 1177 |
|
| 1178 |
/** |
| 1179 |
* Output the forum id a reply belongs to |
| 1180 |
* |
| 1181 |
* @since bbPress (r2679) |
| 1182 |
* |
| 1183 |
* @param int $reply_id Optional. Reply id |
| 1184 |
* @uses bbp_get_reply_forum_id() To get the reply forum id |
| 1185 |
*/ |
| 1186 |
function bbp_reply_forum_id( $reply_id = 0 ) { |
| 1187 |
echo bbp_get_reply_forum_id( $reply_id ); |
| 1188 |
} |
| 1189 |
/** |
| 1190 |
* Return the forum id a reply belongs to |
| 1191 |
* |
| 1192 |
* @since bbPress (r2679) |
| 1193 |
* |
| 1194 |
* @param int $reply_id Optional. Reply id |
| 1195 |
* @uses bbp_get_reply_id() To get the reply id |
| 1196 |
* @uses get_post_meta() To get the reply forum id |
| 1197 |
* @uses apply_filters() Calls 'bbp_get_reply_forum_id' with the forum |
| 1198 |
* id and reply id |
| 1199 |
* @return int Reply's forum id |
| 1200 |
*/ |
| 1201 |
function bbp_get_reply_forum_id( $reply_id = 0 ) { |
| 1202 |
|
| 1203 |
// Assume there is no forum |
| 1204 |
$forum_id = 0; |
| 1205 |
|
| 1206 |
// Check that reply_id is valid |
| 1207 |
if ( $reply_id = bbp_get_reply_id( $reply_id ) ) |
| 1208 |
|
| 1209 |
// Get forum_id from reply |
| 1210 |
if ( $forum_id = get_post_meta( $reply_id, '_bbp_forum_id', true ) ) |
| 1211 |
|
| 1212 |
// Validate the forum_id |
| 1213 |
$forum_id = bbp_get_forum_id( $forum_id ); |
| 1214 |
|
| 1215 |
return apply_filters( 'bbp_get_reply_forum_id', (int) $forum_id, $reply_id ); |
| 1216 |
} |
| 1217 |
|
| 1218 |
/** |
| 1219 |
* Output the numeric position of a reply within a topic |
| 1220 |
* |
| 1221 |
* @since bbPress (r2984) |
| 1222 |
* |
| 1223 |
* @param int $reply_id Optional. Reply id |
| 1224 |
* @param int $topic_id Optional. Topic id |
| 1225 |
* @uses bbp_get_reply_position() To get the reply position |
| 1226 |
*/ |
| 1227 |
function bbp_reply_position( $reply_id = 0, $topic_id = 0 ) { |
| 1228 |
echo bbp_get_reply_position( $reply_id, $topic_id ); |
| 1229 |
} |
| 1230 |
/** |
| 1231 |
* Return the numeric position of a reply within a topic |
| 1232 |
* |
| 1233 |
* @since bbPress (r2984) |
| 1234 |
* |
| 1235 |
* @param int $reply_id Optional. Reply id |
| 1236 |
* @param int $topic_id Optional. Topic id |
| 1237 |
* @uses bbp_get_reply_id() To get the reply id |
| 1238 |
* @uses bbp_get_reply_topic_id() Get the topic id of the reply id |
| 1239 |
* @uses bbp_get_topic_reply_count() To get the topic reply count |
| 1240 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 1241 |
* @uses bbp_get_public_child_ids() To get the reply ids of the topic id |
| 1242 |
* @uses bbp_show_lead_topic() Bump the count if lead topic is included |
| 1243 |
* @uses apply_filters() Calls 'bbp_get_reply_position' with the reply |
| 1244 |
* position, reply id and topic id |
| 1245 |
* @return int Reply position |
| 1246 |
*/ |
| 1247 |
function bbp_get_reply_position( $reply_id = 0, $topic_id = 0 ) { |
| 1248 |
|
| 1249 |
// Get required data |
| 1250 |
$reply_position = 0; |
| 1251 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1252 |
|
| 1253 |
// Get topic id |
| 1254 |
if ( !empty( $topic_id ) ) |
| 1255 |
$topic_id = bbp_get_topic_id( $topic_id ); |
| 1256 |
else |
| 1257 |
$topic_id = bbp_get_reply_topic_id( $reply_id ); |
| 1258 |
|
| 1259 |
// Make sure the topic has replies before running another query |
| 1260 |
if ( $reply_count = bbp_get_topic_reply_count( $topic_id ) ) { |
| 1261 |
|
| 1262 |
// Are we counting hidden replies too? |
| 1263 |
if ( bbp_get_view_all() ) |
| 1264 |
$topic_replies = bbp_get_all_child_ids ( $topic_id, bbp_get_reply_post_type() ); |
| 1265 |
else |
| 1266 |
$topic_replies = bbp_get_public_child_ids( $topic_id, bbp_get_reply_post_type() ); |
| 1267 |
|
| 1268 |
// Get reply id's |
| 1269 |
if ( !empty( $topic_replies ) ) { |
| 1270 |
|
| 1271 |
// Reverse replies array and search for current reply position |
| 1272 |
$topic_replies = array_reverse( $topic_replies ); |
| 1273 |
|
| 1274 |
// Position found |
| 1275 |
if ( $reply_position = array_search( (string) $reply_id, $topic_replies ) ) { |
| 1276 |
|
| 1277 |
// Bump if topic is in replies loop |
| 1278 |
if ( !bbp_show_lead_topic() ) |
| 1279 |
$reply_position++; |
| 1280 |
|
| 1281 |
// Bump now so we don't need to do math later |
| 1282 |
$reply_position++; |
| 1283 |
} |
| 1284 |
} |
| 1285 |
} |
| 1286 |
|
| 1287 |
return apply_filters( 'bbp_get_reply_position', (int) $reply_position, $reply_id, $topic_id ); |
| 1288 |
} |
| 1289 |
|
| 1290 |
/** Reply Admin Links *********************************************************/ |
| 1291 |
|
| 1292 |
/** |
| 1293 |
* Output admin links for reply |
| 1294 |
* |
| 1295 |
* @since bbPress (r2667) |
| 1296 |
* |
| 1297 |
* @param mixed $args See {@link bbp_get_reply_admin_links()} |
| 1298 |
* @uses bbp_get_reply_admin_links() To get the reply admin links |
| 1299 |
*/ |
| 1300 |
function bbp_reply_admin_links( $args = '' ) { |
| 1301 |
echo bbp_get_reply_admin_links( $args ); |
| 1302 |
} |
| 1303 |
/** |
| 1304 |
* Return admin links for reply |
| 1305 |
* |
| 1306 |
* @since bbPress (r2667) |
| 1307 |
* |
| 1308 |
* @param mixed $args This function supports these arguments: |
| 1309 |
* - id: Optional. Reply id |
| 1310 |
* - before: HTML before the links. Defaults to |
| 1311 |
* '<span class="bbp-admin-links">' |
| 1312 |
* - after: HTML after the links. Defaults to '</span>' |
| 1313 |
* - sep: Separator. Defaults to ' | ' |
| 1314 |
* - links: Array of the links to display. By default, edit, trash, |
| 1315 |
* spam and topic split links are displayed |
| 1316 |
* @uses bbp_is_topic() To check if it's the topic page |
| 1317 |
* @uses bbp_is_reply() To check if it's the reply page |
| 1318 |
* @uses bbp_get_reply_id() To get the reply id |
| 1319 |
* @uses bbp_get_reply_edit_link() To get the reply edit link |
| 1320 |
* @uses bbp_get_reply_trash_link() To get the reply trash link |
| 1321 |
* @uses bbp_get_reply_spam_link() To get the reply spam link |
| 1322 |
* @uses bbp_get_topic_split_link() To get the topic split link |
| 1323 |
* @uses current_user_can() To check if the current user can edit or |
| 1324 |
* delete the reply |
| 1325 |
* @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the |
| 1326 |
* reply admin links and args |
| 1327 |
* @return string Reply admin links |
| 1328 |
*/ |
| 1329 |
function bbp_get_reply_admin_links( $args = '' ) { |
| 1330 |
|
| 1331 |
$defaults = array ( |
| 1332 |
'id' => 0, |
| 1333 |
'before' => '<span class="bbp-admin-links">', |
| 1334 |
'after' => '</span>', |
| 1335 |
'sep' => ' | ', |
| 1336 |
'links' => array() |
| 1337 |
); |
| 1338 |
|
| 1339 |
$r = wp_parse_args( $args, $defaults ); |
| 1340 |
|
| 1341 |
$r['id'] = bbp_get_reply_id( (int) $r['id'] ); |
| 1342 |
|
| 1343 |
// If post is a topic, return the topic admin links instead |
| 1344 |
if ( bbp_is_topic( $r['id'] ) ) |
| 1345 |
return bbp_get_topic_admin_links( $args ); |
| 1346 |
|
| 1347 |
// If post is not a reply, return |
| 1348 |
if ( !bbp_is_reply( $r['id'] ) ) |
| 1349 |
return; |
| 1350 |
|
| 1351 |
// Make sure user can edit this reply |
| 1352 |
if ( !current_user_can( 'edit_reply', $r['id'] ) ) |
| 1353 |
return; |
| 1354 |
|
| 1355 |
// If topic is trashed, do not show admin links |
| 1356 |
if ( bbp_is_topic_trash( bbp_get_reply_topic_id( $r['id'] ) ) ) |
| 1357 |
return; |
| 1358 |
|
| 1359 |
// If no links were passed, default to the standard |
| 1360 |
if ( empty( $r['links'] ) ) { |
| 1361 |
$r['links'] = array ( |
| 1362 |
'edit' => bbp_get_reply_edit_link ( $r ), |
| 1363 |
'split' => bbp_get_topic_split_link( $r ), |
| 1364 |
'trash' => bbp_get_reply_trash_link( $r ), |
| 1365 |
'spam' => bbp_get_reply_spam_link ( $r ), |
| 1366 |
); |
| 1367 |
} |
| 1368 |
|
| 1369 |
// Check caps for trashing the topic |
| 1370 |
if ( !current_user_can( 'delete_reply', $r['id'] ) && !empty( $r['links']['trash'] ) ) |
| 1371 |
unset( $r['links']['trash'] ); |
| 1372 |
|
| 1373 |
// See if links need to be unset |
| 1374 |
$reply_status = bbp_get_reply_status( $r['id'] ); |
| 1375 |
if ( in_array( $reply_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ) ) { |
| 1376 |
|
| 1377 |
// Spam link shouldn't be visible on trashed topics |
| 1378 |
if ( $reply_status == bbp_get_trash_status_id() ) |
| 1379 |
unset( $r['links']['spam'] ); |
| 1380 |
|
| 1381 |
// Trash link shouldn't be visible on spam topics |
| 1382 |
elseif ( isset( $r['links']['trash'] ) && ( bbp_get_spam_status_id() == $reply_status ) ) |
| 1383 |
unset( $r['links']['trash'] ); |
| 1384 |
} |
| 1385 |
|
| 1386 |
// Process the admin links |
| 1387 |
$links = implode( $r['sep'], array_filter( $r['links'] ) ); |
| 1388 |
|
| 1389 |
return apply_filters( 'bbp_get_reply_admin_links', $r['before'] . $links . $r['after'], $args ); |
| 1390 |
} |
| 1391 |
|
| 1392 |
/** |
| 1393 |
* Output the edit link of the reply |
| 1394 |
* |
| 1395 |
* @since bbPress (r2740) |
| 1396 |
* |
| 1397 |
* @param mixed $args See {@link bbp_get_reply_edit_link()} |
| 1398 |
* @uses bbp_get_reply_edit_link() To get the reply edit link |
| 1399 |
*/ |
| 1400 |
function bbp_reply_edit_link( $args = '' ) { |
| 1401 |
echo bbp_get_reply_edit_link( $args ); |
| 1402 |
} |
| 1403 |
|
| 1404 |
/** |
| 1405 |
* Return the edit link of the reply |
| 1406 |
* |
| 1407 |
* @since bbPress (r2740) |
| 1408 |
* |
| 1409 |
* @param mixed $args This function supports these arguments: |
| 1410 |
* - id: Reply id |
| 1411 |
* - link_before: HTML before the link |
| 1412 |
* - link_after: HTML after the link |
| 1413 |
* - edit_text: Edit text. Defaults to 'Edit' |
| 1414 |
* @uses bbp_get_reply_id() To get the reply id |
| 1415 |
* @uses bbp_get_reply() To get the reply |
| 1416 |
* @uses current_user_can() To check if the current user can edit the |
| 1417 |
* reply |
| 1418 |
* @uses bbp_get_reply_edit_url() To get the reply edit url |
| 1419 |
* @uses apply_filters() Calls 'bbp_get_reply_edit_link' with the reply |
| 1420 |
* edit link and args |
| 1421 |
* @return string Reply edit link |
| 1422 |
*/ |
| 1423 |
function bbp_get_reply_edit_link( $args = '' ) { |
| 1424 |
$defaults = array ( |
| 1425 |
'id' => 0, |
| 1426 |
'link_before' => '', |
| 1427 |
'link_after' => '', |
| 1428 |
'edit_text' => __( 'Edit', 'bbpress' ) |
| 1429 |
); |
| 1430 |
|
| 1431 |
$r = wp_parse_args( $args, $defaults ); |
| 1432 |
extract( $r ); |
| 1433 |
|
| 1434 |
$reply = bbp_get_reply( bbp_get_reply_id( (int) $id ) ); |
| 1435 |
|
| 1436 |
// Bypass check if user has caps |
| 1437 |
if ( !current_user_can( 'edit_others_replies' ) ) { |
| 1438 |
|
| 1439 |
// User cannot edit or it is past the lock time |
| 1440 |
if ( empty( $reply ) || !current_user_can( 'edit_reply', $reply->ID ) || bbp_past_edit_lock( $reply->post_date_gmt ) ) |
| 1441 |
return; |
| 1442 |
} |
| 1443 |
|
| 1444 |
// No uri to edit reply |
| 1445 |
if ( !$uri = bbp_get_reply_edit_url( $id ) ) |
| 1446 |
return; |
| 1447 |
|
| 1448 |
return apply_filters( 'bbp_get_reply_edit_link', $link_before . '<a href="' . $uri . '">' . $edit_text . '</a>' . $link_after, $args ); |
| 1449 |
} |
| 1450 |
|
| 1451 |
/** |
| 1452 |
* Output URL to the reply edit page |
| 1453 |
* |
| 1454 |
* @since bbPress (r2753) |
| 1455 |
* |
| 1456 |
* @param int $reply_id Optional. Reply id |
| 1457 |
* @uses bbp_get_reply_edit_url() To get the reply edit url |
| 1458 |
*/ |
| 1459 |
function bbp_reply_edit_url( $reply_id = 0 ) { |
| 1460 |
echo bbp_get_reply_edit_url( $reply_id ); |
| 1461 |
} |
| 1462 |
/** |
| 1463 |
* Return URL to the reply edit page |
| 1464 |
* |
| 1465 |
* @since bbPress (r2753) |
| 1466 |
* |
| 1467 |
* @param int $reply_id Optional. Reply id |
| 1468 |
* @uses bbp_get_reply_id() To get the reply id |
| 1469 |
* @uses bbp_get_reply() To get the reply |
| 1470 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 1471 |
* @uses add_query_arg() To add custom args to the url |
| 1472 |
* @uses home_url() To get the home url |
| 1473 |
* @uses apply_filters() Calls 'bbp_get_reply_edit_url' with the edit |
| 1474 |
* url and reply id |
| 1475 |
* @return string Reply edit url |
| 1476 |
*/ |
| 1477 |
function bbp_get_reply_edit_url( $reply_id = 0 ) { |
| 1478 |
global $wp_rewrite, $bbp; |
| 1479 |
|
| 1480 |
if ( !$reply = bbp_get_reply( bbp_get_reply_id( $reply_id ) ) ) |
| 1481 |
return; |
| 1482 |
|
| 1483 |
// Pretty permalinks |
| 1484 |
if ( $wp_rewrite->using_permalinks() ) { |
| 1485 |
$url = $wp_rewrite->root . $bbp->reply_slug . '/' . $reply->post_name . '/edit'; |
| 1486 |
$url = home_url( user_trailingslashit( $url ) ); |
| 1487 |
|
| 1488 |
// Unpretty permalinks |
| 1489 |
} else { |
| 1490 |
$url = add_query_arg( array( bbp_get_reply_post_type() => $reply->post_name, 'edit' => '1' ), home_url( '/' ) ); |
| 1491 |
} |
| 1492 |
|
| 1493 |
return apply_filters( 'bbp_get_reply_edit_url', $url, $reply_id ); |
| 1494 |
} |
| 1495 |
|
| 1496 |
/** |
| 1497 |
* Output the trash link of the reply |
| 1498 |
* |
| 1499 |
* @since bbPress (r2740) |
| 1500 |
* |
| 1501 |
* @param mixed $args See {@link bbp_get_reply_trash_link()} |
| 1502 |
* @uses bbp_get_reply_trash_link() To get the reply trash link |
| 1503 |
*/ |
| 1504 |
function bbp_reply_trash_link( $args = '' ) { |
| 1505 |
echo bbp_get_reply_trash_link( $args ); |
| 1506 |
} |
| 1507 |
|
| 1508 |
/** |
| 1509 |
* Return the trash link of the reply |
| 1510 |
* |
| 1511 |
* @since bbPress (r2740) |
| 1512 |
* |
| 1513 |
* @param mixed $args This function supports these arguments: |
| 1514 |
* - id: Reply id |
| 1515 |
* - link_before: HTML before the link |
| 1516 |
* - link_after: HTML after the link |
| 1517 |
* - sep: Separator |
| 1518 |
* - trash_text: Trash text |
| 1519 |
* - restore_text: Restore text |
| 1520 |
* - delete_text: Delete text |
| 1521 |
* @uses bbp_get_reply_id() To get the reply id |
| 1522 |
* @uses bbp_get_reply() To get the reply |
| 1523 |
* @uses current_user_can() To check if the current user can delete the |
| 1524 |
* reply |
| 1525 |
* @uses bbp_is_reply_trash() To check if the reply is trashed |
| 1526 |
* @uses bbp_get_reply_status() To get the reply status |
| 1527 |
* @uses add_query_arg() To add custom args to the url |
| 1528 |
* @uses wp_nonce_url() To nonce the url |
| 1529 |
* @uses esc_url() To escape the url |
| 1530 |
* @uses bbp_get_reply_edit_url() To get the reply edit url |
| 1531 |
* @uses apply_filters() Calls 'bbp_get_reply_trash_link' with the reply |
| 1532 |
* trash link and args |
| 1533 |
* @return string Reply trash link |
| 1534 |
*/ |
| 1535 |
function bbp_get_reply_trash_link( $args = '' ) { |
| 1536 |
$defaults = array ( |
| 1537 |
'id' => 0, |
| 1538 |
'link_before' => '', |
| 1539 |
'link_after' => '', |
| 1540 |
'sep' => ' | ', |
| 1541 |
'trash_text' => __( 'Trash', 'bbpress' ), |
| 1542 |
'restore_text' => __( 'Restore', 'bbpress' ), |
| 1543 |
'delete_text' => __( 'Delete', 'bbpress' ) |
| 1544 |
); |
| 1545 |
|
| 1546 |
$r = wp_parse_args( $args, $defaults ); |
| 1547 |
extract( $r ); |
| 1548 |
|
| 1549 |
$actions = array(); |
| 1550 |
$reply = bbp_get_reply( bbp_get_reply_id( (int) $id ) ); |
| 1551 |
|
| 1552 |
if ( empty( $reply ) || !current_user_can( 'delete_reply', $reply->ID ) ) { |
| 1553 |
return; |
| 1554 |
} |
| 1555 |
|
| 1556 |
if ( bbp_is_reply_trash( $reply->ID ) ) { |
| 1557 |
$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 ) ) . '">' . esc_html( $restore_text ) . '</a>'; |
| 1558 |
} elseif ( EMPTY_TRASH_DAYS ) { |
| 1559 |
$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 ) ) . '">' . esc_html( $trash_text ) . '</a>'; |
| 1560 |
} |
| 1561 |
|
| 1562 |
if ( bbp_is_reply_trash( $reply->ID ) || !EMPTY_TRASH_DAYS ) { |
| 1563 |
$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' ) ) . '\' );">' . esc_html( $delete_text ) . '</a>'; |
| 1564 |
} |
| 1565 |
|
| 1566 |
// Process the admin links |
| 1567 |
$actions = implode( $sep, $actions ); |
| 1568 |
|
| 1569 |
return apply_filters( 'bbp_get_reply_trash_link', $link_before . $actions . $link_after, $args ); |
| 1570 |
} |
| 1571 |
|
| 1572 |
/** |
| 1573 |
* Output the spam link of the reply |
| 1574 |
* |
| 1575 |
* @since bbPress (r2740) |
| 1576 |
* |
| 1577 |
* @param mixed $args See {@link bbp_get_reply_spam_link()} |
| 1578 |
* @uses bbp_get_reply_spam_link() To get the reply spam link |
| 1579 |
*/ |
| 1580 |
function bbp_reply_spam_link( $args = '' ) { |
| 1581 |
echo bbp_get_reply_spam_link( $args ); |
| 1582 |
} |
| 1583 |
|
| 1584 |
/** |
| 1585 |
* Return the spam link of the reply |
| 1586 |
* |
| 1587 |
* @since bbPress (r2740) |
| 1588 |
* |
| 1589 |
* @param mixed $args This function supports these arguments: |
| 1590 |
* - id: Reply id |
| 1591 |
* - link_before: HTML before the link |
| 1592 |
* - link_after: HTML after the link |
| 1593 |
* - spam_text: Spam text |
| 1594 |
* - unspam_text: Unspam text |
| 1595 |
* @uses bbp_get_reply_id() To get the reply id |
| 1596 |
* @uses bbp_get_reply() To get the reply |
| 1597 |
* @uses current_user_can() To check if the current user can edit the |
| 1598 |
* reply |
| 1599 |
* @uses bbp_is_reply_spam() To check if the reply is marked as spam |
| 1600 |
* @uses add_query_arg() To add custom args to the url |
| 1601 |
* @uses wp_nonce_url() To nonce the url |
| 1602 |
* @uses esc_url() To escape the url |
| 1603 |
* @uses bbp_get_reply_edit_url() To get the reply edit url |
| 1604 |
* @uses apply_filters() Calls 'bbp_get_reply_spam_link' with the reply |
| 1605 |
* spam link and args |
| 1606 |
* @return string Reply spam link |
| 1607 |
*/ |
| 1608 |
function bbp_get_reply_spam_link( $args = '' ) { |
| 1609 |
$defaults = array ( |
| 1610 |
'id' => 0, |
| 1611 |
'link_before' => '', |
| 1612 |
'link_after' => '', |
| 1613 |
'spam_text' => __( 'Spam', 'bbpress' ), |
| 1614 |
'unspam_text' => __( 'Unspam', 'bbpress' ) |
| 1615 |
); |
| 1616 |
|
| 1617 |
$r = wp_parse_args( $args, $defaults ); |
| 1618 |
extract( $r ); |
| 1619 |
|
| 1620 |
$reply = bbp_get_reply( bbp_get_reply_id( (int) $id ) ); |
| 1621 |
|
| 1622 |
if ( empty( $reply ) || !current_user_can( 'moderate', $reply->ID ) ) |
| 1623 |
return; |
| 1624 |
|
| 1625 |
$display = bbp_is_reply_spam( $reply->ID ) ? $unspam_text : $spam_text; |
| 1626 |
|
| 1627 |
$uri = add_query_arg( array( 'action' => 'bbp_toggle_reply_spam', 'reply_id' => $reply->ID ) ); |
| 1628 |
$uri = esc_url( wp_nonce_url( $uri, 'spam-reply_' . $reply->ID ) ); |
| 1629 |
|
| 1630 |
return apply_filters( 'bbp_get_reply_spam_link', $link_before . '<a href="' . $uri . '">' . $display . '</a>' . $link_after, $args ); |
| 1631 |
} |
| 1632 |
|
| 1633 |
/** |
| 1634 |
* Split topic link |
| 1635 |
* |
| 1636 |
* Output the split link of the topic (but is bundled with each topic) |
| 1637 |
* |
| 1638 |
* @since bbPress (r2756) |
| 1639 |
* |
| 1640 |
* @param mixed $args See {@link bbp_get_topic_split_link()} |
| 1641 |
* @uses bbp_get_topic_split_link() To get the topic split link |
| 1642 |
*/ |
| 1643 |
function bbp_topic_split_link( $args = '' ) { |
| 1644 |
echo bbp_get_topic_split_link( $args ); |
| 1645 |
} |
| 1646 |
|
| 1647 |
/** |
| 1648 |
* Get split topic link |
| 1649 |
* |
| 1650 |
* Return the split link of the topic (but is bundled with each reply) |
| 1651 |
* |
| 1652 |
* @since bbPress (r2756) |
| 1653 |
* |
| 1654 |
* @param mixed $args This function supports these arguments: |
| 1655 |
* - id: Reply id |
| 1656 |
* - link_before: HTML before the link |
| 1657 |
* - link_after: HTML after the link |
| 1658 |
* - split_text: Split text |
| 1659 |
* - split_title: Split title attribute |
| 1660 |
* @uses bbp_get_reply_id() To get the reply id |
| 1661 |
* @uses bbp_get_reply() To get the reply |
| 1662 |
* @uses current_user_can() To check if the current user can edit the |
| 1663 |
* topic |
| 1664 |
* @uses bbp_get_reply_topic_id() To get the reply topic id |
| 1665 |
* @uses bbp_get_topic_edit_url() To get the topic edit url |
| 1666 |
* @uses add_query_arg() To add custom args to the url |
| 1667 |
* @uses wp_nonce_url() To nonce the url |
| 1668 |
* @uses esc_url() To escape the url |
| 1669 |
* @uses apply_filters() Calls 'bbp_get_topic_split_link' with the topic |
| 1670 |
* split link and args |
| 1671 |
* @return string Reply spam link |
| 1672 |
*/ |
| 1673 |
function bbp_get_topic_split_link( $args = '' ) { |
| 1674 |
$defaults = array ( |
| 1675 |
'id' => 0, |
| 1676 |
'link_before' => '', |
| 1677 |
'link_after' => '', |
| 1678 |
'split_text' => __( 'Split', 'bbpress' ), |
| 1679 |
'split_title' => __( 'Split the topic from this reply', 'bbpress' ) |
| 1680 |
); |
| 1681 |
|
| 1682 |
$r = wp_parse_args( $args, $defaults ); |
| 1683 |
extract( $r ); |
| 1684 |
|
| 1685 |
$reply_id = bbp_get_reply_id( $id ); |
| 1686 |
$topic_id = bbp_get_reply_topic_id( $reply_id ); |
| 1687 |
|
| 1688 |
if ( empty( $reply_id ) || !current_user_can( 'moderate', $topic_id ) ) |
| 1689 |
return; |
| 1690 |
|
| 1691 |
$uri = esc_url( |
| 1692 |
add_query_arg( |
| 1693 |
array( |
| 1694 |
'action' => 'split', |
| 1695 |
'reply_id' => $reply_id |
| 1696 |
), |
| 1697 |
bbp_get_topic_edit_url( $topic_id ) |
| 1698 |
) ); |
| 1699 |
|
| 1700 |
return apply_filters( 'bbp_get_topic_split_link', $link_before . '<a href="' . $uri . '" title="' . esc_attr( $split_title ) . '">' . $split_text . '</a>' . $link_after, $args ); |
| 1701 |
} |
| 1702 |
|
| 1703 |
/** |
| 1704 |
* Output the row class of a reply |
| 1705 |
* |
| 1706 |
* @since bbPress (r2678) |
| 1707 |
* |
| 1708 |
* @param int $reply_id Optional. Reply ID |
| 1709 |
* @uses bbp_get_reply_class() To get the reply class |
| 1710 |
*/ |
| 1711 |
function bbp_reply_class( $reply_id = 0 ) { |
| 1712 |
echo bbp_get_reply_class( $reply_id ); |
| 1713 |
} |
| 1714 |
/** |
| 1715 |
* Return the row class of a reply |
| 1716 |
* |
| 1717 |
* @since bbPress (r2678) |
| 1718 |
* |
| 1719 |
* @param int $reply_id Optional. Reply ID |
| 1720 |
* @uses get_post_class() To get all the classes including ours |
| 1721 |
* @uses apply_filters() Calls 'bbp_get_reply_class' with the classes |
| 1722 |
* @return string Row class of the reply |
| 1723 |
*/ |
| 1724 |
function bbp_get_reply_class( $reply_id = 0 ) { |
| 1725 |
global $bbp; |
| 1726 |
|
| 1727 |
$reply_id = bbp_get_reply_id( $reply_id ); |
| 1728 |
$count = isset( $bbp->reply_query->current_post ) ? $bbp->reply_query->current_post : 1; |
| 1729 |
$classes = array(); |
| 1730 |
$classes[] = ( (int) $count % 2 ) ? 'even' : 'odd'; |
| 1731 |
$retval = get_post_class( $classes, $reply_id ); |
| 1732 |
$retval = 'class="' . join( ' ', $retval ) . '"'; |
| 1733 |
|
| 1734 |
return apply_filters( 'bbp_get_reply_class', $retval, $reply_id ); |
| 1735 |
} |
| 1736 |
|
| 1737 |
/** |
| 1738 |
* Output the topic pagination count |
| 1739 |
* |
| 1740 |
* @since bbPress (r2519) |
| 1741 |
* |
| 1742 |
* @uses bbp_get_topic_pagination_count() To get the topic pagination count |
| 1743 |
*/ |
| 1744 |
function bbp_topic_pagination_count() { |
| 1745 |
echo bbp_get_topic_pagination_count(); |
| 1746 |
} |
| 1747 |
/** |
| 1748 |
* Return the topic pagination count |
| 1749 |
* |
| 1750 |
* @since bbPress (r2519) |
| 1751 |
* |
| 1752 |
* @uses bbp_number_format() To format the number value |
| 1753 |
* @uses bbp_show_lead_topic() Are we showing the topic as a lead? |
| 1754 |
* @uses apply_filters() Calls 'bbp_get_topic_pagination_count' with the |
| 1755 |
* pagination count |
| 1756 |
* @return string Topic pagination count |
| 1757 |
*/ |
| 1758 |
function bbp_get_topic_pagination_count() { |
| 1759 |
global $bbp; |
| 1760 |
|
| 1761 |
// Define local variable(s) |
| 1762 |
$retstr = ''; |
| 1763 |
|
| 1764 |
// Set pagination values |
| 1765 |
$start_num = intval( ( $bbp->reply_query->paged - 1 ) * $bbp->reply_query->posts_per_page ) + 1; |
| 1766 |
$from_num = bbp_number_format( $start_num ); |
| 1767 |
$to_num = bbp_number_format( ( $start_num + ( $bbp->reply_query->posts_per_page - 1 ) > $bbp->reply_query->found_posts ) ? $bbp->reply_query->found_posts : $start_num + ( $bbp->reply_query->posts_per_page - 1 ) ); |
| 1768 |
$total = bbp_number_format( $bbp->reply_query->found_posts ); |
| 1769 |
|
| 1770 |
/** |
| 1771 |
* Translators - _n() should not be needed, as singular/plural strings |
| 1772 |
* are already separated into unique strings for you |
| 1773 |
*/ |
| 1774 |
|
| 1775 |
// We are not including the lead topic |
| 1776 |
if ( bbp_show_lead_topic() ) { |
| 1777 |
|
| 1778 |
// More than 1 reply |
| 1779 |
if ( $total > 1 ) { |
| 1780 |
|
| 1781 |
// Single reply in a topic with several pages |
| 1782 |
if ( (int) $from_num == (int) $to_num ) { |
| 1783 |
$retstr = sprintf( __( 'Viewing reply %1$s (of %2$s total)', 'bbpress' ), $from_num, $total ); |
| 1784 |
|
| 1785 |
// Several replies in a topic with a single page |
| 1786 |
} elseif ( empty( $to_num ) ) { |
| 1787 |
$retstr = sprintf( __( 'Viewing %1$s replies', 'bbpress' ), $total ); |
| 1788 |
|
| 1789 |
// Several replies in a topic with several pages |
| 1790 |
} elseif ( (int) $from_num != (int) $to_num ) { |
| 1791 |
$retstr = sprintf( __( 'Viewing %1$s replies - %2$s through %3$s (of %4$s total)', 'bbpress' ), $bbp->reply_query->post_count, $from_num, $to_num, $total ); |
| 1792 |
} |
| 1793 |
|
| 1794 |
// Only one reply |
| 1795 |
} else { |
| 1796 |
$retstr = sprintf( __( 'Viewing %1$s reply', 'bbpress' ), $total ); |
| 1797 |
} |
| 1798 |
|
| 1799 |
// We are including the lead topic |
| 1800 |
} else { |
| 1801 |
|
| 1802 |
// More than 1 post |
| 1803 |
if ( $total > 1 ) { |
| 1804 |
|
| 1805 |
// Single post in a topic with several pages |
| 1806 |
if( (int) $from_num == (int) $to_num ) { |
| 1807 |
$retstr = sprintf( __( 'Viewing post %1$s (of %2$s total)', 'bbpress' ), $from_num, $total ); |
| 1808 |
|
| 1809 |
// Several posts in a topic with a single page |
| 1810 |
} elseif ( empty( $to_num ) ) { |
| 1811 |
$retstr = sprintf( __( 'Viewing %1$s posts', 'bbpress' ), $total ); |
| 1812 |
|
| 1813 |
// Several posts in a topic with several pages |
| 1814 |
} elseif ( (int) $from_num != (int) $to_num ) { |
| 1815 |
$retstr = sprintf( __( 'Viewing %1$s posts - %2$s through %3$s (of %4$s total)', 'bbpress' ), $bbp->reply_query->post_count, $from_num, $to_num, $total ); |
| 1816 |
} |
| 1817 |
|
| 1818 |
// Only one post |
| 1819 |
} elseif ( $total == 1 ) { |
| 1820 |
$retstr = sprintf( __( 'Viewing %1$s post', 'bbpress' ), $total ); |
| 1821 |
} |
| 1822 |
} |
| 1823 |
|
| 1824 |
// Filter and return |
| 1825 |
return apply_filters( 'bbp_get_topic_pagination_count', $retstr ); |
| 1826 |
} |
| 1827 |
|
| 1828 |
/** |
| 1829 |
* Output topic pagination links |
| 1830 |
* |
| 1831 |
* @since bbPress (r2519) |
| 1832 |
* |
| 1833 |
* @uses bbp_get_topic_pagination_links() To get the topic pagination links |
| 1834 |
*/ |
| 1835 |
function bbp_topic_pagination_links() { |
| 1836 |
echo bbp_get_topic_pagination_links(); |
| 1837 |
} |
| 1838 |
/** |
| 1839 |
* Return topic pagination links |
| 1840 |
* |
| 1841 |
* @since bbPress (r2519) |
| 1842 |
* |
| 1843 |
* @uses apply_filters() Calls 'bbp_get_topic_pagination_links' with the |
| 1844 |
* pagination links |
| 1845 |
* @return string Topic pagination links |
| 1846 |
*/ |
| 1847 |
function bbp_get_topic_pagination_links() { |
| 1848 |
global $bbp; |
| 1849 |
|
| 1850 |
if ( !isset( $bbp->reply_query->pagination_links ) || empty( $bbp->reply_query->pagination_links ) ) |
| 1851 |
return false; |
| 1852 |
|
| 1853 |
return apply_filters( 'bbp_get_topic_pagination_links', $bbp->reply_query->pagination_links ); |
| 1854 |
} |
| 1855 |
|
| 1856 |
/** Forms *********************************************************************/ |
| 1857 |
|
| 1858 |
/** |
| 1859 |
* Output the value of reply content field |
| 1860 |
* |
| 1861 |
* @since bbPress {unknown} |
| 1862 |
* |
| 1863 |
* @uses bbp_get_form_reply_content() To get value of reply content field |
| 1864 |
*/ |
| 1865 |
function bbp_form_reply_content() { |
| 1866 |
echo bbp_get_form_reply_content(); |
| 1867 |
} |
| 1868 |
/** |
| 1869 |
* Return the value of reply content field |
| 1870 |
* |
| 1871 |
* @since bbPress {unknown} |
| 1872 |
* |
| 1873 |
* @uses bbp_is_reply_edit() To check if it's the reply edit page |
| 1874 |
* @uses apply_filters() Calls 'bbp_get_form_reply_content' with the content |
| 1875 |
* @return string Value of reply content field |
| 1876 |
*/ |
| 1877 |
function bbp_get_form_reply_content() { |
| 1878 |
global $post; |
| 1879 |
|
| 1880 |
// Get _POST data |
| 1881 |
if ( 'POST' == strtoupper( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_reply_content'] ) ) |
| 1882 |
$reply_content = $_POST['bbp_reply_content']; |
| 1883 |
|
| 1884 |
// Get edit data |
| 1885 |
elseif ( !empty( $post->post_content ) && bbp_is_reply_edit() ) |
| 1886 |
$reply_content = $post->post_content; |
| 1887 |
|
| 1888 |
// No data |
| 1889 |
else |
| 1890 |
$reply_content = ''; |
| 1891 |
|
| 1892 |
return apply_filters( 'bbp_get_form_reply_content', esc_textarea( $reply_content ) ); |
| 1893 |
} |
| 1894 |
|
| 1895 |
/** |
| 1896 |
* Output checked value of reply log edit field |
| 1897 |
* |
| 1898 |
* @since bbPress {unknown} |
| 1899 |
* |
| 1900 |
* @uses bbp_get_form_reply_log_edit() To get the reply log edit value |
| 1901 |
*/ |
| 1902 |
function bbp_form_reply_log_edit() { |
| 1903 |
echo bbp_get_form_reply_log_edit(); |
| 1904 |
} |
| 1905 |
/** |
| 1906 |
* Return checked value of reply log edit field |
| 1907 |
* |
| 1908 |
* @since bbPress {unknown} |
| 1909 |
* |
| 1910 |
* @uses apply_filters() Calls 'bbp_get_form_reply_log_edit' with the |
| 1911 |
* log edit value |
| 1912 |
* @return string Reply log edit checked value |
| 1913 |
*/ |
| 1914 |
function bbp_get_form_reply_log_edit() { |
| 1915 |
global $post; |
| 1916 |
|
| 1917 |
// Get _POST data |
| 1918 |
if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_log_reply_edit'] ) ) |
| 1919 |
$reply_revision = $_POST['bbp_log_reply_edit']; |
| 1920 |
|
| 1921 |
// No data |
| 1922 |
else |
| 1923 |
$reply_revision = 1; |
| 1924 |
|
| 1925 |
return apply_filters( 'bbp_get_form_reply_log_edit', checked( $reply_revision, true, false ) ); |
| 1926 |
} |
| 1927 |
|
| 1928 |
/** |
| 1929 |
* Output the value of the reply edit reason |
| 1930 |
* |
| 1931 |
* @since bbPress {unknown} |
| 1932 |
* |
| 1933 |
* @uses bbp_get_form_reply_edit_reason() To get the reply edit reason value |
| 1934 |
*/ |
| 1935 |
function bbp_form_reply_edit_reason() { |
| 1936 |
echo bbp_get_form_reply_edit_reason(); |
| 1937 |
} |
| 1938 |
/** |
| 1939 |
* Return the value of the reply edit reason |
| 1940 |
* |
| 1941 |
* @since bbPress {unknown} |
| 1942 |
* |
| 1943 |
* @uses apply_filters() Calls 'bbp_get_form_reply_edit_reason' with the |
| 1944 |
* reply edit reason value |
| 1945 |
* @return string Reply edit reason value |
| 1946 |
*/ |
| 1947 |
function bbp_get_form_reply_edit_reason() { |
| 1948 |
global $post; |
| 1949 |
|
| 1950 |
// Get _POST data |
| 1951 |
if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['bbp_reply_edit_reason'] ) ) |
| 1952 |
$reply_edit_reason = $_POST['bbp_reply_edit_reason']; |
| 1953 |
|
| 1954 |
// No data |
| 1955 |
else |
| 1956 |
$reply_edit_reason = ''; |
| 1957 |
|
| 1958 |
return apply_filters( 'bbp_get_form_reply_edit_reason', esc_attr( $reply_edit_reason ) ); |
| 1959 |
} |
| 1960 |
|
| 1961 |
?> |
| 1962 |
|