Based on this answer i created a small functionality for users that are logging in for the first 3 times to make some elements classes use css animation. What i am trying to do is to adjust this code to count and control the first 3 times of all user roles except subscribers.
Basically i need this functionality to start counting the first login by user role. Lets say the first time a contributor login, or an editor, or better all user roles except subscribers
Here is my code so far
add_action( 'wp_login', 'track_user_logins', 10, 2 );
function track_user_logins( $user_login, $user ){
if( $login_amount = get_user_meta( $user->id, 'login_amount', true ) ){
// They've Logged In Before, increment existing total by 1
update_user_meta( $user->id, 'login_amount', ++$login_amount );
} else {
// First Login, set it to 1
update_user_meta( $user->id, 'login_amount', 1 );
}
}
add_action('wp_head', 'notificationcss');
function notificationcss{
if ( !current_user_can('subscriber') ) {
// Get current total amount of logins (should be at least 1)
$login_amount = get_user_meta( get_current_user_id(), 'login_amount', true );
// return content based on how many times they've logged in.
if( $login_amount <= 3 ){
echo '<style>.create-post {animation: pulse-blue 2s 7;} .bb-header-icon.logged-in-user.element-toggle.only-mobile img{animation: pulse-red 2s 7;} </style>';
} else {
echo '<style>.create-post {animation: none;} .bb-header-icon.logged-in-user.element-toggle.only-mobile img{animation: none;} </style>';
}
}
}
How could i manipulate the track_user_logins function to count the login times for all roles except subscribers. The existing function counts all users.
Example: A user is registered in the site for the first time with role Subscriber. After some login times(lets say 7-8), his role is being changes to Contributor. From that first time logged in as a Contributor the track_user_logins should start counting.
Any ideas would be gladly appreciated.
if ( !current_user_can('subscriber') ) {
in your code. Does that not work?