rtCamp / login-with-google

Minimal plugin which allows WordPress user to login with google.

Home Page:https://wordpress.org/plugins/login-with-google/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove Login Button from Admin Login Page

Poocey opened this issue · comments

How can we remove the login button from wp-login.php?

Turns out it's added here:

add_action( 'login_form', [ $this, 'login_button' ] );

But I've been unable to remove that action from login_form hook.

@Poocey You can do that easily with the following code (maybe in theme's functions.php file)

function remove_google_login_btn() {
    $plugin = \RtCamp\GoogleLogin\plugin();
    $login_instance = $plugin->container->get( 'login_flow' );
    
    remove_action( 'login_form', [ $login_instance, 'login_button' ] );
}
add_action( 'init', 'remove_google_login_btn' );

Notice that we have a container that is managing instances of all the services (classes). You can call \RtCamp\GoogleLogin\plugin()->container to get the container and call get method to get the respective service.

Let me know if it helps.

Thanks.

Unfortunately container is a private property and can't be accessed directly.

Any recommendations?

Sorry, you can directly use the container function to access container instance.

$container = \RtCamp\GoogleLogin\container();

Thank you so much! That worked flawlessly.
Here was my final snippet in case others want to use it:

/**

  • Remove login button on wp-login.php page
    */
    add_action( 'init', 'mytheme_google_login_remove_from_login_page' );
    function mytheme_google_login_remove_from_login_page() {

    // Make sure plugin is active
    if( ! in_array( 'login-with-google/login-with-google.php', apply_filters('active_plugins', get_option('active_plugins') ) ) ) {
    return;
    }

    $container = \RtCamp\GoogleLogin\container();
    $instance = $container->get( 'login_flow' );

    remove_action( 'login_form', [ $instance, 'login_button' ] );
    }

By the way, after removing the login button on the wp-login.php page, I get this JS error:

this.googleLoginButton is null (Cannot read properties of null (reading 'classList')).

Looks like it's from this line of code:

this.form.querySelector(".wp_google_login"),this.googleLoginButton.classList.remove("hidden")

From this file:

/wp-content/plugins/login-with-google/assets/build/js/login.js