Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
Coppa WPB
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Come mostrare la data di registrazione dell’utente in WordPress

Nota editoriale: guadagniamo una commissione dai link dei partner su WPBeginner. Le commissioni non influenzano le opinioni o le valutazioni dei nostri redattori. Per saperne di più su Processo editoriale.

Volete mostrare la data di registrazione dell’utente in WordPress? Spesso i siti di iscrizione e i forum più popolari mostrano la data di registrazione dell’utente sul profilo come “membro dal 2015”. In questo articolo spiegheremo come mostrare la data di registrazione dell’utente in WordPress.

Showing a the date of a user's registration in WordPress

Dove e come volete mostrare la data di registrazione dell’utente?

Alcuni potrebbero voler visualizzare la data di registrazione di un utente nelle colonne dell’amministrazione della pagina Utenti. Questo vi darà una rapida panoramica di quando un utente si è iscritto al vostro sito web e vi permetterà di ordinarlo in base alla data di registrazione.

Un altro scenario di utilizzo è quello di visualizzare la data di registrazione di un utente nella pagina “Modifica profilo”. In questo modo, qualsiasi amministratore e l’utente stesso potranno vedere quando si è iscritto al vostro sito web.

L’ultimo scenario di utilizzo, ma probabilmente il più diffuso, è quello in cui si desidera visualizzare la data di registrazione dell’utente sul suo profilo pubblico nel front-end del sito web.

Vediamo come fare per tutti questi casi.

Aggiunta della colonna Data di registrazione nella pagina Utenti dell’area amministrativa

La prima cosa da fare è installare e attivare il plugin Admin Columns. Dopo l’attivazione, è necessario visitare Impostazioni ” Colonne amministratore per configurare il plugin.

Add registered column in users table

Nella scheda Colonne amministratore, fare clic su Utenti e poi sul pulsante Aggiungi colonna.

Selezionare quindi “Registrato” nel menu a discesa Tipo e fare clic sul pulsante Aggiornamenti.

Ora potete visitare la schermata degli utenti, dove vedrete una nuova colonna denominata “Registrato” che mostra la data di registrazione di un utente sul vostro sito WordPress.

Users table with registration date column

Scoprite quali altre cose potete fare per aggiungere e personalizzare le colonne di amministrazione in WordPress.

Mostrare il campo della data di registrazione nel profilo utente

Per mostrare la data di registrazione nella pagina di modifica del profilo, è necessario caricare un plugin personalizzato sul proprio sito web.

È sufficiente creare un nuovo file sul computer utilizzando un editor di testo come Notepad e salvarlo come membersince.php sul desktop.

Quindi aprire il file e incollare il seguente codice al suo interno.

<?php
/*
Plugin Name: Member Since
Plugin URI:  https://www.wpbeginner.com
Description: Adds registration date on edit user profile screen. 
Version:     1.0
Author:      WPBeginner
*/


namespace ShowMemberSince;
add_action( 'plugins_loaded', 'ShowMemberSince\init' );
/**
 * Adding needed action hooks
*/
function init(){
  foreach( array( 'show_user_profile', 'edit_user_profile' ) as $hook )
		add_action( $hook, 'ShowMemberSince\add_custom_user_profile_fields', 10, 1 );
}
/**
 * Output table
 * @param object $user User object
 */
function add_custom_user_profile_fields( $user ){
	$table =
	'<h3>%1$s</h3>
	<table class="form-table">
		<tr>
			<th>
				%1$s
			</th>
			<td>
				<p>Member since: %2$s</p>
			</td>
		</tr>
	</table>';
	$udata = get_userdata( $user->ID );
	$registered = $udata->user_registered;
	printf(
		$table,
		'Registered',
		date( "M Y", strtotime( $registered ) )
	);
}
?>

Salvate il file e poi caricatelo sul vostro sito WordPress.

Infine, potete connettervi al vostro sito WordPress utilizzando un client FTP e andare alla cartella /wp-content/plugins/. Selezionare il file membersince.php dal computer e caricarlo.

Ora si può andare alla pagina dei plugin di WordPress e attivare questo plugin sul proprio sito web.

Questo è tutto. Per verificare che tutto funzioni, modificate il profilo di un utente nell’area di amministrazione di WordPress e vedrete la data di registrazione dell’utente.

Showing member registration date in WordPress user profile

Mostrare la data di registrazione dell’utente sul vostro sito web

In questo metodo, utilizzeremo un semplice shortcode per visualizzare la data di registrazione degli utenti sul front-end del vostro sito WordPress.

Per prima cosa dovrete aggiungere il seguente codice nel file functions.php del vostro tema o in un plugin specifico per il sito.


