Commit realizado el 12:13:52 08-04-2024
This commit is contained in:
373
wp-content/plugins/wpforms-lite/src/Admin/Builder/AntiSpam.php
Normal file
373
wp-content/plugins/wpforms-lite/src/Admin/Builder/AntiSpam.php
Normal file
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
|
||||
namespace WPForms\Admin\Builder;
|
||||
|
||||
use WPForms\Forms\Akismet;
|
||||
use WPForms_Builder_Panel_Settings;
|
||||
|
||||
/**
|
||||
* AntiSpam class.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*/
|
||||
class AntiSpam {
|
||||
|
||||
/**
|
||||
* Form data and settings.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $form_data;
|
||||
|
||||
/**
|
||||
* Init class.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
$this->hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hooks.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*/
|
||||
protected function hooks() {
|
||||
|
||||
add_action( 'wpforms_form_settings_panel_content', [ $this, 'panel_content' ], 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a content for `Spam Protection and Security` panel.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param WPForms_Builder_Panel_Settings $instance Settings panel instance.
|
||||
*/
|
||||
public function panel_content( $instance ) {
|
||||
|
||||
$this->form_data = $instance->form_data;
|
||||
|
||||
echo '<div class="wpforms-panel-content-section wpforms-panel-content-section-anti_spam">';
|
||||
echo '<div class="wpforms-panel-content-section-title">';
|
||||
esc_html_e( 'Spam Protection and Security', 'wpforms-lite' );
|
||||
echo '</div>';
|
||||
|
||||
$antispam = wpforms_panel_field(
|
||||
'toggle',
|
||||
'settings',
|
||||
'antispam',
|
||||
$this->form_data,
|
||||
__( 'Enable anti-spam protection', 'wpforms-lite' ),
|
||||
[
|
||||
'tooltip' => __( 'Turn on invisible spam protection.', 'wpforms-lite' ),
|
||||
],
|
||||
false
|
||||
);
|
||||
|
||||
wpforms_panel_fields_group(
|
||||
$antispam,
|
||||
[
|
||||
'description' => __( 'Behind-the-scenes spam filtering that\'s invisible to your visitors.', 'wpforms-lite' ),
|
||||
'title' => __( 'Protection', 'wpforms-lite' ),
|
||||
]
|
||||
);
|
||||
|
||||
if ( ! empty( $this->form_data['settings']['honeypot'] ) ) {
|
||||
wpforms_panel_field(
|
||||
'toggle',
|
||||
'settings',
|
||||
'honeypot',
|
||||
$this->form_data,
|
||||
__( 'Enable anti-spam honeypot', 'wpforms-lite' )
|
||||
);
|
||||
}
|
||||
|
||||
$this->akismet_settings();
|
||||
$this->store_spam_entries_settings();
|
||||
$this->time_limit_settings();
|
||||
$this->captcha_settings();
|
||||
|
||||
/**
|
||||
* Fires once in the end of content panel before Also Available section.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param array $form_data Form data and settings.
|
||||
*/
|
||||
do_action( 'wpforms_admin_builder_anti_spam_panel_content', $this->form_data );
|
||||
|
||||
wpforms_panel_fields_group(
|
||||
$this->get_also_available_block(),
|
||||
[
|
||||
'unfoldable' => true,
|
||||
'default' => 'opened',
|
||||
'group' => 'also_available',
|
||||
'title' => __( 'Also Available', 'wpforms-lite' ),
|
||||
'borders' => [ 'top' ],
|
||||
]
|
||||
);
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it is a new setup.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_new_setup() {
|
||||
|
||||
$form_counts = wp_count_posts( 'wpforms' );
|
||||
$form_counts = array_filter( (array) $form_counts );
|
||||
|
||||
return empty( $form_counts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the *CAPTCHA settings.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*/
|
||||
private function captcha_settings() {
|
||||
|
||||
$captcha_settings = wpforms_get_captcha_settings();
|
||||
|
||||
if (
|
||||
empty( $captcha_settings['provider'] ) ||
|
||||
$captcha_settings['provider'] === 'none' ||
|
||||
empty( $captcha_settings['site_key'] ) ||
|
||||
empty( $captcha_settings['secret_key'] )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$captcha_types = [
|
||||
'hcaptcha' => __( 'Enable hCaptcha', 'wpforms-lite' ),
|
||||
'turnstile' => __( 'Enable Cloudflare Turnstile', 'wpforms-lite' ),
|
||||
'recaptcha' => [
|
||||
'v2' => __( 'Enable Google Checkbox v2 reCAPTCHA', 'wpforms-lite' ),
|
||||
'invisible' => __( 'Enable Google Invisible v2 reCAPTCHA', 'wpforms-lite' ),
|
||||
'v3' => __( 'Enable Google v3 reCAPTCHA', 'wpforms-lite' ),
|
||||
],
|
||||
];
|
||||
|
||||
$is_recaptcha = $captcha_settings['provider'] === 'recaptcha';
|
||||
$captcha_types = $is_recaptcha ? $captcha_types['recaptcha'] : $captcha_types;
|
||||
$captcha_key = $is_recaptcha ? $captcha_settings['recaptcha_type'] : $captcha_settings['provider'];
|
||||
$label = ! empty( $captcha_types[ $captcha_key ] ) ? $captcha_types[ $captcha_key ] : '';
|
||||
|
||||
$recaptcha = wpforms_panel_field(
|
||||
'toggle',
|
||||
'settings',
|
||||
'recaptcha',
|
||||
$this->form_data,
|
||||
$label,
|
||||
[
|
||||
'data' => [
|
||||
'provider' => $captcha_settings['provider'],
|
||||
],
|
||||
'tooltip' => __( 'Enable third-party CAPTCHAs to prevent form submissions from bots.', 'wpforms-lite' ),
|
||||
],
|
||||
false
|
||||
);
|
||||
|
||||
wpforms_panel_fields_group(
|
||||
$recaptcha,
|
||||
[
|
||||
'description' => __( 'Automated tests that help to prevent bots from submitting your forms.', 'wpforms-lite' ),
|
||||
'title' => __( 'CAPTCHA', 'wpforms-lite' ),
|
||||
'borders' => [ 'top' ],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the Spam Entries Store settings.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*/
|
||||
public function store_spam_entries_settings() {
|
||||
|
||||
// Enable storing entries by default for new setup.
|
||||
$store_spam_entries = ! empty( $this->form_data['settings']['store_spam_entries'] )
|
||||
? $this->form_data['settings']['store_spam_entries']
|
||||
: $this->is_new_setup();
|
||||
|
||||
wpforms_panel_field(
|
||||
'toggle',
|
||||
'settings',
|
||||
'store_spam_entries',
|
||||
$this->form_data,
|
||||
__( 'Store spam entries in the database', 'wpforms-lite' ),
|
||||
[
|
||||
'value' => $store_spam_entries,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the Time Limit settings.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*/
|
||||
private function time_limit_settings() {
|
||||
|
||||
wpforms_panel_field(
|
||||
'toggle',
|
||||
'anti_spam',
|
||||
'enable',
|
||||
$this->form_data,
|
||||
__( 'Enable minimum time to submit', 'wpforms-lite' ),
|
||||
[
|
||||
'parent' => 'settings',
|
||||
'subsection' => 'time_limit',
|
||||
'tooltip' => __( 'Set a minimum amount of time a user must spend on a form before submitting.', 'wpforms-lite' ),
|
||||
'input_class' => 'wpforms-panel-field-toggle-next-field',
|
||||
]
|
||||
);
|
||||
|
||||
wpforms_panel_field(
|
||||
'text',
|
||||
'anti_spam',
|
||||
'duration',
|
||||
$this->form_data,
|
||||
__( 'Minimum time to submit', 'wpforms-lite' ),
|
||||
[
|
||||
'parent' => 'settings',
|
||||
'subsection' => 'time_limit',
|
||||
'type' => 'number',
|
||||
'min' => 1,
|
||||
'default' => 3,
|
||||
'after' => sprintf( '<span class="wpforms-panel-field-after">%s</span>', __( 'seconds', 'wpforms-lite' ) ),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the Akismet settings.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*/
|
||||
private function akismet_settings() {
|
||||
|
||||
if ( ! Akismet::is_installed() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$args = [];
|
||||
|
||||
if ( ! Akismet::is_configured() ) {
|
||||
$args['data']['akismet-status'] = 'akismet_no_api_key';
|
||||
}
|
||||
|
||||
if ( ! Akismet::is_activated() ) {
|
||||
$args['data']['akismet-status'] = 'akismet_not_activated';
|
||||
}
|
||||
|
||||
// If Akismet isn't available, disable the Akismet toggle.
|
||||
if ( isset( $args['data'] ) ) {
|
||||
$args['input_class'] = 'wpforms-akismet-disabled';
|
||||
$args['value'] = '0';
|
||||
}
|
||||
|
||||
wpforms_panel_field(
|
||||
'toggle',
|
||||
'settings',
|
||||
'akismet',
|
||||
$this->form_data,
|
||||
__( 'Enable Akismet anti-spam protection', 'wpforms-lite' ),
|
||||
$args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Also Available block.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_also_available_block() {
|
||||
|
||||
$get_started_button_text = __( 'Get Started →', 'wpforms-lite' );
|
||||
$upgrade_to_pro_text = __( 'Upgrade to Pro', 'wpforms-lite' );
|
||||
$captcha_settings = wpforms_get_captcha_settings();
|
||||
$upgrade_url = 'https://wpforms.com/lite-upgrade/';
|
||||
$utm_medium = 'Builder Settings';
|
||||
|
||||
$blocks = [
|
||||
'country_filter' => [
|
||||
'logo' => WPFORMS_PLUGIN_URL . 'assets/images/anti-spam/country-filter.svg',
|
||||
'title' => __( 'Country Filter', 'wpforms-lite' ),
|
||||
'description' => __( 'Stop spam at its source. Allow or deny entries from specific countries.', 'wpforms-lite' ),
|
||||
'link' => wpforms_utm_link( $upgrade_url, $utm_medium, 'Country Filter Feature' ),
|
||||
'link_text' => $upgrade_to_pro_text,
|
||||
'class' => 'wpforms-panel-content-also-available-item-upgrade-to-pro',
|
||||
'show' => ! wpforms()->is_pro(),
|
||||
],
|
||||
'keyword_filter' => [
|
||||
'logo' => WPFORMS_PLUGIN_URL . 'assets/images/anti-spam/keyword-filter.svg',
|
||||
'title' => __( 'Keyword Filter', 'wpforms-lite' ),
|
||||
'description' => __( 'Block form entries that contain specific words or phrases that you define.', 'wpforms-lite' ),
|
||||
'link' => wpforms_utm_link( $upgrade_url, $utm_medium, 'Keyword Filter Feature' ),
|
||||
'link_text' => $upgrade_to_pro_text,
|
||||
'class' => 'wpforms-panel-content-also-available-item-upgrade-to-pro',
|
||||
'show' => ! wpforms()->is_pro(),
|
||||
],
|
||||
'custom_captcha' => [
|
||||
'logo' => WPFORMS_PLUGIN_URL . 'assets/images/anti-spam/custom-captcha.svg',
|
||||
'title' => __( 'Custom Captcha', 'wpforms-lite' ),
|
||||
'description' => __( 'Ask custom questions or require your visitor to answer a random math puzzle.', 'wpforms-lite' ),
|
||||
'link' => wpforms()->is_pro() ? '#' : wpforms_utm_link( $upgrade_url, $utm_medium, 'Custom Captcha Addon' ),
|
||||
'link_text' => wpforms()->is_pro() ? __( 'Add to Form', 'wpforms-lite' ) : $upgrade_to_pro_text,
|
||||
'class' => wpforms()->is_pro() ? 'wpforms-panel-content-also-available-item-add-captcha' : 'wpforms-panel-content-also-available-item-upgrade-to-pro',
|
||||
'show' => true,
|
||||
],
|
||||
'reCAPTCHA' => [
|
||||
'logo' => WPFORMS_PLUGIN_URL . 'assets/images/anti-spam/recaptcha.svg',
|
||||
'title' => 'reCAPTCHA',
|
||||
'description' => __( 'Add Google\'s free anti-spam service and choose between visible or invisible CAPTCHAs.','wpforms-lite' ),
|
||||
'link' => wpforms_utm_link( 'https://wpforms.com/docs/how-to-set-up-and-use-recaptcha-in-wpforms/', $utm_medium, 'reCAPTCHA Feature' ),
|
||||
'link_text' => $get_started_button_text,
|
||||
'show' => $captcha_settings['provider'] !== 'recaptcha' || empty( wpforms_setting( 'captcha-provider' ) ),
|
||||
],
|
||||
'hCaptcha' => [
|
||||
'logo' => WPFORMS_PLUGIN_URL . 'assets/images/anti-spam/hcaptcha.svg',
|
||||
'title' => 'hCaptcha',
|
||||
'description' => __( 'Turn on free, privacy-oriented spam prevention that displays a visual CAPTCHA.','wpforms-lite' ),
|
||||
'link' => wpforms_utm_link( 'https://wpforms.com/docs/how-to-set-up-and-use-hcaptcha-in-wpforms/', $utm_medium, 'hCaptcha Feature' ),
|
||||
'link_text' => $get_started_button_text,
|
||||
'show' => $captcha_settings['provider'] !== 'hcaptcha',
|
||||
],
|
||||
'turnstile' => [
|
||||
'logo' => WPFORMS_PLUGIN_URL . 'assets/images/anti-spam/cloudflare.svg',
|
||||
'title' => 'Cloudflare Turnstile',
|
||||
'description' => __( 'Enable free, CAPTCHA-like spam protection that protects data privacy.','wpforms-lite' ),
|
||||
'link' => wpforms_utm_link( 'https://wpforms.com/docs/setting-up-cloudflare-turnstile/', $utm_medium, 'Cloudflare Turnstile Feature' ),
|
||||
'link_text' => $get_started_button_text,
|
||||
'show' => $captcha_settings['provider'] !== 'turnstile',
|
||||
],
|
||||
'akismet' => [
|
||||
'logo' => WPFORMS_PLUGIN_URL . 'assets/images/anti-spam/akismet.svg',
|
||||
'title' => 'Akismet',
|
||||
'description' => __( 'Integrate the powerful spam-fighting service trusted by millions of sites.','wpforms-lite' ),
|
||||
'link' => wpforms_utm_link( 'https://wpforms.com/docs/setting-up-akismet-anti-spam-protection/', $utm_medium, 'Akismet Feature' ),
|
||||
'link_text' => $get_started_button_text,
|
||||
'show' => ! Akismet::is_installed(),
|
||||
],
|
||||
];
|
||||
|
||||
return wpforms_render(
|
||||
'builder/antispam/also-available',
|
||||
[ 'blocks' => $blocks ],
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
1351
wp-content/plugins/wpforms-lite/src/Admin/Builder/Help.php
Normal file
1351
wp-content/plugins/wpforms-lite/src/Admin/Builder/Help.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace WPForms\Admin\Builder;
|
||||
|
||||
use WPForms\Helpers\CacheBase;
|
||||
|
||||
/**
|
||||
* Form Builder Help Cache.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
class HelpCache extends CacheBase {
|
||||
|
||||
/**
|
||||
* Determine if the class is allowed to load.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function allow_load() {
|
||||
|
||||
if ( wp_doing_cron() || wpforms_doing_wp_cli() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ! wpforms_current_user_can( [ 'create_forms', 'edit_forms' ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return wpforms_is_admin_page( 'builder' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup settings and other things.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
protected function setup() {
|
||||
|
||||
return [
|
||||
'remote_source' => 'https://wpforms.com/wp-content/docs.json',
|
||||
'cache_file' => 'docs.json',
|
||||
/**
|
||||
* Allow modifying Help Docs cache TTL (time to live).
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param int $cache_ttl Cache TTL in seconds. Defaults to 1 week.
|
||||
*/
|
||||
'cache_ttl' => (int) apply_filters( 'wpforms_admin_builder_help_cache_ttl', WEEK_IN_SECONDS ),
|
||||
'update_action' => 'wpforms_builder_help_cache_update',
|
||||
];
|
||||
}
|
||||
}
|
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace WPForms\Admin\Builder\Notifications\Advanced;
|
||||
|
||||
use WPForms_Builder_Panel_Settings;
|
||||
use WPForms\Emails\Helpers;
|
||||
use WPForms\Admin\Education\Helpers as EducationHelpers;
|
||||
|
||||
/**
|
||||
* Email Template.
|
||||
* This class will register the Email Template field in the "Notification" → "Advanced" settings.
|
||||
* The Email Template field will allow users to override the default email template for a specific notification.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*/
|
||||
class EmailTemplate {
|
||||
|
||||
/**
|
||||
* Initialize class.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
$this->hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooks.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*/
|
||||
private function hooks() {
|
||||
|
||||
add_action( 'wpforms_builder_enqueues', [ $this, 'builder_assets' ] );
|
||||
add_action( 'wpforms_builder_print_footer_scripts', [ $this, 'builder_footer_scripts' ] );
|
||||
add_filter( 'wpforms_lite_admin_education_builder_notifications_advanced_settings_content', [ $this, 'settings' ], 5, 3 );
|
||||
add_filter( 'wpforms_pro_admin_builder_notifications_advanced_settings_content', [ $this, 'settings' ], 5, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue assets for the builder.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*/
|
||||
public function builder_assets() {
|
||||
|
||||
$min = wpforms_get_min_suffix();
|
||||
|
||||
wp_enqueue_script(
|
||||
'wpforms-builder-email-template',
|
||||
WPFORMS_PLUGIN_URL . "assets/js/components/admin/builder/email-template{$min}.js",
|
||||
[ 'jquery', 'jquery-confirm', 'wpforms-builder' ],
|
||||
WPFORMS_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'wpforms-builder-email-template',
|
||||
'wpforms_builder_email_template',
|
||||
[
|
||||
'is_pro' => wpforms()->is_pro(),
|
||||
'templates' => Helpers::get_email_template_choices( false ),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output Email Template modal.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*/
|
||||
public function builder_footer_scripts() {
|
||||
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo wpforms_render(
|
||||
'builder/notifications/email-template-modal',
|
||||
[
|
||||
'pro_badge' => ! wpforms()->is_pro() ? EducationHelpers::get_badge( 'Pro' ) : '',
|
||||
],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Email Template settings.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*
|
||||
* @param string $content Notification → Advanced content.
|
||||
* @param WPForms_Builder_Panel_Settings $settings Builder panel settings.
|
||||
* @param int $id Notification id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function settings( $content, $settings, $id ) {
|
||||
|
||||
// Retrieve email template choices and disabled choices.
|
||||
// A few of the email templates are only available in the Pro version and will be disabled for non-Pro users.
|
||||
// The disabled choices will be added to the select field with a "(Pro)" label appended to the name.
|
||||
list( $options, $disabled_options ) = $this->get_email_template_options();
|
||||
|
||||
// Add Email Template field.
|
||||
$content .= wpforms_panel_field(
|
||||
'select',
|
||||
'notifications',
|
||||
'template',
|
||||
$settings->form_data,
|
||||
esc_html__( 'Email Template', 'wpforms-lite' ),
|
||||
[
|
||||
'default' => '',
|
||||
'options' => $options,
|
||||
'disabled_options' => $disabled_options,
|
||||
'class' => 'wpforms-panel-field-email-template-wrap',
|
||||
'input_class' => 'wpforms-panel-field-email-template',
|
||||
'parent' => 'settings',
|
||||
'subsection' => $id,
|
||||
'after' => $this->get_template_modal_link_content(),
|
||||
'tooltip' => esc_html__( 'Override the default email template for this specific notification.', 'wpforms-lite' ),
|
||||
],
|
||||
false
|
||||
);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Email template choices.
|
||||
*
|
||||
* This function will return an array of email template choices and an array of disabled choices.
|
||||
* The disabled choices are templates that are only available in the Pro version.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_email_template_options() {
|
||||
|
||||
// Retrieve the available email template choices.
|
||||
$choices = Helpers::get_email_template_choices( false );
|
||||
|
||||
// If there are no templates or the choices are not an array, return empty arrays.
|
||||
if ( empty( $choices ) || ! is_array( $choices ) ) {
|
||||
return [ [], [] ];
|
||||
}
|
||||
|
||||
// Check if the Pro version is active.
|
||||
$is_pro = wpforms()->is_pro();
|
||||
|
||||
// Initialize arrays for options and disabled options.
|
||||
$options = [];
|
||||
$disabled_options = [];
|
||||
|
||||
// Iterate through the templates and build the $options array.
|
||||
foreach ( $choices as $key => $choice ) {
|
||||
$value = esc_attr( $key );
|
||||
$name = esc_html( $choice['name'] );
|
||||
$is_disabled = ! $is_pro && isset( $choice['is_pro'] ) && $choice['is_pro'];
|
||||
|
||||
// If the option is disabled for non-Pro users, add it to the disabled options array.
|
||||
if ( $is_disabled ) {
|
||||
$disabled_options[] = $value;
|
||||
}
|
||||
|
||||
// Build the $options array with appropriate labels.
|
||||
// Pro badge labels are not meant to be translated.
|
||||
$options[ $key ] = $is_disabled ? sprintf( '%s (Pro)', $name ) : $name;
|
||||
}
|
||||
|
||||
// Add an empty option to the beginning of the $options array.
|
||||
// This is a placeholder option that will be replaced with the default template name.
|
||||
$options = array_merge( [ '' => esc_html__( 'Default Template', 'wpforms-lite' ) ], $options );
|
||||
|
||||
// Return the options and disabled options arrays.
|
||||
return [ $options, $disabled_options ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Email template modal link content.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_template_modal_link_content() {
|
||||
|
||||
return wpforms_render( 'builder/notifications/email-template-link' );
|
||||
}
|
||||
}
|
120
wp-content/plugins/wpforms-lite/src/Admin/Builder/Shortcuts.php
Normal file
120
wp-content/plugins/wpforms-lite/src/Admin/Builder/Shortcuts.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace WPForms\Admin\Builder;
|
||||
|
||||
/**
|
||||
* Form Builder Keyboard Shortcuts modal content.
|
||||
*
|
||||
* @since 1.6.9
|
||||
*/
|
||||
class Shortcuts {
|
||||
|
||||
/**
|
||||
* Initialize class.
|
||||
*
|
||||
* @since 1.6.9
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
// Terminate initialization if not in builder.
|
||||
if ( ! wpforms_is_admin_page( 'builder' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooks.
|
||||
*
|
||||
* @since 1.6.9
|
||||
*/
|
||||
private function hooks() {
|
||||
|
||||
add_filter( 'wpforms_builder_strings', [ $this, 'builder_strings' ], 10, 2 );
|
||||
add_action( 'wpforms_admin_page', [ $this, 'output' ], 30 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shortcuts list.
|
||||
*
|
||||
* @since 1.6.9
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_list() {
|
||||
|
||||
return [
|
||||
'left' => [
|
||||
'ctrl s' => __( 'Save Form', 'wpforms-lite' ),
|
||||
'ctrl p' => __( 'Preview Form', 'wpforms-lite' ),
|
||||
'ctrl b' => __( 'Embed Form', 'wpforms-lite' ),
|
||||
'ctrl f' => __( 'Search Fields', 'wpforms-lite' ),
|
||||
],
|
||||
'right' => [
|
||||
'ctrl h' => __( 'Open Help', 'wpforms-lite' ),
|
||||
'ctrl t' => __( 'Toggle Sidebar', 'wpforms-lite' ),
|
||||
'ctrl e' => __( 'View Entries', 'wpforms-lite' ),
|
||||
'ctrl q' => __( 'Close Builder', 'wpforms-lite' ),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Form builder strings.
|
||||
*
|
||||
* @since 1.6.9
|
||||
*
|
||||
* @param array $strings Form Builder strings.
|
||||
* @param \WP_Post|bool $form Form object.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function builder_strings( $strings, $form ) {
|
||||
|
||||
$strings['shortcuts_modal_title'] = esc_html__( 'Keyboard Shortcuts', 'wpforms-lite' );
|
||||
$strings['shortcuts_modal_msg'] = esc_html__( 'Handy shortcuts for common actions in the builder.', 'wpforms-lite' );
|
||||
|
||||
return $strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and output shortcuts modal content as the wp.template.
|
||||
*
|
||||
* @since 1.6.9
|
||||
*/
|
||||
public function output() {
|
||||
|
||||
echo '
|
||||
<script type="text/html" id="tmpl-wpforms-builder-keyboard-shortcuts">
|
||||
<div class="wpforms-columns wpforms-columns-2">';
|
||||
|
||||
foreach ( $this->get_list() as $list ) {
|
||||
|
||||
echo "<ul class='wpforms-column'>";
|
||||
|
||||
foreach ( $list as $key => $label ) {
|
||||
|
||||
$key = explode( ' ', $key );
|
||||
|
||||
printf(
|
||||
'<li>
|
||||
%1$s
|
||||
<span>
|
||||
<i>%2$s</i><i>%3$s</i>
|
||||
</span>
|
||||
</li>',
|
||||
esc_html( $label ),
|
||||
esc_html( $key[0] ),
|
||||
esc_html( $key[1] )
|
||||
);
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</div>
|
||||
</script>';
|
||||
}
|
||||
}
|
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
namespace WPForms\Admin\Builder;
|
||||
|
||||
use WPForms\Helpers\CacheBase;
|
||||
use WPForms\Tasks\Actions\AsyncRequestTask;
|
||||
|
||||
/**
|
||||
* Single template cache handler.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
class TemplateSingleCache extends CacheBase {
|
||||
|
||||
/**
|
||||
* Template Id (hash).
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* License data (`key` and `type`).
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $license;
|
||||
|
||||
/**
|
||||
* Determine if the class is allowed to load.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function allow_load() {
|
||||
|
||||
$has_permissions = wpforms_current_user_can( [ 'create_forms', 'edit_forms' ] );
|
||||
$allowed_requests = wpforms_is_admin_ajax() || wpforms_is_admin_page( 'builder' ) || wpforms_is_admin_page( 'templates' );
|
||||
$allow = wp_doing_cron() || wpforms_doing_wp_cli() || ( $has_permissions && $allowed_requests );
|
||||
|
||||
// phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName
|
||||
/**
|
||||
* Whether to allow to load this class.
|
||||
*
|
||||
* @since 1.7.2
|
||||
*
|
||||
* @param bool $allow True or false.
|
||||
*/
|
||||
return (bool) apply_filters( 'wpforms_admin_builder_templatesinglecache_allow_load', $allow );
|
||||
// phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-initialize object with the particular template.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param string $template_id Template ID (hash).
|
||||
* @param array $license License data.
|
||||
*
|
||||
* @return TemplateSingleCache
|
||||
*/
|
||||
public function instance( $template_id, $license ) {
|
||||
|
||||
$this->id = $template_id;
|
||||
$this->license = $license;
|
||||
|
||||
$this->init();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide settings.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @return array Settings array.
|
||||
*/
|
||||
protected function setup() {
|
||||
|
||||
return [
|
||||
|
||||
// Remote source URL.
|
||||
'remote_source' => $this->remote_source(),
|
||||
|
||||
// Cache file.
|
||||
'cache_file' => $this->get_cache_file_name(),
|
||||
|
||||
// This filter is documented in wpforms/src/Admin/Builder/TemplatesCache.php.
|
||||
// phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName, WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
|
||||
'cache_ttl' => (int) apply_filters( 'wpforms_admin_builder_templates_cache_ttl', WEEK_IN_SECONDS ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate single template remote URL.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param bool $cache True if the cache arg should be appended to the URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function remote_source( $cache = false ) {
|
||||
|
||||
if ( ! isset( $this->license['key'] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$args = [
|
||||
'license' => $this->license['key'],
|
||||
'site' => site_url(),
|
||||
];
|
||||
|
||||
if ( $cache ) {
|
||||
$args['cache'] = 1;
|
||||
}
|
||||
|
||||
return add_query_arg(
|
||||
$args,
|
||||
'https://wpforms.com/templates/api/get/' . $this->id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cached data.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @return array Cached data.
|
||||
*/
|
||||
public function get() {
|
||||
|
||||
$data = parent::get();
|
||||
|
||||
if ( parent::$updated === false ) {
|
||||
$this->update_usage_tracking();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to update the form template usage tracking database.
|
||||
*
|
||||
* @since 1.7.5
|
||||
*/
|
||||
private function update_usage_tracking() {
|
||||
|
||||
$tasks = wpforms()->get( 'tasks' );
|
||||
|
||||
if ( ! $tasks ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url = $this->remote_source( true );
|
||||
$args = [ 'blocking' => false ];
|
||||
|
||||
$tasks->create( AsyncRequestTask::ACTION )->async()->params( $url, $args )->register();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache directory path.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
protected function get_cache_dir() {
|
||||
|
||||
return parent::get_cache_dir() . 'templates/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate single template cache file name.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
private function get_cache_file_name() {
|
||||
|
||||
return sanitize_key( $this->id ) . '.json';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare data to store in a local cache.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param array $data Raw data received by the remote request.
|
||||
*
|
||||
* @return array Prepared data for caching.
|
||||
*/
|
||||
protected function prepare_cache_data( $data ) {
|
||||
|
||||
if (
|
||||
empty( $data ) ||
|
||||
! is_array( $data ) ||
|
||||
empty( $data['status'] ) ||
|
||||
$data['status'] !== 'success' ||
|
||||
empty( $data['data'] )
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$cache_data = $data['data'];
|
||||
$cache_data['data'] = empty( $cache_data['data'] ) ? [] : $cache_data['data'];
|
||||
$cache_data['data']['settings'] = empty( $cache_data['data']['settings'] ) ? [] : $cache_data['data']['settings'];
|
||||
$cache_data['data']['settings']['ajax_submit'] = '1';
|
||||
|
||||
// Strip the word "Template" from the end of the template name and form title setting.
|
||||
$cache_data['name'] = preg_replace( '/\sTemplate$/', '', $cache_data['name'] );
|
||||
$cache_data['data']['settings']['form_title'] = $cache_data['name'];
|
||||
|
||||
// Unset `From Name` field of the notification settings.
|
||||
// By default, the builder will use the `blogname` option value.
|
||||
unset( $cache_data['data']['settings']['notifications'][1]['sender_name'] );
|
||||
|
||||
return $cache_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wipe cache of an empty templates.
|
||||
*
|
||||
* @since 1.7.5
|
||||
*/
|
||||
public function wipe_empty_templates_cache() {
|
||||
|
||||
$cache_dir = $this->get_cache_dir();
|
||||
$files = glob( $cache_dir . '*.json' );
|
||||
|
||||
foreach ( $files as $filename ) {
|
||||
$content = file_get_contents( $filename );
|
||||
|
||||
if ( empty( $content ) || trim( $content ) === '[]' ) {
|
||||
unlink( $filename );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
967
wp-content/plugins/wpforms-lite/src/Admin/Builder/Templates.php
Normal file
967
wp-content/plugins/wpforms-lite/src/Admin/Builder/Templates.php
Normal file
@@ -0,0 +1,967 @@
|
||||
<?php
|
||||
|
||||
namespace WPForms\Admin\Builder;
|
||||
|
||||
use WP_Query;
|
||||
|
||||
/**
|
||||
* Templates class.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
class Templates {
|
||||
|
||||
/**
|
||||
* All templates data from API.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $api_templates;
|
||||
|
||||
/**
|
||||
* Template categories data.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $categories;
|
||||
|
||||
/**
|
||||
* Template subcategories data.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $subcategories;
|
||||
|
||||
/**
|
||||
* License data.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $license;
|
||||
|
||||
/**
|
||||
* All licenses list.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $all_licenses;
|
||||
|
||||
/**
|
||||
* Favorite templates option.
|
||||
*
|
||||
* @since 1.7.7
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const FAVORITE_TEMPLATES_OPTION = 'wpforms_favorite_templates';
|
||||
|
||||
/**
|
||||
* Determine if the class is allowed to load.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function allow_load() {
|
||||
|
||||
$has_permissions = wpforms_current_user_can( [ 'create_forms', 'edit_forms' ] );
|
||||
$allowed_requests = wpforms_is_admin_ajax() || wpforms_is_admin_page( 'builder' ) || wpforms_is_admin_page( 'templates' );
|
||||
$allow = $has_permissions && $allowed_requests;
|
||||
|
||||
/**
|
||||
* Whether to allow the form templates functionality to load.
|
||||
*
|
||||
* @since 1.7.2
|
||||
*
|
||||
* @param bool $allow True or false.
|
||||
*/
|
||||
return (bool) apply_filters( 'wpforms_admin_builder_templates_allow_load', $allow );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize class.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
if ( ! $this->allow_load() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->init_license_data();
|
||||
$this->init_templates_data();
|
||||
$this->hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooks.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
protected function hooks() {
|
||||
|
||||
add_action( 'admin_init', [ $this, 'create_form_on_request' ], 100 );
|
||||
add_filter( 'wpforms_form_templates_core', [ $this, 'add_templates_to_setup_panel' ], 20 );
|
||||
add_filter( 'wpforms_create_form_args', [ $this, 'apply_to_new_form' ], 10, 2 );
|
||||
add_filter( 'wpforms_save_form_args', [ $this, 'apply_to_existing_form' ], 10, 3 );
|
||||
add_action( 'admin_print_scripts', [ $this, 'upgrade_banner_template' ] );
|
||||
add_action( 'admin_enqueue_scripts', [ $this, 'enqueues' ] );
|
||||
add_action( 'wp_ajax_wpforms_templates_favorite', [ $this, 'ajax_save_favorites' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue assets for the Setup panel.
|
||||
*
|
||||
* @since 1.7.7
|
||||
*/
|
||||
public function enqueues() {
|
||||
|
||||
$min = wpforms_get_min_suffix();
|
||||
|
||||
wp_enqueue_script(
|
||||
'listjs',
|
||||
WPFORMS_PLUGIN_URL . 'assets/lib/list.min.js',
|
||||
[ 'jquery' ],
|
||||
'2.3.0'
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'wpforms-form-templates',
|
||||
WPFORMS_PLUGIN_URL . "assets/js/components/admin/form-templates{$min}.js",
|
||||
[ 'listjs' ],
|
||||
WPFORMS_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
$strings = [
|
||||
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
||||
'admin_nonce' => wp_create_nonce( 'wpforms-admin' ),
|
||||
'nonce' => wp_create_nonce( 'wpforms-form-templates' ),
|
||||
'can_install_addons' => wpforms_can_install( 'addon' ),
|
||||
'activating' => esc_html__( 'Activating', 'wpforms-lite' ),
|
||||
'cancel' => esc_html__( 'Cancel', 'wpforms-lite' ),
|
||||
'heads_up' => esc_html__( 'Heads Up!', 'wpforms-lite' ),
|
||||
'install_confirm' => esc_html__( 'Yes, install and activate', 'wpforms-lite' ),
|
||||
'ok' => esc_html__( 'Ok', 'wpforms-lite' ),
|
||||
'template_addons_error' => esc_html__( 'Could not install OR activate all the required addons. Please download from wpforms.com and install them manually. Would you like to use the template anyway?', 'wpforms-lite' ),
|
||||
'use_template' => esc_html__( 'Yes, use template', 'wpforms-lite' ),
|
||||
];
|
||||
|
||||
if ( $strings['can_install_addons'] ) {
|
||||
/* translators: %1$s - template name, %2$s - addon name(s). */
|
||||
$strings['template_addon_prompt'] = esc_html( sprintf( __( 'The %1$s template requires the %2$s. Would you like to install and activate it?', 'wpforms-lite' ), '%template%', '%addons%' ) );
|
||||
/* translators: %1$s - template name, %2$s - addon name(s). */
|
||||
$strings['template_addons_prompt'] = esc_html( sprintf( __( 'The %1$s template requires the %2$s. Would you like to install and activate all the required addons?', 'wpforms-lite' ), '%template%', '%addons%' ) );
|
||||
} else {
|
||||
/* translators: %s - addon name(s). */
|
||||
$strings['template_addon_prompt'] = esc_html( sprintf( __( "To use all of the features in this template, you'll need the %s. Contact your site administrator to install it, then try opening this template again.", 'wpforms-lite' ), '%addons%' ) );
|
||||
/* translators: %s - addon name(s). */
|
||||
$strings['template_addons_prompt'] = esc_html( sprintf( __( "To use all of the features in this template, you'll need the %s. Contact your site administrator to install them, then try opening this template again.", 'wpforms-lite' ), '%addons%' ) );
|
||||
}
|
||||
|
||||
wp_localize_script(
|
||||
'wpforms-form-templates',
|
||||
'wpforms_form_templates',
|
||||
$strings
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'wpforms-form-templates',
|
||||
'wpforms_addons',
|
||||
$this->get_localized_addons()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get localized addons.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_localized_addons() {
|
||||
|
||||
return wpforms_chain( wpforms()->get( 'addons' )->get_available() )
|
||||
->map(
|
||||
static function( $addon ) {
|
||||
|
||||
return [
|
||||
'title' => $addon['title'],
|
||||
'action' => $addon['action'],
|
||||
'url' => $addon['url'],
|
||||
];
|
||||
}
|
||||
)
|
||||
->value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Init license data.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
private function init_license_data() {
|
||||
|
||||
$this->all_licenses = [ 'lite', 'basic', 'plus', 'pro', 'elite', 'agency', 'ultimate' ];
|
||||
|
||||
// User license data.
|
||||
$this->license['key'] = wpforms_get_license_key();
|
||||
$this->license['type'] = wpforms_get_license_type();
|
||||
$this->license['type'] = in_array( $this->license['type'], [ 'agency', 'ultimate' ], true ) ? 'elite' : $this->license['type'];
|
||||
$this->license['type'] = empty( $this->license['type'] ) ? 'lite' : $this->license['type'];
|
||||
$this->license['index'] = array_search( $this->license['type'], $this->all_licenses, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init templates and categories data.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
private function init_templates_data() {
|
||||
|
||||
// Get cached templates data.
|
||||
$cache_data = wpforms()->get( 'builder_templates_cache' )->get();
|
||||
$templates_all = ! empty( $cache_data['templates'] ) ? $this->sort_templates_by_created_at( $cache_data['templates'] ) : [];
|
||||
$this->categories = ! empty( $cache_data['categories'] ) ? $cache_data['categories'] : [];
|
||||
$this->subcategories = ! empty( $cache_data['subcategories'] ) ? $cache_data['subcategories'] : [];
|
||||
|
||||
// Higher priority templates slugs.
|
||||
// These remote templates are the replication of the default templates,
|
||||
// which were previously included with the WPForms plugin.
|
||||
$higher_templates_slugs = [
|
||||
'simple-contact-form-template',
|
||||
'request-a-quote-form-template',
|
||||
'donation-form-template',
|
||||
'billing-order-form-template',
|
||||
'newsletter-signup-form-template',
|
||||
'suggestion-form-template',
|
||||
];
|
||||
|
||||
$templates_higher = [];
|
||||
$templates_access = [];
|
||||
$templates_denied = [];
|
||||
|
||||
/**
|
||||
* The form template was moved to wpforms/includes/templates/class-simple-contact-form.php file.
|
||||
*
|
||||
* @since 1.7.5.3
|
||||
*/
|
||||
unset( $templates_all['simple-contact-form-template'] );
|
||||
|
||||
foreach ( $templates_all as $i => $template ) {
|
||||
$template['has_access'] = $this->has_access( $template );
|
||||
$template['favorite'] = $this->is_favorite( $i );
|
||||
$template['license'] = $this->get_license_level( $template );
|
||||
$template['source'] = 'wpforms-api';
|
||||
$template['categories'] = ! empty( $template['categories'] ) ? array_keys( $template['categories'] ) : [];
|
||||
|
||||
$is_higher = in_array( $i, $higher_templates_slugs, true );
|
||||
|
||||
if ( $template['has_access'] ) {
|
||||
|
||||
if ( $is_higher ) {
|
||||
$templates_higher[ $i ] = $template;
|
||||
} else {
|
||||
$templates_access[ $i ] = $template;
|
||||
}
|
||||
} else {
|
||||
|
||||
if ( $is_higher ) {
|
||||
$templates_denied = array_merge( [ $i => $template ], $templates_denied );
|
||||
} else {
|
||||
$templates_denied[ $i ] = $template;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort higher priority templates according to the slugs order.
|
||||
$templates_higher = array_replace( array_flip( $higher_templates_slugs ), $templates_higher );
|
||||
$templates_higher = array_filter( $templates_higher, 'is_array' );
|
||||
|
||||
// Finally, merge templates from API.
|
||||
$this->api_templates = array_merge( $templates_higher, $templates_access, $templates_denied );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort templates by their created_at value in ascending order.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param array $templates Templates to be sorted.
|
||||
*
|
||||
* @return array Sorted templates.
|
||||
*/
|
||||
private function sort_templates_by_created_at( array $templates ): array {
|
||||
|
||||
uasort(
|
||||
$templates,
|
||||
static function ( $template_a, $template_b ) {
|
||||
|
||||
if ( $template_a['created_at'] === $template_b['created_at'] ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $template_a['created_at'] < $template_b['created_at'] ? -1 : 1;
|
||||
}
|
||||
);
|
||||
|
||||
return $templates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if user's license level has access to the template.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param array $template Template data.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function has_access( $template ) {
|
||||
|
||||
if ( ! empty( $template['has_access'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$template_licenses = empty( $template['license'] ) ? [] : array_map( 'strtolower', (array) $template['license'] );
|
||||
$has_access = true;
|
||||
|
||||
foreach ( $template_licenses as $template_license ) {
|
||||
|
||||
$has_access = $this->license['index'] >= array_search( $template_license, $this->all_licenses, true );
|
||||
|
||||
if ( $has_access ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $has_access;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get favorites templates list.
|
||||
*
|
||||
* @since 1.7.7
|
||||
*
|
||||
* @param bool $all Optional. True for getting all favorites lists. False by default.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_favorites_list( $all = false ) {
|
||||
|
||||
$favorites_list = (array) get_option( self::FAVORITE_TEMPLATES_OPTION, [] );
|
||||
|
||||
if ( $all ) {
|
||||
return $favorites_list;
|
||||
}
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
return isset( $favorites_list[ $user_id ] ) ? $favorites_list[ $user_id ] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if template is marked as favorite.
|
||||
*
|
||||
* @since 1.7.7
|
||||
*
|
||||
* @param string $template_slug Template slug.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_favorite( $template_slug ) {
|
||||
|
||||
static $favorites;
|
||||
|
||||
if ( ! $favorites ) {
|
||||
$favorites = $this->get_favorites_list();
|
||||
}
|
||||
|
||||
return isset( $favorites[ $template_slug ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save favorites templates.
|
||||
*
|
||||
* @since 1.7.7
|
||||
*/
|
||||
public function ajax_save_favorites() {
|
||||
|
||||
if ( ! check_ajax_referer( 'wpforms-form-templates', 'nonce', false ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
if ( ! isset( $_POST['slug'], $_POST['favorite'] ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$favorites = $this->get_favorites_list( true );
|
||||
$user_id = get_current_user_id();
|
||||
$template_slug = sanitize_text_field( wp_unslash( $_POST['slug'] ) );
|
||||
$is_favorite = sanitize_key( $_POST['favorite'] ) === 'true';
|
||||
$is_exists = isset( $favorites[ $user_id ][ $template_slug ] );
|
||||
|
||||
if ( $is_favorite && $is_exists ) {
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
if ( $is_favorite ) {
|
||||
$favorites[ $user_id ][ $template_slug ] = true;
|
||||
} elseif ( $is_exists ) {
|
||||
unset( $favorites[ $user_id ][ $template_slug ] );
|
||||
}
|
||||
|
||||
update_option( self::FAVORITE_TEMPLATES_OPTION, $favorites );
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the template exists and the customer has access to it.
|
||||
*
|
||||
* @since 1.7.5.3
|
||||
*
|
||||
* @param string $slug Template slug or ID.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_valid_template( $slug ) {
|
||||
|
||||
$template = $this->get_template_by_id( $slug );
|
||||
|
||||
if ( ! $template ) {
|
||||
return ! empty( $this->get_template_by_slug( $slug ) );
|
||||
}
|
||||
|
||||
$has_cache = wpforms()->get( 'builder_template_single' )->instance( $template['id'], $this->license )->get();
|
||||
|
||||
return $this->has_access( $template ) && $has_cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine license level of the template.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param array $template Template data.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_license_level( $template ) {
|
||||
|
||||
$licenses_pro = [ 'basic', 'plus', 'pro' ];
|
||||
$licenses_template = (array) $template['license'];
|
||||
|
||||
if (
|
||||
empty( $template['license'] ) ||
|
||||
in_array( 'lite', $licenses_template, true )
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
foreach ( $licenses_pro as $license ) {
|
||||
if ( in_array( $license, $licenses_template, true ) ) {
|
||||
return 'pro';
|
||||
}
|
||||
}
|
||||
|
||||
return 'elite';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories data.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_categories() {
|
||||
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subcategories data.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_subcategories() {
|
||||
|
||||
return $this->subcategories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get templates data.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_templates() {
|
||||
|
||||
static $templates = [];
|
||||
|
||||
if ( ! empty( $templates ) ) {
|
||||
return $templates;
|
||||
}
|
||||
|
||||
// phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName
|
||||
|
||||
/**
|
||||
* Form templates available in the WPForms core plugin.
|
||||
*
|
||||
* @since 1.4.0
|
||||
*
|
||||
* @param array $templates Core templates data.
|
||||
*/
|
||||
$core_templates = (array) apply_filters( 'wpforms_form_templates_core', [] );
|
||||
|
||||
/**
|
||||
* Form templates available with the WPForms addons.
|
||||
* Allows developers to provide additional templates with an addons.
|
||||
*
|
||||
* @since 1.4.0
|
||||
*
|
||||
* @param array $templates Addons templates data.
|
||||
*/
|
||||
$additional_templates = (array) apply_filters( 'wpforms_form_templates', [] );
|
||||
|
||||
// phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName
|
||||
|
||||
$templates = array_merge( $core_templates, $additional_templates );
|
||||
|
||||
return $templates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single template data.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param string $slug Template slug OR Id.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_template( $slug ) {
|
||||
|
||||
$template = $this->get_template_by_slug( $slug );
|
||||
|
||||
if ( ! $template ) {
|
||||
$template = $this->get_template_by_id( $slug );
|
||||
}
|
||||
|
||||
if ( empty( $template ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ( empty( $template['id'] ) ) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
// Attempt to get template with form data (if available).
|
||||
$full_template = wpforms()
|
||||
->get( 'builder_template_single' )
|
||||
->instance( $template['id'], $this->license )
|
||||
->get();
|
||||
|
||||
if ( ! empty( $full_template['data'] ) ) {
|
||||
return $full_template;
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template data by slug.
|
||||
*
|
||||
* @since 1.7.5.3
|
||||
*
|
||||
* @param string $slug Template slug.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_template_by_slug( $slug ) {
|
||||
|
||||
foreach ( $this->get_templates() as $template ) {
|
||||
if ( ! empty( $template['slug'] ) && $template['slug'] === $slug ) {
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template data by Id.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param string $id Template id.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_template_by_id( $id ) {
|
||||
|
||||
foreach ( $this->api_templates as $template ) {
|
||||
if ( ! empty( $template['id'] ) && $template['id'] === $id ) {
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add templates to the list on the Setup panel.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param array $templates Templates list.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_templates_to_setup_panel( $templates ) {
|
||||
|
||||
return array_merge( $templates, $this->api_templates );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add template data when form is created.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param array $args Create form arguments.
|
||||
* @param array $data Template data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function apply_to_new_form( $args, $data ) {
|
||||
|
||||
if ( empty( $data ) || empty( $data['template'] ) ) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
$template = $this->get_template( $data['template'] );
|
||||
|
||||
if (
|
||||
empty( $template['data'] ) ||
|
||||
! $this->has_access( $template )
|
||||
) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
$template['data']['meta']['template'] = $template['id'];
|
||||
|
||||
// Enable Notifications by default.
|
||||
$template['data']['settings']['notification_enable'] = isset( $template['data']['settings']['notification_enable'] )
|
||||
? $template['data']['settings']['notification_enable']
|
||||
: 1;
|
||||
|
||||
// Unset settings that should be defined locally.
|
||||
unset(
|
||||
$template['data']['settings']['form_title'],
|
||||
$template['data']['settings']['conversational_forms_title'],
|
||||
$template['data']['settings']['form_pages_title']
|
||||
);
|
||||
|
||||
// Unset certain values for each Notification, since:
|
||||
// - Email Subject Line field (subject) depends on the form name that is generated from the template name and form_id.
|
||||
// - From Name field (sender_name) depends on the blog name and can be replaced by WP Mail SMTP plugin.
|
||||
// - From Email field (sender_address) depends on the internal logic and can be replaced by WP Mail SMTP plugin.
|
||||
if ( ! empty( $template['data']['settings']['notifications'] ) ) {
|
||||
foreach ( (array) $template['data']['settings']['notifications'] as $key => $notification ) {
|
||||
unset(
|
||||
$template['data']['settings']['notifications'][ $key ]['subject'],
|
||||
$template['data']['settings']['notifications'][ $key ]['sender_name'],
|
||||
$template['data']['settings']['notifications'][ $key ]['sender_address']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Encode template data to post content.
|
||||
$args['post_content'] = wpforms_encode( $template['data'] );
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add template data when form is updated.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param array $form Form post data.
|
||||
* @param array $data Form data.
|
||||
* @param array $args Update form arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function apply_to_existing_form( $form, $data, $args ) {
|
||||
|
||||
if ( empty( $args ) || empty( $args['template'] ) ) {
|
||||
return $form;
|
||||
}
|
||||
|
||||
$template = $this->get_template( $args['template'] );
|
||||
|
||||
if (
|
||||
empty( $template['data'] ) ||
|
||||
! $this->has_access( $template )
|
||||
) {
|
||||
return $form;
|
||||
}
|
||||
|
||||
$form_data = wpforms_decode( wp_unslash( $form['post_content'] ) );
|
||||
|
||||
// Something is wrong with the form data.
|
||||
if ( empty( $form_data ) ) {
|
||||
return $form;
|
||||
}
|
||||
|
||||
// Compile the new form data preserving needed data from the existing form.
|
||||
$new = $template['data'];
|
||||
$new['id'] = isset( $form['ID'] ) ? $form['ID'] : 0;
|
||||
$new['field_id'] = isset( $form_data['field_id'] ) ? $form_data['field_id'] : 0;
|
||||
$new['settings'] = isset( $form_data['settings'] ) ? $form_data['settings'] : [];
|
||||
$new['payments'] = isset( $form_data['payments'] ) ? $form_data['payments'] : [];
|
||||
$new['meta'] = isset( $form_data['meta'] ) ? $form_data['meta'] : [];
|
||||
$new['meta']['template'] = $template['id'];
|
||||
|
||||
/**
|
||||
* Allow modifying form data when a new template is applied.
|
||||
*
|
||||
* @since 1.7.9
|
||||
*
|
||||
* @param array $new Updated form data.
|
||||
* @param array $form_data Current form data.
|
||||
* @param array $template Template data.
|
||||
*/
|
||||
$new = (array) apply_filters( 'wpforms_admin_builder_templates_apply_to_existing_form_modify_data', $new, $form_data, $template );
|
||||
|
||||
// Update the form with new data.
|
||||
$form['post_content'] = wpforms_encode( $new );
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a form on request.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
public function create_form_on_request() {
|
||||
|
||||
$template = $this->get_template_on_request();
|
||||
|
||||
// Just return if template not found OR user doesn't have access.
|
||||
if ( empty( $template['has_access'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the template requires some addons.
|
||||
if ( $this->check_template_required_addons( $template ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set form title equal to the template's name.
|
||||
$form_title = ! empty( $template['name'] ) ? $template['name'] : esc_html__( 'New form', 'wpforms-lite' );
|
||||
$title_query = new WP_Query(
|
||||
[
|
||||
'post_type' => 'wpforms',
|
||||
'title' => $form_title,
|
||||
'posts_per_page' => 1,
|
||||
'fields' => 'ids',
|
||||
'update_post_meta_cache' => false,
|
||||
'update_post_term_cache' => false,
|
||||
'no_found_rows' => true,
|
||||
]
|
||||
);
|
||||
$title_exists = $title_query->post_count > 0;
|
||||
$form_id = wpforms()->get( 'form' )->add(
|
||||
$form_title,
|
||||
[],
|
||||
[
|
||||
'template' => $template['id'],
|
||||
]
|
||||
);
|
||||
|
||||
// Return if something wrong.
|
||||
if ( ! $form_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update form title if duplicated.
|
||||
if ( $title_exists ) {
|
||||
wpforms()->get( 'form' )->update(
|
||||
$form_id,
|
||||
[
|
||||
'settings' => [
|
||||
'form_title' => $form_title . ' (ID #' . $form_id . ')',
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$this->create_form_on_request_redirect( $form_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template data before creating a new form on request.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @return array|bool Template OR false.
|
||||
*/
|
||||
private function get_template_on_request() {
|
||||
|
||||
if ( ! wpforms_is_admin_page( 'builder' ) || ! wpforms_is_admin_page( 'templates' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! wpforms_current_user_can( 'create_forms' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$form_id = isset( $_GET['form_id'] ) ? (int) $_GET['form_id'] : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
if ( ! empty( $form_id ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$view = isset( $_GET['view'] ) ? sanitize_key( $_GET['view'] ) : 'setup'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
if ( $view !== 'setup' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$template_id = isset( $_GET['template_id'] ) ? sanitize_key( $_GET['template_id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
// Attempt to get the template.
|
||||
$template = $this->get_template( $template_id );
|
||||
|
||||
// Just return if template is not found.
|
||||
if ( empty( $template ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect after creating the form.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param integer $form_id Form ID.
|
||||
*/
|
||||
private function create_form_on_request_redirect( $form_id ) {
|
||||
|
||||
// Redirect to the builder if possible.
|
||||
if ( wpforms_current_user_can( 'edit_form_single', $form_id ) ) {
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
[
|
||||
'view' => 'fields',
|
||||
'form_id' => $form_id,
|
||||
'newform' => '1',
|
||||
],
|
||||
admin_url( 'admin.php?page=wpforms-builder' )
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Redirect to the forms overview admin page if possible.
|
||||
if ( wpforms_current_user_can( 'view_forms' ) ) {
|
||||
wp_safe_redirect(
|
||||
admin_url( 'admin.php?page=wpforms-overview' )
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Finally, redirect to the admin dashboard.
|
||||
wp_safe_redirect( admin_url() );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the template requires some addons and then redirect to the builder for further interaction if needed.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param array $template Template data.
|
||||
*
|
||||
* @return bool True if template requires some addons that are not yet installed and/or activated.
|
||||
*/
|
||||
private function check_template_required_addons( $template ) {
|
||||
|
||||
// Return false if none addons required.
|
||||
if ( empty( $template['addons'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$required_addons = wpforms()->get( 'addons' )->get_by_slugs( $template['addons'] );
|
||||
|
||||
foreach ( $required_addons as $i => $addon ) {
|
||||
if ( empty( $addon['action'] ) || ! in_array( $addon['action'], [ 'install', 'activate' ], true ) ) {
|
||||
unset( $required_addons[ $i ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Return false if not need to install or activate any addons.
|
||||
// We can proceed with creating the form directly in this process.
|
||||
if ( empty( $required_addons ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template for upgrade banner.
|
||||
*
|
||||
* @since 1.7.7
|
||||
*/
|
||||
public function upgrade_banner_template() {
|
||||
|
||||
if ( in_array( wpforms_get_license_type(), [ 'pro', 'elite', 'agency', 'ultimate' ], true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$medium = wpforms_is_admin_page( 'templates' ) ? 'Form Templates Subpage' : 'Builder Templates';
|
||||
?>
|
||||
<script type="text/html" id="tmpl-wpforms-templates-upgrade-banner">
|
||||
<div class="wpforms-template-upgrade-banner">
|
||||
<div class="wpforms-template-content">
|
||||
<h3>
|
||||
<?php
|
||||
/* translators: %d - templates count. */
|
||||
printf( esc_html__( 'Get Access to Our Library of %d Pre-Made Form Templates', 'wpforms-lite' ), count( $this->get_templates() ) );
|
||||
?>
|
||||
</h3>
|
||||
|
||||
<p>
|
||||
<?php esc_html_e( 'Never start from scratch again! While WPForms Lite allows you to create any type of form, you can save even more time with WPForms Pro. Upgrade to access hundreds more form templates and advanced form fields.', 'wpforms-lite' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
<div class="wpforms-template-upgrade-button">
|
||||
<a href="<?php echo esc_url( wpforms_admin_upgrade_link( $medium, 'Upgrade to Pro' ) ); ?>" class="wpforms-btn wpforms-btn-orange wpforms-btn-md" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Upgrade to PRO', 'wpforms-lite' ); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace WPForms\Admin\Builder;
|
||||
|
||||
use WPForms\Helpers\CacheBase;
|
||||
|
||||
/**
|
||||
* Form templates cache handler.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*/
|
||||
class TemplatesCache extends CacheBase {
|
||||
|
||||
/**
|
||||
* Determine if the class is allowed to load.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function allow_load() {
|
||||
|
||||
$has_permissions = wpforms_current_user_can( [ 'create_forms', 'edit_forms' ] );
|
||||
$allowed_requests = wpforms_is_admin_ajax() || wpforms_is_admin_page( 'builder' ) || wpforms_is_admin_page( 'templates' );
|
||||
$allow = wp_doing_cron() || wpforms_doing_wp_cli() || ( $has_permissions && $allowed_requests );
|
||||
|
||||
/**
|
||||
* Whether to load this class.
|
||||
*
|
||||
* @since 1.7.2
|
||||
*
|
||||
* @param bool $allow True or false.
|
||||
*/
|
||||
return (bool) apply_filters( 'wpforms_admin_builder_templatescache_allow_load', $allow ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide settings.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @return array Settings array.
|
||||
*/
|
||||
protected function setup() {
|
||||
|
||||
return [
|
||||
|
||||
// Remote source URL.
|
||||
'remote_source' => 'https://wpforms.com/templates/api/get/',
|
||||
|
||||
// Cache file.
|
||||
'cache_file' => 'templates.json',
|
||||
|
||||
/**
|
||||
* Time-to-live of the templates cache files in seconds.
|
||||
*
|
||||
* This applies to `uploads/wpforms/cache/templates.json`
|
||||
* and all *.json files in `uploads/wpforms/cache/templates/` directory.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param integer $cache_ttl Cache time-to-live, in seconds.
|
||||
* Default value: WEEK_IN_SECONDS.
|
||||
*/
|
||||
'cache_ttl' => (int) apply_filters( 'wpforms_admin_builder_templates_cache_ttl', WEEK_IN_SECONDS ),
|
||||
|
||||
// Scheduled update action.
|
||||
'update_action' => 'wpforms_admin_builder_templates_cache_update',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare data to store in a local cache.
|
||||
*
|
||||
* @since 1.6.8
|
||||
*
|
||||
* @param array $data Raw data received by the remote request.
|
||||
*
|
||||
* @return array Prepared data for caching.
|
||||
*/
|
||||
protected function prepare_cache_data( $data ) {
|
||||
|
||||
if (
|
||||
empty( $data ) ||
|
||||
! is_array( $data ) ||
|
||||
empty( $data['status'] ) ||
|
||||
$data['status'] !== 'success' ||
|
||||
empty( $data['data'] )
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$cache_data = $data['data'];
|
||||
|
||||
// Strip the word "Template" from the end of each template name.
|
||||
foreach ( $cache_data['templates'] as $slug => $template ) {
|
||||
$cache_data['templates'][ $slug ]['name'] = preg_replace( '/\sTemplate$/', '', $template['name'] );
|
||||
}
|
||||
|
||||
return $cache_data;
|
||||
}
|
||||
}
|
@@ -0,0 +1,580 @@
|
||||
<?php
|
||||
|
||||
namespace WPForms\Admin\Builder\Traits;
|
||||
|
||||
/**
|
||||
* Trait ContentInput.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*/
|
||||
trait ContentInput {
|
||||
|
||||
/**
|
||||
* Translatable strings.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @var null|array Translatable strings.
|
||||
*/
|
||||
private static $translatable_strings;
|
||||
|
||||
/**
|
||||
* Constructor overloader to register trait specific hooks.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param bool $init Pass false to allow to shortcut the whole initialization, if needed.
|
||||
*/
|
||||
public function __construct( $init = true ) {
|
||||
|
||||
if ( ! $init ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->content_input_hooks();
|
||||
parent::__construct( $init );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hooks.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*/
|
||||
private function content_input_hooks() {
|
||||
|
||||
add_action( 'wpforms_builder_enqueues', [ $this, 'builder_enqueues' ] );
|
||||
add_action( 'wpforms_builder_print_footer_scripts', [ $this, 'content_editor_tools_template' ] );
|
||||
add_filter( 'wpforms_builder_field_option_class', [ $this, 'builder_field_option_class' ], 10, 2 );
|
||||
add_filter( 'wpforms_builder_strings', [ $this, 'content_builder_strings' ], 10, 2 );
|
||||
add_filter( 'editor_stylesheets', [ $this, 'editor_stylesheets' ] );
|
||||
add_filter( 'media_view_strings', [ $this, 'edit_media_view_strings' ], 10, 2 );
|
||||
add_filter( 'teeny_mce_buttons', [ $this, 'teeny_mce_buttons' ], 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Content field option.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param array $field Field data and settings.
|
||||
*/
|
||||
private function field_option_content( array $field ) {
|
||||
|
||||
$value = ( isset( $field['content'] ) && ! wpforms_is_empty_string( $field['content'] ) ) ? wp_kses( $field['content'], $this->get_allowed_html_tags() ) : '';
|
||||
$output = $this->field_element(
|
||||
'row',
|
||||
$field,
|
||||
[
|
||||
'slug' => 'content',
|
||||
'content' => $this->get_content_editor( $value, $field ),
|
||||
],
|
||||
false
|
||||
);
|
||||
$output .= wpforms_render(
|
||||
'fields/content/action-buttons',
|
||||
[
|
||||
'id' => $field['id'],
|
||||
'preview' => $this->get_input_string( 'preview' ),
|
||||
'expand' => $this->get_input_string( 'expand' ),
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
printf( '<div class="wpforms-expandable-editor">%s</div><div class="wpforms-expandable-editor-clear"></div>', $output ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
/**
|
||||
* Add class name to the field option top element.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param string $class CSS classes.
|
||||
* @param array $field Field data.
|
||||
*/
|
||||
public function builder_field_option_class( $class, $field ) {
|
||||
|
||||
return $this->type === $field['type'] ? $class . ' wpforms-field-has-tinymce' : $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Localized strings for content-field JS script.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param array $strings Localized strings.
|
||||
* @param array $form The form element.
|
||||
*
|
||||
* @return array
|
||||
* @noinspection PhpUnusedParameterInspection
|
||||
*/
|
||||
public function content_builder_strings( $strings, $form ) {
|
||||
|
||||
$strings['content_field'] = [
|
||||
'collapse' => wp_strip_all_tags( $this->get_input_string( 'collapse' ) ),
|
||||
'expand' => wp_strip_all_tags( $this->get_input_string( 'expand' ) ),
|
||||
'editor_default_value' => wp_kses( $this->get_input_string( 'editor_default_value' ), $this->get_allowed_html_tags() ),
|
||||
'content_editor_plugins' => $this->content_editor_plugins(),
|
||||
'content_editor_toolbar' => $this->content_editor_toolbar(),
|
||||
'content_editor_css_url' => $this->content_css_url(),
|
||||
'editor_height' => $this->get_editor_height(),
|
||||
'allowed_html' => array_keys( $this->get_allowed_html_tags() ),
|
||||
'invalid_elements' => $this->get_invalid_elements(),
|
||||
'quicktags_buttons' => $this->get_quicktags_buttons(),
|
||||
'body_class' => $this->get_editor_body_class(),
|
||||
];
|
||||
|
||||
$strings = $this->add_supported_field_type( $strings, $this->type );
|
||||
|
||||
return $strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add editor stylesheet.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param array $stylesheets Editor stylesheets.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function editor_stylesheets( $stylesheets ) {
|
||||
|
||||
if ( wpforms_is_admin_page( 'builder' ) ) {
|
||||
$stylesheets[] = $this->content_css_url();
|
||||
}
|
||||
|
||||
return $stylesheets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit some media view strings to reference a form instead of a page/post.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param array $strings List of media view strings.
|
||||
* @param WP_Post $post Post object.
|
||||
*
|
||||
* @return array Modified media view strings.
|
||||
*/
|
||||
public function edit_media_view_strings( $strings, $post ) {
|
||||
|
||||
if ( wpforms_is_admin_page( 'builder' ) ) {
|
||||
$strings['insertIntoPost'] = esc_html__( 'Insert into form', 'wpforms-lite' );
|
||||
$strings['uploadedToThisPost'] = esc_html__( 'Uploaded to this form', 'wpforms-lite' );
|
||||
}
|
||||
|
||||
return $strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove fullscreen button if this is other tinymce editor instance than content field editor.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param array $buttons Array of editor buttons.
|
||||
* @param string $editor_id Editor textarea ID.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function teeny_mce_buttons( $buttons, $editor_id ) {
|
||||
|
||||
$is_other_editor = strpos( $editor_id, 'wpforms_panel_' ) === 0 || $editor_id === 'entry_note';
|
||||
$key = array_search( 'fullscreen', $buttons, true );
|
||||
|
||||
if ( $is_other_editor && $key !== false ) {
|
||||
unset( $buttons[ $key ] );
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default content editor plugins.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @return array Plugins array.
|
||||
*/
|
||||
private function content_editor_plugins() {
|
||||
|
||||
$plugins = [
|
||||
'charmap',
|
||||
'colorpicker',
|
||||
'hr',
|
||||
'link',
|
||||
'image',
|
||||
'lists',
|
||||
'paste',
|
||||
'tabfocus',
|
||||
'textcolor',
|
||||
'wordpress',
|
||||
'wpemoji',
|
||||
'wptextpattern',
|
||||
'wpeditimage',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get content editor plugins filter.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param array $plugins Plugins array.
|
||||
*/
|
||||
return (array) apply_filters( 'wpforms_builder_content_input_get_content_editor_plugins', $plugins );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default content editor toolbar.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @return array Toolbar buttons array.
|
||||
*/
|
||||
private function content_editor_toolbar() {
|
||||
|
||||
$toolbar = [
|
||||
'formatselect',
|
||||
'bold',
|
||||
'italic',
|
||||
'underline',
|
||||
'strikethrough',
|
||||
'forecolor',
|
||||
'link',
|
||||
'bullist',
|
||||
'numlist',
|
||||
'blockquote',
|
||||
'alignleft',
|
||||
'aligncenter',
|
||||
'alignright',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get content editor toolbar buttons filter.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param array $toolbar Toolbar buttons array.
|
||||
*/
|
||||
return (array) apply_filters( 'wpforms_builder_content_input_get_content_editor_toolbar', $toolbar );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue wpforms-content-field script.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param string $view Current view.
|
||||
*
|
||||
* @noinspection PhpUnusedParameterInspection, PhpUnnecessaryCurlyVarSyntaxInspection
|
||||
*/
|
||||
public function builder_enqueues( $view ) {
|
||||
|
||||
$min = wpforms_get_min_suffix();
|
||||
|
||||
wp_enqueue_script(
|
||||
'wpforms-content-field',
|
||||
WPFORMS_PLUGIN_URL . "assets/js/components/admin/fields/content-field{$min}.js",
|
||||
[ 'wpforms-builder', 'editor', 'quicktags' ],
|
||||
WPFORMS_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
// Enqueue editor styles explicitly. Hack for broken styles when Content field is deleted and Settings > Confirmation editor get broken.
|
||||
wp_enqueue_style(
|
||||
'wpforms-editor-styles',
|
||||
includes_url( 'css/editor.css' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Content editor tools template.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*/
|
||||
public function content_editor_tools_template() {
|
||||
|
||||
?>
|
||||
<script type="text/html" id="tmpl-wpforms-content-editor-tools">
|
||||
<div id="wp-wpforms-field-{{data.optionId}}-content-editor-tools" class="wp-editor-tools hide-if-no-js">
|
||||
<div id="wp-wpforms-field-{{data.optionId}}-content-media-buttons" class="wp-media-buttons">
|
||||
<button type="button" id="insert-media-button" class="button insert-media add_media" data-editor="wpforms-field-{{data.optionId}}-content">
|
||||
<span class="wp-media-buttons-icon"></span>
|
||||
<?php esc_html_e( 'Add Media', 'wpforms-lite' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="wp-editor-tabs">
|
||||
<button type="button" id="wpforms-field-{{data.optionId}}-content-tmce" class="wp-switch-editor switch-tmce" data-wp-editor-id="wpforms-field-{{data.optionId}}-content">
|
||||
<?php esc_html_e( 'Visual', 'wpforms-lite' ); ?>
|
||||
</button>
|
||||
<button type="button" id="wpforms-field-{{data.optionId}}-content-html" class="wp-switch-editor switch-html" data-wp-editor-id="wpforms-field-{{data.optionId}}-content">
|
||||
<?php esc_html_e( 'Text', 'wpforms-lite' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Register types in JS localisation to use in WPFormsContentField.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param array $strings Localized strings.
|
||||
* @param string $type Field type.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function add_supported_field_type( $strings, $type ) {
|
||||
|
||||
$other_supported_field_types = isset( $strings['content_input']['supported_field_types'] ) ? $strings['content_input']['supported_field_types'] : [];
|
||||
|
||||
$strings['content_input'] = [
|
||||
'supported_field_types' => array_merge( $other_supported_field_types, [ $type ] ),
|
||||
];
|
||||
|
||||
return $strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translatable string.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param string $key String key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_input_string( $key ) {
|
||||
|
||||
if ( ! self::$translatable_strings ) {
|
||||
self::$translatable_strings = [
|
||||
'editor_default_value' => __( '<h4>Add Text and Images to Your Form With Ease</h4> <p>To get started, replace this text with your own.</p>', 'wpforms-lite' ),
|
||||
'expand' => __( 'Expand Editor', 'wpforms-lite' ),
|
||||
'collapse' => __( 'Collapse Editor', 'wpforms-lite' ),
|
||||
'preview' => __( 'Update Preview', 'wpforms-lite' ),
|
||||
];
|
||||
}
|
||||
|
||||
return isset( self::$translatable_strings[ $key ] ) ? self::$translatable_strings[ $key ] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Show field preview in the right builder panel.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param array $field Field data.
|
||||
*/
|
||||
private function content_input_preview( $field ) {
|
||||
|
||||
$content = isset( $field['content'] ) ? $field['content'] : $this->get_input_string( 'editor_default_value' );
|
||||
?>
|
||||
<div class="wpforms-field-content-preview">
|
||||
<?php echo wp_kses( $this->do_caption_shortcode( wpautop( $content ) ), $this->get_allowed_html_tags() ); ?>
|
||||
<div class="wpforms-field-content-preview-end"></div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if shortcode is [caption] and if not, return processed content string.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param false|string $return Short-circuit return value. Either false or the value to replace the shortcode with.
|
||||
* @param string $tag Shortcode name.
|
||||
* @param array|string $attr Shortcode attributes array or empty string.
|
||||
* @param array $m Regular expression match array.
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public function short_circuit_shortcodes( $return, $tag, $attr, $m ) {
|
||||
|
||||
return $tag !== 'caption' ? $m[0] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if shortcode is [caption] and if not, short-circuit processing the shortcode.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param string $content Editor content.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function do_caption_shortcode( $content ) {
|
||||
|
||||
/**
|
||||
* Check if user allowed to execute all shortcodes on content field value.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param bool $bool Boolean if shortcodes should be executed.
|
||||
*/
|
||||
if ( apply_filters( 'wpforms_content_input_value_do_shortcode', false ) && ! wpforms_is_admin_page( 'builder' ) ) {
|
||||
return do_shortcode( $content );
|
||||
}
|
||||
|
||||
add_filter( 'pre_do_shortcode_tag', [ $this, 'short_circuit_shortcodes' ], 10, 4 );
|
||||
|
||||
$content = do_shortcode( $content );
|
||||
|
||||
remove_filter( 'pre_do_shortcode_tag', [ $this, 'short_circuit_shortcodes' ] );
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get TinyMCE editor for content field.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param string $value Field value.
|
||||
* @param array $field Field data.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_content_editor( $value, $field ) {
|
||||
/*
|
||||
Heads up, if you are going to edit editor settings, bear in mind editor is instantiated in two places:
|
||||
- PHP instance in \WPForms\Admin\Builder\Traits\ContentInput::get_content_editor
|
||||
- JS instance in WPForms.Admin.Builder.ContentField.initTinyMCE
|
||||
*/
|
||||
$settings = [
|
||||
'media_buttons' => true,
|
||||
'drag_drop_upload' => true,
|
||||
'textarea_name' => "fields[{$field['id']}][content]",
|
||||
'editor_height' => $this->get_editor_height(),
|
||||
'editor_class' => ! empty( $field['required'] ) ? 'wpforms-field-required' : '',
|
||||
'tinymce' => [
|
||||
'init_instance_callback' => 'wpformsContentFieldTinyMCECallback',
|
||||
'plugins' => implode( ',', $this->content_editor_plugins() ),
|
||||
'toolbar1' => implode( ',', $this->content_editor_toolbar() ),
|
||||
'invalid_elements' => $this->get_invalid_elements(),
|
||||
'relative_urls' => false,
|
||||
'remove_script_host' => false,
|
||||
'object_resizing' => false,
|
||||
'body_class' => $this->get_editor_body_class(),
|
||||
],
|
||||
'quicktags' => [
|
||||
'buttons' => $this->get_quicktags_buttons(),
|
||||
],
|
||||
];
|
||||
|
||||
ob_start();
|
||||
wp_editor( $value, 'wpforms-field-option-' . $field['id'] . '-content', $settings );
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get invalid HTML in content editor.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @return string Invalid HTML elements.
|
||||
*/
|
||||
private function get_invalid_elements() {
|
||||
|
||||
return 'form,input,textarea,select,option,script,embed,iframe';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of quicktags buttons.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @return string Quicktags buttons.
|
||||
*/
|
||||
private function get_quicktags_buttons() {
|
||||
|
||||
$quicktag_buttons = [
|
||||
'strong',
|
||||
'em',
|
||||
'block',
|
||||
'del',
|
||||
'ins',
|
||||
'img',
|
||||
'ul',
|
||||
'ol',
|
||||
'li',
|
||||
'code',
|
||||
'link',
|
||||
'close',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get list of quicktags buttons filter.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param string $quicktags_buttons Comma separated list of quicktags buttons.
|
||||
*/
|
||||
return implode( ',', apply_filters( 'wpforms_builder_content_input_get_quicktags_buttons', $quicktag_buttons ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content CSS url.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function content_css_url() {
|
||||
|
||||
$min = wpforms_get_min_suffix();
|
||||
|
||||
return WPFORMS_PLUGIN_URL . "assets/css/builder/content-editor{$min}.css";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content editor height.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @retun int Editor textarea height.
|
||||
*/
|
||||
private function get_editor_height() {
|
||||
|
||||
/**
|
||||
* Get content editor height filter.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param int $height Editor textarea height.
|
||||
*/
|
||||
return (int) apply_filters( 'wpforms_builder_content_input_get_editor_height', 204 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get allowed HTML tags for Content Input Field.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_allowed_html_tags() {
|
||||
|
||||
/**
|
||||
* Filter allowed HTML tags in the content field input.
|
||||
*
|
||||
* @since 1.7.8
|
||||
*
|
||||
* @param array $allowed_tags Allowed tags.
|
||||
*/
|
||||
return (array) apply_filters( 'wpforms_builder_content_input_get_allowed_html_tags', wpforms_get_allowed_html_tags_for_richtext_field() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get editor body class.
|
||||
*
|
||||
* @since 1.7.9
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_editor_body_class() {
|
||||
|
||||
return 'wpforms-content-field-editor-body';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user