-
-
Save imath/b8ddab107cb1733b0184c63b09ae4407 to your computer and use it in GitHub Desktop.
Exemple de morceaux de code personnalisé pour informer sur la date de dernière connexion d'un utilisateur.
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 | |
/** | |
* Chemin: | |
* 1. wp-login.php | |
* 2. wp_signon() | |
* 3. do_action( 'wp_login' ) | |
*/ | |
function atelier_contribution_sept_definit_derniere_connexion( $user_login = '', WP_User $user ) { | |
$user_id = (int) $user->ID; | |
if ( $user_id ) { | |
update_user_meta( $user_id, 'atelier_contribution_sept_derniere_connexion', time() ); | |
} | |
} | |
add_action( 'wp_login', 'atelier_contribution_sept_definit_derniere_connexion', 10, 2 ); | |
/** | |
* Chemin | |
* 1. /wp-admin/profile.php | |
* 2. /wp-admin/user-edit.php | |
* 3. do_action( 'personal_options' ) | |
*/ | |
function atelier_contribution_sept_affiche_derniere_connexion( WP_User $user ) { | |
$derniere_connexion = (int) $user->atelier_contribution_sept_derniere_connexion; | |
if ( ! $derniere_connexion ) { | |
return; | |
} else { | |
$derniere_connexion += ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); | |
} | |
$jour = date_i18n( get_option( 'date_format' ), $derniere_connexion ); | |
$heure = date_i18n( get_option( 'time_format' ), $derniere_connexion ); | |
printf( '<tr> | |
<th scope="row"><label>%s</label></th> | |
<td>%s</td> | |
</tr>', | |
esc_html__( 'Dernière connexion', 'atelier-contribution-sept' ), | |
sprintf( esc_html__( 'le %s à %s', 'atelier-contribution-sept' ), $jour, $heure ) | |
); | |
} | |
add_action( 'personal_options', 'atelier_contribution_sept_affiche_derniere_connexion', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment