functions - Competing Login Redirects - Need to be Combined?

I currently have two login redirects in my general-functions.php file in my mu-plugins directory for my multisite instal

I currently have two login redirects in my general-functions.php file in my mu-plugins directory for my multisite installation.

The first one is for someone who logs in from a specific page. That person should get redirected back to that page after logging in. A "redirect_to" parameter in the URL handles this when the login URL is as follows: .php?redirect_to=/example-page/

The second one is for everyone else logging into the admin section. Those folks should get redirected to: /wp-admin/my-sites.php

Here are the two functions:

function my_login_redirect( $redirect, $user ) {
    $redirect = isset( $_GET['redirect_to'] ) ? $_GET['redirect_to'] : wp_get_raw_referer();
    return $redirect;
}
add_filter( 'user_registration_login_redirect', 'my_login_redirect', 9, 2 );

function admin_default_page() {
    return '/wp-admin/my-sites.php';
}
add_filter('login_redirect', 'admin_default_page', 10);

Both functions work on their own. But sitting in the same functions file, the second one wins out and prevents the first one from working. I have tried to combine them, but unsuccessfully. Obviously, it would make sense to check for a "redirect_to" parameter and perform that redirect if it exists, then redirect everyone else to the My Sites page.

But for whatever reason, I cannot figure out how to do this. I've tried changing the priority of the add_filter, as you can see, but that didn't work. I have tried changing the order in which the functions appear within the functions file. That didn't work. I have tried combining the guts of each function within an if/else statement in either function, and that didn't work for me.

They are referencing two different hooks, so that may be my problem, but I need a way to either combine the two functions or make them function properly independent of each other without the My Sites function winning out every time, which is the current result.

Any help appreciated. Thanks!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745530483a4631670.html

相关推荐

  • functions - Competing Login Redirects - Need to be Combined?

    I currently have two login redirects in my general-functions.php file in my mu-plugins directory for my multisite instal

    23小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信