function wpb_user_registration_date($atts, $content = null ) { 

$userlogin = shortcode_atts( array(
'user' => FALSE,
), $atts );

$uname = $userlogin['user'];     

if ($uname!== FALSE) {             

$user = get_user_by( 'login', $uname );  
if ($user == false) { 

$message ='Sorry no such user found.'; 


} else { 

$udata = get_userdata( $user-ID );
$registered = $udata->user_registered;

$message =	'Member since: ' . date( "d F Y", strtotime( $registered ) );

}
	
} else { 

$message = 'Please provide a username.'; 

} 

return $message; 

} 

add_shortcode('membersince', 'wpb_user_registration_date');

Successivamente, è possibile visualizzare la data di registrazione di un utente utilizzando semplicemente lo shortcode in questo modo:

[membersince user=peter]

Sostituire peter con il nome utente che si desidera mostrare.

Speriamo che questo articolo vi abbia aiutato a mostrare la data di registrazione nei profili utente di WordPress. Potreste anche consultare il nostro tutorial su come aggiungere campi aggiuntivi al profilo utente nella registrazione di WordPress.

Se questo articolo vi è piaciuto, iscrivetevi al nostro canale YouTube per i video tutorial su WordPress. Potete trovarci anche su Twitter e Facebook.

Divulgazione: I nostri contenuti sono sostenuti dai lettori. Ciò significa che se cliccate su alcuni dei nostri link, potremmo guadagnare una commissione. Vedi come WPBeginner è finanziato , perché è importante e come puoi sostenerci. Ecco il nostro processo editoriale .

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Il kit di strumenti WordPress definitivo

Ottenete l'accesso gratuito al nostro kit di strumenti - una raccolta di prodotti e risorse relative a WordPress che ogni professionista dovrebbe avere!

Reader Interactions

18 commentiLascia una risposta

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Tom says

    Hello :) Nice code thank you but is it possible with the shortcode to show the register date of the user which actually logged in?

  3. Ralph says

    TYPO: There is one typo in the code in method 3 that results in the error of date always showing the same value: On line 37 is
    $udata = get_userdata( $user-ID );

    while it should be:
    $udata = get_userdata( $user->ID );

    (Notice the arrow instead of the dash)

  4. chergui djaouida says

    please i need to introduce the date of registration of a user in a php code not by a shortcode how to do?

  5. Isabelle Laplante says

    «Showing Registration Date Field in User Profile» costum Plugin works but do not show the real date… For every users, the added information is«Member since: Jun 2015» … Wich is not the case… Can you help?

  6. Jody Hockley says

    Hi,

    Thanks for the plugin, nice easy fix for a simple problem.

    I have just used the second option to show in the User profile page. However it only show month and year, not the day. How would I alter the plugin code to show the day too?

    Thanks for your help, much appreciated

    Jody

  7. Gerard says

    Very nice :).
    I needed only first code snippet (which works).
    Just one little note: on line 37 you should make it ‘$user->ID” you forgot the ‘>’, else it shows notices when debuggin.

    Thank you.

  8. Davis says

    Admin Columns plugin developer requires $60US to sort by registration date. If you are a site manager, find a better solution. WP should include this ultra-basic functionality in all WP installs.

  9. Hemang Rindani says

    Insightful article. WordPress is the most user friendly CMS that can create complex websites with very less or no technical knowledge. It comes with rich set of modules and plugins that can transform your digital dream into a reality. However, it is important to identify the secured and authenticated tools for your WordPress website to improve the overall website security. WP is capable of handling multiple sites with multiple users which has been a requirement of big organizations. WP provides some great features to manage user accounts and prevent the website from unauthorized access using certain plugins with your website. There are also tools to enhance the user experience like the one described in the article to provide a great personal feel to the user.

    Thanks for the article.

  10. Patrick Catthoor says

    This looked like a feature I could use for my website. So, I tried all 3 methods.
    Method 1 works like a charm, but both methods 2 and 3 always provide the same date: 01 January 1970. Something must be wrong, but I couldn’t figure out what.
    Any ideas?

    • Celito C. Macachor says

      I realize this is an old issue, but I just came across this article after a recent search. Great, insightful articles, but I have the same concern as Patrick’s. In the all users list, the registration date is correct. While it is not critical, only one date (July 2016) is shown for all users in the Member since field. Has this issue been resolved? Thanks for any updated information.

Lascia una risposta

Grazie per aver scelto di lasciare un commento. Tenga presente che tutti i commenti sono moderati in base alle nostre politica dei commenti e il suo indirizzo e-mail NON sarà pubblicato. Si prega di NON utilizzare parole chiave nel campo del nome. Avremo una conversazione personale e significativa.