Ticket #2036: 2036.7.diff
File 2036.7.diff, 41.8 KB (added by , 10 years ago) |
---|
-
includes/admin/metaboxes.php
400 400 // Get some meta 401 401 $reply_topic_id = bbp_get_reply_topic_id( $post_id ); 402 402 $reply_forum_id = bbp_get_reply_forum_id( $post_id ); 403 $reply_to = bbp_get_reply_to( $post_id ); 403 404 404 405 // Allow individual manipulation of reply forum 405 406 if ( current_user_can( 'edit_others_replies' ) || current_user_can( 'moderate' ) ) : ?> … … 435 436 <input name="parent_id" id="bbp_topic_id" type="text" value="<?php echo esc_attr( $reply_topic_id ); ?>" /> 436 437 </p> 437 438 439 <p> 440 <strong class="label"><?php _e( 'Reply To:', 'bbpress' ); ?></strong> 441 <label class="screen-reader-text" for="bbp_reply_to"><?php _e( 'Reply To', 'bbpress' ); ?></label> 442 <input name="bbp_reply_to" id="bbp_reply_to" type="text" value="<?php echo esc_attr( $reply_to ); ?>" /> 443 </p> 444 438 445 <?php 439 446 wp_nonce_field( 'bbp_reply_metabox_save', 'bbp_reply_metabox' ); 440 447 do_action( 'bbp_reply_metabox', $post_id ); -
includes/admin/replies.php
220 220 '<ul>' . 221 221 '<li>' . __( '<strong>Forum</strong> dropdown determines the parent forum that the reply belongs to. Select the forum, or leave the default (Use Forum of Topic) to post the reply in forum of the topic.', 'bbpress' ) . '</li>' . 222 222 '<li>' . __( '<strong>Topic</strong> determines the parent topic that the reply belongs to.', 'bbpress' ) . '</li>' . 223 '<li>' . __( '<strong>Reply To</strong> determines the threading of the reply.', 'bbpress' ) . '</li>' . 223 224 '</ul>' 224 225 ) ); 225 226 … … 300 301 // Get the reply meta post values 301 302 $topic_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0; 302 303 $forum_id = !empty( $_POST['bbp_forum_id'] ) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id( $topic_id ); 304 $reply_to = !empty( $_POST['bbp_reply_to'] ) ? (int) $_POST['bbp_reply_to'] : 0; 303 305 304 306 // Get reply author data 305 307 $anonymous_data = bbp_filter_anonymous_post_data(); … … 307 309 $is_edit = (bool) isset( $_POST['save'] ); 308 310 309 311 // Formally update the reply 310 bbp_update_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit );312 bbp_update_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit, $reply_to ); 311 313 312 314 // Allow other fun things to happen 313 do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id );315 do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id, $reply_to ); 314 316 do_action( 'bbp_author_metabox_save', $reply_id, $anonymous_data ); 315 317 316 318 return $reply_id; -
includes/admin/settings.php
176 176 177 177 'bbp_settings_theme_compat' => array( 178 178 179 // Replies per page setting179 // Theme package setting 180 180 '_bbp_theme_package_id' => array( 181 181 'title' => __( 'Current Package', 'bbpress' ), 182 182 'callback' => 'bbp_admin_setting_callback_subtheme_id', … … 203 203 'callback' => 'bbp_admin_setting_callback_replies_per_page', 204 204 'sanitize_callback' => 'intval', 205 205 'args' => array() 206 ), 207 208 // Set reply threading level 209 '_bbp_thread_replies_depth' => array( 210 'title' => __( 'Thread level', 'bbpress' ), 211 'callback' => 'bbp_admin_setting_callback_thread_replies_depth', 212 'sanitize_callback' => 'intval', 213 'args' => array() 206 214 ) 207 215 ), 208 216 … … 505 513 } 506 514 507 515 /** 516 * Hierarchical reply max depth level setting field; replies will be threaded 517 * if depth is 2 or greater 518 * 519 * @since bbPress (r####) 520 * 521 * @uses apply_filters() Calls 'bbp_thread_replies_depth_max' to set a 522 * maximum displayed level 523 * @uses selected() To display the selected attribute 524 */ 525 function bbp_admin_setting_callback_thread_replies_depth() { 526 527 // Set maximum depth for dropdown 528 $max_depth = (int) apply_filters( 'bbp_thread_replies_depth_max', 10 ); 529 $current_depth = get_option( '_bbp_thread_replies_depth' ); 530 531 ?> 532 <label for="_bbp_thread_replies_depth"> 533 <select id="_bbp_thread_replies_depth" name="_bbp_thread_replies_depth"> 534 <?php for ( $i = 0; $i <= $max_depth; $i++ ) : ?> 535 536 <option value="<?php echo esc_attr( $i ); ?>" <?php selected( $i, $current_depth ); ?>><?php echo esc_html( $i ); ?></option> 537 538 <?php endfor; ?> 539 </select> 540 <?php _e( ' levels deep', 'bbpress' ); ?> 541 </label> 542 <?php 543 } 544 545 /** 508 546 * Allow topic and reply revisions 509 547 * 510 548 * @since bbPress (r3412) -
includes/common/classes.php
259 259 } 260 260 } 261 261 262 /** 263 * Create hierarchical list of bbPress replies. 264 * 265 * @package bbPress 266 * @subpackage Classes 267 * 268 * @since bbPress (r####) 269 */ 270 class Walker_Reply extends Walker { 271 272 /** 273 * @see Walker::$tree_type 274 * 275 * @since bbPress (r####) 276 * 277 * @var string 278 */ 279 var $tree_type = 'reply'; 280 281 /** 282 * @see Walker::$db_fields 283 * 284 * @since bbPress (r####) 285 * 286 * @var array 287 */ 288 var $db_fields = array( 289 'parent' => 'reply_to', 290 'id' => 'ID' 291 ); 292 293 /** 294 * @see Walker::start_lvl() 295 * 296 * @since bbPress (r####) 297 * 298 * @param string $output Passed by reference. Used to append additional content 299 * @param int $depth Depth of reply 300 * @param array $args Uses 'style' argument for type of HTML list 301 */ 302 public function start_lvl( &$output, $depth = 0, $args = array( ) ) { 303 $GLOBALS['reply_depth'] = $depth + 1; 304 305 switch ( $args['style'] ) { 306 case 'div': 307 break; 308 case 'ol': 309 echo "<ol class='children'>\n"; 310 break; 311 case 'ul': 312 default: 313 echo "<ul class='children'>\n"; 314 break; 315 } 316 } 317 318 /** 319 * @see Walker::end_lvl() 320 * 321 * @since bbPress (r####) 322 * 323 * @param string $output Passed by reference. Used to append additional content 324 * @param int $depth Depth of reply 325 * @param array $args Will only append content if style argument value is 'ol' or 'ul' 326 */ 327 public function end_lvl( &$output, $depth = 0, $args = array( ) ) { 328 $GLOBALS['reply_depth'] = $depth + 1; 329 330 switch ( $args['style'] ) { 331 case 'div': 332 break; 333 case 'ol': 334 echo "</ol>\n"; 335 break; 336 case 'ul': 337 default: 338 echo "</ul>\n"; 339 break; 340 } 341 } 342 343 /** 344 * @since bbPress (r####) 345 */ 346 public function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { 347 348 if ( !$element ) 349 return; 350 351 // Get element's id 352 $id_field = $this->db_fields['id']; 353 $id = $element->$id_field; 354 355 // Display element 356 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); 357 358 // If we're at the max depth and the current element still has children, loop over those 359 // and display them at this level to prevent them being orphaned to the end of the list. 360 if ( $max_depth <= $depth + 1 && isset( $children_elements[$id] ) ) { 361 foreach ( $children_elements[$id] as $child ) 362 $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output ); 363 364 unset( $children_elements[$id] ); 365 } 366 } 367 368 /** 369 * @see Walker:start_el() 370 * 371 * @since bbPress (r####) 372 */ 373 public function start_el( &$output, $reply, $depth, $args, $id = 0 ) { 374 375 // Set up reply 376 $depth++; 377 $GLOBALS['reply_depth'] = $depth; 378 bbpress()->reply_query->post = $reply; 379 bbpress()->current_reply_id = $reply->ID; 380 381 // Check for a callback and use it if specified 382 if ( !empty( $args['callback'] ) ) { 383 call_user_func( $args['callback'], $reply, $args, $depth ); 384 return; 385 } 386 387 // Style for div or list element 388 if ( 'div' == $args['style'] ) { 389 $tag = 'div'; 390 $add_below = 'reply'; 391 } else { 392 $tag = 'li'; 393 $add_below = 'div-reply'; 394 } ?> 395 396 <<?php echo $tag ?>> 397 398 <?php bbp_get_template_part( 'loop', 'single-reply' ); ?> 399 400 </<?php echo $tag ?>> 401 402 <?php 403 } 404 405 /** 406 * @since bbPress (r####) 407 */ 408 public function end_el( &$output, $reply, $depth = 0, $args = array( ) ) { 409 410 // Check for a callback and use it if specified 411 if ( !empty( $args['end-callback'] ) ) { 412 call_user_func( $args['end-callback'], $reply, $args, $depth ); 413 return; 414 } 415 416 // Style for div or list element 417 if ( 'div' == $args['style'] ) 418 echo "</div>\n"; 419 else 420 echo "</li>\n"; 421 } 422 } 423 262 424 endif; // class_exists check -
includes/common/template-tags.php
1582 1582 1583 1583 <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php bbp_reply_title(); ?>" /> 1584 1584 <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php bbp_reply_id(); ?>" /> 1585 <input type="hidden" name="bbp_reply_to" id="bbp_reply_to" value="<?php bbp_form_reply_to(); ?>" /> 1585 1586 <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-reply" /> 1586 1587 1587 1588 <?php if ( current_user_can( 'unfiltered_html' ) ) … … 1593 1594 1594 1595 <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?>" /> 1595 1596 <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" /> 1597 <input type="hidden" name="bbp_reply_to" id="bbp_reply_to" value="<?php bbp_form_reply_to(); ?>" /> 1596 1598 <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-reply" /> 1597 1599 1598 1600 <?php if ( current_user_can( 'unfiltered_html' ) ) -
includes/core/actions.php
181 181 add_action( 'bbp_forum_attributes_metabox_save', 'bbp_save_forum_extras', 2 ); 182 182 183 183 // New/Edit Reply 184 add_action( 'bbp_new_reply', 'bbp_update_reply', 10, 6);185 add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 6);184 add_action( 'bbp_new_reply', 'bbp_update_reply', 10, 7 ); 185 add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 7 ); 186 186 187 187 // Before Delete/Trash/Untrash Reply 188 188 add_action( 'wp_trash_post', 'bbp_trash_reply' ); -
includes/core/options.php
34 34 '_bbp_enable_favorites' => 1, // Favorites 35 35 '_bbp_enable_subscriptions' => 1, // Subscriptions 36 36 '_bbp_allow_topic_tags' => 1, // Topic Tags 37 '_bbp_thread_replies_depth' => 0, // Thread replies depth 37 38 '_bbp_allow_anonymous' => 0, // Allow anonymous posting 38 39 '_bbp_allow_global_access' => 1, // Users from all sites can post 39 40 '_bbp_use_wp_editor' => 1, // Use the WordPress editor if available … … 227 228 } 228 229 229 230 /** 231 * Are replies threaded 232 * 233 * @since bbPress (r####) 234 * 235 * @param bool $default Optional. Default value true 236 * @uses apply_filters() Calls 'bbp_thread_replies' with the calculated value and 237 * the thread replies depth 238 * @uses get_option() To get thread replies option 239 * @return bool Are replies threaded? 240 */ 241 function bbp_thread_replies() { 242 $depth = bbp_thread_replies_depth(); 243 $retval = (bool) ( $depth > 1 ); 244 245 return (bool) apply_filters( 'bbp_thread_replies', $retval, $depth ); 246 } 247 248 /** 249 * Maximum reply thread depth 250 * 251 * @since bbPress (r####) 252 * 253 * @param int $default Thread replies depth 254 * @uses apply_filters() Calls 'bbp_thread_replies_depth' with the option value and 255 * the default depth 256 * @uses get_option() To get the thread replies depth 257 * @return int Thread replies depth 258 */ 259 function bbp_thread_replies_depth( $default = 1 ) { 260 return (int) apply_filters( 'bbp_thread_replies_depth', (int) get_option( '_bbp_thread_replies_depth', $default ) ); 261 } 262 263 /** 230 264 * Are topic and reply revisions allowed 231 265 * 232 266 * @since bbPress (r3412) … … 283 317 * @return bool Use WP editor? 284 318 */ 285 319 function bbp_use_wp_editor( $default = 1 ) { 320 321 // Disable if replies are threaded 322 if ( bbp_thread_replies() ) 323 $default = 0; 324 286 325 return (bool) apply_filters( 'bbp_use_wp_editor', (bool) get_option( '_bbp_use_wp_editor', $default ) ); 287 326 } 288 327 -
includes/replies/functions.php
97 97 * @uses wp_set_post_terms() To set the topic tags 98 98 * @uses wp_insert_post() To insert the reply 99 99 * @uses do_action() Calls 'bbp_new_reply' with the reply id, topic id, forum 100 * id, anonymous data and reply author 100 * id, anonymous data, reply author, edit (false), and 101 * the reply to id 101 102 * @uses bbp_get_reply_url() To get the paginated url to the reply 102 103 * @uses wp_safe_redirect() To redirect to the reply url 103 104 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error … … 116 117 } 117 118 118 119 // Define local variable(s) 119 $topic_id = $forum_id = $reply_author = $anonymous_data = 0;120 $topic_id = $forum_id = $reply_author = $anonymous_data = $reply_to = 0; 120 121 $reply_title = $reply_content = $terms = ''; 121 122 122 123 /** Reply Author **********************************************************/ … … 195 196 } 196 197 } 197 198 199 /** Reply To **************************************************************/ 200 201 // Handle Reply To of the reply; $_REQUEST for non-JS submissions 202 if ( isset( $_REQUEST['bbp_reply_to'] ) ) { 203 $reply_to = (int) $_REQUEST['bbp_reply_to']; 204 } 205 206 $reply_to = bbp_get_reply_id( $reply_to ); 207 198 208 /** Unfiltered HTML *******************************************************/ 199 209 200 210 // Remove kses filters from title and content for capable users and if the nonce is verified … … 364 374 365 375 /** Update counts, etc... *********************************************/ 366 376 367 do_action( 'bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author );377 do_action( 'bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, false, $reply_to ); 368 378 369 379 /** Additional Actions (After Save) ***********************************/ 370 380 … … 421 431 * @uses wp_update_post() To update the reply 422 432 * @uses bbp_get_reply_topic_id() To get the reply topic id 423 433 * @uses bbp_get_topic_forum_id() To get the topic forum id 434 * @uses bbp_get_reply_to() To get the reply to id 424 435 * @uses do_action() Calls 'bbp_edit_reply' with the reply id, topic id, forum 425 * id, anonymous data, reply author and bool true (for edit) 436 * id, anonymous data, reply author, bool true (for edit), 437 * and the reply to id 426 438 * @uses bbp_get_reply_url() To get the paginated url to the reply 427 439 * @uses wp_safe_redirect() To redirect to the reply url 428 440 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error … … 501 513 502 514 $forum_id = bbp_get_topic_forum_id( $topic_id ); 503 515 516 /** Reply To **************************************************************/ 517 518 $reply_to = bbp_get_reply_to( $reply_id ); 519 504 520 // Forum exists 505 521 if ( !empty( $forum_id ) && ( $forum_id !== bbp_get_reply_forum_id( $reply_id ) ) ) { 506 522 … … 660 676 if ( !empty( $reply_id ) && !is_wp_error( $reply_id ) ) { 661 677 662 678 // Update counts, etc... 663 do_action( 'bbp_edit_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author , true /* Is edit */ );679 do_action( 'bbp_edit_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author , true /* Is edit */, $reply_to ); 664 680 665 681 /** Additional Actions (After Save) ***********************************/ 666 682 … … 702 718 * @param bool|array $anonymous_data Optional logged-out user data. 703 719 * @param int $author_id Author id 704 720 * @param bool $is_edit Optional. Is the post being edited? Defaults to false. 721 * @param int $reply_to Optional. Reply to id 705 722 * @uses bbp_get_reply_id() To get the reply id 706 723 * @uses bbp_get_topic_id() To get the topic id 707 724 * @uses bbp_get_forum_id() To get the forum id … … 718 735 * @uses bbp_add_user_subscription() To add the user's subscription 719 736 * @uses bbp_update_reply_forum_id() To update the reply forum id 720 737 * @uses bbp_update_reply_topic_id() To update the reply topic id 738 * @uses bbp_update_reply_to() To update the reply to id 721 739 * @uses bbp_update_reply_walker() To update the reply's ancestors' counts 722 740 */ 723 function bbp_update_reply( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false ) {741 function bbp_update_reply( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0 ) { 724 742 725 743 // Validate the ID's passed from 'bbp_new_reply' action 726 $reply_id = bbp_get_reply_id( $reply_id ); 727 $topic_id = bbp_get_topic_id( $topic_id ); 728 $forum_id = bbp_get_forum_id( $forum_id ); 744 $reply_id = bbp_get_reply_id( $reply_id ); 745 $topic_id = bbp_get_topic_id( $topic_id ); 746 $forum_id = bbp_get_forum_id( $forum_id ); 747 $reply_to = bbp_get_reply_id( $reply_to ); 729 748 730 749 // Bail if there is no reply 731 750 if ( empty( $reply_id ) ) … … 789 808 // Reply meta relating to reply position in tree 790 809 bbp_update_reply_forum_id( $reply_id, $forum_id ); 791 810 bbp_update_reply_topic_id( $reply_id, $topic_id ); 811 bbp_update_reply_to( $reply_id, $reply_to ); 792 812 793 813 // Update associated topic values if this is a new reply 794 814 if ( empty( $is_edit ) ) { … … 1026 1046 return apply_filters( 'bbp_update_reply_topic_id', (int) $topic_id, $reply_id ); 1027 1047 } 1028 1048 1049 /* 1050 * Update the reply's meta data with its reply to id 1051 * 1052 * @since bbPress (r####) 1053 * 1054 * @param int $reply_id Reply id to update 1055 * @param int $reply_to Optional. Reply to id 1056 * @uses bbp_get_reply_id() To get the reply id 1057 * @uses update_post_meta() To update the reply to meta 1058 * @uses apply_filters() Calls 'bbp_update_reply_to' with the reply id and 1059 * and reply to id 1060 * @return bool Reply's parent reply id 1061 */ 1062 function bbp_update_reply_to( $reply_id = 0, $reply_to = 0 ) { 1063 1064 // Validation 1065 $reply_id = bbp_get_reply_id( $reply_id ); 1066 $reply_to = bbp_get_reply_id( $reply_to ); 1067 1068 // Return if no reply 1069 if ( empty( $reply_id ) ) 1070 return; 1071 1072 // Return if no reply to 1073 if ( empty( $reply_to ) ) 1074 return; 1075 1076 // Set the reply to 1077 update_post_meta( $reply_id, '_bbp_reply_to', $reply_to ); 1078 1079 return (int) apply_filters( 'bbp_update_reply_to', (int) $reply_to, $reply_id ); 1080 } 1081 1029 1082 /** 1030 1083 * Update the revision log of the reply 1031 1084 * … … 1286 1339 $last_reply_id = $move_reply->ID; 1287 1340 $freshness = $move_reply->post_date; 1288 1341 1342 // Get the reply to 1343 $parent = bbp_get_reply_to( $move_reply->ID ); 1344 1345 // Fix orphaned children 1346 $children = get_posts( array( 1347 'post_type' => bbp_get_reply_post_type(), 1348 'meta_key' => '_bbp_reply_to', 1349 'meta_value' => $move_reply->ID, 1350 ) ); 1351 foreach ( $children as $child ) 1352 bbp_update_reply_to( $child->ID, $parent ); 1353 1354 // Remove reply_to from moved reply 1355 delete_post_meta( $move_reply->ID, '_bbp_reply_to' ); 1356 1289 1357 // It is a new topic and we need to set some default metas to make 1290 1358 // the topic display in bbp_has_topics() list 1291 1359 if ( 'topic' == $move_option ) { … … 2072 2140 2073 2141 return (int) $reply_position; 2074 2142 } 2143 2144 /** Hierarchical Replies ******************************************************/ 2145 2146 /** 2147 * List replies 2148 * 2149 * @since bbPress (r####) 2150 */ 2151 function bbp_list_replies( $args = array(), $replies = null ) { 2152 global $reply_alt, $reply_depth, $reply_thread_alt; 2153 2154 // In reply loop 2155 bbpress()->reply_query->in_the_loop = true; 2156 2157 // Initialize variables 2158 $reply_alt = $reply_thread_alt = 0; 2159 $reply_depth = 1; 2160 2161 $defaults = array( 2162 'walker' => null, 2163 'max_depth' => bbp_thread_replies_depth(), 2164 'style' => 'ul', 2165 'callback' => null, 2166 'end_callback' => null, 2167 'page' => 1, 2168 'per_page' => -1 2169 ); 2170 2171 $r = wp_parse_args( $args, $defaults ); 2172 2173 // Get replies to loop through in $_replies 2174 if ( null !== $replies ) { 2175 $replies = (array) $replies; 2176 if ( empty( $replies ) ) 2177 return; 2178 $_replies = $replies; 2179 } else { 2180 if ( empty( bbpress()->reply_query->posts ) ) 2181 return; 2182 $_replies = bbpress()->reply_query->posts; 2183 } 2184 2185 if ( empty( $walker ) ) 2186 $walker = new Walker_Reply; 2187 2188 $walker->paged_walk( $_replies, $r['max_depth'], $r['page'], $r['per_page'], $r ); 2189 bbpress()->max_num_pages = $walker->max_pages; 2190 2191 bbpress()->reply_query->in_the_loop = false; 2192 } -
includes/replies/template-tags.php
80 80 'paged' => bbp_get_paged(), // On this page 81 81 'orderby' => 'date', // Sorted by date 82 82 'order' => 'ASC', // Oldest to newest 83 'hierarchical' => false, // Hierarchical replies 83 84 'ignore_sticky_posts' => true, // Stickies not supported 84 85 's' => $default_reply_search, // Maybe search 85 86 ); … … 113 114 // Parse arguments against default values 114 115 $r = bbp_parse_args( $args, $default, 'has_replies' ); 115 116 117 // Set posts_per_page value if replies are threaded 118 $replies_per_page = $r['posts_per_page']; 119 if ( $r['hierarchical'] ) { 120 $r['posts_per_page'] = -1; 121 } 122 116 123 // Get bbPress 117 124 $bbp = bbpress(); 118 125 … … 120 127 $bbp->reply_query = new WP_Query( $r ); 121 128 122 129 // Add pagination values to query object 123 $bbp->reply_query->posts_per_page = $r ['posts_per_page'];130 $bbp->reply_query->posts_per_page = $replies_per_page; 124 131 $bbp->reply_query->paged = $r['paged']; 125 132 126 133 // Never home, regardless of what parse_query says … … 131 138 $bbp->reply_query->is_single = true; 132 139 } 133 140 141 // Only add reply to if query returned results 142 if ( (int) $bbp->reply_query->found_posts ) { 143 144 // Get reply to for each reply 145 foreach ( $bbp->reply_query->posts as &$post ) { 146 147 // Check for reply post type 148 if ( $post->post_type == bbp_get_reply_post_type() ) { 149 $reply_to = bbp_get_reply_to( $post->ID ); 150 151 // Make sure it's a reply to a reply 152 if ( empty( $reply_to ) || ( bbp_get_reply_topic_id( $post->ID ) == $reply_to ) ) 153 $reply_to = 0; 154 $post->reply_to = $reply_to; 155 } 156 } 157 } 158 134 159 // Only add pagination if query returned results 135 160 if ( (int) $bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page ) { 136 161 … … 161 186 $base = add_query_arg( 'paged', '%#%' ); 162 187 } 163 188 164 // Add pagination to query object 165 $bbp->reply_query->pagination_links = paginate_links( 166 apply_filters( 'bbp_replies_pagination', array( 167 'base' => $base, 168 'format' => '', 169 'total' => ceil( (int) $bbp->reply_query->found_posts / (int) $r['posts_per_page'] ), 170 'current' => (int) $bbp->reply_query->paged, 171 'prev_text' => is_rtl() ? '→' : '←', 172 'next_text' => is_rtl() ? '←' : '→', 173 'mid_size' => 1, 174 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false 175 ) ) 176 ); 189 // Figure out total pages 190 if ( $r['hierarchical'] ) { 191 $walker = new Walker_Reply; 192 $total_pages = ceil( (int) $walker->get_number_of_root_elements( $bbp->reply_query->posts ) / (int) $replies_per_page ); 193 } else { 194 $total_pages = ceil( (int) $bbp->reply_query->found_posts / (int) $replies_per_page ); 177 195 178 // Remove first page from pagination 179 if ( $wp_rewrite->using_permalinks() ) { 180 $bbp->reply_query->pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $bbp->reply_query->pagination_links ); 181 } else { 182 $bbp->reply_query->pagination_links = str_replace( '&paged=1', '', $bbp->reply_query->pagination_links ); 196 // Add pagination to query object 197 $bbp->reply_query->pagination_links = paginate_links( 198 apply_filters( 'bbp_replies_pagination', array( 199 'base' => $base, 200 'format' => '', 201 'total' => $total_pages, 202 'current' => (int) $bbp->reply_query->paged, 203 'prev_text' => is_rtl() ? '→' : '←', 204 'next_text' => is_rtl() ? '←' : '→', 205 'mid_size' => 1, 206 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false 207 ) ) 208 ); 209 210 // Remove first page from pagination 211 if ( $wp_rewrite->using_permalinks() ) { 212 $bbp->reply_query->pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $bbp->reply_query->pagination_links ); 213 } else { 214 $bbp->reply_query->pagination_links = str_replace( '&paged=1', '', $bbp->reply_query->pagination_links ); 215 } 183 216 } 184 217 } 185 218 … … 386 419 // Set needed variables 387 420 $reply_id = bbp_get_reply_id ( $reply_id ); 388 421 $topic_id = bbp_get_reply_topic_id( $reply_id ); 389 $reply_page = ceil( (int) bbp_get_reply_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() ); 422 423 // Hierarchical reply page 424 if ( bbp_thread_replies() ) { 425 $reply_page = 1; 426 427 // Standard reply page 428 } else { 429 $reply_page = ceil( (int) bbp_get_reply_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() ); 430 } 431 390 432 $reply_hash = '#post-' . $reply_id; 391 433 $topic_link = bbp_get_topic_permalink( $topic_id, $redirect_to ); 392 434 $topic_url = remove_query_arg( 'view', $topic_link ); … … 1377 1419 } 1378 1420 1379 1421 /** 1422 * Output the reply's ancestor reply id 1423 * 1424 * @since bbPress (r####) 1425 * 1426 * @param int $reply_id Optional. Reply id 1427 * @uses bbp_get_reply_ancestor_id() To get the reply's ancestor id 1428 */ 1429 function bbp_reply_ancestor_id( $reply_id = 0 ) { 1430 echo bbp_get_reply_ancestor_id( $reply_id ); 1431 } 1432 /** 1433 * Return the reply's ancestor reply id 1434 * 1435 * @since bbPress (r####) 1436 * 1437 * @param in $reply_id Reply id 1438 * @uses bbp_get_reply_id() To get the reply id 1439 */ 1440 function bbp_get_reply_ancestor_id( $reply_id = 0 ) { 1441 1442 // Validation 1443 $reply_id = bbp_get_reply_id( $reply_id ); 1444 if ( empty( $reply_id ) ) 1445 return false; 1446 1447 // Find highest reply ancestor 1448 $ancestor_id = $reply_id; 1449 while ( $parent_id = bbp_get_reply_to( $ancestor_id ) ) { 1450 if ( empty( $parent_id ) || $parent_id == $ancestor_id || $parent_id == bbp_get_reply_topic_id( $reply_id ) || $parent_id == $reply_id ) 1451 break; 1452 $ancestor_id = $parent_id; 1453 } 1454 1455 return (int) $ancestor_id; 1456 } 1457 1458 /** 1459 * Output the reply to id of a reply 1460 * 1461 * @since bbPress (r####) 1462 * 1463 * @param int $reply_id Optional. Reply id 1464 * @uses bbp_get_reply_to() To get the reply to id 1465 */ 1466 function bbp_reply_to( $reply_id = 0 ) { 1467 echo bbp_get_reply_to( $reply_id ); 1468 } 1469 /** 1470 * Return the reply to id of a reply 1471 * 1472 * @since bbPress (r####) 1473 * 1474 * @param int $reply_id Optional. Reply id 1475 * @uses bbp_get_reply_id() To get the reply id 1476 * @uses get_post_meta() To get the reply to id 1477 * @uses apply_filters() Calls 'bbp_get_reply_to' with the reply to id and 1478 * reply id 1479 * @return int Reply's reply to id 1480 */ 1481 function bbp_get_reply_to( $reply_id = 0 ) { 1482 1483 // Assume there is no reply_to set 1484 $reply_to = 0; 1485 1486 // Check that reply_id is valid 1487 if ( $reply_id = bbp_get_reply_id( $reply_id ) ) 1488 1489 // Get reply_to value 1490 $reply_to = (int) get_post_meta( $reply_id, '_bbp_reply_to', true ); 1491 1492 return (int) apply_filters( 'bbp_get_reply_to', $reply_to, $reply_id ); 1493 } 1494 1495 /** 1496 * Output the link for the reply to 1497 * 1498 * @since bbPress (r####) 1499 * 1500 * @param array $args 1501 * @param int $reply 1502 * @uses bbp_get_reply_to_link() To get the reply to link 1503 */ 1504 function bbp_reply_to_link( $args = array(), $reply = 0 ) { 1505 echo bbp_get_reply_to_link( $args, $reply ); 1506 } 1507 1508 /** 1509 * Return the link for a reply to a reply 1510 * 1511 * @since bbPress (r####) 1512 * 1513 * @param array $args Arguments 1514 * @param int $reply_id Reply id 1515 * @uses bbp_current_user_can_access_create_reply_form() To check permissions 1516 * @uses bbp_get_reply_id() To validate the reply id 1517 * @uses bbp_get_reply() To get the reply 1518 * @uses apply_filters() Calls 'bbp_get_reply_to_link' with the formatted link, 1519 * the arguments array, and the reply 1520 * @return string Link for a reply to a reply 1521 */ 1522 function bbp_get_reply_to_link( $args = array(), $reply_id = 0 ) { 1523 1524 // Parse arguments against default values 1525 $r = bbp_parse_args( $args, array( 1526 'id' => 0, 1527 'link_before' => '', 1528 'link_after' => '', 1529 'reply_text' => __( 'Reply', 'bbpress' ), 1530 'depth' => 0, 1531 'add_below' => 'post', 1532 'respond_id' => 'new-reply-' . bbp_get_topic_id(), 1533 ), 'get_reply_to_link' ); 1534 1535 $reply = bbp_get_reply( bbp_get_reply_id( (int) $r['id'] ) ); 1536 1537 // Bail if no reply or user cannot reply 1538 if ( empty( $reply ) || ! bbp_current_user_can_access_create_reply_form() ) 1539 return; 1540 1541 // Build the URI and return value 1542 $uri = remove_query_arg( array( 'bbp_reply_to' ) ); 1543 $uri = add_query_arg( array( 'bbp_reply_to' => $reply->ID ) ); 1544 $uri = esc_url( wp_nonce_url( $uri, 'respond_id_' . $reply->ID ) ); 1545 $uri = $uri . '#new-post'; 1546 $onclick = 'return addReply.moveForm("' . $r['add_below'] . '-' . $reply->ID . '","' . $reply->ID . '","' . $r['respond_id'] . '","' . $reply->post_parent . '")'; 1547 $r['uri'] = $uri; 1548 $retval = $r['link_before'] . '<a href="' . $r['uri'] . '" class="bbp-reply-to-link" onclick=' . "'{$onclick}' >" . $r['reply_text'] . '</a>' . $r['link_after']; 1549 1550 return apply_filters( 'bbp_get_reply_spam_link', $retval, $r ); 1551 } 1552 1553 /** 1554 * Output the reply to a reply cancellation link 1555 * 1556 * @since bbPress (r####) 1557 * 1558 * @uses bbp_get_cancel_reply_to_link() To get the reply cancellation link 1559 */ 1560 function bbp_cancel_reply_to_link( $text = '' ) { 1561 echo bbp_get_cancel_reply_to_link( $text ); 1562 } 1563 /** 1564 * Return the cancellation link for a reply to a reply 1565 * 1566 * @since bbPress (r####) 1567 * 1568 * @param string $text The cancel text 1569 * @uses apply_filters() Calls 'bbp_get_cancel_reply_to_link' with the cancellation 1570 * link and the cancel text 1571 * @return string The cancellation link 1572 */ 1573 function bbp_get_cancel_reply_to_link( $text = '' ) { 1574 1575 // Bail if not hierarchical or editing a reply 1576 if ( ! bbp_thread_replies() || bbp_is_reply_edit() ) 1577 return; 1578 1579 // Set default text 1580 if ( empty( $text ) ) 1581 $text = __( 'Cancel', 'bbpress' ); 1582 1583 $reply_to = isset( $_GET['bbp_reply_to'] ) ? (int) $_GET['bbp_reply_to'] : 0; 1584 1585 // Set visibility 1586 $style = !empty( $reply_to ) ? '' : ' style="display:none;"'; 1587 $link = esc_url( remove_query_arg( array( 'bbp_reply_to', '_wpnonce' ) ) ) . '#post-' . $reply_to; 1588 1589 return apply_filters( 'bbp_get_cancel_reply_to_link', '<a rel="nofollow" id="bbp-cancel-reply-to-link" href="' . $link . '"' . $style . '>' . $text . '</a>', $link, $text ); 1590 } 1591 1592 /** 1380 1593 * Output the numeric position of a reply within a topic 1381 1594 * 1382 1595 * @since bbPress (r2984) … … 1516 1729 'split' => bbp_get_topic_split_link( $r ), 1517 1730 'trash' => bbp_get_reply_trash_link( $r ), 1518 1731 'spam' => bbp_get_reply_spam_link ( $r ), 1732 'reply' => bbp_get_reply_to_link ( $r ) 1519 1733 ), $r['id'] ); 1520 1734 } 1521 1735 … … 2011 2225 $total_int = (int) $bbp->reply_query->found_posts; 2012 2226 $total = bbp_number_format( $total_int ); 2013 2227 2228 // We are threading replies 2229 if ( bbp_thread_replies() ) { 2230 $walker = new Walker_Reply; 2231 $threads = (int) $walker->get_number_of_root_elements( $bbp->reply_query->posts ); 2232 2233 // Adjust for topic 2234 $threads--; 2235 $retstr = sprintf( _n( 'Viewing %1$d reply thread', 'Viewing %1$d reply threads', $threads, 'bbbpress' ), $threads ); 2236 2014 2237 // We are not including the lead topic 2015 if ( bbp_show_lead_topic() ) {2238 } elseif ( bbp_show_lead_topic() ) { 2016 2239 2017 2240 // Several replies in a topic with a single page 2018 2241 if ( empty( $to_num ) ) { … … 2108 2331 } 2109 2332 2110 2333 /** 2334 * Output the value of the reply to field 2335 * 2336 * @since bbPress (r####) 2337 * 2338 * @uses bbp_get_form_reply_to() To get value of the reply to field 2339 */ 2340 function bbp_form_reply_to() { 2341 echo bbp_get_form_reply_to(); 2342 } 2343 2344 /** 2345 * Return the value of reply to field 2346 * 2347 * @since bbPress (r####) 2348 * 2349 * @uses bbp_get_reply_id() To validate the reply to 2350 * @uses apply_filters() Calls 'bbp_get_form_reply_to' with the reply to 2351 * @return string Value of reply to field 2352 */ 2353 function bbp_get_form_reply_to() { 2354 2355 // Set initial value 2356 $reply_to = 0; 2357 2358 // Get $_REQUEST data 2359 if ( isset( $_REQUEST['bbp_reply_to'] ) ) 2360 $reply_to = (int) $_REQUEST['bbp_reply_to']; 2361 2362 // If empty, get from meta 2363 if ( empty( $reply_to ) ) 2364 $reply_to = bbp_get_reply_to(); 2365 2366 // Validate 2367 $reply_to = bbp_get_reply_id( $reply_to ); 2368 2369 return (int) apply_filters( 'bbp_get_form_reply_to', $reply_to ); 2370 } 2371 2372 /** 2111 2373 * Output checked value of reply log edit field 2112 2374 * 2113 2375 * @since bbPress (r31301) -
includes/topics/functions.php
1259 1259 bbp_update_reply_topic_id( $reply->ID, $destination_topic->ID ); 1260 1260 bbp_update_reply_forum_id( $reply->ID, bbp_get_topic_forum_id( $destination_topic->ID ) ); 1261 1261 1262 // Adjust reply to values 1263 $reply_to = bbp_get_reply_to( $reply->ID ); 1264 if ( empty( $reply_to ) ) 1265 bbp_update_reply_to( $reply->ID, $source_topic->ID ); 1266 1262 1267 // Do additional actions per merged reply 1263 1268 do_action( 'bbp_merged_topic_reply', $reply->ID, $destination_topic->ID ); 1264 1269 } … … 1592 1597 break; 1593 1598 } 1594 1599 1600 // Save reply ids 1601 $reply_ids = array(); 1602 1595 1603 // Change the post_parent of each reply to the destination topic id 1596 1604 foreach ( $replies as $reply ) { 1597 1605 … … 1611 1619 // Update the reply 1612 1620 wp_update_post( $postarr ); 1613 1621 1622 // Gather reply ids 1623 $reply_ids[] = $reply->ID; 1624 1614 1625 // Adjust reply meta values 1615 1626 bbp_update_reply_topic_id( $reply->ID, $destination_topic->ID ); 1616 1627 bbp_update_reply_forum_id( $reply->ID, bbp_get_topic_forum_id( $destination_topic->ID ) ); 1617 1628 1629 // Adjust reply to values 1630 $reply_to = bbp_get_reply_to( $reply->ID ); 1631 1632 // Not a reply to a reply that moved over 1633 if ( !in_array( $reply_to, $reply_ids ) ) 1634 bbp_update_reply_to( $reply->ID, 0 ); 1635 1636 // New topic from reply can't be a reply to 1637 if ( ( $from_reply->ID == $destination_topic->ID && $from_reply->ID == $reply_to ) ) 1638 bbp_update_reply_to( $reply->ID, 0 ); 1639 1618 1640 // Do additional actions per split reply 1619 1641 do_action( 'bbp_split_topic_reply', $reply->ID, $destination_topic->ID ); 1620 1642 } 1621 1643 1644 // Remove reply to from new topic 1645 if ( $from_reply->ID == $destination_topic->ID ) 1646 delete_post_meta( $from_reply->ID, '_bbp_reply_to' ); 1647 1622 1648 // Set the last reply ID and freshness 1623 1649 $last_reply_id = $reply->ID; 1624 1650 $freshness = $reply->post_date; -
includes/topics/template-tags.php
788 788 function bbp_get_topic_pagination( $args = '' ) { 789 789 global $wp_rewrite; 790 790 791 if ( bbp_thread_replies() ) 792 return; 793 791 794 // Parse arguments against default values 792 795 $r = bbp_parse_args( $args, array( 793 796 'topic_id' => bbp_get_topic_id(), -
templates/default/bbpress/content-single-topic.php
31 31 32 32 <?php endif; ?> 33 33 34 <?php if ( bbp_has_replies( ) ) : ?>34 <?php if ( bbp_has_replies( array( 'hierarchical' => bbp_thread_replies() ) ) ) : ?> 35 35 36 36 <?php bbp_get_template_part( 'pagination', 'replies' ); ?> 37 37 -
templates/default/bbpress/form-reply.php
142 142 143 143 <?php do_action( 'bbp_theme_before_reply_form_submit_button' ); ?> 144 144 145 <?php bbp_cancel_reply_to_link(); ?> 146 145 147 <button type="submit" tabindex="<?php bbp_tab_index(); ?>" id="bbp_reply_submit" name="bbp_reply_submit" class="button submit"><?php _e( 'Submit', 'bbpress' ); ?></button> 146 148 147 149 <?php do_action( 'bbp_theme_after_reply_form_submit_button' ); ?> -
templates/default/bbpress/loop-replies.php
39 39 40 40 <li class="bbp-body"> 41 41 42 <?php while ( bbp_replies() ) : bbp_the_reply();?>42 <?php if ( bbp_thread_replies() ) : ?> 43 43 44 <?php bbp_ get_template_part( 'loop', 'single-reply'); ?>44 <?php bbp_list_replies(); ?> 45 45 46 <?php e ndwhile;?>46 <?php else : ?> 47 47 48 <?php while ( bbp_replies() ) : bbp_the_reply(); ?> 49 50 <?php bbp_get_template_part( 'loop', 'single-reply' ); ?> 51 52 <?php endwhile; ?> 53 54 <?php endif; ?> 55 48 56 </li><!-- .bbp-body --> 49 57 50 58 <li class="bbp-footer"> -
templates/default/bbpress/pagination-replies.php
12 12 <?php do_action( 'bbp_template_before_pagination_loop' ); ?> 13 13 14 14 <div class="bbp-pagination"> 15 15 16 <div class="bbp-pagination-count"> 16 17 17 18 <?php bbp_topic_pagination_count(); ?> -
templates/default/bbpress-functions.php
179 179 wp_enqueue_script( 'jquery' ); 180 180 } 181 181 182 // Topic favorite/subscribe182 // Topic-specific scripts 183 183 if ( bbp_is_single_topic() ) { 184 185 // Topic favorite/unsubscribe 184 186 wp_enqueue_script( 'bbpress-topic', $this->url . 'js/topic.js', array( 'jquery' ), $this->version ); 187 188 // Hierarchical replies 189 if ( bbp_thread_replies() ) { 190 wp_enqueue_script( 'bbpress-reply', $this->url . 'js/reply.js', array(), $this->version ); 191 } 185 192 } 186 193 187 194 // User Profile edit -
templates/default/css/bbpress-rtl.css
65 65 padding: 0; 66 66 } 67 67 68 #bbpress-forums ul.children { 69 margin-right: 2em; 70 } 71 68 72 #bbpress-forums li { 69 73 margin: 0; 70 74 list-style: none; … … 350 354 overflow-wrap: normal; 351 355 } 352 356 357 /* =Reply to 358 -------------------------------------------------------------- */ 359 360 #bbpress-forums div.bbp-reply-to { 361 margin-right: 130px; 362 padding: 12px 0px 12px 12px; 363 text-align: left; 364 } 365 366 #bbpress-forums div#bbp-cancel-reply-to { 367 text-align: left; 368 } 369 353 370 /* =Breadcrumb and Tags 354 371 -------------------------------------------------------------- */ 355 372 -
templates/default/css/bbpress.css
65 65 padding: 0; 66 66 } 67 67 68 #bbpress-forums ul.children { 69 margin-left: 2em; 70 } 71 68 72 #bbpress-forums li { 69 73 margin: 0; 70 74 list-style: none; … … 350 354 overflow-wrap: normal; 351 355 } 352 356 357 /* =Reply to 358 -------------------------------------------------------------- */ 359 360 #bbpress-forums div.bbp-reply-to { 361 margin-left: 130px; 362 padding: 12px 12px 12px 0; 363 text-align: right; 364 } 365 366 #bbpress-forums div#bbp-cancel-reply-to { 367 text-align: right; 368 } 369 353 370 /* =Breadcrumb and Tags 354 371 -------------------------------------------------------------- */ 355 372 -
templates/default/js/reply.js
1 addReply = { 2 moveForm : function(replyId, parentId, respondId, postId) { 3 var t = this, div, reply = t.I(replyId), respond = t.I(respondId), cancel = t.I('bbp-cancel-reply-to-link'), parent = t.I('bbp_reply_to'), post = t.I('bbp_topic_id'); 4 5 if ( ! reply || ! respond || ! cancel || ! parent ) 6 return; 7 8 t.respondId = respondId; 9 postId = postId || false; 10 11 if ( ! t.I('bbp-temp-form-div') ) { 12 div = document.createElement('div'); 13 div.id = 'bbp-temp-form-div'; 14 div.style.display = 'none'; 15 respond.parentNode.insertBefore(div, respond); 16 } 17 18 reply.parentNode.insertBefore(respond); 19 if ( post && postId ) 20 post.value = postId; 21 parent.value = parentId; 22 cancel.style.display = ''; 23 24 cancel.onclick = function() { 25 var t = addReply, temp = t.I('bbp-temp-form-div'), respond = t.I(t.respondId); 26 27 if ( ! temp || ! respond ) 28 return; 29 30 t.I('bbp_reply_to').value = '0'; 31 temp.parentNode.insertBefore(respond, temp); 32 temp.parentNode.removeChild(temp); 33 this.style.display = 'none'; 34 this.onclick = null; 35 return false; 36 } 37 38 try { t.I('bbp_reply_content').focus(); } 39 catch(e) {} 40 41 return false; 42 }, 43 44 I : function(e) { 45 return document.getElementById(e); 46 } 47 }