BP_Media::total_media_count( int $user_id )
Count total media for the given user
Description
Parameters
- $user_id
-
(Required)
Return
(array|bool|int)
Source
File: bp-media/classes/class-bp-media.php
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 | public static function total_media_count( $user_id = 0 ) { global $wpdb ; $bp = buddypress(); $privacy = array ( 'public' ); if ( is_user_logged_in() ) { $privacy [] = 'loggedin' ; if ( bp_is_active( 'friends' ) ) { $is_friend = friends_check_friendship( get_current_user_id(), $user_id ); if ( $is_friend ) { $privacy [] = 'friends' ; } } } $privacy = "'" . implode( "', '" , $privacy ) . "'" ; $count_sql = "SELECT COUNT(*) FROM {$bp->media->table_name} WHERE user_id = {$user_id} AND privacy IN ({$privacy})" ; $cache_group = 'bp_media_user_media_count' ; $cached = bp_core_get_incremented_cache( $count_sql , $cache_group ); if ( false === $cached ) { $results = $wpdb ->get_col( $count_sql ); $total_count = intval ( $results [0] ); bp_core_set_incremented_cache( $count_sql , $cache_group , $total_count ); } else { $total_count = $cached ; } return $total_count ; } |
Changelog
Version | Description |
---|---|
BuddyBoss 1.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.