php – How to Fix Undefined array key “action” on WordPress site running on Php8

Question

I’m getting error PHP message: PHP Warning: Undefined array key “action” for this code:

function disable_lost_password() {
    if ( in_array( $_GET['action'], array('lostpassword', 'retrievepassword') ) ) {
        wp_redirect( wp_login_url(), 301 );
        exit;
    }
}
add_action( "init", "disable_lost_password" );

How to fix it?

in progress 0
Rajesh Patel 6 months 2021-06-01T19:39:12-05:00 0 Answer 0 views 0

Answer ( 1 )

    0
    2021-06-02T06:16:53-05:00

    You should check if an array item is set before using the item, e.g.

    if ( isset( $_GET['action'] ) && in_array( ... ) )

Leave an answer

Browse
Browse