Changeset 3934 for branches/plugin/bbp-includes/bbp-reply-functions.php
- Timestamp:
- 06/01/2012 11:36:53 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-reply-functions.php
r3919 r3934 209 209 210 210 /** Reply Blacklist *******************************************************/ 211 211 212 212 if ( !bbp_check_for_blacklist( $anonymous_data, $reply_author, $reply_title, $reply_content ) ) 213 213 bbp_add_error( 'bbp_reply_blacklist', __( '<strong>ERROR</strong>: Your reply cannot be created at this time.', 'bbpress' ) ); 214 214 215 215 /** Reply Moderation ******************************************************/ 216 216 217 217 $post_status = bbp_get_public_status_id(); 218 218 if ( !bbp_check_for_moderation( $anonymous_data, $reply_author, $reply_title, $reply_content ) ) … … 243 243 'post_status' => $post_status, 244 244 'post_type' => bbp_get_reply_post_type(), 245 'comment_status' => 'closed' 245 'comment_status' => 'closed', 246 'menu_order' => (int) ( bbp_get_topic_reply_count( $topic_id ) + 1 ) 246 247 ); 247 248 … … 468 469 469 470 /** Reply Blacklist *******************************************************/ 470 471 471 472 if ( !bbp_check_for_blacklist( $anonymous_data, bbp_get_reply_author_id( $reply_id ), $reply_title, $reply_content ) ) 472 473 bbp_add_error( 'bbp_reply_blacklist', __( '<strong>ERROR</strong>: Your reply cannot be edited at this time.', 'bbpress' ) ); 473 474 474 475 /** Reply Moderation ******************************************************/ 475 476 476 477 $post_status = bbp_get_public_status_id(); 477 478 if ( !bbp_check_for_moderation( $anonymous_data, bbp_get_reply_author_id( $reply_id ), $reply_title, $reply_content ) ) … … 1174 1175 // Get pre spam status 1175 1176 $reply['post_status'] = get_post_meta( $reply_id, '_bbp_spam_meta_status', true ); 1176 1177 1177 1178 // Delete pre spam meta 1178 1179 delete_post_meta( $reply_id, '_bbp_spam_meta_status' ); … … 1355 1356 1356 1357 if ( bbp_use_autoembed() && is_a( $wp_embed, 'WP_Embed' ) ) { 1357 add_filter( 'bbp_get_reply_content', array( $wp_embed, 'autoembed' ), 8 ); 1358 add_filter( 'bbp_get_reply_content', array( $wp_embed, 'autoembed' ), 8 ); 1358 1359 } 1359 1360 } … … 1500 1501 /** 1501 1502 * Redirect if unathorized user is attempting to edit a reply 1502 * 1503 * 1503 1504 * @since bbPress (r3605) 1504 1505 * … … 1522 1523 } 1523 1524 1525 /** Reply Position ************************************************************/ 1526 1527 /** 1528 * Update the position of the reply. 1529 * 1530 * The reply position is stored in the menu_order column of the posts table. 1531 * This is done to prevent using a meta_query to retrieve posts in the proper 1532 * freshness order. By updating the menu_order accordingly, we're able to 1533 * leverage core WordPress query ordering much more effectively. 1534 * 1535 * @since bbPress (r3933) 1536 * 1537 * @global type $wpdb 1538 * @param type $reply_id 1539 * @param type $reply_position 1540 * @return mixed 1541 */ 1542 function bbp_update_reply_position( $reply_id = 0, $reply_position = 0 ) { 1543 1544 // Bail if reply_id is empty 1545 $reply_id = bbp_get_reply_id( $reply_id ); 1546 if ( empty( $reply_id ) ) 1547 return false; 1548 1549 // If no position was passed, get it from the db and update the menu_order 1550 if ( empty( $reply_position ) ) { 1551 $reply_position = bbp_get_reply_position_raw( $reply_id, bbp_get_reply_topic_id( $reply_id ) ); 1552 } 1553 1554 // Update the replies' 'menp_order' with the reply position 1555 global $wpdb; 1556 $wpdb->update( $wpdb->posts, array( 'menu_order' => $reply_position ), array( 'ID' => $reply_id ) ); 1557 1558 return (int) $reply_position; 1559 } 1560 1561 /** 1562 * Get the position of a reply by querying the DB directly for the replies 1563 * of a given topic. 1564 * 1565 * @since bbPress (r3933) 1566 * 1567 * @param int $reply_id 1568 * @param int $topic_id 1569 */ 1570 function bbp_get_reply_position_raw( $reply_id = 0, $topic_id = 0 ) { 1571 1572 // Get required data 1573 $reply_id = bbp_get_reply_id( $reply_id ); 1574 $topic_id = !empty( $topic_id ) ? bbp_get_topic_id( $topic_id ) : bbp_get_reply_topic_id( $reply_id ); 1575 1576 // If reply is actually the first post in a topic, return 0 1577 if ( $reply_id != $topic_id ) { 1578 1579 // Make sure the topic has replies before running another query 1580 $reply_count = bbp_get_topic_reply_count( $topic_id ); 1581 if ( !empty( $reply_count ) ) { 1582 1583 // Get reply id's 1584 $topic_replies = bbp_get_all_child_ids( $topic_id, bbp_get_reply_post_type() ); 1585 if ( !empty( $topic_replies ) ) { 1586 1587 // Reverse replies array and search for current reply position 1588 $topic_replies = array_reverse( $topic_replies ); 1589 $reply_position = array_search( (string) $reply_id, $topic_replies ); 1590 1591 // Bump the position to compensate for the lead topic post 1592 $reply_position++; 1593 } 1594 } 1595 } else { 1596 $reply_position = 0; 1597 } 1598 1599 return $reply_position; 1600 } 1601 1524 1602 ?>
Note: See TracChangeset
for help on using the changeset viewer.