Skip Navigation

[Resolved] Redirect to a content template / URL

This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Author
Posts
#908366

I created a redirect for my users of a certain user role the first time they log in. This is working as intended. See code:

[code]// Login redirect 1st login
//hook when user registers
add_action( 'user_register', 'myplugin_registration_save', 10, 1 );

function myplugin_registration_save( $user_id ) {

// insert meta that user not logged in first time
update_user_meta($user_id, 'prefix_first_login', '1');

}

// hook when user logs in
add_action('wp_login', 'your_function', 10, 2);

function your_function($user_login, $user) {

$user_id = $user->ID;
$role = $user->roles[0];
// getting prev. saved meta
$first_login = get_user_meta($user_id, 'prefix_first_login', true);
// if first time login
if( ($first_login == '1' ) && ($role == 'vakman')) {
// update meta after first login
update_user_meta($user_id, 'prefix_first_login', '0');
// redirect to given URL
wp_redirect( 'hidden link' );
exit;
}
}[/code]

However I actually want the user to land on the "edit user form". But the URL for it contains the user's name. Like so domain.com/slug/user-name/content-template-id=587 and adding the form to a page doesn't show the form ofcourse. How could I best tackle this?

Also is it possible for a user to see a message the first time they land on this page?

#908660

Hello,

I assume you are going to get the user's login name (user_login) by user's ID ($user_id)
It needs custom codes, for example you can try with WordPress built-in function get_user_by(), like this:

$user_obj = get_user_by('id', $user_id);
$user_login = $user_obj->user_login;

More help:
https://developer.wordpress.org/reference/functions/get_user_by/