namespace WPForms\Admin\Builder\Settings;
use WPForms\Frontend\CSSVars;
use WPForms\Integrations\Gutenberg\RestApi;
use WPForms\Integrations\Gutenberg\ThemesData;
use WPForms_Builder_Panel_Settings;
* CSS vars class instance.
* Rest API class instance.
protected $themes_data_obj;
* Size options for themes settings.
* Border type options for themes settings.
* Whether a modern engine is enabled.
* Whether full style is used.
public function init(): void {
$this->css_vars_obj = wpforms()->obj( 'css_vars' );
$this->is_admin = current_user_can( 'manage_options' );
$this->is_modern = wpforms_get_render_engine() === 'modern';
$this->is_full_styles = (int) wpforms_setting( 'disable-css', '1' ) === 1;
'small' => esc_html__( 'Small', 'wpforms-lite' ),
'medium' => esc_html__( 'Medium', 'wpforms-lite' ),
'large' => esc_html__( 'Large', 'wpforms-lite' ),
$this->border_options = [
'none' => esc_html__( 'None', 'wpforms-lite' ),
'solid' => esc_html__( 'Solid', 'wpforms-lite' ),
'dashed' => esc_html__( 'Dashed', 'wpforms-lite' ),
'dotted' => esc_html__( 'Dotted', 'wpforms-lite' ),
protected function hooks(): void {
add_action( 'wpforms_form_settings_panel_content', [ $this, 'panel_content' ] );
add_action( 'wpforms_builder_panel_sidebar_after', [ $this, 'sidebar_content' ], 10, 2 );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueues' ] );
* Enqueue assets for the builder themes.
public function enqueues(): void {
$min = wpforms_get_min_suffix();
'wpforms-builder-themes',
WPFORMS_PLUGIN_URL . "assets/js/admin/builder/themes/builder-themes{$min}.js",
[ 'wpforms-builder', 'wp-api-fetch' ],
WPFORMS_PLUGIN_URL . 'assets/css/frontend/modern/wpforms-full.css',
'wpforms-builder-themes',
'wpforms_builder_themes',
$this->get_localize_data()
wp_add_inline_style( 'wpforms-full', $this->css_vars_obj->get_root_vars_css() );
protected function get_localize_data(): array {
'modules' => $this->get_modules(),
'field-size' => CSSVars::FIELD_SIZE,
'label-size' => CSSVars::LABEL_SIZE,
'button-size' => CSSVars::BUTTON_SIZE,
'container-shadow-size' => CSSVars::CONTAINER_SHADOW_SIZE,
'heads_up' => esc_html__( 'Heads Up!', 'wpforms-lite' ),
'themes_error' => esc_html__( 'Error loading themes. Please try again later.', 'wpforms-lite' ),
'button_background' => esc_html__( 'Button Background', 'wpforms-lite' ),
'button_text' => esc_html__( 'Button Text', 'wpforms-lite' ),
'copy_paste_error' => esc_html__( 'There was an error parsing your JSON code. Please check your code and try again.', 'wpforms-lite' ),
'field_label' => esc_html__( 'Field Label', 'wpforms-lite' ),
'field_sublabel' => esc_html__( 'Field Sublabel', 'wpforms-lite' ),
'field_border' => esc_html__( 'Field Border', 'wpforms-lite' ),
'theme_delete_title' => esc_html__( 'Delete Form Theme', 'wpforms-lite' ),
// Translators: %1$s: Theme name.
'theme_delete_confirm' => esc_html__( 'Are you sure you want to delete the %1$s theme?', 'wpforms-lite' ),
'theme_delete_cant_undone' => esc_html__( 'This cannot be undone.', 'wpforms-lite' ),
'theme_delete_yes' => esc_html__( 'Yes, Delete', 'wpforms-lite' ),
'theme_copy' => esc_html__( 'Copy', 'wpforms-lite' ),
'theme_custom' => esc_html__( 'Custom Theme', 'wpforms-lite' ),
'theme_noname' => esc_html__( 'Noname Theme', 'wpforms-lite' ),
'background' => esc_html__( 'Background Styles', 'wpforms-lite' ),
'container' => esc_html__( 'Container Styles', 'wpforms-lite' ),
'themes' => esc_html__( 'Themes', 'wpforms-lite' ),
'isAdmin' => $this->is_admin,
'isPro' => wpforms()->is_pro(),
'isModern' => $this->is_modern,
'isFullStyles' => $this->is_full_styles,
'route_namespace' => RestApi::ROUTE_NAMESPACE,
* Get Form Builder themes modules.
* @return array Modules list.
public function get_modules(): array {
$min = wpforms_get_min_suffix();
'path' => "./modules/common{$min}.js",
'path' => "./modules/themes{$min}.js",
'path' => "./modules/stock-photos{$min}.js",
'path' => "./modules/background{$min}.js",
'name' => 'advancedSettings',
'path' => "./modules/advanced-settings{$min}.js",
* Add a content for `Themes` panel.
* @param WPForms_Builder_Panel_Settings $instance Settings panel instance.
* @noinspection HtmlUnknownTarget
public function panel_content( WPForms_Builder_Panel_Settings $instance ): void {
$this->form_data = $instance->form_data;
$url = wpforms_utm_link( 'https://wpforms.com/docs/styling-your-forms/', 'Builder Themes', 'Description Link' );
<div class="wpforms-panel-content-section wpforms-panel-content-section-themes">
<div class="wpforms-panel-content-section-themes-inner">
<div class="wpforms-panel-content-section-themes-top">
<div class="wpforms-panel-content-section-title">
<?php esc_html_e( 'Form Themes', 'wpforms-lite' ); ?>
<div class="wpforms-panel-content-section-themes-preview">
<p class="wpforms-panel-content-section-themes-preview-description">
/* translators: %s - URL to the documentation. */
__( 'Customize the look and feel of your form with premade themes or simple style settings that allow you to use your own colors to match your brand. Themes and style settings are also available in the Block Editor and Elementor, where you can see a realtime preview. <a href="%s" target="_blank">Learn more about styling your forms</a>.', 'wpforms-lite' ),
<div class="wpforms-alert wpforms-alert-warning wpforms-alert-warning-wide wpforms-builder-themes-preview-notice">
<?php esc_html_e( 'Preview only', 'wpforms-lite' ); ?>
<?php esc_html_e( 'The fields shown below are for demo purposes and do not reflect the fields in your actual form.', 'wpforms-lite' ); ?>
echo wpforms_render( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'builder/themes/notices',
'is_modern' => $this->is_modern,
'is_full_styles' => $this->is_full_styles,
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo wpforms_render( 'builder/themes/preview' );
</div> <!-- .wpforms-panel-content-section-themes-top -->
</div> <!-- .wpforms-panel-content-section-themes-inner -->
</div> <!-- .wpforms-panel-content-section-themes -->
* Add content for the Themes Sidebar.
* @param object $form Current form object.
* @param string $slug Current panel slug.
public function sidebar_content( $form, $slug ): void {
if ( $slug !== 'settings' ) {
$form_obj = wpforms()->obj( 'form' );
if ( ! $form_obj || ! isset( $form->ID ) ) {
$form_data = $form_obj->get( $form->ID, [ 'content_only' => true ] );
$this->form_data = $form_data;
$this->show_sidebar_html();
private function show_sidebar_html(): void {
<div id="wpforms-builder-themes-sidebar" class="wpforms-hidden">
<div class="wpforms-builder-themes-sidebar-head">
<button id="wpforms-builder-themes-back"> <?php esc_html_e( 'Back to Settings', 'wpforms-lite' ); ?></button>
<div id="wpforms-builder-themes-sidebar-tabs">
<a href="#" class="active"><?php esc_html_e( 'General', 'wpforms-lite' ); ?></a>
<?php if ( $this->is_admin ) : ?>
<a href="#"><?php esc_html_e( 'Advanced', 'wpforms-lite' ); ?></a>
<div class="wpforms-builder-themes-sidebar-content">
<div class="wpforms-builder-themes-sidebar-general wpforms-builder-themes-sidebar-tab-content">
<?php $this->show_sidebar_themes(); ?>
<div class="wpforms-builder-themes-restricted <?php echo esc_attr( ! $this->is_admin ? 'wpforms-hidden' : '' ); ?>">
<?php $this->show_sidebar_field_styles(); ?>
<?php $this->show_sidebar_label_styles(); ?>
<?php $this->show_sidebar_button_styles(); ?>
<?php $this->show_sidebar_container_styles(); ?>
<?php $this->show_sidebar_background_styles(); ?>
<?php $this->show_sidebar_other_styles(); ?>
<div class="wpforms-builder-themes-sidebar-advanced wpforms-builder-themes-sidebar-tab-content wpforms-hidden">
<?php $this->show_sidebar_advanced(); ?>
private function show_sidebar_themes(): void {
<div class="wpforms-add-fields-group">
<a href="#" class="wpforms-add-fields-heading" data-group="themes">
<span><?php esc_html_e( 'Themes', 'wpforms-lite' ); ?></span>
<i class="fa fa-angle-down"></i>
<div class="wpforms-add-fields-buttons">
esc_html__( 'Theme', 'wpforms-lite' ),
'value' => $this->form_data['settings']['themes']['wpformsTheme'] ?? 'default',
'class' => 'wpforms-hidden',
'value' => $this->form_data['settings']['themes']['isCustomTheme'] ?? '',
'class' => 'wpforms-hidden',
<div class="wpforms-builder-themes-control"></div>
esc_html__( 'Theme Name', 'wpforms-lite' ),
'value' => $this->form_data['settings']['themes']['themeName'] ?? '',
'class' => 'wpforms-hidden',
<button id="wpforms-builder-themer-remove-theme" class="wpforms-hidden"><?php esc_html_e( 'Delete Theme', 'wpforms-lite' ); ?></button>
* Show sidebar field styles.
private function show_sidebar_field_styles(): void {
<div class="wpforms-add-fields-group">
<a href="#" class="wpforms-add-fields-heading" data-group="field_styles">
<span><?php esc_html_e( 'Field Styles', 'wpforms-lite' ); ?></span>
<i class="fa fa-angle-down"></i>
<div class="wpforms-add-fields-buttons">
<div class="wpforms-builder-themes-fields-row">
esc_html__( 'Size', 'wpforms-lite' ),
'options' => $this->size_options,
'value' => $this->form_data['settings']['themes']['fieldSize'] ?? 'medium',
esc_html__( 'Border', 'wpforms-lite' ),
'options' => $this->border_options,
'value' => $this->form_data['settings']['themes']['fieldBorderStyle'] ?? 'solid',
<div class="wpforms-builder-themes-fields-row">