Skip to content

Commit

Permalink
First Release
Browse files Browse the repository at this point in the history
  • Loading branch information
benhuson committed Feb 1, 2012
0 parents commit b264ebb
Show file tree
Hide file tree
Showing 7 changed files with 410 additions and 0 deletions.
100 changes: 100 additions & 0 deletions admin/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

class Password_Protected_Admin {

/**
* Constructor
*/
function Password_Protected_Admin() {
add_action( 'admin_init', array( $this, 'privacy_settings' ) );
add_action( 'admin_notices', array( $this, 'password_protected_admin_notices' ) );
}

/**
* Settings API
*/
function privacy_settings() {
add_settings_section(
'password_protected',
'Password Protected Settings',
array( $this, 'password_protected_settings_section' ),
'privacy'
);
add_settings_field(
'password_protected_status',
'Password Protection Status',
array( $this, 'password_protected_status_field' ),
'privacy',
'password_protected'
);
add_settings_field(
'password_protected_password',
'New Password',
array( $this, 'password_protected_password_field' ),
'privacy',
'password_protected'
);
register_setting( 'privacy', 'password_protected_status', 'intval' );
register_setting( 'privacy', 'password_protected_password', array( $this, 'sanitize_password_protected_password' ) );
}

/**
* Sanitize Password Field Input
*/
function sanitize_password_protected_password( $val ) {
$old_val = get_option( 'password_protected_password' );
if ( empty( $val['new'] ) ) {
return $old_val;
} elseif ( empty( $val['confirm'] ) ) {
add_settings_error( 'password_protected_password', 'password_protected_password', __( 'New password not saved. When setting a new password please enter it in both fields.', 'password_protected' ) );
return $old_val;
} elseif ( $val['new'] != $val['confirm'] ) {
add_settings_error( 'password_protected_password', 'password_protected_password', __( 'New password not saved. Password fields did not match.', 'password_protected' ) );
return $old_val;
} elseif ( $val['new'] == $val['confirm'] ) {
add_settings_error( 'password_protected_password', 'password_protected_password', __( 'New password saved.', 'password_protected' ), 'updated' );
return $val['new'];
}
return get_option( 'password_protected_password' );
}

/**
* Password Protected Section
*/
function password_protected_settings_section() {
echo '<p>' . __( 'Password protect your web site. Users will be asked to enter a password to view the site.', 'password_protected' ) . '</p>';
}

/**
* Password Protection Status Field
*/
function password_protected_status_field() {
echo '<input name="password_protected_status" id="password_protected_status" type="checkbox" value="1" ' . checked( 1, get_option( 'password_protected_status' ), false ) . ' /> ' . __( 'Enabled', 'password_protected' );
}

/**
* Password Field
*/
function password_protected_password_field() {
echo '<input type="password" name="password_protected_password[new]" id="password_protected_password_new" size="16" value="" autocomplete="off"> <span class="description">' . __( 'If you would like to change the password type a new one. Otherwise leave this blank.', 'password_protected' ) . '</span><br>
<input type="password" name="password_protected_password[confirm]" id="password_protected_password_confirm" size="16" value="" autocomplete="off"> <span class="description">' . __( 'Type your new password again.', 'password_protected' ) . '</span>';
}

/**
* 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 '<div class="error"><p>' . __( 'You have enabled password protection but not yet set a password. Please set one below.', 'password_protected' ) . '</p></div>';
}
}
}

}

?>
Binary file added assets/banner-772x250.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 136 additions & 0 deletions password-protected.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

/*
Plugin Name: Password Protected
Plugin URI: http://www.benhuson.co.uk/
A very simple way to quickly password protect your WordPress site with a single password. Integrates seamlessly into your WordPress privacy settings.
Version: 1.0
Author: Ben Huson
Author URI: http://www.benhuson.co.uk/
License: GPLv2
*/

/*
Copyright 2012 Ben Huson (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// Start session if not already started...
if ( session_id() == '' )
session_start();

// Setup Password Protected
global $Password_Protected;
$Password_Protected = new Password_Protected();

class Password_Protected {

var $admin = null;
var $errors = null;

/**
* Constructor
*/
function Password_Protected() {
$this->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 <a href="'. get_bloginfo( 'url' ) .'">website</a>.' ) );
}

/**
* 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 );
}

}

?>
38 changes: 38 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -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
Binary file added screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b264ebb

Please sign in to comment.