diff --git a/admin/admin.php b/admin/admin.php new file mode 100644 index 0000000..23236d2 --- /dev/null +++ b/admin/admin.php @@ -0,0 +1,100 @@ +' . __( 'Password protect your web site. Users will be asked to enter a password to view the site.', 'password_protected' ) . '

'; + } + + /** + * Password Protection Status Field + */ + function password_protected_status_field() { + echo ' ' . __( 'Enabled', 'password_protected' ); + } + + /** + * Password Field + */ + function password_protected_password_field() { + echo ' ' . __( 'If you would like to change the password type a new one. Otherwise leave this blank.', 'password_protected' ) . '
+ ' . __( 'Type your new password again.', 'password_protected' ) . ''; + } + + /** + * Password Admin Notice + * Warns the user if they have enabled password protection but not entered a password + */ + function password_protected_admin_notices(){ + global $current_screen; + if ( $current_screen->id == 'options-privacy' ) { + $status = get_option( 'password_protected_status' ); + $pwd = get_option( 'password_protected_password' ); + if ( (bool) $status && empty( $pwd ) ) { + echo '

' . __( 'You have enabled password protection but not yet set a password. Please set one below.', 'password_protected' ) . '

'; + } + } + } + +} + +?> \ No newline at end of file diff --git a/assets/banner-772x250.png b/assets/banner-772x250.png new file mode 100644 index 0000000..70db043 Binary files /dev/null and b/assets/banner-772x250.png differ diff --git a/password-protected.php b/password-protected.php new file mode 100644 index 0000000..02082f7 --- /dev/null +++ b/password-protected.php @@ -0,0 +1,136 @@ +errors = new WP_Error(); + add_action( 'init', array( $this, 'maybe_process_login' ), 1 ); + add_action( 'template_redirect', array( $this, 'maybe_show_login' ), 1 ); + $this->disable_feeds(); + if ( is_admin() ) { + include_once( dirname( __FILE__ ) . '/admin/admin.php' ); + $this->admin = new Password_Protected_Admin(); + } + } + + /** + * Is Active? + */ + function is_active() { + if ( (bool) get_option( 'password_protected_status' ) ) + return true; + return false; + } + + /** + * Disable Feeds + */ + function disable_feeds() { + add_action( 'do_feed', array( $this, 'disable_feed' ), 1 ); + add_action( 'do_feed_rdf', array( $this, 'disable_feed' ), 1 ); + add_action( 'do_feed_rss', array( $this, 'disable_feed' ), 1 ); + add_action( 'do_feed_rss2', array( $this, 'disable_feed' ), 1 ); + add_action( 'do_feed_atom', array( $this, 'disable_feed' ), 1 ); + } + + /** + * Disable Feed + * @todo Make Translatable + */ + function disable_feed() { + wp_die( __( 'Feeds are not available for this site. Please visit the website.' ) ); + } + + /** + * Maybe Process Login + */ + function maybe_process_login() { + if ( $this->is_active() && isset( $_REQUEST['password_protected_pwd'] ) ) { + $password_protected_pwd = $_REQUEST['password_protected_pwd']; + $pwd = get_option( 'password_protected_password' ); + // If correct password... + if ( $password_protected_pwd == $pwd && $pwd != '' ) { + $_SESSION[$this->get_site_id() . '_password_protected_auth'] = 1; + } else { + // ... otherwise incorrect password + $this->errors->add( 'incorrect_password', 'Incorrect Password' ); + } + } + + // Log out + if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'logout' ) { + $_SESSION[$this->get_site_id() . '_password_protected_auth'] = 0; + $this->errors = new WP_Error(); + $this->errors->add( 'logged_out', __( 'You are now logged out.' ), 'message' ); + } + } + + /** + * Maybe Show Login + */ + function maybe_show_login() { + // Don't show login if not enabled + if ( ! $this->is_active() ) + return; + + // Logged in + if ( isset( $_SESSION[$this->get_site_id() . '_password_protected_auth'] ) && $_SESSION[$this->get_site_id() . '_password_protected_auth'] == 1 ) + return; + + // Show login form + include( dirname( __FILE__ ) . '/theme/login.php' ); + exit(); + } + + /** + * Get Site ID + */ + function get_site_id() { + global $blog_id; + return apply_filters( 'password_protected_blog_id', $blog_id ); + } + +} + +?> \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..56a0aa7 --- /dev/null +++ b/readme.txt @@ -0,0 +1,38 @@ +=== Password Protected === +Contributors: husobj +Donate link: http://www.benhuson.co.uk/donate/ +Tags: password, protect, password protect, login +Requires at least: 3.0 +Tested up to: 3.3.1 +Stable tag: 1.0 + +A very simple way to quickly password protect your WordPress site with a single password. Integrates seamlessly into your WordPress privacy settings. + +== Description == + +A very simple way to quickly password protect your WordPress site with a single password. Integrates seamlessly into your WordPress privacy settings. + +Features include: + +* Password protect your WordPress site with a single password. +* Integrates seamlessly into your WordPress privacy settings. +* Works with Mark Jaquith's [Login Logo](http://wordpress.org/extend/plugins/login-logo/) plugin. + +== Installation == + +To install and configure this plugin... + +1. Upload or install the plugin through your WordPress admin. +2. Activate the plugin via the 'Plugins' admin menu. +3. Configuration the password in your WordPress Privacy settings. + +== Screenshots == + +1. Login page perfectly mimicks the WordPress login. +2. Integrates seamlessly into your WordPress privacy settings. + +== Changelog == + += 1.0 = + +* First Release \ No newline at end of file diff --git a/screenshot-1.png b/screenshot-1.png new file mode 100644 index 0000000..8611083 Binary files /dev/null and b/screenshot-1.png differ diff --git a/screenshot-2.png b/screenshot-2.png new file mode 100644 index 0000000..0de7ef5 Binary files /dev/null and b/screenshot-2.png differ diff --git a/theme/login.php b/theme/login.php new file mode 100644 index 0000000..fc6c69a --- /dev/null +++ b/theme/login.php @@ -0,0 +1,136 @@ + + + errors->add( 'test_cookie', __( "ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress." ) ); + +// Shake it! +$shake_error_codes = array( 'empty_password', 'incorrect_password' ); +if ( $Password_Protected->errors->get_error_code() && in_array( $Password_Protected->errors->get_error_code(), $shake_error_codes ) ) + add_action( 'password_protected_login_head', 'wp_shake_js', 12 ); + +// Add support for Mark Jaquith's Login Logo plugin +// http://wordpress.org/extend/plugins/login-logo/ +if ( class_exists( 'CWS_Login_Logo_Plugin' ) ) + add_action( 'password_protected_login_head', array( new CWS_Login_Logo_Plugin, 'login_head' ) ); + +?> + +> + + + +<?php echo apply_filters( 'password_protected_wp_title', get_bloginfo( 'name' ) ); ?> + + + + + + + + + +
+

+ errors->get_error_code() ) { + $errors = ''; + $messages = ''; + foreach ( $Password_Protected->errors->get_error_codes() as $code ) { + $severity = $Password_Protected->errors->get_error_data( $code ); + foreach ( $Password_Protected->errors->get_error_messages( $code ) as $error ) { + if ( 'message' == $severity ) + $messages .= ' ' . $error . "
\n"; + else + $errors .= ' ' . $error . "
\n"; + } + } + if ( ! empty( $errors ) ) + echo '
' . apply_filters( 'password_protected_login_errors', $errors ) . "
\n"; + if ( ! empty( $messages ) ) + echo '

' . apply_filters( 'password_protected_login_messages', $messages ) . "

\n"; + } + ?> + +
+

+ +

+ +

+ + +

+
+ +
+ + + + + +
+ + + \ No newline at end of file