0

I see this error

Notice: Undefined index: action in /home/olexywro/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(352) : eval()'d code on line 6

in my login page with this code snippets:

// Redirect Registration Page
function my_registration_page_redirect()
{
    global $pagenow;

    if ( ( strtolower($pagenow) == 'wp-login.php') && ( strtolower( $_GET['action']) == 'register' ) ) {
        wp_redirect( home_url('/zarejestruj-sie/'));
    }
}
add_filter( 'init', 'my_registration_page_redirect' );

Somone could me tell me why?

6th line of this code:

if ( ( strtolower($pagenow) == 'wp-login.php') && ( strtolower( $_GET['action']) == 'register' ) ) {
  • 1
    The culprit is likely that the action GET variable is not set. Changing ( strtolower( $_GET['action']) to isset($_GET['action']) && strtolower( $_GET['action']) should solve the immediate issue. On a side note, it looks like you're using this "snippet ops" plugin to execute code you're storing as a string via PHP's eval() - this can be a very dangerous practice and open your site to a plethora of security vulnerabilities. I'd recommend looking into alternate solutions to whatever problem that plugin is solving, unless you understand and are comfortable with the risks it presents. – bosco Sep 17 '18 at 16:12
2

You're doing this:

strtolower( $_GET['action'])

But you're not checking if $_GET['action'] exists first. You can't count on it being set, because when you visit wp-login.php, it doesn't have ?action= in the URL, but this hook still fires.

So you need to add isset( $_GET['action'] ) to your conditions:

if ( 
    strtolower($pagenow) == 'wp-login.php' &&
    isset( $_GET['action'] ) &&
    strtolower( $_GET['action'] ) == 'register'
) {

}

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.