rtCamp / login-with-google

Minimal plugin which allows WordPress user to login with google.
https://wordpress.org/plugins/login-with-google/
GNU General Public License v2.0
57 stars 17 forks source link

Remove Login Button from Admin Login Page #174

Open Poocey opened 5 months ago

Poocey commented 5 months ago

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.

ankitrox commented 2 months ago

@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.

Poocey commented 2 months ago

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

Any recommendations?

ankitrox commented 2 months ago

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

$container = \RtCamp\GoogleLogin\container();
Poocey commented 2 months ago

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

/**

Poocey commented 2 months ago

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