2

After a new user creates an account and logs in, the subscriber lands at the /wp-admin/profile.php page. With certain demographics, I've found some users tend to get stuck there.

I'd like to be able to add HTML such as a descriptive paragraph with links to areas on the site, to the top of the Subscriber level Profile page; if possible between the 'Profile' header and 'Personal Details'.

Uses for this include directing users back to applications, specific forms, etc.

Pseudo code for envisioned profile.php is:

...
<h1>Profile</h1>

if user is subscriber, then echo:

<div class="subscriberProfile">
    <p>Looking for the <a href="http://example.com/form">Example Form</a>?</p>
</div>

Thank you in advance.

2
  • Why not just redirect after login, to a different page altogether? Personally I don't like dropping the user into their profile page...would rather have a nicer page to land on. – C C Sep 14 '16 at 23:50
  • That's definitely plausible for sites where users have only one segment of subscribers; i.e. users only register for x, etc., but if users are registering for a-z, the landing page could become less effective. I could definitely see myself using that for a registration exclusive to applications, etc. – beta208 Sep 15 '16 at 12:10
4

Add this code to your functions.php to add a notice for users with the subscriber role on their profile and dashboard admin pages.

function wpse239290_user_welcome_notice() {
    // Make sure that the user is assigned to the subscriber role, specifically.
    // Alternatively, capabilities can be checked with current_user_can(), but roles are not supposed to be checked this way.
    $user = wp_get_current_user();
    if ( ! in_array( 'subscriber', $user->roles ) ) {
        return;
    }

    // Make sure the profile or dashboard screens are being viewed.
    $screen = get_current_screen();
    if ( ! $screen || ( 'profile' !== $screen->id && 'dashboard' !== $screen->id ) ) {
        return;
    }

    // Show a friendly green notice, and allow it to be dismissed (it will re-appear if the page is reloaded though).
    $class = 'notice notice-success is-dismissible';

    // Customize the HTML to  fit your preferences.
    $message = '<p>Looking for the <a href="http://example.com/form">Example Form</a></p>';

    printf( '<div class="%1$s"><div class="subscriberProfile">%2$s</div></div>', $class, $message ); 
}
add_action( 'admin_notices', 'wpse239290_user_welcome_notice' );
4
  • I'll give this a shot in the dev environment. I'm assuming this goes on functions.php rather than the profile.php template? I'll find out soon enough. – beta208 Sep 15 '16 at 12:08
  • How could I make this apply to the dashboard too? if ( ! $screen || 'profile' !== $screen->id ) { return; } something about OR 'dashboard' – beta208 Sep 15 '16 at 13:40
  • 1
    Sure! Updated the code so that it works on the dashboard too. – Dave Romsey Sep 15 '16 at 14:19
  • 1
    Thanks Dave. This has been really helpful. PS: Dave Romsey ~ Ramsey, that's priceless. Thanks for formatting the post. That is helpful to know too. – beta208 Sep 15 '16 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.