Changeset 6607
- Timestamp:
- 07/02/2017 04:39:49 PM (7 years ago)
- Location:
- trunk/src/includes
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/common/functions.php
r6586 r6607 1472 1472 1473 1473 $query = new WP_Query( array( 1474 'fields' => 'ids', 1475 'post_parent' => $parent_id, 1476 'post_status' => $post_status, 1477 'post_type' => $post_type, 1478 'orderby' => array( 1474 'fields' => 'ids', 1475 'post_parent' => $parent_id, 1476 'post_status' => $post_status, 1477 'post_type' => $post_type, 1478 'posts_per_page' => 1, 1479 'orderby' => array( 1479 1480 'post_date' => 'DESC', 1480 1481 'ID' => 'DESC' 1481 1482 ), 1482 1483 1483 // Maybe change these later1484 ' posts_per_page' => 1,1484 // Performance 1485 'suppress_filters' => true, 1485 1486 'update_post_term_cache' => false, 1486 1487 'update_post_meta_cache' => false, … … 1508 1509 1509 1510 // Bail if nothing passed 1510 if ( empty( $parent_id ) ) {1511 if ( empty( $parent_id ) || empty( $post_type ) ) { 1511 1512 return false; 1512 1513 } … … 1521 1522 1522 1523 $query = new WP_Query( array( 1523 'fields' => 'ids', 1524 'post_parent' => $parent_id, 1525 'post_status' => $post_status, 1526 'post_type' => $post_type, 1527 1528 // Maybe change these later 1529 'posts_per_page' => -1, 1524 'fields' => 'ids', 1525 'post_parent' => $parent_id, 1526 'post_status' => $post_status, 1527 'post_type' => $post_type, 1528 'posts_per_page' => -1, 1529 1530 // Performance 1531 'nopaging' => true, 1532 'suppress_filters' => true, 1530 1533 'update_post_term_cache' => false, 1531 1534 'update_post_meta_cache' => false, … … 1567 1570 1568 1571 $query = new WP_Query( array( 1569 'fields' => 'ids', 1570 'suppress_filters' => true, 1571 'post_parent' => $parent_id, 1572 'post_status' => $post_status, 1573 'post_type' => $post_type, 1574 'posts_per_page' => -1, 1575 1576 // Maybe change these later 1572 'fields' => 'ids', 1573 'post_parent' => $parent_id, 1574 'post_status' => $post_status, 1575 'post_type' => $post_type, 1576 'posts_per_page' => -1, 1577 'orderby' => array( 1578 'post_date' => 'DESC', 1579 'ID' => 'DESC' 1580 ), 1581 1582 // Performance 1583 'nopaging' => true, 1584 'suppress_filters' => true, 1577 1585 'update_post_term_cache' => false, 1578 1586 'update_post_meta_cache' => false, 1579 1587 'ignore_sticky_posts' => true, 1580 'no_found_rows' => true, 1581 'nopaging' => true 1588 'no_found_rows' => true 1582 1589 ) ); 1583 1590 $child_ids = ! empty( $query->posts ) ? $query->posts : array(); -
trunk/src/includes/forums/capabilities.php
r6573 r6607 219 219 220 220 /** 221 * Get array of forum IDs that a user can moderate222 *223 * @since 2.6.0 bbPress (r5834)224 *225 * @param int $user_id User id.226 *227 * @return boolean|array Return false on error or empty, or array of forum ids228 */229 function bbp_get_moderator_forum_ids( $user_id = 0 ) {230 $user_id = bbp_get_user_id( $user_id );231 $forums = new WP_Query( array(232 'fields' => 'ids',233 'post_type' => bbp_get_forum_post_type(),234 'nopaging' => true,235 'no_found_rows' => true,236 'meta_query' => array( array(237 'key' => '_bbp_moderator_id',238 'value' => $user_id,239 'compare' => 'NUMERIC'240 ) )241 ) );242 243 // Filter & return244 return (array) apply_filters( 'bbp_get_moderator_forum_ids', $forums->posts, $user_id, $forums );245 }246 247 /**248 221 * Can a user moderate a forum? 249 222 * -
trunk/src/includes/forums/functions.php
r6585 r6607 963 963 // Query for private forums 964 964 $private_forums = new WP_Query( array( 965 'fields' => 'ids', 966 'suppress_filters' => true, 967 'post_type' => bbp_get_forum_post_type(), 968 'post_status' => bbp_get_private_status_id(), 969 'posts_per_page' => -1, 965 'fields' => 'ids', 966 'post_type' => bbp_get_forum_post_type(), 967 'post_status' => bbp_get_private_status_id(), 968 'posts_per_page' => -1, 970 969 971 970 // Performance 971 'nopaging' => true, 972 'suppress_filters' => true, 973 'update_post_term_cache' => false, 974 'update_post_meta_cache' => false, 972 975 'ignore_sticky_posts' => true, 973 'no_found_rows' => true, 974 'nopaging' => true, 975 'update_post_term_cache' => false, 976 'update_post_meta_cache' => false 976 'no_found_rows' => true 977 977 ) ); 978 978 … … 986 986 987 987 // Performance 988 'nopaging' => true, 989 'suppress_filters' => true, 990 'update_post_term_cache' => false, 991 'update_post_meta_cache' => false, 988 992 'ignore_sticky_posts' => true, 989 'no_found_rows' => true, 990 'nopaging' => true, 991 'update_post_term_cache' => false, 992 'update_post_meta_cache' => false 993 'no_found_rows' => true 993 994 ) ); 994 995 … … 1603 1604 * i.e. the forum is automatically retrieved. 1604 1605 * @param bool $total_count Optional. To return the total count or normal count? 1605 1606 1606 * @return int Forum topic count 1607 1607 */ … … 1662 1662 if ( empty( $topic_count ) ) { 1663 1663 $query = new WP_Query( array( 1664 'fields' => 'ids', 1665 'suppress_filters' => true, 1666 'post_parent' => $forum_id, 1667 'post_status' => array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ), 1668 'post_type' => bbp_get_topic_post_type(), 1669 'posts_per_page' => -1, 1664 'fields' => 'ids', 1665 'post_parent' => $forum_id, 1666 'post_status' => array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ), 1667 'post_type' => bbp_get_topic_post_type(), 1668 'posts_per_page' => -1, 1670 1669 1671 1670 // Performance 1671 'nopaging' => true, 1672 'suppress_filters' => true, 1672 1673 'update_post_term_cache' => false, 1673 1674 'update_post_meta_cache' => false, 1674 1675 'ignore_sticky_posts' => true, 1675 'no_found_rows' => true, 1676 'nopaging' => true 1676 'no_found_rows' => true 1677 1677 ) ); 1678 1678 $topic_count = $query->post_count; … … 1720 1720 if ( ! empty( $topic_ids ) ) { 1721 1721 $query = new WP_Query( array( 1722 'fields' => 'ids', 1723 'suppress_filters' => true, 1724 'post_parent__in' => $topic_ids, 1725 'post_status' => bbp_get_public_status_id(), 1726 'post_type' => bbp_get_reply_post_type(), 1727 'posts_per_page' => -1, 1722 'fields' => 'ids', 1723 'post_parent__in' => $topic_ids, 1724 'post_status' => bbp_get_public_status_id(), 1725 'post_type' => bbp_get_reply_post_type(), 1726 'posts_per_page' => -1, 1728 1727 1729 1728 // Performance 1729 'nopaging' => true, 1730 'suppress_filters' => true, 1730 1731 'update_post_term_cache' => false, 1731 1732 'update_post_meta_cache' => false, 1732 1733 'ignore_sticky_posts' => true, 1733 'no_found_rows' => true, 1734 'nopaging' => true 1734 'no_found_rows' => true 1735 1735 ) ); 1736 1736 $reply_count = ! empty( $query->posts ) ? count( $query->posts ) : 0; … … 2137 2137 'update_post_meta_cache' => false, 2138 2138 'ignore_sticky_posts' => true, 2139 'no_found_rows' => true, 2140 'nopaging' => true 2139 'no_found_rows' => true 2141 2140 ) ); 2142 2141 $reply_id = array_shift( $query->posts ); … … 2273 2272 // Note that we get all post statuses here 2274 2273 $topics = new WP_Query( array( 2275 'fields' => 'id=>parent', 2276 'suppress_filters' => true, 2277 2278 // What and how 2279 'post_type' => bbp_get_topic_post_type(), 2280 'post_parent' => $forum_id, 2281 'post_status' => array_keys( get_post_stati() ), 2282 'posts_per_page' => -1, 2274 'fields' => 'id=>parent', 2275 'post_type' => bbp_get_topic_post_type(), 2276 'post_parent' => $forum_id, 2277 'post_status' => array_keys( get_post_stati() ), 2278 'posts_per_page' => -1, 2283 2279 2284 2280 // Performance 2281 'nopaging' => true, 2282 'suppress_filters' => true, 2283 'update_post_term_cache' => false, 2284 'update_post_meta_cache' => false, 2285 2285 'ignore_sticky_posts' => true, 2286 'no_found_rows' => true, 2287 'nopaging' => true, 2288 'update_post_term_cache' => false, 2289 'update_post_meta_cache' => false 2286 'no_found_rows' => true 2290 2287 ) ); 2291 2288 … … 2330 2327 // Forum is being trashed, so its topics (and replies) are trashed too 2331 2328 $topics = new WP_Query( array( 2332 'fields' => 'id=>parent', 2333 'suppress_filters' => true, 2334 'post_type' => bbp_get_topic_post_type(), 2335 'post_parent' => $forum_id, 2336 'post_status' => $post_stati, 2337 'posts_per_page' => -1, 2329 'fields' => 'id=>parent', 2330 'post_type' => bbp_get_topic_post_type(), 2331 'post_parent' => $forum_id, 2332 'post_status' => $post_stati, 2333 'posts_per_page' => -1, 2338 2334 2339 2335 // Performance 2336 'nopaging' => true, 2337 'suppress_filters' => true, 2338 'update_post_term_cache' => false, 2339 'update_post_meta_cache' => false, 2340 2340 'ignore_sticky_posts' => true, 2341 'no_found_rows' => true, 2342 'nopaging' => true, 2343 'update_post_term_cache' => false, 2344 'update_post_meta_cache' => false 2341 'no_found_rows' => true 2345 2342 ) ); 2346 2343 -
trunk/src/includes/topics/functions.php
r6585 r6607 2882 2882 // Topic is being spammed, so its replies are trashed 2883 2883 $replies = new WP_Query( array( 2884 'suppress_filters' => true, 2885 'post_type' => bbp_get_reply_post_type(), 2886 'post_status' => bbp_get_public_status_id(), 2887 'post_parent' => $topic_id, 2888 'posts_per_page' => -1, 2889 'nopaging' => true, 2890 'no_found_rows' => true, 2891 'fields' => 'id=>parent' 2884 'fields' => 'id=>parent', 2885 'post_type' => bbp_get_reply_post_type(), 2886 'post_status' => bbp_get_public_status_id(), 2887 'post_parent' => $topic_id, 2888 'posts_per_page' => -1, 2889 2890 // Performance 2891 'nopaging' => true, 2892 'suppress_filters' => true, 2893 'update_post_term_cache' => false, 2894 'update_post_meta_cache' => false, 2895 'ignore_sticky_posts' => true, 2896 'no_found_rows' => true 2892 2897 ) ); 2893 2898 … … 2915 2920 /** 2916 2921 * Store the tags to a topic in post meta before it's marked as spam so they 2917 * can be retr eived and unspammed later.2922 * can be retrieved and unspammed later. 2918 2923 * 2919 2924 * Usually you'll want to do this before the topic itself is marked as spam. … … 3273 3278 // Note that we get all post statuses here 3274 3279 $replies = new WP_Query( array( 3275 'suppress_filters' => true, 3276 'post_type' => bbp_get_reply_post_type(), 3277 'post_status' => array_keys( get_post_stati() ), 3278 'post_parent' => $topic_id, 3279 'posts_per_page' => -1, 3280 'nopaging' => true, 3281 'no_found_rows' => true, 3282 'fields' => 'id=>parent' 3280 'fields' => 'id=>parent', 3281 'post_type' => bbp_get_reply_post_type(), 3282 'post_status' => array_keys( get_post_stati() ), 3283 'post_parent' => $topic_id, 3284 'posts_per_page' => -1, 3285 3286 // Performance 3287 'nopaging' => true, 3288 'suppress_filters' => true, 3289 'update_post_term_cache' => false, 3290 'update_post_meta_cache' => false, 3291 'ignore_sticky_posts' => true, 3292 'no_found_rows' => true 3283 3293 ) ); 3284 3294 … … 3329 3339 // Topic is being trashed, so its replies are trashed too 3330 3340 $replies = new WP_Query( array( 3331 'suppress_filters' => true, 3332 'post_type' => bbp_get_reply_post_type(), 3333 'post_status' => bbp_get_public_status_id(), 3334 'post_parent' => $topic_id, 3335 'posts_per_page' => -1, 3336 'nopaging' => true, 3337 'no_found_rows' => true, 3338 'fields' => 'id=>parent' 3341 'fields' => 'id=>parent', 3342 'post_type' => bbp_get_reply_post_type(), 3343 'post_status' => bbp_get_public_status_id(), 3344 'post_parent' => $topic_id, 3345 'posts_per_page' => -1, 3346 3347 // Performance 3348 'nopaging' => true, 3349 'suppress_filters' => true, 3350 'update_post_term_cache' => false, 3351 'update_post_meta_cache' => false, 3352 'ignore_sticky_posts' => true, 3353 'no_found_rows' => true 3339 3354 ) ); 3340 3355 -
trunk/src/includes/users/engagements.php
r6573 r6607 228 228 // Filter & return 229 229 return apply_filters( 'bbp_get_user_engagements', $engagements, $user_id ); 230 }231 232 /**233 * Get a user's engaged topic ids234 *235 * @since 2.6.0 bbPress (r6320)236 *237 * @param int $user_id Optional. User id238 *239 * @return array Topic ids if user has engaged, otherwise empty array240 */241 function bbp_get_user_engaged_topic_ids( $user_id = 0 ) {242 $user_id = bbp_get_user_id( $user_id );243 $engagements = new WP_Query( array(244 'fields' => 'ids',245 'post_type' => bbp_get_topic_post_type(),246 'nopaging' => true,247 'no_found_rows' => true,248 'meta_query' => array( array(249 'key' => '_bbp_engagement',250 'value' => $user_id,251 'compare' => 'NUMERIC'252 ) )253 ) );254 255 // Filter & return256 return (array) apply_filters( 'bbp_get_user_engaged_topic_ids', $engagements->posts, $user_id );257 230 } 258 231 … … 928 901 929 902 /** 903 * Get a user's object IDs 904 * 905 * For the most part, you should not need to use this function, and may even 906 * want to come up with a more efficient way to get IDs on your own. Nevertheless, 907 * it is available here for your convenience, using the most efficient query 908 * parameters available inside of the various query APIs. 909 * 910 * @since 2.6.0 bbPress (r6606) 911 * 912 * @param int $user_id The user id 913 * @param string $meta_key The relationship key 914 * @param string $meta_type The relationship type (usually 'post') 915 * @param array $args The arguments to override defaults 916 * 917 * @return array|bool Results if user has objects, otherwise null 918 */ 919 function bbp_get_user_object_ids( $args = array() ) { 920 $object_ids = $defaults = array(); 921 922 // Parse arguments 923 $r = bbp_parse_args( $args, array( 924 'user_id' => 0, 925 'object_type' => bbp_get_topic_post_type(), 926 'meta_key' => '', 927 'meta_type' => 'post', 928 'filter' => 'user_object_ids', 929 'args' => array() 930 ), 'get_user_object_ids' ); 931 932 // Sanitize arguments 933 $r['user_id'] = bbp_get_user_id( $r['user_id'] ); 934 $r['meta_key'] = sanitize_key( $r['meta_key'] ); 935 $r['meta_type'] = sanitize_key( $r['meta_type'] ); 936 $r['object_type'] = sanitize_key( $r['object_type'] ); 937 $r['filter'] = sanitize_key( $r['filter'] ); 938 939 // Defaults 940 if ( 'post' === $r['meta_type'] ) { 941 $defaults = array( 942 'fields' => 'ids', 943 'post_type' => $r['object_type'], 944 'posts_per_page' => -1, 945 'meta_query' => array( array( 946 'key' => $r['meta_key'], 947 'value' => $r['user_id'], 948 'compare' => 'NUMERIC' 949 ), 950 951 // Performance 952 'nopaging' => true, 953 'suppress_filters' => true, 954 'update_post_term_cache' => false, 955 'update_post_meta_cache' => false, 956 'ignore_sticky_posts' => true, 957 'no_found_rows' => true 958 ) ); 959 } 960 961 // Parse arguments 962 $r = bbp_parse_args( $r['args'], $defaults, "get_{$r['filter']}_args" ); 963 964 // Queries 965 if ( 'post' === $r['meta_type'] ) { 966 $query = new WP_Query( $r ); 967 $object_ids = $query->posts; 968 } 969 970 // Filter & return 971 return (array) apply_filters( "bbp_get_{$r['filter']}", $object_ids, $r, $args ); 972 } 973 974 /** 975 * Get array of forum IDs that a user can moderate 976 * 977 * @since 2.6.0 bbPress (r5834) 978 * 979 * @param int $user_id User id. 980 * 981 * @return array Return array of forum ids, or empty array 982 */ 983 function bbp_get_moderator_forum_ids( $user_id = 0 ) { 984 return bbp_get_user_object_ids( array( 985 'user_id' => $user_id, 986 'meta_key' => '_bbp_moderator_id', 987 'post_type' => bbp_get_forum_post_type(), 988 'filter' => 'moderator_forum_ids' 989 ) ); 990 } 991 992 /** 993 * Get a user's engaged topic ids 994 * 995 * @since 2.6.0 bbPress (r6320) 996 * 997 * @param int $user_id Optional. User id 998 * 999 * @return array Return array of topic ids, or empty array 1000 */ 1001 function bbp_get_user_engaged_topic_ids( $user_id = 0 ) { 1002 return bbp_get_user_object_ids( array( 1003 'user_id' => $user_id, 1004 'meta_key' => '_bbp_engagement', 1005 'filter' => 'user_engaged_topic_ids' 1006 ) ); 1007 } 1008 1009 /** 930 1010 * Get a user's favorite topic ids 931 1011 * … … 934 1014 * @param int $user_id Optional. User id 935 1015 * 936 * @return array |bool Results if user has favorites, otherwise null1016 * @return array Return array of favorited ids, or empty array 937 1017 */ 938 1018 function bbp_get_user_favorites_topic_ids( $user_id = 0 ) { 939 $user_id = bbp_get_user_id( $user_id ); 940 $favorites = new WP_Query( array( 941 'fields' => 'ids', 942 'post_type' => bbp_get_topic_post_type(), 943 'nopaging' => true, 944 'no_found_rows' => true, 945 'meta_query' => array( array( 946 'key' => '_bbp_favorite', 947 'value' => $user_id, 948 'compare' => 'NUMERIC' 949 ) ) 1019 return bbp_get_user_object_ids( array( 1020 'user_id' => $user_id, 1021 'meta_key' => '_bbp_favorite', 1022 'filter' => 'user_favorites_topic_ids' 950 1023 ) ); 951 952 // Filter & return 953 return (array) apply_filters( 'bbp_get_user_favorites_topic_ids', $favorites->posts, $user_id ); 954 } 955 1024 } 956 1025 957 1026 /** … … 962 1031 * @param int $user_id Optional. User id 963 1032 * 964 * @return array |bool Results if user has subscriptions, otherwise null1033 * @return array Return array of subscribed ids, or empty array 965 1034 */ 966 1035 function bbp_get_user_subscribed_forum_ids( $user_id = 0 ) { 967 $user_id = bbp_get_user_id( $user_id ); 968 $subscriptions = new WP_Query( array( 969 'fields' => 'ids', 970 'post_type' => bbp_get_forum_post_type(), 971 'nopaging' => true, 972 'no_found_rows' => true, 973 'meta_query' => array( array( 974 'key' => '_bbp_subscription', 975 'value' => $user_id, 976 'compare' => 'NUMERIC' 977 ) ) 1036 return bbp_get_user_object_ids( array( 1037 'user_id' => $user_id, 1038 'meta_key' => '_bbp_subscription', 1039 'post_type' => bbp_get_forum_post_type(), 1040 'filter' => 'user_subscribed_forum_ids' 978 1041 ) ); 979 980 // Filter & return981 return (array) apply_filters( 'bbp_get_user_subscribed_forum_ids', $subscriptions->posts, $user_id );982 1042 } 983 1043 … … 989 1049 * @param int $user_id Optional. User id 990 1050 * 991 * @return array |bool Results if user has subscriptions, otherwise null1051 * @return array Return array of subscribed ids, or empty array 992 1052 */ 993 1053 function bbp_get_user_subscribed_topic_ids( $user_id = 0 ) { 994 $user_id = bbp_get_user_id( $user_id ); 995 $subscriptions = new WP_Query( array( 996 'fields' => 'ids', 997 'post_type' => bbp_get_topic_post_type(), 998 'nopaging' => true, 999 'no_found_rows' => true, 1000 'meta_query' => array( array( 1001 'key' => '_bbp_subscription', 1002 'value' => $user_id, 1003 'compare' => 'NUMERIC' 1004 ) ) 1054 return bbp_get_user_object_ids( array( 1055 'user_id' => $user_id, 1056 'meta_key' => '_bbp_subscription', 1057 'filter' => 'user_subscribed_topic_ids' 1005 1058 ) ); 1006 1007 // Filter & return1008 return (array) apply_filters( 'bbp_get_user_subscribed_topic_ids', $subscriptions->posts, $user_id );1009 1059 } 1010 1060
Note: See TracChangeset
for help on using the changeset viewer.