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
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.