Last active
August 9, 2019 03:08
-
-
Save adamrosloniec/54f2ab0427cef7f86b439dce624d87a0 to your computer and use it in GitHub Desktop.
WordPress - Hide Login Page with custom hidden $_GET and show website only via Rest API endpoints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function hide_login_page_and_show_only_rest_api_endpoints() { | |
// work only on productions sites | |
if ( | |
!stristr($_SERVER['SERVER_NAME'], 'local') | |
&& !is_user_logged_in() | |
) { | |
if ( | |
( | |
in_array( $GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php') | |
&& isset($_GET['your_custom_get']) | |
&& $_GET['your_custom_get'] === 'true' | |
) || ( | |
stristr($_SERVER['REQUEST_URI'], '/wp-json/') | |
) | |
) { | |
// ok | |
} else { | |
// die | |
global $wp_query; | |
$wp_query->set_404(); | |
status_header( 404 ); | |
nocache_headers(); | |
die(); | |
} | |
} | |
} | |
add_action( 'wp_loaded', 'hide_login_page_and_show_only_rest_api_endpoints' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment