How to personalize Membership 2 Pro login experience?

On the default page, that a person sees upon logging into their account. I would like the message to say "Good evening or Good morning (depending on day) 'first name'". Is it possible to customize the welcome based on time of day? If not, what about adding their first name?

  • Adam Czajczyk

    Hello Julius,

    I hope you're well today and thank you for your question!

    That's indeed quite an interesting idea!

    You can customize the "welcome message" easily I think. By default Membership 2 is set to redirect user to the "Account" page after login. To add a custom message there, please follow these steps:

    - go to your dashboard's "Membership 2 -> Settings" page -> "General" tab
    - click on "Edit page" link right below the "Account" page drop-down list

    This will open "Account" page for editing. You can now add your message here the same way that you add any content to any WordPress post/page. Please make sure though that you kept "[ms-membership-account]" shortcode intact.

    As for adding "time based" greeting and user name. This would require some additional code. Fortunately, it should be quite simple to achieve.

    1. To greet user by his/her first name, please add this code to your current theme's functions.php file:

    // display user's first name shortcode
    // usage [wpmu_firstname]
    
    function wpmu_user_firstname_shortcode() {
    	$current_user = wp_get_current_user();
    	return $current_user->user_firstname;
    
    }
    add_shortcode('wpmu_firstname','wpmu_user_firstname_shortcode');

    This adds a shortcode that you may use anywhere in your posts/pages and it will just display the first name of logged in user. The shortcode is

    [wpmu_firstname]

    2. To define various greetings based on time of the day, add another piece of code to the functions.php file of your current theme:

    // greets users depending on time of the day
    // usage [wpmu_greetings]
    
    function wpmu_user_timegreetings_shortcode() {
    	$hours_passed = round((time() - strtotime("today")) / 3600);
    	switch ($hours_passed) {
    		case 0:
    			$greeting = '1 greeting';
    			break;
    		case 1:
    			$greeting = '1 greeting';
    			break;
    		case 2:
    			$greeting = '1 greeting';
    			break;
    		case 3:
    			$greeting = '1 greeting';
    			break;
    		case 4:
    			$greeting = '1 greeting';
    			break;
    		case 5:
    			$greeting = '1 greeting';
    			break;
    		case 6:
    			$greeting = '1 greeting';
    			break;
    		case 7:
    			$greeting = '1 greeting';
    			break;
    		case 8:
    			$greeting = '1 greeting';
    			break;
    		case 9:
    			$greeting = '1 greeting';
    			break;
    		case 10:
    			$greeting = '1 greeting';
    			break;
    		case 11:
    			$greeting = '1 greeting';
    			break;
    		case 12:
    			$greeting = '1 greeting';
    			break;
    		case 13:
    			$greeting = '1 greeting';
    			break;
    		case 14:
    			$greeting = '1 greeting';
    			break;
    		case 15:
    			$greeting = '1 greeting';
    			break;
    		case 16:
    			$greeting = '1 greeting';
    			break;
    		case 17:
    			$greeting = '1 greeting';
    			break;
    		case 18:
    			$greeting = '1 greeting';
    			break;
    		case 19:
    			$greeting = '1 greeting';
    			break;
    		case 20:
    			$greeting = '1 greeting';
    			break;
    		case 21:
    			$greeting = '1 greeting';
    			break;
    		case 22:
    			$greeting = '1 greeting';
    			break;
    		case 23:
    			$greeting = '1 greeting';
    			break;
    	}
    	return $greeting;
    }
    add_shortcode('wpmu_greetings','wpmu_user_timegreetings_shortcode');

    You will want however to adjust this code first. As you can see there are 24 lines like this:

    $greeting = '1 greeting';

    The values before them (e.g. 3, 10, 22) indicate how many hours had already passed since last midnight. Therefore replace the "1 greeting" string with your own greeting for each time of the day et voila: you got 24 different greetings for each of 24 hours of the day.

    To sum it up:

    Once you add both these codes to your theme's "functions.php" file you could use for example such line on your Memberships 2 "Account" page to greet user automatically:

    [wpmu_greetings] [wpmu_firstname]!
    Welcome to our site!

    I hope that helps!

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.