Changeset 5954 for trunk/src/includes/forums/functions.php
- Timestamp:
- 11/18/2015 04:39:54 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/forums/functions.php
r5951 r5954 1556 1556 * 1557 1557 * @since 2.0.0 bbPress (r2888) 1558 * 1559 * @param int $forum_id Optional. Topic id to update 1560 * @param int $topic_count Optional. Set the topic count manually 1558 * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects 1559 * 1560 * @param int $forum_id Optional. Topic id to update. 1561 * @param int $topic_count Optional. Set the topic count manually. 1561 1562 * @uses bbp_is_topic() To check if the supplied id is a topic 1562 1563 * @uses bbp_get_topic_id() To get the topic id … … 1566 1567 * @uses bbp_get_spam_status_id() To get the spam status id 1567 1568 * @uses bbp_get_pending_status_id() To get the pending status id 1568 * @uses wpdb::prepare() To prepare our sql query 1569 * @uses wpdb::get_var() To execute our query and get the var back 1569 * @uses bbp_get_topic_post_type() To get the topic post type 1570 1570 * @uses update_post_meta() To update the forum hidden topic count meta 1571 1571 * @uses apply_filters() Calls 'bbp_update_forum_topic_count_hidden' with the … … 1590 1590 // Get topics of forum 1591 1591 if ( empty( $topic_count ) ) { 1592 $statuses = array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ); 1593 $post_status = "'" . implode( "','", $statuses ) . "'"; 1594 $bbp_db = bbp_db(); 1595 $topic_count = $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $forum_id, bbp_get_topic_post_type() ) ); 1592 $query = new WP_Query( array( 1593 'fields' => 'ids', 1594 'post_parent' => $forum_id, 1595 'post_status' => array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ), 1596 'post_type' => bbp_get_topic_post_type(), 1597 1598 // Maybe change these later 1599 'posts_per_page' => -1, 1600 'update_post_term_cache' => false, 1601 'update_post_meta_cache' => false, 1602 'ignore_sticky_posts' => true, 1603 ) ); 1604 $topic_count = $query->post_count; 1605 unset( $query ); 1596 1606 } 1597 1607 … … 1609 1619 * 1610 1620 * @since 2.0.0 bbPress (r2464) 1611 * 1612 * @param int $forum_id Optional. Forum id or topic id. It is checked whether it 1621 * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects 1622 * 1623 * @param int $forum_id Optional. Forum id or topic id. It is checked whether it 1613 1624 * is a topic or a forum. If it's a topic, its parent, 1614 1625 * i.e. the forum is automatically retrieved. 1615 * @param bool $total_count Optional. To return the total count or normal1616 * count?1617 1626 * @uses bbp_get_forum_id() To get the forum id 1618 1627 * @uses bbp_forum_query_subforum_ids() To get the subforum ids 1619 1628 * @uses bbp_update_forum_reply_count() To update the forum reply count 1620 1629 * @uses bbp_forum_query_topic_ids() To get the forum topic ids 1621 * @uses wpdb::prepare() To prepare the sql statement1622 * @uses wpdb::get_var() To execute the query and get the var back1630 * @uses bbp_get_public_status_id() To get the public status id 1631 * @uses bbp_get_reply_post_type() To get the reply post type 1623 1632 * @uses update_post_meta() To update the forum's reply count meta 1624 * @uses apply_filters() Calls 'bbp_update_forum_ topic_count' with the reply1633 * @uses apply_filters() Calls 'bbp_update_forum_reply_count' with the reply 1625 1634 * count and forum id 1626 1635 * @return int Forum reply count … … 1643 1652 $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 1644 1653 if ( ! empty( $topic_ids ) ) { 1645 $bbp_db = bbp_db(); 1646 $topic_ids = implode( ',', wp_parse_id_list( $topic_ids ) ); 1647 $reply_count = (int) $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s';", bbp_get_public_status_id(), bbp_get_reply_post_type() ) ); 1654 $query = new WP_Query( array( 1655 'fields' => 'ids', 1656 'post_parent__in' => $topic_ids, 1657 'post_status' => bbp_get_public_status_id(), 1658 'post_type' => bbp_get_reply_post_type(), 1659 1660 // Maybe change these later 1661 'posts_per_page' => -1, 1662 'update_post_term_cache' => false, 1663 'update_post_meta_cache' => false, 1664 'ignore_sticky_posts' => true, 1665 ) ); 1666 $reply_count = ! empty( $query->posts ) ? count( $query->posts ) : 0; 1667 unset( $query ); 1648 1668 } 1649 1669 … … 2069 2089 function bbp_forum_query_subforum_ids( $forum_id ) { 2070 2090 $subforum_ids = bbp_get_all_child_ids( $forum_id, bbp_get_forum_post_type() ); 2071 //usort( $subforum_ids, '_bbp_forum_query_usort_subforum_ids' );2072 2091 2073 2092 return (array) apply_filters( 'bbp_forum_query_subforum_ids', $subforum_ids, $forum_id ); … … 2075 2094 2076 2095 /** 2077 * Callback to sort forum ID's based on last active time2078 *2079 * @since 2.1.0 bbPress (r3789)2080 *2081 * @param int $a First forum ID to compare2082 * @param int $b Second forum ID to compare2083 * @return Position change based on sort2084 */2085 function _bbp_forum_query_usort_subforum_ids( $a = 0, $b = 0 ) {2086 $ta = get_post_meta( $a, '_bbp_last_active_time', true );2087 $tb = get_post_meta( $b, '_bbp_last_active_time', true );2088 return ( $ta < $tb ) ? -1 : 1;2089 }2090 2091 /**2092 2096 * Returns the forum's last reply id 2093 2097 * 2094 2098 * @since 2.0.0 bbPress (r2908) 2095 * 2096 * @param int $forum_id Forum id 2097 * @param int $topic_ids Optional. Topic ids 2098 * @uses wp_cache_get() To check for cache and retrieve it 2099 * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects 2100 * 2101 * @param int $forum_id Forum id. 2102 * @param int $topic_ids Optional. Topic ids. 2103 * @uses bbp_get_forum_id() To validate the forum id 2099 2104 * @uses bbp_forum_query_topic_ids() To get the forum's topic ids 2100 * @uses wpdb::prepare() To prepare the query 2101 * @uses wpdb::get_var() To execute the query and get the var back 2105 * @uses bbp_get_public_status_id() To get the public status id 2102 2106 * @uses bbp_get_reply_post_type() To get the reply post type 2103 * @uses wp_cache_set() To set the cache for future use2104 2107 * @uses apply_filters() Calls 'bbp_forum_query_last_reply_id' with the reply id 2105 2108 * and forum id 2106 2109 */ 2107 function bbp_forum_query_last_reply_id( $forum_id, $topic_ids = 0 ) { 2108 2109 $cache_id = 'bbp_get_forum_' . $forum_id . '_reply_id'; 2110 $reply_id = wp_cache_get( $cache_id, 'bbpress_posts' ); 2111 2112 if ( false === $reply_id ) { 2113 2114 if ( empty( $topic_ids ) ) { 2115 $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 2116 } 2117 2118 if ( ! empty( $topic_ids ) ) { 2119 $bbp_db = bbp_db(); 2120 $topic_ids = implode( ',', wp_parse_id_list( $topic_ids ) ); 2121 $reply_id = (int) $bbp_db->get_var( $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", bbp_get_public_status_id(), bbp_get_reply_post_type() ) ); 2122 } else { 2123 $reply_id = 0; 2124 } 2125 2126 wp_cache_set( $cache_id, $reply_id, 'bbpress_posts' ); 2127 } else { 2128 $reply_id = (int) $reply_id; 2129 } 2110 function bbp_forum_query_last_reply_id( $forum_id = 0, $topic_ids = 0 ) { 2111 2112 // Validate forum 2113 $forum_id = bbp_get_forum_id( $forum_id ); 2114 2115 // Get topic ID's if none were passed 2116 if ( empty( $topic_ids ) ) { 2117 $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 2118 } 2119 2120 $query = new WP_Query( array( 2121 'fields' => 'ids', 2122 'post_parent__in' => $topic_ids, 2123 'post_status' => bbp_get_public_status_id(), 2124 'post_type' => bbp_get_reply_post_type(), 2125 2126 // Maybe change these later 2127 'posts_per_page' => 1, 2128 'update_post_term_cache' => false, 2129 'update_post_meta_cache' => false, 2130 'ignore_sticky_posts' => true, 2131 ) ); 2132 $reply_id = array_shift( $query->posts ); 2133 unset( $query ); 2130 2134 2131 2135 return (int) apply_filters( 'bbp_forum_query_last_reply_id', $reply_id, $forum_id );
Note: See TracChangeset
for help on using the changeset viewer.