Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Login Button from Admin Login Page #174

Open
Poocey opened this issue Feb 15, 2024 · 6 comments
Open

Remove Login Button from Admin Login Page #174

Poocey opened this issue Feb 15, 2024 · 6 comments

Comments

@Poocey
Copy link

Poocey commented Feb 15, 2024

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
Copy link
Contributor

@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
Copy link
Author

Poocey commented May 10, 2024

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

Any recommendations?

@ankitrox
Copy link
Contributor

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

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

@Poocey
Copy link
Author

Poocey commented May 13, 2024

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' ] );
    }

@Poocey Poocey closed this as completed May 13, 2024
@Poocey
Copy link
Author

Poocey commented May 16, 2024

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

@Poocey Poocey reopened this May 16, 2024
@Poocey
Copy link
Author

Poocey commented Jul 22, 2024

Any update here? Still getting js error: null is not an object (evaluating 'this.googleLoginButton.classList')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants