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.