| Server IP : 195.130.67.5 / Your IP : 216.73.217.154 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Old Sites/repository/wp-content/plugins/registered-users-only/ |
Upload File : |
<?php /*
**************************************************************************
Plugin Name: Registered Users Only
Plugin URI: https://alex.blog/wordpress-plugins/registered-users-only/
Description: Redirects all non-logged in users to your login form. Make sure to <a href="options-general.php?page=registered-users-only">disable registration</a> if you want your blog truly private.
Version: 1.1.0
Author: Alex Mills (Viper007Bond)
Author URI: https://alex.blog/
Text Domain: registered-users-only
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
**************************************************************************
Copyright (C) 2015-2018 Alex Mills (Viper007Bond)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
**************************************************************************/
class RegisteredUsersOnly {
public $exclusions = array();
// Class initialization
function __construct() {
// Register our hooks
add_action( 'wp', array( $this, 'MaybeRedirect' ) );
add_action( 'init', array( $this, 'LoginFormMessage' ) );
add_action( 'admin_menu', array( $this, 'AddAdminMenu' ) );
if ( isset( $_POST['regusersonly_action'] ) && 'update' == $_POST['regusersonly_action'] ) {
add_action( 'init', array( $this, 'POSTHandle' ) );
}
}
// Register the options page
public function AddAdminMenu() {
add_options_page(
__( 'Registered Users Only Options', 'registered-users-only' ),
__( 'Registered Only', 'registered-users-only' ),
'manage_options',
'registered-users-only',
array( $this, 'OptionsPage' )
);
}
// Depending on conditions, run an authentication check
public function MaybeRedirect() {
// If the user is logged in, then abort
if ( current_user_can( 'read' ) ) {
return;
}
$settings = get_option( 'registered-users-only' );
// Feeds
if ( 1 == $settings['feeds'] && is_feed() ) {
return;
}
// This is a base array of pages that will be EXCLUDED from being blocked
$this->exclusions = array(
'wp-login.php',
'wp-register.php',
'wp-cron.php', // Just incase
'wp-trackback.php',
'wp-app.php',
'xmlrpc.php',
);
// If the current script name is in the exclusion list, abort
if ( in_array(
basename( $_SERVER['PHP_SELF'] ),
apply_filters( 'registered-users-only_exclusions', $this->exclusions )
) ) {
return;
}
// Still here? Okay, then redirect to the login form
auth_redirect();
}
// Use some deprecate code (yeah, I know) to insert a "You must login" error message to the login form
// If this breaks in the future, oh well, it's just a pretty message for users
public function LoginFormMessage() {
// Don't show the error message if anything else is going on (registration, etc.)
if (
'wp-login.php' != basename( $_SERVER['PHP_SELF'] ) ||
! empty( $_POST ) ||
( ! empty( $_GET ) && empty( $_GET['redirect_to'] ) )
) {
return;
}
global $error;
$error = __( 'Only registered and logged in users are allowed to view this site. Please log in now.', 'registered-users-only' );
}
// Update options submitted from the options form
public function POSTHandle() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'Cheatin’ uh?' ) );
}
check_admin_referer( 'registered-users-only' );
$settings = array(
'feeds' => ( ! empty( $_POST['regusersonly_feeds'] ) ) ? 1 : 0,
);
update_option( 'registered-users-only', $settings );
update_option(
'users_can_register',
( ! empty( $_POST['users_can_register'] ) ) ? 1 : 0
);
wp_redirect( add_query_arg( 'updated', 'true' ) );
exit();
}
// Output the configuration page for the plugin
public function OptionsPage() {
$settings = get_option( 'registered-users-only' );
?>
<div class="wrap">
<h2><?php _e( 'Registered Users Only', 'registered-users-only' ); ?></h2>
<form method="post" action="">
<?php wp_nonce_field( 'registered-users-only' ) ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e( 'Membership' ); ?></th>
<td>
<label for="users_can_register">
<input name="users_can_register" type="checkbox" id="users_can_register" value="1"<?php checked( '1', get_option( 'users_can_register' ) ); ?> />
<?php _e( 'Anyone can register' ) ?>
</label><br />
<?php _e( 'This is a default WordPress option placed here for easy changing.', 'registered-users-only' ); ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Guest Access', 'registered-users-only' ); ?></th>
<td>
<label for="regusersonly_feeds">
<input name="regusersonly_feeds" type="checkbox" id="regusersonly_feeds" value="1"<?php checked( '1', $settings['feeds'] ); ?> />
<?php _e( 'Allow access to your post and comment feeds (Warning: this will reveal all post contents to guests!)', 'registered-users-only' ); ?>
</label><br />
</td>
</tr>
</table>
<p class="submit">
<?php submit_button(); ?>
<input type="hidden" name="regusersonly_action" value="update" />
</p>
</form>
</div>
<?php
}
}
function RegisteredUsersOnly() {
global $RegisteredUsersOnly;
$RegisteredUsersOnly = new RegisteredUsersOnly();
}
// Start this plugin once all other plugins are fully loaded
add_action( 'plugins_loaded', 'RegisteredUsersOnly' );