Fixed default wp page restriction function

This commit is contained in:
champsupertramp
2015-11-25 19:27:41 +08:00
parent 94aa894dba
commit 1ec02e11a9
+58 -55
View File
@@ -6,80 +6,83 @@
add_action('init','um_block_wpadmin_for_guests'); add_action('init','um_block_wpadmin_for_guests');
function um_block_wpadmin_for_guests() { function um_block_wpadmin_for_guests() {
global $pagenow; global $pagenow;
if ( isset( $_REQUEST['um_panic_key'] ) && $_REQUEST['um_panic_key'] == um_get_option('panic_key') ) { if ( isset( $_REQUEST['um_panic_key'] ) && $_REQUEST['um_panic_key'] == um_get_option('panic_key') ) {
exit( wp_redirect( add_query_arg('_verified_key', $_REQUEST['um_panic_key'], wp_login_url() ) ) ); exit( wp_redirect( add_query_arg('_verified_key', $_REQUEST['um_panic_key'], wp_login_url() ) ) );
} }
if ( !isset( $_REQUEST['_verified_key'] ) || $_REQUEST['_verified_key'] != um_get_option('panic_key') ) { if ( !isset( $_REQUEST['_verified_key'] ) || $_REQUEST['_verified_key'] != um_get_option('panic_key') ) {
// Logout screen
// Logout screen if ( isset( $pagenow ) && $pagenow == 'wp-login.php' && is_user_logged_in() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'logout' ) {
if ( isset( $pagenow ) && $pagenow == 'wp-login.php' && is_user_logged_in() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'logout' ) { $redirect = um_get_core_page('logout');
$redirect = um_get_core_page('logout');
if ( isset( $_REQUEST['redirect_to'] ) && !empty( $_REQUEST['redirect_to'] ) ) {
$redirect = add_query_arg( 'redirect_to', $_REQUEST['redirect_to'], $redirect );
}
exit( wp_redirect( $redirect ) );
}
// Login screen
if ( isset( $pagenow ) && $pagenow == 'wp-login.php' && !is_user_logged_in() && !isset( $_REQUEST['action'] ) ) {
$allowed = um_get_option('wpadmin_login'); if ( isset( $_REQUEST['redirect_to'] ) && !empty( $_REQUEST['redirect_to'] ) ) {
$allowed = apply_filters('um_whitelisted_wpadmin_access', $allowed ); $redirect = add_query_arg( 'redirect_to', $_REQUEST['redirect_to'], $redirect );
if ( !$allowed ) {
$act = um_get_option('wpadmin_login_redirect');
$custom_url = um_get_option('wpadmin_login_redirect_url');
if ( $act == 'um_login_page' || !$custom_url ) {
$redirect = um_get_core_page('login');
} else {
$redirect = $custom_url;
} }
exit( wp_redirect( $redirect ) ); exit( wp_redirect( $redirect ) );
} }
}
// Login screen
if ( isset( $pagenow ) && $pagenow == 'wp-login.php' && !is_user_logged_in() && !isset( $_REQUEST['action'] ) ) {
// Register screen $allowed = um_get_option('wpadmin_login');
if ( isset( $pagenow ) && $pagenow == 'wp-login.php' && !is_user_logged_in() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'register' ) { $allowed = apply_filters('um_whitelisted_wpadmin_access', $allowed );
$allowed = um_get_option('wpadmin_register');
$allowed = apply_filters('um_whitelisted_wpadmin_access', $allowed );
if ( !$allowed ) {
$act = um_get_option('wpadmin_register_redirect'); if ( !$allowed ) {
$custom_url = um_get_option('wpadmin_register_redirect_url');
$act = um_get_option('wpadmin_login_redirect');
if ( $act == 'um_register_page' || !$custom_url ) { $custom_url = um_get_option('wpadmin_login_redirect_url');
$redirect = um_get_core_page('register');
} else { if ( $act == 'um_login_page' || !$custom_url ) {
$redirect = $custom_url; $redirect = um_get_core_page('login');
} else {
$redirect = $custom_url;
}
exit( wp_redirect( $redirect ) );
}
}
// Register screen
if ( isset( $pagenow ) && $pagenow == 'wp-login.php' && !is_user_logged_in() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'register' ) {
$allowed = um_get_option('wpadmin_register');
$allowed = apply_filters('um_whitelisted_wpadmin_access', $allowed );
if ( !$allowed ) {
$act = um_get_option('wpadmin_register_redirect');
$custom_url = um_get_option('wpadmin_register_redirect_url');
if ( $act == 'um_register_page' || !$custom_url ) {
$redirect = um_get_core_page('register');
} else {
$redirect = $custom_url;
}
exit( wp_redirect( $redirect ) );
} }
exit( wp_redirect( $redirect ) );
} }
}
// Lost password page // Lost password page
if ( isset( $pagenow ) && $pagenow == 'wp-login.php' && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'lostpassword' ) { if ( isset( $pagenow ) && $pagenow == 'wp-login.php' && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'lostpassword' ) {
exit( wp_redirect( um_get_core_page('password-reset') ) ); exit( wp_redirect( um_get_core_page('password-reset') ) );
} }
// Prevention for logged in user // Prevention for logged in user
if ( isset( $pagenow ) && $pagenow == 'wp-login.php' && is_user_logged_in() ) { if ( isset( $pagenow ) && $pagenow == 'wp-login.php' && is_user_logged_in() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] != 'postpass' ) {
if ( !um_user('can_access_wpadmin') ) {
exit( wp_redirect( home_url() ) );
} else {
exit( wp_redirect( admin_url() ) );
}
if ( !um_user('can_access_wpadmin') ) {
exit( wp_redirect( home_url() ) );
} else {
exit( wp_redirect( admin_url() ) );
} }
} }
}
} }
/*** /***