Skip to content

Instantly share code, notes, and snippets.

@gene1wood
Last active July 1, 2024 00:11
Show Gist options
  • Save gene1wood/f3d39a8f894973cc8d75e2a632ec3715 to your computer and use it in GitHub Desktop.
Save gene1wood/f3d39a8f894973cc8d75e2a632ec3715 to your computer and use it in GitHub Desktop.
Disable Wordpress native username password login when using Google Apps Login
<?php
/**
* Plugin Name: Disable Native Login
* Plugin URI: https://cs.cementhorizon.com/
* Description: Disable the native username password login in wordpress
* Version: 1.0.0
* Author: Gene Wood
* Author URI: https://cs.cementhorizon.com/
* License: GPL2
*/
// Install this by putting it in wp-content/plugins/disable-native-login/
// https://deluxeblogtips.com/completely-disable-login-username-password-wordpress/
add_action( 'login_init', function () {
if ( isset( $_POST['log'] ) || isset( $_POST['user_login'] ) ) {
die;
}
} );
// https://codex.wordpress.org/Customizing_the_Login_Form
function hide_login_form() { ?>
<style type="text/css">
#loginform h3.galogin-or, #loginform p:not(.galogin), #loginform div.user-pass-wrap, #login p#nav {
display: none;
}
</style>
<?php }
add_action( 'login_enqueue_scripts', 'hide_login_form' );
?>
@skyzlmt
Copy link

skyzlmt commented May 20, 2024

thank you for this. perfect for me as I only want users to login via my social button (patreon).
But, I wanted a URL override to display the old form based on Query string. I am a Microsoft.Net programmer so not an expert in Wordpres dev or PHP but pieced this together. If you like and want to incorporate it in but have a cleaner implementation... feel free to modify

Simply adding a query parameter "&localadmin" will display the original fields and allow login the classic way. obviously that localadmin can be adjusted. :-)

add_action( 'login_init', function () {
	$referrer_url = wp_get_referer();
	if (str_contains($referrer_url,'localadmin'))
		{	
			return;
		}	
	
	if ( isset( $_POST['log'] ) || isset( $_POST['user_login'] ) ) {
		die;
	}
} );

// https://codex.wordpress.org/Customizing_the_Login_Form
function hide_login_form() { 
	$current_url = add_query_arg( NULL, NULL );
	if (str_contains($current_url,'localadmin'))
		{	
			return;
		}	
?>
    <style type="text/css">
        #loginform h3.galogin-or, #loginform p:not(.galogin), #loginform div.user-pass-wrap, #login p#nav {
            display: none;
        }
    </style>
<?php
   }
add_action( 'login_enqueue_scripts', 'hide_login_form' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment