billw16 on "Do Not Redirect new user to Edit Profile Page"

ساخت وبلاگ

Simple Goal: Do not redirect new users to the WP Edit Profile Page on their initial login (using the native WP Registration process).

I do not want to permanently redirect users to some other page (that would defeat any bookmarks, links, and any other navigation to a restricted page). I do not want to prevent users from EVER going to their Edit Profile Page, I just don't want them to AUTOMATICALLY go there when they first login.

Should be simple right? Honestly I think this should be a setting in WP core - I mean really, who wants their new users to immediately go to their profile edit page? Anyway, in fact the solution is very simple, but (maybe because I'm new to WP and php) this took me a lot of time - searching for a plugin, or code, and trying various things that didn't really work for us. Since I didn't find a plugin, nor a post about how to do this, I thought I'd post my solution. Hopefully this will help others.

I added the code below to our site plugin. (for site plugin see http://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/ ):

/* REDIRECT AFTER INITIAL LOGIN
* Prevents new users from automatically going to profile page
*/
function my_login_redirect( $redirect_to, $request, $user ) {
$admin_url = home_url()."/wp-admin/";
if ( $redirect_to == $admin_url ) {
if (empty($request)) {
return home_url();
} else {
return $redirect_to;
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );

Obviously, you could redirect to any other page rather than home_url, or add other conditions as needed. If anyone has improvements on this, they are welcome.

NOTE: This solution is dependent on the way the native WP registration process currently works, which may change in some future update. Currently (WP 4.5.2) after the user confirms or changes their password (by following a link in the registration email they received), they are prompted to login, after which they are automatically redirected to WP administration (home path wp-admin) which calls profile.php and '$request' is empty.

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 405 تاريخ : چهارشنبه 3 شهريور 1395 ساعت: 2:22