Skip to content

Instantly share code, notes, and snippets.

@wbcomdev
Last active June 23, 2022 07:21
Show Gist options
  • Select an option

  • Save wbcomdev/145155baeeb4c953ebf673b02f6f8918 to your computer and use it in GitHub Desktop.

Select an option

Save wbcomdev/145155baeeb4c953ebf673b02f6f8918 to your computer and use it in GitHub Desktop.
<?php
/**
* Bp_profile_views_member_header_display
*
* @return void
*/
function wbbp_display_profile_views_at_member_header() {
global $wpdb;
$user_id = get_current_user_id();
$displayed_user_id = bp_displayed_user_id();
if ( $user_id === $displayed_user_id ) {
$views = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM `' . $wpdb->prefix . 'bp_profile_views` WHERE `user_id`= %d', $user_id ), ARRAY_A );
if ( count( $views ) > 0 ) {
$view_count = count( $views );
$view_image_url = BUDDYPRESS_PROFILE_VIEWS_URL . '/public/images/view-icon.svg';
echo sprintf(
'<div class="single-member-profile-view"><img src="%s" alt="%s"><span><b>%d</b> Views</span></div>',
esc_url( $view_image_url ),
esc_attr__( 'Views', 'bp-profile-views' ),
$view_count,
);
}
}
}
add_action( 'bp_before_member_header_meta', 'wbbp_display_profile_views_at_member_header' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment