Last active
January 28, 2021 12:43
-
-
Save chavesm/fe4e9108acd644d3fb3dba95e0c4f55b to your computer and use it in GitHub Desktop.
MonsterInsights filter that supports displaying the login name (or full name) rather than an internal ID in Top logged-in report.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Custom Filter for the User ID Dimension | |
* | |
* Add this to your theme's functions.php file. | |
*/ | |
function display_username_instead_of_user_id( $user_id ) { | |
$user = get_user_by( 'id', $user_id ); | |
return $user->user_login; | |
// or return $user->first_name . ' ' . $user->last_name; | |
// or return $user->user_login . ' ('. $user_id . ')'; | |
} | |
add_filter( 'mi_get_user_by', 'display_username_instead_of_user_id', 10, 3 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Apply a filter to display a more human-friendly string | |
* rather than the internal WordPress user ID. | |
* | |
* /google-analytics-premium/pro/includes/admin/reports/report-dimensions.php | |
*/ | |
// If logged-in user dimension, then apply a filter | |
// to display user login, name, etc. ~mlc. | |
if ( intval( $key ) === 5 ) $title = apply_filters( 'mi_get_user_by', $title ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where does the apply_filters call go?
Insert the if condition in the
prepare_report_data()
function around line 128 of the report-dimensions.php file.