Changeset 6607 for trunk/src/includes/users/engagements.php
- Timestamp:
- 07/02/2017 04:39:49 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.