Password Protected Status Turn on/off password protection.
', 'password-protected' )
. __( '
Protected Permissions Allow access for logged in users and administrators without needing to enter a password. You will need to enable this option if you want administrators to be able to preview the site in the Theme Customizer. Also allow RSS Feeds to be accessed when the site is password protected.
', 'password-protected' )
. __( '
Password Fields To set a new password, enter it into both fields. You cannot set an `empty` password. To disable password protection uncheck the Enabled checkbox.
';
}
/**
* Password Protection Permissions Field
*/
public function password_protected_permissions_field() {
echo '
';
}
/**
* Password Field
*/
public 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' ) . '
';
}
/**
* Allowed IP Addresses Field
*/
public function password_protected_allowed_ip_addresses_field() {
echo '' . esc_html( get_option( 'password_protected_allowed_ip_addresses' ) ) . '';
echo '
' . esc_html__( 'Enter one IP address per line.', 'password-protected' );
if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
echo ' ' . esc_html( sprintf( __( 'Your IP address is %s.', 'password-protected' ), $_SERVER['REMOTE_ADDR'] ) );
}
echo '
';
}
/**
* Remember Me Field
*/
public function password_protected_remember_me_field() {
echo '
';
}
/**
* Remember Me lifetime field
*/
public function password_protected_remember_me_lifetime_field() {
echo '';
}
/**
* Password Protected Page description
*/
public function password_protected_page_description() {
return 1;
}
/**
* Password Protected text above passsword
*/
public function password_protected_text_above_password() {
echo '';
}
/**
* Password Protected below above passsword
*/
public function password_protected_text_below_password() {
echo '';
}
public function password_protected_use_transient() {
$use_transient = get_option( 'password_protected_use_transient', false );
$checked = empty( $use_transient ) ? '' : 'checked="checked"';
echo ' ' . esc_attr__( 'This option will save your passwords in transients for your IP instead of cookies. Only use it if you face any cache-related issues on your site.', 'password-protected' ) . '';
}
/**
* Help Tab text field
*/
public function password_protected_help_tab() {
echo '
'
. __( 'Password protect your web site. Users will be asked to enter a password to view the site.', 'password-protected' )
. ' '
. __( 'For more information about Password Protected settings, view the "Help" tab at the top of this page.', 'password-protected' )
. '
';
}
/**
* Try pro sideabr
*/
public function password_protected_try_pro() {
$image_url = PASSWORD_PROTECTED_URL . 'assets/images/';
echo '
Level up your WordPress protection with
Password Protected Pro
Protect Specific Post Types
Whitelist Specific User Role
Password Protect WP-Admin
Password Attempt Activity Report
Specific Post/Page Protection
Certain Page/Posts Exclusions
Password Attempts Restriction
Password Expiration and Usage Limit
Bypass URL (Post, Page, Category, etc.)
Activity Log For Each Password Attempt
Multiple Password Management
';
}
/**
* Pre-update 'password_protected_password' Option
*
* Before the password is saved, MD5 it!
* Doing it in this way allows developers to intercept with an earlier filter if they
* need to do something with the plaintext password.
*
* @param string $newvalue New Value.
* @param string $oldvalue Old Value.
* @return string Filtered new value.
*/
public function pre_update_option_password_protected_password( $newvalue, $oldvalue ) {
global $Password_Protected;
if ( $newvalue != $oldvalue ) {
$newvalue = $Password_Protected->encrypt_password( $newvalue );
}
return $newvalue;
}
/**
* Plugin Row Meta
*
* Adds GitHub and translate links below the plugin description on the plugins page.
*
* @param array $plugin_meta Plugin meta display array.
* @param string $plugin_file Plugin reference.
* @param array $plugin_data Plugin data.
* @param string $status Plugin status.
* @return array Plugin meta array.
*/
public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
if ( 'password-protected/password-protected.php' == $plugin_file ) {
$plugin_meta[] = sprintf( '%s', __( 'http://github.com/benhuson/password-protected', 'password-protected' ), __( 'GitHub', 'password-protected' ) );
$plugin_meta[] = sprintf( '%s', __( 'https://translate.wordpress.org/projects/wp-plugins/password-protected', 'password-protected' ), __( 'Translate', 'password-protected' ) );
}
return $plugin_meta;
}
/**
* Plugin Action Links
*
* Adds settings link on the plugins page.
*
* @param array $actions Plugin action links array.
* @return array Plugin action links array.
*/
public function plugin_action_links( $actions ) {
$actions[] = sprintf( '%s', admin_url( 'admin.php?page=password-protected' ), __( 'Settings', 'password-protected' ) );
return $actions;
}
/**
* Password Admin Notice
* Warns the user if they have enabled password protection but not entered a password
*/
public function password_protected_admin_notices() {
global $Password_Protected;
// Check Support
$screens = $this->plugin_screen_ids( array( 'dashboard', 'plugins' ) );
if ( $this->is_current_screen( $screens ) ) {
$supported = $Password_Protected->is_plugin_supported();
if ( is_wp_error( $supported ) ) {
echo $this->admin_error_display( $supported->get_error_message( $supported->get_error_code() ) );
}
}
// Settings
if ( $this->is_current_screen( $this->plugin_screen_ids() ) ) {
$status = get_option( 'password_protected_status' );
$pwd = get_option( 'password_protected_password' );
if ( (bool) $status && empty( $pwd ) ) {
$error_message = __( 'You have enabled password protection but not yet set a password. Please set one below.', 'password-protected' );
$error = apply_filters( 'password_protected_password_status_activation', $error_message );
if( !empty( $error ) ) {
echo $this->admin_error_display( $error );
}
}
if ( current_user_can( 'manage_options' ) && ( (bool) get_option( 'password_protected_administrators' ) || (bool) get_option( 'password_protected_users' ) ) ) {
if ( (bool) get_option( 'password_protected_administrators' ) && (bool) get_option( 'password_protected_users' ) ) {
echo $this->admin_error_display( __( 'You have enabled password protection and allowed administrators and logged in users - other users will still need to enter a password to view the site.', 'password-protected' ) );
} elseif ( (bool) get_option( 'password_protected_administrators' ) ) {
if ( (bool) get_option( 'password_protected_status' ) ) {
echo $this->admin_error_display( __( 'You have enabled password protection and allowed administrators - other users will still need to enter a password to view the site.', 'password-protected' ) );
}
} elseif ( (bool) get_option( 'password_protected_users' ) ) {
if ( (bool) get_option( 'password_protected_status' ) ) {
echo $this->admin_error_display( __( 'You have enabled password protection and allowed logged in users - other users will still need to enter a password to view the site.', 'password-protected' ) );
}
}
}
}
}
/**
* Admin Error Display
*
* Returns a string wrapped in HTML to display an admin error.
*
* @param string $string Error string.
* @return string HTML error.
*/
private function admin_error_display( $string ) {
return '
' . $string . '
';
}
/**
* Is Current Screen
*
* Checks wether the admin is displaying a specific screen.
*
* @param string|array $screen_id Admin screen ID(s).
* @return boolean
*/
public function is_current_screen( $screen_id ) {
if ( function_exists( 'get_current_screen' ) ) {
$current_screen = get_current_screen();
if ( ! is_array( $screen_id ) ) {
$screen_id = array( $screen_id );
}
if ( in_array( $current_screen->id, $screen_id ) ) {
return true;
}
}
return false;
}
/**
* Plugin Screen IDs
*
* @param string|array $screen_id Additional screen IDs to add to the returned array.
* @return array Screen IDs.
*/
public function plugin_screen_ids( $screen_id = '' ) {
$screen_ids = array( 'options-' . $this->options_group, 'settings_page_' . $this->options_group );
array_push( $screen_ids, 'toplevel_page_'.$this->options_group );
if ( ! empty( $screen_id ) ) {
if ( is_array( $screen_id ) ) {
$screen_ids = array_merge( $screen_ids, $screen_id );
} else {
$screen_ids[] = $screen_id;
}
}
// toplevel_page_password-protected
return $screen_ids;
}
/**
* @return bool
* true if password protected pro is installed and activated otherwise false
*/
public function password_protected_pro_is_installed_and_activated(): bool {
return class_exists( 'Password_Protected_Pro' );
}
/**
* @return void
* Display Pro Features
*/
public function password_protected_get_pro_features() {
$image_url = PASSWORD_PROTECTED_URL . 'assets/images/';
echo '