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'] );
}
}
}