Created
January 26, 2015 12:55
-
-
Save coquer/b090b54765e92ad073f3 to your computer and use it in GitHub Desktop.
WP-protect site with pass
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 | |
/* | |
Plugin Name: Admin Only Sections | |
Plugin URI: http://jorgerodriguez.dk/ | |
Description: Block non admin users | |
Version: 1.0.3 | |
Author: Jorge Rodriguez (jycr753) | |
Author URI: http://jorgerodriguez.dk/ | |
*/ | |
$wpba_required_capability = 'edit_others_posts'; | |
$wpba_redirect_to = ''; | |
if (defined('WPBA_REQUIRED_CAPABILITY')) | |
$wpba_required_capability = WPBA_REQUIRED_CAPABILITY; | |
if (defined('WPBA_REDIRECT_TO')) | |
$wpba_redirect_to = WPBA_REDIRECT_TO; | |
if (!function_exists('wpba_init')) { | |
function wpba_init() { | |
global $wpba_required_capability, $wpba_redirect_to; | |
if (stripos($_SERVER['REQUEST_URI'],'/wp-admin/') !== false && stripos($_SERVER['REQUEST_URI'],'async-upload.php') == false && stripos($_SERVER['REQUEST_URI'],'admin-ajax.php') == false){ | |
if (!current_user_can($wpba_required_capability)) { | |
if ($wpba_redirect_to == '') { $wpba_redirect_to = get_option('home'); } | |
// die("eeror"); | |
wp_redirect(home_url()); exit; | |
} | |
} | |
} | |
} | |
add_action('init','wpba_init',0); | |
add_action( 'parse_request', 'dmk_redirect_to_login_if_not_logged_in', 1 ); | |
function dmk_redirect_to_login_if_not_logged_in() { | |
is_user_logged_in() || auth_redirect(); | |
} | |
add_filter( 'login_url', 'dmk_strip_loggedout', 1, 1 ); | |
function dmk_strip_loggedout( $login_url ) { | |
return str_replace( '%3Floggedout%3Dtrue', '', $login_url ); | |
} | |
show_admin_bar(false); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment