Change Register/Lost Password “action links” URLs, titles & Modify Error pages. Theme My Login plugin driven Wordpress network multisite

前端 未结 1 1456
悲&欢浪女
悲&欢浪女 2021-01-28 02:48

I have set up a huge a network multisite for my client which receives 1000\'s of new users per month and is already 5 clone network sites deep and counting It has a static Home

相关标签:
1条回答
  • 2021-01-28 03:29

    Here is the final working code I added just above /* Include popcorn.js --------------------- */ of functions.php after much testing and changing:

    /* Filter to redirect register and lost password pages-------------WPN-09-03-2016--*/
    
    function tml_action_url( $url, $action, $instance ) {
        if ( 'register' == $action )
            $url = 'https://EXTERNAL-REGISTRATION-PAGE/';
        elseif ( 'lostpassword' == $action )
            $url = 'https://EXTERNAL-PASSWORD-RESET-PAGE';
        return $url;
    }
    add_filter( 'tml_action_url', 'tml_action_url', 10, 3 );
    
    /* Filter to change titles of links to above--------------------WPN-09-03-2016--*/
    
    function tml_title( $title, $action ) {
        if ( is_user_logged_in() ) {
            $user = wp_get_current_user;
            if ( 'profile' == $action )
                $title = 'Your Profile';
            else
                $title = sprintf( 'Welcome, %s', $user->display_name );
        } else {
            switch ( $action ) {
                case 'register' :
                    $title = 'Not a member? Register';
                    break;
                case 'lostpassword':
                    $title = 'Forgot your password? Reset it';
                    break;
                case 'retrievepassword':
                case 'resetpass':
                case 'rp':
                case 'login':
                default:
                    $title = 'Sign In';
            }
        }
        return $title;
    }
    add_filter( 'tml_title', 'tml_title', 11, 2 );
    
    /* Filter to change link in user error message------------------WPN-10-03-2016--*/
    
    function login_error_message($error){
        //check if that's the error you are looking for
        $pos = strpos($error, 'incorrect');
        if (is_int($pos)) {
            //its the right error so you can overwrite it
            $error = "<strong>ERROR</strong>: Invalid username/password. <a href= https://EXTERNAL-PASSWORD-RESET-PAGE/>Lost Password?</a>";
        }
        else $error = "<strong>ERROR</strong>: Invalid username/password. <a href= https://EXTERNAL-PASSWORD-RESET-PAGE/>Lost Password?</a>";
        return $error;
    }
    add_filter('login_errors','login_error_message');
    

    Kudos to Igor Yavych who bailed me out while I was making a rookie mistake very early hours of the morning after no sleep last night while experimenting with code to finally get the working result! ( See here: Wordpress PHP issue in functions.php regarding if and else if statement )

    0 讨论(0)
提交回复
热议问题