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

Jak wyświetlić datę rejestracji użytkownika w WordPress

Czy chcesz wyświetlać datę rejestracji użytkownika w WordPress? Często popularne witryny członkowskie i fora wyświetlają datę rejestracji użytkownika w profilu jako „członek od 2015 roku”. W tym artykule omówimy, jak wyświetlić datę rejestracji użytkownika w WordPress.

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

Gdzie i jak wyświetlać datę rejestracji użytkownika?

Niektórzy z was mogą po prostu chcieć wyświetlać datę rejestracji użytkownika w kolumnach administratora na stronie Użytkownicy. Da ci to szybki przegląd tego, kiedy użytkownik dołączył do twojej witryny internetowej i pozwoli ci sortować według daty rejestracji.

Innym scenariuszem użycia jest wyświetlenie daty rejestracji użytkownika na stronie „Edytuj profil”. Pozwoli to każdemu administratorowi i samemu użytkownikowi zobaczyć, kiedy dołączył do twojej witryny internetowej.

Ostatnim, ale prawdopodobnie najbardziej popularnym scenariuszem jest wyświetlanie daty rejestracji użytkownika na jego publicznym profilu na front-endzie twojej witryny internetowej.

Przyjrzyjmy się, jak można to zrobić.

Dodawanie kolumny Data rejestracji na stronie Użytkownicy w obszarze administracyjnym

Pierwszą rzeczą, którą musisz zrobić, to zainstalować i włączyć wtyczkę Admin Columns. Po włączaniu należy przejść na stronę Ustawienia „ Kolumny administratora, aby skonfigurować wtyczkę.

Add registered column in users table

W karcie Kolumny administratora kliknij Użytkownicy, a następnie kliknij przycisk Dodaj kolumnę.

Następnie wybierz „Zarejestrowany” w rozwijanym menu Rodzaj i kliknij przycisk Zapisz aktualizacje.

Możesz teraz przejść na ekran użytkowników, gdzie zobaczysz nową kolumnę oznaczoną jako „Zarejestrowany”, pokazującą datę rejestracji użytkownika na twojej witrynie WordPress.

Users table with registration date column

Zobacz, co jeszcze możesz zrobić, aby dodać i dostosować kolumny administratora w WordPress.

Wyświetlanie pola daty rejestracji w profilu użytkownika

Aby wyświetlić datę rejestracji na stronie edycji profilu, musisz wgrać własną wtyczkę do swojej witryny internetowej.

Wystarczy utworzyć nowy plik na twoim komputerze za pomocą edytora tekstu, takiego jak Notatnik i zapisać go jako membersince.php na pulpicie.

Następnie otwórz plik i wklej do niego następujący kod.

<?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 ) )
	);
}
?>

.

Zapisz twój plik, a następnie prześlij go na twoją witrynę WordPress.

Na koniec możesz połączyć się z twoją witryną WordPress za pomocą klienta FTP, a następnie przejść do katalogu /wp-content/plugins/. Wybierz plik membersince.php z twojego komputera, a następnie prześlij go.

Teraz możesz przejść do strony wtyczek WordPress i włącz tę wtyczkę w twojej witrynie internetowej.

To wszystko. Sprawdź, czy wszystko działa, edytując profil użytkownika w twoim obszarze administracyjnym WordPress, a zobaczysz datę rejestracji użytkownika.

Showing member registration date in WordPress user profile

Wyświetlanie daty rejestracji użytkownika na twojej witrynie internetowej

W tej metodzie będziemy używać krótkiego kodu do wyświetlania daty rejestracji dowolnego użytkownika na front-endzie twojej witryny WordPress.

Najpierw musisz dodać następujący kod w pliku functions. php twojego motywu lub we wtyczce specyficznej dla witryny.


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');

.

Następnie możesz wyświetlić datę rejestracji użytkownika, po prostu używając krótkiego kodu w następujący sposób:

[membersince user=peter].

Zastąp peter nazwą użytkownika, którą chcesz wyświetlić.

Mamy nadzieję, że ten artykuł pomógł ci pokazać datę rejestracji w profilach użytkowników WordPress. Możesz również zapoznać się z naszym poradnikiem na temat dodawania dodatkowych pól profilu użytkownika w rejestracji WordPress.

Jeśli podobał Ci się ten artykuł, zasubskrybuj nasz kanał YouTube, aby zobaczyć poradniki dotyczące filmów WordPress. Możesz nas również znaleźć na Twitterze i Facebooku.

Ujawnienie: Nasze treści są wspierane przez czytelników. Oznacza to, że jeśli klikniesz na niektóre z naszych linków, możemy otrzymać prowizję. Zobacz jak WPBeginner jest finansowany, dlaczego to ma znaczenie i jak możesz nas wspierać. Oto nasz proces redakcyjny.

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.

Najlepszy zestaw narzędzi WordPress

Uzyskaj BEZPŁATNY dostęp do naszego zestawu narzędzi - zbiór produktów i zasobów związanych z WordPressem, które każdy profesjonalista powinien mieć!

Reader Interactions

18 komentarzyZostaw odpowiedź

  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.

Zostaw odpowiedź

Dziękujemy za pozostawienie komentarza. Pamiętaj, że wszystkie komentarze są moderowane zgodnie z naszymi polityka komentarzy, a Twój adres e-mail NIE zostanie opublikowany. NIE używaj słów kluczowych w polu nazwy. Przeprowadźmy osobistą i konstruktywną rozmowę.