This commit is contained in:
2026-04-26 23:47:49 +02:00
parent 1b95f03d1e
commit b073e009d8
5288 changed files with 1112699 additions and 55536 deletions

View File

@@ -0,0 +1,67 @@
<?php
class PPW_Beaver_Loader {
/**
* Instance of PPW_Beaver_Loader class.
*
* @var PPW_Beaver_Loader
*/
protected static $instance = null;
/**
* PPW_Beaver_Loader constructor.
*/
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'setup_hooks' ) );
}
/**
* Setup hooks.
*/
public function setup_hooks() {
if ( ! class_exists( 'FLBuilder' ) ) {
return;
}
add_filter( 'fl_builder_custom_fields', array( $this, 'register_fields' ) );
// Load custom modules.
add_action( 'init', array( $this, 'load_modules' ) );
}
/**
* Get instance
*
* @return PPW_Beaver_Loader
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
// Use static instead of self due to the inheritance later.
// For example: ChildSC extends this class, when we call get_instance
// it will return the object of child class. On the other hand, self function
// will return the object of base class.
self::$instance = new static();
}
return self::$instance;
}
/**
* Load modules
*/
public function load_modules() {
require_once __DIR__ . '/modules/ppw-individual-page/class-ppw-module.php';
}
/**
* Register custom fields.
*
* @param array $fields Fields.
*
* @return array Fields.
*/
public function register_fields( $fields ) {
$fields['input-number'] = PPW_DIR_PATH . 'includes/addons/beaver-builder/fields/input-number.php';
return $fields;
}
}

View File

@@ -0,0 +1,10 @@
<div class="fl-compound-field-setting fl-animation-field-delay" style="width: 40%">
<div class="fl-unit-field-inputs">
<div class="fl-unit-field-input">
<input type="number" name="{{data.name}}" value="{{data.value}}" oninput="(validity.valid)||(value='');" step="1" min="1"/>
</div>
<div class="fl-unit-field-input fl-unit-field-unit-select">
<div class="fl-field-unit-select">hour(s)</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,121 @@
<?php
class PPWBB_Shortcode_Module extends FLBuilderModule {
/**
* PPWBB_Individual_Content_Module constructor.
*/
public function __construct() {
parent::__construct(
array(
'name' => __( 'Password Protect WordPress (PPWP)', 'password-protect-page' ),
'description' => __( 'Password protected content', 'password-protect-page' ),
'category' => __( 'Partial Content Protection', 'password-protect-page' ),
'dir' => PPW_DIR_PATH . 'includes/addons/beaver-builder/modules/ppw-individual-page/',
'url' => PPW_DIR_URL . 'includes/addons/beaver-builder/modules/ppw-individual-page/',
'icon' => 'editor-code.svg'
)
);
}
}
function ppwbb_load_individual_content_module() {
$raw_roles = apply_filters(
'ppw_supported_white_list_roles',
array(
'administrator',
'editor',
'author',
'contributor',
'subscriber',
)
);
$role_options = array_reduce(
$raw_roles,
function ( $carry, $value ) {
$carry[ $value ] = __( $value, 'password-protect-page' );
return $carry;
},
array()
);
$general_fields = array(
'ppwp_passwords' => array(
'type' => 'text',
'label' => __( 'Passwords', 'password-protect-page' ),
'placeholder' => __( 'Enter your password, e.g. password1 password2', 'password-protect-page' ),
'description' => 'Multiple passwords are separated by space, case-sensitivity, no more than 100 characters and dont contain [, ], “, ',
'default' => 'password1 password2',
),
'ppwp_whitelisted_roles' => array(
'type' => 'select',
'label' => __( 'Whitelisted Roles', 'password-protect-page' ),
'description' => 'Select user roles who can access protected area without having to enter passwords',
'options' => $role_options,
'multi-select' => true,
),
'ppwp_protected_content' => array(
'type' => 'editor',
'label' => __( 'Protected Content', 'password-protect-page' ),
'default' => __( 'This is your protected content.', 'password-protect-page' ),
'rows' => '6',
),
);
$general_fields = apply_filters( PPW_Constants::HOOK_SHORTCODE_BEAVER_BUILDER_GENERAL_FIELDS, $general_fields );
$instruction_fields = array(
'ppwp_headline' => array(
'type' => 'text',
'label' => __( 'Headline', 'password-protect-page' ),
'default' => __( PPW_Constants::DEFAULT_SHORTCODE_HEADLINE, 'password-protect-page' ),
),
'ppwp_placeholder' => array(
'type' => 'text',
'label' => __( 'Placeholder', 'password-protect-page' ),
'default' => __( '', 'password-protect-page' ),
),
'ppwp_button' => array(
'type' => 'text',
'label' => __( 'Button', 'password-protect-page' ),
'default' => __( PPW_Constants::DEFAULT_SHORTCODE_BUTTON, 'password-protect-page' ),
),
'ppwp_description' => array(
'type' => 'editor',
'label' => __( 'Description', 'password-protect-page' ),
'default' => __( PPW_Constants::DEFAULT_SHORTCODE_DESCRIPTION, 'password-protect-page' ),
'rows' => '6',
),
);
$instruction_fields = apply_filters( PPW_Constants::HOOK_SHORTCODE_BEAVER_BUILDER_INSTRUCTION_FIELDS, $instruction_fields );
$form = array(
'general' =>
array(
'title' => __( 'Shortcode', 'password-protect-page' ),
'sections' => array(
'general' => array(
'title' => __( 'Protection', 'password-protect-page' ),
'fields' => $general_fields,
),
'instruction' => array(
'title' => __( 'Password Form', 'password-protect-page' ),
'fields' => $instruction_fields,
),
),
),
);
$form = apply_filters( PPW_Constants::HOOK_SHORTCODE_BEAVER_BUILDER_FIELDS, $form );
FLBuilder::register_module(
'PPWBB_Shortcode_Module',
$form
);
}
ppwbb_load_individual_content_module();

View File

@@ -0,0 +1,8 @@
#fl-field-ppwp_passwords .fl-field-description, #fl-field-ppwp_whitelisted_roles .fl-field-description {
background: #f0f0f0;
color: #333 !important;
display: block;
float: none;
margin: 10px 0 0 0;
padding: 10px;
}

View File

@@ -0,0 +1,39 @@
<?php
$shortcode = '[ppwp passwords="' . $settings->ppwp_passwords . '"';
if ( ! empty( $settings->ppwp_headline ) ) {
$shortcode .= ' headline="' . esc_html__($settings->ppwp_headline) . '"';
}
if ( ! empty( $settings->ppwp_description ) ) {
$shortcode .= ' description="' . esc_html__( $settings->ppwp_description ) . '"';
}
if ( ! empty( $settings->ppwp_placeholder ) ) {
$shortcode .= ' placeholder="' . esc_html__( $settings->ppwp_placeholder ) . '"';
}
if ( ! empty( $settings->ppwp_button ) ) {
$shortcode .= ' button="' . esc_html__( $settings->ppwp_button ) . '"';
}
if ( ! empty( $settings->ppwp_cookie ) ) {
$shortcode .= ' cookie="' . absint( $settings->ppwp_cookie ) . '"';
}
if ( ! empty( $settings->ppwp_download_limit ) ) {
$shortcode .= ' download_limit="' . absint( $settings->ppwp_download_limit ) . '"';
}
if ( is_array( $settings->ppwp_whitelisted_roles ) && count( $settings->ppwp_whitelisted_roles ) > 0 ) {
$whitelisted_roles = implode( ',', $settings->ppwp_whitelisted_roles );
$shortcode .= ' whitelisted_roles="' . $whitelisted_roles . '"';
}
$shortcode = apply_filters( PPW_Constants::HOOK_SHORTCODE_BEAVER_BUILDER_ATTRIBUTES, $shortcode, $settings );
$shortcode .= ']';
echo '<div class="description">' . $shortcode . $settings->ppwp_protected_content . '[/ppwp]' . '</div>'; // phpcs:ignores -- we already escape inside the $shortcode.

View File

@@ -0,0 +1,87 @@
<?php
if ( ! class_exists( 'PPW_Elementor' ) ) {
class PPW_Elementor {
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @access protected
* @var PPW_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* Minimum elementor version.
*
* @var PPW_Elementor
*/
private static $instance;
const MINIMUM_ELEMENTOR_VERSION = '2.0.0';
const MINIMUM_PPW_FREE_VERSION = '1.2.3.3';
/**
* Get instance.
*
* @param PPW_Loader $loader Maintains and registers all hooks for the plugin.
*
* @return PPW_Elementor
*/
public static function get_instance( $loader ) {
if ( null === self::$instance ) {
self::$instance = new self( $loader );
}
return self::$instance;
}
/**
* Constructor.
*
* @param PPW_Loader $loader Maintains and registers all hooks for the plugin.
*
* PPW_Elementor constructor.
*/
public function __construct( $loader ) {
$this->loader = $loader;
$this->init();
}
/**
* Register Elementor hooks.
*/
public function init() {
if ( ! did_action( 'elementor/loaded' ) ) {
return;
}
if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) || ! version_compare( PPW_VERSION, self::MINIMUM_PPW_FREE_VERSION, '>=' ) ) {
return;
}
$this->loader->add_action( 'elementor/widgets/widgets_registered', $this, 'register_widgets' );
}
/**
* Register widgets.
*/
public function register_widgets() {
$supported_pro_version = array( '1.1.5', '1.1.5.1' );
if ( defined( 'PPW_PRO_VERSION' ) && in_array( PPW_PRO_VERSION, $supported_pro_version, true ) && is_pro_active_and_valid_license() ) {
return;
}
// Include widget files.
require_once __DIR__ . '/widgets/class-ppw-elementor-widget-shortcode.php';
require_once __DIR__ . '/widgets/class-ppw-elementor-advance-widget-shortcode.php';
// Register widget.
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new PPW_Shortcode_Widget() );
// Handle hooks from origin widget to add more features.
$advance_widget = new PPW_Shortcode_Advance_Widget();
$advance_widget->init();
}
}
}

View File

@@ -0,0 +1,52 @@
<?php
use Elementor\Plugin;
if ( ! class_exists( 'PPW_Shortcode_Advance_Widget' ) ) {
/**
* Advance Elementor ShortCode Widget
*
* @since 1.4.5
*
* Class PPW_Shortcode_Advance_Widget
*/
class PPW_Shortcode_Advance_Widget {
/**
* Register hooks.
*/
public function init() {
add_filter( PPW_Constants::HOOK_SHORTCODE_ELEMENTOR_CONTENT, array( $this, 'handle_elementor_show_content_option' ), 10, 2 );
}
/**
* Handle elementor content with the new attribute "Show Content"
*
* @param string $content The current content.
* @param array $settings The setting array includes:
* string ppwp_protected_content.
*
* @return string
*/
public function handle_elementor_show_content_option( $content, $settings ) {
if ( ! $this->is_show_content_enabled( $settings ) ) {
return $content;
}
return apply_filters( PPW_Constants::HOOK_SHORTCODE_ELEMENTOR_PREVIEW_CONTENT, $settings['ppwp_protected_content'], $content, $settings );
}
/**
* Check whether the ppwp_show_content option is enabled.
*
* @param array $settings The Elementor widget settings (refer to handle_elementor_show_content_option function).
*
* @return bool True if the value equals to 'yes'.
*/
private function is_show_content_enabled( $settings ) {
if ( ! Plugin::$instance->editor->is_edit_mode() ) {
return false;
}
return isset( $settings['ppwp_show_content'] ) && 'yes' === $settings['ppwp_show_content'];
}
}
}

View File

@@ -0,0 +1,319 @@
<?php
if ( ! class_exists( 'PPW_Shortcode_Widget' ) ) {
class PPW_Shortcode_Widget extends \Elementor\Widget_Base {
/**
* Get element name.
*
* Retrieve the element name.
*
* @return string The name.
* @since 1.4.0
* @access public
*/
public function get_name() {
return 'ppwp';
}
/**
* Get skin title.
*
* Retrieve the skin title.
*
* @since 1.0.0
* @access public
* @abstract
*/
public function get_title() {
return __( 'Password Protection (PPWP)', 'password-protect-page' );
}
/**
* Get widget icon.
*
* Retrieve the widget icon.
*
* @return string Widget icon.
* @since 1.0.0
* @access public
*/
public function get_icon() {
return 'fas fa-shield-alt';
}
/**
* Get widget categories.
*
* Retrieve the widget categories.
*
* @return array Widget categories.
* @since 1.0.10
* @access public
*/
public function get_categories() {
return array( 'general' );
}
/**
* Add Controls to Widgets
*/
protected function _register_controls() { //phpcs:ignore -- this is not our function
$is_gold_activate = defined( 'PDA_GOLD_V3_VERSION' );
$is_ppwp_pro_activate = is_pro_active_and_valid_license();
$roles = array();
$raw_roles = apply_filters(
'ppw_supported_white_list_roles',
array(
'administrator',
'editor',
'author',
'contributor',
'subscriber',
)
);
foreach ( $raw_roles as $value ) {
$roles[ $value ] = $value;
}
$this->start_controls_section(
'ppwp_section',
array(
'label' => __( 'PPWP Shortcode', 'password-protect-page' ),
)
);
$controls = array(
array(
'key' => 'ppwp_protect_options',
'value' => array(
'label' => __( 'Partial Content Protection', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::HEADING,
'separator' => 'before',
),
),
array(
'key' => 'ppwp_passwords',
'value' => array(
'label' => __( 'Passwords', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::TEXT,
'placeholder' => __( 'Enter your password, e.g. password1 password2', 'password-protect-page' ),
'default' => 'password1 password2',
'description' => 'Multiple passwords are separated by space, case-sensitivity, no more than 100 characters and dont contain [, ], “, ',
'label_block' => true,
),
),
array(
'key' => 'ppwp_whitelisted_roles',
'value' => array(
'label' => __( 'Whitelisted Roles', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::SELECT2,
'placeholder' => __( 'Select whitelisted roles', 'password-protect-page' ),
'multiple' => true,
'options' => $roles,
'description' => 'Select user roles who can access protected area without having to enter passwords',
'label_block' => true,
),
),
array(
'key' => 'ppwp_protected_content_headline',
'value' => array(
'label' => __( 'Protected Content', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::HEADING,
'separator' => 'before',
),
),
array(
'key' => 'ppwp_protected_content',
'value' => array(
'type' => \Elementor\Controls_Manager::WYSIWYG,
'default' => __( 'This is your protected content.', 'password-protect-page' ),
),
),
array(
'key' => 'ppwp_show_content',
'value' => array(
'label' => __( 'Show Content', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::SWITCHER,
'default' => 'no',
'label_on' => __( 'Show', 'essential-addons-elementor' ),
'label_off' => __( 'Hide', 'essential-addons-elementor' ),
'return_value' => 'yes',
'description' => 'You can force show content in order to style them properly.',
),
),
array(
'key' => 'ppwp_protect_instruction',
'value' => array(
'label' => __( 'Password Form', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::HEADING,
'separator' => 'before',
),
),
array(
'key' => 'ppwp_headline',
'value' => array(
'label' => __( 'Headline', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => 'Restricted Content',
'label_block' => true,
),
),
array(
'key' => 'ppwp_label',
'value' => array(
'label' => __( 'Label', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => PPW_Constants::DEFAULT_SHORTCODE_LABEL,
'label_block' => true,
),
),
array(
'key' => 'ppwp_description',
'value' => array(
'label' => __( 'Description', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::WYSIWYG,
'default' => 'To view this protected content, enter the password below:',
'label_block' => true,
),
),
array(
'key' => 'ppwp_placeholder',
'value' => array(
'label' => __( 'Placeholder', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => '',
'label_block' => true,
),
),
array(
'key' => 'ppwp_loading',
'value' => array(
'label' => __( 'Loading', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => PPW_Constants::DEFAULT_SHORTCODE_LOADING,
'label_block' => true,
),
),
array(
'key' => 'ppwp_button',
'value' => array(
'label' => __( 'Button', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => 'Enter',
'label_block' => true,
),
),
array(
'key' => 'ppwp_error_msg',
'value' => array(
'label' => __( 'Error message', 'password-protect-page' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG,
'label_block' => true,
),
),
);
$controls = apply_filters( PPW_Constants::HOOK_SHORTCODE_ELEMENTOR_CONTROLS, $controls );
foreach ( $controls as $control ) {
if ( ! isset( $control['is_hide'] ) || true !== $control['is_hide'] ) {
$this->add_control( $control['key'], $control['value'] );
}
}
$this->end_controls_section();
}
/**
* Render content.
*/
protected function render() {
$shortcode = do_shortcode( $this->generate_shortcode() );
?>
<div class="elementor-shortcode"><?php echo $shortcode; // phpcs:ignores -- we already escape inside the $shortcode.?></div>
<?php
}
/**
* Render shortcode widget as plain content.
*
* Override the default behavior by printing the shortcode instead of rendering it.
*
* @since 1.0.0
* @access public
*/
public function render_plain_content() {
// In plain mode, render without shortcode.
echo $this->generate_shortcode(); // phpcs:ignores -- we already escape inside the $shortcode.
}
/**
* Generate PPWP shortcode.
*
* @return string PPWP Shortcode
*/
public function generate_shortcode() {
$settings = $this->get_settings_for_display();
$content = apply_filters( PPW_Constants::HOOK_SHORTCODE_ELEMENTOR_CONTENT, '', $settings );
if ( ! empty( $content ) ) {
return $content;
}
$passwords = isset( $settings['ppwp_passwords'] ) ? $settings['ppwp_passwords'] : '';
$whitelisted_roles = $this->transform_whitelisted_roles_to_string( $settings );
$download_limit = isset( $settings['ppwp_download_limit'] ) ? $settings['ppwp_download_limit'] : '';
$cookie = isset( $settings['ppwp_cookie'] ) ? $settings['ppwp_cookie'] : '';
$headline = isset( $settings['ppwp_headline'] ) ? $settings['ppwp_headline'] : '';
$description = isset( $settings['ppwp_description'] ) ? $settings['ppwp_description'] : '';
$label = isset( $settings['ppwp_label'] ) ? $settings['ppwp_label'] : '';
$placeholder = isset( $settings['ppwp_placeholder'] ) ? $settings['ppwp_placeholder'] : '';
$button = isset( $settings['ppwp_button'] ) ? $settings['ppwp_button'] : '';
$error_msg = isset( $settings['ppwp_error_msg'] ) ? $settings['ppwp_error_msg'] : '';
$loading = isset( $settings['ppwp_loading'] ) ? $settings['ppwp_loading'] : '';
$shortcode = sprintf(
'[ppwp id="" class="" passwords="%1$s" cookie="%2$s" download_limit="%3$s" whitelisted_roles="%4$s" headline="%5$s" description="%6$s" placeholder="%7$s" button="%8$s" label="%9$s" error_msg="%10$s" loading="%11$s"',
$passwords,
$cookie,
$download_limit,
$whitelisted_roles,
esc_html__( $headline ),
esc_html__( $description ),
esc_html__( $placeholder ),
esc_html__( $button ),
esc_html__( $label ),
esc_html__( $error_msg ),
esc_html__( $loading )
);
$shortcode = apply_filters( PPW_Constants::HOOK_SHORTCODE_ELEMENTOR_ATTRIBUTES, $shortcode, $settings );
$shortcode .= ']';
return $shortcode . $settings['ppwp_protected_content'] . '[/ppwp]';
}
/**
* Get whitelisted roles from Settings.
*
* @param array $settings The settings.
*
* @return string
*/
private function transform_whitelisted_roles_to_string( $settings ) {
if (
! isset( $settings['ppwp_whitelisted_roles'] ) ||
! is_array( $settings['ppwp_whitelisted_roles'] ) ||
count( $settings['ppwp_whitelisted_roles'] ) === 0
) {
return '';
}
return implode( ',', $settings['ppwp_whitelisted_roles'] );
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* Fired during plugin activation
*
* @link https://passwordprotectwp.com
* @since 1.0.0
*
* @package Password_Protect_Page
* @subpackage Password_Protect_Page/includes
*/
/**
* Fired during plugin activation.
*
* This class defines all code necessary to run during the plugin's activation.
*
* @since 1.0.0
* @package Password_Protect_Page
* @subpackage Password_Protect_Page/includes
* @author BWPS <hello@preventdirectaccess.com>
*/
class PPW_Activator {
/**
* Short Description. (use period)
*
* Long Description.
*
* @since 1.0.0
*/
public static function activate() {
if ( ! version_compare( PHP_VERSION, '5.6', '>=' ) ) {
/* translators: %s: PHP version */
$message = sprintf( esc_html__( 'Password Protect WordPress requires PHP version %s+, plugin cannot be activated.', 'password-protect-page' ), '5.6' );
$html_message = sprintf( '<div class="error">%s</div>', wpautop( $message ) );
wp_die( wp_kses_post( $html_message ) );
} elseif ( ! version_compare( get_bloginfo( 'version' ), '4.7', '>=' ) ) {
/* translators: %s: PHP version */
$message = sprintf( esc_html__( 'Password Protect WordPress requires WordPress version %s+. Because you are using an earlier version, the plugin cannot be activated.', 'password-protect-page' ), '4.7' );
$html_message = sprintf( '<div class="error">%s</div>', wpautop( $message ) );
wp_die( wp_kses_post( $html_message ) );
}
if ( is_plugin_active( PPW_Constants::PRO_DIRECTORY ) ) {
$installed_plugins = get_plugins();
$version = $installed_plugins[ PPW_Constants::PRO_DIRECTORY ]['Version'];
if ( - 1 === version_compare( $version, '1.1.0' ) ) {
wp_die( wp_kses_post( __( 'You need to <a target="_blank" rel="noreferrer noopener" href="https://passwordprotectwp.com/docs/ppwp-pro-free/">update our Pro to its latest version</a> for our Password Protect WordPress plugins to work properly. You <b>must NOT delete</b> the current Free version. Otherwise, youll lose all your current settings data.', 'password-protect-page' ) ) );
}
}
}
}

View File

@@ -0,0 +1,938 @@
<?php
/**
* Registered PPW API
*/
if ( ! class_exists( 'PPW_API' ) ) {
/**
* API definitions
*/
class PPW_API {
/**
* Messages.
*/
const MESSAGES = array(
'PASSWORD_UPDATE_SUCCESSFULLY' => 'Great! Youve updated the password successfully.',
'PASSWORD_UPDATE_FAILURE' => 'Opps! Something went wrong. Please try again.',
);
/**
* Register rest routes
*/
public function register_rest_routes() {
register_rest_route(
'wppp/v1',
'check-content-password/(?P<id>\d+)',
array(
'methods' => 'POST',
'callback' => array(
$this,
'ppwp_check_content_password',
),
'args' => array(
'id' => array(
'description' => __( 'Post ID' ),
'sanitize_callback' => 'absint',
'type' => 'integer',
),
'page' => array(
'description' => __( 'Page index' ),
'sanitize_callback' => 'absint',
'type' => 'integer',
),
'idx' => array(
'description' => __( 'Form index' ),
'sanitize_callback' => 'absint',
'type' => 'integer',
),
),
'permission_callback' => '__return_true',
)
);
register_rest_route(
'wppp/v1',
'master-passwords',
array(
'methods' => 'GET',
'callback' => array(
$this,
'ppwp_get_master_passwords',
),
'permission_callback' => array( $this, 'can_access' ),
)
);
register_rest_route(
'wppp/v1',
'master-passwords',
array(
'methods' => 'DELETE',
'callback' => array(
$this,
'delete_password',
),
'permission_callback' => array( $this, 'can_access' ),
)
);
register_rest_route(
'wppp/v1',
'master-passwords',
array(
'methods' => 'PUT',
'callback' => array(
$this,
'update_password',
),
'permission_callback' => array( $this, 'can_access' ),
)
);
register_rest_route(
'wppp/v1',
'master-passwords/status',
array(
'methods' => 'PUT',
'callback' => array(
$this,
'change_status',
),
'permission_callback' => array( $this, 'can_access' ),
)
);
register_rest_route(
'wppp/v1',
'master-passwords',
array(
'methods' => 'POST',
'callback' => array(
$this,
'add_new_master_password',
),
'permission_callback' => array( $this, 'can_access' ),
)
);
register_rest_route(
'wppp/v1',
'/master-passwords/bulk-delete',
array(
'methods' => 'POST',
'callback' => array(
$this,
'bulk_delete_master_passwords',
),
'permission_callback' => array( $this, 'can_access' ),
)
);
register_rest_route(
'wppp/v1',
'/master-passwords/all-expired-delete',
array(
'methods' => 'POST',
'callback' => array(
$this,
'all_expired_delete_master_passwords',
),
'permission_callback' => array( $this, 'can_access' ),
)
);
register_rest_route(
'wppp/v1',
'validate-password',
array(
'methods' => 'POST',
'callback' => array(
$this,
'validate_password',
),
'permission_callback' => '__return_true',
'show_in_index' => false
)
);
register_rest_route(
'wppp/v1',
'pcp/(?P<id>\d+)/settings',
array(
'methods' => 'GET',
'callback' => array(
$this,
'get_pcp_settings',
),
'permission_callback' => array( $this, 'can_access' ),
'show_in_index' => false,
)
);
register_rest_route(
'wppp/v1',
'pcp/(?P<id>\d+)/settings',
array(
'methods' => 'POST',
'callback' => array(
$this,
'update_pcp_settings',
),
'permission_callback' => array( $this, 'can_access' ),
'show_in_index' => false,
)
);
}
public function can_access() {
return ppw_allow_manage_passwords();
}
/**
* Get Master Passwords.
*/
public function ppwp_get_master_passwords() {
$ppwp_db = new PPW_Repository_Passwords();
wp_send_json(
array(
'result' => $ppwp_db->get_master_passwords_info(),
'success' => true,
),
200
);
}
/**
* Get expired time stamp
*
* @param string $days_to_expired Number of days.
*
* @return int
* @throws Exception Emits Exception in case of an error with DateTime.
*/
private function get_expired_time_stamp( $days_to_expired ) {
$curr_date = new DateTime();
$expired_date = $curr_date->modify( intval( $days_to_expired ) . ' day' );
return $expired_date->getTimestamp();
}
/**
* Add new variable.
*
* @param WP_REST_Request $request The REST API request to process.
*
* @return WP_REST_Response The REST response.
* @throws Exception Exception.
*/
public function add_new_master_password( $request ) {
$passwords = $request->get_param( 'password' );
$usage_limit = $request->get_param( 'usage_limit' );
$expired_dates = $request->get_param( 'expired_dates' );
$role_type = $request->get_param( 'role_type' );
$roles_selected = $request->get_param( 'roles_selected' );
$label = $request->get_param( 'label' );
$post_types = $request->get_param( 'post_types' );
$protection_types = $request->get_param( 'protection_types' );
$ppwp_repo = new PPW_Repository_Passwords();
foreach ( $passwords as $password ) {
if ( $ppwp_repo->find_by_master_password( $password ) || '' === $password ) {
return wp_send_json(
array(
'result' => array(),
'success' => false,
),
400
);
}
}
$roles = PPW_Constants::PPW_MASTER_GLOBAL;
if ( 'roles' === $role_type ) {
$roles = $roles_selected;
}
try {
$is_added = false;
foreach ( $passwords as $password ) {
$is_added = $ppwp_repo->add_new_password(
array(
'password' => $password,
'created_time' => time(),
'campaign_app_type' => $roles,
'usage_limit' => $usage_limit ? $usage_limit : null,
'expired_date' => $expired_dates ? $this->get_expired_time_stamp( $expired_dates ) : null,
'label' => $label,
'post_types' => $post_types,
'protection_types' => $protection_types
)
);
}
if ( $is_added ) {
return wp_send_json(
array(
'result' => $is_added,
'success' => true,
),
200
);
}
} catch ( Exception $exception ) {
return wp_send_json(
array(
'result' => array(),
'success' => false,
'message' => $exception->getMessage(),
),
400
);
}
return wp_send_json(
array(
'result' => array(),
'success' => false,
),
400
);
}
/**
* Delete password by id.
*
* @param object $request Request from body.
*
* @return WP_REST_Response The REST response.
*/
public function delete_password( $request ) {
$id = $request->get_param( 'id' );
$ppwp_repo = new PPW_Repository_Passwords();
$is_deleted = $ppwp_repo->delete( $id );
if ( $is_deleted ) {
return wp_send_json(
array(
'result' => $is_deleted,
'success' => true,
),
200
);
}
return wp_send_json(
array(
'result' => array(),
'success' => false,
),
400
);
}
/**
* Bulk delete master password.
*
* @param object $request Request from body.
*
* @return WP_REST_Response The REST response.
*/
public function bulk_delete_master_passwords( $request ) {
$ids = $request->get_param( 'ids' );
$ppwp_repo = new PPW_Repository_Passwords();
$is_deleted = $ppwp_repo->bulk_delete_passwords( $ids );
if ( $is_deleted ) {
return wp_send_json(
array(
'result' => $is_deleted,
'success' => true,
'message' => 'Great! Youve deleted the passwords successfully.'
),
200
);
}
return wp_send_json(
array(
'result' => array(),
'success' => false,
'message' => ''
),
400
);
}
/**
* All Expired delete master password.
*
* @param object $request Request from body.
*
* @return WP_REST_Response The REST response.
*/
public function all_expired_delete_master_passwords( $request ) {
$ids = $request->get_param( 'ids' );
$campaign_app_type='master_';
$ppwp_repo = new PPW_Repository_Passwords();
$is_deleted = $ppwp_repo->delete_all_expired_password($ids, $campaign_app_type);
if ( $is_deleted ) {
return wp_send_json(
array(
'result' => $is_deleted,
'success' => true,
'message' => 'Great! Youve deleted all the expired passwords successfully.'
),
200
);
}
return wp_send_json(
array(
'result' => array(),
'success' => false,
'message' => 'An error occurred, or no expired passwords were detected.'
),
400
);
}
/**
* Update password by id.
*
* @param object $request Request from body.
*
* @return WP_REST_Response The REST response.
*/
public function update_password( $request ) {
$data = $request->get_param( 'data' );
$id = $request->get_param( 'id' );
$ppwp_repo = new PPW_Repository_Passwords();
$is_updated = $ppwp_repo->update_password(
$id,
$data
);
if ( $is_updated ) {
return wp_send_json(
array(
'result' => $is_updated,
'success' => true,
'message' => self::MESSAGES['PASSWORD_UPDATE_SUCCESSFULLY'],
),
200
);
}
return wp_send_json(
array(
'result' => array(),
'success' => false,
'message' => self::MESSAGES['PASSWORD_UPDATE_FAILURE'],
),
400
);
}
/**
* Change status by id.
*
* @param object $request Request from body.
*
* @return WP_REST_Response The REST response.
*/
public function change_status( $request ) {
$id = $request->get_param( 'id' );
$is_activated = $request->get_param( 'is_activated' );
$ppwp_repo = new PPW_Repository_Passwords();
$is_updated = $ppwp_repo->update_password(
$id,
array(
'is_activated' => $is_activated,
)
);
if ( $is_updated ) {
return wp_send_json(
array(
'result' => $is_updated,
'success' => true,
'message' => self::MESSAGES['PASSWORD_UPDATE_SUCCESSFULLY'],
),
200
);
}
return wp_send_json(
array(
'result' => array(),
'success' => false,
'message' => self::MESSAGES['PASSWORD_UPDATE_FAILURE'],
),
400
);
}
/**
* Checking the content passwords
*
* @param array $data Post data.
*
* @return bool
*/
public function ppwp_check_content_password( $data ) {
do_action( PPW_Constants::HOOK_RESTRICT_CONTENT_BEFORE_CHECK_PWD, $data );
$result = array(
'isValid' => false,
'message' => _x( apply_filters( PPW_Constants::HOOK_RESTRICT_CONTENT_ERROR_MESSAGE, PPW_Constants::DEFAULT_WRONG_PASSWORD_MESSAGE ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
);
$is_valid_data = apply_filters( PPW_Constants::HOOK_SHORT_CODE_VALID_POST_DATA, $this->is_valid_data_content_password( $data ) );
if ( ! $is_valid_data ) {
return wp_send_json(
$result,
400
);
}
$post = get_post( $data['id'] );
if ( is_null( $post ) ) {
return wp_send_json(
$result,
400
);
}
$content = apply_filters( PPW_Constants::HOOK_SHORTCODE_CONTENT_SOURCE, $post->post_content, $post, $data );
if ( false === $content ) {
return wp_send_json(
$result,
400
);
}
if ( ! has_shortcode( $content, PPW_Constants::PPW_HOOK_SHORT_CODE_NAME ) ) {
return wp_send_json(
$result,
400
);
}
$matches = ppw_free_search_shortcode_content( $content );
$matches = $this->filter_short_code_matches( $matches, PPW_Constants::PPW_HOOK_SHORT_CODE_NAME );
if ( ! isset( $matches[ $data['idx'] ] ) ) {
return wp_send_json(
$result,
400
);
}
// Get all arguments of shortcode.
$shortcode = $matches[ $data['idx'] ];
if ( PPW_Recaptcha::get_instance()->using_pcp_recaptcha()
&& ! PPW_Recaptcha::get_instance()->is_valid_recaptcha() ) {
$result['message'] = PPW_Recaptcha::get_instance()->get_error_message();
return wp_send_json(
$result,
400
);
}
// Valid passwords.
$array_values = ppw_free_valid_pcp_password( $shortcode, $data['pss'] );
if ( $array_values['is_valid_password'] ) {
$atts = $array_values['atts'];
$result['cookie_expired_time'] = $atts['cookie'];
$result['isValid'] = true;
$result['message'] = '';
do_action( PPW_Constants::HOOK_RESTRICT_CONTENT_AFTER_VALID_PWD, $post, $data['pss'] );
if ( ppw_core_get_setting_type_bool_by_option_name( PPW_Constants::NO_RELOAD_PAGE, PPW_Constants::MISC_OPTIONS ) ) {
$post_content = ppw_get_pcp_post_content_with_third_party( $post, $data['idx'] );
$result['content'] = ! empty( $post_content ) ? $post_content : $shortcode[5];
$result['noReload'] = true;
}
}
// Allow custom error message from error_msg shortcode's attribute.
if ( isset( $array_values['message'] ) ) {
$result['message'] = _x( wp_kses_post( $array_values['message'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' );
}
$result = apply_filters( 'ppw_pcp_api_result', $result, $data['pss'], $post );
return wp_send_json(
$result,
200
);
}
/**
* Validate input data.
*
* @param array $data POST data.
*
* @return bool
*/
private function is_valid_data_content_password( $data ) {
return isset( $data['id'] ) && isset( $data['page'] ) && $data['page'] > 0 && isset( $data['formType'] );
}
/**
* Checking the password is valid in short code attribute.
* Sample data:
* Array
* (
* [0] => [ppwp passwords="123456 123"]This is the content under Group2[/ppwp]
* [1] =>
* [2] => ppwp
* [3] => passwords="123456 123"
* [4] =>
* [5] => This is the content under Group2
* [6] =>
* ).
*
* @param array $shortcode The found short codes in the content.
*
* @param string $password Password from request.
*
* @return array
* @deprecated 1.5.2
*
*/
private function handle_valid_password( $shortcode, $password ) {
$default_args = array(
'is_valid_password' => false,
'atts' => array(),
);
// Check ppwp shortcode exist.
if ( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME !== $shortcode[2] || ! isset( $shortcode[3] ) ) {
return $default_args;
}
// Parse shortcode string to array.
$parsed_atts = shortcode_parse_atts( trim( $shortcode[3] ) );
// Get attributes from shortcode.
$atts = PPW_Shortcode::get_instance()->get_attributes( $parsed_atts );
$passwords = apply_filters( PPW_Constants::HOOK_SHORTCODE_PASSWORDS, array_filter( $atts['passwords'], 'strlen' ), $parsed_atts );
// Check password exist.
if ( in_array( $password, $passwords, true ) ) {
$default_args['is_valid_password'] = true;
$default_args['atts'] = $atts;
}
if ( isset( $parsed_atts['error_msg'] ) ) {
$default_args['message'] = wp_kses_post( $parsed_atts['error_msg'] );
}
return $default_args;
}
/**
* Search shortcode content
*
* @param string $content The post content.
*
* @return mixed
* @deprecated 1.5.2
*
*/
private function search_shortcode_content( $content ) {
preg_match_all( '/' . get_shortcode_regex( array( 'ppwp' ) ) . '/', $content, $matches, PREG_SET_ORDER );
return $matches;
}
/**
* Filter short code result by name
*
* @param array $result The result need to filter.
* @param string $shortcode_name Short code name.
*
* @return array
*/
private function filter_short_code_matches( $result, $shortcode_name ) {
return array_values(
array_filter(
$result,
function ( $match ) use ( $shortcode_name ) {
return isset( $match[2] ) && $shortcode_name === $match[2];
}
)
);
}
/**
* Generate post data.
*
* @param WP_Post|object|int $post WP_Post instance or Post ID/object.
*
* @return array|bool $elements Elements of post or false on failure.
* @since 5.2.0
*
*/
private function generate_postdata( $post ) {
if ( ! ( $post instanceof WP_Post ) ) {
$post = get_post( $post );
}
if ( ! $post ) {
return false;
}
$id = (int) $post->ID;
$authordata = get_userdata( $post->post_author );
$currentday = mysql2date( 'd.m.y', $post->post_date, false );
$currentmonth = mysql2date( 'm', $post->post_date, false );
$numpages = 1;
$multipage = 0;
$page = $this->get( 'page' );
if ( ! $page ) {
$page = 1;
}
/*
* Force full post content when viewing the permalink for the $post,
* or when on an RSS feed. Otherwise respect the 'more' tag.
*/
if ( $post->ID === get_queried_object_id() && ( is_page() || is_single() ) ) {
$more = 1;
} elseif ( is_feed() ) {
$more = 1;
} else {
$more = 0;
}
$content = $post->post_content;
if ( false !== strpos( $content, '<!--nextpage-->' ) ) {
$content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content );
$content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content );
$content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content );
// Remove the nextpage block delimiters, to avoid invalid block structures in the split content.
$content = str_replace( '<!-- wp:nextpage -->', '', $content );
$content = str_replace( '<!-- /wp:nextpage -->', '', $content );
// Ignore nextpage at the beginning of the content.
if ( 0 === strpos( $content, '<!--nextpage-->' ) ) {
$content = substr( $content, 15 );
}
$pages = explode( '<!--nextpage-->', $content );
} else {
$pages = array( $post->post_content );
}
/**
* Filters the "pages" derived from splitting the post content.
*
* "Pages" are determined by splitting the post content based on the presence
* of `<!-- nextpage -->` tags.
*
* @param string[] $pages Array of "pages" from the post content split by `<!-- nextpage -->` tags.
* @param WP_Post $post Current post object.
*
* @since 4.4.0
*
*/
$pages = apply_filters( 'content_pagination', $pages, $post );
$numpages = count( $pages );
if ( $numpages > 1 ) {
if ( $page > 1 ) {
$more = 1;
}
$multipage = 1;
} else {
$multipage = 0;
}
$elements = compact( 'id', 'authordata', 'currentday', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages' );
return $elements;
}
/**
* @param $request
*
* @return WP_REST_Response
*/
public function validate_password( $request ) {
$post_id = $request->get_param( 'post_id' );
$password = $request->get_param( 'post_password' );
$post_id = absint( $post_id );
$password = wp_unslash( $password ); // phpcs:ignore -- not sanitize password because we allow all character.
if ( empty( $post_id ) ) {
return new WP_REST_Response(
array(
'success' => false,
'message' => 'Post ID is empty',
),
400
);
}
$post = get_post( $post_id );
if ( empty( $post ) ) {
return new WP_REST_Response(
array(
'success' => false,
'message' => 'Post not found',
),
400
);
}
$post_content = apply_filters( 'the_content', $post->post_content );
$password_service = new PPW_Password_Services();
$is_valid = $password_service->is_valid_password_from_request( $post_id, $password );
if ( ! $is_valid ) {
return new WP_REST_Response(
array(
'success' => false,
'message' => ppw_core_get_error_msg( $post_id ),
),
400
);
}
// Don not check post type in PPWP shortcode.
add_filter( 'ppw_shortcode_allow_bypass_valid_post_type', '__return_true' );
return new WP_REST_Response(
array(
'success' => true,
'post_content' => '<div>' . do_shortcode( $post_content ) . '</div>',
'message' => 'The password you entered is correct',
),
200
);
}
public function get_pcp_settings( $request ) {
$ppwp_db = new PPW_Repository_Passwords();
$post_id = $request->get_param( 'id' );
$passwords = $ppwp_db->get_passwords_with_type_and_post_id( PPW_Content_Protection::PASSWORD_GLOBAL_TYPE, $post_id, 'password' );
$setting = array();
if ( count( $passwords ) > 0 ) {
$passwords = array_map(
function ( $password_info ) {
return $password_info->password;
},
$passwords
);
$setting['passwords'] = $passwords;
} else {
$setting['passwords'] = array();
}
return new WP_REST_Response(
$setting,
200
);
}
public function update_pcp_settings( $request ) {
$ppwp_db = new PPW_Repository_Passwords();
$ppwp_area = new PPW_Content_Protection();
$post_id = $request->get_param( 'id' );
$passwords = $request->get_param( 'passwords' );
$post = get_post( $post_id );
if ( ! $ppwp_area->check_area_exist( $post ) ) {
return new WP_REST_Response(
array(
'success' => false,
),
400
);
}
if ( empty( $passwords ) ) {
$ppwp_db->delete_passwords_by_post_id( $post_id );
return new WP_REST_Response(
array(
'success' => true,
),
200
);
}
$raw_password_dbs = $ppwp_db->get_passwords_with_type_and_post_id( PPW_Content_Protection::PASSWORD_GLOBAL_TYPE, $post_id, 'id, password' );
if ( count( $raw_password_dbs ) > 0 ) {
$password_dbs = array_map(
function ( $password_info ) {
return $password_info->password;
},
$raw_password_dbs
);
$passwords_to_add = array_values( array_diff( $passwords, $password_dbs ) );
$passwords_to_delete = array_values( array_diff( $password_dbs, $passwords ) );
foreach ( $passwords_to_add as $password_to_add ) {
$password = trim( $password_to_add );
if ( '' === $password ) {
continue;
}
$password_data = array(
'post_id' => $post_id,
'created_time' => time(),
'campaign_app_type' => PPW_Content_Protection::PASSWORD_GLOBAL_TYPE,
'password' => $password,
'usage_limit' => null,
'expired_date' => null,
);
$ppwp_db->add_new_password( $password_data );
}
$ids = array();
foreach ( $raw_password_dbs as $raw_password_db ) {
if ( in_array( $raw_password_db->password, $passwords_to_delete ) ) {
$ids[] = $raw_password_db->id;
}
}
$ids = array_unique( $ids );
$ppwp_db->delete_passwords( $ids, $post_id );
} else {
foreach ( $passwords as $password ) {
$password = trim( $password );
if ( '' === $password ) {
continue;
}
$password_data = array(
'post_id' => $post_id,
'created_time' => time(),
'campaign_app_type' => PPW_Content_Protection::PASSWORD_GLOBAL_TYPE,
'password' => $password,
'usage_limit' => null,
'expired_date' => null,
);
$ppwp_db->add_new_password( $password_data );
}
}
return new WP_REST_Response(
array(
'success' => true,
),
200
);
}
}
}

View File

@@ -0,0 +1,522 @@
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://www.buildwps.com/
* @since 1.0.0
*
* @package Prevent_ur_pages
* @subpackage Prevent_ur_pages/include
*/
/**
*
* Defines the Constants
*
* @package Prevent_ur_pages
* @subpackage Prevent_ur_pages/include
* @author Bwps <support@bwps.us>
*/
if ( ! class_exists( 'PPW_Constants' ) ) {
/**
* Constants helper class
*
* Class PPW_Free_Constants
*/
class PPW_Constants {
// Hook.
const HOOK_IS_PRO_ACTIVATE = 'ppw_is_pro_activate';
const HOOK_CUSTOM_STYLE_FORM_ENTIRE_SITE = 'ppw_free_custom_style_form_entire_site';
const HOOK_MESSAGE_ENTERING_WRONG_PASSWORD = 'ppwp_text_for_entering_wrong_password';
const HOOK_MESSAGE_PASSWORD_FORM = 'ppwp_customize_password_form_message';
const HOOK_CUSTOM_PASSWORD_FORM = 'ppwp_customize_password_form';
const HOOK_CALLBACK_URL = 'ppwp_callback_url';
const CALL_BACK_URL_PARAM = 'callback_url';
const HOOK_SHOULD_RENDER_PASSWORD_FORM = 'ppwp_should_render_password_form';
const HOOK_DEFAULT_TAB = 'ppw_default_tab';
const HOOK_SITEWIDE_TAB = 'ppw_sitewide_tab';
const HOOK_PCP_TAB = 'ppw_pcp_tab';
const HOOK_ADD_NEW_TAB = 'ppw_add_new_tab';
const HOOK_ADD_NEW_SITEWIDE_SUBMENU = 'ppw_sitewide_submenu_add_new_tab';
const HOOK_ADD_NEW_PCP_SUBMENU = 'ppw_pcp_submenu_add_new_tab';
const HOOK_RENDER_CONTENT_FOR_TAB = 'ppw_render_content_';
const HOOK_CUSTOM_TAB = 'ppw_custom_tab';
const HOOK_CUSTOM_SITEWIDE_TAB = 'ppw_custom_sitewide_tab';
const HOOK_CUSTOM_PCP_TAB = 'ppw_custom_pcp_tab';
const HOOK_RENDER_CONTENT_FOR_SITEWIDE_TAB = 'ppw_render_sitewide_content_';
const HOOK_RENDER_CONTENT_FOR_PCP_TAB = 'ppw_render_pcp_content_';
const HOOK_COOKIE_EXPIRED = 'post_password_expires';
const HOOK_CHECK_PASSWORD_BEFORE_RENDER_CONTENT = 'ppw_check_password_before_render_content';
const HOOK_FUNCTION_HANDLE_META_BOX = 'ppw_function_handle_meta_box';
const HOOK_META_BOX_POSITION = 'ppw_meta_box_position';
const HOOK_CHECK_PASSWORD_IS_VALID = 'ppw_check_password_is_valid';
const HOOK_BEFORE_RENDER_FORM_ENTIRE_SITE = 'ppw_before_render_form_entire_site';
const HOOK_HIDE_DEFAULT_PW_WP_POSITION = 'ppw_hide_default_pw_wp_position';
const HOOK_PLUGIN_INFO = 'ppw_plugin_info';
const HOOK_CUSTOM_HEADER_FORM_ENTIRE_SITE = 'ppw_custom_header_form_entire_site';
const HOOK_CUSTOM_FOOTER_FORM_ENTIRE_SITE = 'ppw_custom_footer_form_entire_site';
const HOOK_CUSTOM_TEXT_FEATURE_REMOVE_DATA = 'ppw_custom_text_feature_remove_data';
const HOOK_POST_TYPES = 'ppw_post_types';
const HOOK_MIGRATE_COMPLETE_MESSAGE = 'ppw_complete_message';
const HOOK_PARAM_PASSWORD_SUCCESS = 'ppw_custom_param';
const HOOK_SHORT_CODE_ATTRS = 'ppw_short_code_attributes';
const HOOK_SUPPORTED_WHITELIST_ROLES = 'ppw_supported_white_list_roles';
const HOOK_SUPPORTED_POST_TYPES = 'ppw_supported_post_types';
const HOOK_SHORT_CODE_TEMPLATE = 'ppw_short_code_template';
const HOOK_RESTRICT_CONTENT_ERROR_MESSAGE = 'ppw_restrict_content_custom_error_message';
const HOOK_RESTRICT_CONTENT_BEFORE_CHECK_PWD = 'ppw_restrict_content_before_check_pw';
const HOOK_RESTRICT_CONTENT_AFTER_VALID_PWD = 'ppw_restrict_content_after_valid_pw';
const HOOK_SHORT_CODE_WHITELISTED_ROLES = 'ppw_restrict_content_whitelisted_roles';
const HOOK_SHORT_CODE_ERROR_MESSAGE = 'ppw_restrict_content_error_message';
const HOOK_SHORTCODE_NOT_SUPPORT_TYPE_ERROR_MESSAGE = 'ppw_restrict_content_not_support_post_type_error_message';
const HOOK_SHORT_CODE_BEFORE_CHECK_PASSWORD = 'ppw_restrict_content_before_check_password';
const HOOK_SHORT_CODE_AFTER_CHECK_PASSWORD = 'ppw_restrict_content_before_check_password';
const HOOK_SHORT_CODE_VALID_POST_DATA = 'ppw_restrict_content_valid_post_data';
const HOOK_HANDLE_BEFORE_RENDER_WOO_PRODUCT = 'ppw_handle_before_render_woo_product';
const HOOK_SHORTCODE_ATTRIBUTES_VALIDATION = 'ppw_shortcode_attributes_validation';
const HOOK_SHORTCODE_PASSWORDS = 'ppw_shortcode_passwords';
const HOOK_SHORTCODE_RENDER_CONTENT = 'ppw_shortcode_render_content';
const HOOK_SHORTCODE_CONTENT_SOURCE = 'ppw_content_shortcode_source';
const HOOK_SHORTCODE_SETTINGS_EXTENDS = 'ppw_shortcode_settings_extend';
const HOOK_MASTER_PASSWORDS_VALID_POST_TYPES = 'ppw_master_passwords_valid_post_types';
const HOOK_SHORTCODE_BEAVER_BUILDER_FIELDS = 'ppw_shortcode_beaver_builder_fields';
const HOOK_SHORTCODE_BEAVER_BUILDER_GENERAL_FIELDS = 'ppw_shortcode_beaver_builder_general_fields';
const HOOK_SHORTCODE_BEAVER_BUILDER_INSTRUCTION_FIELDS = 'ppw_shortcode_beaver_builder_instruction_fields';
const HOOK_SHORTCODE_BEAVER_BUILDER_ATTRIBUTES = 'ppw_shortcode_beaver_builder_attributes';
const HOOK_SHORTCODE_ELEMENTOR_CONTROLS = 'ppw_shortcode_elementor_controls';
const HOOK_SHORTCODE_ELEMENTOR_ATTRIBUTES = 'ppw_shortcode_elementor_attributes';
const HOOK_SHORTCODE_ELEMENTOR_CONTENT = 'ppw_shortcode_elementor_content';
const HOOK_SHORTCODE_ELEMENTOR_PREVIEW_CONTENT = 'ppw_shortcode_elementor_preview_content';
const HOOK_SHORTCODE_BEFORE_RENDER_PASSWORD_FORM = 'ppw_shortcode_before_render_password_form';
const HOOK_SIDEBAR_SHORTCODE = 'ppw_sidebar_shortcode';
const HOOK_CHECK_CONTENT_IS_PROTECTED_BY_PRO = 'ppw_check_content_is_protected_by_pro';
const HOOK_CUSTOM_OPTION_HIDE_PROTECT_CONTENT = 'ppw_custom_option_hide_protect_content';
const HOOK_CUSTOM_POST_TYPE_HIDE_PROTECTED_POST = 'ppw_custom_post_type_for_hide_protected_post';
const HOOK_CUSTOM_POST_TYPE_RECENT_POST = 'ppw_custom_post_type_for_recent_post';
const HOOK_CUSTOM_POST_TYPE_NEXT_AND_PREVIOUS = 'ppw_custom_post_type_for_next_and_previous';
const HOOK_CUSTOM_POST_ID_HIDE_PROTECTED_POST = 'ppw_custom_post_id_for_hide_protected_post';
const HOOK_CUSTOM_DEFAULT_OPTIONS_HIDE_PROTECTED_POST = 'ppw_custom_default_options_for_hide_protected_post';
const HOOK_CUSTOM_POSITIONS_HIDE_PROTECTED_POST = 'ppw_custom_positions_for_hide_protected_post';
const HOOK_SHORTCODE_ALLOW_BYPASS_VALID_POST_TYPE = 'ppw_shortcode_allow_bypass_valid_post_type';
const HOOK_ADVANCED_TAB_LOAD_ASSETS = 'ppw_misc_tab_load_assets';
const HOOK_ADVANCED_VALID_INPUT_DATA = 'ppw_misc_valid_input_data';
// End hook.
// Short code attribute.
const SHORT_CODE_FORM_HEADLINE = '[PPWP_FORM_HEADLINE]';
const SHORT_CODE_FORM_INSTRUCT = '[PPWP_FORM_INSTRUCTIONS]';
const SHORT_CODE_FORM_PLACEHOLDER = '[PPW_PLACEHOLDER]';
const SHORT_CODE_FORM_AUTH = '[PPW_AUTH]';
const SHORT_CODE_FORM_CURRENT_URL = '[PPW_CURRENT_URL]';
const SHORT_CODE_FORM_ERROR_MESSAGE = '[PPW_ERROR_MESSAGE]';
const SHORT_CODE_BUTTON = '[PPW_BUTTON_LABEL]';
const SHORT_CODE_FORM_ID = '[PPW_FORM_ID]';
const SHORT_CODE_FORM_CLASS = '[PPW_FORM_CLASS]';
const SHORT_CODE_PASSWORD_LABEL = '[PPWP_FORM_PASSWORD_LABEL]';
const SHORTCODE_ABOVE_PASSWORD_INPUT = '[PPWP_FORM_ABOVE_PASSWORD_INPUT]';
const SHORTCODE_BELOW_PASSWORD_INPUT = '[PPWP_FORM_BELOW_PASSWORD_INPUT]';
const SHORTCODE_DESC_ABOVE_BTN = '[SHORTCODE_DESC_ABOVE_BTN]';
const SHORTCODE_DESC_BELOW_FORM = '[SHORTCODE_DESC_BELOW_FORM]';
// End short code attribute.
// Default.
const DEFAULT_SUBMIT_LABEL = 'Enter';
const DEFAULT_PASSWORD_LABEL = 'Password:';
const DEFAULT_HEADLINE_TEXT = '';
const DEFAULT_PLACEHOLDER = '';
const DEFAULT_IS_SHOW_PASSWORD = 0;
const DEFAULT_FORM_BACKGROUND_COLOR = '';
const DEFAULT_FORM_PADDING = '';
const DEFAULT_FORM_MARGIN = '';
const DEFAULT_FORM_BORDER_RADIUS = '';
const DEFAULT_HEADLINE_FONT_SIZE = '';
const DEFAULT_HEADLINE_FONT_WEIGHT = '';
const DEFAULT_HEADLINE_FONT_COLOR = '';
const DEFAULT_TEXT_FONT_SIZE = '';
const DEFAULT_TEXT_FONT_WEIGHT = '';
const DEFAULT_TEXT_FONT_COLOR = '';
const DEFAULT_ERROR_TEXT_FONT_SIZE = '';
const DEFAULT_ERROR_TEXT_FONT_WEIGHT = '';
const DEFAULT_ERROR_TEXT_FONT_COLOR = '#dc3232';
const DEFAULT_ERROR_TEXT_BACKGROUND_COLOR = '';
const DEFAULT_BUTTON_TEXT_FONT_COLOR = '';
const DEFAULT_BUTTON_BACKGROUND_COLOR = '';
const DEFAULT_BUTTON_TEXT_HOVER_COLOR = '';
const DEFAULT_BUTTON_BACKGROUND_HOVER_COLOR = '';
const DEFAULT_SHOW_PASSWORD_TEXT = 'Show password';
const DEFAULT_SHOW_PASSWORD_TEXT_SIZE = '';
const DEFAULT_PASSWORD_LABEL_FONT_COLOR = '';
// End default.
// Message.
const DEFAULT_FORM_MESSAGE = 'This content is password protected. To view it please enter your password below:';
const DEFAULT_SHORTCODE_DESC_ABOVE_PWD_BTN = '';
const DEFAULT_SHORTCODE_DESC_BELOW_PWD_FORM = '';
const DEFAULT_WRONG_PASSWORD_MESSAGE = 'Please enter the correct password!';
const DEFAULT_ERROR_RECAPTCHA_MESSAGE = 'Google reCAPTCHA verification failed, please try again later.';
const BAD_REQUEST_MESSAGE = 'Our server cannot understand the data request!';
const EMPTY_PASSWORD = 'Please fill out empty fields.';
const DUPLICATE_PASSWORD = 'You can\'t create duplicate password. Please try again.';
const SPACE_PASSWORD = 'Spaces not accepted in password. Please remove them and try again.';
// End message.
// Modules.
const MENU_NAME = 'wp_protect_password_options';
const SITEWIDE_PAGE_PREFIX = 'ppwp-sitewide';
const EXTERNAL_SERVICES_PREFIX = 'ppwp-integrations';
const PCP_PAGE_PREFIX = 'ppwp-partial-protection';
const META_BOX_MODULE = 'meta-box';
const ENTIRE_SITE_MODULE = 'entire-site';
const GENERAL_SETTINGS_MODULE = 'general';
const EXTERNAL_SETTINGS_MODULE = 'external';
const EXTERNAL_CONFIGURATION_MODULE = 'external-configuration';
const MISC_SETTINGS_MODULE = 'misc';
const TROUBLESHOOT_SETTINGS_MODULE = 'troubleshooting';
const SHORTCODES_SETTINGS_MODULE = 'shortcodes';
// End modules.
const COOKIE_NAME = 'wp-postpass-role_';
const ENTIRE_SITE_FORM_NONCE = 'ppw_entire_site_form_nonce';
const GENERAL_FORM_NONCE = 'ppw_general_form_nonce';
const PCP_FORM_NONCE = 'ppw_pcp_nonce';
const ROW_ACTION_NONCE = 'ppw_row_action_nonce';
const ENTIRE_SITE_OPTIONS = 'wp_protect_password_set_password_options';
const GENERAL_OPTIONS = 'wp_protect_password_setting_options';
const MISC_OPTIONS = 'wp_protect_password_misc_options';
const SHORTCODE_OPTIONS = 'wp_protect_password_shortcode_options';
const EXTERNAL_OPTIONS = 'wp_protect_password_external_options';
const POST_PROTECTION_ROLES = 'post_protection_roles';
const ENTIRE_SITE_COOKIE_NAME = 'pda_protect_password';
const GLOBAL_PASSWORDS = 'wp_protect_password_multiple_passwords';
const COOKIE_EXPIRED = 'wpp_password_cookie_expired';
const REMOVE_DATA = 'wpp_remove_data';
const USE_CUSTOM_FORM_ACTION = 'wpp_use_custom_form_action';
const NO_RELOAD_PAGE = 'wpp_no_reload_page';
const USE_SHORTCODE_PAGE_BUILDER = 'wpp_use_shortcode_page_builder';
const USING_RECAPTCHA = 'wpp_use_recaptcha';
const RECAPTCHA_TYPE = 'wpp_recaptcha_type';
const RECAPTCHA_PASSWORD_TYPES = 'wpp_recaptcha_password_types';
const RECAPTCHA_API_KEY = 'wpp_recaptcha_api_key';
const RECAPTCHA_V2_CHECKBOX_API_KEY = 'wpp_recaptcha_v2_checkbox_api_key';
const RECAPTCHA_API_SECRET = 'wpp_recaptcha_api_secret';
const RECAPTCHA_V2_CHECKBOX_API_SECRET = 'wpp_recaptcha_v2_checkbox_api_secret';
const RECAPTCHA_SCORE = 'wpp_recaptcha_score';
const PROTECT_EXCERPT = 'wpp_protect_excerpt';
const MAX_COOKIE_EXPIRED = 8760;
const MIN_COOKIE_EXPIRED = 0;
const DOMAIN = 'password-protect-page';
const WRONG_PASSWORD_PARAM = 'ppwp_enter_wrong_password';
const PASSWORD_PARAM_NAME = 'ppwp';
const PASSWORD_PARAM_VALUE = '1';
const IS_PROTECT_ENTIRE_SITE = 'ppwp_apply_password_for_entire_site';
const PASSWORD_ENTIRE_SITE = 'password_for_website';
const SET_NEW_PASSWORD_ENTIRE_SITE = 'ppwp_set_new_password_for_entire_site';
const META_BOX_NONCE = 'ppw_meta_box_nonce';
const SUBSCRIBE_FORM_NONCE = 'ppw_subscribe_form_nonce';
const USER_SUBSCRIBE = 'ppw_free_subscribe';
const MIGRATED_DEFAULT_PW = 'migrated_default_pw';
const MIGRATED_FREE_FLAG = 'migrated_free';
const PRO_DIRECTORY = 'wp_protect_password/wp-protect-password.php';
const PRO_ROOT_DIR = 'wp_protect_password';
const DEV_PRO_DIRECTORY = 'password-protect-page-pro/wp-protect-password.php';
const DEV_PRO_ROOT_DIR = 'password-protect-page-pro';
const PPW_HOOK_SHORT_CODE_NAME = 'ppwp';
const PPW_ERROR_MESSAGE_COLOR = '#dc3232';
const WP_POST_PASS = 'wp-postpass_';
const CUSTOM_POST_CLASS = 'ppwp-short-code-post';
const CUSTOM_TABLE_COLUMN_NAME = 'ppw_password_protection';
const CUSTOM_TABLE_COLUMN_TITLE = 'Password Protection';
const DEFAULT_SHORTCODE_CLASS_NAME = 'ppw-restricted-content';
const DEFAULT_SHORTCODE_HEADLINE = 'Restricted Content';
const DEFAULT_SHORTCODE_DESCRIPTION = 'To view this protected content, enter the password below:';
const DEFAULT_SHORTCODE_BUTTON = 'Enter';
const DEFAULT_SHORTCODE_LABEL = 'Password:';
const DEFAULT_SHORTCODE_ERROR_MSG = 'Please enter the correct password!';
const DEFAULT_SHORTCODE_LOADING = 'Loading...';
const DEFAULT_SHORTCODE_SHOW_PASSWORD = false;
const DEFAULT_SHORTCODE_SHOW_PASSWORD_TEXT = 'Show password';
const TBL_NAME = 'pda_passwords';
const TBL_VERSION = 'pda-pwd-tbl-version';
const DB_DATA_COLUMN_TABLE = array(
array(
'old_version' => '1.0',
'new_version' => '1.1',
'value' => 'hits_count mediumint(9) NOT NULL',
),
array(
'old_version' => '1.1',
'new_version' => '1.2',
'value' => 'is_default tinyint(1) DEFAULT 0',
),
array(
'old_version' => '1.2',
'new_version' => '1.3',
'value' => 'expired_date BIGINT DEFAULT NULL',
),
array(
'old_version' => '1.3',
'new_version' => '1.4',
'value' => 'usage_limit mediumint(9)',
),
);
const DB_UPDATE_COLUMN_TABLE = array(
array(
'old_version' => '1.4',
'new_version' => '1.5',
'value' => "campaign_app_type campaign_app_type text DEFAULT '' NULL",
),
array(
'old_version' => '1.5',
'new_version' => '1.6',
'value' => "password password varchar(255) DEFAULT '' NULL",
),
);
const PPW_MASTER_GLOBAL = 'master_global';
const PPW_MASTER_ROLE = 'master_role_';
const MASTER_COOKIE_NAME = 'ppw_master-';
// Const for feature "Hide Protected Content".
const DEFAULT_POST_TYPE = array( 'post', 'page' );
const HIDE_PROTECTED = 'ppw_hide_protected_';
const HIDE_SELECTED = 'ppw_hide_selected_';
const FRONT_PAGE = 'ppw_front_page';
const CATEGORY_PAGE = 'ppw_category_page';
const TAG_PAGE = 'ppw_tag_page';
const AUTHOR_PAGE = 'ppw_author_page';
const ARCHIVES_PAGE = 'ppw_archives_page';
const NEXT_PREVIOUS = 'ppw_next_previous';
const RECENT_POST = 'ppw_recent_post';
const SEARCH_RESULTS = 'ppw_search_results';
const FEEDS = 'ppw_feeds';
const EVERYWHERE_PAGE = 'ppw_everywhere_pages';
const XML_YOAST_SEO_SITEMAPS = 'ppw_xml_yoast_seo_sitemaps';
// End const for feature "Hide Protected Content".
const PROTECTION_STATUS = array(
'protect' => 1,
'unprotect' => 0,
);
const PROTECT_LABEL = 'Protect';
const UNPROTECT_LABEL = 'Unprotect';
const CONTEXT_PASSWORD_FORM = 'PPF';
const CONTEXT_PCP_PASSWORD_FORM = 'PCP';
const CONTEXT_SITEWIDE_PASSWORD_FORM = 'SWP Lite';
}
}

View File

@@ -0,0 +1,563 @@
<?php
/**
* Class PPW_Repository_Passwords
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'PPW_Repository_Passwords' ) ) {
/**
* DB class to create table and manage version
* Class PPW_Pro_DB
*/
class PPW_Repository_Passwords {
/**
* Table version
* @var string
*/
private $tbl_version;
/**
* Table name
* @var string
*/
private $tbl_name;
/**
* @var object
*/
private $wpdb;
/**
* Instance of PPW_Pro_Shortcode class.
*
* @var PPW_Repository_Passwords
*/
protected static $instance = null;
/**
* PPW_Pro_DB constructor.
*
* @param $prefix
*/
public function __construct( $prefix = false ) {
global $wpdb;
$this->wpdb = $wpdb;
$this->tbl_version = $this->get_table_version();
$this->tbl_name = ! $prefix ? $this->wpdb->prefix . PPW_Constants::TBL_NAME : $prefix . PPW_Constants::TBL_NAME;
}
/**
* Get short code instance
*
* @return PPW_Repository_Passwords
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
// Use static instead of self due to the inheritance later.
// For example: ChildSC extends this class, when we call get_instance
// it will return the object of child class. On the other hand, self function
// will return the object of base class.
self::$instance = new static();
}
return self::$instance;
}
/**
* Install table
*/
public function install() {
// TODO: Check highest version to create table.
$this->init_tbl();
// Add new column.
foreach ( PPW_Constants::DB_DATA_COLUMN_TABLE as $data ) {
$this->add_new_column( $data['old_version'], $data['new_version'], $data['value'] );
}
// Update column.
foreach ( PPW_Constants::DB_UPDATE_COLUMN_TABLE as $dt ) {
$this->update_table( $dt['old_version'], $dt['new_version'], $dt['value'] );
}
// TODO: Add column for pro version.
$this->update_label_and_post_types_column();
}
/**
* Uninstall table
*/
public function uninstall() {
$this->wpdb->query( "DROP TABLE IF EXISTS $this->tbl_name" ); // phpcs:ignore -- We do not need to prepare because don't have any param to pass.
}
/**
* Init table
*/
private function init_tbl() {
if ( $this->is_table_does_not_exist() ) {
$charset_collate = $this->wpdb->get_charset_collate();
$sql = "CREATE TABLE $this->tbl_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
post_id mediumint(9) NOT NULL,
contact_id mediumint(9) NULL,
campaign_app_type varchar(50) DEFAULT '' NULL,
password varchar(30) NOT NULL,
is_activated tinyint(1) DEFAULT 1,
created_time BIGINT DEFAULT NULL,
expired_time BIGINT DEFAULT NULL,
UNIQUE KEY id(id)
) $charset_collate;";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $sql );
// Init setting when installing plugin firstly.
update_option( PPW_Constants::MISC_OPTIONS, wp_json_encode( array( 'wpp_use_custom_form_action' => 'true' ) ), 'no' );
$this->tbl_version = "1.0";
$this->update_table_version( $this->tbl_version );
}
}
/**
* Add new column for table
*
* @param $old_version
* @param $new_version
* @param $value
*/
private function add_new_column( $old_version, $new_version, $value ) {
if ( $this->tbl_version === $old_version ) {
if ( is_null( $this->check_column_exist( $value ) ) ) {
$charset_collate = $this->wpdb->get_charset_collate();
$sql = "CREATE TABLE $this->tbl_name ( $value ) $charset_collate;";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $sql );
}
$this->tbl_version = $new_version;
$this->update_table_version( $this->tbl_version );
}
}
/**
* Update value for column in table
*
* @param $old_version
* @param $new_version
* @param $value
*/
private function update_table( $old_version, $new_version, $value ) {
if ( $this->tbl_version === $old_version ) {
$sql = "ALTER TABLE $this->tbl_name CHANGE $value";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$this->wpdb->query( $sql ); // phpcs:ignore -- We don't need to prepare this one.
$this->tbl_version = $new_version;
$this->update_table_version( $this->tbl_version );
}
}
/**
* Check table is exist
*
* @return bool
*/
private function is_table_does_not_exist() {
$preparation = $this->wpdb->prepare( 'SHOW TABLES LIKE %s', $this->tbl_name );
return $this->wpdb->get_var( $preparation ) != $this->tbl_name; // phpcs:ignore -- we already prepared above, but there are no data to prepare
}
/**
* Get the plugin table's version
*/
private function get_table_version() {
$version = get_option( PPW_Constants::TBL_VERSION, false );
return ! $version ? '1.0' : $version;
}
/**
* Update table version
*
* @param $version
*/
private function update_table_version( $version ) {
update_option( PPW_Constants::TBL_VERSION, $version );
}
/**
* Get password info by password and post id
*
* @param string $password The password.
*
* @return mixed
*/
public function get_master_password_info_by_password( $password ) {
$like_master_param = 'master_';
$query_string = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s and campaign_app_type LIKE %s and post_id = 0 and is_activated = 1 and (expired_date is NULL OR expired_date > UNIX_TIMESTAMP()) and (usage_limit is NULL OR hits_count < usage_limit)", $password, $this->wpdb->esc_like( $like_master_param ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
return $this->wpdb->get_row( $query_string ); // phpcs:ignore -- we already prepared above
}
/**
* Get master password which activating.
*
* @return array|object|null Database query results.
*/
public function get_activate_master_passwords_info() {
$like_master_param = 'master_';
$query_string = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE post_id = 0 AND campaign_app_type LIKE %s and is_activated = 1", $this->wpdb->esc_like( $like_master_param ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder.
return $this->wpdb->get_results( $query_string ); // phpcs:ignore -- we already prepared above
}
/**
* Get master password which in database.
*
* @return array|object|null Database query results.
*/
public function get_master_passwords_info() {
$like_master_param = 'master_';
$query_string = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE post_id = 0 AND campaign_app_type LIKE %s", $this->wpdb->esc_like( $like_master_param ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
return $this->wpdb->get_results( $query_string ); // phpcs:ignore -- we already prepared above
}
/**
* Add a row in table by id.
*
* @param array $data Data to add.
*
* @return int|false The number of rows updated, or false on error.
*/
public function add_new_password( $data ) {
$is_added = $this->wpdb->insert( $this->tbl_name, $data );
if ( $is_added ) {
return $this->wpdb->insert_id;
}
return false;
}
public function delete_passwords( $ids, $post_id ) {
$ids = implode( ',', array_map( 'absint', $ids ) );
$post_id = absint( $post_id );
$query_string = $this->wpdb->prepare( "DELETE FROM {$this->tbl_name} WHERE id IN(%1s) AND post_id = %d", $ids, $post_id ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder and put the $ids in quotes.
$this->wpdb->query( $query_string ); // phpcs:ignore -- we already prepared above
}
/**
* Find password by post ID.
*
* @param string $password Password.
*
* @return array|object|void|null Database query result in format specified by $output or null on failure
*/
public function find_by_master_password( $password ) {
$like_master_param = 'master_';
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s AND post_id = 0 AND campaign_app_type LIKE %s", $password, $this->wpdb->esc_like( $like_master_param ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
}
/**
* Find shared category password.
*
* @param string $password Password.
*
* @return array|object|void|null Database query result in format specified by $output or null on failure
*/
public function find_by_shared_category_password( $password ) {
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s AND post_id = 0 AND campaign_app_type = %s", $password, PPW_Category_Service::SHARED_CATEGORY_TYPE ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
}
/**
* Get all shared categories password.
*
* @return array|object|void|null Database query result in format specified by $output or null on failure
*/
public function get_all_shared_categories_password() {
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE post_id = 0 AND campaign_app_type = %s", PPW_Category_Service::SHARED_CATEGORY_TYPE ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
return $this->wpdb->get_results( $sql ); // phpcs:ignore -- we already prepared above
}
public function get_passwords_with_type_and_post_id( $type, $post_id, $column = '*' ) {
$sql = $this->wpdb->prepare( "SELECT %1s FROM {$this->tbl_name} WHERE post_id = %d AND campaign_app_type = %s", $column, $post_id, $type ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder, and put $column in quotes.
return $this->wpdb->get_results( $sql ); // phpcs:ignore -- we already prepared above
}
/***
* Get all custom categories's password
* @param $taxonomy_type
*
* @return mixed
*/
public function get_all_custom_categories_password( $taxonomy_type ) {
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE post_id = 0 AND campaign_app_type = %s", $taxonomy_type ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
return $this->wpdb->get_results( $sql ); // phpcs:ignore -- we already prepared above
}
/***
* Check password with custom category type.
*
* @param $password
* @param $taxonomy
*
* @return mixed
*/
public function find_by_shared_custom_category_password( $password, $taxonomy_type ) {
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s AND post_id = 0 AND campaign_app_type = %s", $password, $taxonomy_type ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
}
/**
* Get shared category password by password ID.
*
* @param int $password_id Password ID.
*
* @return array|object|void|null Database query result in format specified by $output or null on failure
*/
public function get_shared_category_password( $password_id ) {
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY id = %d AND campaign_app_type = %s", $password_id, PPW_Category_Service::SHARED_CATEGORY_TYPE ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
}
/**
* Get shared category password by password ID.
*
* @param int $password_id Password ID.
*
* @return array|object|void|null Database query result in format specified by $output or null on failure
*/
public function get_shared_custom_category_password( $password_id, $taxonomy ) {
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE id = %d AND campaign_app_type = %s", $password_id, $taxonomy ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
}
/**
* Delete a row in table by id.
*
* @param int $id ID.
*
* @return int|false The number of rows updated, or false on error.
*/
public function delete( $id ) {
return $this->wpdb->delete(
$this->tbl_name,
array(
'id' => absint( $id ),
)
);
}
/**
* Update a row in table by id.
*
* @param int $id ID.
* @param array $data Data to update.
*
* @return int|false The number of rows updated, or false on error.
*/
public function update_password( $id, $data ) {
return $this->wpdb->update(
$this->tbl_name,
$data,
array(
'id' => absint( $id ),
)
);
}
/**
* Update label and post types column.
*/
public function update_label_and_post_types_column() {
$this->add_new_column( '1.6', '1.7', 'label TINYTEXT' );
$this->add_new_column( '1.7', '1.8', 'post_types varchar(255)' );
$this->add_new_column( '1.8', '1.9', 'protection_types varchar(50)' );
}
/**
* Check column exist in database.
*
* @param string $value Value to add new column.
*
* @return string|null|false Database query result (as string), or null on failure
* @since 1.4.0 Init function.
*/
private function check_column_exist( $value ) {
if ( empty( $value ) ) {
return false;
}
$value_patterns = explode( ' ', $value );
$field_name = $value_patterns[0];
$query = $this->wpdb->prepare( "SHOW COLUMNS FROM {$this->tbl_name} LIKE %s", $this->wpdb->esc_like( $field_name ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
return $this->wpdb->get_var( $query ); // phpcs:ignore -- we already prepared above
}
/**
* Get all backup post password.
*
* @return array|object|void|null Database query result in format specified by $output or null on failure
*/
public function get_wp_post_passwords() {
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->postmeta} WHERE meta_key = %s", 'ppwp_post_password_bk' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
return $this->wpdb->get_results( $sql ); // phpcs:ignore -- we already prepared above
}
/**
* Count all backup post password.
*
* @return int - number for count
*/
public function count_wp_post_passwords() {
$sql = $this->wpdb->prepare( "SELECT COUNT(*) FROM {$this->wpdb->postmeta} WHERE meta_key = %s", 'ppwp_post_password_bk' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
return $this->wpdb->get_var( $sql ); // phpcs:ignore -- we already prepared above
}
/**
* Delete selected passwords by id
* String will convert to int
*
* @param array $selected_ids ID Passwords selected.
*
* @return mixed
*/
public function bulk_delete_passwords( $selected_ids ) {
$selected_ids = implode( ',', array_map( 'absint', $selected_ids ) );
$query_string = $this->wpdb->prepare( "DELETE FROM {$this->tbl_name} WHERE ID IN(%1s)", $selected_ids ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder and put the $ids in quotes.
return $this->wpdb->query( $query_string ); // phpcs:ignore -- we already prepared above
}
/**
* Delete all expired master password
*/
public function delete_all_expired_password( $ids, $campaign_app_type) {
return $this->wpdb->query($this->wpdb->prepare( "DELETE FROM $this->tbl_name WHERE `campaign_app_type` LIKE '%$campaign_app_type%' and `expired_date` < UNIX_TIMESTAMP(NOW()) or `hits_count` >= `usage_limit`"));
//return $this->wpdb->query($this->wpdb->prepare( "DELETE FROM $this->tbl_name WHERE `campaign_app_type` = %s", $campaign_app_type));
}
public function delete_passwords_by_post_id( $post_id ) {
return $this->wpdb->delete(
$this->tbl_name,
array(
'post_id' => absint( $post_id ),
)
);
}
public function find_activated_password( $password, $params ) {
$args = wp_parse_args(
$params,
array(
'post_id' => 0,
'roles' => array(),
'global_type' => '',
'role_type' => '',
'allow_to_check_expired' => true,
)
);
$like_where = '';
if ( $args['role_type'] ) {
$like_where = $this->generate_where_like_for_roles( $args['roles'], $args['role_type'] );
}
$expired_where = '';
if ( $args['allow_to_check_expired'] ) {
$expired_where = ' AND (expired_date IS NULL OR expired_date > UNIX_TIMESTAMP()) AND (usage_limit IS NULL OR hits_count < usage_limit) ';
}
$query = $this->wpdb->prepare(
"SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s AND is_activated = 1 AND ( campaign_app_type = %s {$like_where}) AND post_id = %d {$expired_where}", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder and put the extended where sql query in quotes.
$password,
$args['global_type'],
$args['post_id']
);
return $this->wpdb->get_row( $query ); // phpcs:ignore -- we already prepared above
}
public function find_activated_passwords_by_ids( $password_ids, $params ) {
$args = wp_parse_args(
$params,
array(
'post_id' => 0,
'roles' => array(),
'global_type' => '',
'role_type' => '',
'allow_to_check_expired' => true,
)
);
$password_ids = array_map( 'absint', $password_ids );
$password_ids_str = implode( ', ', $password_ids );
$like_where = '';
if ( $args['role_type'] ) {
$like_where = $this->generate_where_like_for_roles( $args['roles'], $args['role_type'] );
}
$expired_where = '';
if ( $args['allow_to_check_expired'] ) {
$expired_where = ' AND (expired_date IS NULL OR expired_date > UNIX_TIMESTAMP()) AND (usage_limit IS NULL OR hits_count < usage_limit) ';
}
$query = $this->wpdb->prepare(
"SELECT * FROM {$this->tbl_name} WHERE id IN (%1s) AND is_activated = 1 AND ( campaign_app_type = %s {$like_where}) AND post_id = %d {$expired_where}", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder and put the $ids and the where sql string in quotes.
$password_ids_str,
$args['global_type'],
$args['post_id']
);
return $this->wpdb->get_results( $query ); // phpcs:ignore -- we already prepared above
}
/**
* Generate query to get password roles type in DB
*
* @param array $roles User roles.
*
* @return string
*/
private function generate_where_like_for_roles( $roles, $role_type ) {
$where_like_string = '';
$pcp_role = $role_type;
if ( is_array( $roles ) && count( $roles ) > 0 ) {
/**
* Generate roles to string with like condition.
* Example:
* ['editor,'admin'] to ' OR campaign_app_type LIKE '%editor% OR campaign_app_type LIKE '%admin%'
*/
$where_like_string = array_reduce(
$roles,
function ( $carry, $role ) use ( $pcp_role ) {
if ( ! empty( $role ) ) {
$carry = $carry . "OR campaign_app_type LIKE '%{$pcp_role}{$role};%' OR campaign_app_type LIKE '%{$pcp_role}{$role}' ";
}
return $carry;
}, $where_like_string );
$where_like_string = ! empty( $where_like_string ) ? $where_like_string : '';
}
return $where_like_string;
}
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Fired during plugin deactivation
*
* @link https://passwordprotectwp.com
* @since 1.0.0
*
* @package Password_Protect_Page
* @subpackage Password_Protect_Page/includes
*/
/**
* Fired during plugin deactivation.
*
* This class defines all code necessary to run during the plugin's deactivation.
*
* @since 1.0.0
* @package Password_Protect_Page
* @subpackage Password_Protect_Page/includes
* @author BWPS <hello@preventdirectaccess.com>
*/
class PPW_Deactivator {
/**
* Short Description. (use period)
*
* Long Description.
*
* @since 1.0.0
*/
public static function deactivate() {
PPW_Options_Services::get_instance()->delete_flag( PPW_Constants::MIGRATED_DEFAULT_PW );
PPW_Options_Services::get_instance()->delete_flag( PPW_Constants::MIGRATED_FREE_FLAG );
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* PPWP External Settings
*/
class PPW_External_Settings {
/**
* Render UI external submenu settings page.
*/
public function render_ui() {
$_get = wp_unslash( $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We no need to handle nonce verfication for render UI.
$head_title = is_pro_active_and_valid_license() ? 'PPWP Pro' : 'PPWP Lite';
?>
<div class="wrap">
<div id="icon-themes" class="icon32"></div>
<h2>
<?php echo esc_html__( $head_title . ': Integrations', 'password-protect-page' ); ?>
</h2>
<?php
$activated_tab = isset( $_get['tab'] ) ? $_get['tab'] : 'recaptcha';
$this->render_tabs( $activated_tab );
$this->render_content( $activated_tab );
?>
</div>
<?php
}
/**
* Get external tabs.
*
* @return array
*/
public function get_tabs() {
return apply_filters(
'ppw_external_tabs',
array(
array(
'tab' => 'recaptcha',
'tab_name' => 'reCAPTCHA',
),
array(
'tab' => 'configuration',
'tab_name' => 'Configuration',
),
)
);
}
/**
* Render tab for external page.
*
* @param string $active_tab Activate tab
*/
public function render_tabs( $active_tab ) {
$tabs = $this->get_tabs();
?>
<h2 class="ppwp_wrap_tab_title nav-tab-wrapper">
<?php
if ( ! is_array( $tabs ) ) {
return;
}
foreach ( $tabs as $tab ) {
if ( ! is_array( $tab ) ) {
continue;
}
if ( empty( $tab['tab'] ) || empty( $tab['tab_name'] ) ) {
continue;
}
?>
<a href="?page=<?php echo esc_html( PPW_Constants::EXTERNAL_SERVICES_PREFIX ); ?>&tab=<?php echo esc_attr( $tab['tab'] ); ?>"
class="nav-tab <?php echo $active_tab === $tab['tab'] ? 'nav-tab-active' : ''; ?>"><?php esc_attr_e( $tab['tab_name'], 'password-protect-page' ); ?></a>
<?php } ?>
</h2>
<?php
}
/**
* Render content
* @param string $active_tab Active Tab
*/
public function render_content( $active_tab ) {
$tabs = $this->get_tabs();
foreach ( $tabs as $tab ) {
if ( $active_tab === $tab['tab'] ) {
do_action( 'ppw_render_external_content_' . $tab['tab'] );
break;
}
}
}
}

View File

@@ -0,0 +1,747 @@
<?php
/**
* Check condition and include plugin.php file
*/
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
/**
* Escape a WP_Error object for passing directly to wp_die().
*
* The wp_die() function accepts an WP_Error object as the first parameter, but it
* does not escape it\'s contents before printing it out to the user. By passing
* the object through this function before giving it to wp_die(), the potential for
* XSS should be avoided.
*
* Example:
*
* wp_die( my_prefix_escape_wp_error( $error ) );
*
* @param WP_Error $error The error to escape.
*
* @return WP_Error The escaped error.
*/
function ppw_escape_wp_error( $error ) {
$code = $error->get_error_code();
$error_data = $error->error_data;
if ( isset( $error_data[ $code ]['title'] ) ) {
$error_data[ $code ]['title'] = wp_kses(
$error->error_data[ $code ]['title'],
'escape_wp_error_title'
);
$error->error_data = $error_data;
}
$all_errors = $error->errors;
foreach ( $all_errors as $code => $errors ) {
foreach ( $errors as $key => $message ) {
$all_errors[ $code ][ $key ] = wp_kses(
$message,
'escape_wp_error_message'
);
}
}
$error->errors = $all_errors;
return $error;
}
/**
* Check data before update setting
*
* @param array $request Request data.
* @param array $setting_keys Keys need to check.
* @param bool $is_check_cookie Is check cookie.
*
* @return bool
*/
function ppw_free_is_setting_data_invalid( $request, $setting_keys, $is_check_cookie = true ) {
if ( ppw_free_is_setting_keys_and_nonce_invalid( $request, PPW_Constants::GENERAL_FORM_NONCE ) ) {
return true;
}
$settings = $request['settings'];
foreach ( $setting_keys as $key ) {
if ( ! array_key_exists( $key, $settings ) ) {
return true;
}
}
if ( ! $is_check_cookie ) {
return false;
}
// Check regular expression.
return ppw_core_validate_cookie_expiry( $settings[ PPW_Constants::COOKIE_EXPIRED ] );
}
/**
* Check data before update entire site settings
*
* @param $request
*
* @return bool
*/
function ppw_free_is_entire_site_settings_data_invalid( $request ) {
return ppw_free_is_setting_keys_and_nonce_invalid( $request, PPW_Constants::ENTIRE_SITE_FORM_NONCE );
}
/**
* @param $request
* @param $nonce_key
*
* @return bool
*/
function ppw_free_is_setting_keys_and_nonce_invalid( $request, $nonce_key ) {
if ( ! array_key_exists( 'settings', $request ) ||
! array_key_exists( 'security_check', $request ) ) {
return true;
}
if ( ! wp_verify_nonce( $request['security_check'], $nonce_key ) ) {
return true;
}
return false;
}
/**
* Check error before create new password
*
* @param $request
* @param $setting_keys
*
* @return bool
*/
function ppw_free_error_before_create_password( $request, $setting_keys ) {
if ( ppw_free_is_setting_keys_and_nonce_invalid( $request, PPW_Constants::META_BOX_NONCE ) ) {
return true;
}
$settings = $request["settings"];
foreach ( $setting_keys as $key ) {
if ( ! array_key_exists( $key, $settings ) ) {
return true;
}
}
return false;
}
/**
* Validate password type is global
*
* @param $new_global_passwords
* @param $current_global_passwords
* @param $current_roles_password
*/
function ppw_free_validate_password_type_global( $new_global_passwords, $current_global_passwords, $current_roles_password ) {
if ( count( $new_global_passwords ) < 1 && empty( $current_global_passwords ) ) {
wp_send_json(
array(
'is_error' => true,
'message' => PPW_Constants::EMPTY_PASSWORD,
),
400
);
wp_die();
}
$global_validate = ppw_free_check_duplicate_global_password( $new_global_passwords, $current_roles_password );
if ( $global_validate ) {
wp_send_json(
array(
'is_error' => true,
'message' => PPW_Constants::DUPLICATE_PASSWORD,
),
400
);
wp_die();
}
}
/**
* Check case duplicate password type is global
*
* @param $new_global_passwords
* @param $current_roles_password
*
* @return bool
*/
function ppw_free_check_duplicate_global_password( $new_global_passwords, $current_roles_password ) {
if ( empty( $current_roles_password ) ) {
return false;
}
$password_duplicate = array_intersect( $new_global_passwords, array_values( $current_roles_password ) );
return ! empty( $password_duplicate );
}
/**
* Validate password type is role
*
* @param $role_selected
* @param $new_role_password
* @param $current_global_passwords
* @param $current_roles_password
*/
function ppw_free_validate_password_type_role( $role_selected, $new_role_password, $current_global_passwords, $current_roles_password ) {
if ( '' === $new_role_password && ( ! isset( $current_roles_password[ $role_selected ] ) || '' === $current_roles_password[ $role_selected ] ) ) {
wp_send_json(
array(
'is_error' => true,
'message' => PPW_Constants::EMPTY_PASSWORD,
),
400
);
wp_die();
}
$role_validate = ppw_free_check_duplicate_role_password( $new_role_password, $current_global_passwords );
if ( $role_validate ) {
wp_send_json(
array(
'is_error' => true,
'message' => PPW_Constants::DUPLICATE_PASSWORD,
),
400
);
wp_die();
}
}
/**
* Check case duplicate password type is role
*
* @param $new_role_password
* @param $current_global_passwords
*
* @return bool
*/
function ppw_free_check_duplicate_role_password( $new_role_password, $current_global_passwords ) {
if ( empty( $current_global_passwords ) ) {
return false;
}
$new_role_password = wp_unslash( $new_role_password );
return in_array( $new_role_password, $current_global_passwords );
}
/**
* Get all page and post
*
* @return array
*/
function ppw_free_get_all_page_post() {
return array_merge( get_pages(), get_posts( array( 'post_status' => 'publish', 'numberposts' => - 1 ) ) );
}
/**
* Helper to fix serialized data
* TODO: write UT for this important function
*
* @param $raw_data
* @param $is_un_slashed
*
* @return array
*/
function ppw_free_fix_serialize_data( $raw_data, $is_un_slashed = true ) {
if ( ! $raw_data ) {
return array();
}
if ( ! is_string( $raw_data ) ) {
if ( is_array( $raw_data ) ) {
return $raw_data;
}
return array();
}
$serialize_raw_data = @unserialize( $raw_data );
if ( false === $serialize_raw_data ) {
return $raw_data;
}
return $is_un_slashed ? wp_unslash( $serialize_raw_data ) : $serialize_raw_data;
}
/**
* @param $cookie
* @param $expiration
*
* @return bool
*/
function ppw_free_bypass_cache_with_cookie_for_pro_version( $cookie, $expiration ) {
if ( defined( 'COOKIEHASH' ) ) {
$cookie_hash = preg_quote( constant( 'COOKIEHASH' ) );
}
setcookie( PPW_Constants::WP_POST_PASS . $cookie_hash, $cookie, $expiration, COOKIEPATH, COOKIE_DOMAIN );
return true;
}
/**
* Check custom login form is showing to avoid conflict with the_password_form default of WordPress.
* - Check post type is default type ( post or page )
* - Do not show login form product type because we handled it in PPW Pro version. ( woocommerce_before_single_product
* hook )
* - If Pro version is active then we check protection type in setting to show login form
*
* @param string $post_type Post Type of Post.
*
* @return bool True|False Is show login form.
*/
function ppw_is_post_type_selected_in_setting( $post_type ) {
/**
* Check default post type
* Free & Pro version default: post and page type.
*/
if ( 'post' === $post_type || 'page' === $post_type ) {
return true;
}
$is_handle_old_product_type = apply_filters( PPW_Constants::HOOK_HANDLE_BEFORE_RENDER_WOO_PRODUCT, 'product' === $post_type, $post_type );
if ( $is_handle_old_product_type || ! class_exists( 'PPW_Pro_Constants' ) ) {
return false;
}
$post_type_selected = ppw_core_get_setting_type_array( PPW_Pro_Constants::WPP_WHITELIST_COLUMN_PROTECTIONS );
/**
* Check post type in setting which user selected.
*/
return in_array( $post_type, $post_type_selected, true );
}
/**
* Get post_id from referer url if Post data is not exist post_id.
*
* @return int post_id Post ID, 0 if post id not exist.
*/
function ppw_get_post_id_from_request() {
$_server = wp_unslash( $_SERVER );
$_post = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- We no need to handle nonce verification for this function.
if ( isset( $_post['post_id'] ) ) {
return (int) wp_unslash( $_post['post_id'] );
}
/**
* Make sure http referer on server.
* Not make exception in url_to_postid.
*/
if ( ! isset( $_server['HTTP_REFERER'] ) ) {
return 0;
}
// Get post id from referer url.
return url_to_postid( $_server['HTTP_REFERER'] );
}
/**
* WP introduced is_wp_version_compatible function from version 5.2.0 only.
* (https://developer.wordpress.org/reference/functions/is_wp_version_compatible/)
* Need to write the helper by our-self.
*
* @param string $required Version to check.
*
* @return bool
*/
function ppw_is_wp_version_compatible( $required ) {
return empty( $required ) || version_compare( get_bloginfo( 'version' ), $required, '>=' );
}
/**
* Get page title for home, category, tag or post
*
* @return string
*/
function ppw_get_page_title() {
$site_title = get_bloginfo( 'title' );
$site_description = get_bloginfo( 'description' );
$post_title = wp_title( '', false ); // Post title, category tile, tag title.
$dash_score_site = '' === $site_title || '' === $site_description ? '' : ' ';
$dash_score_post = '' === $site_title || '' === $post_title ? '' : ' ';
return is_home() || is_front_page()
? sprintf( '%1$s%2$s%3$s', $site_title, $dash_score_site, $site_description )
: sprintf( '%1$s%2$s%3$s', $post_title, $dash_score_post, $site_title );
}
/**
* Get post excerpt if post is protected via Settings.
*
* @param WP_Post $post Post WordPress Object.
* @param string $content Content of post.
* @param bool $is_show_excerpt Is show excerpt.
* TODO: Need to refactor logic for this function.
*
* @return string
*/
function ppw_handle_protected_content( $post, $content, $is_show_excerpt ) {
if ( $is_show_excerpt && $post->post_excerpt ) {
$content = $post->post_excerpt . $content;
}
if ( ! is_singular() && ! preg_match( '/name=.+post_id/mi', $content ) ) {
$content = '<em>[This is password-protected.]</em>';
return apply_filters( 'the_ppw_password_message', $content );
}
return $content;
}
/**
* Helper function to get Pro version.
*/
function ppw_get_pro_version() {
if ( ! defined( 'PPW_PRO_VERSION' ) ) {
return '';
}
return PPW_PRO_VERSION;
}
/**
* Bypass function using to
* - Display feed content when user turn on sitewide protection.
*
* @return bool True is bypass sitewide.
*/
function ppw_free_has_bypass_sitewide_protection() {
$has_bypass = defined( 'PPWP_SITEWIDE_FEED_DISPLAY' ) && PPWP_SITEWIDE_FEED_DISPLAY && is_feed();
return apply_filters( 'ppwp_sitewide_has_bypass', $has_bypass );
}
/**
* Bypass function using to
* - Display feed content when post/page is protected by single protection.
*
* @return bool True is bypass post_password_required.
*/
function ppw_free_has_bypass_single_protection() {
$has_bypass = defined( 'PPWP_SINGLE_FEED_DISPLAY' ) && PPWP_SINGLE_FEED_DISPLAY && is_feed();
return apply_filters( 'ppwp_single_has_bypass', $has_bypass );
}
/**
* Has support PPWP shortcode for page builder.
*
* @return bool
*/
function ppw_free_has_support_shortcode_page_builder() {
// Have user turn on option.
$enabled = ppw_core_get_setting_type_bool_by_option_name( PPW_Constants::USE_SHORTCODE_PAGE_BUILDER, PPW_Constants::SHORTCODE_OPTIONS );
return apply_filters( 'ppwp_shortcode_enable_page_builder', $enabled );
}
/**
* Checks the plaintext password against the encrypted Password.
*
* @param string $password Plaintext user's password
* @param string $hash Hash of the user's password to check against.
*
* @return bool False, if the $password does not match the hashed password
* @link https://developer.wordpress.org/reference/functions/wp_check_password/
*/
function ppw_free_check_password( $password, $hash ) {
global $wp_hasher;
// If the stored hash is longer than an MD5,
// presume the new style phpass portable hash.
if ( empty( $wp_hasher ) ) {
require_once ABSPATH . WPINC . '/class-phpass.php';
// By default, use the portable hash from phpass.
$wp_hasher = new PasswordHash( 8, true );
}
return $wp_hasher->CheckPassword( $password, $hash );
}
/**
* Retrieve the shortcode matches for searching.
*
* @param $content
*
* @return array The regular expression contains 6 different sub matches to help with parsing.
* 1 - An extra [ to allow for escaping shortcodes with double [[]]
* 2 The shortcode name
* 3 The shortcode argument list
* 4 The self closing /
* 5 The content of a shortcode when it wraps some content.
* 6 An extra ] to allow for escaping shortcodes with double [[]]
*/
function ppw_free_search_shortcode_content( $content ) {
preg_match_all( '/' . get_shortcode_regex( array( 'ppwp' ) ) . '/', $content, $matches, PREG_SET_ORDER );
return $matches;
}
function ppw_free_valid_pcp_password( $shortcode, $password ) {
$default_args = array(
'is_valid_password' => false,
'atts' => array(),
);
// Check ppwp shortcode exist.
if ( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME !== $shortcode[2] || ! isset( $shortcode[3] ) ) {
return $default_args;
}
// Parse shortcode string to array.
$parsed_atts = shortcode_parse_atts( trim( $shortcode[3] ) );
// Get attributes from shortcode.
$atts = PPW_Shortcode::get_instance()->get_attributes( $parsed_atts );
$passwords = apply_filters( PPW_Constants::HOOK_SHORTCODE_PASSWORDS, array_filter( $atts['passwords'], 'strlen' ), $parsed_atts );
// Check password exist.
if ( in_array( $password, $passwords, true ) ) {
$default_args['is_valid_password'] = true;
$default_args['atts'] = $atts;
}
if ( isset( $parsed_atts['error_msg'] ) ) {
$default_args['message'] = wp_kses_post( $parsed_atts['error_msg'] );
}
return apply_filters( 'ppw_validated_pcp_password', $default_args, $password, $parsed_atts, $shortcode );
}
/**
* Validate date.
*
* @param $date
* @param string $format
*
* @return bool
*/
function ppw_free_validate_date( $date ) {
return false !== strtotime( $date );
}
function ppw_get_background_image( $image ) {
$img = get_theme_mod( 'ppwp_pro_form_background_image', '' );
if ( ! empty( $img ) ) {
return $img;
}
return PPW_DIR_URL . 'includes/customizers/assets/images/backgrounds/' . $image;
}
/**
* Support with builder plugin.
*
* @param integer $post_id Post ID.
* @param string $post_content Post Content.
*
* @return string Post Content.
*/
function ppw_support_third_party_content_plugin( $post_id, $post_content ) {
if ( method_exists( '\WPBMap', 'addAllMappedShortcodes' ) ) {
\WPBMap::addAllMappedShortcodes();
}
if ( class_exists( '\TablePress' ) ) {
\TablePress::$controller = \TablePress::load_controller( 'frontend' );
\TablePress::$controller->init_shortcodes();
}
if ( class_exists( '\\Elementor\\Plugin' ) ) {
if ( \Elementor\Plugin::$instance->db->is_built_with_elementor( $post_id ) ) {
// Disable function check post_password_required because need to get content show to user.
remove_all_filters( 'post_password_required' );
$post_content = \Elementor\Plugin::$instance->frontend->get_builder_content( $post_id, true );
}
}
return apply_filters( 'ppw_content_compatibility', $post_content );
}
/**
* Get PPWP Pro plugin data version.
*
* @return false|string
*/
function ppw_get_pro_data_version() {
if ( defined( 'PPW_PRO_VERSION' ) ) {
return PPW_PRO_VERSION;
}
if ( ! function_exists( 'get_plugins' )
|| ! function_exists( 'is_plugin_active' )
|| ! function_exists( 'get_plugins' )
) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
// Check plugin is active from option data.
if ( ! is_plugin_active( PPW_Constants::PRO_DIRECTORY ) && ! is_plugin_active( PPW_Constants::DEV_PRO_DIRECTORY ) ) {
return false;
}
// Get plugin version from file.
$installed_plugins = get_plugins();
// Get Pro Production folder version.
if ( isset( $installed_plugins[ PPW_Constants::PRO_DIRECTORY ], $installed_plugins[ PPW_Constants::PRO_DIRECTORY ]['Version'] ) ) {
return $installed_plugins[ PPW_Constants::PRO_DIRECTORY ]['Version'];
}
// Get Pro Development folder version.
if ( isset( $installed_plugins[ PPW_Constants::DEV_PRO_DIRECTORY ], $installed_plugins[ PPW_Constants::DEV_PRO_DIRECTORY ]['Version'] ) ) {
return $installed_plugins[ PPW_Constants::DEV_PRO_DIRECTORY ]['Version'];
}
return false;
}
/**
* Get allowed capability.
*
* @return string
*/
function ppw_get_allowed_capability() {
if ( current_user_can( 'manage_options' ) ) {
return 'manage_options';
}
return 'ppwp_manage_options';
}
/**
* Allow user to display all PPWP option.
*
* @return bool
*/
function ppw_allow_manage_passwords() {
$capability = ppw_get_allowed_capability();
return current_user_can( $capability ) || current_user_can( 'edit_posts' );
}
function ppw_allowed_master_protection_type() {
return apply_filters( 'ppw_allowed_master_protection_type', false );
}
function ppw_get_current_user_agent() {
return ! empty( $server_env['HTTP_USER_AGENT'] ) ? $server_env['HTTP_USER_AGENT'] : 'N/A';
}
function ppw_get_current_ip_address() {
$server = wp_unslash( $_SERVER );
if ( ! empty( $server['HTTP_CF_CONNECTING_IP'] ) ) {
return $server['HTTP_CF_CONNECTING_IP'];
}
if ( ! empty( $server['HTTP_CLIENT_IP'] ) ) {
return $server['HTTP_CLIENT_IP'];
}
if ( ! empty( $server['HTTP_X_FORWARDED_FOR'] ) ) {
return $server['HTTP_X_FORWARDED_FOR'];
}
return $server['REMOTE_ADDR'];
}
/**
* Get current user name.
*
* @return string
*/
function ppw_get_current_username() {
$current_user = wp_get_current_user();
return 0 === $current_user->ID ? 'N/A' : $current_user->user_login;
}
function ppw_tracking_master_password( $post_id, $password, $type = 'single' ) {
$meta_data = array(
'protection_type' => $type,
);
$meta_data = apply_filters( 'ppw_master_pcp_password_meta', $meta_data );
$meta_data_encoded = wp_json_encode( $meta_data );
$data = array(
'user_agent' => ppw_get_current_user_agent(),
'ip_address' => ppw_get_current_ip_address(),
'password' => $password,
'username' => ppw_get_current_username(),
'post_type' => 'ppwp_master',
'access_date' => time(),
'post_id' => $post_id,
'meta_data' => $meta_data_encoded,
);
do_action( 'ppwp_track_password', $data );
}
function ppw_get_pcp_post_content_with_third_party( $post, $index ) {
$allowed = did_action( 'elementor/loaded' );
$allowed = apply_filters( 'ppw_pcp_third_party_content_allowed', $allowed );
if ( ! $allowed ) {
return false;
}
setup_postdata( $post );
$post_content = ppw_support_third_party_content_plugin( $post->ID, false );
if ( empty( $post_content ) ) {
return false;
}
wp_reset_postdata();
$matches = ppw_free_search_shortcode_content( $post_content );
if ( isset( $matches[ $index ] ) ) {
$new_shortcode = $matches[ $index ];
return isset( $new_shortcode[5] ) ? $new_shortcode[5] : false;
}
return false;
}
function ppw_get_value( $data, $key, $default = '' ) {
if ( ! isset( $data[ $key ] ) ) {
return $default;
}
return $data[ $key ];
}
function ppw_free_render_sidebar() {
if ( ! is_pro_active_and_valid_license() ) {
include PPW_DIR_PATH . 'includes/views/sidebar/view-ppw-sidebar.php';
} else {
do_action( PPW_Constants::HOOK_SIDEBAR_SHORTCODE );
}
}
function ppw_get_utc() {
$min = 60 * get_option('gmt_offset');
$sign = $min < 0 ? "-" : "+";
$absmin = abs($min);
return sprintf("UTC%s%02d:%02d", $sign, $absmin/60, $absmin%60);
}
function ppw_get_terms_with_all_lang( $args ) {
global $sitepress;
if ( $sitepress ) {
remove_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ) );
remove_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ) );
remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) );
$terms = get_terms( $args );
add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10, 4 );
add_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ), 1, 1 );
add_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ), 10, 2 );
} else {
$terms = get_terms( $args );
}
return $terms;
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* Define the internationalization functionality
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @link https://passwordprotectwp.com
* @since 1.0.0
*
* @package Password_Protect_Page
* @subpackage Password_Protect_Page/includes
*/
/**
* Define the internationalization functionality.
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @since 1.0.0
* @package Password_Protect_Page
* @subpackage Password_Protect_Page/includes
* @author BWPS <hello@preventdirectaccess.com>
*/
class PPW_i18n {
/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain(
'password-protect-page',
false,
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
);
}
}

View File

@@ -0,0 +1,139 @@
<?php
/**
* Register all actions and filters for the plugin
*
* @link https://passwordprotectwp.com
* @since 1.0.0
*
* @package Password_Protect_Page
* @subpackage Password_Protect_Page/includes
*/
/**
* Register all actions and filters for the plugin.
*
* Maintain a list of all hooks that are registered throughout
* the plugin, and register them with the WordPress API. Call the
* run function to execute the list of actions and filters.
*
* @package Password_Protect_Page
* @subpackage Password_Protect_Page/includes
* @author BWPS <hello@preventdirectaccess.com>
*/
class PPW_Loader {
/**
* The array of actions registered with WordPress.
*
* @since 1.0.0
* @access protected
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
*/
protected $actions;
/**
* The array of filters registered with WordPress.
*
* @since 1.0.0
* @access protected
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
*/
protected $filters;
/**
* Initialize the collections used to maintain the actions and filters.
*
* @since 1.0.0
*/
public function __construct() {
$this->actions = array();
$this->filters = array();
}
/**
* Add a new action to the collection to be registered with WordPress.
*
* @since 1.0.0
* @param string $hook The name of the WordPress action that is being registered.
* @param object $component A reference to the instance of the object on which the action is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
*/
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* Add a new filter to the collection to be registered with WordPress.
*
* @since 1.0.0
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
*/
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* Add new short code to the collection to be registered with WordPress.
*
* @param $tag
* @param $component
* @param $callback
*/
public function add_shortcode ( $tag, $component, $callback ) {
add_shortcode( $tag, array ( $component, $callback) );
}
/**
* A utility function that is used to register the actions and hooks into a single
* collection.
*
* @since 1.0.0
* @access private
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the $callback.
* @return array The collection of actions and filters registered with WordPress.
*/
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
$hooks[] = array(
'hook' => $hook,
'component' => $component,
'callback' => $callback,
'priority' => $priority,
'accepted_args' => $accepted_args
);
return $hooks;
}
/**
* Register the filters and actions with WordPress.
*
* @since 1.0.0
*/
public function run() {
foreach ( $this->filters as $hook ) {
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
foreach ( $this->actions as $hook ) {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* PPWP Partial Protection Settings
*/
if ( ! class_exists( 'PPW_Partial_Protection_Settings' ) ) {
class PPW_Partial_Protection_Settings {
/**
* Render UI for Partial Protection page.
*/
public function render_ui() {
$_get = wp_unslash( $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We no need to handle nonce verfication for render UI.
$head_title = is_pro_active_and_valid_license() ? 'PPWP Pro' : 'PPWP Lite';
?>
<div class="wrap">
<h2><?php echo esc_html__( $head_title . ': Partial Protection', 'password-protect-page' ) ?></h2>
<?php
$default_tab = apply_filters( PPW_Constants::HOOK_PCP_TAB, 'general' );
$active_tab = isset( $_get['tab'] ) ? $_get['tab'] : $default_tab;
$this->render_tabs( $active_tab );
$this->render_content( $active_tab );
?>
</div>
<?php
}
/**
* Render tab for Partial Protection page.
*
* @param string $active_tab Active tab.
*/
public function render_tabs( $active_tab ) {
$tabs = apply_filters(
PPW_Constants::HOOK_ADD_NEW_PCP_SUBMENU,
array(
array(
'tab' => 'general',
'tab_name' => 'General',
),
)
);
?>
<h2 class="ppwp_wrap_tab_title nav-tab-wrapper">
<?php
if ( ! is_array( $tabs ) ) {
return;
}
foreach ( $tabs as $tab ) {
if ( ! is_array( $tab ) ) {
continue;
}
if ( empty( $tab['tab'] ) || empty( $tab['tab_name'] ) ) {
continue;
}
if ( isset( $tab['link'] ) ) {
$link = $tab['link'];
} else {
$link = '?page=' . esc_html( PPW_Constants::PCP_PAGE_PREFIX ) . '&tab=' . esc_attr( $tab['tab'] );
}
?>
<a href="<?php echo esc_url( $link ); ?>"
class="nav-tab <?php echo $active_tab === $tab['tab'] ? 'nav-tab-active' : ''; ?>"><?php esc_attr_e( $tab['tab_name'], 'password-protect-page' ); ?></a>
<?php } ?>
</h2>
<?php
}
/**
* Render content for Partial Protection page.
*
* @param string $active_tab Active tab.
*/
public function render_content( $active_tab ) {
$tabs = apply_filters( PPW_Constants::HOOK_CUSTOM_PCP_TAB, array( 'general' ) );
foreach ( $tabs as $tab ) {
if ( $active_tab === $tab ) {
do_action( PPW_Constants::HOOK_RENDER_CONTENT_FOR_PCP_TAB . $tab );
break;
}
}
}
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* PPWP Settings
*/
if ( ! class_exists( "PPW_Settings" ) ) {
class PPW_Settings {
/**
* Render UI settings page
*/
public function render_ui() {
$_get = wp_unslash( $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We no need to handle nonce verification for render UI.
$plugin_info = apply_filters( PPW_Constants::HOOK_PLUGIN_INFO, array(
'name' => 'Password Protect WordPress - PPWP',
'version' => PPW_VERSION,
) );
?>
<div class="wrap">
<div id="icon-themes" class="icon32"></div>
<h2>
<?php esc_html_e( $plugin_info['name'], 'password-protect-page' ); ?>
<span class="ppwp_version"><?php esc_html_e( $plugin_info['version'] ) ?></span>
</h2>
<?php
$default_tab = apply_filters( PPW_Constants::HOOK_DEFAULT_TAB, 'general' );
$activate_tab = isset( $_get['tab'] ) ? $_get['tab'] : $default_tab;
$this->render_tabs( $activate_tab );
$this->render_content( $activate_tab );
?>
</div>
<?php
}
/**
* Render tab for settings page
*
* @param string $active_tab Active tab.
*/
private function render_tabs( $active_tab ) {
$tabs = apply_filters(
PPW_Constants::HOOK_ADD_NEW_TAB,
array(
array(
'tab' => 'general',
'tab_name' => 'General',
),
array(
'tab' => 'misc',
'tab_name' => 'Advanced',
),
array(
'tab' => 'entire_site',
'tab_name' => 'Sitewide',
),
array(
'tab' => 'shortcodes',
'tab_name' => 'Shortcodes',
),
array(
'tab' => 'master_passwords',
'tab_name' => 'Master Passwords',
),
array(
'tab' => 'troubleshooting',
'tab_name' => 'Troubleshooting',
)
)
);
?>
<h2 class="ppwp_wrap_tab_title nav-tab-wrapper">
<?php
if ( ! is_array( $tabs ) ) {
return;
}
foreach ( $tabs as $tab ) {
if ( ! is_array( $tab ) ) {
continue;
}
if ( empty( $tab['tab'] ) || empty( $tab['tab_name'] ) ) {
continue;
}
?>
<a href="?page=<?php echo esc_html( PPW_Constants::MENU_NAME ); ?>&tab=<?php echo esc_attr( $tab['tab'] ); ?>"
class="nav-tab <?php echo $active_tab === $tab['tab'] ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( $tab['tab_name'], PPW_Constants::DOMAIN ); ?></a>
<?php } ?>
</h2>
<?php
}
/**
* Render content for settings page
*
* @param string $active_tab Active tab.
*/
private function render_content( $active_tab ) {
$tabs = apply_filters( PPW_Constants::HOOK_CUSTOM_TAB, array( 'general', 'misc', 'entire_site', 'shortcodes', 'master_passwords', 'troubleshooting' ) );
foreach ( $tabs as $tab ) {
if ( $active_tab === $tab ) {
do_action( PPW_Constants::HOOK_RENDER_CONTENT_FOR_TAB . $tab );
break;
}
}
}
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* PPWP Sitewide Settings
*/
if ( ! class_exists( 'PPW_Sitewide_Settings' ) ) {
class PPW_Sitewide_Settings {
/**
* Render UI sitewide submenu settings page
*/
public function render_ui() {
$_get = wp_unslash( $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We no need to handle nonce verification for render UI.
$head_title = is_pro_active_and_valid_license() ? 'PPWP Pro' : 'PPWP Lite';
?>
<div class="wrap">
<div id="icon-themes" class="icon32"></div>
<h2>
<?php echo esc_html__( $head_title . ': Sitewide Protection', 'password-protect-page' ); ?>
</h2>
<?php
$general_tab = apply_filters( PPW_Constants::HOOK_SITEWIDE_TAB, 'general' );
$activated_tab = isset( $_get['tab'] ) ? $_get['tab'] : $general_tab;
$this->render_tabs( $activated_tab );
$this->render_content( $activated_tab );
?>
</div>
<?php
}
/**
* Render tab for sitewide page
*
* @param string $active_tab Activate tab
*/
public function render_tabs( $active_tab ) {
$tabs = apply_filters(
PPW_Constants::HOOK_ADD_NEW_SITEWIDE_SUBMENU,
array(
array(
'tab' => 'general',
'tab_name' => 'General',
),
)
);
?>
<h2 class="ppwp_wrap_tab_title nav-tab-wrapper">
<?php
if ( ! is_array( $tabs ) ) {
return;
}
foreach ( $tabs as $tab ) {
if ( ! is_array( $tab ) ) {
continue;
}
if ( empty( $tab['tab'] ) || empty( $tab['tab_name'] ) ) {
continue;
}
?>
<a href="?page=<?php echo esc_html( PPW_Constants::SITEWIDE_PAGE_PREFIX ); ?>&tab=<?php echo esc_attr( $tab['tab'] ); ?>"
class="nav-tab <?php echo $active_tab === $tab['tab'] ? 'nav-tab-active' : ''; ?>"><?php esc_attr_e( $tab['tab_name'], PPW_Constants::DOMAIN ); ?></a>
<?php } ?>
</h2>
<?php
}
/**
* Render the content
* @param string $active_tab Active Tab
*/
public function render_content( $active_tab ) {
$tabs = apply_filters( PPW_Constants::HOOK_CUSTOM_SITEWIDE_TAB, array( 'general' ) );
foreach ( $tabs as $tab ) {
if ( $active_tab === $tab ) {
do_action( PPW_Constants::HOOK_RENDER_CONTENT_FOR_SITEWIDE_TAB . $tab );
break;
}
}
}
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* PPWP Class for Uninstall plugin
*/
if ( ! class_exists( 'PPW_Uninstall' ) ) {
class PPW_Uninstall {
/**
* Uninstall plugin
*/
public static function uninstall() {
self::handle_uninstall_plugin();
}
/**
* Handle uninstall plugin
*/
private static function handle_uninstall_plugin() {
if ( is_multisite() ) {
foreach ( get_sites() as $site ) {
$blog_id = $site->blog_id;
if ( ppw_core_get_setting_type_bool( PPW_Constants::REMOVE_DATA, $blog_id ) ) {
global $wpdb;
self::delete_general_option( $blog_id );
self::delete_entire_site_option( $blog_id );
$wp_prefix = $wpdb->get_blog_prefix( $blog_id );
ppw_core_delete_data_in_post_meta_by_meta_key( PPW_Constants::POST_PROTECTION_ROLES, $wp_prefix );
ppw_core_delete_data_in_post_meta_by_meta_key( PPW_Constants::GLOBAL_PASSWORDS, $wp_prefix );
}
}
} else {
if ( ppw_core_get_setting_type_bool( PPW_Constants::REMOVE_DATA ) ) {
self::delete_general_option();
self::delete_entire_site_option();
ppw_core_delete_data_in_post_meta_by_meta_key( PPW_Constants::POST_PROTECTION_ROLES );
ppw_core_delete_data_in_post_meta_by_meta_key( PPW_Constants::GLOBAL_PASSWORDS );
}
}
}
/**
* Handle delete general option
*
* @param $site_id
*/
private static function delete_general_option( $site_id = false ) {
$settings = ! $site_id ? get_option( PPW_Constants::GENERAL_OPTIONS ) : get_blog_option( $site_id, PPW_Constants::GENERAL_OPTIONS );
if ( ! $settings ) {
return;
}
$options = json_decode( $settings );
if ( ! is_object( $options ) ) {
return;
}
$new_options = (array) $options;
unset( $new_options[ PPW_Constants::COOKIE_EXPIRED ] );
unset( $new_options[ PPW_Constants::REMOVE_DATA ] );
if ( ! $site_id ) {
update_option( PPW_Constants::GENERAL_OPTIONS, wp_json_encode( $new_options ) );
} else {
update_blog_option( $site_id, PPW_Constants::GENERAL_OPTIONS, wp_json_encode( $new_options ) );
}
}
/**
* Handle delete entire site option
*
* @param $site_id
*/
private static function delete_entire_site_option( $site_id = false ) {
$options = ! $site_id ? get_option( PPW_Constants::ENTIRE_SITE_OPTIONS ) : get_blog_option( $site_id, PPW_Constants::ENTIRE_SITE_OPTIONS );
if ( ! $options ) {
return;
}
if ( ! is_array( $options ) ) {
return;
}
unset( $options[ PPW_Constants::IS_PROTECT_ENTIRE_SITE ] );
unset( $options[ PPW_Constants::PASSWORD_ENTIRE_SITE ] );
if ( ! $site_id ) {
update_option( PPW_Constants::ENTIRE_SITE_OPTIONS, $options );
} else {
update_blog_option( $site_id, PPW_Constants::ENTIRE_SITE_OPTIONS, $options );
}
}
}
}

View File

@@ -0,0 +1,478 @@
<?php
/**
* The file that defines the core plugin class
*
* A class definition that includes attributes and functions used across both the
* public-facing side of the site and the admin area.
*
* @link https://passwordprotectwp.com
* @since 1.0.0
*
* @package Password_Protect_Page
* @subpackage Password_Protect_Page/includes
*/
/**
* The core plugin class.
*
* This is used to define internationalization, admin-specific hooks, and
* public-facing site hooks.
*
* Also maintains the unique identifier of this plugin as well as the current
* version of the plugin.
*
* @since 1.0.0
* @package Password_Protect_Page
* @subpackage Password_Protect_Page/includes
* @author BWPS <hello@preventdirectaccess.com>
*/
class Password_Protect_Page {
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @access protected
* @var PPW_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The unique identifier of this plugin.
*
* @since 1.0.0
* @access protected
* @var string $plugin_name The string used to uniquely identify this plugin.
*/
protected $plugin_name;
/**
* The current version of the plugin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @since 1.0.0
*/
public function __construct() {
if ( defined( 'PPW_VERSION' ) ) {
$this->version = PPW_VERSION;
} else {
$this->version = '1.0.0';
}
$this->plugin_name = 'password-protect-page';
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_public_hooks();
}
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - Password_Protect_Page_Loader. Orchestrates the hooks of the plugin.
* - Password_Protect_Page_i18n. Defines internationalization functionality.
* - Password_Protect_Page_Admin. Defines all hooks for the admin area.
* - Password_Protect_Page_Public. Defines all hooks for the public side of the site.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function load_dependencies() {
/**
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ppw-loader.php';
/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ppw-i18n.php';
/**
* Require Constants
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ppw-constants.php';
/**
* Require Functions
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ppw-functions.php';
/**
* Require Service Interfaces
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'core/class-ppw-service-interfaces.php';
/**
* Require Options Services
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-options.php';
/**
* Require Recaptcha Services Class
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-recaptcha.php';
/**
* Require Services Class
* TODO: need to rename for meaningful idea.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-passwords.php';
/**
* The class responsible for subscribe services
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-subscribe.php';
/**
* The class responsible for defining all actions that occur in the admin area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-assets.php';
/**
* The class responsible for caching service
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-cache.php';
/**
* The class responsible for settings
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . '/includes/class-ppw-settings.php';
/**
* The class responsible for sitewide settings
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . '/includes/class-ppw-sitewide-settings.php';
/**
* The class responsible for external settings
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . '/includes/class-ppw-external-settings.php';
/**
* The class responsible for shortcode settings
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . '/includes/class-ppw-partial-protection-settings.php';
/**
* The class responsible for entire site services
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-entire-site.php';
/**
* The class responsible for shortcode service
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-shortcode.php';
/**
* The class responsible for API declaration
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ppw-api.php';
/**
* The class responsible for core functions
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'core/class-ppw-functions.php';
/**
* The class responsible for defining all actions that occur in the admin area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ppw-admin.php';
/**
* The class responsible for defining all actions that occur in the public-facing
* side of the site.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-ppw-public.php';
/**
* The class responsible for defining all actions that occur in the customizer
* side of the site.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-customizer.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-customizer-sitewide.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-customizer-upsell.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-customizer-pcp.php';
/**
* The class responsible for defining all addons.
*/
require_once PPW_DIR_PATH . 'includes/addons/beaver-builder/class-ppw-beaver-loader.php';
require_once PPW_DIR_PATH . 'includes/addons/elementor/class-ppw-elementor.php';
/**
* The class responsible for defining database functions.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ppw-db.php';
/**
* The class responsible for defining protect category.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-category.php';
/**
* The class responsible for defining protect category.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-content-protection.php';
/**
* The class responsible for plugin SDK
*/
if ( is_pro_active_and_valid_license() ) {
// Need the load the pro lib first that using for the other add-ons.
ppw_core_load_pro_lib();
}
$this->loader = new PPW_Loader();
$pro_version = ppw_get_pro_data_version();
if ( $pro_version && version_compare( $pro_version, '1.3.2', '<' ) ) {
if ( function_exists( 'wp_get_theme' ) ) {
$curr_theme = wp_get_theme();
$theme_name = $curr_theme->get( 'Name' );
if ( method_exists( $curr_theme, 'get' )
&& in_array( $theme_name, array( 'Edubin', 'StoreVilla' ) ) ) {
require_once( ABSPATH . WPINC . '/class-wp-customize-section.php' );
}
}
require_once( ABSPATH . WPINC . '/class-wp-customize-control.php' );
}
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the Password_Protect_Page_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function set_locale() {
$plugin_i18n = new PPW_i18n();
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
}
/**
* Register all of the hooks related to the admin area functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_admin_hooks() {
$plugin_admin = new PPW_Admin( $this->get_plugin_name(), $this->get_version() );
PPW_Customizer_Service::get_instance();
PPW_Customizer_Sitewide::register_themes();
PPW_Recaptcha::get_instance()->register();
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_assets' );
$this->loader->add_action( 'admin_menu', $plugin_admin, 'ppw_add_menu', 10 );
$this->loader->add_action( 'admin_notices', $plugin_admin, 'handle_admin_notices', 10 );
$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'ppw_free_add_custom_meta_box_to_edit_page' );
$this->loader->add_action( 'login_form_ppw_postpass', $plugin_admin, 'ppw_handle_enter_password' );
// Hook to handle default action WordPress which use our plugin.
$this->loader->add_action( 'login_form_postpass', $plugin_admin, 'ppw_handle_enter_password_for_default_action' );
$this->loader->add_action( 'template_redirect', $plugin_admin, 'ppw_render_form_entire_site' );
$this->loader->add_action( 'ppw_redirect_after_enter_password', $plugin_admin, 'ppw_handle_redirect_after_enter_password' );
$this->loader->add_action( 'admin_init', $plugin_admin, 'handle_admin_init' );
$this->load_base();
if ( ! is_pro_active_and_valid_license() ) {
PPW_Customizer_Sitewide::get_instance()->register_sitewide_form();
PPW_Customizer_Upsell::get_instance();
$this->loader->add_action( 'wp_ajax_ppw_free_set_password', $plugin_admin, 'ppw_free_set_password' );
$this->loader->add_filter( 'ppwp_customize_password_form', $plugin_admin, 'render_custom_below_description' );
$this->loader->add_action( 'wp_ajax_ppw_free_update_general_settings', $plugin_admin, 'ppw_free_update_general_settings' );
$this->loader->add_action( 'wp_ajax_ppw_free_update_entire_site_settings', $plugin_admin, 'ppw_free_update_entire_site_settings' );
$this->loader->add_action( 'admin_init', $plugin_admin, 'handle_admin_init_when_pro_is_not_activate' );
$this->loader->add_action( 'ppw_render_content_general', $plugin_admin, 'ppw_free_render_content_general', 10 );
$this->loader->add_action( 'ppw_render_content_entire_site', $plugin_admin, 'ppw_free_render_content_entire_site', 11 );
$this->loader->add_filter( 'post_password_required', $plugin_admin, 'ppw_handle_post_password_required', 10, 2 );
$this->loader->add_filter( PPW_Constants::HOOK_CUSTOM_TAB, $plugin_admin, 'ppw_handle_custom_tab', 50 );
$this->loader->add_filter( PPW_Constants::HOOK_ADD_NEW_TAB, $plugin_admin, 'ppw_handle_add_new_tab', 50 );
$this->loader->add_filter( PPW_Constants::HOOK_CUSTOM_TAB, $plugin_admin, 'ppw_handle_hide_shortcode_content', 50 );
$this->loader->add_filter( PPW_Constants::HOOK_ADD_NEW_TAB, $plugin_admin, 'ppw_handle_hide_shortcode_tab', 50 );
$this->loader->add_action( 'ppw_render_sitewide_content_general', $plugin_admin, 'ppw_free_render_content_entire_site', 10 );
// Testing only the new feature that applied for free only.
$this->loader->add_shortcode( 'ppw-content-protect', $plugin_admin, 'handle_content_protect_short_code' );
$this->loader->add_action( 'post_row_actions', $plugin_admin, 'ppw_custom_row_action', 10, 2 );
$this->loader->add_action( 'page_row_actions', $plugin_admin, 'ppw_custom_row_action', 10, 2 );
$this->loader->add_action( 'wp_ajax_ppw_update_post_status', $plugin_admin, 'handle_update_post_status' );
$post_types = array( 'post', 'page' );
foreach ( $post_types as $post_type ) {
$this->loader->add_filter( 'manage_' . $post_type . '_posts_columns', $plugin_admin, 'add_custom_column' );
$this->loader->add_action( 'manage_' . $post_type . '_posts_custom_column', $plugin_admin, 'render_content_custom_column', 10, 2 );
}
PPW_Category_Service::get_instance()->register( false );
} else {
$this->loader->add_action( 'plugins_loaded', $plugin_admin, 'handle_plugin_loaded' );
$this->loader->add_action( 'admin_init', $plugin_admin, 'update_column_for_ppwp_pro' );
PPW_Category_Service::get_instance()->register( true );
}
PPW_Customizer_Sitewide::get_instance()->register_sitewide_style();
$this->loader->add_action( 'wp_ajax_ppw_free_update_misc_settings', $plugin_admin, 'ppw_free_update_misc_settings' );
$this->loader->add_action( 'wp_ajax_ppw_free_update_category_settings', $plugin_admin, 'ppw_free_update_category_settings' );
$this->loader->add_action( 'wp_ajax_ppw_free_update_shortcode_settings', $plugin_admin, 'ppw_free_update_shortcode_settings' );
$this->loader->add_action( 'wp_ajax_ppw_free_update_external_settings', $plugin_admin, 'ppw_free_update_external_settings' );
$this->loader->add_action( 'wp_ajax_ppw_free_restore_wp_passwords', $plugin_admin, 'ppw_free_restore_wp_passwords' );
$this->loader->add_action( 'ppw_render_content_shortcodes', $plugin_admin, 'ppw_free_render_content_shortcodes', 11 );
$this->loader->add_action( 'ppw_render_content_master_passwords', $plugin_admin, 'ppw_free_render_content_master_passwords', 11 );
$this->loader->add_action( 'ppw_render_content_misc', $plugin_admin, 'ppw_free_render_content_misc', 11 );
$this->loader->add_action( 'ppw_render_content_troubleshooting', $plugin_admin, 'ppw_free_render_content_troubleshooting', 11 );
$this->loader->add_action( PPW_Constants::HOOK_RESTRICT_CONTENT_AFTER_VALID_PWD, $plugin_admin, 'set_postpass_cookie_to_prevent_cache', 10, 2 );
$this->loader->add_action( 'rest_api_init', $plugin_admin, 'rest_api_init', 10, 2 );
$this->loader->add_filter( 'ppw_content_shortcode_source', $plugin_admin, 'handle_content_shortcode_for_multiple_pages', 11, 3 );
PPW_Beaver_Loader::get_instance();
$this->loader->add_action( 'wp_ajax_ppw_free_subscribe_request', $plugin_admin, 'handle_subscribe_request' );
$this->loader->add_action( 'ppw_render_pcp_content_general', $plugin_admin, 'ppw_free_render_content_pcp_general_tab', 10 );
$this->loader->add_action( 'ppw_render_external_content_recaptcha', $plugin_admin, 'ppw_free_render_content_external_recaptcha', 10 );
$this->loader->add_action( 'ppw_render_external_content_configuration', $plugin_admin, 'ppw_free_render_content_external_configuration', 10 );
$this->loader->add_action( 'plugin_row_meta', $plugin_admin, 'register_plugins_links', 10, 2 );
$this->loader->add_action( 'ppwp_render_sitewide_countdown', $plugin_admin, 'ppw_sitewide_countdown' );
$this->loader->add_action( 'ppwp_sitewide_hide_password_form', $plugin_admin, 'ppw_sitewide_hide_password_form' );
$this->loader->add_action( 'ppwp_countdown_timer_styles', $plugin_admin, 'register_countdown_timer_style' );
$this->loader->add_filter( 'register_post_type_args', $plugin_admin, 'ppwp_unset_rest_routes', 99, 2 );
$this->loader->add_filter( 'plugin_action_links_' . PPW_PLUGIN_BASE_NAME, $plugin_admin, 'handle_plugin_links', 30 );
$this->loader->add_filter( 'ppwp_customizer_custom_fields', $plugin_admin, 'ppw_customizer_custom_fields', 11, 2 );
PPW_Elementor::get_instance( $this->loader );
PPW_Customizer_PCP::get_instance()->register();
PPW_Content_Protection::get_instance()->register();
}
/**
* Register all of the hooks related to the public-facing functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_public_hooks() {
$plugin_public = new PPW_Public( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_action( 'template_redirect', $plugin_public, 'handle_access_link', - 10 );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_assets' );
$this->loader->add_filter( 'the_content', $plugin_public, 'ppw_the_content', 99999 );
$this->loader->add_filter( 'ppw_cookie_expire', $plugin_public, 'set_cookie_time', 10 );
$this->loader->add_filter( 'ppw_sitewide_cookie_expiration', $plugin_public, 'set_cookie_time', 10 );
$this->loader->add_filter( 'ppw_sitewide_form_action', $plugin_public, 'set_sitewide_form_action', 10 );
$this->loader->add_action( 'wp_ajax_nopriv_ppw_validate_password', $plugin_public, 'ppw_validate_password' );
$this->loader->add_action( 'wp_ajax_ppw_validate_password', $plugin_public, 'ppw_validate_password' );
$this->loader->add_filter( 'et_builder_load_actions', $plugin_public, 'add_action_to_divi' );
/**
* The hook to render our password form
*/
$this->loader->add_filter( 'the_password_form', $plugin_public, 'ppw_the_password_form', 99999999 );
// Register ppwp_content_protector shortcode with WordPress.
$this->loader->add_action( 'init', $plugin_public, 'register_shortcodes' );
// Add hook to handle feature "Hide Protected Content".
$this->loader->add_filter( 'posts_where_paged', $plugin_public, 'handle_hide_post_protected', 10, 2 );
$this->loader->add_filter( 'widget_posts_args', $plugin_public, 'handle_hide_post_protected_recent_post', 10, 1 );
$this->loader->add_filter( 'get_next_post_where', $plugin_public, 'handle_hide_post_protected_next_and_previous', 10, 1 );
$this->loader->add_filter( 'get_previous_post_where', $plugin_public, 'handle_hide_post_protected_next_and_previous', 10, 1 );
$this->loader->add_filter( 'get_pages', $plugin_public, 'handle_hide_page_protected', 10, 2 );
$this->loader->add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', $plugin_public, 'handle_hide_page_protected_yoast_seo_sitemaps', 10, 1 );
$this->loader->add_filter( 'ppwp_ppf_action_url', $plugin_public, 'ppw_core_get_ppf_action_url' );
$this->loader->add_action( 'wp', $plugin_public, 'ppw_core_validate_login', 5 );
}
/**
* Run the loader to execute all of the hooks with WordPress.
*
* @since 1.0.0
*/
public function run() {
$this->loader->run();
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @return string The name of the plugin.
* @since 1.0.0
*/
public function get_plugin_name() {
return $this->plugin_name;
}
/**
* The reference to the class that orchestrates the hooks with the plugin.
*
* @return PPW_Loader Orchestrates the hooks of the plugin.
* @since 1.0.0
*/
public function get_loader() {
return $this->loader;
}
/**
* Retrieve the version number of the plugin.
*
* @return string The version number of the plugin.
* @since 1.0.0
*/
public function get_version() {
return $this->version;
}
/**
* Load base classes
*/
private function load_base() {
$core_dir = PPW_DIR_PATH . 'core/base';
require_once "$core_dir/class-ppw-module.php";
require_once "$core_dir/class-ppw-background-task.php";
require_once PPW_DIR_PATH . 'includes/services/class-ppw-migration.php';
require_once "$core_dir/class-ppw-background-task-manager.php";
require_once "$core_dir/class-ppw-data-migration-manager.php";
require_once PPW_DIR_PATH . 'includes/services/class-ppw-migrations.php';
require_once PPW_DIR_PATH . 'includes/services/class-ppw-migration-manager.php';
require_once PPW_DIR_PATH . 'includes/services/class-ppw-password-recovery.php';
require_once PPW_DIR_PATH . 'includes/services/class-ppw-password-recovery-manager.php';
}
}

View File

@@ -0,0 +1,57 @@
body.ppwp-sitewide-protection {
background: #2a2c2e url("<?php echo esc_url( ppw_get_background_image( 'sw-default1.jpg' ) ); ?>") no-repeat center/cover !important;
}
.pda-form-login {
width: 50%;
height: 100%;
position: relative;
margin: 0 0 0 auto;
padding: 0;
}
.ppwp-countdown-container {
position: absolute;
bottom: 0;
right: 2px;
width: 50%;
}
.pda-form-login a.ppw-swp-logo {
top: 22%;
position: absolute;
left: 50%;
transform: translate(-50%, -50%);
}
.pda-form-login form {
position: absolute;
width: 350px;
left: 50%;
transform: translate(-50%, -50%);
top: 50%;
padding: 3rem;
background: #0404047a;
color: #fff;
}
.pda-form-login .input_wp_protect_password,
.pda-form-login .button-login {
width: 100%;
padding: .8rem;
border: 1px solid #001428;
outline: 0;
font-size: 1rem;
}
.pda-form-login .input_wp_protect_password {
background: #acb2c9;
margin-bottom: 1.5rem;
}
.pda-form-login .button-login {
text-transform: uppercase;
font-weight: 700;
background: #001428;
border-color: #fff;
}

View File

@@ -0,0 +1,95 @@
body.ppwp-sitewide-protection {
background: #2a2c2e url("<?php echo esc_url( ppw_get_background_image( 'sw-default2.jpg' ) ); ?>") no-repeat center/cover !important;
}
.pda-form-login {
width: 50%;
height: 100%;
position: relative;
left: 0;
margin: 0 0 0 auto;
padding: 0;
}
.ppwp-countdown-container {
position: absolute;
bottom: 0;
right: 2px;
width: 50%;
margin: 0 0 0 auto;
}
.pda-form-login form {
max-width: 350px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: relative;
padding: 2rem;
overflow: hidden;
background: #111;
border-radius: 0.4em;
border: 1px solid #191919;
box-shadow: 1px 1px 78px #171717;
color: #fff;
}
.pda-form-login a.ppw-swp-logo {
top: 26%;
position: absolute;
left: 50%;
transform: translate(-50%, -50%);
}
.pda-form-login form:before {
content: "";
width: 8px;
height: 5px;
position: absolute;
left: 34%;
top: -7px;
border-radius: 50%;
box-shadow: 0 0 6px 4px #fff;
}
.pda-form-login form:after {
content: "";
width: 400px;
height: 200px;
position: absolute;
top: 0;
left: 35px;
transform: rotate(75deg);
background: linear-gradient(50deg, rgba(255, 255, 255, 0.15), transparent);
opacity: .4;
z-index: -1;
}
.pda-form-login .input_wp_protect_password {
padding: .8rem;
background: linear-gradient(#1f2124, #27292c);
border: 1px solid #000;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1);
border-radius: 3px;
color: #fff;
padding-right: 2.5rem;
}
.pda-form-login .input_wp_protect_password:focus {
box-shadow: inset 0 0 2px #000;
background: #494d54;
outline: none;
}
.pda-form-login .button-login {
width: 100%;
border: 1px solid rgba(0, 0, 0, 0.4);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), inset 0 10px 10px rgba(255, 255, 255, 0.1);
border-radius: 3px;
background: #218dd6;
cursor: pointer;
font-weight: 700;
font-size: 15px;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.8);
margin-top: 1rem;
}

View File

@@ -0,0 +1,63 @@
body.ppwp-sitewide-protection {
background: #2a2c2e url("<?php echo esc_url( ppw_get_background_image( 'sw-default3.jpg' ) ); ?>") no-repeat center/cover !important;
margin: 0;
}
.pda-form-login {
width: 50%;
background: #ffffffc4;
height: 100%;
position: relative;
box-shadow: 0 1px 13px #ECEBEB;
left: 0;
margin: 0;
padding-top:0;
}
.ppwp-countdown-container {
position: absolute;
bottom: 0;
width: 50%;
margin: 0 0 0 auto;
}
.pda-form-login a.ppw-swp-logo {
top: 32%;
position: absolute;
left: 50%;
transform: translate(-50%, -50%);
}
.pda-form-login form {
position: absolute;
max-width: 350px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
background: transparent;
box-shadow: 0 0 black;
}
.pda-form-login .input_wp_protect_password {
width: 100%;
font-size: 1rem;
outline: 0;
border-radius: 30px;
border: 2px solid #d0cece;
padding: 1rem 3.5rem 1rem 1.5rem;
background: white;
}
.pda-form-login .button-login {
margin-top: 1rem;
text-transform: uppercase;
font-weight: 700;
color: #fff;
border-color: #cac8c7;
border-radius: 30px;
width: 40%;
text-align: center;
padding: .8rem;
background: #7d7974;
box-shadow: 2px 4px 1px #cac8c7;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

View File

@@ -0,0 +1,4 @@
.datetime .customize-control-error-message {
color: red;
display: none;
}

View File

@@ -0,0 +1,32 @@
( function( $, api ) {
api.controlConstructor['datetime'] = api.Control.extend( {
ready: function() {
var control = this;
this.container.on( 'change', 'input[type="datetime-local"]', function() {
if (control.params.id === 'ppwp_sitewide_start_time' && this.value ) {
var endTime = document.getElementById("datetime-ppwp_sitewide_end_time");
endTime.min = this.value;
}
if (control.params.id === 'ppwp_sitewide_start_time' && !this.value ) {
var endTime = document.getElementById("datetime-ppwp_sitewide_end_time");
endTime.min = this.min;
}
if (control.params.id === 'ppwp_sitewide_end_time' ) {
document.getElementById('datetime-ppwp_sitewide_end_time-error-message').style.display = 'none';
var startTime = document.getElementById("datetime-ppwp_sitewide_start_time").value;
var countDownDateStart = new Date(startTime).getTime();
var countDownDateEnd = new Date(this.value).getTime();
if ( countDownDateStart > countDownDateEnd ) {
document.getElementById('datetime-ppwp_sitewide_end_time-error-message').style.display = 'block';
}
}
value = this.value;
control.setting.set( value );
} );
}
} );
} )( jQuery, wp.customize );

View File

@@ -0,0 +1,40 @@
.control-title--wrapper span.customize-control-title {
margin: 0px -12px;
border: 1px solid #ddd;
padding: 13px;
font-size: 13px;
font-weight: 600;
letter-spacing: 2px;
line-height: 1;
text-transform: uppercase;
color: #555;
background-color: #fff;
margin-top: 8px;
}
#accordion-panel-ppwp {
margin-top: 1rem;
}
#accordion-panel-ppwp h3 {
border-top: 1px solid #ddd;
}
#accordion-section-ppwp_upsell {
margin-bottom: 1rem;
}
#accordion-section-ppwp_upsell .ppwp-accordion-section-title {
color: #f78935!important;
border-left-color: #f78935!important;
}
#accordion-section-ppwp_upsell .ppwp-accordion-section-title a {
color: #f78935!important;
text-decoration: none;
display: block;
}
#accordion-section-ppwp_upsell .accordion-section-title:after {
color: #f78935!important;
}

View File

@@ -0,0 +1,107 @@
.customize-control-toggle .toggle--wrapper {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
flex-direction: row;
-webkit-box-direction: normal;
-webkit-box-orient: horizontal;
-webkit-box-pack: start;
-webkit-flex-direction: row;
-ms-flex-direction: row;
-ms-flex-pack: start;
-webkit-justify-content: flex-start;
justify-content: flex-start;
margin-bottom: 10px;
align-items: baseline;
}
.customize-control-toggle .toggle--wrapper .customize-control-title {
font-weight: 600;
margin-bottom: 0px;
vertical-align: middle;
-webkit-box-flex: 2;
-webkit-flex: 2 0 0;
-ms-flex: 2 0 0;
flex: 2 0 0;
}
.customize-control-toggle .toggle--wrapper input[type=checkbox] {
display: none;
}
.customize-control-toggle {
margin-bottom: 0
}
.customize-control-toggle .toggle--wrapper label {
background-color: #555d66;
border-radius: 14px;
cursor: pointer;
display: inline-block;
height: 20px;
outline: none;
position: relative;
right: 0px;
top: 2px;
-webkit-transition: background 0.2s ease;
transition: background 0.2s ease;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
width: 34px;
}
.customize-control-toggle .toggle--wrapper label::after,
.customize-control-toggle .toggle--wrapper label::before {
content: "";
display: block;
position: absolute;
}
.customize-control-toggle .toggle--wrapper label::after {
border: 2px solid #555d66;
border-radius: 50%;
box-sizing: border-box;
height: 12px;
left: 4px;
top: 4px;
-webkit-transition: background 0.2s ease, -webkit-transform 0.2s ease;
transition: background 0.2s ease, -webkit-transform 0.2s ease;
transition: transform 0.2s ease, background 0.2s ease;
transition: transform 0.2s ease, background 0.2s ease, -webkit-transform 0.2s ease;
width: 12px;
}
.customize-control-toggle .toggle--wrapper label::before {
background-color: #eee;
border-radius: 60px;
bottom: 2px;
left: 2px;
right: 2px;
top: 2px;
-webkit-transition: background 0.2s ease;
transition: background 0.2s ease;
}
.customize-control-toggle .toggle--wrapper input[type=checkbox]:checked + label {
background-color: #f78935;
}
.customize-control-toggle .toggle--wrapper input[type=checkbox]:checked + label::after {
background-color: #f78935;
border: 2px solid #fff;
-webkit-transform: translateX(14px);
-ms-transform: translateX(14px);
transform: translateX(14px);
}
.customize-control-toggle .toggle--wrapper input[type=checkbox]:checked + label::before {
background-color: #f78935;
}
.customize-control-toggle:hover .toggle--wrapper label::before {
background-color: #fdefe4;
}

View File

@@ -0,0 +1,16 @@
( function( $, api ) {
api.controlConstructor['toggle'] = api.Control.extend( {
ready: function() {
var control = this;
this.container.on( 'change', 'input:checkbox', function() {
value = this.checked ? true : false;
control.setting.set( value );
} );
}
} );
} )( jQuery, wp.customize );

View File

@@ -0,0 +1,12 @@
( function( $, api ) {
api.sectionConstructor['ppwp-upsell-section'] = api.Section.extend( {
// No events for this type of section.
attachEvents: function () {},
// Always make the section active.
isContextuallyActive: function () {
return true;
}
} );
} )( jQuery, wp.customize );

View File

@@ -0,0 +1,39 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( class_exists( 'WP_Customize_Section' ) && ! class_exists( 'PPW_Customize_Link_Section' ) ) {
/**
* PPW_Customize_Link_Section Initial setup
*/
class PPW_Customize_Link_Section extends WP_Customize_Section {
public $type = 'ppwp-upsell-section';
public $ppwp_url = '';
public $ppwp_text = '';
public $id = '';
public function json() {
$json = parent::json();
$json['ppwp_text'] = $this->ppwp_text;
$json['ppwp_url'] = esc_url( $this->ppwp_url );
$json['id'] = $this->id;
return $json;
}
protected function render_template() {
?>
<li id="accordion-section-{{ data.id }}"
class="ppwp-accordion-section accordion-section control-section control-panel control-panel-default">
<h3 class="ppwp-accordion-section-title accordion-section-title"><a href="{{{ data.ppwp_url }}}"
target="_blank">{{ data.ppwp_text
}}</a></h3>
</li>
<?php
}
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* datetime Customizer Control
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Exit if WP_Customize_Control does not exsist.
if ( ! class_exists( 'WP_Customize_Control' ) ) {
return null;
}
/**
* This class is for the datetime control in the Customizer.
*
* @access public
*/
class PPW_Datetime_Control extends WP_Customize_Control {
/**
* The type of customize control.
*
* @access public
* @since 1.3.4
* @var string
*/
public $type = 'datetime';
/**
* Enqueue scripts and styles.
*
* @access public
* @since 1.0.0
* @return void
*/
public function enqueue() {
wp_enqueue_style( 'ppw-designer-datetime-control-styles', PPW_DIR_URL . 'includes/customizers/assets/ppw-datetime.css', false, PPW_VERSION, 'all' );
wp_enqueue_script( 'ppw-designer-datetime-control-scripts', PPW_DIR_URL . 'includes/customizers/assets/ppw-datetime.js', array( 'jquery' ), PPW_VERSION, true );
}
/**
* Add custom parameters to pass to the JS via JSON.
*
* @access public
* @since 1.0.0
* @return void
*/
public function to_json() {
parent::to_json();
// The setting value.
$this->json['id'] = $this->id;
$this->json['value'] = $this->value();
$this->json['min'] = date('Y-m-d\TH:i', current_time( 'timestamp' ));
}
/**
* Don't render the content via PHP. This control is handled with a JS template.
*
* @access public
* @since 1.0.0
* @return void
*/
public function render_content() {}
/**
* An Underscore (JS) template for this control's content.
*
* Class variables for this control class are available in the `data` JS object;
* export custom variables by overriding {@see WP_Customize_Control::to_json()}.
*
* @see WP_Customize_Control::print_template()
*
* @access protected
* @since 1.3.4
* @return void
*/
protected function content_template() {
?>
<label class="datetime">
<div class="datetime--wrapper">
<# if ( data.label ) { #>
<span class="customize-control-title">{{ data.label }}</span>
<# } #>
<# if ( data.description ) { #>
<span class="customize-control-description"><span>Note:</span> {{ data.description }}</span>
<# } #>
<input type="datetime-local" id="datetime-{{ data.id }}" name="datetime" min="{{ data.min }}" value="{{ data.value }}">
<label for="datetime-{{ data.id }}" class="datetime-label"></label>
</div>
<span id="datetime-{{ data.id }}-error-message" class="customize-control-error-message">Input wrong value.</span>
</label>
<?php
}
}

View File

@@ -0,0 +1,287 @@
<?php
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Exit if WP_Customize_Control does not exsist.
if ( ! class_exists( 'WP_Customize_Control' ) ) {
return null;
}
class PPW_Presets_Control extends WP_Customize_Control {
/**
* @var string Control type
*/
public $type = 'ppw-presets';
/**
* Render the content on the theme customizer page.
*/
public function render_content() {
if ( empty( $this->choices ) ) {
return;
}
$name = 'password-protect-page_preset-' . $this->id; ?>
<span class="customize-control-title">
<?php echo esc_attr( $this->label ); ?>
<?php if ( ! empty( $this->description ) ) : ?>
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php endif; ?>
</span>
<div id="input_<?php echo esc_attr( $this->id ); ?>" class="image">
<?php foreach ( $this->choices as $val ) : ?>
<div class="password-protect-page_thumbnail">
<input class="image-select" type="radio"
value="<?php echo esc_attr( $val['id'] ); ?>"
id="<?php echo esc_attr($this->id . $val['id']); ?>"
name="<?php echo esc_attr( $name ); ?>" <?php checked( $this->value(), $val['id'] ); ?> />
<label for="<?php echo esc_attr($this->id . $val['id']); ?>">
<div class="password-protect-page_thumbnail_img">
<img src="<?php echo esc_url($val['thumbnail']); ?>" alt="<?php echo esc_attr( $val['id'] ); ?>"
title="<?php echo esc_attr( $val['id'] ); ?>">
</div>
<h3><?php echo esc_html( $val['name'] ) ?></h3>
</label>
</div>
<?php endforeach; ?>
</div>
<input name='presets_hidden' type="hidden" <?php $this->link(); ?> value="<?php echo esc_attr( $this->value() ); ?>"/>
<?php }
}
function ppw_presets_control_css() {
?>
<style>
.customize-control-ppw-presets .image.ui-buttonset input[type=radio] {
height: auto;
}
.customize-control-ppw-presets .image.ui-buttonset label {
display: inline-block;
margin-right: 5px;
margin-bottom: 5px;
}
.customize-control-ppw-presets .image.ui-buttonset label.ui-state-active {
background: none;
}
.customize-control-ppw-presets .customize-control-radio-buttonset label {
padding: 5px 10px;
background: #f7f7f7;
border-left: 1px solid #dedede;
line-height: 35px;
}
.customize-control-ppw-presets label img {
border: 1px solid #bbb;
opacity: 0.5;
}
#customize-controls .customize-control-ppw-presets label img {
max-width: 250px;
height: auto;
width: 100%;
margin-bottom: 0;
border: 0;
display: block;
}
.customize-control-ppw-presets label.ui-state-active img {
background: #dedede;
border-color: #000;
opacity: 1;
margin-bottom: 0;
}
.customize-control-ppw-presets label.ui-state-hover img {
opacity: 0.9;
border-color: #999;
}
.customize-control-radio-buttonset label.ui-corner-left {
border-radius: 3px 0 0 3px;
border-left: 0;
}
.customize-control-radio-buttonset label.ui-corner-right {
border-radius: 0 3px 3px 0;
}
#customize-control-ppw_customize_presets_settings input[type=radio]{
display: none;
}
#customize-control-ppw_customize_presets_settings label{
display: block;
position: relative;
width: 100%;
}
#customize-control-ppw_customize_presets_settings .password-protect-page_thumbnail{
width: calc(50% - 10px);
margin-bottom: 10px;
position: relative;
border: 5px solid transparent;
-webkit-transition:all 0.2s ease-in-out;
-moz-transition:all 0.2s ease-in-out;
-ms-transition:all 0.2s ease-in-out;
transition:all 0.2s ease-in-out;
}
#customize-control-ppw_customize_presets_settings .password-protect-page_thumbnail:nth-child(odd){
float: left;
}
#customize-control-ppw_customize_presets_settings .password-protect-page_thumbnail:nth-child(even){
float: right;
}
#customize-control-ppw_customize_presets_settings .image:after{
content: '';
display: table;
clear: both;
}
#customize-control-ppw_customize_presets_settings h3{
margin: 0;
font: 400 14px 'Open Sans', Arial, Helvetica, sans-serif;
line-height: 1.1;
padding: 3px;
text-align: center;
background: #eee;
color: #777777;
}
#customize-control-ppw_customize_presets_settings label .password-protect-page_thumbnail_img:after {
content: '';
width: 20px;
height: 20px;
border-radius: 50%;
background: #ff8935;
position: absolute;
top: -5px;
left: -5px;
border-radius: 50%;
visibility: hidden;
}
#customize-control-ppw_customize_presets_settings label .password-protect-page_thumbnail_img:before {
height: 6px;
width: 3px;
-webkit-transform-origin: left top;
-moz-transform-origin: left top;
-ms-transform-origin: left top;
-o-transform-origin: left top;
transform-origin: left top;
border-right: 3px solid white;
border-top: 3px solid white;
border-radius: 2.5px !important;
content: '';
position: absolute;
z-index: 2;
opacity: 0;
margin-top: 0px;
margin-left: -7px;
top: 5px;
left: 4px;
}
#customize-control-ppw_customize_presets_settings .password-protect-page_thumbnail_img{
display: block;
position: relative;
}
#customize-control-ppw_customize_presets_settings input[type="radio"]:checked + label .password-protect-page_thumbnail_img:before {
-webkit-animation-delay: 100ms;
-moz-animation-delay: 100ms;
animation-delay: 100ms;
-webkit-animation-duration: 1s;
-moz-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-timing-function: ease;
-moz-animation-timing-function: ease;
animation-timing-function: ease;
-webkit-animation-name: checkmark;
-moz-animation-name: checkmark;
animation-name: checkmark;
-webkit-transform: scaleX(-1) rotate(135deg);
-moz-transform: scaleX(-1) rotate(135deg);
-ms-transform: scaleX(-1) rotate(135deg);
-o-transform: scaleX(-1) rotate(135deg);
transform: scaleX(-1) rotate(135deg);
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
animation-fill-mode: forwards;
z-index: 2;
}
#customize-control-ppw_customize_presets_settings input[type="radio"]:checked + label .password-protect-page_thumbnail_img:after{
visibility: visible;
}
#customize-control-ppw_customize_presets_settings img{
margin-bottom: 0;
}
#customize-control-ppw_customize_presets_settings input[type="radio"]:checked + label img{
opacity: 1;
}
#customize-control-ppw_customize_presets_settings .password-protect-page_thumbnail:hover{
border-color: #ccc;
}
@-webkit-keyframes checkmark {
0% {
height: 0;
width: 0;
opacity: 1;
}
20% {
height: 0;
width: 5px;
opacity: 1;
}
40% {
height: 10px;
width: 5px;
opacity: 1;
}
100% {
height: 10px;
width: 5px;
opacity: 1;
}
}
@-moz-keyframes checkmark {
0% {
height: 0;
width: 0;
opacity: 1;
}
20% {
height: 0;
width: 5px;
opacity: 1;
}
40% {
height: 10px;
width: 5px;
opacity: 1;
}
100% {
height: 10px;
width: 5px;
opacity: 1;
}
}
@keyframes checkmark {
0% {
height: 0;
width: 0;
opacity: 1;
}
20% {
height: 0;
width: 5px;
opacity: 1;
}
40% {
height: 10px;
width: 5px;
opacity: 1;
}
100% {
height: 10px;
width: 5px;
opacity: 1;
}
}
</style>
<?php
}
add_action( 'customize_controls_print_styles', 'ppw_presets_control_css' );
?>

View File

@@ -0,0 +1,39 @@
<?php
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Exit if WP_Customize_Control does not exsist.
if ( ! class_exists( 'WP_Customize_Control' ) ) {
return null;
}
class PPW_Text_Editor_Custom_Control extends WP_Customize_Control {
/**
* @var string Control type
*/
public $type = 'editor';
/**
* Render the content on the theme customizer page.
*/
public function render_content() {
$input_id = $this->id;
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
</label>
<input type="hidden" <?php echo esc_url( $this->get_link() ); ?> value="<?php echo esc_attr( $this->value() ); ?>">
<?php
wp_editor( $this->value(), $input_id, array(
'textarea_name' => $input_id,
'textarea_rows' => 3,
) );
do_action( 'admin_footer' );
do_action( 'admin_print_footer_scripts' );
?>
<?php
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* Toggle Customizer Control
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Exit if WP_Customize_Control does not exsist.
if ( ! class_exists( 'WP_Customize_Control' ) ) {
return null;
}
/**
* This class is for the toggle control in the Customizer.
*
* @access public
*/
class PPW_Title_Group_Control extends WP_Customize_Control {
public $type = 'control_title';
public function enqueue() {
wp_enqueue_style( 'control-title-group-styles', PPW_DIR_URL . 'includes/customizers/assets/ppw-title-group-control.css', false, PPW_VERSION, 'all' );
}
public function render_content() {}
protected function content_template() {
?>
<div class="control-title--wrapper">
<span class="customize-control-title">{{ data.label }}</span>
</div>
<?php
}
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* Toggle Customizer Control
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Exit if WP_Customize_Control does not exsist.
if ( ! class_exists( 'WP_Customize_Control' ) ) {
return null;
}
/**
* This class is for the toggle control in the Customizer.
*
* @access public
*/
class PPW_Toggle_Control extends WP_Customize_Control {
/**
* The type of customize control.
*
* @access public
* @since 1.3.4
* @var string
*/
public $type = 'toggle';
/**
* Enqueue scripts and styles.
*
* @access public
* @since 1.0.0
* @return void
*/
public function enqueue() {
wp_enqueue_style( 'ppw-designer-toggle-control-styles', PPW_DIR_URL . 'includes/customizers/assets/ppw-toggle-control.css', false, PPW_VERSION, 'all' );
wp_enqueue_script( 'ppw-designer-toggle-control-scripts', PPW_DIR_URL . 'includes/customizers/assets/ppw-toggle-control.js', array( 'jquery' ), PPW_VERSION, true );
}
/**
* Add custom parameters to pass to the JS via JSON.
*
* @access public
* @since 1.0.0
* @return void
*/
public function to_json() {
parent::to_json();
// The setting value.
$this->json['id'] = $this->id;
$this->json['value'] = $this->value();
$this->json['link'] = $this->get_link();
$this->json['defaultValue'] = $this->setting->default;
}
/**
* Don't render the content via PHP. This control is handled with a JS template.
*
* @access public
* @since 1.0.0
* @return void
*/
public function render_content() {}
/**
* An Underscore (JS) template for this control's content.
*
* Class variables for this control class are available in the `data` JS object;
* export custom variables by overriding {@see WP_Customize_Control::to_json()}.
*
* @see WP_Customize_Control::print_template()
*
* @access protected
* @since 1.3.4
* @return void
*/
protected function content_template() {
?>
<label class="toggle">
<div class="toggle--wrapper">
<# if ( data.label ) { #>
<span class="customize-control-title">{{ data.label }}</span>
<# } #>
<input id="toggle-{{ data.id }}" type="checkbox" class="toggle--input" value="{{ data.value }}" {{{ data.link }}} <# if ( data.value ) { #> checked="checked" <# } #> />
<label for="toggle-{{ data.id }}" class="toggle--label"></label>
</div>
<# if ( data.description ) { #>
<span class="description customize-control-description">{{ data.description }}</span>
<# } #>
</label>
<?php
}
}

View File

@@ -0,0 +1 @@
<?php // Silence is golden

View File

@@ -0,0 +1,170 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* https://github.com/A5hleyRich/wp-background-processing GPL v2.0
*
* WP Async Request
*
* @package WP-Background-Processing
*/
if ( ! class_exists( 'WP_Async_Request' ) ) {
/**
* Abstract WP_Async_Request class.
*
* @abstract
*/
abstract class WP_Async_Request {
/**
* Prefix
*
* (default value: 'wp')
*
* @var string
* @access protected
*/
protected $prefix = 'wp';
/**
* Action
*
* (default value: 'async_request')
*
* @var string
* @access protected
*/
protected $action = 'async_request';
/**
* Identifier
*
* @var mixed
* @access protected
*/
protected $identifier;
/**
* Data
*
* (default value: array())
*
* @var array
* @access protected
*/
protected $data = array();
/**
* Initiate new async request
*/
public function __construct() {
$this->identifier = $this->prefix . '_' . $this->action;
add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
}
/**
* Set data used during the request
*
* @param array $data Data.
*
* @return $this
*/
public function data( $data ) {
$this->data = $data;
return $this;
}
/**
* Dispatch the async request
*
* @return array|WP_Error
*/
public function dispatch() {
$url = add_query_arg( $this->get_query_args(), $this->get_query_url() );
$args = $this->get_post_args();
return wp_remote_post( esc_url_raw( $url ), $args );
}
/**
* Get query args
*
* @return array
*/
protected function get_query_args() {
if ( property_exists( $this, 'query_args' ) ) {
return $this->query_args;
}
return array(
'action' => $this->identifier,
'nonce' => wp_create_nonce( $this->identifier ),
);
}
/**
* Get query URL
*
* @return string
*/
protected function get_query_url() {
if ( property_exists( $this, 'query_url' ) ) {
return $this->query_url;
}
return admin_url( 'admin-ajax.php' );
}
/**
* Get post args
*
* @return array
*/
protected function get_post_args() {
if ( property_exists( $this, 'post_args' ) ) {
return $this->post_args;
}
return array(
'timeout' => 0.01,
'blocking' => false,
'body' => $this->data,
'cookies' => $_COOKIE,
'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
);
}
/**
* Maybe handle
*
* Check for correct nonce and pass to handler.
*/
public function maybe_handle() {
// Don't lock up other requests while processing
session_write_close();
check_ajax_referer( $this->identifier, 'nonce' );
$this->handle();
wp_die();
}
/**
* Handle
*
* Override this method to perform any actions required
* during the async request.
*/
abstract protected function handle();
}
}

View File

@@ -0,0 +1,519 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* https://github.com/A5hleyRich/wp-background-processing GPL v2.0
*
* WP Background Process
*
* @package WP-Background-Processing
*/
if ( ! class_exists( 'WP_Background_Process' ) ) {
/**
* Abstract WP_Background_Process class.
*
* @abstract
* @extends WP_Async_Request
*/
abstract class WP_Background_Process extends WP_Async_Request {
/**
* Action
*
* (default value: 'background_process')
*
* @var string
* @access protected
*/
protected $action = 'background_process';
/**
* Start time of current process.
*
* (default value: 0)
*
* @var int
* @access protected
*/
protected $start_time = 0;
/**
* Cron_hook_identifier
*
* @var mixed
* @access protected
*/
protected $cron_hook_identifier;
/**
* Cron_interval_identifier
*
* @var mixed
* @access protected
*/
protected $cron_interval_identifier;
/**
* Initiate new background process
*/
public function __construct() {
parent::__construct();
$this->cron_hook_identifier = $this->identifier . '_cron';
$this->cron_interval_identifier = $this->identifier . '_cron_interval';
add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
}
/**
* Dispatch
*
* @access public
* @return void
*/
public function dispatch() {
// Schedule the cron healthcheck.
$this->schedule_event();
// Perform remote post.
return parent::dispatch();
}
/**
* Push to queue
*
* @param mixed $data Data.
*
* @return $this
*/
public function push_to_queue( $data ) {
$this->data[] = $data;
return $this;
}
/**
* Save queue
*
* @return $this
*/
public function save() {
$key = $this->generate_key();
if ( ! empty( $this->data ) ) {
update_site_option( $key, $this->data );
}
return $this;
}
/**
* Update queue
*
* @param string $key Key.
* @param array $data Data.
*
* @return $this
*/
public function update( $key, $data ) {
if ( ! empty( $data ) ) {
update_site_option( $key, $data );
}
return $this;
}
/**
* Delete queue
*
* @param string $key Key.
*
* @return $this
*/
public function delete( $key ) {
delete_site_option( $key );
return $this;
}
/**
* Generate key
*
* Generates a unique key based on microtime. Queue items are
* given a unique key so that they can be merged upon save.
*
* @param int $length Length.
*
* @return string
*/
protected function generate_key( $length = 64 ) {
$unique = md5( microtime() . rand() );
$prepend = $this->identifier . '_batch_';
return substr( $prepend . $unique, 0, $length );
}
/**
* Maybe process queue
*
* Checks whether data exists within the queue and that
* the process is not already running.
*/
public function maybe_handle() {
// Don't lock up other requests while processing
session_write_close();
if ( $this->is_process_running() ) {
// Background process already running.
wp_die();
}
if ( $this->is_queue_empty() ) {
// No data to process.
wp_die();
}
check_ajax_referer( $this->identifier, 'nonce' );
$this->handle();
wp_die();
}
/**
* Is queue empty
*
* @return bool
*/
protected function is_queue_empty() {
global $wpdb;
$table = $wpdb->options;
$column = 'option_name';
if ( is_multisite() ) {
$table = $wpdb->sitemeta;
$column = 'meta_key';
}
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
$count = $wpdb->get_var( // phpcs:ignore -- WPCS: db call ok, cache ok.
$wpdb->prepare(
"SELECT COUNT(*) FROM {$table} WHERE %1s LIKE %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder and put the $column in quotes.
$column,
$key
)
);
return ( $count > 0 ) ? false : true;
}
/**
* Is process running
*
* Check whether the current process is already running
* in a background process.
*/
protected function is_process_running() {
if ( get_site_transient( $this->identifier . '_process_lock' ) ) {
// Process already running.
return true;
}
return false;
}
/**
* Lock process
*
* Lock the process so that multiple instances can't run simultaneously.
* Override if applicable, but the duration should be greater than that
* defined in the time_exceeded() method.
*/
protected function lock_process() {
$this->start_time = time(); // Set start time of current process.
$lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute
$lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration );
set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration );
}
/**
* Unlock process
*
* Unlock the process so that other instances can spawn.
*
* @return $this
*/
protected function unlock_process() {
delete_site_transient( $this->identifier . '_process_lock' );
return $this;
}
/**
* Get batch
*
* @return stdClass Return the first batch from the queue
*/
protected function get_batch() {
global $wpdb;
$table = $wpdb->options;
$column = 'option_name';
$key_column = 'option_id';
$value_column = 'option_value';
if ( is_multisite() ) {
$table = $wpdb->sitemeta;
$column = 'meta_key';
$key_column = 'meta_id';
$value_column = 'meta_value';
}
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
$query = $wpdb->get_row( // phpcs:ignore -- WPCS: db call ok, cache ok.
$wpdb->prepare(
"SELECT * FROM {$table} WHERE %1s LIKE %s ORDER BY %s ASC LIMIT 1", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder and put the $column in quotes.
$column,
$key,
$key_column
)
);
$batch = new stdClass();
// $batch->key = $query->$column;
// $batch->data = maybe_unserialize( $query->$value_column );
$batch->key = !empty( $query->$column ) ? $query->$column : '';
$batch->data = !empty( $query->$value_column ) ? maybe_unserialize( $query->$value_column ) : array();
return $batch;
}
/**
* Handle
*
* Pass each queue item to the task handler, while remaining
* within server memory and time limit constraints.
*/
protected function handle() {
$this->lock_process();
do {
$batch = $this->get_batch();
foreach ( $batch->data as $key => $value ) {
$task = $this->task( $value );
if ( false !== $task ) {
$batch->data[ $key ] = $task;
} else {
unset( $batch->data[ $key ] );
}
if ( $this->time_exceeded() || $this->memory_exceeded() ) {
// Batch limits reached.
break;
}
}
// Update or delete current batch.
if ( ! empty( $batch->data ) ) {
$this->update( $batch->key, $batch->data );
} else {
$this->delete( $batch->key );
}
} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() );
$this->unlock_process();
// Start next batch or complete process.
if ( ! $this->is_queue_empty() ) {
$this->dispatch();
} else {
$this->complete();
}
wp_die();
}
/**
* Memory exceeded
*
* Ensures the batch process never exceeds 90%
* of the maximum WordPress memory.
*
* @return bool
*/
protected function memory_exceeded() {
$memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory
$current_memory = memory_get_usage( true );
$return = false;
if ( $current_memory >= $memory_limit ) {
$return = true;
}
return apply_filters( $this->identifier . '_memory_exceeded', $return );
}
/**
* Get memory limit
*
* @return int
*/
protected function get_memory_limit() {
if ( function_exists( 'ini_get' ) ) {
$memory_limit = ini_get( 'memory_limit' );
} else {
// Sensible default.
$memory_limit = '128M';
}
if ( ! $memory_limit || -1 === intval( $memory_limit ) ) {
// Unlimited, set to 32GB.
$memory_limit = '32000M';
}
return intval( $memory_limit ) * 1024 * 1024;
}
/**
* Time exceeded.
*
* Ensures the batch never exceeds a sensible time limit.
* A timeout limit of 30s is common on shared hosting.
*
* @return bool
*/
protected function time_exceeded() {
$finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds
$return = false;
if ( time() >= $finish ) {
$return = true;
}
return apply_filters( $this->identifier . '_time_exceeded', $return );
}
/**
* Complete.
*
* Override if applicable, but ensure that the below actions are
* performed, or, call parent::complete().
*/
protected function complete() {
// Unschedule the cron healthcheck.
$this->clear_scheduled_event();
}
/**
* Schedule cron healthcheck
*
* @access public
* @param mixed $schedules Schedules.
* @return mixed
*/
public function schedule_cron_healthcheck( $schedules ) {
$interval = apply_filters( $this->identifier . '_cron_interval', 5 );
if ( property_exists( $this, 'cron_interval' ) ) {
$interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval );
}
// Adds every 5 minutes to the existing schedules.
$schedules[ $this->identifier . '_cron_interval' ] = array(
'interval' => MINUTE_IN_SECONDS * $interval,
'display' => sprintf( __( 'Every %d Minutes', 'elementor' ), $interval ),
);
return $schedules;
}
/**
* Handle cron healthcheck
*
* Restart the background process if not already running
* and data exists in the queue.
*/
public function handle_cron_healthcheck() {
if ( $this->is_process_running() ) {
// Background process already running.
exit;
}
if ( $this->is_queue_empty() ) {
// No data to process.
$this->clear_scheduled_event();
exit;
}
$this->handle();
exit;
}
/**
* Schedule event
*/
protected function schedule_event() {
if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier );
}
}
/**
* Clear scheduled event
*/
protected function clear_scheduled_event() {
$timestamp = wp_next_scheduled( $this->cron_hook_identifier );
if ( $timestamp ) {
wp_unschedule_event( $timestamp, $this->cron_hook_identifier );
}
}
/**
* Cancel Process
*
* Stop processing queue items, clear cronjob and delete batch.
*
*/
public function cancel_process() {
if ( ! $this->is_queue_empty() ) {
$batch = $this->get_batch();
$this->delete( $batch->key );
wp_clear_scheduled_hook( $this->cron_hook_identifier );
}
}
/**
* Task
*
* Override this method to perform any actions required on each
* queue item. Return the modified item for further processing
* in the next pass through. Or, return false to remove the
* item from the queue.
*
* @param mixed $item Queue item to iterate over.
*
* @return mixed
*/
abstract protected function task( $item );
}
}

View File

@@ -0,0 +1,384 @@
<?php
/**
* Created by PhpStorm.
* User: gaupoit
* Date: 7/24/19
* Time: 15:00
*/
if ( ! class_exists( 'PPW_Asset_Services' ) ) {
class PPW_Asset_Services {
/**
* Current screen
*
* @var
*/
private $screen;
/**
* Page name of current screen
* @var string
*/
private $page;
/**
* Tab name of current screen
* @var
*/
private $tab;
public function __construct( $screen, $get_params ) {
$this->screen = $screen;
if ( isset( $get_params['page'] ) ) {
$this->page = $get_params['page'];
}
if ( isset( $get_params['tab'] ) ) {
$this->tab = $get_params['tab'];
}
}
/**
* Render css and js for entire site tab
*/
public function load_assets_for_entire_site_tab() {
$module = PPW_Constants::ENTIRE_SITE_MODULE;
if ( PPW_Constants::MENU_NAME === $this->page && 'entire_site' === $this->tab ) {
$this->load_bundle_css( PPW_VERSION );
$this->load_js( $module, PPW_VERSION );
wp_localize_script(
"ppw-$module-js",
'ppw_entire_site_data',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
)
);
$this->load_select2_lib();
$this->load_toastr_lib();
}
}
/**
* Render css & js for sitewide submenu
*/
public function load_assets_for_entire_site_page() {
$module = PPW_Constants::ENTIRE_SITE_MODULE;
if ( PPW_Constants::SITEWIDE_PAGE_PREFIX === $this->page && ( 'general' === $this->tab || null === $this->tab ) ) {
$this->load_bundle_css( PPW_VERSION );
$this->load_js( $module, PPW_VERSION );
wp_localize_script(
"ppw-$module-js",
'ppw_entire_site_data',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
)
);
$this->load_select2_lib();
$this->load_toastr_lib();
}
}
public function load_assets_for_shortcode_page() {
if ( PPW_Constants::PCP_PAGE_PREFIX === $this->page && ( 'general' === $this->tab || null === $this->tab ) ) {
$this->load_bundle_css( PPW_VERSION );
$this->load_toastr_lib();
$this->load_shared_lib();
}
}
public function load_assets_for_external_page() {
if ( PPW_Constants::EXTERNAL_SERVICES_PREFIX === $this->page && ( 'recaptcha' === $this->tab || null === $this->tab ) ) {
$this->load_bundle_css( PPW_VERSION );
$this->load_toastr_lib();
$this->load_shared_lib();
$module = PPW_Constants::EXTERNAL_SETTINGS_MODULE;
$this->load_select2_lib();
$this->load_js( $module, PPW_VERSION );
wp_localize_script(
"ppw-$module-js",
'ppw_external_data',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'home_url' => ppw_core_get_home_url_with_ssl(),
)
);
}
}
public function load_assets_for_external_configuration() {
if ( PPW_Constants::EXTERNAL_SERVICES_PREFIX === $this->page && 'configuration' === $this->tab ) {
$this->load_bundle_css( PPW_VERSION );
$this->load_toastr_lib();
$this->load_shared_lib();
$module = PPW_Constants::EXTERNAL_CONFIGURATION_MODULE;
$this->load_select2_lib();
$this->load_js( $module, PPW_VERSION );
wp_localize_script(
"ppw-$module-js",
'ppw_external_data',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'home_url' => ppw_core_get_home_url_with_ssl(),
)
);
}
}
/**
* Load assets for shortcode setting.
*/
public function load_assets_for_shortcode_setting() {
$module = PPW_Constants::SHORTCODES_SETTINGS_MODULE;
$is_shortcode_tab = PPW_Constants::MENU_NAME === $this->page
&& 'shortcodes' === $this->tab;
$is_pcp_submenu = PPW_Constants::PCP_PAGE_PREFIX === $this->page
&& ( 'general' === $this->tab || null === $this->tab );
if ( $is_shortcode_tab || $is_pcp_submenu ) {
$this->load_select2_lib();
$this->load_js( $module, PPW_VERSION );
wp_localize_script(
"ppw-$module-js",
'ppw_shortcode_data',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'home_url' => ppw_core_get_home_url_with_ssl(),
'nonce' => wp_create_nonce( PPW_Constants::GENERAL_FORM_NONCE ),
)
);
}
}
/**
* Is Partial Protection submenu.
*
* @param string $page Page name.
* @param string $tab Tab name.
*
* @return bool
*/
public static function is_partial_protection_submenu( $page, $tab ) {
return PPW_Constants::PCP_PAGE_PREFIX === $page
&& ( 'general' === $tab || null === $tab );
}
/**
* Render css and js for general tab
*/
public function load_assets_for_general_tab() {
$module = PPW_Constants::GENERAL_SETTINGS_MODULE;
if ( PPW_Constants::MENU_NAME === $this->page && ( $module === $this->tab || null === $this->tab ) ) {
$this->load_bundle_css( PPW_VERSION );
$this->load_js( $module, PPW_VERSION );
wp_localize_script(
"ppw-$module-js",
'ppw_general_data',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'home_url' => ppw_core_get_home_url_with_ssl(),
'nonce' => wp_create_nonce( 'wp_rest' ),
)
);
$this->load_select2_lib();
$this->load_toastr_lib();
}
}
/**
* Render css and js for general tab
*/
public function load_assets_for_misc_tab() {
$module = PPW_Constants::MISC_SETTINGS_MODULE;
if ( PPW_Constants::MENU_NAME === $this->page && ( $module === $this->tab || null === $this->tab ) ) {
$this->load_bundle_css( PPW_VERSION );
$this->load_js( $module, PPW_VERSION );
wp_localize_script(
"ppw-$module-js",
'ppw_misc_data',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'home_url' => ppw_core_get_home_url_with_ssl(),
'nonce' => wp_create_nonce( 'wp_rest' ),
)
);
$this->load_select2_lib();
$this->load_toastr_lib();
do_action( PPW_Constants::HOOK_ADVANCED_TAB_LOAD_ASSETS );
}
}
/**
* Render css and js for general tab
*/
public function load_assets_for_category_page() {
global $pagenow;
$module = 'category';
$is_show = 'edit-tags.php' === $pagenow && isset( $_GET['taxonomy'] ) && 'category' === $_GET['taxonomy']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We not hanlde nonce for load assets.
$is_show = apply_filters( 'ppwp_is_load_assets_for_category_page', $is_show );
if ( $is_show ) {
$this->load_bundle_css( PPW_VERSION );
$this->load_css( $module, PPW_VERSION );
$this->load_js( $module, PPW_VERSION );
wp_localize_script(
"ppw-$module-js",
'ppw_category_data',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'home_url' => ppw_core_get_home_url_with_ssl(),
'nonce' => wp_create_nonce( 'wp_rest' ),
)
);
$this->load_select2_lib();
$this->load_toastr_lib();
do_action( 'ppw_category_page_load_assets' );
}
}
/**
* Render css and js for troubleshoot tab
*/
public function load_assets_for_troubleshoot_tab() {
$module = PPW_Constants::TROUBLESHOOT_SETTINGS_MODULE;
if ( PPW_Constants::MENU_NAME === $this->page && ( $module === $this->tab || null === $this->tab ) ) {
$this->load_bundle_css( PPW_VERSION );
$this->load_js( $module, PPW_VERSION );
}
}
/**
* Load asserts for meta-box.
*/
public function load_assets_for_meta_box() {
$module = PPW_Constants::META_BOX_MODULE;
$this->load_css( $module, PPW_VERSION );
$this->load_js( $module, PPW_VERSION );
wp_localize_script(
"ppw-$module-js",
'save_password_data',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'error_message' => array(
'duplicate_password' => PPW_Constants::DUPLICATE_PASSWORD,
'empty_password' => PPW_Constants::EMPTY_PASSWORD,
'space_password' => PPW_Constants::SPACE_PASSWORD,
),
)
);
$this->load_toastr_lib();
}
/**
* Load asserts for shortcodes setting tab.
*/
public function load_assets_for_shortcodes() {
$module = PPW_Constants::SHORTCODES_SETTINGS_MODULE;
if ( PPW_Constants::MENU_NAME === $this->page && $module === $this->tab ) {
$this->load_bundle_css( PPW_VERSION );
$this->load_toastr_lib();
$this->load_shared_lib();
}
}
/**
* Render Select2 library
*/
public function load_select2_lib() {
wp_enqueue_script( 'ppw-select2-js', PPW_DIR_URL . 'admin/js/lib/select2.min.js', array( 'jquery' ), '4.0.3', true );
wp_enqueue_style( 'ppw-select2-css', PPW_DIR_URL . 'admin/css/lib/select2.min.css', array(), '4.0.3', 'all' );
}
/**
* Load js file to show notice when deactivating the plugin.
*/
public function load_js_show_notice_deactivate_plugin() {
if ( 'plugins' === $this->screen ) {
wp_enqueue_script( 'ppw-notice-deactivate-js', PPW_DIR_URL . 'admin/js/class-ppw-notice-deactivate.js', array( 'jquery' ), PPW_VERSION, true );
wp_localize_script(
'ppw-notice-deactivate-js',
'ppw_deactivate_data',
array(
'is_active_pro' => is_plugin_active( PPW_Constants::PRO_DIRECTORY ) || is_plugin_active( PPW_Constants::DEV_PRO_DIRECTORY ),
)
);
}
}
/**
* Load the shared lib.
*/
public function load_shared_lib() {
wp_enqueue_script( 'ppw-shared-js', PPW_DIR_URL . 'includes/views/shared/assets/dist/ppwUtils.bundle.js', array( 'jquery' ), PPW_VERSION, true );
wp_localize_script(
'ppw-shared-js',
'ppw_general_data',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
)
);
}
/**
* Render Toastr library
*/
public function load_toastr_lib() {
wp_enqueue_script( 'ppw-toastr-js', PPW_DIR_URL . 'admin/js/lib/toastr.min.js', array( 'jquery' ), '2.1.3', true );
wp_enqueue_style( 'ppw-toastr-css', PPW_DIR_URL . 'admin/css/lib/toastr.min.css', array(), '2.1.3', 'all' );
}
/**
* Render CSS to hide feature set password of WP
*/
public function load_css_hide_feature_set_password_wp() {
$page_post_screens = apply_filters(
PPW_Constants::HOOK_HIDE_DEFAULT_PW_WP_POSITION,
array(
'edit-post',
'edit-page',
'page',
'post',
)
);
if ( in_array( $this->screen, $page_post_screens, true ) ) {
wp_enqueue_style( 'ppw-hide-default-css', PPW_DIR_URL . 'admin/css/ppw-hide-default.css', array(), PPW_VERSION, 'all' );
}
}
/**
* Helper function to load css of module
*
* @param string $module Module for loading.
* @param string $version Version to load.
* @param array $dependencies Dependencies.
*/
public function load_css( $module, $version, $dependencies = array() ) {
wp_enqueue_style( "ppw-$module-css", PPW_VIEW_URL . "dist/ppw-$module.css", $dependencies, $version, 'all' );
}
/**
* Load bundle css file
*
* @param string $version CSS version.
*/
public function load_bundle_css( $version ) {
wp_enqueue_style( 'ppw-bundle-css', PPW_DIR_URL . 'admin/css/dist/ppw-setting.css', array(), $version, 'all' );
if ( ppw_is_wp_version_compatible( '5.3' ) ) {
wp_enqueue_style( 'ppw-bundle-css-wp-5-3', PPW_DIR_URL . 'includes/views/dist/ppw-general-wp-5-3.css', array(), $version, 'all' );
}
}
/**
* Helper function to load js of module
*
* @param string $module Module for loading.
* @param string $version Version to load.
* @param array $dependencies Dependencies.
*/
public function load_js( $module, $version, $dependencies = array() ) {
wp_enqueue_script( "ppw-$module-js", PPW_VIEW_URL . "dist/ppw-$module.js", $dependencies, $version, 'all' );
}
}
}

View File

@@ -0,0 +1,241 @@
<?php
use W3TC\Dispatcher;
if ( ! class_exists( 'PPW_Cache_Services' ) ) {
/**
* Class PPW_Free_Handle_Cache
*/
class PPW_Cache_Services {
public function __construct() {
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
}
/**
* Handle cache for page/post have password type is role with Super Cache plugin
*
* @param $new_role_password
* @param $id
* @param $current_roles_password
* @param $current_global_passwords
* @deprecated
*/
function handle_cache_for_password_type_role_with_super_cache( $new_role_password, $id, $current_roles_password, $current_global_passwords ) {
if ( ! is_plugin_active( 'wp-super-cache/wp-cache.php' ) ) {
return;
}
if ( ! empty( $new_role_password ) ) {
$uri = $this->get_uri_by_post_id( $id );
global $cache_rejected_uri;
if ( ! in_array( '/' . $uri, $cache_rejected_uri ) ) {
$this->add_page_post_to_list_not_cache_for_super_cache( $id, $uri, $cache_rejected_uri );
}
} else {
if ( ! empty( $current_global_passwords ) ) {
return;
}
$result = array_values( $current_roles_password );
$result = array_filter( $result, 'strlen' );
if ( empty( $result ) ) {
$this->remove_page_post_to_list_not_cache_for_super_cache( $id );
}
}
}
/**
* Handle cache for page/post have password type is global with Super Cache plugin
*
* @param $new_global_passwords
* @param $id
* @param $current_roles_password
* @deprecated
*/
function handle_cache_for_password_type_global_with_super_cache( $new_global_passwords, $id, $current_roles_password ) {
if ( ! is_plugin_active( 'wp-super-cache/wp-cache.php' ) ) {
return;
}
if ( ! empty( $new_global_passwords ) ) {
$uri = $this->get_uri_by_post_id( $id );
global $cache_rejected_uri;
if ( ! in_array( '/' . $uri, $cache_rejected_uri ) ) {
$this->add_page_post_to_list_not_cache_for_super_cache( $id, $uri, $cache_rejected_uri );
}
} else {
$result = array_values( $current_roles_password );
$result = array_filter( $result, 'strlen' );
if ( empty( $result ) ) {
$this->remove_page_post_to_list_not_cache_for_super_cache( $id );
}
}
}
/**
* Add page or post to list not cache of WP Super Cache plugin
*
* @param $post_id
* @param $uri
* @param $cache_rejected_uri
* @deprecated
*/
function add_page_post_to_list_not_cache_for_super_cache( $post_id, $uri, $cache_rejected_uri ) {
// 1. Add URI to list not cache
global $wp_cache_config_file;
array_push( $cache_rejected_uri, '/' . $uri );
$all_uri = array_map( function ( $key, $cache ) {
return " $key => '$cache'";
}, array_keys( $cache_rejected_uri ), $cache_rejected_uri );
$all_uri = implode( ',', $all_uri );
$text = "array($all_uri )";
wp_cache_replace_line( '^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file );
// 3. Clear cache by post_id
wp_cache_post_edit( $post_id );
}
/**
* Remove page or post in list not cache of WP Super Cache plugin
*
* @param $post_id
* @deprecated
*/
function remove_page_post_to_list_not_cache_for_super_cache( $post_id ) {
// 1. Get URI in permalink by post_id
$uri = $this->get_uri_by_post_id( $post_id );
$uri = '/' . $uri;
// 2. Remove URI in list not cache
global $cache_rejected_uri, $wp_cache_config_file;
$cache_rejected_uri = array_unique( $cache_rejected_uri );
if ( ( $key = array_search( $uri, $cache_rejected_uri ) ) !== false ) {
unset( $cache_rejected_uri[ $key ] );
$all_uri = array_map( function ( $key, $cache ) {
return " $key => '$cache'";
}, array_keys( $cache_rejected_uri ), $cache_rejected_uri );
$all_uri = implode( ',', $all_uri );
$text = "array($all_uri )";
wp_cache_replace_line( '^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file );
}
}
/**
* get URI by post_id
*
* @param $post_id
*
* @return string
* @deprecated
*/
function get_uri_by_post_id( $post_id ) {
$permalink = get_permalink( $post_id );
$parse_url = parse_url( $permalink );
$uri = $parse_url['path'];
$uri = explode( '/', $uri );
$uri = ! empty( $uri[ count( $uri ) - 1 ] ) ? $uri[ count( $uri ) - 1 ] : $uri[ count( $uri ) - 2 ];
return $uri;
}
/**
* Clear cache all page
* @deprecated
*/
function clear_cache_super_cache() {
if ( ! is_plugin_active( 'wp-super-cache/wp-cache.php' ) ) {
return;
}
if ( is_multisite() ) {
wp_cache_clear_cache( get_current_blog_id() );
} else {
wp_cache_clear_cache();
}
}
/**
* Check W3 Total Cache has config cookie group
*
* @return bool
*/
function check_has_config_w3_total_cache() {
$config = Dispatcher::config();
$groups = $config->get_array( 'pgcache.cookiegroups.groups' );
if ( ! array_key_exists( 'password_protect_wordpress', $groups ) ) {
return false;
}
if ( ! $groups['password_protect_wordpress']['enabled'] || $groups['password_protect_wordpress']['cache'] ) {
return false;
}
$cookies = $groups['password_protect_wordpress']['cookies'];
return in_array( 'pda_protect_password', $cookies ) && in_array( 'wp-postpass-role_*', $cookies );
}
/**
* Update cookie to option and modify htaccess file for WP Fastest Cache plugin
* @deprecated
*/
function custom_option_exclude_page_and_cookie_fastest_cache() {
if ( ! is_plugin_active( 'wp-fastest-cache/wpFastestCache.php' ) ) {
return;
}
$old_fastest = get_option( "WpFastestCacheExclude" );
$fastest_cache = new WpFastestCache();
if ( $old_fastest ) {
$old_fastest = json_decode( $old_fastest );
$tmp1 = false;
$tmp2_free = false;
foreach ( $old_fastest as $fast ) {
if ( 'cookie' === $fast->type && 'contain' === $fast->prefix && 'pda_protect_password' === $fast->content ) {
$tmp1 = true;
}
if ( 'cookie' === $fast->type && 'contain' === $fast->prefix && 'wp-postpass-role_' === $fast->content ) {
$tmp2_free = true;
}
}
if ( ! $tmp1 ) {
array_push( $old_fastest, (object) array(
'prefix' => 'contain',
'content' => 'pda_protect_password',
'type' => 'cookie'
) );
}
if ( ! $tmp2_free ) {
array_push( $old_fastest, (object) array(
'prefix' => 'contain',
'content' => 'wp-goldpass-pagepost_',
'type' => 'cookie'
) );
}
update_option( "WpFastestCacheExclude", json_encode( $old_fastest ) );
$fastest_cache->modify_htaccess_for_exclude();
} else {
$ppwp_cookie = array(
(object) array(
'prefix' => 'contain',
'content' => 'pda_protect_password',
'type' => 'cookie'
)
);
array_push( $ppwp_cookie, (object) array(
'prefix' => 'contain',
'content' => 'wp-postpass-role_',
'type' => 'cookie'
) );
add_option( "WpFastestCacheExclude", json_encode( $ppwp_cookie ), null, "yes" );
$fastest_cache->modify_htaccess_for_exclude();
}
}
}
}

View File

@@ -0,0 +1,355 @@
<?php
/**
*
* Class PPW_Category
*/
class PPW_Category_Service {
const COOKIE_NAME = 'ppw_cat-';
const OPTION_NAME = 'ppwp_category_options';
const SHARED_CATEGORY_TYPE = 'shared_category';
/**
* @var null|integer Category ID.
*/
private $category_id = null;
/**
* Is using post password required
* @var bool
*/
private $unlocked = false;
/**
* @var null|PPW_Category_Service Instance.
*/
protected static $instance = null;
private $is_pro_activated;
/**
* Get instance.
*
* @return PPW_Category_Service
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Register hooks.
*
* @param bool $is_pro_activated Is pro activated
*/
public function register( $is_pro_activated = false ) {
$this->is_pro_activated = $is_pro_activated;
$this->unlocked = $this->is_pro_activated;
add_filter( 'post_password_required', array( $this, 'category_password_required' ), 15, 2 );
add_filter( 'ppw_is_valid_password', array( $this, 'check_valid_password' ), 15, 3 );
add_action( 'category_pre_add_form', array( $this, 'display_category_ui' ) );
// Check post is protected before.
add_filter( 'ppw_is_valid_cookie', array( $this, 'ppw_is_valid_cookie' ) );
add_filter( 'ppwp_post_password_required', array( $this, 'ppwp_post_password_required' ), 100 );
}
/**
* Check if content is protected and unlocked password form.
*
* @param boolean $is_valid
*
* @return bool True is valid cookie.
*/
public function ppw_is_valid_cookie( $is_valid ) {
$this->unlocked = $is_valid;
return $is_valid;
}
/**
* If post is protected and
*
* @param array $data Unlock data from PPWP Fro.
*
* @return mixed
*/
public function ppwp_post_password_required( $data ) {
if ( ! isset( $data['is_content_unlocked'] ) ) {
return $data;
}
$this->unlocked = $data['is_post_protected'] && $data['is_content_unlocked'];
return $data;
}
/**
* Display category UI.
*/
public function display_category_ui() {
$categories = ppw_get_terms_with_all_lang(
array(
'taxonomy' => 'category',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
)
);
$is_protect = ppw_core_get_setting_type_bool_by_option_name( 'ppwp_is_protect_category', self::OPTION_NAME );
$protected_categories = ppw_core_get_setting_type_array_by_option_name( 'ppwp_protected_categories_selected', self::OPTION_NAME );
// Get first password to display to user.
$passwords = PPW_Repository_Passwords::get_instance()->get_all_shared_categories_password();
if ( count( $passwords ) > 0 ) {
$password = $passwords[0]->password;
} else {
$password = '';
}
ob_start();
include PPW_DIR_PATH . 'includes/views/category/view-option.php';
echo ob_get_clean(); // phpcs:ignore -- we already escape on the view-option.php
}
/**
* Filters whether a category requires the user to supply a password.
*
* @param bool Whether the user needs to supply a password.
* True if password has not been provided or is incorrect,
* false if password has been supplied or is not required.
*
* @return bool false if a password is not required or the correct password cookie is present, true otherwise.
*/
public function category_password_required( $required, $post ) {
$post_id = ! empty( $post ) ? $post->ID : false;
if ( ! $post_id ) {
return $required;
}
// Get all protected categories of a Post.
$protected_categories = $this->get_protected_categories( $post_id );
if ( empty( $protected_categories ) ) {
return $required;
}
$validated_cookie = apply_filters( 'ppw_category_is_valid_cookie', $this->is_valid_cookie(), $post_id, $post, $required );
if ( $validated_cookie ) {
return false;
}
add_filter( 'ppwp_ppf_action_url', array( $this, 'get_action_url' ), 9999 );
// Unlocked by PPWP Free and PPWP Pro
// Include Single, AL, Group.
if ( apply_filters( 'ppw_category_unlocked', $this->unlocked, $post_id, $protected_categories ) ) {
$this->unlocked = $this->is_pro_activated;
return $required;
}
return true;
}
/**
* Get protected categories if user turn on Option.
*
* @param integer $post_id Post ID.
*
* @return array Empty if user turn off option or post ID not include protected categories.
*/
public function get_protected_categories( $post_id ) {
// Check user has turn on option.
$enabled = ppw_core_get_setting_type_bool_by_option_name( 'ppwp_is_protect_category', self::OPTION_NAME );
$enabled = apply_filters( 'ppw_category_is_enabled', $enabled, $post_id );
if ( ! $enabled ) {
return array();
}
$categories_id = $this->get_categories_by_post_id( $post_id );
// Not handle with categories of post are empty.
if ( empty( $categories_id ) ) {
return array();
}
// Get protected categories of current post.
$protected_categories = ppw_core_get_setting_type_array_by_option_name( 'ppwp_protected_categories_selected', self::OPTION_NAME );;
$protected_categories = array_intersect( $categories_id, $protected_categories );
// Reorder index of array.
return array_values( $protected_categories );
}
/**
* Replace current action by action URL of category to check password.
*/
public function get_action_url( $url ) {
if ( is_category() ) {
$callback_url = get_category_link( get_queried_object_id() );
} elseif ( is_singular() ) {
$callback_url = get_the_permalink();
} else {
global $wp;
$callback_url = home_url( $wp->request );
}
$callback_url = rawurlencode( $callback_url );
return add_query_arg(
array(
PPW_Constants::CALL_BACK_URL_PARAM => $callback_url,
),
$url
);
}
/**
* Check password is valid after show message if it is wrong password.
*
* @param bool $is_valid Is valid password.
* @param int $post_id Post ID.
* @param string $password Password.
*
* @return bool True if password is valid.
*/
public function check_valid_password( $is_valid, $post_id, $password ) {
$protected_categories = $this->get_protected_categories( $post_id );
if ( empty( $protected_categories ) ) {
return $is_valid;
}
return apply_filters( 'ppw_category_is_valid_password', $this->is_valid_password( $protected_categories, $password, $post_id ), $is_valid, $protected_categories, $post_id, $password ) || $is_valid;
}
/**
* Set password to cookie
*
* @param string $password Password string.
* @param string $cookie_name Cookie name.
* @param false|int $password_id Password ID.
*
* @return bool
*/
public function set_password_to_cookie( $password, $cookie_name, $password_id = false ) {
$password_hashed = wp_hash_password( $password );
$expire = apply_filters( PPW_Constants::HOOK_COOKIE_EXPIRED, time() + 7 * DAY_IN_SECONDS );
$password_cookie_expired = ppw_core_get_setting_type_string( PPW_Constants::COOKIE_EXPIRED );
if ( ! empty( $password_cookie_expired ) ) {
$time = explode( ' ', $password_cookie_expired )[0];
$unit = ppw_core_get_unit_time( $password_cookie_expired );
if ( 0 !== $unit ) {
$expire = apply_filters( PPW_Constants::HOOK_COOKIE_EXPIRED, time() + (int) $time * $unit );
}
}
$referer = wp_get_referer();
if ( $referer ) {
$secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) );
} else {
$secure = false;
}
if ( $password_id ) {
$password_hashed = $password_id . '|' . $password_hashed;
}
$expire = apply_filters( 'ppw_cookie_expire', $expire );
$expire = apply_filters( 'ppwp_cookie_expiry', $expire );
return setcookie( $cookie_name . COOKIEHASH, $password_hashed, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
}
/**
* Handle password with data sent by user.
*
* @param array $categories_id Categories ID.
* @param string $password Password.
* @param integer $post_id Post ID.
*
* @return bool
*/
public function is_valid_password( $categories_id, $password, $post_id ) {
// Get current roles will empty if user using subdomain because path of cookie.
$password_info = PPW_Repository_Passwords::get_instance()->find_by_shared_category_password( $password );
if ( ! $password_info ) {
return false;
}
$this->set_password_to_cookie( $password, self::COOKIE_NAME, $password_info->id );
$this->set_password_to_cookie( $password, PPW_Constants::WP_POST_PASS );
do_action( 'ppw_category_after_set_password_to_cookie', $categories_id, $password_info, $post_id );
return true;
}
/**
* Is valid cookie.
*
* @return bool
*/
public function is_valid_cookie() {
$_cookie = wp_unslash( $_COOKIE );
if ( ! isset( $_cookie[ self::COOKIE_NAME . COOKIEHASH ] ) ) {
return false;
}
$cookie_value = $_cookie[ self::COOKIE_NAME . COOKIEHASH ];
$cookie_value = explode( '|', $cookie_value );
if ( count( $cookie_value ) < 2 ) {
return false;
}
$password_id = (int) $cookie_value[0];
$password_hashed = $cookie_value[1];
$password_info = PPW_Repository_Passwords::get_instance()->get_shared_category_password( $password_id );
if ( ! $password_info ) {
return false;
}
if ( ppw_free_check_password( $password_info->password, $password_hashed ) ) {
return true;
}
return false;
}
/**
* Get categories by post ID.
*
* @param int $post_id Post ID.
*
* @return array|WP_Error The requested term data or empty array if no terms found. WP_Error if any of the
* taxonomies don't exist.
* @link https://developer.wordpress.org/reference/functions/wp_get_post_categories/
*/
public function get_categories_by_post_id( $post_id ) {
$terms = get_the_terms( $post_id, $this->get_current_taxonomy( $post_id ) );
if ( empty( $terms ) ) {
return array();
}
return array_map(
function ( $term ) {
return $term->term_id;
},
$terms
);
}
/**
* Get current taxonomy from Post ID.
*
* @param int $post_id Post ID.
*
* @return string Current taxonomy.
*/
public function get_current_taxonomy( $post_id ) {
return apply_filters( 'ppw_category_get_taxonomy', 'category', $post_id );
}
}

View File

@@ -0,0 +1,510 @@
<?php
class PPW_Content_Protection {
/**
* @var PPW_Content_Protection
*/
protected static $instance;
const POST_TYPE = 'ppwp-section';
const SETTING_META_KEY = 'ppw_pcp_setting';
const PASSWORD_GLOBAL_TYPE = 'PCPSection';
const PASSWORD_ROLE_TYPE = 'PCPSectionRole_';
const COOKIE_NAME = 'ppw_section-';
const ADMIN_PATH = 'edit.php?post_type=ppwp-section';
const SHORTCODE_COLUMN = 'ppw_pcp_shortcode';
/**
* @var PPW_Password_Services
*/
private $password_service;
/**
* @var PPW_Repository_Passwords
*/
private $password_repo;
/**
* @return PPW_Content_Protection
*/
public static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function __construct() {
$this->password_service = new PPW_Password_Services();
$this->password_repo = new PPW_Repository_Passwords();
}
public function register() {
add_action( 'init', array( $this, 'register_post_type' ) );
add_action( 'wp_ajax_ppw_pcp_validate_password', array( $this, 'validate_password' ) );
add_action( 'wp_ajax_nopriv_ppw_pcp_validate_password', array( $this, 'validate_password' ) );
add_filter( 'ppw_shortcode_render_content', array( $this, 'handle_shortcode_with_area' ), 10, 2 );
add_filter( 'et_builder_load_actions', array( $this, 'add_action_to_divi' ) );
add_filter( 'ppw_pcp_valid_shortcode', array( $this, 'valid_shortcode' ), 10, 2 );
add_action( 'admin_init', array( $this, 'maybe_add_metabox' ) );
add_filter( 'ppw_shortcode_unlock_content', array( $this, 'maybe_unlock_content_by_cookie' ), 15, 2 );
add_filter( 'ppw_pcp_submenu_add_new_tab', array( $this, 'add_pcp_tab' ), 1000 );
add_filter( 'manage_' . self::POST_TYPE . '_posts_columns', array( $this, 'add_shortcode_column' ) );
add_action( 'manage_' . self::POST_TYPE . '_posts_custom_column', array(
$this,
'render_content_custom_column',
), 10, 2 );
add_action( 'admin_notices', array( $this, 'handle_admin_notices' ) );
}
public function add_shortcode_column( $columns ) {
$inserted = array(
self::SHORTCODE_COLUMN => 'Shortcode'
);
return array_slice( $columns, 0, 2, true )
+ $inserted
+ array_slice( $columns, 2, count( $columns ) - 1, true );
}
public function render_content_custom_column( $column, $post_id ) {
if ( $column === self::SHORTCODE_COLUMN ) {
echo '[ppwp section="' . absint( $post_id ) . '" /]';
}
}
public function add_pcp_tab( $tabs ) {
$tabs[] = array(
'tab' => 'section',
'tab_name' => 'Section Protection',
'link' => self::ADMIN_PATH,
);
return $tabs;
}
public function valid_shortcode( $content, $attrs ) {
if ( ! isset( $attrs['section'] ) || ! is_numeric( $attrs['section'] ) ) {
return $content;
}
if ( absint( $attrs['section'] ) > 0 ) {
return true;
}
return $content;
}
public function register_post_type() {
$args = array(
'labels' => array(
'name' => __( 'Section Protection', 'password-protect-page' ),
'singular_name' => __( 'Section Protection', 'password-protect-page' ),
'add_new' => __( 'Add New', 'password-protect-page' ),
'add_new_item' => __( 'Add New', 'password-protect-page' ),
'edit_item' => __( 'Edit', 'password-protect-page' ),
'new_item' => __( 'New', 'password-protect-page' ),
'view_item' => __( 'View', 'password-protect-page' ),
'search_items' => __( 'Search', 'password-protect-page' ),
'not_found' => __( 'No found', 'password-protect-page' ),
'not_found_in_trash' => __( 'No found in Trash', 'password-protect-page' ),
),
'public' => false,
'hierarchical' => true,
'show_ui' => true,
'show_in_menu' => self::ADMIN_PATH,
'_builtin' => false,
'capability_type' => 'post',
'supports' => array( 'title', 'editor' ),
'rewrite' => false,
'query_var' => false,
'show_in_rest' => true,
);
if ( current_user_can( 'administrator' ) ) {
$args['public'] = true;
$args['publicly_queryable'] = true;
}
// if ( is_admin() ) {
// global $pagenow, $typenow, $post;
// if ( 'edit.php' === $pagenow || self::POST_TYPE === $typenow ) {
// $args['show_in_menu'] = PPW_Constants::MENU_NAME;
// } elseif ( isset( $_GET['post_type'] ) && self::POST_TYPE === $_GET['post_type'] ) {
// $args['show_in_menu'] = PPW_Constants::MENU_NAME;
// } elseif ( isset( $_GET['post'] ) && isset( $_GET['action'] ) ) {
// $post_type = get_post_type( $_GET['post'] );
//
// if ( $post_type === self::POST_TYPE ) {
// $args['show_in_menu'] = PPW_Constants::MENU_NAME;
// }
// }
// }
register_post_type( self::POST_TYPE, $args );
}
/**
* Add ajax support for Divi builder.
*
* @param array $actions array of allowed actions.
*
* @return array
*/
public function add_action_to_divi( $actions ) {
$actions[] = 'ppw_pcp_validate_password';
return $actions;
}
public function handle_shortcode_with_area( $content, $attrs ) {
if ( ! isset( $attrs['section'] ) ) {
return $content;
}
$post_id = absint( $attrs['section'] );
if ( ! $post_id ) {
return $content;
}
$post = get_post( $post_id );
if ( empty( $post ) || $post->post_type !== self::POST_TYPE ) {
return $content;
}
$post_content = $this->massage_post_content( $post_id, $post->post_content );
if ( is_null( $post_content ) ) {
return $content;
}
return $post_content;
}
public function massage_post_content( $post_id, $post_content ) {
$post_content = ppw_support_third_party_content_plugin( $post_id, $post_content );
return apply_filters( 'the_content', $post_content );
}
public function maybe_add_metabox() {
$attributes = apply_filters(
'ppw_pcp_metabox_attributes',
array(
'title' => __( 'Password Protect WordPress', PPW_Constants::DOMAIN ),
'callback' => array( $this, 'display_metabox' ),
'screen' => array( self::POST_TYPE ),
'context' => 'side',
'priority' => 'high',
)
);
add_meta_box(
'ppw_pcp_meta_box',
$attributes['title'],
$attributes['callback'],
$attributes['screen'],
$attributes['context'],
$attributes['priority']
);
}
public function display_metabox() {
ob_start();
?>
<div id="ppw-pcp-metabox"></div>
<?php
wp_enqueue_script( 'ppw-pcp-metabox', PPW_DIR_URL . 'admin/js/dist/pcp-metabox.js', array(), PPW_VERSION, true );
wp_localize_script(
'ppw-pcp-metabox',
'pcpMetabox',
array(
'rest_url' => get_rest_url( null, '/wppp/v1/pcp' ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'post_id' => get_the_ID(),
'customize_url' => admin_url( 'customize.php' ),
'extra_html' => apply_filters( 'ppw_pcp_metabox_extra_html', '')
)
);
echo ob_get_clean(); // phpcs:ignore -- we cannot escape ob_start ob_get_clean(), there are no variable to escape in statement above
}
public function validate_single_password( $params ) {
$password = $params['password'];
$area = $params['area'];
$roles = ppw_core_get_current_role();
$args = array(
'post_id' => $area,
'roles' => $roles,
'global_type' => self::PASSWORD_GLOBAL_TYPE,
'role_type' => self::PASSWORD_ROLE_TYPE,
);
$password_info = $this->password_repo->find_activated_password( $password, $args );
if ( empty( $password_info ) ) {
return false;
}
$this->password_service->set_cookie_bypass_cache( $password, self::COOKIE_NAME . $area . 'p' . $password_info->id );
do_action( 'ppw_after_save_section_cookie', $password_info );
return true;
}
public function validate_password() {
if ( ! isset( $_POST['pss'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
wp_send_json(
array(
'success' => false,
'message' => 'Please enter the correct password!',
),
403
);
exit();
}
if ( ! isset( $_POST['area'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
wp_send_json(
array(
'success' => false,
'message' => 'Area value is required!',
),
403
);
exit();
}
if ( ! isset( $_POST['post_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
wp_send_json(
array(
'success' => false,
'message' => 'Post ID is required!',
),
403
);
exit();
}
$password = wp_unslash( $_POST['pss'] ); // phpcs:ignore -- not sanitize password because we allow all character.
$area = absint( $_POST['area'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
$post_id = absint( $_POST['post_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
$post = get_post( $area );
if ( empty( $post ) ) {
wp_send_json(
array(
'success' => false,
'message' => 'Post does not exist',
),
403
);
exit();
}
if ( $post->post_type !== self::POST_TYPE ) {
wp_send_json(
array(
'success' => false,
'message' => 'Post type is not valid',
),
403
);
exit();
}
$setting = get_post_meta( $area, self::SETTING_META_KEY, true );
$params = array(
'password' => $password,
'area' => $area,
'post_id' => $post_id,
'setting' => $setting,
);
$is_valid_by_single = $this->validate_single_password( $params );
$is_valid_password = apply_filters( 'ppw_pcp_area_is_valid_password', $is_valid_by_single, $params );
if ( $is_valid_password ) {
wp_send_json(
array(
'reload' => ! ppw_core_get_setting_type_bool_by_option_name( PPW_Constants::NO_RELOAD_PAGE, PPW_Constants::MISC_OPTIONS ),
'success' => true,
'message' => '',
'content' => $this->massage_post_content( $area, $post->post_content ),
),
200
);
exit();
}
wp_send_json(
array(
'success' => false,
'message' => get_theme_mod( 'ppwp_pcp_err_msg_text', PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG ),
),
400
);
}
public function check_area_exist( $post ) {
if ( empty( $post ) ) {
return false;
}
if ( $post->post_type !== self::POST_TYPE ) {
return false;
}
return true;
}
public function get_info_from_area_cookie( $area ) {
$_cookie = wp_unslash( $_COOKIE );
if ( empty( $_cookie ) ) {
return array();
}
$cookie_keys = array_filter(
array_keys( $_cookie ),
function ( $key ) {
return false !== strpos( $key, self::COOKIE_NAME );
}
);
if ( 0 === count( $cookie_keys ) ) {
return array();
}
$results = array();
foreach ( $cookie_keys as $cookie_key ) {
$info = str_replace( self::COOKIE_NAME, '', $cookie_key );
$info = str_replace( COOKIEHASH, '', $info );
$info = explode( 'p', $info );
$password_id = absint( ppw_get_value( $info, 1, 0 ) );
$cookie_area = absint( ppw_get_value( $info, 0, 0 ) );
if ( $area !== $cookie_area ) {
continue;
}
$results[ $password_id ] = array(
'cookie_name' => $cookie_key,
'cookie_value' => $_cookie[ $cookie_key ],
);
}
return $results;
}
public function validate_cookie( $area ) {
$cookie_passwords = $this->get_info_from_area_cookie( $area );
if ( empty( $cookie_passwords ) ) {
return false;
}
$password_ids = array_keys( $cookie_passwords );
$roles = ppw_core_get_current_role();
$params = array(
'post_id' => $area,
'roles' => $roles,
'global_type' => self::PASSWORD_GLOBAL_TYPE,
'role_type' => self::PASSWORD_ROLE_TYPE,
'allow_to_check_expired' => false,
);
$password_infos = $this->password_repo->find_activated_passwords_by_ids(
$password_ids,
$params
);
if ( empty( $password_infos ) ) {
return false;
}
foreach ( $password_infos as $password_info ) {
if ( ! isset( $cookie_passwords[ $password_info->id ] ) ) {
continue;
}
$cookie = $cookie_passwords[ $password_info->id ];
$hashed_password = $cookie['cookie_value'];
if ( ppw_free_check_password( $password_info->password, $hashed_password ) ) {
return true;
}
}
return false;
}
public function maybe_unlock_content_by_cookie( $is_valid, $attrs ) {
if ( $is_valid || ! isset( $attrs['section'] ) ) {
return $is_valid;
}
$area = $attrs['section'];
$setting = get_post_meta( $area, self::SETTING_META_KEY, true );
$post = get_post( $area );
if ( ! $this->check_area_exist( $post ) ) {
return $is_valid;
}
$params = array(
'area' => absint( $area ),
'setting' => $setting,
);
$is_valid_cookie = $this->validate_cookie( $params['area'] );
return apply_filters( 'ppw_pcp_valid_area_password', $is_valid_cookie, $params );
}
public function handle_admin_notices() {
if ( ! function_exists( 'get_current_screen' ) ) {
return;
}
$current_screen = get_current_screen();
if ( ! isset( $current_screen->post_type ) ) {
return;
}
if ( $current_screen->post_type !== self::POST_TYPE ) {
return;
}
$button_contexts = array( 'ppwp-section' );
if ( in_array( $current_screen->id, $button_contexts ) ) {
$edit_url = admin_url( self::ADMIN_PATH );
$button = '<span style="float: right;">
<a href="' . $edit_url . '">
<button class="button button-primary">
Go back to all sections
</button>
</a>
</span>';
} else {
$button = '';
}
?>
<div class="notice">
<p>
<div>
<b>Password Protect WordPress: Section Protection</b>
<?php echo $button;?>
</div>
<a target="_blank" rel="noopener noreferrer"
href="https://passwordprotectwp.com/docs/section-protection/?utm_source=user-website&utm_medium=section-protection-list&utm_campaign=ppwp-free">Protect section of your
content</a> by creating section templates below. Add these sections to your content using
auto-generated section shortcodes.
</p>
</div>
<?php
}
}

View File

@@ -0,0 +1,816 @@
<?php
if ( ! class_exists( 'PPW_Customizer_PCP' ) ) {
class PPW_Customizer_PCP {
/**
* Instance of PPW_Pro_Shortcode class.
*
* @var PPW_Customizer_PCP
*/
protected static $instance = null;
const PANEL = 'ppwp_pcp';
const GENERAL_SECTION = 'ppwp_pcp_form';
const FORM_SECTION = 'ppwp_pcp_form';
const ERR_MSG_SECTION = 'ppwp_pcp_err_msg';
const BUTTON_SECTION = 'ppwp_pcp_button';
/**
* Get instance of PPW_Customizer
*
* @return PPW_Customizer_PCP
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
// Use static instead of self due to the inheritance later.
// For example: ChildSC extends this class, when we call get_instance
// it will return the object of child class. On the other hand, self function
// will return the object of base class.
self::$instance = new static();
}
return self::$instance;
}
public function register() {
add_action( 'customize_register', array( $this, 'customize_register' ), 15 );
add_action( 'wp_head', array( $this, 'dynamic_styles' ) );
add_filter( 'ppw_pcp_attributes', array( $this, 'load_customizer_attributes' ) );
add_filter( 'ppw_validated_pcp_password', array( $this, 'load_customizer_err_msg' ), 10, 3 );
}
/**
* Load customizer attributes.
*
* @param array $attrs Attributes
*
* @return array
*/
public function load_customizer_attributes( $attrs ) {
$attrs['headline'] = get_theme_mod( 'ppwp_pcp_form_headline', PPW_Constants::DEFAULT_SHORTCODE_HEADLINE );
$attrs['description'] = get_theme_mod( 'ppwp_pcp_form_description', PPW_Constants::DEFAULT_SHORTCODE_DESCRIPTION );
$attrs['label'] = get_theme_mod( 'ppwp_pcp_form_label', PPW_Constants::DEFAULT_SHORTCODE_LABEL );
$attrs['placeholder'] = get_theme_mod( 'ppwp_pcp_form_placeholder', '' );
$attrs['error_msg'] = get_theme_mod( 'ppwp_pcp_err_msg_text', PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG );
$attrs['button'] = get_theme_mod( 'ppwp_pcp_button_text', PPW_Constants::DEFAULT_SHORTCODE_BUTTON );
$attrs['loading'] = get_theme_mod( 'ppwp_pcp_button_loading_text', PPW_Constants::DEFAULT_SHORTCODE_LOADING );
$attrs['show_password'] = get_theme_mod( 'ppwp_pcp_form_is_show_password', PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD );
$attrs['show_password_text'] = get_theme_mod( 'ppwp_pcp_form_show_password_text', PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD_TEXT );
// $attrs['desc_above_btn'] = get_theme_mod( 'ppwp_pcp_description_above_btn', PPW_Constants::DEFAULT_SHORTCODE_DESC_ABOVE_PWD_BTN );
$attrs['desc_below_form'] = get_theme_mod( 'ppwp_pcp_description_below_form', PPW_Constants::DEFAULT_SHORTCODE_DESC_BELOW_PWD_FORM );
return $attrs;
}
/**
* Load customizer error message.
*
* @param array $attrs Attributes.
* @param string $password Password.
* @param array $parsed_attrs Parsed attributes.
*
* @return array
*/
public function load_customizer_err_msg( $attrs, $password, $parsed_attrs ) {
if ( isset( $parsed_attrs['error_msg'] ) ) {
return $attrs;
}
if ( isset( $attrs['is_valid_password'] ) && ! $attrs['is_valid_password'] ) {
$attrs['message'] = get_theme_mod( 'ppwp_pcp_err_msg_text', PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG );
}
return $attrs;
}
/**
* Register customizer.
*
* @param WP_Customize $wp_customize WP Customize class.
*/
public function customize_register( $wp_customize ) {
if ( ! class_exists( 'PPW_Title_Group_Control' ) ) {
include PPW_DIR_PATH . 'includes/customizers/class-ppw-title-group-control.php';
}
if ( ! class_exists( 'PPW_Toggle_Control' ) ) {
include PPW_DIR_PATH . 'includes/customizers/class-ppw-toggle-control.php';
}
if ( ! class_exists( 'PPW_Text_Editor_Custom_Control' ) ) {
include PPW_DIR_PATH . 'includes/customizers/class-ppw-text-editor-control.php';
}
$wp_customize->add_panel(
self::PANEL,
array(
'priority' => 9990,
'capability' => 'edit_theme_options',
'theme_supports' => '',
'title' => __( 'PPWP Partial Protection Form', 'password-protect-page' ),
)
);
$this->append_form_section( $wp_customize );
$this->append_err_msg_section( $wp_customize );
$this->append_button_section( $wp_customize );
}
/**
* Append form section.
*
* @param WP_Customize $wp_customize WP Customize class.
*/
public function append_form_section( $wp_customize ) {
$wp_customize->add_section(
self::FORM_SECTION,
array(
'title' => __( 'Password Form', 'password-protect-page' ),
'panel' => self::PANEL,
'priority' => 10,
)
);
$wp_customize->add_setting( 'ppwp_pcp_form_background_title' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_pcp_form_background_title', array(
'label' => __( 'Background', 'password-protect-page' ),
'section' => self::FORM_SECTION,
'settings' => 'ppwp_pcp_form_background_title',
'type' => 'control_title',
'priority' => 0,
) )
);
$wp_customize->add_setting( 'ppwp_pcp_form_background_color' );
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
'ppwp_pcp_form_background_color_control',
array(
'label' => __( 'Form Background Color', 'password-protect-page' ),
'section' => self::FORM_SECTION,
'settings' => 'ppwp_pcp_form_background_color',
'priority' => 10,
)
)
);
$wp_customize->add_setting( 'ppwp_pcp_form_padding' );
$wp_customize->add_control(
'ppwp_pcp_form_padding_control',
array(
'label' => __( 'Padding', 'password-protect-page' ),
'description' => __( 'Padding in px', 'password-protect-page' ),
'section' => self::FORM_SECTION,
'settings' => 'ppwp_pcp_form_padding',
'type' => 'number',
'priority' => 20,
)
);
/* form background border radius */
$wp_customize->add_setting( 'ppwp_pcp_form_border_radius', array(
'default' => PPW_Constants::DEFAULT_FORM_BORDER_RADIUS,
) );
$wp_customize->add_control( 'ppwp_pcp_form_border_radius_control', array(
'label' => __( 'Border Radius', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'description' => 'Border Radius in px',
'settings' => 'ppwp_pcp_form_border_radius',
'type' => 'number',
'priority' => 40,
) );
$wp_customize->add_setting( 'ppwp_pcp_form_headline_title' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_pcp_form_headline_title', array(
'label' => __( 'Headline', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_headline_title',
'type' => 'control_title',
'priority' => 50,
) )
);
$wp_customize->add_setting( 'ppwp_pcp_form_headline', array(
'default' => PPW_Constants::DEFAULT_SHORTCODE_HEADLINE,
) );
$wp_customize->add_control(
new PPW_Text_Editor_Custom_Control(
$wp_customize,
'ppwp_pcp_form_headline',
array(
'label' => __( 'Headline', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_headline',
'type' => 'textarea',
'priority' => 60,
)
)
);
$wp_customize->add_setting( 'ppwp_pcp_form_headline_font_size', array(
'default' => PPW_Constants::DEFAULT_HEADLINE_FONT_SIZE,
) );
$wp_customize->add_control( 'ppwp_pcp_form_headline_font_size_control', array(
'label' => __( 'Font Size', 'password-protect-page' ),
'description' => __( 'Font size in px', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_headline_font_size',
'type' => 'number',
'priority' => 70,
) );
$wp_customize->add_setting( 'ppwp_pcp_form_headline_font_weight', array(
'default' => PPW_Constants::DEFAULT_HEADLINE_FONT_WEIGHT,
) );
$wp_customize->add_control( 'ppwp_pcp_form_headline_font_weight_control', array(
'label' => __( 'Font Weight', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_headline_font_weight',
'type' => 'number',
'priority' => 80,
) );
$wp_customize->add_setting( 'ppwp_pcp_form_headline_color', array(
'default' => PPW_Constants::DEFAULT_HEADLINE_FONT_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pcp_form_headline_color_control', array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_headline_color',
'priority' => 90,
) )
);
$wp_customize->add_setting( 'ppwp_pcp_form_description_title' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_pcp_form_description_title', array(
'label' => __( 'Description Above Form', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_description_title',
'type' => 'control_title',
'priority' => 100,
) )
);
$wp_customize->add_setting( 'ppwp_pcp_form_description', array(
'default' => PPW_Constants::DEFAULT_SHORTCODE_DESCRIPTION,
) );
$wp_customize->add_control(
new PPW_Text_Editor_Custom_Control(
$wp_customize,
'ppwp_pcp_form_description',
array(
'label' => __( 'Description', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_description',
'type' => 'textarea',
'priority' => 110,
)
)
);
$wp_customize->add_setting( 'ppwp_pcp_form_description_font_size', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_SIZE,
) );
$wp_customize->add_control( 'ppwp_pcp_form_description_font_size_control', array(
'label' => __( 'Font Size', 'password-protect-page' ),
'description' => __( 'Font size in px', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_description_font_size',
'type' => 'number',
'priority' => 120,
) );
$wp_customize->add_setting( 'ppwp_pcp_form_description_font_weight', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT,
) );
$wp_customize->add_control( 'ppwp_pcp_form_description_font_weight_control', array(
'label' => __( 'Font Weight', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_description_font_weight',
'type' => 'number',
'priority' => 130,
) );
$wp_customize->add_setting( 'ppwp_pcp_form_description_color', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pcp_form_description_color_control', array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_description_color',
'priority' => 140,
) )
);
$wp_customize->add_setting( 'ppwp_pcp_form_desc_title' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_pcp_form_desc_title',
array(
'label' => __( 'Description Below Form', 'password-protect-page' ),
'section' => 'ppwp_pcp_form',
'settings' => 'ppwp_pcp_form_desc_title',
'type' => 'control_title',
'priority' => 145,
)
)
);
$wp_customize->add_setting( 'ppwp_pcp_description_below_form', array(
'default' => PPW_Constants::DEFAULT_SHORTCODE_DESC_BELOW_PWD_FORM,
) );
$wp_customize->add_control(
new PPW_Text_Editor_Custom_Control(
$wp_customize,
'ppwp_pcp_description_below_form', array(
'label' => __( 'Description', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_description_below_form',
'type' => 'textarea',
'priority' => 146,
)
) );
$wp_customize->add_setting( 'ppwp_pcp_form_description_below_form_font_size', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_SIZE,
) );
$wp_customize->add_control( 'ppwp_pcp_form_description_below_form_font_size_control', array(
'label' => __( 'Font Size', 'password-protect-page' ),
'description' => __( 'Font size in px', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_description_below_form_font_size',
'type' => 'number',
'priority' => 147,
) );
$wp_customize->add_setting( 'ppwp_pcp_form_description_below_form_font_weight', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT,
) );
$wp_customize->add_control( 'ppwp_pcp_form_description_below_form_font_weight_control', array(
'label' => __( 'Font Weight', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_description_below_form_font_weight',
'type' => 'number',
'priority' => 148,
) );
$wp_customize->add_setting( 'ppwp_pcp_form_description_below_form_color', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pcp_form_description_below_form_color_control', array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => self::GENERAL_SECTION,
'settings' => 'ppwp_pcp_form_description_below_form_color',
'priority' => 149,
) )
);
// $wp_customize->add_setting( 'ppwp_pcp_desc_above_btn' );
// $wp_customize->add_control(
// new PPW_Title_Group_Control(
// $wp_customize,
// 'ppwp_pcp_desc_above_btn',
// array(
// 'label' => __( 'Description Above Button', 'password-protect-page' ),
// 'section' => 'ppwp_pcp_form',
// 'settings' => 'ppwp_pcp_desc_above_btn',
// 'type' => 'control_title',
// 'priority' => 150,
// )
// )
// );
// $wp_customize->add_setting( 'ppwp_pcp_description_above_btn', array(
// 'default' => PPW_Constants::DEFAULT_SHORTCODE_DESC_ABOVE_PWD_BTN,
// ) );
// $wp_customize->add_control(
// new PPW_Text_Editor_Custom_Control(
// $wp_customize,
// 'ppwp_pcp_description_above_btn',
// array(
// 'label' => __( 'Description', 'password-protect-page' ),
// 'section' => self::GENERAL_SECTION,
// 'settings' => 'ppwp_pcp_description_above_btn',
// 'type' => 'textarea',
// 'priority' => 152,
// )
// )
// );
// $wp_customize->add_setting( 'ppwp_pcp_form_description_above_btn_font_size', array(
// 'default' => PPW_Constants::DEFAULT_TEXT_FONT_SIZE,
// ) );
// $wp_customize->add_control( 'ppwp_pcp_form_description_above_btn_font_size_control', array(
// 'label' => __( 'Font Size', 'password-protect-page' ),
// 'description' => __( 'Font size in px', 'password-protect-page' ),
// 'section' => self::GENERAL_SECTION,
// 'settings' => 'ppwp_pcp_form_description_above_btn_font_size',
// 'type' => 'number',
// 'priority' => 153,
// ) );
// $wp_customize->add_setting( 'ppwp_pcp_form_description_above_btn_font_weight', array(
// 'default' => PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT,
// ) );
// $wp_customize->add_control( 'ppwp_pcp_form_description_above_btn_font_weight_control', array(
// 'label' => __( 'Font Weight', 'password-protect-page' ),
// 'section' => self::GENERAL_SECTION,
// 'settings' => 'ppwp_pcp_form_description_above_btn_font_weight',
// 'type' => 'number',
// 'priority' => 154,
// ) );
// $wp_customize->add_setting( 'ppwp_pcp_form_description_above_btn_color', array(
// 'default' => PPW_Constants::DEFAULT_TEXT_FONT_COLOR,
// ) );
// $wp_customize->add_control(
// new \WP_Customize_Color_Control(
// $wp_customize,
// 'ppwp_pcp_form_description_above_btn_color_control', array(
// 'label' => __( 'Text Color', 'password-protect-page' ),
// 'section' => self::GENERAL_SECTION,
// 'settings' => 'ppwp_pcp_form_description_above_btn_color',
// 'priority' => 155,
// ) )
// );
$wp_customize->add_setting( 'ppwp_pcp_form_label_title' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_pcp_form_label_title',
array(
'label' => __( 'Password Field', 'password-protect-page' ),
'section' => 'ppwp_pcp_form',
'settings' => 'ppwp_pcp_form_label_title',
'type' => 'control_title',
'priority' => 159,
)
)
);
$wp_customize->add_setting( 'ppwp_pcp_form_label', array(
'default' => PPW_Constants::DEFAULT_SHORTCODE_LABEL,
) );
$wp_customize->add_control( 'ppwp_pcp_form_label_control', array(
'label' => __( 'Password Label', 'password-protect-page' ),
'section' => 'ppwp_pcp_form',
'settings' => 'ppwp_pcp_form_label',
'type' => 'text',
'priority' => 160,
) );
$wp_customize->add_setting( 'ppwp_pcp_form_label_font_size', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_SIZE,
) );
$wp_customize->add_control( 'ppwp_pcp_form_label_font_size_control', array(
'label' => __( 'Font Size', 'password-protect-page' ),
'description' => __( 'Font size in px', 'password-protect-page' ),
'section' => 'ppwp_pcp_form',
'settings' => 'ppwp_pcp_form_label_font_size',
'type' => 'number',
'priority' => 170,
) );
$wp_customize->add_setting( 'ppwp_pcp_form_label_font_weight', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT,
) );
$wp_customize->add_control( 'ppwp_pcp_form_label_font_weight_control', array(
'label' => __( 'Font Weight', 'password-protect-page' ),
'section' => 'ppwp_pcp_form',
'settings' => 'ppwp_pcp_form_label_font_weight',
'type' => 'number',
'priority' => 180,
) );
$wp_customize->add_setting( 'ppwp_pcp_form_label_color', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pcp_form_label_color_control', array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => 'ppwp_pcp_form',
'settings' => 'ppwp_pcp_form_label_color',
'priority' => 190,
) )
);
$wp_customize->add_setting( 'ppwp_pcp_form_placeholder', array(
'default' => PPW_Constants::DEFAULT_PLACEHOLDER,
) );
$wp_customize->add_control( 'ppwp_pcp_form_placeholder_control', array(
'label' => __( 'Placeholder', 'password-protect-page' ),
'section' => 'ppwp_pcp_form',
'settings' => 'ppwp_pcp_form_placeholder',
'type' => 'text',
'priority' => 200,
) );
$wp_customize->add_setting( 'ppwp_pcp_form_show_password_title' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_pcp_form_show_password_title', array(
'label' => __( 'Show Password', 'password-protect-page' ),
'section' => 'ppwp_pcp_form',
'settings' => 'ppwp_pcp_form_show_password_title',
'type' => 'control_title',
'priority' => 210,
) )
);
$wp_customize->add_setting( 'ppwp_pcp_form_is_show_password', array(
'default' => PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD,
) );
$wp_customize->add_control(
new PPW_Toggle_Control(
$wp_customize,
'ppwp_pcp_form_is_show_password_control', array(
'label' => __( 'Show Password Reveal Button', 'password-protect-page' ),
'section' => 'ppwp_pcp_form',
'type' => 'toggle',
'settings' => 'ppwp_pcp_form_is_show_password',
'priority' => 220,
) )
);
$wp_customize->add_setting( 'ppwp_pcp_form_show_password_text', array(
'default' => PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD_TEXT,
) );
$wp_customize->add_control( 'ppwp_pcp_form_show_password_text_control', array(
'label' => __( 'Button Text', 'password-protect-page' ),
'section' => 'ppwp_pcp_form',
'settings' => 'ppwp_pcp_form_show_password_text',
'type' => 'text',
'priority' => 230,
) );
}
/**
* Append error message section.
*
* @param WP_Customize $wp_customize WP Customize class.
*/
public function append_err_msg_section( $wp_customize ) {
/* form error message section */
$wp_customize->add_section( self::ERR_MSG_SECTION, array(
'title' => __( 'Error Message', 'password-protect-page' ),
'panel' => self::PANEL,
'priority' => 20,
) );
$wp_customize->add_setting( 'ppwp_pcp_err_msg_text', array(
'default' => PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG,
) );
$wp_customize->add_control(
new PPW_Text_Editor_Custom_Control(
$wp_customize,
'ppwp_pcp_err_msg_text',
array(
'label' => __( 'Wrong Password Message', 'password-protect-page' ),
'section' => self::ERR_MSG_SECTION,
'settings' => 'ppwp_pcp_err_msg_text',
'type' => 'textarea',
'priority' => 10,
)
)
);
$wp_customize->add_setting( 'ppwp_pcp_err_msg_text_font_size', array(
'default' => PPW_Constants::DEFAULT_ERROR_TEXT_FONT_SIZE,
) );
$wp_customize->add_control( 'ppwp_pcp_err_msg_text_font_size_control', array(
'label' => __( 'Font Size', 'password-protect-page' ),
'description' => __( 'Font size in px', 'password-protect-page' ),
'section' => self::ERR_MSG_SECTION,
'settings' => 'ppwp_pcp_err_msg_text_font_size',
'type' => 'number',
'priority' => 20,
) );
$wp_customize->add_setting( 'ppwp_pcp_err_msg_text_font_weight', array(
'default' => PPW_Constants::DEFAULT_ERROR_TEXT_FONT_WEIGHT,
) );
$wp_customize->add_control( 'ppwp_pcp_err_msg_text_font_weight_control', array(
'label' => __( 'Font Weight', 'password-protect-page' ),
'section' => self::ERR_MSG_SECTION,
'settings' => 'ppwp_pcp_err_msg_text_font_weight',
'type' => 'number',
'priority' => 25,
) );
$wp_customize->add_setting( 'ppwp_pcp_err_msg_text_color', array(
'default' => PPW_Constants::DEFAULT_ERROR_TEXT_FONT_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pcp_err_msg_text_color_control', array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => self::ERR_MSG_SECTION,
'settings' => 'ppwp_pcp_err_msg_text_color',
'priority' => 30,
) )
);
$wp_customize->add_setting( 'ppwp_pcp_err_msg_background_color', array(
'default' => '#ffffff',
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pcp_err_msg_background_color_control', array(
'label' => __( 'Background Color', 'password-protect-page' ),
'section' => self::ERR_MSG_SECTION,
'settings' => 'ppwp_pcp_err_msg_background_color',
'priority' => 35,
) )
);
}
/**
* Append button section.
*
* @param WP_Customize $wp_customize WP Customize class.
*/
public function append_button_section( $wp_customize ) {
$wp_customize->add_section( self::BUTTON_SECTION, array(
'title' => __( 'Button', 'password-protect-page' ),
'panel' => self::PANEL,
'priority' => 300,
) );
$wp_customize->add_setting( 'ppwp_pcp_button_text', array(
'default' => PPW_Constants::DEFAULT_SHORTCODE_BUTTON,
) );
$wp_customize->add_control( 'ppwp_pcp_button_text_control', array(
'label' => __( 'Button Label', 'password-protect-page' ),
'section' => 'ppwp_pcp_button',
'settings' => 'ppwp_pcp_button_text',
'type' => 'text',
) );
$wp_customize->add_setting( 'ppwp_pcp_button_loading_text', array(
'default' => __( PPW_Constants::DEFAULT_SHORTCODE_LOADING, 'password-protect-page' ),
) );
$wp_customize->add_control( 'ppwp_pcp_button_loading_text_control', array(
'label' => __( 'Button Loading Label', 'password-protect-page' ),
'section' => 'ppwp_pcp_button',
'settings' => 'ppwp_pcp_button_loading_text',
'type' => 'text',
) );
$wp_customize->add_setting( 'ppwp_pcp_button_text_color', array(
'default' => PPW_Constants::DEFAULT_BUTTON_TEXT_FONT_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pcp_button_text_color_control', array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => 'ppwp_pcp_button',
'settings' => 'ppwp_pcp_button_text_color',
) )
);
$wp_customize->add_setting( 'ppwp_pcp_button_text_hover_color', array(
'default' => PPW_Constants::DEFAULT_BUTTON_TEXT_HOVER_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pcp_button_text_hover_color_control', array(
'label' => __( 'Text Color (Hover)', 'password-protect-page' ),
'section' => 'ppwp_pcp_button',
'settings' => 'ppwp_pcp_button_text_hover_color',
) )
);
$wp_customize->add_setting( 'ppwp_pcp_button_background_color', array(
'default' => PPW_Constants::DEFAULT_BUTTON_BACKGROUND_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pcp_button_background_color_control', array(
'label' => __( 'Background Color', 'password-protect-page' ),
'section' => 'ppwp_pcp_button',
'settings' => 'ppwp_pcp_button_background_color',
) )
);
$wp_customize->add_setting( 'ppwp_pcp_button_background_hover_color', array(
'default' => PPW_Constants::DEFAULT_BUTTON_BACKGROUND_HOVER_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pcp_button_background_hover_color_control', array(
'label' => __( 'Background Color (Hover)', 'password-protect-page' ),
'section' => 'ppwp_pcp_button',
'settings' => 'ppwp_pcp_button_background_hover_color',
) )
);
}
/**
* Add dynamic styles
*
* @return void
*/
public function dynamic_styles() {
$ppw_custom_css = "
<style>
.ppw-form {
background-color: " . get_theme_mod( 'ppwp_pcp_form_background_color', PPW_Constants::DEFAULT_FORM_BACKGROUND_COLOR ) . "!important;
padding: " . get_theme_mod( 'ppwp_pcp_form_padding', PPW_Constants::DEFAULT_FORM_PADDING ) . "px!important;
border-radius: " . get_theme_mod( 'ppwp_pcp_form_border_radius', PPW_Constants::DEFAULT_FORM_BORDER_RADIUS ) . "px!important;
}
.ppw-headline.ppw-pcp-pf-headline {
font-size: " . get_theme_mod( 'ppwp_pcp_form_headline_font_size', PPW_Constants::DEFAULT_HEADLINE_FONT_SIZE ) . "px!important;
font-weight: " . get_theme_mod( 'ppwp_pcp_form_headline_font_weight', PPW_Constants::DEFAULT_HEADLINE_FONT_WEIGHT ) . "!important;
color: " . get_theme_mod( 'ppwp_pcp_form_headline_color', PPW_Constants::DEFAULT_HEADLINE_FONT_COLOR ) . "!important;
}
.ppw-description.ppw-pcp-pf-desc {
font-size: " . get_theme_mod( 'ppwp_pcp_form_description_font_size', PPW_Constants::DEFAULT_TEXT_FONT_SIZE ) . "px!important;
font-weight: " . get_theme_mod( 'ppwp_pcp_form_description_font_weight', PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT ) . "!important;
color: " . get_theme_mod( 'ppwp_pcp_form_description_color', PPW_Constants::DEFAULT_TEXT_FONT_COLOR ) . "!important;
}
.ppw-pcp-pf-desc-above-btn {
display: block;
}
.ppw-pcp-pf-desc-below-form {
font-size: " . get_theme_mod( 'ppwp_pcp_form_description_below_form_font_size', PPW_Constants::DEFAULT_TEXT_FONT_SIZE ) . "px!important;
font-weight: " . get_theme_mod( 'ppwp_pcp_form_description_below_form_font_weight', PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT ) . "!important;
color: " . get_theme_mod( 'ppwp_pcp_form_description_below_form_color', PPW_Constants::DEFAULT_TEXT_FONT_COLOR ) . "!important;
}
.ppw-input label.ppw-pcp-password-label {
font-size: " . get_theme_mod( 'ppwp_pcp_form_label_font_size', PPW_Constants::DEFAULT_TEXT_FONT_SIZE ) . "px!important;
font-weight: " . get_theme_mod( 'ppwp_pcp_form_label_font_weight', PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT ) . "!important;
color: " . get_theme_mod( 'ppwp_pcp_form_label_color', PPW_Constants::DEFAULT_TEXT_FONT_COLOR ) . "!important;
}
.ppw-form input[type='submit'] {
color: " . get_theme_mod( 'ppwp_pcp_button_text_color', PPW_Constants::DEFAULT_BUTTON_TEXT_FONT_COLOR ) . "!important;
background: " . get_theme_mod( 'ppwp_pcp_button_background_color', PPW_Constants::DEFAULT_BUTTON_BACKGROUND_COLOR ) . "!important;
}
.ppw-form input[type='submit']:hover {
color: " . get_theme_mod( 'ppwp_pcp_button_text_hover_color', PPW_Constants::DEFAULT_BUTTON_TEXT_HOVER_COLOR ) . "!important;
background: " . get_theme_mod( 'ppwp_pcp_button_background_hover_color', PPW_Constants::DEFAULT_BUTTON_BACKGROUND_HOVER_COLOR ) . "!important;
}
div.ppw-error.ppw-pcp-pf-error-msg {
font-size: " . get_theme_mod( 'ppwp_pcp_err_msg_text_font_size', PPW_Constants::DEFAULT_ERROR_TEXT_FONT_SIZE ) . "px!important;
font-weight: " . get_theme_mod( 'ppwp_pcp_err_msg_text_font_weight', PPW_Constants::DEFAULT_ERROR_TEXT_FONT_WEIGHT ) . "!important;
color: " . get_theme_mod( 'ppwp_pcp_err_msg_text_color', PPW_Constants::DEFAULT_ERROR_TEXT_FONT_COLOR ) . "!important;
background: " . get_theme_mod( 'ppwp_pcp_err_msg_background_color', PPW_Constants::DEFAULT_ERROR_TEXT_BACKGROUND_COLOR ) . "!important;
}
</style>
";
// compress $ppw_custom_css.
$ppw_custom_css = preg_replace( "/\s{2,}/", " ", str_replace( "\n", "", str_replace( ', ', ",", $ppw_custom_css ) ) );
echo $ppw_custom_css;
}
/*
* Optimize css.
*/
public function optimize_css( $sw_custom_css ) {
return preg_replace( "/\s{2,}/", " ", str_replace( "\n", "", str_replace( ', ', ",", $sw_custom_css ) ) );
}
}
}

View File

@@ -0,0 +1,440 @@
<?php
if ( ! class_exists( 'PPW_Customizer_Sitewide' ) ) {
// TODO: need to force PPW_Pro_Customizer_Service extend this class to remove the code duplication.
class PPW_Customizer_Sitewide {
/**
* Instance of PPW_Pro_Shortcode class.
*
* @var PPW_Customizer_Sitewide
*/
protected static $instance = null;
public function register_sitewide_form() {
add_action( 'customize_register', array( $this, 'customize_register' ), 15 );
}
public static function register_themes() {
$self = new self();
add_action( 'customize_register', array( $self, 'customize_register_themes' ), 25 );
add_action( 'ppw_custom_style_form_entire_site', array( $self, 'load_css_to_pro' ), 15 );
}
public function register_sitewide_style() {
add_action( PPW_Constants::HOOK_CUSTOM_STYLE_FORM_ENTIRE_SITE, array( $this, 'dynamic_styles' ) );
}
/**
* @param $wp_customize
*/
public function customize_register_themes( $wp_customize ) {
if ( ! class_exists( 'PPW_Presets_Control' ) ) {
include PPW_DIR_PATH . 'includes/customizers/class-ppw-presets.php';
}
$wp_customize->add_section( 'ppw_customize_presets', array(
'title' => __( 'Themes', 'password-protect-page' ),
'panel' => 'ppwp_sitewide',
'priority' => 50,
) );
$wp_customize->add_setting( 'ppw_customize_presets_settings', array(
'default' => 'default0',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control(
new PPW_Presets_Control( $wp_customize, 'ppw_customize_presets_settings',
array(
'section' => 'ppw_customize_presets',
// 'label' => __( 'Themes', 'loginpress' ),
'choices' => $this->get_templates(),
)
)
);
}
/**
* Get instance of PPW_Customizer
*
* @return PPW_Customizer_Sitewide
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
// Use static instead of self due to the inheritance later.
// For example: ChildSC extends this class, when we call get_instance
// it will return the object of child class. On the other hand, self function
// will return the object of base class.
self::$instance = new static();
}
return self::$instance;
}
/**
* Register customizer fields
*
* @param object $wp_customize customizer object.
*
* @return void
*/
public function customize_register( $wp_customize ) {
if ( ! class_exists( 'PPW_Toggle_Control' ) ) {
include PPW_DIR_PATH . 'includes/customizers/class-ppw-title-group-control.php';
}
if ( ! class_exists( 'PPW_Title_Group_Control' ) ) {
include PPW_DIR_PATH . 'includes/customizers/class-ppw-toggle-control.php';
}
/* register toggle control */
$wp_customize->register_control_type( 'PPW_Toggle_Control' );
$wp_customize->register_control_type( 'PPW_Title_Group_Control' );
$wp_customize->add_panel( 'ppwp_sitewide',
array(
'priority' => 9980,
'capability' => 'edit_theme_options',
'theme_supports' => '',
'title' => __( 'PPWP Sitewide Login Form', 'password-protect-page' ),
)
);
/* form logo section */
$wp_customize->add_section( 'ppwp_pro_form_logo', array(
'title' => __( 'Logo', 'password-protect-page' ),
'panel' => 'ppwp_sitewide',
'priority' => 100,
) );
// Add an option to disable the logo.
$wp_customize->add_setting( 'ppwp_pro_logo_disable' );
$wp_customize->add_control(
new PPW_Toggle_Control(
$wp_customize,
'ppwp_pro_logo_disable_control', array(
'label' => __( 'Disable Logo', 'password-protect-page' ),
'section' => 'ppwp_pro_form_logo',
'type' => 'toggle',
'settings' => 'ppwp_pro_logo_disable',
) )
);
/* logo customize */
$wp_customize->add_setting( 'ppwp_pro_logo_customize', array(
'default' => __( PPW_DIR_URL . 'includes/views/entire-site/assets/ppwp-logo.png', 'password-protect-page' ),
) );
$wp_customize->add_control(
new \WP_Customize_Image_Control(
$wp_customize,
'ppwp_pro_logo_customize_control', array(
'label' => __( 'Logo Image', 'password-protect-page' ),
'section' => 'ppwp_pro_form_logo',
'settings' => 'ppwp_pro_logo_customize',
) )
);
/* logo width */
$wp_customize->add_setting( 'ppwp_pro_logo_customize_width' );
$wp_customize->add_control( 'ppwp_pro_logo_customize_width_control', array(
'label' => __( 'Logo Width', 'password-protect-page' ),
'description' => __( 'Width in px', 'password-protect-page' ),
'section' => 'ppwp_pro_form_logo',
'settings' => 'ppwp_pro_logo_customize_width',
'type' => 'number',
) );
/* logo height */
$wp_customize->add_setting( 'ppwp_pro_logo_customize_height' );
$wp_customize->add_control( 'ppwp_pro_logo_customize_height_control', array(
'label' => __( 'Logo Height', 'password-protect-page' ),
'description' => __( 'Height in px', 'password-protect-page' ),
'section' => 'ppwp_pro_form_logo',
'settings' => 'ppwp_pro_logo_customize_height',
'type' => 'number',
) );
/* logo border-radius */
$wp_customize->add_setting( 'ppwp_pro_logo_customize_border_radius' );
$wp_customize->add_control( 'ppwp_pro_logo_customize_border_radius_control', array(
'label' => __( 'Logo Radius', 'password-protect-page' ),
'description' => __( 'Border Radius in %', 'password-protect-page' ),
'section' => 'ppwp_pro_form_logo',
'settings' => 'ppwp_pro_logo_customize_border_radius',
'type' => 'number',
) );
/* password form section */
$wp_customize->add_section( 'ppwp_pro_form_instructions', array(
'title' => __( 'Password Form', 'password-protect-page' ),
'panel' => 'ppwp_sitewide',
'priority' => 300,
) );
/* form section group */
$wp_customize->add_setting( 'ppwp_pro_form_section_group' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_pro_form_section_group', array(
'label' => __( 'Password Form', 'password-protect-page' ),
'section' => 'ppwp_pro_form_instructions',
'settings' => 'ppwp_pro_form_section_group',
'type' => 'control_title',
) )
);
/* form countdown section */
apply_filters('ppwp_customizer_custom_fields', $wp_customize, $wp_customize);
/* enable form transparency */
$wp_customize->add_setting( 'ppwp_pro_form_enable_transparency' );
$wp_customize->add_control(
new PPW_Toggle_Control(
$wp_customize,
'ppwp_pro_form_enable_transparency_control', array(
'label' => __( 'Enable Form Transparency', 'password-protect-page' ),
'section' => 'ppwp_pro_form_instructions',
'type' => 'toggle',
'settings' => 'ppwp_pro_form_enable_transparency',
) )
);
/* password form background color */
$wp_customize->add_setting( 'ppwp_pro_form_instructions_background_color', array(
'default' => '',
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pro_form_instructions_background_color_control', array(
'label' => __( 'Form Background Color', 'password-protect-page' ),
'section' => 'ppwp_pro_form_instructions',
'settings' => 'ppwp_pro_form_instructions_background_color',
) )
);
/* password form width */
$wp_customize->add_setting( 'ppwp_pro_form_instructions_width' );
$wp_customize->add_control( 'ppwp_pro_form_instructions_width_control', array(
'label' => __( 'Form Width', 'password-protect-page' ),
'section' => 'ppwp_pro_form_instructions',
'settings' => 'ppwp_pro_form_instructions_width',
'description' => 'Width in px',
'type' => 'number',
) );
/* password form border radius */
$wp_customize->add_setting( 'ppwp_pro_form_instructions_border_radius' );
$wp_customize->add_control( 'ppwp_pro_form_instructions_border_radius_control', array(
'label' => __( 'Form Border Radius', 'password-protect-page' ),
'section' => 'ppwp_pro_form_instructions',
'settings' => 'ppwp_pro_form_instructions_border_radius',
'description' => 'Border Radius in px',
'type' => 'number',
) );
/* password label group */
$wp_customize->add_setting( 'ppwp_pro_password_label_group' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_pro_password_label_group', array(
'label' => __( 'Password Field', 'password-protect-page' ),
'section' => 'ppwp_pro_form_instructions',
'settings' => 'ppwp_pro_password_label_group',
'type' => 'control_title',
) )
);
/* password label font size */
$wp_customize->add_setting( 'ppwp_pro_form_instructions_password_label_font_size' );
$wp_customize->add_control( 'ppwp_pro_form_instructions_password_label_font_size_control', array(
'label' => __( 'Font Size', 'password-protect-page' ),
'section' => 'ppwp_pro_form_instructions',
'settings' => 'ppwp_pro_form_instructions_password_label_font_size',
'description' => __( 'Font size in px', 'password-protect-page' ),
'type' => 'number',
) );
/* password label color */
$wp_customize->add_setting( 'ppwp_pro_form_instructions_password_label_color' );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pro_form_instructions_password_label_color_control', array(
'label' => __( 'Label Color', 'password-protect-page' ),
'section' => 'ppwp_pro_form_instructions',
'settings' => 'ppwp_pro_form_instructions_password_label_color',
) )
);
/* placeholder text */
$wp_customize->add_setting( 'ppwp_pro_form_instructions_placeholder' );
$wp_customize->add_control( 'ppwp_pro_form_instructions_placeholder_control', array(
'label' => __( 'Placeholder', 'password-protect-page' ),
'section' => 'ppwp_pro_form_instructions',
'settings' => 'ppwp_pro_form_instructions_placeholder',
'type' => 'text',
) );
/* form button section */
$wp_customize->add_section( 'ppwp_pro_form_button', array(
'title' => __( 'Button', 'password-protect-page' ),
'panel' => 'ppwp_sitewide',
'priority' => 400,
) );
/* button label */
$wp_customize->add_setting( 'ppwp_pro_form_button_label', array(
'default' => __( 'Enter', 'password-protect-page' ),
) );
$wp_customize->add_control( 'ppwp_pro_form_button_label_control', array(
'label' => __( 'Button Label', 'password-protect-page' ),
'section' => 'ppwp_pro_form_button',
'settings' => 'ppwp_pro_form_button_label',
'type' => 'text',
) );
/* button text color */
$wp_customize->add_setting( 'ppwp_pro_form_button_text_color' );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pro_form_button_text_color_control', array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => 'ppwp_pro_form_button',
'settings' => 'ppwp_pro_form_button_text_color',
) )
);
/* button background color */
$wp_customize->add_setting( 'ppwp_pro_form_button_background_color' );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_pro_form_button_background_color_control', array(
'label' => __( 'Background Color', 'password-protect-page' ),
'section' => 'ppwp_pro_form_button',
'settings' => 'ppwp_pro_form_button_background_color',
) )
);
}
/**
* Add dynamic styles
*
* TODO: move this styles into css file.
* @return void
*/
public function dynamic_styles() {
$sw_custom_css = $this->get_preset_css();
$sw_custom_css = $sw_custom_css . '
.pda-form-login {
width: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_instructions_width' ) ) . 'px!important;
}
.pda-form-login label {
font-size: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_instructions_password_label_font_size' ) ) . 'px!important;
color: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_instructions_password_label_color' ) ) . '!important;
}
.pda-form-login form {
background-color: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_instructions_background_color' ) ) . '!important;
border-radius: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_instructions_border_radius' ) ) . 'px!important;
}
.pda-form-login a.ppw-swp-logo {
background-image: none, url(' . esc_url( get_theme_mod( 'ppwp_pro_logo_customize', PPW_DIR_URL . 'includes/views/entire-site/assets/ppwp-logo.png' ) ) . ')!important;
background-size: cover;
width: ' . esc_attr( get_theme_mod( 'ppwp_pro_logo_customize_width', '' ) ) . 'px!important;
height: ' . esc_attr( get_theme_mod( 'ppwp_pro_logo_customize_height', '' ) ) . 'px!important;
border-radius: ' . esc_attr( get_theme_mod( 'ppwp_pro_logo_customize_border_radius', '' ) ) . '%!important;
}
.pda-form-login .button-login {
color: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_button_text_color' ) ) . '!important;
background-color: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_button_background_color' ) ) . '!important;
border-color: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_button_background_color' ) ) . '!important;
}
';
// remove space in $sw_custom_css.
$sw_custom_css = $this->optimize_css( $sw_custom_css );
echo $sw_custom_css; // phpcs:ignore -- we already escase inside the css
}
/*
* Optimize css.
*/
public function optimize_css( $sw_custom_css ) {
return preg_replace( "/\s{2,}/", " ", str_replace( "\n", "", str_replace( ', ', ",", $sw_custom_css ) ) );
}
/**
* Get templates.
*
* @return array
*/
public function get_templates() {
$free_templates = array();
$themes_name = array(
__( 'Default', 'password-protect-page' ),
__( 'Event', 'password-protect-page' ),
__( 'Business', 'password-protect-page' ),
__( 'Wedding', 'password-protect-page' ),
);
foreach ( $themes_name as $index => $theme_name ) {
$free_templates["default{$index}"] = array(
'thumbnail' => PPW_DIR_URL . 'includes/customizers/assets/images/thumbnail/sw-default' . $index . '.png',
'id' => "default{$index}",
'name' => $theme_name,
'css_file' => PPW_DIR_PATH . 'includes/customizers/assets/css/sw-default' . $index . '.php',
);
}
return apply_filters( 'ppw_customizer_sitewide_templates', $free_templates );
}
/**
* Get css of a theme.
*
* @return string
*/
public function get_preset_css() {
$default_preset = 'default0';
$preset = esc_attr( get_theme_mod( 'ppw_customize_presets_settings', $default_preset ) );
$sw_custom_css = '';
if ( $preset !== $default_preset ) {
$templates = $this->get_templates();
if ( isset( $templates[ $preset ], $templates[ $preset ]['css_file'] ) ) {
ob_start();
include_once( $templates[ $preset ]['css_file'] );
?>
@media screen and (max-width: 768px) {
.pda-form-login {
width: 100%;
}
.pda-form-login form {
width: 90%;
}
}
<?php
$sw_custom_css = ob_get_clean();
}
}
return $sw_custom_css;
}
public function load_css_to_pro() {
echo $this->optimize_css( $this->get_preset_css() ); // phpcs:ignores -- we don't need to escape css, already escape $preset above
}
}
}

View File

@@ -0,0 +1,63 @@
<?php
if ( ! class_exists( 'PPW_Customizer_Upsell' ) ) {
/**
* Register PPW_Customizer_Upsell Configurations.
*/
class PPW_Customizer_Upsell {
/**
* Register upsell section for customize
*
* @var PPW_Customizer_Upsell
*/
protected static $instance = null;
/**
* Constructor for PPW_Customizer_Upsell
*/
public function __construct() {
add_action( 'customize_register', array( $this, 'customize_register' ) );
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue' ) );
}
/**
* Get instance of PPW_Customizer_Upsell
*
* @return PPW_Customizer_Upsell
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new static();
}
return self::$instance;
}
public function customize_register( $wp_customize ) {
include PPW_DIR_PATH . 'includes/customizers/class-ppw-customize-link-section.php';
$wp_customize->register_section_type( 'PPW_Customize_Link_Section' );
$wp_customize->add_section(
new PPW_Customize_Link_Section( $wp_customize, 'ppwp_upsell',
array(
'ppwp_text' => __( 'More options available in PPWP Pro', 'password-protect-page' ),
'ppwp_url' => esc_url( 'https://passwordprotectwp.com/features/lite-vs-pro-version/?utm_source=user-website&utm_medium=wp-customizer&utm_campaign=ppwp-free#sitewide-customizer' ),
'capability' => 'edit_theme_options',
'priority' => 9999,
'type' => 'ppwp-upsell-section',
)
)
);
}
public function enqueue() {
wp_enqueue_script( 'ppw-upsell-section-scripts', PPW_DIR_URL . 'includes/customizers/assets/ppw-upsell-section.js', array( 'jquery' ), PPW_VERSION, true );
}
}
}

View File

@@ -0,0 +1,749 @@
<?php
if ( ! class_exists( 'PPW_Customizer_Service' ) ) {
class PPW_Customizer_Service {
/**
* Instance of PPW_Pro_Shortcode class.
*
* @var PPW_Customizer_Service
*/
protected static $instance = null;
/**
* Constructor for PPW_Customizer
*/
public function __construct() {
add_action( 'customize_register', array( $this, 'customize_register' ) );
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue' ) );
add_action( 'wp_head', array( $this, 'dynamic_styles' ) );
}
/**
* Get instance of PPW_Customizer
*
* @return PPW_Customizer_Service
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
// Use static instead of self due to the inheritance later.
// For example: ChildSC extends this class, when we call get_instance
// it will return the object of child class. On the other hand, self function
// will return the object of base class.
self::$instance = new static();
}
return self::$instance;
}
/**
* Get below text style.
*
* @return string
*/
public function get_below_text_style() {
if ( defined( 'PPW_PRO_VERSION' ) ) {
return '';
}
$desc_font_size = get_theme_mod( 'ppwp_form_instructions_below_text_font_size' );
$desc_font_weight = get_theme_mod( 'ppwp_form_instructions_below_text_font_weight' );
$desc_color = get_theme_mod( 'ppwp_form_instructions_below_text_color' );
$customizer_style = "
.ppw-ppf-desc-below {
font-size: " . $desc_font_size . "px!important;
font-weight: " . $desc_font_weight . "!important;
color: " . $desc_color . "!important;
}
";
return $customizer_style;
}
/**
* Add below description customize.
*
* @param $wp_customize
*/
public function add_below_desc( $wp_customize ) {
if ( defined( 'PPW_PRO_VERSION' ) ) {
return;
}
$wp_customize->add_setting( 'ppwp_form_instructions_description_below_title' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_form_instructions_description_below_title',
array(
'label' => __( 'Description Below Form', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_description_below_title',
'type' => 'control_title',
)
)
);
/* instructions text */
$wp_customize->add_setting( 'ppwp_form_instructions_below_text' );
$wp_customize->add_control(
new PPW_Text_Editor_Custom_Control(
$wp_customize,
'ppwp_form_instructions_below_text',
array(
'label' => __( 'Description', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_below_text',
'type' => 'textarea',
)
)
);
/* instructions font size */
$wp_customize->add_setting( 'ppwp_form_instructions_below_text_font_size' );
$wp_customize->add_control(
'ppwp_form_instructions_below_text_font_size_control',
array(
'label' => __( 'Font Size', 'password-protect-page' ),
'description' => __( 'Font size in px', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_below_text_font_size',
'type' => 'number',
) );
/* instructions font weight */
$wp_customize->add_setting( 'ppwp_form_instructions_below_text_font_weight' );
$wp_customize->add_control(
'ppwp_form_instructions_below_text_font_weight_control',
array(
'label' => __( 'Font Weight', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_below_text_font_weight',
'type' => 'number',
) );
/* text color - form instructions */
$wp_customize->add_setting( 'ppwp_form_instructions_below_text_color' );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_form_instructions_below_text_color_control',
array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_below_text_color',
)
)
);
}
/**
* Register customizer fields
*
* @param object $wp_customize customizer object.
*
* @return void
*/
public function customize_register( $wp_customize ) {
if ( ! class_exists( 'PPW_Title_Group_Control' ) ) {
include PPW_DIR_PATH . 'includes/customizers/class-ppw-title-group-control.php';
}
if ( ! class_exists( 'PPW_Toggle_Control' ) ) {
include PPW_DIR_PATH . 'includes/customizers/class-ppw-toggle-control.php';
}
if ( ! class_exists( 'PPW_Text_Editor_Custom_Control' ) ) {
include PPW_DIR_PATH . 'includes/customizers/class-ppw-text-editor-control.php';
}
/* register toggle control */
$wp_customize->register_control_type( 'PPW_Toggle_Control' );
$wp_customize->register_control_type( 'PPW_Title_Group_Control' );
$wp_customize->register_control_type( 'PPW_Text_Editor_Custom_Control' );
$wp_customize->add_panel( 'ppwp',
array(
'priority' => 9970,
'capability' => 'edit_theme_options',
'theme_supports' => '',
'title' => __( 'PPWP Single Password Form', 'password-protect-page' ),
)
);
/* form instructions section */
$wp_customize->add_section( 'ppwp_form_instructions', array(
'title' => __( 'Password Form', 'password-protect-page' ),
'panel' => 'ppwp',
'priority' => 100,
) );
$wp_customize->add_setting( 'ppwp_form_instructions_background_title' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_form_instructions_background_title', array(
'label' => __( 'Background', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_background_title',
'type' => 'control_title',
) )
);
/* form background color */
$wp_customize->add_setting( 'ppwp_form_instructions_background_color', array(
'default' => PPW_Constants::DEFAULT_FORM_BACKGROUND_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_form_instructions_background_color_control', array(
'label' => __( 'Background Color', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_background_color',
) )
);
/* form background padding */
$wp_customize->add_setting( 'ppwp_form_instructions_padding', array(
'default' => PPW_Constants::DEFAULT_FORM_PADDING,
) );
$wp_customize->add_control( 'ppwp_form_instructions_padding_control', array(
'label' => __( 'Padding', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'description' => 'Padding in px',
'settings' => 'ppwp_form_instructions_padding',
'type' => 'number',
) );
/* form background border radius */
$wp_customize->add_setting( 'ppwp_form_instructions_border_radius', array(
'default' => PPW_Constants::DEFAULT_FORM_BORDER_RADIUS,
) );
$wp_customize->add_control( 'ppwp_form_instructions_border_radius_control', array(
'label' => __( 'Border Radius', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'description' => 'Border Radius in px',
'settings' => 'ppwp_form_instructions_border_radius',
'type' => 'number',
) );
$wp_customize->add_setting( 'ppwp_form_instructions_headline_title' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_form_instructions_headline_title', array(
'label' => __( 'Headline', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_headline_title',
'type' => 'control_title',
) )
);
/* instructions headline */
$wp_customize->add_setting( 'ppwp_form_instructions_headline', array(
'default' => __( PPW_Constants::DEFAULT_HEADLINE_TEXT, 'password-protect-page' ),
) );
$wp_customize->add_control(
new PPW_Text_Editor_Custom_Control(
$wp_customize,
'ppwp_form_instructions_headline',
array(
'label' => __( 'Headline', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_headline',
'type' => 'textarea',
)
)
);
/* headline font size */
$wp_customize->add_setting( 'ppwp_form_instructions_headline_font_size', array(
'default' => PPW_Constants::DEFAULT_HEADLINE_FONT_SIZE,
) );
$wp_customize->add_control( 'ppwp_form_instructions_headline_font_size_control', array(
'label' => __( 'Font Size', 'password-protect-page' ),
'description' => __( 'Font size in px', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_headline_font_size',
'type' => 'number',
) );
/* headline font weight */
$wp_customize->add_setting( 'ppwp_form_instructions_headline_font_weight', array(
'default' => PPW_Constants::DEFAULT_HEADLINE_FONT_WEIGHT,
) );
$wp_customize->add_control( 'ppwp_form_instructions_headline_font_weight_control', array(
'label' => __( 'Font Weight', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_headline_font_weight',
'type' => 'number',
) );
/* headline color */
$wp_customize->add_setting( 'ppwp_form_instructions_headline_color', array(
'default' => PPW_Constants::DEFAULT_HEADLINE_FONT_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_form_instructions_headline_color_control', array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_headline_color',
) )
);
$wp_customize->add_setting( 'ppwp_form_instructions_description_title' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_form_instructions_description_title', array(
'label' => __( 'Description Above Form', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_description_title',
'type' => 'control_title',
) )
);
/* instructions text */
$wp_customize->add_setting( 'ppwp_form_instructions_text', array(
'default' => __( apply_filters( PPW_Constants::HOOK_MESSAGE_PASSWORD_FORM, PPW_Constants::DEFAULT_FORM_MESSAGE ), 'password-protect-page' ),
) );
$wp_customize->add_control(
new PPW_Text_Editor_Custom_Control(
$wp_customize,
'ppwp_form_instructions_text',
array(
'label' => __( 'Description', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_text',
'type' => 'textarea',
)
)
);
/* instructions font size */
$wp_customize->add_setting( 'ppwp_form_instructions_text_font_size', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_SIZE,
) );
$wp_customize->add_control( 'ppwp_form_instructions_text_font_size_control', array(
'label' => __( 'Font Size', 'password-protect-page' ),
'description' => __( 'Font size in px', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_text_font_size',
'type' => 'number',
) );
/* instructions font weight */
$wp_customize->add_setting( 'ppwp_form_instructions_text_font_weight', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT,
) );
$wp_customize->add_control( 'ppwp_form_instructions_text_font_weight_control', array(
'label' => __( 'Font Weight', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_text_font_weight',
'type' => 'number',
) );
/* text color - form instructions */
$wp_customize->add_setting( 'ppwp_form_instructions_text_color', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_form_instructions_text_color_control', array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_text_color',
) )
);
$this->add_below_desc( $wp_customize );
// Add one more tab below "Description Text Color" control.
do_action( 'ppw_customize_after_text_color', $wp_customize );
$wp_customize->add_setting( 'ppwp_form_instructions_label_title' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_form_instructions_label_title', array(
'label' => __( 'Password Field', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_label_title',
'type' => 'control_title',
) )
);
$wp_customize->add_setting( 'ppwp_form_instructions_password_label', array(
'default' => PPW_Constants::DEFAULT_PASSWORD_LABEL,
) );
$wp_customize->add_control( 'ppwp_form_instructions_password_label_control', array(
'label' => __( 'Password Label', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_password_label',
'type' => 'text',
) );
/* instructions font size */
$wp_customize->add_setting( 'ppwp_form_instructions_password_label_font_size', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_SIZE,
) );
$wp_customize->add_control( 'ppwp_form_instructions_password_label_font_size_control', array(
'label' => __( 'Font Size', 'password-protect-page' ),
'description' => __( 'Font size in px', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_password_label_font_size',
'type' => 'number',
) );
/* instructions font weight */
$wp_customize->add_setting( 'ppwp_form_instructions_password_label_font_weight', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT,
) );
$wp_customize->add_control( 'ppwp_form_instructions_password_label_font_weight_control', array(
'label' => __( 'Font Weight', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_password_label_font_weight',
'type' => 'number',
) );
/* text color - form instructions */
$wp_customize->add_setting( 'ppwp_form_instructions_password_label_color', array(
'default' => PPW_Constants::DEFAULT_TEXT_FONT_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_form_instructions_password_label_color_control', array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_password_label_color',
) )
);
/* placeholder text */
$wp_customize->add_setting( 'ppwp_form_instructions_placeholder', array(
'default' => __( PPW_Constants::DEFAULT_PLACEHOLDER, 'password-protect-page' ),
) );
$wp_customize->add_control( 'ppwp_form_instructions_placeholder_control', array(
'label' => __( 'Placeholder', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_placeholder',
'type' => 'text',
) );
$wp_customize->add_setting( 'ppwp_form_instructions_show_password_title' );
$wp_customize->add_control(
new PPW_Title_Group_Control(
$wp_customize,
'ppwp_form_instructions_show_password_title', array(
'label' => __( 'Show Password', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_show_password_title',
'type' => 'control_title',
) )
);
/* password typing - form instructions */
$wp_customize->add_setting( 'ppwp_form_instructions_is_show_password', array(
'default' => PPW_Constants::DEFAULT_IS_SHOW_PASSWORD,
) );
$wp_customize->add_control(
new PPW_Toggle_Control(
$wp_customize,
'ppwp_form_instructions_is_show_password_control', array(
'label' => __( 'Show Password Reveal Button', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'type' => 'toggle',
'settings' => 'ppwp_form_instructions_is_show_password',
) )
);
/* show password text */
$wp_customize->add_setting( 'ppwp_form_instructions_show_password_text', array(
'default' => PPW_Constants::DEFAULT_SHOW_PASSWORD_TEXT,
) );
$wp_customize->add_control( 'ppwp_form_instructions_show_password_text_control', array(
'label' => __( 'Button Text', 'password-protect-page' ),
'section' => 'ppwp_form_instructions',
'settings' => 'ppwp_form_instructions_show_password_text',
'type' => 'text',
) );
do_action('ppw_customize_after_form_instructions', $wp_customize);
/* form error message section */
$wp_customize->add_section( 'ppwp_form_error_message', array(
'title' => __( 'Error Messages', 'password-protect-page' ),
'panel' => 'ppwp',
'priority' => 200,
) );
/* error message text */
$wp_customize->add_setting( 'ppwp_form_error_message_text', array(
'default' => __( apply_filters( PPW_Constants::HOOK_MESSAGE_ENTERING_WRONG_PASSWORD, PPW_Constants::DEFAULT_WRONG_PASSWORD_MESSAGE ), 'password-protect-page' ),
) );
$wp_customize->add_control(
new PPW_Text_Editor_Custom_Control(
$wp_customize,
'ppwp_form_error_message_text',
array(
'label' => __( 'Wrong Password Message', 'password-protect-page' ),
'section' => 'ppwp_form_error_message',
'settings' => 'ppwp_form_error_message_text',
'type' => 'textarea',
'priority' => 10,
)
)
);
/* error message text */
$wp_customize->add_setting( 'ppwp_form_error_recaptcha_message_text', array(
'default' => __( PPW_Constants::DEFAULT_ERROR_RECAPTCHA_MESSAGE, 'password-protect-page' ),
) );
$wp_customize->add_control(
new PPW_Text_Editor_Custom_Control(
$wp_customize,
'ppwp_form_error_recaptcha_message_text',
array(
'label' => __( 'Failed reCAPTCHA Message', 'password-protect-page' ),
'section' => 'ppwp_form_error_message',
'settings' => 'ppwp_form_error_recaptcha_message_text',
'type' => 'textarea',
'priority' => 15,
)
)
);
/* error message font size */
$wp_customize->add_setting( 'ppwp_form_error_message_text_font_size', array(
'default' => PPW_Constants::DEFAULT_ERROR_TEXT_FONT_SIZE,
) );
$wp_customize->add_control( 'ppwp_form_error_message_text_font_size_control', array(
'label' => __( 'Font Size', 'password-protect-page' ),
'description' => __( 'Font size in px', 'password-protect-page' ),
'section' => 'ppwp_form_error_message',
'settings' => 'ppwp_form_error_message_text_font_size',
'type' => 'number',
'priority' => 20,
) );
/* error message font weight */
$wp_customize->add_setting( 'ppwp_form_error_message_text_font_weight', array(
'default' => PPW_Constants::DEFAULT_ERROR_TEXT_FONT_WEIGHT,
) );
$wp_customize->add_control( 'ppwp_form_error_message_text_font_weight_control', array(
'label' => __( 'Font Weight', 'password-protect-page' ),
'section' => 'ppwp_form_error_message',
'settings' => 'ppwp_form_error_message_text_font_weight',
'type' => 'number',
'priority' => 25,
) );
/* error message text color */
$wp_customize->add_setting( 'ppwp_form_error_message_text_color', array(
'default' => PPW_Constants::DEFAULT_ERROR_TEXT_FONT_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_form_error_message_text_color_control', array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => 'ppwp_form_error_message',
'settings' => 'ppwp_form_error_message_text_color',
'priority' => 30,
) )
);
/* error message background color */
$wp_customize->add_setting( 'ppwp_form_error_message_background_color', array(
'default' => '#ffffff',
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_form_error_message_background_color_control', array(
'label' => __( 'Background Color', 'password-protect-page' ),
'section' => 'ppwp_form_error_message',
'settings' => 'ppwp_form_error_message_background_color',
'priority' => 35,
) )
);
/* form button */
$wp_customize->add_section( 'ppwp_form_button', array(
'title' => __( 'Button', 'password-protect-page' ),
'panel' => 'ppwp',
'priority' => 300,
) );
/* button label */
$wp_customize->add_setting( 'ppwp_form_button_label', array(
'default' => __( PPW_Constants::DEFAULT_SUBMIT_LABEL, 'password-protect-page' ),
) );
$wp_customize->add_control( 'ppwp_form_button_label_control', array(
'label' => __( 'Button Label', 'password-protect-page' ),
'section' => 'ppwp_form_button',
'settings' => 'ppwp_form_button_label',
'type' => 'text',
) );
/* button text color */
$wp_customize->add_setting( 'ppwp_form_button_text_color', array(
'default' => PPW_Constants::DEFAULT_BUTTON_TEXT_FONT_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_form_button_text_color_control', array(
'label' => __( 'Text Color', 'password-protect-page' ),
'section' => 'ppwp_form_button',
'settings' => 'ppwp_form_button_text_color',
) )
);
/* button text hover color */
$wp_customize->add_setting( 'ppwp_form_button_text_hover_color', array(
'default' => PPW_Constants::DEFAULT_BUTTON_TEXT_HOVER_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_form_button_text_hover_color_control', array(
'label' => __( 'Text Color (Hover)', 'password-protect-page' ),
'section' => 'ppwp_form_button',
'settings' => 'ppwp_form_button_text_hover_color',
) )
);
/* button background color */
$wp_customize->add_setting( 'ppwp_form_button_background_color', array(
'default' => PPW_Constants::DEFAULT_BUTTON_BACKGROUND_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_form_button_background_color_control', array(
'label' => __( 'Background Color', 'password-protect-page' ),
'section' => 'ppwp_form_button',
'settings' => 'ppwp_form_button_background_color',
) )
);
/* button background hover color */
$wp_customize->add_setting( 'ppwp_form_button_background_hover_color', array(
'default' => PPW_Constants::DEFAULT_BUTTON_BACKGROUND_HOVER_COLOR,
) );
$wp_customize->add_control(
new \WP_Customize_Color_Control(
$wp_customize,
'ppwp_form_button_background_hover_color_control', array(
'label' => __( 'Background Color (Hover)', 'password-protect-page' ),
'section' => 'ppwp_form_button',
'settings' => 'ppwp_form_button_background_hover_color',
) )
);
}
/**
* Add dynamic styles
*
* @return void
*/
public function dynamic_styles() {
$below_text_styles = $this->get_below_text_style();
$ppw_custom_css = "
<style>
.ppw-ppf-input-container {
background-color: " . get_theme_mod( 'ppwp_form_instructions_background_color', PPW_Constants::DEFAULT_FORM_BACKGROUND_COLOR ) . "!important;
padding: " . get_theme_mod( 'ppwp_form_instructions_padding', PPW_Constants::DEFAULT_FORM_PADDING ) . "px!important;
border-radius: " . get_theme_mod( 'ppwp_form_instructions_border_radius', PPW_Constants::DEFAULT_FORM_BORDER_RADIUS ) . "px!important;
}
.ppw-ppf-input-container div.ppw-ppf-headline {
font-size: " . get_theme_mod( 'ppwp_form_instructions_headline_font_size', PPW_Constants::DEFAULT_HEADLINE_FONT_SIZE ) . "px!important;
font-weight: " . get_theme_mod( 'ppwp_form_instructions_headline_font_weight', PPW_Constants::DEFAULT_HEADLINE_FONT_WEIGHT ) . "!important;
color: " . get_theme_mod( 'ppwp_form_instructions_headline_color', PPW_Constants::DEFAULT_HEADLINE_FONT_COLOR ) . "!important;
}
.ppw-ppf-input-container div.ppw-ppf-desc {
font-size: " . get_theme_mod( 'ppwp_form_instructions_text_font_size', PPW_Constants::DEFAULT_TEXT_FONT_SIZE ) . "px!important;
font-weight: " . get_theme_mod( 'ppwp_form_instructions_text_font_weight', PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT ) . "!important;
color: " . get_theme_mod( 'ppwp_form_instructions_text_color', PPW_Constants::DEFAULT_TEXT_FONT_COLOR ) . "!important;
}
.ppw-ppf-input-container label.ppw-pwd-label {
font-size: " . get_theme_mod( 'ppwp_form_instructions_password_label_font_size', PPW_Constants::DEFAULT_TEXT_FONT_SIZE ) . "px!important;
font-weight: " . get_theme_mod( 'ppwp_form_instructions_password_label_font_weight', PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT ) . "!important;
color: " . get_theme_mod( 'ppwp_form_instructions_password_label_color', PPW_Constants::DEFAULT_TEXT_FONT_COLOR ) . "!important;
}
div.ppwp-wrong-pw-error {
font-size: " . get_theme_mod( 'ppwp_form_error_message_text_font_size', PPW_Constants::DEFAULT_ERROR_TEXT_FONT_SIZE ) . "px!important;
font-weight: " . get_theme_mod( 'ppwp_form_error_message_text_font_weight', PPW_Constants::DEFAULT_ERROR_TEXT_FONT_WEIGHT ) . "!important;
color: " . get_theme_mod( 'ppwp_form_error_message_text_color', PPW_Constants::DEFAULT_ERROR_TEXT_FONT_COLOR ) . "!important;
background: " . get_theme_mod( 'ppwp_form_error_message_background_color', PPW_Constants::DEFAULT_ERROR_TEXT_BACKGROUND_COLOR ) . "!important;
}
.ppw-ppf-input-container input[type='submit'] {
color: " . get_theme_mod( 'ppwp_form_button_text_color', PPW_Constants::DEFAULT_BUTTON_TEXT_FONT_COLOR ) . "!important;
background: " . get_theme_mod( 'ppwp_form_button_background_color', PPW_Constants::DEFAULT_BUTTON_BACKGROUND_COLOR ) . "!important;
}
.ppw-ppf-input-container input[type='submit']:hover {
color: " . get_theme_mod( 'ppwp_form_button_text_hover_color', PPW_Constants::DEFAULT_BUTTON_TEXT_HOVER_COLOR ) . "!important;
background: " . get_theme_mod( 'ppwp_form_button_background_hover_color', PPW_Constants::DEFAULT_BUTTON_BACKGROUND_HOVER_COLOR ) . "!important;
}
{$below_text_styles}
</style>
";
// compress $ppw_custom_css.
$ppw_custom_css = preg_replace( "/\s{2,}/", " ", str_replace( "\n", "", str_replace( ', ', ",", $ppw_custom_css ) ) );
echo $ppw_custom_css;
}
/**
* Enqueue script for customizer control
*/
public function enqueue() {
wp_enqueue_script( 'ppwp-customizer', PPW_DIR_URL . 'admin/js/customizer.js', array( 'jquery' ), PPW_VERSION, true );
wp_localize_script(
"ppwp-customizer",
'ppw_data',
array(
'backgroundDIR' => PPW_DIR_URL . 'includes/customizers/assets/images/backgrounds/',
)
);
}
}
}

View File

@@ -0,0 +1,168 @@
<?php
if ( ! class_exists( 'PPW_Entire_Site_Services' ) ) {
class PPW_Entire_Site_Services {
/**
* Auth cookie
*
* @return bool
*/
function validate_auth_cookie_entire_site() {
$cookie_elements = $this->parse_cookie_entire_site();
if ( false === $cookie_elements ) {
return false;
}
if ( (int) $cookie_elements[1] < time() ) {
return false;
}
$password = ppw_core_get_setting_entire_site_type_string( PPW_Constants::PASSWORD_ENTIRE_SITE );
$hash = hash_hmac( 'md5', PPW_Constants::ENTIRE_SITE_COOKIE_NAME, $password );
return $cookie_elements[0] === $hash;
}
/**
* Parse cookie
*
* @return array|bool
*/
function parse_cookie_entire_site() {
$_cookie = wp_unslash( $_COOKIE );
$cookie_name = PPW_Constants::ENTIRE_SITE_COOKIE_NAME;
if ( empty( $_cookie[ $cookie_name ] ) ) {
return false;
}
$cookie = $_cookie[ $cookie_name ];
$cookie_elements = explode( '|', $cookie );
if ( count( $cookie_elements ) !== 2 ) {
return false;
}
return $cookie_elements;
}
/**
* Check is valid password
*
* @param $password
*
* @return bool
*/
public function entire_site_is_valid_password( $password ) {
$_request = wp_unslash( $_REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
if ( ! isset( $_request['input_wp_protect_password'] ) ) {
return false;
}
$password_input = $_request['input_wp_protect_password'];
$validated = md5( $password_input ) === $password;
return apply_filters( 'ppw_sitewide_valid_password', $validated );
}
/**
* Set password to cookie
*
* @param string $password Password.
*/
public function entire_site_set_password_to_cookie( $password ) {
$expiration = time() + 7 * DAY_IN_SECONDS;
$cookie_expired = ppw_core_get_setting_type_string( PPW_Constants::COOKIE_EXPIRED );
if ( ! empty( $cookie_expired ) ) {
$time = explode( ' ', $cookie_expired )[0];
$unit = ppw_core_get_unit_time( $cookie_expired );
if ( 0 !== $unit ) {
$expiration = time() + (int) $time * $unit;
}
}
$hash = hash_hmac( 'md5', PPW_Constants::ENTIRE_SITE_COOKIE_NAME, $password );
$cookie = $hash . '|' . $expiration;
$expiration = apply_filters( 'ppw_sitewide_cookie_expiration', $expiration, $password );
ppw_free_bypass_cache_with_cookie_for_pro_version( $cookie, $expiration );
setcookie( PPW_Constants::ENTIRE_SITE_COOKIE_NAME, $cookie, $expiration, COOKIEPATH, COOKIE_DOMAIN );
}
/**
* Redirect after enter password
*/
public function entire_site_redirect_after_enter_password() {
// Can get the HTTP_REFERER first as the redirect URL that:
// Fixes the private link redirection belonged to PPP Pro.
$_server = wp_unslash( $_SERVER );
if ( ! empty( $_server['HTTP_REFERER'] ) ) {
$current_url = $_server['HTTP_REFERER'];
} else {
global $wp;
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
}
// TODO: consider to user wp_safe_redirect.
wp_redirect( $current_url );
}
/**
* Handle before update settings for entire site
*
* @param $data_settings
*
* @return bool
*/
public function handle_before_update_settings( $data_settings ) {
// Clear cache Super Cache plugin
// $free_cache = new PPW_Cache_Services();
// $free_cache->clear_cache_super_cache();
if ( array_key_exists( PPW_Constants::IS_PROTECT_ENTIRE_SITE, $data_settings ) && $data_settings[ PPW_Constants::IS_PROTECT_ENTIRE_SITE ] === "true" ) {
// Create new password
if ( ! array_key_exists( PPW_Constants::SET_NEW_PASSWORD_ENTIRE_SITE, $data_settings ) ) {
return $this->create_new_password( $data_settings );
}
// Change password
if ( array_key_exists( PPW_Constants::SET_NEW_PASSWORD_ENTIRE_SITE, $data_settings ) && $data_settings[ PPW_Constants::SET_NEW_PASSWORD_ENTIRE_SITE ] === "true" ) {
return $this->change_password( $data_settings );
}
// Don't change password
return true;
}
// Unprotect entire site
return delete_option( PPW_Constants::ENTIRE_SITE_OPTIONS );
}
/**
* Create new password entire site
*
* @param $data_settings
*
* @return bool
*/
public function create_new_password( $data_settings ) {
$data_settings[ PPW_Constants::PASSWORD_ENTIRE_SITE ] = md5( $data_settings[ PPW_Constants::PASSWORD_ENTIRE_SITE ] );
update_option( PPW_Constants::ENTIRE_SITE_OPTIONS, $data_settings );
return true;
}
/**
* Change password entire site
*
* @param $data_settings
*
* @return bool
*/
public function change_password( $data_settings ) {
$data_settings[ PPW_Constants::PASSWORD_ENTIRE_SITE ] = md5( $data_settings[ PPW_Constants::PASSWORD_ENTIRE_SITE ] );
unset( $data_settings[ PPW_Constants::SET_NEW_PASSWORD_ENTIRE_SITE ] );
update_option( PPW_Constants::ENTIRE_SITE_OPTIONS, $data_settings );
return true;
}
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* Created by PhpStorm.
* User: gaupoit
* Date: 7/31/19
* Time: 14:57
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'PPW_Default_PW_Manager_Services' ) ) {
class PPW_Default_PW_Manager_Services extends PPW_Migration_Manager {
/**
* Get module name.
*
* Retrieve the module name.
*
* @return string Module name.
* @since 1.7.0
* @access public
*
*/
public function get_name() {
return 'default-pwd-migration';
}
public function get_action() {
return 'ppw_default_pwd_migration';
}
public function get_plugin_name() {
return 'ppw';
}
public function get_plugin_label() {
return __( PPW_PLUGIN_NAME, 'password-protect-page' );
}
public function get_updater_label() {
return sprintf( '<strong>%s </strong> &#8211;', __( 'Password Protect WordPress', 'password-protect-page' ) );
}
public function get_query_limit() {
// TODO: Implement get_query_limit() method.
}
public function get_migrations_class() {
return 'PPW_Default_PW_Migrations';
}
public function get_migration_label() {
return sprintf( '<strong>%s </strong> &#8211;', __( 'PPWP Data Migration', 'password-protect-page' ) );
}
public function get_success_message() {
return '<p>' . sprintf( __( '%s The <a href="https://passwordprotectwp.com/password-migration/" target="_blank" rel="noopener noreferrer">password migration process</a> is now complete. Thank you for your patience!', 'password-protect-page' ), $this->get_updater_label() ) . '</p>';
}
}
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* User: gaupoit
* Date: 7/25/19
* Time: 14:48
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'PPW_Migration' ) ) {
class PPW_Migration extends PPW_Background_Task {
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Created by PhpStorm.
* User: gaupoit
* Date: 7/31/19
* Time: 14:57
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'PPW_Default_PW_Migrations' ) ) {
class PPW_Default_PW_Migrations {
public static function migrate_v_2_6_0() {
error_log( 'Migrate Default Password' );
$free_service = new PPW_Password_Services();
$free_service->migrate_default_password();
PPW_Options_Services::get_instance()->add_flag( PPW_Constants::MIGRATED_DEFAULT_PW );
error_log( 'Migrated OK' );
}
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* Created by PhpStorm.
* User: gaupoit
* Date: 7/30/19
* Time: 20:34
*/
if ( ! class_exists( 'PPW_Options_Services' ) ) {
class PPW_Options_Services {
protected static $instance;
private $prefix;
public function __construct() {
$this->prefix = 'ppw_pro';
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new PPW_Options_Services();
}
return self::$instance;
}
public function add_flag( $flag ) {
update_option( $this->prefix . '_' . $flag, 1 );
}
public function get_flag( $flag ) {
return get_option( $this->prefix . '_' . $flag );
}
public function delete_flag( $flag ) {
$option_name = $this->prefix . '_' . $flag;
if ( is_multisite() ) {
foreach ( get_sites() as $site ) {
delete_blog_option( $site->blog_id, $option_name );
}
} else {
delete_option( $option_name );
}
}
}
}

View File

@@ -0,0 +1,134 @@
<?php
class PPW_Password_Recovery_Manager extends PPW_Background_Task_Manager {
private $completed;
public function __construct() {
$this->handle_admin_notices();
parent::__construct();
}
protected function handle_admin_notices() {
if ( ! is_admin() ) {
return;
}
$action = 'admin_notices';
if ( $this->is_completed() ) {
add_action( $action, array( $this, 'admin_notice_upgrade_is_completed' ) );
}
if ( $this->is_running() ) {
add_action( $action, array( $this, 'admin_notice_upgrade_is_running' ) );
}
}
public function is_running() {
$task_runner = $this->get_task_runner();
return $task_runner->is_running();
}
public function is_completed() {
if ( isset( $this->completed ) ) {
return $this->completed;
}
$this->completed = $this->get_flag( 'completed' );
return $this->completed;
}
public function get_task_runner_class() {
return 'PPW_Password_Recovery';
}
public function get_query_limit() {
return 100;
}
public function on_runner_complete( $did_tasks = false ) {
// Implement log here
if ( $did_tasks ) {
$this->add_flag( 'completed' );
}
}
public function start_run() {
$updater = $this->get_task_runner();
if ( $updater->is_running() ) {
return;
}
$restore_password_callbacks = $this->get_restore_password_callbacks();
if ( empty( $restore_password_callbacks ) ) {
$this->on_runner_complete();
return;
}
foreach ( $restore_password_callbacks as $callback ) {
$updater->push_to_queue(
array(
'callback' => $callback,
)
);
}
$updater->save()->dispatch();
}
public function get_restore_password_callbacks() {
$callbacks[] = array( 'PPW_Password_Recovery_Manager', 'restore_passwords' );
return $callbacks;
}
public static function restore_passwords() {
return ( new PPW_Password_Services() )->restore_wp_post_password();
}
public function admin_notice_upgrade_is_running() {
$continue_action = $this->get_continue_action_url();
$message = '<p>'
. __( 'Password recovery process is running in the background.', 'password-protect-page' )
. '</p>'
. '<p>'
. sprintf( 'Taking a while? <a href="%s" class="button-primary">Click here to run it now</a>', $continue_action )
. '</p>';
echo '<div class="notice notice-warning">' . wp_kses_post( $message ) . '</div>';
}
public function admin_notice_upgrade_is_completed() {
$this->delete_flag( 'completed' );
$message = $this->get_success_message();
if ( ! empty( $message ) ) {
echo '<div class="notice notice-success">' . wp_kses_post( $message ) . '</div>';
}
}
public function get_action() {
return 'password_recovery_process';
}
public function get_plugin_name() {
return 'ppw';
}
public function get_plugin_label() {
return __( PPW_PLUGIN_NAME, 'password-protect-page' );
}
public function get_name() {
return 'ppw-password-recovery';
}
public function get_success_message() {
return '<p>' . sprintf( __( '%s <a href="https://passwordprotectwp.com/docs/password-migration/#backup" target="_blank" rel="noopener noreferrer">Password recovery process</a> is now complete.. Thank you for your patience!', 'password-protect-page' ), $this->get_updater_label() ) . '</p>';
}
public function get_updater_label() {
return sprintf( '<strong>%s </strong> &#8211;', __( 'Password Protect WordPress', 'password-protect-page' ) );
}
}

View File

@@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: gaupoit
* Date: 7/25/19
* Time: 14:48
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class PPW_Password_Recovery extends PPW_Background_Task {
}

View File

@@ -0,0 +1,566 @@
<?php
/**
*
* Class PPW_Recaptcha
*/
class PPW_Recaptcha {
const TYPE_PARAM = 'ppwp_type';
const TYPE_VALUE = 'recaptcha';
const RECAPTCHA_V3_TYPE = 'recaptcha_v3';
const RECAPTCHA_V2_CHECKBOX_TYPE = 'recaptcha_v2_checkbox';
const RECAPTCHA_V2_INVISIBLE_TYPE = 'recaptcha_v2_invisible';
const SINGLE_PASSWORD = 'single';
const PCP_PASSWORD = 'pcp';
const SITEWIDE_PASSWORD = 'sitewide';
private $show_message = false;
/**
* @var PPW_Recaptcha
*/
protected static $instance;
/**
* @return PPW_Recaptcha
*/
public static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Recaptcha error message.
*
* @return string
*/
public function get_error_message() {
$message = get_theme_mod( 'ppwp_form_error_recaptcha_message_text', PPW_Constants::DEFAULT_ERROR_RECAPTCHA_MESSAGE );
$message = wp_kses_post( $message );
return _x( $message, PPW_Constants::CONTEXT_PASSWORD_FORM, 'password-protect-page' );
}
/**
* Register hooks.
* @since 1.0.0
*/
public function register() {
add_filter( 'ppwp_customize_ppf', array( $this, 'maybe_customize_error_message' ), 25 );
add_filter( 'ppwp_ppf_redirect_url', array( $this, 'maybe_add_blocked_message' ), 20, 2 );
add_filter( 'ppwp_ppf_referrer_url', array( $this, 'maybe_remove_recaptcha_query' ), 10, 2 );
add_filter( 'ppwpea_recaptcha_v2_site_key', array( $this, 'get_ppwpea_recaptcha_v2_api_key' ), 10 );
add_filter( 'ppwpea_recaptcha_v2_secret', array( $this, 'get_ppwpea_recaptcha_v2_api_secret' ), 10 );
add_action( 'wp_footer', array( $this, 'load_js_in_footer' ), 10 );
add_action( 'ppw_custom_footer_form_entire_site', array( $this, 'maybe_load_sitewide_recaptcha_js' ), 10 );
add_action( 'ppw_sitewide_above_submit_button', array( $this, 'maybe_add_recaptcha_input_below_sitewide_form' ), 10 );
add_action( 'ppw_sitewide_custom_internal_css', array( $this, 'customize_sitewide_css' ), 10 );
add_filter( 'ppw_sitewide_valid_password', array( $this, 'validate_sitewide_password' ), 10 );
}
/**
* Remove blocked query if user enter right password.
*
* @param string $referrer_url Referrer URL.
*
* @return string
*/
public function maybe_remove_recaptcha_query( $referrer_url ) {
if ( ! $this->using_single_recaptcha() ) {
return $referrer_url;
}
if ( $this->has_recaptcha_parameter( $referrer_url ) ) {
$referrer_url = add_query_arg( self::TYPE_PARAM, false, $referrer_url );
}
return $referrer_url;
}
public function using_recaptcha() {
return ppw_core_get_setting_type_bool_by_option_name( PPW_Constants::USING_RECAPTCHA, PPW_Constants::EXTERNAL_OPTIONS );
}
/**
* Add blocked message if user turn on option.
*
* @param string $redirect_url Redirect URL.
* @param array $params Parameters.
*
* @return string
*/
public function maybe_add_blocked_message( $redirect_url, $params ) {
if ( ! $this->using_single_recaptcha() ) {
return $redirect_url;
}
if ( $params['is_valid'] ) {
return $redirect_url;
}
if ( ! $this->show_message ) {
// Remove blocked parameter if URL has it.
if ( $this->has_recaptcha_parameter( $redirect_url ) ) {
$redirect_url = add_query_arg( self::TYPE_PARAM, false, $redirect_url );
}
return $redirect_url;
}
$redirect_url = add_query_arg( self::TYPE_PARAM, self::TYPE_VALUE, $redirect_url );
return $redirect_url;
}
/**
* Has recaptcha parameter on URL.
*
* @param string $url $url URL.
* @param string $query_value Query value.
*
* @return bool
*/
private function has_recaptcha_parameter( $url = '', $query_value = self::TYPE_VALUE ) {
if ( empty( $url ) ) {
$query_params = ppw_core_get_query_param();
} else {
$query_params = ppw_core_get_param_in_url( $url );
}
if ( ! isset( $query_params[ self::TYPE_PARAM ] ) ) {
return false;
}
return $query_value === $query_params[ self::TYPE_PARAM ];
}
/**
* Customize error message.
*
* @param array $params Parameters.
*
* @return array
*/
public function maybe_customize_error_message( $params ) {
if ( ! $this->using_single_recaptcha() ) {
return $params;
}
if ( $this->has_recaptcha_parameter() ) {
$message = $this->get_error_message();
$params['error_msg'] = apply_filters( 'ppw_recaptcha_error_message', $message, $params );
}
return $params;
}
/**
* Validate recaptcha.
*
* @return bool
*/
public function is_valid_recaptcha() {
$_post = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- We no need to handle nonce verification here because already handle on parent function.
if ( ! isset( $_post['g-recaptcha-response'] ) ) {
$this->show_message = true;
return false;
}
$result = $this->verify_recaptcha( $_post['g-recaptcha-response'] );
if ( ! $result['success'] ) {
$this->show_message = true;
return false;
}
return true;
}
/**
* Get limit score.
*
* @return double
*/
public function get_limit_score() {
$score = ppw_core_get_settings_by_option_name( PPW_Constants::RECAPTCHA_SCORE, PPW_Constants::EXTERNAL_OPTIONS );
if ( is_null( $score ) ) {
return (double) 0.5;
}
return (double) $score;
}
/**
* Get setting api key of recaptcha with current type.
*
* @param string $type Recaptcha type.
* @param string $default Default value.
*
* @return string
*/
public function get_setting_api_key( $type = '', $default = '' ) {
if ( empty( $type ) ) {
$type = $this->get_recaptcha_type();
}
switch ( $type ) {
case self::RECAPTCHA_V3_TYPE:
return $this->get_recaptcha_v3_api_key();
case self::RECAPTCHA_V2_CHECKBOX_TYPE:
return $this->get_recaptcha_v2_api_key();
default:
return $default;
}
}
/**
* Get setting api secret of recaptcha with current type.
*
* @param string $type Recaptcha type.
* @param string $default Default value.
*
* @return string
*/
public function get_setting_api_secret( $type = '', $default = '' ) {
if ( empty( $type ) ) {
$type = $this->get_recaptcha_type();
}
switch ( $type ) {
case self::RECAPTCHA_V3_TYPE:
return $this->get_recaptcha_v3_api_secret();
case self::RECAPTCHA_V2_CHECKBOX_TYPE:
return $this->get_recaptcha_v2_api_secret();
default:
return $default;
}
}
/**
* Get recaptcha v3 API key.
*
* @return string
*/
public function get_recaptcha_v3_api_key() {
return ppw_core_get_setting_type_string_by_option_name( PPW_Constants::RECAPTCHA_API_KEY, PPW_Constants::EXTERNAL_OPTIONS );
}
/**
* Get recaptcha v3 API secret.
*
* @return string
*/
public function get_recaptcha_v3_api_secret() {
return ppw_core_get_setting_type_string_by_option_name( PPW_Constants::RECAPTCHA_API_SECRET, PPW_Constants::EXTERNAL_OPTIONS );
}
/**
* Get recaptcha v2 API key.
*
* @return string
*/
public function get_recaptcha_v2_api_key() {
return ppw_core_get_setting_type_string_by_option_name( PPW_Constants::RECAPTCHA_V2_CHECKBOX_API_KEY, PPW_Constants::EXTERNAL_OPTIONS );
}
/**
* Get recaptcha v2 API secret.
*
* @return string
*/
public function get_recaptcha_v2_api_secret() {
return ppw_core_get_setting_type_string_by_option_name( PPW_Constants::RECAPTCHA_V2_CHECKBOX_API_SECRET, PPW_Constants::EXTERNAL_OPTIONS );
}
/**
* Get recaptcha type.
*
* @return string
*/
public function get_recaptcha_type() {
$recaptcha_type = ppw_core_get_setting_type_string_by_option_name( PPW_Constants::RECAPTCHA_TYPE, PPW_Constants::EXTERNAL_OPTIONS );
return $recaptcha_type ? $recaptcha_type : self::RECAPTCHA_V3_TYPE;
}
/**
* Get password types selected.
*
* @return string[]
*/
public function get_password_types() {
$password_types = ppw_core_get_setting_type_array_by_option_name( PPW_Constants::RECAPTCHA_PASSWORD_TYPES, PPW_Constants::EXTERNAL_OPTIONS );
return $password_types ? $password_types : array( 'single' );
}
/**
* Using single recaptcha
*
* @return bool
*/
public function using_single_recaptcha() {
return $this->using_recaptcha() && in_array( self::SINGLE_PASSWORD, $this->get_password_types() );
}
/**
* Using sitewide recaptcha
*
* @return bool
*/
public function using_sitewide_recaptcha() {
return $this->using_recaptcha() && in_array( self::SITEWIDE_PASSWORD, $this->get_password_types() );
}
/**
* Using sitewide recaptcha
*
* @return bool
*/
public function using_pcp_recaptcha() {
return $this->using_recaptcha() && in_array( self::PCP_PASSWORD, $this->get_password_types() );
}
/**
* Load recaptcha v2 javascript.
*/
public function load_recaptcha_v2_js() {
ob_start();
?>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<?php
echo ob_get_clean(); // phpcs:ignore -- we cannot escape ob_start ob_get_clean(), there are no variable to escape in statement above
}
/**
* Load recaptcha v3 javascript.
*/
public function load_recaptcha_v3_js() {
$recaptcha_key = $this->get_recaptcha_v3_api_key();
ob_start();
?>
<script src="https://www.google.com/recaptcha/api.js?render=<?php echo esc_attr( $recaptcha_key ); ?>"></script>
<script>
grecaptcha.ready(function () {
grecaptcha.execute('<?php echo esc_attr( $recaptcha_key ); ?>', {action: 'enter_password'}).then(function (token) {
var recaptchaResponse = document.getElementById('ppwRecaptchaResponse');
recaptchaResponse.value = token;
});
});
</script>
<?php
echo ob_get_clean(); // phpcs:ignore -- we already escape the $recaptcha_key above
}
/**
* Verify google recaptcha V3.
*
* @param string $recaptcha_response Recaptcha response.
*
* @return array
*/
public function verify_recaptcha( $recaptcha_response ) {
$default = array(
'success' => false,
'message' => '',
);
if ( ! $recaptcha_response ) {
return $default;
}
$secret = $this->get_setting_api_secret();
if ( ! $secret ) {
return $default;
}
$response = wp_remote_post(
'https://www.google.com/recaptcha/api/siteverify',
array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => array(
'secret' => $secret,
'response' => $recaptcha_response,
),
'cookies' => array(),
)
);
if ( is_wp_error( $response ) ) {
return $default;
}
$body = wp_remote_retrieve_body( $response );
$body = json_decode( $body );
// Whether this request was a valid reCAPTCHA token for your site.
$success = isset( $body->success ) && $body->success;
$external = true;
if ( $this->get_recaptcha_type() === self::RECAPTCHA_V3_TYPE ) {
$limit_score = $this->get_limit_score();
// The score for this request (0.0 - 1.0) 1.0 is very likely a good interaction, 0.0 is very likely a bot.
$score = isset( $body->score ) ? (double) $body->score : 0;
$external = $score > $limit_score;
}
$default['success'] = $success && $external;
return $default;
}
/**
* Load PPWPEA api key.
*
* @param string $key Recaptcha API key.
*
* @return string
*/
public function get_ppwpea_recaptcha_v2_api_key( $key ) {
return $this->get_recaptcha_v2_api_key();
}
/**
* Load PPWPEA api secret.
*
* @param string $secret Recaptcha API secret.
*
* @return string
*/
public function get_ppwpea_recaptcha_v2_api_secret( $secret ) {
return $this->get_recaptcha_v2_api_secret();
}
public function maybe_load_sitewide_recaptcha_js() {
if ( ! $this->using_sitewide_recaptcha() ) {
return;
}
$this->add_recaptcha_to_head();
}
/**
* Add recaptcha to head.
*/
public function add_recaptcha_to_head() {
$recaptcha_type = $this->get_recaptcha_type();
switch ( $recaptcha_type ) {
case self::RECAPTCHA_V3_TYPE:
$this->load_recaptcha_v3_js();
break;
case self::RECAPTCHA_V2_CHECKBOX_TYPE:
case self::RECAPTCHA_V2_INVISIBLE_TYPE:
$this->load_recaptcha_v2_js();
break;
}
}
/**
* Add recaptcha input below sitewide form.
*/
public function maybe_add_recaptcha_input_below_sitewide_form() {
$recaptcha_input = $this->get_recaptcha_input();
if ( ! empty( $recaptcha_input ) ) {
echo $recaptcha_input;
}
}
/**
* Get recaptcha input.
*
* @return string
*/
public function get_recaptcha_input() {
switch ( $this->get_recaptcha_type() ) {
case PPW_Recaptcha::RECAPTCHA_V2_CHECKBOX_TYPE:
$site_key = $this->get_recaptcha_v2_api_key();
return '<div class="ppw-recaptcha g-recaptcha" data-sitekey="' . $site_key . '"></div>';
default:
return '<input type="hidden" name="g-recaptcha-response" id="ppwRecaptchaResponse" />';
}
}
/**
* Customize sitewide css.
*/
public function customize_sitewide_css() {
if ( ! $this->using_sitewide_recaptcha() ) {
return;
}
?>
.g-recaptcha {
transform:scale(0.9);
transform-origin:0 0;
}
<?php
}
/**
* Validate sitewide password form.
*
* @param $validated
*
* @return bool
*/
public function validate_sitewide_password( $validated ) {
if ( ! $validated ) {
return $validated;
}
if ( ! $this->using_sitewide_recaptcha() ) {
return $validated;
}
if ( ! $this->is_valid_recaptcha() ) {
add_filter( 'ppw_sitewide_error_message', array( $this, 'get_sitewide_error_message' ) );
return false;
}
return $validated;
}
/**
* Get sitewide error message.
*
* @return string
*/
public function get_sitewide_error_message() {
return __( 'Google reCAPTCHA verification failed, please try again later.', 'password-protect-page' );
}
/**
* Load JS in footer.
*/
public function load_js_in_footer() {
if ( ! $this->using_single_recaptcha() ) {
return;
}
$allowed = is_singular();
$allowed = apply_filters( 'ppw_recaptcha_allowed_to_load_script', $allowed );
if ( ! $allowed ) {
return;
}
$post_id = get_the_ID();
if ( ! $post_id || ! post_password_required( $post_id ) ) {
return;
}
$this->add_recaptcha_to_head();
}
}

View File

@@ -0,0 +1,803 @@
<?php
/**
* PPWP Shortcoe
*/
if ( ! class_exists( 'PPW_Shortcode' ) ) {
/**
*
* Class PPW_Shortcode
*/
class PPW_Shortcode {
/**
* Short code attributes.
*
* @var array
*/
private $attributes;
/**
* Supported roles.
*
* @var array
*/
private $supported_roles;
/**
* Supported post types.
*
* @var array
*/
private $supported_post_types;
/**
* The main class name which using to add the index.
*
* @var string
*/
private $main_class_name;
/**
* Register the short code ppwp_content_protector with WordPress
* and include the asserts for it.
*/
public function __construct() {
$this->attributes = apply_filters(
PPW_Constants::HOOK_SHORT_CODE_ATTRS,
array(
'passwords' => '',
'headline' => PPW_Constants::DEFAULT_SHORTCODE_HEADLINE,
'description' => PPW_Constants::DEFAULT_SHORTCODE_DESCRIPTION,
'id' => '',
'class' => '',
'placeholder' => '',
'button' => PPW_Constants::DEFAULT_SHORTCODE_BUTTON,
'whitelisted_roles' => '',
'group' => '',
'label' => PPW_Constants::DEFAULT_SHORTCODE_LABEL,
'error_msg' => PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG,
'loading' => PPW_Constants::DEFAULT_SHORTCODE_LOADING,
'on' => '',
'off' => '',
'acf_field' => '',
'show_password' => PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD,
'show_password_text' => PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD_TEXT,
'section' => 0,
'desc_above_btn' => PPW_Constants::DEFAULT_SHORTCODE_DESC_ABOVE_PWD_BTN,
'desc_below_form' => PPW_Constants::DEFAULT_SHORTCODE_DESC_BELOW_PWD_FORM,
)
);
// Defined by WordPress: https://wordpress.org/support/article/roles-and-capabilities/.
$this->supported_roles = apply_filters(
PPW_Constants::HOOK_SUPPORTED_WHITELIST_ROLES,
array(
'administrator',
'editor',
'author',
'contributor',
'subscriber',
)
);
$this->supported_post_types = apply_filters(
PPW_Constants::HOOK_SUPPORTED_POST_TYPES,
array(
'page',
'post',
)
);
add_shortcode( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME, array( $this, 'render_shortcode' ) );
add_filter( 'ppw_content_shortcode_source', array( $this, 'render_block_content' ), 15 );
// Support page builder.
add_action( 'the_post', array( $this, 'maybe_remove_ppwp_shortcode' ), 10 );
add_action( 'the_post', array( $this, 'maybe_add_ppwp_shortcode' ), 99999 );
/**
* Need to keep the old Pro version work, because the sidewide shortcode is using global var ppwContentGlobal.
*/
if ( defined( 'PPW_PRO_VERSION' ) ) {
$pro_version = ppw_get_pro_version();
if ( version_compare( $pro_version, '1.2.2', '<' ) ) {
add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) );
}
}
$this->main_class_name = PPW_Constants::DEFAULT_SHORTCODE_CLASS_NAME;
}
/**
* Maybe remove shortcode before WPBakery and WordPress do_shortcode in FrontEnd.
*/
public function maybe_remove_ppwp_shortcode() {
if ( ! ppw_free_has_support_shortcode_page_builder() ) {
return;
}
remove_shortcode( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME );
}
/**
* Maybe add shortcode back.
*/
public function maybe_add_ppwp_shortcode() {
if ( ! ppw_free_has_support_shortcode_page_builder() ) {
return;
}
add_filter( 'the_content', function ( $content ) {
add_shortcode( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME, array( $this, 'render_shortcode' ) );
/* translators: Opening curly double quote. */
$opening_quote = _x( '&#8220;', 'opening curly double quote' );
/* translators: Closing curly double quote. */
$closing_quote = _x( '&#8221;', 'closing curly double quote' );
/* translators: Apostrophe, for example in 'cause or can't. */
$apos = _x( '&#8217;', 'apostrophe' );
/* translators: Prime, for example in 9' (nine feet). */
$prime = _x( '&#8242;', 'prime' );
/* translators: Double prime, for example in 9" (nine inches). */
$double_prime = _x( '&#8243;', 'double prime' );
/* translators: Opening curly single quote. */
$opening_single_quote = _x( '&#8216;', 'opening curly single quote' );
/* translators: Closing curly single quote. */
$closing_single_quote = _x( '&#8217;', 'closing curly single quote' );
$matches = ppw_free_search_shortcode_content( $content );
if ( ! empty( $matches ) ) {
foreach ( $matches as $match ) {
// The shortcode argument list
$old_argument_shortcode = $match[3];
$argument_shortcode = $match[3];
$argument_shortcode = str_replace( $opening_quote, '"', $argument_shortcode );
$argument_shortcode = str_replace( $closing_quote, '"', $argument_shortcode );
$argument_shortcode = str_replace( $apos, '\'', $argument_shortcode );
$argument_shortcode = str_replace( $prime, '\'', $argument_shortcode );
$argument_shortcode = str_replace( $double_prime, '"', $argument_shortcode );
$argument_shortcode = str_replace( $opening_single_quote, '\'', $argument_shortcode );
$argument_shortcode = str_replace( $closing_single_quote, '\'', $argument_shortcode );
$content = str_replace( $old_argument_shortcode, $argument_shortcode, $content );
}
}
$content = do_shortcode( $content );
return $content;
}, 99999 );
}
/**
* Get short code instance
*
* @return PPW_Shortcode
*/
public static function get_instance() {
return new PPW_Shortcode();
}
/**
* Render password form or restricted content
* 0. Check current post type is in whitelist types
* 1. Check is valid attributes
* 2. Check whitelist roles
* 3. Check password is correct compare to Cookie
* 4. Show form
*
* @param array $attrs list of attributes including password.
* @param string $content the content inside short code.
*
* @return string
*/
public function render_shortcode( $attrs, $content = null ) {
global $page;
// In case the shortcode is outside in the loop, the page is 0.
$number = ! empty( $page ) ? $page : 1;
$this->attributes = apply_filters( 'ppw_pcp_attributes', $this->attributes, $number );
$attrs = shortcode_atts(
$this->attributes,
$attrs
);
$message = $this->is_valid_shortcode( $attrs, $content );
$message = apply_filters( 'ppw_pcp_valid_shortcode', $message, $attrs );
if ( true !== $message ) {
return $this->get_invalid_shortcode_message( $message, $attrs );
}
$content = sprintf(
'<div class="%s">%s</div>',
$this->get_main_class_name( $attrs ),
do_shortcode( $content )
);
$whitelisted_roles = apply_filters( PPW_Constants::HOOK_SHORT_CODE_WHITELISTED_ROLES, $attrs['whitelisted_roles'] );
if ( $this->is_whitelisted_role( $whitelisted_roles ) ) {
// Remember to wrap the content between the parent div. If you want to replace the shortcode content.
return apply_filters( PPW_Constants::HOOK_SHORTCODE_RENDER_CONTENT, $content, $attrs );
}
// Unlock content by datetime.
$unlocked = apply_filters( 'ppw_shortcode_unlock_content', $this->is_unlock_content_by_time( $attrs ), $attrs );
if ( $unlocked ) {
return apply_filters( PPW_Constants::HOOK_SHORTCODE_RENDER_CONTENT, $content, $attrs );
}
do_action( PPW_Constants::HOOK_SHORT_CODE_BEFORE_CHECK_PASSWORD, $content );
// Passwords attribute format: passwords="123 345 898942".
$passwords = apply_filters( PPW_Constants::HOOK_SHORTCODE_PASSWORDS, array_filter( explode( ' ', trim( $attrs['passwords'] ) ), 'strlen' ), $attrs );
foreach ( $passwords as $password ) {
// When passwords attribute having special characters eg: <script>alert('hello')</script>. WP will encode the HTML tag. Need to decode to compare the value in Cookie.
$hashed_password = wp_hash_password( wp_specialchars_decode( $password ) );
if ( $this->is_valid_password( $hashed_password ) ) {
// Remember to wrap the content between the parent div. If you want to replace the shortcode content.
return apply_filters( PPW_Constants::HOOK_SHORTCODE_RENDER_CONTENT, $content, $attrs );
}
}
do_action( PPW_Constants::HOOK_SHORT_CODE_AFTER_CHECK_PASSWORD, $content );
$this->add_scripts();
// Show custom text instead of password form.
$custom_form = apply_filters( PPW_Constants::HOOK_SHORTCODE_BEFORE_RENDER_PASSWORD_FORM, false, $attrs );
if ( false !== $custom_form ) {
return sprintf(
'<div class="%s">%s</div>',
$this->get_main_class_name( $attrs ),
$this->massage_attributes( $custom_form )
);
}
$password_form = $this->get_restricted_content_form( $attrs, $number );
return apply_filters( 'ppw_pcp_password_form', $password_form, $attrs );
}
/**
* Show content if user set on_date or off_date attribute.
* $on_date: Date to unlock content
* $off_date: Date to protect content.
*
* @param array $attrs Attributes.
*
* @return false True is unlock content else false.
*/
private function is_unlock_content_by_time( $attrs ) {
$on_date = false;
if ( '' !== $attrs['on'] ) {
$on_date = strtotime( $attrs['on'] );
}
$off_date = false;
if ( '' !== $attrs['off'] ) {
$off_date = strtotime( $attrs['off'] );
}
// Show password form if on_date and off_date are empty.
if ( ! $on_date && ! $off_date ) {
return false;
}
$now = current_time( 'timestamp' );
// Unlock content between on_date and off_date.
if ( $on_date && $off_date && $on_date <= $now && $off_date >= $now ) {
return apply_filters( 'ppw_shortcode_unlock_content_by_time', true, $attrs );
}
// Unlock content from on_date.
if ( $on_date && ! $off_date && $now >= $on_date ) {
return apply_filters( 'ppw_shortcode_unlock_content_by_time', true, $attrs );
}
return false;
}
/**
* Require javascript bundle file for shortcode.
*/
public function add_scripts() {
static $count_script = 0;
$count_script ++;
$assert_folder = '/public/js/dist';
$is_using_pcp_recaptcha = PPW_Recaptcha::get_instance()->using_pcp_recaptcha();
wp_enqueue_script(
'ppw-cookie',
PPW_DIR_URL . "$assert_folder/ppw-rc-form.bundle.js",
array( 'jquery' ),
PPW_VERSION,
false
);
wp_localize_script(
'ppw-cookie',
'ppwContentGlobal',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'restUrl' => get_rest_url(),
'ajax_nonce' => wp_create_nonce( 'ppw_pcp_nonce' ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'cookieExpiration' => $this->get_cookie_expiration(),
'supportedClassNames' => apply_filters(
'ppw_shortcode_supported_class_name',
array(
'defaultType' => PPW_Constants::DEFAULT_SHORTCODE_CLASS_NAME,
)
),
'label' => array(
'LOADING' => _x( 'Loading...', PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
),
'isUsingPCPRecaptcha' => $is_using_pcp_recaptcha
)
);
// Avoid conflict with updating post on Gutenberg when updating post.
if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) {
if ( $is_using_pcp_recaptcha && $count_script === 1 ) {
add_action( 'wp_footer', function () {
PPW_Recaptcha::get_instance()->add_recaptcha_to_head();
} );
}
}
}
/**
* Check whether short code is valid.
*
* @param array $attrs Shortcode attributes.
* @param string $content Short code content.
*
* @return string
*/
private function is_valid_shortcode( $attrs, $content ) {
if ( ! $this->is_supported_post_types( get_post_type() ) ) {
/* translators: %s: Short code name */
$message = sprintf( __( 'Our Free version [%s] shortcode doesn\'t support Custom Post Type', 'password-protect-page' ), PPW_Constants::PPW_HOOK_SHORT_CODE_NAME );
return apply_filters( PPW_Constants::HOOK_SHORTCODE_NOT_SUPPORT_TYPE_ERROR_MESSAGE, $message );
}
/* translators: %s: Short code name */
$message = sprintf( __( '[%s] Empty content, invalid attributes or values', 'password-protect-page' ), PPW_Constants::PPW_HOOK_SHORT_CODE_NAME );
$message = apply_filters( PPW_Constants::HOOK_SHORT_CODE_ERROR_MESSAGE, $message );
if ( $this->is_empty_content( $content, $attrs ) ) {
return $message;
}
if ( ! $this->is_valid_attributes( $attrs ) ) {
return $message;
}
return true;
}
/**
* @param $attrs
*/
private function is_valid_date( $attrs ) {
if ( '' !== $attrs['on'] && ! ppw_free_validate_date( $attrs['on'] ) ) {
return false;
}
if ( '' !== $attrs['off'] && ! ppw_free_validate_date( $attrs['off'] ) ) {
return false;
}
return true;
}
/**
* Check if the password is valid, comparing with cookie.
*
* @param string $password Password.
*
* @return bool
*/
private function is_valid_password( $password ) {
$is_valid = apply_filters( 'ppw_shortcode_is_valid_password_with_cookie', false, $password, $_COOKIE );
if ( $is_valid ) {
return apply_filters( 'ppw_shortcode_after_check_is_valid_password_with_cookie', $is_valid, $password, array() );
}
$cookie_name = 'ppw_rc-' . get_the_ID();
if ( ! isset( $_COOKIE[ $cookie_name ] ) ) {
return false;
}
global $wp_hasher;
$cookie_val = json_decode( wp_unslash( $_COOKIE[ $cookie_name ] ) ); // phpcs:ignore -- Here do not need to sanitize $_COOKIE data, because we use it for comparision.
if ( ! is_array( $cookie_val ) ) {
return false;
}
foreach ( $cookie_val as $val ) {
if ( get_the_ID() !== (int) $val->post_id ) {
continue;
}
foreach ( $val->passwords as $cookie_pass ) {
if ( $wp_hasher->CheckPassword( $cookie_pass, $password ) ) {
return true;
}
}
}
return false;
}
/**
* Get restricted content form.
*
* @param array $attrs Short-code attributes.
* @param int $number Short-code attributes.
*
* @return array|mixed
*/
private function get_restricted_content_form( $attrs, $number ) {
$checkbox = '';
if ( wp_validate_boolean( $attrs['show_password'] ) ) {
$checkbox = '<label class="ppw-pcp-checkbox-label"><input class="ppw-pcp-checkbox" type="checkbox" /> ' . _x( $this->massage_attributes( $attrs['show_password_text'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ) . '</label>';
}
$desc_above_btn = '';
if ( wp_validate_boolean( $attrs['desc_above_btn'] ) ) {
$desc_above_btn = '<span class="ppw-pcp-pf-desc-above-btn">'._x( $this->massage_attributes( $attrs['desc_above_btn'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ).'</span>';
}
// Temp hide recaptcha on section protection.
if ( PPW_Recaptcha::get_instance()->using_pcp_recaptcha() && empty( $attrs['section'] ) ) {
$recaptcha_input = PPW_Recaptcha::get_instance()->get_recaptcha_input();
} else {
$recaptcha_input = '';
}
ob_start();
include apply_filters(
PPW_Constants::HOOK_SHORT_CODE_TEMPLATE,
PPW_DIR_PATH . 'includes/views/shortcode/view-ppw-restriced-content-form.php'
);
$form_template = ob_get_contents();
ob_end_clean();
$className = '' === $attrs['class'] ? $this->get_main_class_name( $attrs ) : $this->get_main_class_name( $attrs ) . ' ' . $attrs['class'];
// phpcs:disable
$form_params = array(
PPW_Constants::SHORT_CODE_FORM_HEADLINE => _x( $this->massage_attributes( $attrs['headline'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
PPW_Constants::SHORT_CODE_FORM_INSTRUCT => _x( $this->massage_attributes( $attrs['description'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
PPW_Constants::SHORT_CODE_FORM_PLACEHOLDER => _x( $this->massage_attributes( $attrs['placeholder'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
PPW_Constants::SHORT_CODE_FORM_AUTH => get_the_ID(),
PPW_Constants::SHORT_CODE_BUTTON => _x( wp_kses_post( $attrs['button'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
PPW_Constants::SHORT_CODE_FORM_CURRENT_URL => $this->get_the_permalink_without_cache( wp_rand( 0, 100 ) ),
PPW_Constants::SHORT_CODE_FORM_ID => esc_attr( '' === $attrs['id'] ? get_the_ID() . wp_rand( 0, 1000 ) : wp_kses_post( $attrs['id'] ) ),
PPW_Constants::SHORT_CODE_FORM_CLASS => esc_attr( $className ),
PPW_Constants::SHORT_CODE_PASSWORD_LABEL => _x( $this->massage_attributes( $attrs['label'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
PPW_Constants::SHORTCODE_ABOVE_PASSWORD_INPUT => apply_filters( 'ppw_pcp_above_password_field', '', $attrs ),
PPW_Constants::SHORTCODE_BELOW_PASSWORD_INPUT => apply_filters( 'ppw_pcp_below_password_field', '', $attrs ),
PPW_Constants::SHORT_CODE_FORM_ERROR_MESSAGE => '',
PPW_Constants::SHORTCODE_DESC_ABOVE_BTN => $desc_above_btn,
PPW_Constants::SHORTCODE_DESC_BELOW_FORM => _x( $this->massage_attributes( $attrs['desc_below_form'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
'[PPW_PAGE]' => $number,
'[PPW_CHECKBOX]' => $checkbox,
'[PPW_BUTTON_LOADING]' => esc_attr_x( $attrs['loading'], PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
'[AREA]' => absint( $attrs['section'] ),
'[PPW_RECAPTCHA_INPUT]' => $this->massage_attributes( $recaptcha_input ),
);
// phpcs:enable
foreach ( $form_params as $key => $value ) {
$form_template = str_replace( $key, $value, $form_template );
}
return $form_template;
}
/**
* Massage attributes before showing the front end.
*
* @param string $val The value.
*
* @return mixed
*/
private function massage_attributes( $val ) {
return wp_kses_post( html_entity_decode( $val ) );
}
/**
* Get post permalink with random value
*
* @param int $rand_value Random value.
*
* @return string
*/
private function get_the_permalink_without_cache( $rand_value ) {
return get_the_permalink() . "?action=postpass&r=$rand_value";
}
/**
* Validate short_code attributes
*
* @param array $attrs Attributes.
*
* @return bool
*/
private function is_valid_attributes( $attrs ) {
$required_attrs = apply_filters(
PPW_Constants::HOOK_SHORTCODE_ATTRIBUTES_VALIDATION,
array(
array(
'key' => 'passwords',
'length' => 100,
'delimiter' => ' ',
),
),
$attrs
);
foreach ( $required_attrs as $attr ) {
$val = trim( $attrs[ $attr['key'] ] );
if ( '' === $val ) {
return false;
}
$items = explode( $attr['delimiter'], $val );
foreach ( $items as $item ) {
if ( $attr['length'] < strlen( $item ) ) {
return false;
}
}
}
if ( ! $this->is_valid_date( $attrs ) ) {
return false;
}
return true;
}
/**
* Invalid shortcode message.
*
* @param string $message Error message.
* @param array $attrs Attributes shortcode.
*
* @return string
*/
private function get_invalid_shortcode_message( $message, $attrs ) {
$color = esc_attr( PPW_Constants::PPW_ERROR_MESSAGE_COLOR );
return sprintf(
'<span class="%s" style="color:%s;display: block">%s</span>',
$this->get_main_class_name( $attrs ),
$color,
$message
);
}
/**
* Is whitelisted roles
*
* @param string $whitelisted_roles Attribute whitelist roles from shortcode.
*
* @return bool
*/
private function is_whitelisted_role( $whitelisted_roles ) {
$roles = explode( ',', trim( $whitelisted_roles ) );
foreach ( $roles as $role ) {
$role = trim( $role );
if ( in_array( $role, $this->supported_roles, true ) && current_user_can( $role ) ) {
return true;
}
}
return false;
}
/**
* Is current post type supported.
*
* @param string $type Current post type.
*
* @return bool
*/
private function is_supported_post_types( $type ) {
$is_bypass = apply_filters( PPW_Constants::HOOK_SHORTCODE_ALLOW_BYPASS_VALID_POST_TYPE, defined( 'PPW_PRO_VERSION' ) );
if ( $is_bypass ) {
return true;
}
return in_array( $type, $this->supported_post_types, true );
}
/**
* Get cookie expiration
*
* @return int
*/
public function get_cookie_expiration() {
$default = apply_filters( PPW_Constants::HOOK_COOKIE_EXPIRED, time() + 7 * DAY_IN_SECONDS );
$setting_expiration = ppw_core_get_setting_type_string( PPW_Constants::COOKIE_EXPIRED );
if ( empty( $setting_expiration ) ) {
return $default;
}
$tmp = explode( ' ', $setting_expiration );
if ( count( $tmp ) < 2 ) {
return $default;
}
$val = $tmp[0];
$unit = ppw_core_get_unit_time( $setting_expiration );
if ( 0 === $unit ) {
return $default;
}
return apply_filters( PPW_Constants::HOOK_COOKIE_EXPIRED, time() + (int) $val * $unit );
}
/**
* Check whether the content is empty.
*
* @param string $content The content.
* @param array $attrs The shortcode attributes.
*
* @return bool
*/
private function is_empty_content( $content, $attrs ) {
$is_empty = '' === $content;
return apply_filters( 'ppwp_shortcode_is_empty_content', $is_empty, $content, $attrs );
}
/**
* Get attributes from shortcode
*
* @param array $parsed_atts Shortcode attributes in array type.
*
* @return array
*/
public function get_attributes( $parsed_atts ) {
// Default values for attributes.
$default_values = array(
'passwords' => array(),
'cookie' => $this->get_cookie_expiration(),
);
// Shortcode_parse_atts return array or empty which we only use array.
if ( ! is_array( $parsed_atts ) ) {
return $default_values;
}
// Get passwords attribute.
if ( isset( $parsed_atts['passwords'] ) ) {
$default_values['passwords'] = $this->get_passwords_attribute( $parsed_atts );
}
// Get cookie attribute.
if ( isset( $parsed_atts['cookie'] ) && intval( $parsed_atts['cookie'] ) > PPW_Constants::MIN_COOKIE_EXPIRED ) {
$default_values['cookie'] = $this->get_expired_time_cookie_attribute( $parsed_atts );
}
return $default_values;
}
/**
* Convert string password to array
* Example:
* Input: 'a b c'
* Output: ['a','b','c']
*
* @param array $parsed_atts Attributes parsed.
*
* @return array
*/
private function get_passwords_attribute( $parsed_atts ) {
return array_map(
function ( $p ) {
return wp_specialchars_decode( $p );
},
explode( ' ', $parsed_atts['passwords'] )
);
}
/**
* Convert day to timestamp of cookie.
*
* @param array $parsed_atts Attributes parsed.
*
* @return int
*/
private function get_expired_time_cookie_attribute( $parsed_atts ) {
$hours = absint( $parsed_atts['cookie'] );
$hours = $hours > PPW_Constants::MAX_COOKIE_EXPIRED ? PPW_Constants::MAX_COOKIE_EXPIRED : $hours;
return time() + $hours * HOUR_IN_SECONDS;
}
/**
* Get main class name.
*
* @param array $attrs Attributes shortcode.
*
* @return string
*/
public function get_main_class_name( $attrs ) {
$post_fix = empty( $attrs['type'] )
? ''
: '-' . $attrs['type'];
return $this->main_class_name . $post_fix;
}
/**
* Get content for post by page number. Case use break page in content.
*
* @param object $post The post content.
* @param int $page The page number.
*
* @return bool|string
*/
public function get_content_by_page_number( $post, $page ) {
if ( function_exists( 'generate_postdata' ) ) {
$postdata = generate_postdata( $post );
$pages = $postdata['pages'];
} else {
$postdata = setup_postdata( $post );
global $pages;
}
if ( false === $postdata ) {
return false;
}
return $pages[ $page - 1 ];
}
/**
* Handle block content on Gutenberg
*
* @param string $content Post content.
*
* @return string Content after rendered.
*/
public function render_block_content( $content ) {
if ( ! function_exists( 'parse_blocks' ) ||
! function_exists( 'has_blocks' ) ||
! function_exists( 'render_block' )
) {
return $content;
}
if ( has_blocks( $content ) ) {
$content_markup = '';
$blocks = parse_blocks( $content );
foreach ( $blocks as $block ) {
$content_markup .= render_block( $block );
}
return $content_markup;
}
return $content;
}
}
}

View File

@@ -0,0 +1,49 @@
<?php
if ( ! class_exists( 'PPW_Password_Subscribe' ) ) {
class PPW_Password_Subscribe {
/**
* Handle subscriber request(Call api to save data for subscriber)
*
* @param string $email email user request.
*
* @return array
*/
public function handle_subscribe_request( $email ) {
$ppw_config = include PPW_DIR_PATH . 'config.php';
$data = array(
'email' => $email,
'plugin' => 'ppwp',
);
$args = array(
'body' => json_encode( $data ),
'timeout' => '100',
'redirection' => '5',
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(
'Content-Type' => 'application/json',
),
);
$response = wp_remote_post(
$ppw_config->subscribe_api,
$args
);
$status_code = absint( wp_remote_retrieve_response_code( $response ) );
if ( is_wp_error( $response ) ) {
return array(
'error_message' => $response->get_error_message(),
);
} else if ( $status_code >= 400 ) {
return array(
'error_message' => __('Invalid email address', 'password-protect-page'),
);
} else {
update_user_meta( get_current_user_id(), PPW_Constants::USER_SUBSCRIBE, true );
return array(
'data' => json_decode( wp_remote_retrieve_body( $response ) ),
);
}
}
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* PPWP Lite: Category Protection
*/
?>
<h2 class="ppw-cat__title"> <?php echo esc_html__('PPWP Lite: Category Protection','password-protect-page');?></h2>
<form method="post" id="ppwp_protect_category_form" class="ppw-cat__form">
<input type="hidden" id="ppw_category_form_nonce" value="<?php echo esc_attr( wp_create_nonce(PPW_Constants::GENERAL_FORM_NONCE) ); ?>" />
<div class="form__option-wrapper">
<span class="form__option-switch-btn">
<label class="pda_switch ppw-switch__wrapper" for="ppwp_is_protect_category">
<input type="checkbox" id="ppwp_is_protect_category" <?php echo $is_protect ? 'checked' : '' ?> />
<span class="pda-slider round ppw-switch--btn"></span>
</label>
</span>
<span class="form__option-label">
<?php echo esc_html__('Password Protect Categories', 'password-protect-page') ?>
</span>
</div>
<p class="form__desc"><?php echo wp_kses_post( sprintf( '<a target="_blank" rel="noreferrer noopener" href="%1$s">%2$s</a> %3$s <a href="%4$s">%5$s</a>.', 'https://passwordprotectwp.com/docs/password-protect-wordpress-categories/?utm_source=user-website&utm_medium=category-protection&utm_campaign=ppwp-free', __( 'Protect all posts under protected categories', 'password-protect-page' ), __( 'with a single password. Customize the password form using', 'password-protect-page' ), admin_url( 'customize.php?autofocus[panel]=ppwp' ), __( 'WordPress Customizer', 'password-protect-page' ) ) ); ?></p>
<p class="form__select-wrapper form__input-wrapper">
<label class="form__label form__label-cats" for="ppwp-cat-select"><?php echo esc_html__('Select your private categories', 'password-protect-page') ?></label>
<select class="form__select" id="ppwp_protected_categories_selected" multiple="multiple">
<?php
foreach ($categories as $category) {
$selected = in_array($category->term_id, $protected_categories) ? 'selected' : '';
echo '<option ' . esc_attr( $selected ) . ' value="' . esc_attr( $category->term_id ) . '">' . esc_html( $category->name ) . '</option>';
}
?>
</select>
<div id="ppwp_error_protected_categories_selected" style="display: none; color: red; position: absolute; font-size: 12px;">This field is required.</div>
</p>
<p class="form__input-wrapper">
<label class="form__label form__label__pass" for="ppwp_categories_password"><?php echo esc_html__('Set a password', 'password-protect-page') ?></label>
<input class="form__input" id="ppwp_categories_password" type="text" placeholder="Enter a password" value="<?php echo esc_html( $password ) ?>">
<div id="ppwp_error_categories_password" style="display: none; color: red; position: absolute; font-size: 12px;">This field is required.</div>
</p>
<p class="form__btn-wrapper">
<input type="submit" name="submit" id="ppwp-submit" class="button button-primary" value="Save Changes">
</p>
</form>

View File

@@ -0,0 +1,18 @@
<?php
/**
* Password Protected Service
*/
$service = new PPW_Password_Services();
$is_protected = $service->is_protected_content( $post_id );
$icon_class = $is_protected ? 'dashicons-lock' : 'dashicons-unlock';
$color_class = $is_protected ? 'ppw_protected_color' : 'ppw_unprotected_color';
$status = $is_protected ? 'protected' : 'unprotected';
$post = get_post( $post_id );
?>
<div class="ppw-column">
<span id="ppw-badge-protection_<?php echo esc_attr( $post_id ); ?>"
class="ppw-badge-protection <?php echo esc_attr( $color_class ); ?>">
<i class="dashicons <?php echo esc_attr( $icon_class ); ?>"></i> <?php echo esc_html( $status, 'password-protect-page' ); ?>
</span>
</div>

View File

@@ -0,0 +1,2 @@
.ppw-cat__form{padding-bottom:0rem;margin-bottom:2rem;border-bottom:1px solid #bbb}.ppw-cat__form .ppw-switch__wrapper{margin:0 7px 0 0}.form__option-wrapper{display:flex;align-items:center}.form__option-wrapper .form__option-label{font-size:15px}.form__input-wrapper label{display:block;padding:2px 0}.form__input-wrapper input{width:95%}.form__input-wrapper{margin-bottom:2px !important}.form__btn-wrapper{margin-top:30px}.form__label__pass{margin-top:22px}

View File

@@ -0,0 +1 @@
!function(e){var t={};function r(p){if(t[p])return t[p].exports;var o=t[p]={i:p,l:!1,exports:{}};return e[p].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,p){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:p})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var p=Object.create(null);if(r.r(p),Object.defineProperty(p,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(p,o,function(t){return e[t]}.bind(null,o));return p},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=8)}({8:function(e,t,r){"use strict";r.r(t);r(9);!function(e){e(function(){e("#ppwp_protected_categories_selected").select2({width:"95%"}),e("#ppwp_is_protect_category").change(function(){e(this).prop("checked")?(e(".form__input-wrapper").show(),e("#ppwp_categories_password").trigger("change")):(e(".form__input-wrapper").hide(),e("#ppwp_error_categories_password").hide(),e("#ppwp_error_protected_categories_selected").hide())}),e("#ppwp_is_protect_category").trigger("change"),e("#ppwp_protect_category_form").submit(function(t){t.preventDefault();var r=e("#ppwp_categories_password").val(),p=e("#ppwp_protected_categories_selected").val(),o=e("#ppwp_is_protect_category").prop("checked");o&&""===r?e(this).find("#ppwp_error_categories_password").show():e(this).find("#ppwp_error_categories_password").hide(),o&&0===p.length?e(this).find("#ppwp_error_protected_categories_selected").show():e(this).find("#ppwp_error_protected_categories_selected").hide();var c={ppwp_is_protect_category:e("#ppwp_is_protect_category").prop("checked"),ppwp_categories_password:e("#ppwp_categories_password").val(),ppwp_protected_categories_selected:e("#ppwp_protected_categories_selected").val()};c.ppwp_categories_password=c.ppwp_categories_password.trim(),(!o||""!==r&&0!==p.length)&&(e("#ppwp-submit").prop("disabled",!0),function(t,r){!function(t,r){e.ajax({url:ppw_category_data.ajax_url,type:"POST",data:t,timeout:5e3,success:function(e){r(e,null)},error:function(e){r(null,e)}})}({action:"ppw_free_update_category_settings",settings:t,security_check:e("#ppw_category_form_nonce").val()},r)}(c,function(t,r){t&&(toastr.success("Great! Your settings have been updated successfully.","PPWP Lite"),setTimeout(function(){window.location.reload()},700)),r&&(400===r.status?toastr.error(r.responseJSON.message,"PPWP Lite"):toastr.error("Oops! Something went wrong. Please try again.","PPWP Lite")),e("#ppwp-submit").prop("disabled",!1)}))})})}(jQuery)},9:function(e,t,r){}});

View File

@@ -0,0 +1 @@
!function(e){var r={};function t(s){if(r[s])return r[s].exports;var p=r[s]={i:s,l:!1,exports:{}};return e[s].call(p.exports,p,p.exports,t),p.l=!0,p.exports}t.m=e,t.c=r,t.d=function(e,r,s){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:s})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(t.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var p in e)t.d(s,p,function(r){return e[r]}.bind(null,p));return s},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=2)}([function(e,r,t){"use strict";r.a=function(e){e("#ppw_subscribe_form").submit(function(r){r.preventDefault();const t=e("#ppw_email_subscribe").val().trim();/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t)?(e("#ppw_subscribe_button").val("Saving..."),function(e,r,t){var s={action:"ppw_free_subscribe_request",settings:r,security_check:e("#ppw_subscribe_form_nonce").val()};!function(e,r,t){let s=!1;window.ppw_general_data?s=ppw_general_data.ajax_url:window.ppw_entire_site_data&&(s=ppw_entire_site_data.ajax_url),s&&e.ajax({url:s,type:"POST",data:r,timeout:5e3,success:function(e){t(e,null)},error:function(e){t(null,e)}})}(e,s,t)}(e,{ppw_email:t},function(r,t){r?(e("#ppw_subscribe_form").hide(),e("#ppw_subscribe_form_success").show()):t&&(400===t.status?(e(".ppw_subscribe_error").text(t.responseJSON.message),e(".ppw_subscribe_error").show("slow")):(e(".ppw_subscribe_error").text("Oops! Something went wrong. Please reload the page and try again."),e(".ppw_subscribe_error").show("slow"))),e("#ppw_subscribe_button").val("Get Lucky")})):(e(".ppw_subscribe_error").show("slow"),e("#ppw_email_subscribe").focus(),e("#ppw_subscribe_button").val("Get Lucky"))})}},,function(e,r,t){"use strict";t.r(r);var s=t(0);!function(e){e(function(){e(".ppwp_select2").select2({width:"100%"}),e("#ppwp_free_switch_exclude_page").change(function(){e(this).prop("checked")?e(".ppwp_free_wrap_select_exclude_page").show():e(".ppwp_free_wrap_select_exclude_page").hide()}),e("#ppwp_free_switch_exclude_page").trigger("change"),e("#ppwp_apply_password_for_entire_site").change(function(){e(this).prop("checked")?(e(".ppwp_logic_show_input_password").show(),e("#ppwp_password_for_entire_site").attr("required",!0),e("#ppwp_password_for_entire_site").trigger("change")):(e(".ppwp_logic_show_input_password").hide(),e("#submit").prop("disabled",!1),e("#ppwp_password_for_entire_site").attr("required",!1))}),e("#ppwp_apply_password_for_entire_site").trigger("change"),e("#ppwp_set_new_password_for_entire_site").change(function(){e(this).prop("checked")?(e("#ppwp_new_password_entire_site").show(),e("#ppwp_password_for_entire_site").attr("required",!0)):(e("#ppwp_new_password_entire_site").hide(),e("#ppwp_password_for_entire_site").val(""),e("#submit").prop("disabled",!1),e("#ppwp_password_for_entire_site").attr("required",!1))}),e("#ppwp_set_new_password_for_entire_site").trigger("change"),e("#ppwp_password_for_entire_site").change(function(){-1!==e(this).val().indexOf(" ")?(toastr.error("Please remove spaces in password!","Password Protect WordPress"),e("#submit").prop("disabled",!0)):e("#submit").prop("disabled",!1)}),e("#ppwp_password_for_entire_site").trigger("change"),Object(s.a)(e),e("#ppw_entire_site_form").submit(function(r){r.preventDefault(),function(r,t){!function(r,t){e("#submit").prop("disabled",!0),e.ajax({url:ppw_entire_site_data.ajax_url,type:"POST",data:r,success:function(e){t(e,null)},error:function(e){t(null,e)},timeout:5e3})}({action:"ppw_free_update_entire_site_settings",settings:r,security_check:e("#ppw_entire_site_form_nonce").val()},t)}({ppwp_apply_password_for_entire_site:e("#ppwp_apply_password_for_entire_site").prop("checked"),password_for_website:e("#ppwp_password_for_entire_site").val(),ppwp_set_new_password_for_entire_site:e("#ppwp_set_new_password_for_entire_site").prop("checked")},function(r,t){r&&(toastr.success("Great! Your settings have been updated successfully.","PPWP Lite"),location.reload(!0)),t&&(400===t.status?toastr.error(t.responseJSON.message,"PPWP Lite"):toastr.error("Oops! Something went wrong. Please try again.","PPWP Lite"),console.log("Data error",t),e("#submit").prop("disabled",!1))})})})}(jQuery)}]);

View File

@@ -0,0 +1 @@
!function(e){var r={};function t(p){if(r[p])return r[p].exports;var a=r[p]={i:p,l:!1,exports:{}};return e[p].call(a.exports,a,a.exports,t),a.l=!0,a.exports}t.m=e,t.c=r,t.d=function(e,r,p){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:p})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var p=Object.create(null);if(t.r(p),Object.defineProperty(p,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var a in e)t.d(p,a,function(r){return e[r]}.bind(null,a));return p},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=6)}({0:function(e,r,t){"use strict";r.a=function(e){e("#ppw_subscribe_form").submit(function(r){r.preventDefault();const t=e("#ppw_email_subscribe").val().trim();/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t)?(e("#ppw_subscribe_button").val("Saving..."),function(e,r,t){var p={action:"ppw_free_subscribe_request",settings:r,security_check:e("#ppw_subscribe_form_nonce").val()};!function(e,r,t){let p=!1;window.ppw_general_data?p=ppw_general_data.ajax_url:window.ppw_entire_site_data&&(p=ppw_entire_site_data.ajax_url),p&&e.ajax({url:p,type:"POST",data:r,timeout:5e3,success:function(e){t(e,null)},error:function(e){t(null,e)}})}(e,p,t)}(e,{ppw_email:t},function(r,t){r?(e("#ppw_subscribe_form").hide(),e("#ppw_subscribe_form_success").show()):t&&(400===t.status?(e(".ppw_subscribe_error").text(t.responseJSON.message),e(".ppw_subscribe_error").show("slow")):(e(".ppw_subscribe_error").text("Oops! Something went wrong. Please reload the page and try again."),e(".ppw_subscribe_error").show("slow"))),e("#ppw_subscribe_button").val("Get Lucky")})):(e(".ppw_subscribe_error").show("slow"),e("#ppw_email_subscribe").focus(),e("#ppw_subscribe_button").val("Get Lucky"))})}},6:function(e,r,t){"use strict";t.r(r);var p=t(0);!function(e){function r(r,t){!function(r,t){e.ajax({url:ppw_external_data.ajax_url,type:"POST",data:r,timeout:5e3,success:function(e){t(e,null)},error:function(e){t(null,e)}})}({action:"ppw_free_update_external_settings",settings:r,security_check:e("#ppw_general_form_nonce").val()},t)}e(function(){Object(p.a)(e),e("#wpp_external_v2_form").submit(function(t){t.preventDefault();var p=e("#wpp_recaptcha_v2_checkbox_api_key").val().trim(),a=e("#wpp_recaptcha_v2_checkbox_api_secret").val().trim();if(a?e(this).find("#ppwp-error-require-v2-secret").hide():(e(this).find("#ppwp-error-require-v2-secret").show(),e(this).find("#wpp_recaptcha_v2_checkbox_api_secret").focus()),p?e(this).find("#ppwp-error-require-v2-key").hide():(e(this).find("#ppwp-error-require-v2-key").show(),e(this).find("#wpp_recaptcha_v2_checkbox_api_key").focus()),""!==p&&""!==a){r({wpp_recaptcha_v2_checkbox_api_key:e("#wpp_recaptcha_v2_checkbox_api_key").val(),wpp_recaptcha_v2_checkbox_api_secret:e("#wpp_recaptcha_v2_checkbox_api_secret").val()},function(r,t){r&&(toastr.success("Great! Your settings have been updated successfully.","PPWP Lite"),location.reload(!0)),t&&(400===t.status?toastr.error(t.responseJSON.message,"PPWP Lite"):toastr.error("Oops! Something went wrong. Please try again!","PPWP Lite"),e("#v2_submit_btn").prop("disabled",!1))})}})}),e(function(){Object(p.a)(e),e("#wpp_external_v3_form").submit(function(t){t.preventDefault();var p=e("#wpp_recaptcha_api_key").val().trim(),a=e("#wpp_recaptcha_api_secret").val().trim();if(a?e(this).find("#ppwp-error-require-v3-secret").hide():(!1,e(this).find("#ppwp-error-require-v3-secret").show(),e(this).find("#wpp_recaptcha_api_secret").focus()),p?e(this).find("#ppwp-error-require-v3-key").hide():(!1,e(this).find("#ppwp-error-require-v3-key").show(),e(this).find("#wpp_recaptcha_api_key").focus()),""!==p&&""!==a){r({wpp_recaptcha_api_key:e("#wpp_recaptcha_api_key").val(),wpp_recaptcha_api_secret:e("#wpp_recaptcha_api_secret").val(),wpp_recaptcha_score:e("#wpp_recaptcha_score").val()},function(r,t){r&&(toastr.success("Great! Your settings have been updated successfully.","PPWP Lite"),location.reload(!0)),t&&(400===t.status?toastr.error(t.responseJSON.message,"PPWP Lite"):toastr.error("Oops! Something went wrong. Please try again!","PPWP Lite"),e("#v3_submit_btn").prop("disabled",!1))})}})})}(jQuery)}});

View File

@@ -0,0 +1 @@
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,r),s.l=!0,s.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(n,s,function(t){return e[t]}.bind(null,s));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=5)}({0:function(e,t,r){"use strict";t.a=function(e){e("#ppw_subscribe_form").submit(function(t){t.preventDefault();const r=e("#ppw_email_subscribe").val().trim();/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(r)?(e("#ppw_subscribe_button").val("Saving..."),function(e,t,r){var n={action:"ppw_free_subscribe_request",settings:t,security_check:e("#ppw_subscribe_form_nonce").val()};!function(e,t,r){let n=!1;window.ppw_general_data?n=ppw_general_data.ajax_url:window.ppw_entire_site_data&&(n=ppw_entire_site_data.ajax_url),n&&e.ajax({url:n,type:"POST",data:t,timeout:5e3,success:function(e){r(e,null)},error:function(e){r(null,e)}})}(e,n,r)}(e,{ppw_email:r},function(t,r){t?(e("#ppw_subscribe_form").hide(),e("#ppw_subscribe_form_success").show()):r&&(400===r.status?(e(".ppw_subscribe_error").text(r.responseJSON.message),e(".ppw_subscribe_error").show("slow")):(e(".ppw_subscribe_error").text("Oops! Something went wrong. Please reload the page and try again."),e(".ppw_subscribe_error").show("slow"))),e("#ppw_subscribe_button").val("Get Lucky")})):(e(".ppw_subscribe_error").show("slow"),e("#ppw_email_subscribe").focus(),e("#ppw_subscribe_button").val("Get Lucky"))})}},5:function(e,t,r){"use strict";r.r(t);var n=r(0);!function(e){e(function(){e(".ppw_select_types").select2({width:"100%"}),e("#wpp_use_recaptcha").change(function(){e(this).prop("checked")?(e("#wpp_recaptcha_options").show(),e("#wpp_recaptcha_password_types").attr("required",!0)):(e("#wpp_recaptcha_options").hide(),e("#wpp_recaptcha_password_types").attr("required",!1))}),Object(n.a)(e),e("#wpp_external_form").submit(function(t){t.preventDefault(),function(t,r){var n={action:"ppw_free_update_external_settings",settings:t,security_check:e("#ppw_general_form_nonce").val()};e("#submit").prop("disabled",!0),function(t,r){e.ajax({url:ppw_external_data.ajax_url,type:"POST",data:t,timeout:5e3,success:function(e){r(e,null)},error:function(e){r(null,e)}})}(n,r)}(function(){var t=e("#wpp_use_recaptcha").prop("checked"),r={wpp_use_recaptcha:t};t&&(r.wpp_recaptcha_type=e("#wpp_recaptcha_type").val(),r.wpp_recaptcha_password_types=e("#wpp_recaptcha_password_types").val());return r}(),function(t,r){if(t)return toastr.success("Great! Your settings have been updated successfully.","PPWP Lite"),void location.reload(!0);r&&(400===r.status?toastr.error(r.responseJSON.message,"PPWP Lite"):toastr.error("Oops! Something went wrong. Please try again.","PPWP Lite"),e("#submit").prop("disabled",!1))})})})}(jQuery)}});

View File

@@ -0,0 +1,2 @@
body{background:#f1f1f1;min-width:0;font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif}.pda-form-login h1{margin:0}.pda-form-login{width:320px;padding:8% 0 0;margin:auto}.pda-form-login a.ppw-swp-logo{width:85px;height:85px;margin:0 auto 25px;text-indent:-9999px;display:block}.pda-form-login form{padding:26px 24px;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,0.13);box-sizing:border-box}.pda-form-login .button-login{padding:0.5rem;background:#0085ba;border-color:#0085ba;color:#fff;font-size:13px;cursor:pointer;border-style:solid;border-radius:3px;font-family:inherit;padding:0.5rem}.pda-form-login .input_wp_protect_password{background:#fbfbfb;width:100%;padding:9px;margin:10px 0;border:1px solid #ddd;background-color:#fff}.ppw-entire-site-password-error{color:#dc3232;font-size:13px;margin-bottom:1rem}

View File

@@ -0,0 +1 @@
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=12)}({12:function(e,t,r){"use strict";r.r(t);r(13)},13:function(e,t,r){}});

View File

@@ -0,0 +1,2 @@
.ppw_main_container input[type=text],.ppw_main_container input[type=password]{height:35px}.ppw_main_container #pppw-copy-shortcode{height:34px}.ppw_main_container select{min-height:30px;margin-bottom:5px}.ppw_main_container .recaptcha-btn{margin-top:15px}.ppw_main_container .ppwp-title{margin-top:20px}.ppw_main_container .ppwp-recaptcha-input input{margin-bottom:2px}.ppw_main_container .ppw-recaptcha-score .ppw_main_container{margin-top:5px;min-height:35px !important;margin-bottom:7px !important}.ppw_main_container #wpp_external_v3_form .ppwp_settings_table{margin-bottom:15px}.ppw_main_container #recaptcha-score-container{margin-bottom:5px}.ppw_main_container .v3_submit_btn{margin-top:5px}

View File

@@ -0,0 +1 @@
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=14)}({14:function(e,t,r){"use strict";r.r(t);r(15)},15:function(e,t,r){}});

View File

@@ -0,0 +1 @@
!function(e){var t={};function r(s){if(t[s])return t[s].exports;var p=t[s]={i:s,l:!1,exports:{}};return e[s].call(p.exports,p,p.exports,r),p.l=!0,p.exports}r.m=e,r.c=t,r.d=function(e,t,s){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(r.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var p in e)r.d(s,p,function(t){return e[t]}.bind(null,p));return s},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=3)}([function(e,t,r){"use strict";t.a=function(e){e("#ppw_subscribe_form").submit(function(t){t.preventDefault();const r=e("#ppw_email_subscribe").val().trim();/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(r)?(e("#ppw_subscribe_button").val("Saving..."),function(e,t,r){var s={action:"ppw_free_subscribe_request",settings:t,security_check:e("#ppw_subscribe_form_nonce").val()};!function(e,t,r){let s=!1;window.ppw_general_data?s=ppw_general_data.ajax_url:window.ppw_entire_site_data&&(s=ppw_entire_site_data.ajax_url),s&&e.ajax({url:s,type:"POST",data:t,timeout:5e3,success:function(e){r(e,null)},error:function(e){r(null,e)}})}(e,s,r)}(e,{ppw_email:r},function(t,r){t?(e("#ppw_subscribe_form").hide(),e("#ppw_subscribe_form_success").show()):r&&(400===r.status?(e(".ppw_subscribe_error").text(r.responseJSON.message),e(".ppw_subscribe_error").show("slow")):(e(".ppw_subscribe_error").text("Oops! Something went wrong. Please reload the page and try again."),e(".ppw_subscribe_error").show("slow"))),e("#ppw_subscribe_button").val("Get Lucky")})):(e(".ppw_subscribe_error").show("slow"),e("#ppw_email_subscribe").focus(),e("#ppw_subscribe_button").val("Get Lucky"))})}},,,function(e,t,r){"use strict";r.r(t);var s=r(0);!function(e){e(function(){e(".ppwp_select2").select2({width:"100%"}),e("#wpp_free_whitelist_roles").change(function(){"custom_roles"===e(this).val()?e("#wpp_free_roles_access").show():e("#wpp_free_roles_access").hide()}),e("#wpp_free_whitelist_roles").trigger("change"),e("#ppwp_free_apply_password_for_pages_posts").change(function(){e(this).prop("checked")?e(".ppwp-free-pages-posts-set-password").show():e(".ppwp-free-pages-posts-set-password").hide()}),e("#ppwp_free_apply_password_for_pages_posts").trigger("change"),e("#wpp_password_cookie_units").change(function(){!function(t){switch(t){case"days":e("#wpp_password_cookie_times").attr({max:365});break;case"hours":e("#wpp_password_cookie_times").attr({max:8760});break;case"minutes":e("#wpp_password_cookie_times").attr({max:525600});break;case"seconds":e("#wpp_password_cookie_times").attr({max:31536e3})}}(e(this).val())}),e("#ppw_select_custom_post_type_edit").change(function(){e(".ppw_hide_protect_content").hide();const t=e(this).val();if("page_post"===t){const t=["post","page"];t.forEach(function(t){!function(t){e(".ppw_wrap_"+t).show(),e("#ppw_hide_protected_"+t).change(function(){this.checked?function(t,r){e(t).show(),e(r).prop("required",!0)}("#ppw_wrap_hide_selected_"+t,"#ppw_hide_selected_"+t):function(t,r){e(t).hide(),e(r).prop("required",!1)}("#ppw_wrap_hide_selected_"+t,"#ppw_hide_selected_"+t)})}(t)})}}),e("#ppw_select_custom_post_type_edit").trigger("change"),Object(s.a)(e),e("#wp_protect_password_general_form").submit(function(t){t.preventDefault(),function(t,r){var s={action:"ppw_free_update_general_settings",settings:t,security_check:e("#ppw_general_form_nonce").val()};e("#submit").prop("disabled",!0),function(t,r){e.ajax({url:ppw_general_data.ajax_url,type:"POST",data:t,timeout:5e3,success:function(e){r(e,null)},error:function(e){r(null,e)}})}(s,r)}(function(){let t={wpp_password_cookie_expired:e("#wpp_password_cookie_times").val()+" "+e("#wpp_password_cookie_units").val(),wpp_remove_data:e("#wpp_remove_data").prop("checked")};return["post","page"].map(function(t){return{["ppw_hide_protected_"+t]:e("#ppw_hide_protected_"+t).prop("checked"),["ppw_hide_selected_"+t]:e("#ppw_hide_selected_"+t).val()}}).forEach(function(e){Object.keys(e).forEach(function(r){t[r]=e[r]})}),t}(),function(t,r){t&&(toastr.success("Great! Your settings have been updated successfully.","PPWP Lite"),location.reload(!0)),r&&(400===r.status?toastr.error(r.responseJSON.message,"PPWP Lite"):toastr.error("Oops! Something went wrong. Please try again.","PPWP Lite"),console.log("Data error",r),e("#submit").prop("disabled",!1))})})})}(jQuery)}]);

View File

@@ -0,0 +1,2 @@
.pda-pwd-tools{margin-bottom:0.5rem}.pda-pwd-tools input[type=radio].disabled,.pda-pwd-tools input[type=radio].disabled:checked:before,.pda-pwd-tools input[type=radio]:disabled,.pda-pwd-tools input[type=radio]:disabled:checked:before,.pda-pwd-tools input[type=checkbox].disabled,.pda-pwd-tools input[type=checkbox].disabled:checked:before,.pda-pwd-tools input[type=checkbox]:disabled,.pda-pwd-tools input[type=checkbox]:disabled:checked:before{opacity:1;cursor:inherit}.pda-pwd-tbl-actions{cursor:pointer}textarea[name="wpp_multiple_password"]{width:94%}#all_roles_select{margin-top:0;margin-bottom:5px}#all_roles_select span{border-radius:6px 0;padding:0rem 0.2rem;background:#FFFF00;cursor:pointer;transition:0.4s;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;max-width:100%;display:inline-block}div#passwords-roles-map label{display:block}.pda-selected-role-select2,input.post-protection-password,textarea[name="wpp_multiple_password"]{width:100%}.ppwp_set_password_type{width:70%}#ppwp_set_password_metabox .ppwp_apply_password{display:block;margin-bottom:5px}#ppwp_set_password_metabox .ppwp_show_hide_password_roles{margin-top:5px}#ppwp_set_password_metabox .ppwp_input_set_type_password{margin-top:5px}#ppwp_set_password_metabox .ppwp_default_hide_checkbox_roles{display:none}.ppwp-button-hide{float:right;padding:0;cursor:pointer;text-decoration:underline}.ppwp-button-submit{color:#555;border-color:#ccc;background:#f7f7f7;box-shadow:0 1px 0 #ccc;vertical-align:top;display:inline-block;text-decoration:none;font-size:13px;line-height:26px;height:28px;margin:0;padding:0 10px 1px;cursor:pointer;border-width:1px;border-style:solid;-webkit-appearance:none;border-radius:3px;white-space:nowrap;box-sizing:border-box}.ppwp-button-submit:hover{background:#fafafa;border-color:#999;color:#23282d}#passwords-roles-map .ppwp-wrap-submit-hide{margin-top:13px}.ppwp_multiple_password{width:100%}.ppwp_wrap_role_password{margin-top:5px}.pda-selected-role-select2{box-sizing:border-box}.ppwp-button-submit[disabled]{color:#a0a5aa;border-color:#ddd;background:#f7f7f7;box-shadow:none;text-shadow:0 1px 0 #fff;cursor:default}

View File

@@ -0,0 +1 @@
!function(e){var s={};function t(o){if(s[o])return s[o].exports;var r=s[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}t.m=e,t.c=s,t.d=function(e,s,o){t.o(e,s)||Object.defineProperty(e,s,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,s){if(1&s&&(e=t(e)),8&s)return e;if(4&s&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&s&&"string"!=typeof e)for(var r in e)t.d(o,r,function(s){return e[s]}.bind(null,r));return o},t.n=function(e){var s=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(s,"a",s),s},t.o=function(e,s){return Object.prototype.hasOwnProperty.call(e,s)},t.p="",t(t.s=10)}({10:function(e,s,t){"use strict";t.r(s);t(11);!function(e,s){function t(e){return-1===e.indexOf(" ")}function o(e){s(e).focus(function(){s("#save_password").prop("disabled",!1)})}s(function(){!function(){const e=s(".pda-selected-role-select2").val();if(e){const t=""===s("#post-protection-password-"+e).text()?"":s("#post-protection-password-"+e).text();s("#post-protection-password").val(t)}}(),function(){s("#post-protection-password").change(function(){-1!==s(this).val().indexOf(" ")?(toastr.error(save_password_data.error_message.space_password,"Password Protect WordPress"),s("#save_password").prop("disabled",!0)):s("#save_password").prop("disabled",!1)}),o("#post-protection-password"),s(".ppwp_multiple_password").change(function(){const e=s(this).val().split("\n").filter(e=>e.replace(/\s/g,"").length);return new Set(e).size!==e.length?(toastr.error(save_password_data.error_message.duplicate_password,"Password Protect WordPress"),void s("#save_password").prop("disabled",!0)):(s("#save_password").prop("disabled",!1),e.every(t)?void s("#save_password").prop("disabled",!1):(toastr.error(save_password_data.error_message.space_password,"Password Protect WordPress"),void s("#save_password").prop("disabled",!0)))}),o(".ppwp_multiple_password");let e={};s(".pda-selected-role-select2").on("focus",function(){let t=this.value;e[t]=s("#post-protection-password").val(),s("#"+t).val(s("#post-protection-password").val())}).change(function(){let t,o=s(".pda-selected-role-select2").val();t=void 0!==e[o]?e[o]:""===s("#post-protection-password-"+o).text()?"":s("#post-protection-password-"+o).text(),"global"===o?(s("#post-protection-password").hide(),s("#ppwp_multiple_password").show()):(s("#post-protection-password").show(),s("#ppwp_multiple_password").hide()),s("#post-protection-password").val(t),"global"===s("#is_role_selected").val()?s("#label-password-post").text("Passwords"):s("#label-password-post").text("Password")}),s(".pda-selected-role-select2").trigger("change"),s(".edit-post-protection").click(function(){s("#post-protection").show(),s(this).hide()}),s(".button-cancel").click(function(){s("#post-protection").hide(),s(".edit-post-protection").show()})}(),s("#save_password").click(function(e){e.preventDefault();const o=s(".ppwp_multiple_password").val().split("\n").filter(e=>e.replace(/\s/g,"").length),r=s(".post-protection-password").val(),a=s("#is_role_selected").val();(function(e){if("global"!==s(".pda-selected-role-select2").val())return!1;if(!e.every(t))return toastr.error(save_password_data.error_message.space_password,"Password Protect WordPress"),s("#save_password").prop("disabled",!0),!0;if(new Set(e).size!==e.length)return toastr.error(save_password_data.error_message.duplicate_password,"Password Protect WordPress"),s("#save_password").prop("disabled",!0),!0})(o)||function(e,t){const o={action:"ppw_free_set_password",settings:e,security_check:s("#ppw_meta_box_nonce").val()};s("#save_password").text("Submitting"),s("#save_password").prop("disabled",!0),s.ajax({url:save_password_data.ajax_url,type:"POST",data:o,success:function(e){t(e,null)},error:function(e){t(null,e)},timeout:5e3})}({save_password:r,is_role_selected:a,id_page_post:s("#id_page_post").val(),ppwp_multiple_password:o.length<=0?"":o},function(e,t){s("#save_password").text("Submit"),s("#save_password").prop("disabled",!1);e&&(!function(e){const t=Object.keys(e).filter(function(s){return""!==e[s]}),o=t.map(function(e){return"<span>"+e+"</span>"}).join(" "),r=t.length>1?t.length+" roles":t.length+" role";s("#all_roles_select").html(o),s("#number_roles").text(r)}(e),"global"===a?s("#ppwp_multiple_password").val(o.join("\n")):s("#post-protection-password").val(r),toastr.success("Great! Youve updated the password successfully.","PPWP Lite")),t&&(400===t.status?toastr.error(t.responseJSON.message,"PPWP Lite"):toastr.error("Opps! Something went wrong. Please try again.","PPWP Lite"),console.log("Data error",t))})})})}(window,jQuery)},11:function(e,s,t){}});

View File

@@ -0,0 +1 @@
!function(e){var t={};function r(o){if(t[o])return t[o].exports;var s=t[o]={i:o,l:!1,exports:{}};return e[o].call(s.exports,s,s.exports,r),s.l=!0,s.exports}r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(o,s,function(t){return e[t]}.bind(null,s));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}([function(e,t,r){"use strict";t.a=function(e){e("#ppw_subscribe_form").submit(function(t){t.preventDefault();const r=e("#ppw_email_subscribe").val().trim();/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(r)?(e("#ppw_subscribe_button").val("Saving..."),function(e,t,r){var o={action:"ppw_free_subscribe_request",settings:t,security_check:e("#ppw_subscribe_form_nonce").val()};!function(e,t,r){let o=!1;window.ppw_general_data?o=ppw_general_data.ajax_url:window.ppw_entire_site_data&&(o=ppw_entire_site_data.ajax_url),o&&e.ajax({url:o,type:"POST",data:t,timeout:5e3,success:function(e){r(e,null)},error:function(e){r(null,e)}})}(e,o,r)}(e,{ppw_email:r},function(t,r){t?(e("#ppw_subscribe_form").hide(),e("#ppw_subscribe_form_success").show()):r&&(400===r.status?(e(".ppw_subscribe_error").text(r.responseJSON.message),e(".ppw_subscribe_error").show("slow")):(e(".ppw_subscribe_error").text("Oops! Something went wrong. Please reload the page and try again."),e(".ppw_subscribe_error").show("slow"))),e("#ppw_subscribe_button").val("Get Lucky")})):(e(".ppw_subscribe_error").show("slow"),e("#ppw_email_subscribe").focus(),e("#ppw_subscribe_button").val("Get Lucky"))})}},,,,function(e,t,r){"use strict";r.r(t);var o=r(0);!function(e){var t="PPWP Lite";e(function(){e(".ppwp_select2").select2({width:"100%"}),Object(o.a)(e),e("#wpp_misc_common_form").submit(function(r){r.preventDefault(),function(t,r){var o={action:"ppw_free_update_misc_settings",settings:t,security_check:e("#ppw_misc_form_nonce").val()};e("#submit").prop("disabled",!0),function(t,r){e.ajax({url:ppw_misc_data.ajax_url,type:"POST",data:t,timeout:5e3,success:function(e){r(e,null)},error:function(e){r(null,e)}})}(o,r)}(function(){let t={wpp_protect_excerpt:e("#wpp_protect_excerpt").prop("checked"),wpp_use_custom_form_action:!0,wpp_no_reload_page:e("#wpp_no_reload_page").prop("checked")};window.ppwMapAdvancedData&&"function"==typeof window.ppwMapAdvancedData&&(t=window.ppwMapAdvancedData(t));return t}(),function(r,o){r&&(toastr.success("Great! Your settings have been updated successfully.",t),location.reload(!0)),o&&(400===o.status?toastr.error(o.responseJSON.message,t):toastr.error("Oops! Something went wrong. Please try again.",t),console.log("Data error",o),e("#submit").prop("disabled",!1))})}),e("#ppw-restore-passwords").click(function(r){r.preventDefault(),function(r){r.prop("disabled",!0);var o={action:"ppw_free_restore_wp_passwords",security_check:e("#ppw_misc_form_nonce").val()};e.ajax({url:ppw_misc_data.ajax_url,type:"POST",data:o,timeout:5e3,success:function(e){console.log(e),toastr.success(e.message,t),r.prop("disabled",!1),location.reload()},error:function(e){400===e.status?toastr.error(e.responseJSON.message,t):toastr.error("Failed to start restoring the backup passwords.",t),r.prop("disabled",!1)}})}(e(this))})})}(jQuery)}]);

View File

@@ -0,0 +1 @@
!function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=7)}({0:function(e,t,r){"use strict";t.a=function(e){e("#ppw_subscribe_form").submit(function(t){t.preventDefault();const r=e("#ppw_email_subscribe").val().trim();/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(r)?(e("#ppw_subscribe_button").val("Saving..."),function(e,t,r){var o={action:"ppw_free_subscribe_request",settings:t,security_check:e("#ppw_subscribe_form_nonce").val()};!function(e,t,r){let o=!1;window.ppw_general_data?o=ppw_general_data.ajax_url:window.ppw_entire_site_data&&(o=ppw_entire_site_data.ajax_url),o&&e.ajax({url:o,type:"POST",data:t,timeout:5e3,success:function(e){r(e,null)},error:function(e){r(null,e)}})}(e,o,r)}(e,{ppw_email:r},function(t,r){t?(e("#ppw_subscribe_form").hide(),e("#ppw_subscribe_form_success").show()):r&&(400===r.status?(e(".ppw_subscribe_error").text(r.responseJSON.message),e(".ppw_subscribe_error").show("slow")):(e(".ppw_subscribe_error").text("Oops! Something went wrong. Please reload the page and try again."),e(".ppw_subscribe_error").show("slow"))),e("#ppw_subscribe_button").val("Get Lucky")})):(e(".ppw_subscribe_error").show("slow"),e("#ppw_email_subscribe").focus(),e("#ppw_subscribe_button").val("Get Lucky"))})}},7:function(e,t,r){"use strict";r.r(t);var o=r(0);!function(e){e(function(){e(".ppwp_select2").select2({width:"100%"}),Object(o.a)(e),e("#wpp_shortcode_form").submit(function(t){t.preventDefault(),function(t,r){var o={action:"ppw_free_update_shortcode_settings",settings:t,security_check:ppw_shortcode_data.nonce};e("#submit").prop("disabled",!0),function(t,r){e.ajax({url:ppw_shortcode_data.ajax_url,type:"POST",data:t,timeout:5e3,success:function(e){r(e,null)},error:function(e){r(null,e)}})}(o,r)}({wpp_use_shortcode_page_builder:e("#wpp_use_shortcode_page_builder").prop("checked")},function(t,r){t&&(toastr.success("Great! Your settings have been updated successfully.","PPWP Lite"),location.reload(!0)),r&&(400===r.status?toastr.error(r.responseJSON.message,"PPWP Lite"):toastr.error("Oops! Something went wrong. Please try again.","PPWP Lite"),console.log("Data error",r),e("#submit").prop("disabled",!1))})})})}(jQuery)}});

View File

@@ -0,0 +1 @@
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([,function(e,t){!function(e){"use strict";e(function(){e(".ppw-collapse-title").click(function(){e(this).next().slideToggle()})})}(jQuery)}]);

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@@ -0,0 +1,101 @@
<?php
/**
* PPWP Countdown
*/
$text_above = get_theme_mod('ppwp_sitewide_above_countdown');
$text_below = get_theme_mod('ppwp_sitewide_below_countdown');
$start_date = get_theme_mod('ppwp_sitewide_start_time');
$end_date = get_theme_mod('ppwp_sitewide_end_time');
$is_date_countdown = get_theme_mod('ppwp_sitewide_is_show_day');
$time_unit = get_theme_mod( 'ppwp_sitewide_time_unit_countdown', 'default');
$day_of_countdown = strip_tags(get_theme_mod( 'ppwp_countdown_day_text', 'Days' ));
$hour_of_countdown = strip_tags(get_theme_mod( 'ppwp_countdown_hour_text', 'Hours' ));
$minute_of_countdown = strip_tags(get_theme_mod( 'ppwp_countdown_minute_text', 'Mimutes' ));
$second_of_countdown = strip_tags(get_theme_mod( 'ppwp_countdown_second_text', 'Seconds' ));
?>
<div class="ppwp-countdown-container">
<div id="ppwp_desc_above_countdown"><?php echo wp_kses_post( $text_above ); ?></div>
<div id="ppwp_sitewide_countdown" class="ppwp-sitewide-countdown"></div>
<div id="ppwp_desc_below_countdown"><?php echo wp_kses_post( $text_below ); ?></div>
</div>
<script>
const getCountdown = () => {
const datetime = new Date().toString();
const utcTime = (function() {
let utc = '';
let operator = '';
if (datetime.indexOf('+') >= 0) {
utc = datetime.split('+');
operator = '+';
} else {
utc = datetime.split('-');
operator = '-';
}
const utcNumber = utc[1].split(' ')[0];
const hour = Math.floor(parseInt(utcNumber)/100);
const min = (parseInt(utcNumber)%(hour*100))/60*100;
return parseFloat(hour + '.' + min) - parseFloat("<?php echo get_option('gmt_offset'); ?>");
})();
const time_unit = "<?php echo esc_attr( $time_unit ); ?>"
const end_date = "<?php echo esc_attr( $end_date ); ?>";
const countDownDate = new Date(end_date).getTime();
const start_date = "<?php echo esc_attr( $start_date ); ?>";
const countDownDateStart = new Date(start_date).getTime();
var getNow = new Date().getTime() - utcTime*3600*1000;
const isShowCountdown = "<?php echo esc_attr( $is_show_countdown ); ?>";
const isShowDateCountdown = "<?php echo esc_attr( $is_date_countdown ); ?>";
let checkvalue = false;
if (getNow < countDownDateStart) {
const x = setInterval(function() {
if( getNow < countDownDateStart ) {
getNow = new Date().getTime() - utcTime*3600*1000;
} else {
checkvalue = true;
if ( end_date ) {
getDay();
}
clearInterval(x);
}
}, 1000);
} else {
if ( end_date ) {
getDay();
}
}
function getDay() {
const x = setInterval(function() {
const now = new Date().getTime() - utcTime*3600*1000;
const distance = countDownDate - now;
const { hours, days, minutes, seconds } = (function(distance){
const hours = Math.floor(distance % (1000 * 60 * 60 * 24) / (1000 * 60 * 60));
const days = Math.floor(distance / (1000 * 60 * 60 *24));
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
return { hours, days, minutes, seconds };
})(distance);
if (isShowCountdown || isShowCountdown === '') {
if (distance > 0) {
if(days > 0) {
document.getElementById("ppwp_sitewide_countdown").innerHTML = '<div class="ppwp_countdown_timer_day"><div class="ppwp_countdown_time">' + days + "</div><div class='ppwp_countdown_timer_unit'> <?php echo esc_attr( $day_of_countdown ); ?></div>" + '</div><div class="ppwp_coundown_colon_spacing">:</div><div class="ppwp_countdown_timer_hour"><div class="ppwp_countdown_time">' + hours + " </div><div class='ppwp_countdown_timer_unit'><?php echo esc_attr( $hour_of_countdown ); ?></div>"+ '</div><div class="ppwp_coundown_colon_spacing">:</div><div class="ppwp_countdown_timer_minute"><div class="ppwp_countdown_time">' + minutes + " </div><div class='ppwp_countdown_timer_unit'><?php echo esc_attr( $minute_of_countdown ); ?></div>"+ '</div><div class="ppwp_coundown_colon_spacing">:</div><div class="ppwp_countdown_timer_second"><div class="ppwp_countdown_time">' + seconds + " </div><div class='ppwp_countdown_timer_unit'><?php echo esc_attr( $second_of_countdown ); ?></div>" + '</div>';
} else {
const hours = Math.floor(distance / (1000 * 60 * 60));
document.getElementById("ppwp_sitewide_countdown").innerHTML = '<div class="ppwp_countdown_timer_hour"><div class="ppwp_countdown_time">' + hours + " </div><div class='ppwp_countdown_timer_unit'><?php echo esc_attr( $hour_of_countdown ); ?></div>"+ '</div><div class="ppwp_coundown_colon_spacing">:</div><div class="ppwp_countdown_timer_minute"><div class="ppwp_countdown_time">' + minutes + " </div><div class='ppwp_countdown_timer_unit'><?php echo esc_attr( $minute_of_countdown ); ?></div>"+ '</div><div class="ppwp_coundown_colon_spacing">:</div><div class="ppwp_countdown_timer_second"><div class="ppwp_countdown_time">' + seconds + " </div><div class='ppwp_countdown_timer_unit'><?php echo esc_attr( $second_of_countdown ); ?></div>" + '</div>';
}
document.getElementById('ppwp_desc_above_countdown').style.display = 'block';
document.getElementById('ppwp_desc_below_countdown').style.display = 'block';
} else {
clearInterval(x);
document.getElementById('ppwp_sitewide_countdown').style.display = 'none';
document.getElementById('ppwp_desc_above_countdown').style.display = 'none';
document.getElementById('ppwp_desc_below_countdown').style.display = 'none';
}
}
}, 1000);
}
};
getCountdown();
</script>

View File

@@ -0,0 +1,19 @@
<?php
/**
* PPWP Protected Entire Site
*/
?>
<form class="ppw_main_container" id="ppw_entire_site_form">
<input type="hidden"
value="<?php echo esc_attr( wp_create_nonce( PPW_Constants::ENTIRE_SITE_FORM_NONCE ) ); ?>"
id="ppw_entire_site_form_nonce"/>
<table class="ppwp_settings_table" cellpadding="4">
<?php
include PPW_DIR_PATH . 'includes/views/entire-site/view-ppw-set-password.php';
include PPW_DIR_PATH . 'includes/views/entire-site/view-ppw-exclude-page.php';
?>
</table>
<?php
submit_button();
?>
</form>

View File

@@ -0,0 +1,26 @@
<?php
/**
* PPWP Exclude Protected page
*/
$all_page_post = ppw_free_get_all_page_post();
?>
<tr class="ppwp_free_version ppwp_logic_show_input_password <?php echo esc_attr( $is_display ); ?>">
<td></td>
<td class="ppwp_set_height_for_password_entire_site">
<div class="ppwp_wrap_new_password">
<span class="feature-input"></span>
<span class="ppwp-set-new-password-text">
Exclude certain pages, posts and custom post types from site-wide protection. Available in Pro version.
</span>
</div>
<div class="ppwp_free_wrap_select_exclude_page ppwp-hidden-password">
<select multiple="multiple" class="ppwp_select2">
<option value="ppwp_home_page">Home Page</option>
<?php foreach ( $all_page_post as $page ) { ?>
<option><?php echo esc_html( $page->post_title ); ?></option>
<?php } ?>
</select>
</div>
</td>
</tr>

View File

@@ -0,0 +1,73 @@
<?php
/**
* PPWP Form Password
*/
$page_title = ppw_get_page_title();
$password_label = _x( 'Password:', PPW_Constants::CONTEXT_SITEWIDE_PASSWORD_FORM, 'password-protect-page' );
$password_placehoder = wp_kses_post( get_theme_mod( 'ppwp_pro_form_instructions_placeholder' ) );
$btn_label = get_theme_mod( 'ppwp_pro_form_button_label', PPW_Constants::DEFAULT_SHORTCODE_BUTTON );
$disable_logo = get_theme_mod( 'ppwp_pro_logo_disable', 0 ) ? 'none' : 'block';
$form_transparency = get_theme_mod( 'ppwp_pro_form_enable_transparency' ) ? 'style="background: none!important; box-shadow: initial;"' : '';
$is_wrong_password = isset( $_GET['action'] ) && $_GET['action'] === 'ppw_postpass' && isset( $_POST['input_wp_protect_password'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended -- We no need to handle nonce verification for render UI.
$internal_css = '<link rel="stylesheet" href="' . PPW_VIEW_URL . 'dist/ppw-form-entire-site.css" type="text/css">' . PHP_EOL;
$form_action = apply_filters( 'ppw_sitewide_form_action', '?action=ppw_postpass' );
$err_msg = apply_filters( 'ppw_sitewide_error_message', esc_html__( 'Please enter the correct password!', 'password-protect-page' ) );
$start_date = get_theme_mod( 'ppwp_sitewide_start_time' );
$end_date = get_theme_mod( 'ppwp_sitewide_end_time' );
$is_show_form = $end_date ? true : false;
?>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="description" content=""/>
<meta name="viewport" content="width=device-width"/>
<link rel="icon" href="<?php echo esc_attr( get_site_icon_url() ); ?>"/>
<?php echo apply_filters( 'ppw_sitewide_external_css', $internal_css ); ?>
<title><?php echo esc_attr( $page_title ); ?></title>
<?php do_action( PPW_Constants::HOOK_CUSTOM_HEADER_FORM_ENTIRE_SITE ); ?>
<style>
<?php
do_action( 'ppw_sitewide_custom_internal_css' );
do_action( PPW_Constants::HOOK_CUSTOM_STYLE_FORM_ENTIRE_SITE );
do_action( 'ppwp_sitewide_hide_password_form' );
do_action( 'ppwp_countdown_timer_styles' );
?>
</style>
<?php wp_custom_css_cb(); ?>
</head>
<body class="ppwp-sitewide-protection">
<div class="pda-form-login ppw-swp-form-container">
<h1>
<a style="display: <?php echo esc_attr( $disable_logo ); ?>" title="<?php echo esc_attr__( 'This site is password protected by PPWP plugin', 'password-protect-page') ?>" class="ppw-swp-logo">Password Protect WordPress plugin</a>
</h1>
<?php
do_action( 'ppw_sitewide_above_password_form_container' );
?>
<form <?php echo wp_kses_post( $form_transparency ); ?> class="ppw-swp-form" action="<?php echo esc_attr( $form_action ); ?>" method="post">
<?php do_action( 'ppw_sitewide_above_password_form' ); ?>
<label for="input_wp_protect_password"><?php echo esc_html( $password_label ); ?></label>
<input class="input_wp_protect_password" type="password" id="input_wp_protect_password"
name="input_wp_protect_password" placeholder="<?php echo esc_attr( $password_placehoder ); ?>"/>
<?php
if ( $is_wrong_password ) {
?>
<div id="ppw_entire_site_wrong_password" class="ppw-entire-site-password-error">
<?php echo wp_kses_post( $err_msg ); ?>
</div>
<?php
}
do_action( 'ppw_sitewide_above_submit_button' );
?>
<input type="submit" class="button button-primary button-login" value="<?php echo esc_html( $btn_label ); ?>">
<?php do_action( 'ppw_sitewide_below_password_form' ); ?>
</form>
</div>
<?php
do_action('ppwp_render_sitewide_countdown');
?>
<?php do_action( PPW_Constants::HOOK_CUSTOM_FOOTER_FORM_ENTIRE_SITE ); ?>
</body>
</html>

View File

@@ -0,0 +1,66 @@
<?php
/**
* PPWP Set Password & Password Protect Entire Site
*/
$password_for_website = ppw_core_get_setting_entire_site_type_string( PPW_Constants::PASSWORD_ENTIRE_SITE );
$is_protected = ppw_core_get_setting_entire_site_type_bool( PPW_Constants::IS_PROTECT_ENTIRE_SITE );
$is_display = $is_protected ? '' : 'ppwp-hidden-password';
?>
<tr>
<td>
<?php if ( $is_protected ) { ?>
<label class="pda_switch" for="ppwp_apply_password_for_entire_site">
<input type="checkbox" id="ppwp_apply_password_for_entire_site" checked/>
<span class="pda-slider round"></span>
</label>
<?php } else { ?>
<label class="pda_switch" for="ppwp_apply_password_for_entire_site">
<input type="checkbox" id="ppwp_apply_password_for_entire_site"/>
<span class="pda-slider round"></span>
</label>
<?php } ?>
</td>
<td>
<p>
<label><?php echo esc_html__( 'Password Protect Entire Site', PPW_Constants::DOMAIN ) ?></label>
<?php echo esc_html__( 'Set passwords to ', 'password-protect-page' ); ?>
<a target="_blank" rel="noopener" href="https://passwordprotectwp.com/docs/password-protect-wordpress-lite/?utm_source=user-website&utm_medium=sitewide-protection-general&utm_campaign=ppwp-free#sitewide">
<?php echo esc_html__( 'protect your entire WordPress site', 'password-protect-page' ); ?></a>.
<?php echo sprintf('%1$s<a href="%2$s">%3$s</a>', esc_html__('Customize password login form using ', 'password-protect-page' ), admin_url( 'customize.php?autofocus[panel]=ppwp_sitewide' ), __( 'WordPress Customizer', 'password-protect-page' ) ) ?>
</p>
</td>
</tr>
<?php if ( ! empty( $password_for_website ) ) { ?>
<tr class="ppwp_logic_show_input_password <?php echo esc_attr( $is_display ) ?>">
<td></td>
<td class="ppwp_set_height_for_password_entire_site">
<p><?php esc_html_e( 'Youve set a password to protect your site.', PPW_Constants::DOMAIN ); ?></p>
<div class="ppwp_wrap_new_password_for_entire_site ppwp_wrap_new_password">
<label class="pda_switch" for="ppwp_set_new_password_for_entire_site">
<input type="checkbox" id="ppwp_set_new_password_for_entire_site"/>
<span class="pda-slider round"></span>
</label>
<span class="ppwp-set-new-password-text">Set a new password</span>
</div>
<div class="ppwp_hidden_new_password_for_entire_site" id="ppwp_new_password_entire_site">
<div class="ppwp_wrap_new_password">
<label class="pda_switch"></label>
<span class="ppwp-set-new-password-input">
<input required type="text" autocomplete="off" placeholder="Enter new password"
id="ppwp_password_for_entire_site" name="ppwp_password_for_entire_site">
</span>
</div>
</div>
</td>
</tr>
<?php } else { ?>
<tr class="ppwp_logic_show_input_password <?php echo esc_attr( $is_display ) ?>">
<td></td>
<td class="ppwp_text_after_enter_password_succes">
<p><?php echo esc_html__( 'Set a password', PPW_Constants::DOMAIN ) ?></p>
<input required type="text" autocomplete="off" placeholder="Enter a password"
id="ppwp_password_for_entire_site" name="ppwp_password_for_entire_site">
</td>
</tr>
<?php } ?>

View File

@@ -0,0 +1,116 @@
<?php
/**
* General Configuration Settings
*/
$api_key = PPW_Recaptcha::get_instance()->get_recaptcha_v3_api_key();
$api_key_v2 = PPW_Recaptcha::get_instance()->get_recaptcha_v2_api_key();
$api_secret = PPW_Recaptcha::get_instance()->get_recaptcha_v3_api_secret();
$api_secret_v2 = PPW_Recaptcha::get_instance()->get_recaptcha_v2_api_secret();
$score = PPW_Recaptcha::get_instance()->get_limit_score();
?>
<div class="ppw_main_container" id="ppw_shortcodes_form">
<table class="ppwp_settings_table" cellpadding="4">
<td colspan="2">
<div style="margin-bottom: 1rem">
<h3 style="text-transform: none; margin-bottom: 0.5rem">
<?php echo esc_html__('Configure reCAPTCHA key','password-protect-page'); ?></h3>
<a rel="noopener" target="_blank" href="https://g.co/recaptcha/v3"><?php echo esc_html__('Get the Site Key and Secret Key','password-protect-page');?></a><?php echo esc_html__('from Google','password-protect-page')?>
</div>
</td>
</table>
<form id="wpp_external_v3_form" method="post">
<input type="hidden" id="ppw_general_form_nonce"
value="<?php echo esc_attr( wp_create_nonce( PPW_Constants::GENERAL_FORM_NONCE ) ); ?>"/>
<table class="ppwp_settings_table" cellpadding="4">
<tr id="wpp_recaptcha_configs">
<td class="feature-input">
<span class="feature-input"></span>
</td>
<td>
<p>
<label><?php echo esc_html__( 'reCAPTCHA v3', 'password-protect-page' ) ?></label>
</p>
<span>
<p>
<label><?php echo esc_html__( 'Site Key', 'password-protect-page' ) ?></label>
</p>
<span class="ppwp-recaptcha-input">
<input id="<?php echo esc_attr( PPW_Constants::RECAPTCHA_API_KEY ); ?>" type="text"
value="<?php echo esc_attr( $api_key ); ?>"/>
<div id="ppwp-error-require-v3-key" style="display: none; color: red; position: absolute; font-size: 12px;">This field is required.</div>
</span>
<p>
<label class="ppwp-title"><?php echo esc_html__( 'Secret Key', 'password-protect-page' ) ?></label>
</p>
<span class="ppwp-recaptcha-input">
<input id="<?php echo esc_attr( PPW_Constants::RECAPTCHA_API_SECRET ); ?>" type="text"
value="<?php echo esc_attr( $api_secret ); ?>"/>
</span>
<div id="ppwp-error-require-v3-secret" style="display: none; color: red; position: absolute; font-size: 12px;">This field is required.</div>
<p id="recaptcha-score-container">
<label class="ppwp-title"><?php echo esc_html__( 'Threshold', 'password-protect-page' ) ?></label>
Define users' score that will pass reCAPTCHA protection
<span class="ppw-recaptcha-score">
<select class="ppw_main_container select"
id="<?php echo esc_attr( PPW_Constants::RECAPTCHA_SCORE ); ?>">
<?php
for ( $i = 0; $i <= 10; $i ++ ) {
$s = number_format( ( $i / 10 ), 1 );
$selected = (double) $s === $score ? 'selected="selected"' : '';
echo '<option value="' . esc_attr( $s ) . '"' . esc_html( $selected ) . '>' . esc_html( $s ) . '</option>';
}
?>
</select>
</span>
</p>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" name="v3_submit_btn" id="submit" class="button button-primary v3_submit_btn" value="Save Changes">
</td>
</tr>
</table>
</form>
<form id="wpp_external_v2_form" method="post">
<table class="ppwp_settings_table" cellpadding="4">
<tr id="wpp_recaptcha_configs">
<td class="feature-input">
<span class="feature-input"></span>
</td>
<td>
<p>
<label><?php echo esc_html__( 'reCAPTCHA v2 - Checkbox', 'password-protect-page' ); ?></label>
</p>
<span>
<p>
<label><?php echo esc_html__( 'Site Key', 'password-protect-page' ) ?></label>
</p>
<span class="ppwp-recaptcha-input">
<input id="<?php echo esc_attr( PPW_Constants::RECAPTCHA_V2_CHECKBOX_API_KEY ); ?>" type="text"
value="<?php echo esc_attr( $api_key_v2 ); ?>"/>
</span>
<div id="ppwp-error-require-v2-key" style="display: none; color: red; position: absolute; font-size: 12px;"><?php echo esc_html__('This field is required.','password-protect-page');?> </div>
<p>
<label class="ppwp-title"><?php echo esc_html__( 'Secret Key', 'password-protect-page' ) ?></label>
</p>
<span class="ppwp-recaptcha-input">
<input id="<?php echo esc_attr( PPW_Constants::RECAPTCHA_V2_CHECKBOX_API_SECRET ); ?>" type="text"
value="<?php echo esc_attr( $api_secret_v2 ); ?>"/>
</span>
<div id="ppwp-error-require-v2-secret" style="display: none; color: red; position: absolute; font-size: 12px;"><?php echo esc_html__('This field is required.','password-protect-page');?></div>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" name="v2_submit_btn" id="submit" class="button button-primary recaptcha-btn" value="Save Changes">
</td>
</tr>
</table>
</form>
</div>

View File

@@ -0,0 +1,80 @@
<?php
/**
* PPWP General Settings
*/
$using_recaptcha = PPW_Recaptcha::get_instance()->using_recaptcha() ? 'checked' : '';
$recaptcha_type = PPW_Recaptcha::get_instance()->get_recaptcha_type();
$password_types = PPW_Recaptcha::get_instance()->get_password_types();
$type_options = array(
PPW_Recaptcha::RECAPTCHA_V3_TYPE => __( 'reCAPTCHA v3', 'password-protect-page' ),
PPW_Recaptcha::RECAPTCHA_V2_CHECKBOX_TYPE => __( 'reCAPTCHA v2 - Checkbox', 'password-protect-page' ),
);
$password_type_options = array(
PPW_Recaptcha::SINGLE_PASSWORD => __( 'Single password form', 'password-protect-page' ),
PPW_Recaptcha::SITEWIDE_PASSWORD => __( 'Sitewide login form', 'password-protect-page' ),
PPW_Recaptcha::PCP_PASSWORD => __( 'PCP password form', 'password-protect-page' ),
);
?>
<div class="ppw_main_container" id="ppw_shortcodes_form">
<form id="wpp_external_form" method="post">
<input type="hidden" id="ppw_general_form_nonce"
value="<?php echo esc_attr( wp_create_nonce( PPW_Constants::GENERAL_FORM_NONCE ) ); ?>"/>
<table class="ppwp_settings_table" cellpadding="4">
<tr>
<td>
<label class="pda_switch" for="<?php echo esc_attr( PPW_Constants::USING_RECAPTCHA ); ?>">
<input type="checkbox"
id="<?php echo esc_attr( PPW_Constants::USING_RECAPTCHA ); ?>" <?php echo esc_html( $using_recaptcha ); ?>>
<span class="pda-slider round"></span>
</label>
</td>
<td>
<p style="margin-bottom: 6px;">
<label><?php esc_attr_e( 'Enable Google reCAPTCHA Protection', 'password-protect-page' ) ?></label>
<a rel="noopener" target="_blank" href="https://passwordprotectwp.com/docs/add-google-recaptcha-wordpress-password-form/?utm_source=user-website&utm_medium=integration-recaptcha&utm_campaign=ppwp-free"><?php echo esc_html__('Protect
your password form','password-protect-page')?></a>
<?php echo esc_html__('from abuse and spam while allowing real user access only','password-protect-page');?>
</p>
<div
<?php echo $using_recaptcha ? '' : 'style="display: none"'; ?>
id="wpp_recaptcha_options">
<div>
<p><?php esc_attr_e( 'Choose reCAPTCHA type', 'password-protect-page' ); ?></p>
<select
class="ppw_main_container select"
id="wpp_recaptcha_type">
<?php
foreach ( $type_options as $key => $value ) {
$selected = $key === $recaptcha_type ? 'selected="selected"' : '';
echo '<option value="' . esc_attr( $key ) . '" ' . esc_html( $selected ) . '>' . esc_html( $value ) . '</option>';
}
?>
<option value="recaptcha_v2_invisible"
disabled><?php echo esc_html__( 'reCAPTCHA v2 - Invisible', 'password-protect-page' ); ?></option>
</select>
</div>
<div style="max-width: 25rem;">
<p><?php esc_attr_e( 'Choose which password form to apply reCAPTCHA', 'password-protect-page' ); ?></p>
<select id="wpp_recaptcha_password_types" class="ppw_main_container select ppw_select_types" required multiple="multiple">
<?php
foreach ( $password_type_options as $key => $value ) {
$selected = in_array( $key, $password_types) ? 'selected="selected"' : '';
echo '<option value="' . esc_attr( $key ) . '" ' . esc_html( $selected ) . '>' . esc_html( $value ) . '</option>';
}
?>
</select>
</div>
</div>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
</td>
</tr>
</table>
</form>
</div>

View File

@@ -0,0 +1,16 @@
<?php
/**
* Password Protect Child Pages
*/
?>
<tr class="ppwp_free_version">
<td class="feature-input"><span class="feature-input"></span></td>
<td>
<p>
<label>
<?php echo esc_html__( 'Password Protect Child Pages', PPW_Constants::DOMAIN ); ?>
</label>
<?php echo esc_html__( 'Automatically protect all child pages once their parent is protected. Available in Pro version.', PPW_Constants::DOMAIN ); ?>
</p>
</td>
</tr>

View File

@@ -0,0 +1,22 @@
<?php
$post_types = ppw_core_get_all_post_types();
unset( $post_types['post'] );
unset( $post_types['page'] );
?>
<tr class="ppwp_free_version">
<td class="feature-input"><span class="feature-input"></span></td>
<td>
<p>
<label>
<?php echo esc_html__( 'Post Type Protection', PPW_Constants::DOMAIN ); ?>
</label>
<?php echo _e( '<a target="_blank" rel="noopener noreferrer" href="https://passwordprotectwp.com/docs/settings/?utm_source=user-website&utm_medium=settings-general-tab&utm_campaign=ppwp-free#cpt">Select which custom post types</a> you want to password protect. Default: Pages & Posts.', PPW_Constants::DOMAIN ); // phpcs:ignore -- there is no value to escape. ?>
</p>
<div class="ppw_wrap_select_protection_selected">
<div class="ppw_wrap_protection_selected">
<span class="ppw_protection_selected">Pages</span>
<span class="ppw_protection_selected">Posts</span>
</div>
</div>
</td>
</tr>

View File

@@ -0,0 +1,13 @@
<tr class="ppwp_free_version">
<td class="feature-input"><span class="feature-input"></span></td>
<td>
<p>
<label><?php echo esc_html__( 'Error Message', PPW_Constants::DOMAIN ) ?></label>
<?php echo _e( 'Customize the error message when users enter wrong passwords.<em> Available in Pro version only.</em>', PPW_Constants::DOMAIN ) ?>
</p>
<span>
<input type="text"
value="<?php echo esc_html( PPW_Constants::DEFAULT_WRONG_PASSWORD_MESSAGE ); ?>"/>
</span>
</td>
</tr>

View File

@@ -0,0 +1,55 @@
<?php
$password_cookie_expired = ppw_core_get_setting_type_string( PPW_Constants::COOKIE_EXPIRED );
$time = 7;
$units = 'days';
$one_year = 365;
$max = $one_year;
if ( ! empty( $password_cookie_expired ) ) {
$tmp = explode( ' ', $password_cookie_expired );
if ( count( $tmp ) === 2 ) {
$time = (int) $tmp[0];
$units = $tmp[1];
switch ( $units ) {
case 'hours':
$max = $one_year * 24;
break;
case 'minutes':
$max = $one_year * 24 * 60;
break;
case 'seconds':
$max = $one_year * 24 * 60 * 60;
break;
default:
$max = $one_year;
}
}
}
?>
<tr>
<td class="feature-input"><span class="feature-input"></span></td>
<td>
<p>
<label><?php echo esc_html__( 'Cookie Expiration Time', PPW_Constants::DOMAIN ); ?></label>
<?php echo _e( 'By default, users wont have to re-enter passwords until its cookie expires. You can also <a target="_blank" href="https://passwordprotectwp.com/docs/settings/?utm_source=user-website&utm_medium=settings-general-tab&utm_campaign=ppwp-free#cookies">use session cookies</a> to log users out right after they close the browser.', PPW_Constants::DOMAIN ); // phpcs:ignore -- there is no value to escape. ?>
</p>
<input required value="<?php echo esc_attr( $time ); ?>" class="wpp_time_number" type="number"
id="wpp_password_cookie_times" min="1" max="<?php echo esc_attr( $max ); ?>"/>
<select id="wpp_password_cookie_units" class="wpp_password_cookie_units">
<option value="days" <?php if ( 'days' === $units ) {
echo 'selected';
} ?>><?php echo esc_html__( 'Days', PPW_Constants::DOMAIN ); ?></option>
<option value="hours" <?php if ( 'hours' === $units ) {
echo 'selected';
} ?> ><?php echo esc_html__( 'Hours', PPW_Constants::DOMAIN ) ?>
</option>
<option value="minutes" <?php if ( 'minutes' === $units ) {
echo 'selected';
} ?> ><?php echo esc_html__( 'Minutes', PPW_Constants::DOMAIN ) ?>
</option>
<option value="seconds" <?php if ( 'seconds' === $units ) {
echo 'selected';
} ?> ><?php echo esc_html__( 'Seconds', PPW_Constants::DOMAIN ) ?>
</option>
</select>
</td>
</tr>

View File

@@ -0,0 +1,10 @@
<tr class="ppwp_free_version">
<td class="feature-input"><span class="feature-input"></span></td>
<td>
<p>
<label><?php echo esc_html__( 'Form Message', PPW_Constants::DOMAIN ) ?></label>
<?php echo _e( 'Customize the message which displays above the password field.<em> Available in Pro version only.</em>', PPW_Constants::DOMAIN ) ?>
</p>
<input type="text" value="<?php echo esc_html( PPW_Constants::DEFAULT_FORM_MESSAGE ); ?>"/>
</td>
</tr>

View File

@@ -0,0 +1,77 @@
<form class="ppw_main_container" id="wp_protect_password_general_form">
<input type="hidden" id="ppw_general_form_nonce"
value="<?php echo esc_attr( wp_create_nonce( PPW_Constants::GENERAL_FORM_NONCE ) ); ?>"/>
<table class="ppwp_settings_table" cellpadding="4">
<tr id="pda-password-protection">
<td colspan="2">
<h3><?php echo esc_html__( 'PASSWORD PROTECTION', 'password-protect-page' ); ?></h3>
</td>
</tr>
<?php
include PPW_DIR_PATH . 'includes/views/general/view-ppw-custom-column-permission.php';
include PPW_DIR_PATH . 'includes/views/general/view-ppw-expired-cookie.php';
include PPW_DIR_PATH . 'includes/views/general/view-ppw-whitelist-roles.php';
include PPW_DIR_PATH . 'includes/views/general/view-ppw-auto-protect-child-page.php';
// include PPW_DIR_PATH . 'includes/views/general/view-ppw-protect-private-pages.php';
include PPW_DIR_PATH . 'includes/views/general/view-ppw-hide-protected-post.php';
?>
<tr>
<td colspan="2">
<hr>
</td>
</tr>
<tr id="wpp-password-form">
<td colspan="2">
<h3><?php echo esc_html__( 'PASSWORD FORM CUSTOMIZATION', 'password-protect-page' ); ?></h3>
</td>
</tr>
<tr>
<td class="feature-input"><span class="feature-input"></span></td>
<td>
<?php
$link_error_message = sprintf(
'<a target="_blank" rel="noopener" href="%s">error message & password form</a>',
'https://passwordprotectwp.com/customize-password-form-wordpress-customizer/?utm_source=user-website&utm_medium=settings-general-tab&utm_campaign=ppwp-free'
);
$link_customizer = sprintf(
'<a target="_blank" rel="noopener" href="%s">WordPress Customizer</a>',
'customize.php?autofocus[panel]=ppwp'
);
$form_message = sprintf(
// translators: %s: Link to documentation.
esc_html__( 'Customize the default %1$s including headline, description and button under %2$s.', 'password-protect-page' ),
$link_error_message,
$link_customizer
);
?>
<?php echo wp_kses_post( $form_message ); ?>
</td>
</tr>
<?php
// include PPW_DIR_PATH . 'includes/views/general/view-ppw-form-message.php';
// include PPW_DIR_PATH . 'includes/views/general/view-ppw-error-message.php';
?>
<tr>
<td colspan="2">
<hr>
</td>
</tr>
<tr id="wpp-password-form">
<td colspan="2">
<h3><?php echo esc_html__( 'ADVANCED OPTIONS', 'password-protect-page' ); ?></h3>
</td>
</tr>
<?php
include PPW_DIR_PATH . 'includes/views/general/view-ppw-remove-search-engine.php';
include PPW_DIR_PATH . 'includes/views/general/view-ppw-remove-data.php';
?>
</table>
<?php
submit_button();
?>
<table class="ppwp_settings_table" cellpadding="4">
<?php
include PPW_DIR_PATH . 'includes/views/general/view-ppw-notices-cache.php';
?>
</table>
</form>

View File

@@ -0,0 +1,32 @@
<?php
$ppw_post_types = ppw_core_get_post_type_for_hide_protect_content();
$link_description = sprintf( '<a target="_blank" rel="noopener" href="%s">Hide your password protected content</a>', 'https://passwordprotectwp.com/docs/how-to-hide-password-protected-wordpress-content/?utm_source=user-website&utm_medium=settings-general-tab&utm_campaign=ppwp-free' );
// translators: %s: Link to documentation.
$link_description_rss = sprintf( '<a target="_blank" rel="noopener" href="%s">show protected content in RSS feeds</a>', 'https://passwordprotectwp.com/docs/display-protected-content-rss-feed/?utm_source=user-website&utm_medium=settings-general-tab&utm_campaign=ppwp-free' );
$description = sprintf( esc_html__( '%s from selected views. Learn how to %s.', 'password-protect-page' ), $link_description, $link_description_rss );
?>
<tr>
<td class="feature-input"><span class="feature-input"></span></td>
<td>
<p>
<label><?php echo esc_html__( 'Protected Content Visibility', 'password-protect-page' ); ?></label>
<?php echo $description; // phpcs:ignore -- could not escape html ?>
<p>Switch post types to customize their own visibility. Only Pages & Posts are available on Free version.</p>
<select class="ppw_select_custom_post_type_edit" id="ppw_select_custom_post_type_edit">
<?php
foreach ( $ppw_post_types as $ppw_type ) {
$ppw_disabled = apply_filters( PPW_Constants::HOOK_CUSTOM_OPTION_HIDE_PROTECT_CONTENT, 'page_post' === $ppw_type['value'] ? '' : 'disabled', $ppw_type['value'] );
?>
<option <?php echo esc_attr( $ppw_disabled ); ?>
value="<?php echo esc_attr( $ppw_type['value'] ); ?>"><?php echo esc_attr( $ppw_type['label'] ); ?></option>
<?php
}
?>
</select>
</p>
</td>
</tr>
<?php
ppw_core_check_logic_before_render_ui( $ppw_post_types );
?>

View File

@@ -0,0 +1,14 @@
<tr>
<td colspan="2">
<hr>
</td>
</tr>
<tr>
<td class="feature-input"><span class="feature-input"></span></td>
<td>
<p>
<label><?php echo esc_html__( 'Caching Plugins & Server-side Caching', PPW_Constants::DOMAIN ); ?></label>
<?php _e( 'If youre using a caching plugin or server-side caching, youll need to <a rel="noopener noreferrer" target="_blank" href="https://passwordprotectwp.com/docs/caching-plugins-cache-servers-integration/?utm_source=user-website&utm_medium=settings-general-tab&utm_campaign=ppwp-free">update your caching configurations</a> for our Password Protect Wordpress plugin to work properly.', PPW_Constants::DOMAIN ); ?>
</p>
</td>
</tr>

View File

@@ -0,0 +1,31 @@
<?php
$all_page_post = ppw_free_get_all_page_post();
?>
<tr class="ppwp_free_version">
<td class="feature-input"><span class="feature-input"></span></td>
<td>
<p>
<label>
<?php echo esc_html__( 'Password Protect Private Pages', PPW_Constants::DOMAIN ) ?>
</label>
<?php echo _e( 'Set the same password to protect the following pages and posts. Available in Pro version.', PPW_Constants::DOMAIN ) ?>
</p>
</td>
</tr>
<tr class="ppwp-free-pages-posts-set-password ppwp-hidden-password ppwp_free_version">
<td></td>
<td><p><?php echo esc_html__( 'Select your private pages or posts', PPW_Constants::DOMAIN ) ?></p>
<select multiple="multiple" class="ppwp_select2">
<?php foreach ( $all_page_post as $page ): ?>
<option disabled="disabled"><?php echo esc_html( $page->post_title ) ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr class="ppwp-free-pages-posts-set-password ppwp-hidden-password ppwp_free_version">
<td></td>
<td class="ppwp_wrap_set_new_password_for_pages_posts">
<p><?php echo esc_html__( 'Set a password', PPW_Constants::DOMAIN ) ?></p>
<input type="text" placeholder="Enter a password"/>
</td>
</tr>

Some files were not shown because too many files have changed in this diff Show More