This commit is contained in:
2025-11-18 16:39:33 +00:00
parent c70394d367
commit df1f90c6cd
9673 changed files with 3464697 additions and 34 deletions
@@ -0,0 +1,123 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Api;
defined( 'ABSPATH' ) || exit;
class Common extends \ElementsKit_Lite\Core\Handler_Api {
public function config() {
$this->prefix = 'widget-builder';
$this->param = '/(?P<id>\w+(|[-]\w+))/';
}
private function fix_title( $title ) {
return ( $title == '' ) ? ( 'ElementsKit_Lite Custom Widget #' . time() ) : $title;
}
public function post_push() {
if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
return array(
'success' => false,
'message' => array(
esc_html__( 'Not enough permission.', 'elementskit-lite' ),
),
);
}
$id = $this->request['id'];
$data = json_decode( $this->request['data'] );
if ( ! property_exists( $data, 'title' ) || ! property_exists( $data, 'tabs' ) || ! ( $data->tabs instanceof \stdClass ) ) {
return array(
'success' => false,
'message' => array(
esc_html__( 'Invalid data.', 'elementskit-lite' ),
),
);
}
$title = $this->fix_title( $data->title );
$widget_data = array(
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'elementskit_widget',
);
$widget = get_post( $id );
if ( $widget == null ) {
$id = wp_insert_post( $widget_data );
} else {
$widget_data['ID'] = $id;
wp_update_post( $widget_data );
}
update_post_meta( $id, '_elementor_edit_mode', 'builder' );
update_post_meta( $id, '_wp_page_template', 'elementor_canvas' );
$data->push_id = $id;
//update_post_meta( $id, '_wp_page_template', 'elementor_canvas' );
update_post_meta( $id, 'elementskit_custom_widget_data', $data );
\ElementsKit_Lite\Modules\Widget_Builder\Widget_File::instance()->create( $data, $id );
return array(
'success' => true,
'message' => array(
esc_html__( 'Widget data saved!', 'elementskit-lite' ),
),
'push_id' => $id,
);
}
public function post_pull() {
if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
return array(
'success' => false,
'message' => array(
esc_html__( 'Not enough permission.', 'elementskit-lite' ),
),
);
}
$id = $this->request['id'];
$default = array(
'title' => 'New Widget',
'icon' => 'eicon-cog',
'categories' => array( 'basic' ),
'push_id' => $id,
'markup' => '',
'css' => '',
'js' => '',
'css_includes' => '',
'js_includes' => '',
'tabs' => array(
'content' => array(),
'style' => array(),
'advanced' => array(),
),
);
$widget_data = get_post_meta( $id, 'elementskit_custom_widget_data', true );
return is_object( $widget_data ) ? $widget_data : $default;
}
public function post_import() {
//$id = $this->request['id'];
return array(
'success' => true,
'message' => 'hi',
//'file' => $this->request
);
}
}
@@ -0,0 +1 @@
#post-body-content,#postbox-container-1{display:none}#post-body{margin-right:0!important}#elementskit-widget-builder-markup .inside{margin-top:0;padding:0}#elementskit-widget-builder-markup>.postbox-header,.meta-box-sortables:first-child{display:none}.postbox{border-width:0}.js .postbox>.handlediv{display:none}.postbox>h2{display:none}#wpbody-content{padding-bottom:0}#wpfooter{display:none}#elementor-panel-header-menu-button{visibility:hidden}#elementor-panel-footer-tools>div:not(#elementor-panel-footer-responsive){display:none}.elementor-add-new-section>:not(.elementor-add-section-button):not(.elementor-add-section-drag-title){display:none!important}.elementor-add-section-button{margin-left:30px;margin-right:30px}
File diff suppressed because one or more lines are too long
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

File diff suppressed because one or more lines are too long
@@ -0,0 +1,43 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Animation extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => \'' . esc_html( $conf->default ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( ! empty( $conf->prefix_class ) ) {
$ret .= "\t\t\t\t" . '\'prefix_class\' => \'' . esc_html( $conf->prefix_class ) . '\',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,43 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Background extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
$ret .= "\t\t\t\t'fields_options' => [";
$ret .= "\n\t\t\t\t\t'background' => [";
$ret .= "\n\t\t\t\t\t\t'label' => '" . esc_html( $conf->label ) . "',";
if ( ! empty( $conf->description ) ) {
$ret .= "\n\t\t\t\t\t\t'description' => '" . esc_html( $conf->description ) . "',";
}
if ( isset( $conf->show_label ) ) {
$ret .= "\n\t\t\t\t\t\t'show_label' => " . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',';
}
if ( isset( $conf->label_block ) ) {
$ret .= "\n\t\t\t\t\t\t'label_block' => " . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',';
}
$ret .= "\n\t\t\t\t\t],";
$ret .= "\n\t\t\t\t],\n";
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->selector ) ) {
$selectorProperty = str_replace( ',', ', {{WRAPPER}} ', esc_html( $conf->selector ) );
$ret .= "\t\t\t\t" . '\'selector\' => \'{{WRAPPER}} ' . $selectorProperty . '\',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,43 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Border extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
$ret .= "\t\t\t\t'fields_options' => [";
$ret .= "\n\t\t\t\t\t'border' => [";
$ret .= "\n\t\t\t\t\t\t'label' => '" . esc_html( $conf->label ) . "',";
if ( ! empty( $conf->description ) ) {
$ret .= "\n\t\t\t\t\t\t'description' => '" . esc_html( $conf->description ) . "',";
}
if ( isset( $conf->show_label ) ) {
$ret .= "\n\t\t\t\t\t\t'show_label' => " . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',';
}
if ( isset( $conf->label_block ) ) {
$ret .= "\n\t\t\t\t\t\t'label_block' => " . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',';
}
$ret .= "\n\t\t\t\t\t],";
$ret .= "\n\t\t\t\t],\n";
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->selector ) ) {
$selectorProperty = str_replace( ',', ', {{WRAPPER}} ', esc_html( $conf->selector ) );
$ret .= "\t\t\t\t" . '\'selector\' => \'{{WRAPPER}} ' . $selectorProperty . '\' ,' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,48 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Box_Shadow extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->label ) ) {
$ret .= "\t\t\t\t" . '\'label\' => esc_html( \'' . esc_html( $conf->label ) . '\', \'elementskit\' ),' . PHP_EOL;
}
if ( ! empty( $conf->selector ) ) {
$selectorProperty = str_replace( ',', ', {{WRAPPER}} ', esc_html( $conf->selector ) );
$ret .= "\t\t\t\t" . '\'selector\' => \'{{WRAPPER}} ' . $selectorProperty . '\',' . PHP_EOL;
}
if ( isset( $conf->show_label ) || isset( $conf->label_block ) || ! empty( $conf->separator ) || ! empty( $conf->classes ) ) :
$ret .= "\t\t\t\t'fields_options' => [";
$ret .= "\n\t\t\t\t\t'box_shadow_type' => [";
if ( isset( $conf->show_label ) ) {
$ret .= "\n\t\t\t\t\t\t'show_label' => " . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',';
}
if ( isset( $conf->label_block ) ) {
$ret .= "\n\t\t\t\t\t\t'label_block' => " . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',';
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\n\t\t\t\t\t\t'separator' => '" . esc_html( $conf->separator ) . "',";
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\n\t\t\t\t\t\t'classes' => '" . esc_html( $conf->classes ) . "',";
}
$ret .= "\n\t\t\t\t\t],";
$ret .= "\n\t\t\t\t],\n";
endif;
return $ret;
}
}
@@ -0,0 +1,62 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Choose extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\' ,' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->toggle ) ) {
$ret .= "\t\t\t\t" . '\'toggle\' => ' . ( $conf->toggle == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '\'options\' => array(' . PHP_EOL;
if ( ! empty( $conf->options ) ) {
$realArray = (array) $conf->options;
foreach ( $realArray as $val => $label ) {
$ret .= "\t\t\t\t\t" . '\'' . $val . '\' => array(' . PHP_EOL;
$ret .= "\t\t\t\t\t\t" . '\'title\' => esc_html( \'' . esc_html( $label->title ) . '\' ),' . PHP_EOL;
$ret .= "\t\t\t\t\t\t" . '\'icon\' => \'' . esc_html( $label->icon ) . '\',' . PHP_EOL;
$ret .= "\t\t\t\t\t" . '),' . PHP_EOL;
}
}
$ret .= "\t\t\t\t" . ')' . PHP_EOL;
return $ret;
}
}
@@ -0,0 +1,51 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Code extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->placeholder ) ) {
$ret .= "\t\t\t\t" . '\'placeholder\' => esc_html( \'' . esc_html( $conf->placeholder ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => \'' . esc_html( $conf->default ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->rows ) ) {
$ret .= "\t\t\t\t" . '\'rows\' => ' . intval( $conf->rows ) . ',' . PHP_EOL;
}
if ( isset( $conf->language ) ) {
$ret .= "\t\t\t\t" . '\'language\' => \'' . esc_html( $conf->language ) . '\',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,52 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Color extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->selectors ) ) {
$selectors = (array) $conf->selectors;
$ret .= "\t\t\t\t" . '\'selectors\' => array(' . PHP_EOL;
foreach ( $selectors as $selectorName => $selectorValue ) {
$selectorProperty = str_replace( ',', ', {{WRAPPER}} ', $selectorName );
$ret .= "\t\t\t\t\t" . '\'{{WRAPPER}} ' . $selectorProperty . '\' => \'' . esc_html( $selectorValue ) . '\',' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->alpha ) ) {
$ret .= "\t\t\t\t" . '\'alpha\' => ' . ( $conf->alpha == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,60 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Date_Time extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\' ,' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '\'picker_options\' => array(' . PHP_EOL;
if ( ! empty( $conf->picker_options ) ) {
foreach ( $conf->picker_options as $idx => $v_option ) {
$exp = explode( ':', $v_option );
// Check if $exp[1] is a boolean
if (filter_var($exp[1], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null) {
// If it's boolean, return the actual boolean value (true/false)
$ret .= "\t\t\t\t\t" . '\'' . esc_html($exp[0]) . '\' => ' . (filter_var($exp[1], FILTER_VALIDATE_BOOLEAN) ? 'true' : 'false') . ',' . PHP_EOL;
} else {
// Otherwise, return it as a string
$ret .= "\t\t\t\t\t" . '\'' . esc_html($exp[0]) . '\' => \'' . esc_html($exp[1]) . '\',' . PHP_EOL;
}
}
}
$ret .= "\t\t\t\t" . ')' . PHP_EOL;
return $ret;
}
}
@@ -0,0 +1,62 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Dimensions extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->placeholder ) ) {
$ret .= "\t\t\t\t" . '\'placeholder\' => esc_html( \'' . esc_html( $conf->placeholder ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->allowed_dimensions ) ) {
$allowed_dimensions = (array) $conf->allowed_dimensions;
$ret .= "\t\t\t\t" . '\'allowed_dimensions\' => array(' . PHP_EOL;
foreach ( $allowed_dimensions as $key => $value ) {
$ret .= "\t\t\t\t\t" . '\'' . esc_html( $value ) . '\',' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->selectors ) ) {
$selectors = (array) $conf->selectors;
$ret .= "\t\t\t\t" . '\'selectors\' => array(' . PHP_EOL;
foreach ( $selectors as $selectorName => $selectorValue ) {
$selectorProperty = str_replace( ',', ', {{WRAPPER}} ', $selectorName );
$ret .= "\t\t\t\t\t" . '\'{{WRAPPER}} ' . $selectorProperty . '\' => \'' . esc_html( $selectorValue ) . '\',' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,79 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Font extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\' ,' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( ! empty( $conf->options ) ) {
$ret .= "\t\t\t\t" . '\'options\' => array(' . PHP_EOL;
$realArray = (array) $conf->options;
foreach ( $realArray as $val => $label ) {
$ret .= "\t\t\t\t\t" . '\'' . esc_html( $label ) . '\' => \'' . esc_html( $val ) . '\',' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
if ( ! empty( $conf->groups ) ) {
$ret .= "\t\t\t\t" . '\'groups\' => array(' . PHP_EOL;
$realArray = (array) $conf->groups;
foreach ( $realArray as $val => $label ) {
$ret .= "\t\t\t\t\t" . '\'' . esc_html( $val ) . '\' => \'' . esc_html( $label ) . '\',' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
if ( ! empty( $conf->selectors ) ) {
$selectors = (array) $conf->selectors;
$ret .= "\t\t\t\t" . '\'selectors\' => array(' . PHP_EOL;
foreach ( $selectors as $selectorName => $selectorValue ) {
$selectorProperty = str_replace( ',', ', {{WRAPPER}} ', $selectorName );
$ret .= "\t\t\t\t\t" . '\'{{WRAPPER}} ' . $selectorProperty . '\' => \'' . esc_html( $selectorValue ) . '\',' . PHP_EOL;
}
$ret .= "\t\t\t\t" . ')' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,39 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Gallery extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\' ,' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,41 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Hover extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\' ,' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '\'prefix_class\' => \'\' ,' . PHP_EOL;
return $ret;
}
}
@@ -0,0 +1,52 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Icons extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\' ,' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( ! empty( $conf->skin ) ) {
$ret .= "\t\t\t\t" . '\'skin\' => \'' . esc_html( $conf->skin ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->fa4compatibility ) ) {
$ret .= "\t\t\t\t" . '\'fa4compatibility\' => \'' . esc_html( $conf->fa4compatibility ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => array(' . PHP_EOL;
$ret .= "\t\t\t\t\t" . '\'value\' => \'' . esc_html( $conf->default->value ) . '\',' . PHP_EOL;
$ret .= "\t\t\t\t\t" . '\'library\' => \'' . esc_html( $conf->default->library ) . '\',' . PHP_EOL;
$ret .= "\t\t\t\t" . ')' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,59 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Image_Dimensions extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) && ( ! empty( $conf->default->width ) || ! empty( $conf->default->height ) ) ) {
$ret .= "\t\t\t\t" . '\'default\' => array(' . PHP_EOL;
if ( ! empty( $conf->default->width ) ) {
$ret .= "\t\t\t\t\t" . '\'width\' => ' . esc_html( $conf->default->width ) . ',' . PHP_EOL;
}
if ( ! empty( $conf->default->height ) ) {
$ret .= "\t\t\t\t\t" . '\'height\' => ' . esc_html( $conf->default->height ) . ',' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->selectors ) ) {
$selectors = (array) $conf->selectors;
$ret .= "\t\t\t\t" . '\'selectors\' => array(' . PHP_EOL;
foreach ( $selectors as $selectorName => $selectorValue ) {
$selectorProperty = str_replace( ',', ', {{WRAPPER}} ', $selectorName );
$ret .= "\t\t\t\t\t" . '\'{{WRAPPER}} ' . $selectorProperty . '\' => \'' . esc_html( $selectorValue ) . '\',' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,52 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Image_Size extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->label ) ) {
$ret .= "\t\t\t\t" . '\'label\' => esc_html( \'' . esc_html( $conf->label ) . '\', \'elementskit\' ),' . PHP_EOL;
}
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->exclude ) ) {
$ret .= "\t\t\t\t" . '\'exclude\' => [';
foreach ( $conf->exclude as $value ) {
$ret .= '\'' . $value . '\',';
}
$ret .= '],' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\' ,' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,56 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
/**
* Control_Type_Input for \Elementor\Controls_Manager::TEXT
* check below link for argument list
*
*
* @see https://developers.elementor.com/elementor-controls/text-control/
*
* @package Elementor
*/
class Control_Type_Input extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->placeholder ) ) {
$ret .= "\t\t\t\t" . '\'placeholder\' => esc_html( \'' . esc_html( $conf->placeholder ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( ! empty( $conf->input_type ) ) {
$ret .= "\t\t\t\t" . '\'input_type\' => \'' . esc_html( $conf->input_type ) . '\',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,43 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Media extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => array(' . PHP_EOL;
$ret .= "\t\t\t\t\t" . '\'url\' => \'' . esc_url( $conf->default->url ) . '\',' . PHP_EOL;
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,55 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Number extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->placeholder ) ) {
$ret .= "\t\t\t\t" . '\'placeholder\' => esc_html( \'' . esc_html( $conf->placeholder ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->min ) ) {
$ret .= "\t\t\t\t" . '\'min\' => \'' . floatval( $conf->min ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->max ) ) {
$ret .= "\t\t\t\t" . '\'max\' => \'' . floatval( $conf->max ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->step ) ) {
$ret .= "\t\t\t\t" . '\'step\' => \'' . esc_html( $conf->step ) . '\',' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,53 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Select extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '\'options\' => array(' . PHP_EOL;
if ( ! empty( $conf->options ) ) {
$realArray = (array) $conf->options;
foreach ( $realArray as $val => $label ) {
$ret .= "\t\t\t\t\t" . '\'' . esc_html( $val ) . '\' => esc_html( \'' . esc_html( $label ) . '\' ),' . PHP_EOL;
}
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,81 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Select2 extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
if ( gettype( $conf->default ) == 'string' ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
} else {
$ret .= "\t\t\t\t" . '\'default\' => array(' . PHP_EOL;
$defaults = (array) $conf->default;
foreach ( $defaults as $key ) {
$ret .= "\t\t\t\t\t" . '\'' . esc_html( $key ) . '\',' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( isset( $conf->multiple ) ) {
$ret .= "\t\t\t\t" . '\'multiple\' => ' . ( $conf->multiple == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '\'options\' => array(' . PHP_EOL;
if ( ! empty( $conf->options ) ) {
$realArray = (array) $conf->options;
foreach ( $realArray as $val => $label ) {
$ret .= "\t\t\t\t\t" . '\'' . esc_html( $val ) . '\' => esc_html( \'' . esc_html( $label ) . '\' ),' . PHP_EOL;
}
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
if ( ! empty( $conf->selectors ) ) {
$selectors = (array) $conf->selectors;
$ret .= "\t\t\t\t" . '\'selectors\' => array(' . PHP_EOL;
foreach ( $selectors as $selectorName => $selectorValue ) {
$selectorProperty = str_replace( ',', ', {{WRAPPER}} ', $selectorName );
$ret .= "\t\t\t\t\t" . '\'{{WRAPPER}} ' . $selectorProperty . '\' => \'' . esc_html( $selectorValue ) . '\',' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,94 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
/**
* Class Control_Type_Slider
*
* @see https://developers.elementor.com/elementor-controls/slider-control/
*
* @package ElementsKit_Lite\Modules\Widget_Builder\Controls
*/
class Control_Type_Slider extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\',' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => array(' . PHP_EOL;
$ret .= "\t\t\t\t\t" . '\'unit\' => \'' . esc_html( $conf->default->unit ) . '\',' . PHP_EOL;
$ret .= "\t\t\t\t\t" . '\'size\' => \'' . esc_html( $conf->default->size ) . '\',' . PHP_EOL;
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
if ( ! empty( $conf->size_units ) ) {
$ret .= "\t\t\t\t" . '\'size_units\' => array(' . PHP_EOL;
foreach ( $conf->size_units as $size ) {
$ret .= "\t\t\t\t\t" . '\'' . esc_html( $size ) . '\',' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
if ( ! empty( $conf->range ) ) {
$ret .= "\t\t\t\t" . '\'range\' => array(' . PHP_EOL;
$realArray = (array) $conf->range;
foreach ( $realArray as $val => $label ) {
$ret .= "\t\t\t\t\t" . '\'' . $val . '\' => array(' . PHP_EOL;
$ret .= "\t\t\t\t\t\t" . '\'min\' => \'' . floatval( $label->min ) . '\',' . PHP_EOL;
$ret .= "\t\t\t\t\t\t" . '\'max\' => \'' . floatval( $label->max ) . '\',' . PHP_EOL;
$ret .= "\t\t\t\t\t\t" . '\'step\' => \'' . esc_html( $label->step ) . '\',' . PHP_EOL;
$ret .= "\t\t\t\t\t" . '),' . PHP_EOL;
}
$ret .= "\t\t\t\t" . ')' . PHP_EOL;
}
if ( ! empty( $conf->selectors ) ) {
$selectors = (array) $conf->selectors;
$ret .= "\t\t\t\t" . '\'selectors\' => array(' . PHP_EOL;
foreach ( $selectors as $selectorName => $selectorValue ) {
$selectorProperty = str_replace( ',', ', {{WRAPPER}} ', $selectorName );
$ret .= "\t\t\t\t\t" . '\'{{WRAPPER}} ' . $selectorProperty . '\' => \'' . esc_html( $selectorValue ) . '\',' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,49 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Switch extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\' ,' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( ! empty( $conf->label_on ) ) {
$ret .= "\t\t\t\t" . '\'label_on\' => \'' . esc_html( $conf->label_on ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->label_off ) ) {
$ret .= "\t\t\t\t" . '\'label_off\' => \'' . esc_html( $conf->label_off ) . '\' ,' . PHP_EOL;
}
$ret .= "\t\t\t\t" . '\'return_value\' => \'' . esc_html( $conf->return_value ) . '\' ,' . PHP_EOL;
return $ret;
}
}
@@ -0,0 +1,47 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Text_Area extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->placeholder ) ) {
$ret .= "\t\t\t\t" . '\'placeholder\' => esc_html( \'' . esc_html( $conf->placeholder ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\',' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
}
if ( isset( $conf->rows ) ) {
$ret .= "\t\t\t\t" . '\'rows\' => ' . intval( $conf->rows ) . ',' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,48 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Text_Shadow extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->label ) ) {
$ret .= "\t\t\t\t" . '\'label\' => esc_html( \'' . esc_html( $conf->label ) . '\', \'elementskit\' ),' . PHP_EOL;
}
if ( ! empty( $conf->selector ) ) {
$selectorProperty = str_replace( ',', ', {{WRAPPER}} ', esc_html( $conf->selector ) );
$ret .= "\t\t\t\t" . '\'selector\' => \'{{WRAPPER}} ' . $selectorProperty . '\',' . PHP_EOL;
}
if ( isset( $conf->show_label ) || isset( $conf->label_block ) || ! empty( $conf->separator ) || ! empty( $conf->classes ) ) :
$ret .= "\t\t\t\t'fields_options' => [";
$ret .= "\n\t\t\t\t\t'text_shadow_type' => [";
if ( isset( $conf->show_label ) ) {
$ret .= "\n\t\t\t\t\t\t'show_label' => " . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',';
}
if ( isset( $conf->label_block ) ) {
$ret .= "\n\t\t\t\t\t\t'label_block' => " . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',';
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\n\t\t\t\t\t\t'separator' => '" . esc_html( $conf->separator ) . "',";
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\n\t\t\t\t\t\t'classes' => '" . esc_html( $conf->classes ) . "',";
}
$ret .= "\n\t\t\t\t\t],";
$ret .= "\n\t\t\t\t],\n";
endif;
return $ret;
}
}
@@ -0,0 +1,49 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_Typography extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->label ) ) {
$ret .= "\t\t\t\t" . '\'label\' => esc_html( \'' . esc_html( $conf->label ) . '\', \'elementskit\' ),' . PHP_EOL;
}
if ( ! empty( $conf->selector ) ) {
$selectorProperty = str_replace( ',', ', {{WRAPPER}} ', esc_html( $conf->selector ) );
$ret .= "\t\t\t\t" . '\'selector\' => \'{{WRAPPER}} ' . $selectorProperty . '\',' . PHP_EOL;
}
if ( isset( $conf->show_label ) || isset( $conf->label_block ) || ! empty( $conf->separator ) || ! empty( $conf->classes ) ) :
$ret .= "\t\t\t\t'fields_options' => [";
$ret .= "\n\t\t\t\t\t'typography' => [";
if ( isset( $conf->show_label ) ) {
$ret .= "\n\t\t\t\t\t\t'show_label' => " . ( $conf->show_label == 1 ? 'true' : 'false' ) . ',';
}
if ( isset( $conf->label_block ) ) {
$ret .= "\n\t\t\t\t\t\t'label_block' => " . ( $conf->label_block == 1 ? 'true' : 'false' ) . ',';
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\n\t\t\t\t\t\t'separator' => '" . esc_html( $conf->separator ) . "',";
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\n\t\t\t\t\t\t'classes' => '" . esc_html( $conf->classes ) . "',";
}
$ret .= "\n\t\t\t\t\t],";
$ret .= "\n\t\t\t\t],\n";
endif;
return $ret;
}
}
@@ -0,0 +1,54 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class Control_Type_URL extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->placeholder ) ) {
$ret .= "\t\t\t\t" . '\'placeholder\' => esc_html( \'' . esc_html( $conf->placeholder ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->show_external ) ) {
$ret .= "\t\t\t\t" . '\'show_external\' => ' . ( $conf->show_external == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => array(' . PHP_EOL;
$ret .= "\t\t\t\t\t" . '\'url\' => \'' . esc_url( $conf->default->url ) . '\',' . PHP_EOL;
$ret .= "\t\t\t\t\t" . '\'is_external\' => ' . ( $conf->default->is_external == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
$ret .= "\t\t\t\t\t" . '\'nofollow\' => ' . ( $conf->default->nofollow == 1 ? 'true' : 'false' ) . ',' . PHP_EOL;
$ret .= "\t\t\t\t" . '),' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\',' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,50 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
/**
* Class Control_Type_Wys
*
* @see https://developers.elementor.com/elementor-controls/wysiwyg-control/
*
* @package ElementsKit_Lite\Modules\Widget_Builder\Controls
*/
class Control_Type_Wys extends CT_Base {
public function start_writing_conf( $file_handler, $conf ) {
$ret = '';
if ( ! empty( $conf->placeholder ) ) {
$ret .= "\t\t\t\t" . '\'placeholder\' => esc_html( \'' . esc_html( $conf->placeholder ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->description ) ) {
$ret .= "\t\t\t\t" . '\'description\' => esc_html( \'' . esc_html( $conf->description ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->default ) ) {
$ret .= "\t\t\t\t" . '\'default\' => esc_html( \'' . esc_html( $conf->default ) . '\' ),' . PHP_EOL;
}
if ( ! empty( $conf->separator ) ) {
$ret .= "\t\t\t\t" . '\'separator\' => \'' . esc_html( $conf->separator ) . '\' ,' . PHP_EOL;
}
if ( ! empty( $conf->classes ) ) {
$ret .= "\t\t\t\t" . '\'classes\' => \'' . esc_html( $conf->classes ) . '\' ,' . PHP_EOL;
}
if ( isset( $conf->show_label ) ) {
$ret .= "\t\t\t\t" . '\'show_label\' => ' . ( $conf->show_label == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
if ( isset( $conf->label_block ) ) {
$ret .= "\t\t\t\t" . '\'label_block\' => ' . ( $conf->label_block == 1 ? 'true' : 'false' ) . ' ,' . PHP_EOL;
}
return $ret;
}
}
@@ -0,0 +1,16 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
abstract class CT_Base implements CT_Contract {
protected $text_domain;
public function __construct( $txt_domain ) {
$this->text_domain = $txt_domain;
}
}
@@ -0,0 +1,11 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
interface CT_Contract {
public function start_writing_conf( $file_handler, $conf);
}
@@ -0,0 +1,112 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
defined( 'ABSPATH' ) || exit;
class CT_Factory {
public function make( $type, $domain, $group = 'single' ) {
if ( $group == 'single' ) {
switch ( $type ) {
case 'TextControl':
return new Control_Type_Input( $domain );
case 'NumberControl':
return new Control_Type_Number( $domain );
case 'UrlControl':
return new Control_Type_URL( $domain );
case 'TextareaControl':
return new Control_Type_Text_Area( $domain );
case 'SelectControl':
return new Control_Type_Select( $domain );
case 'Select2Control':
return new Control_Type_Select2( $domain );
case 'CodeControl':
return new Control_Type_Code( $domain );
case 'SwitcherControl':
return new Control_Type_Switch( $domain );
case 'ChooseControl':
return new Control_Type_Choose( $domain );
case 'ColorControl':
return new Control_Type_Color( $domain );
case 'EntranceAnimationControl':
return new Control_Type_Animation( $domain );
case 'HoverAnimationControl':
return new Control_Type_Animation( $domain );
case 'DateTimeControl':
return new Control_Type_Date_Time( $domain );
case 'FontControl':
return new Control_Type_Font( $domain );
case 'GalleryControl':
return new Control_Type_Gallery( $domain );
case 'SliderControl':
return new Control_Type_Slider( $domain );
case 'IconsControl':
return new Control_Type_Icons( $domain );
case 'MediaControl':
return new Control_Type_Media( $domain );
case 'WysiwygControl':
return new Control_Type_Wys( $domain );
case 'DimensionsControl':
return new Control_Type_Dimensions( $domain );
case 'ImageDimensionsControl':
return new Control_Type_Image_Dimensions( $domain );
default:
return new Control_Type_Input( $domain );
}
} elseif ( $group == 'group' ) {
switch ( $type ) {
case 'BackgroundControl':
return new Control_Type_Background( $domain );
case 'BorderControl':
return new Control_Type_Border( $domain );
case 'TextShadowControl':
return new Control_Type_Text_Shadow( $domain );
case 'BoxShadowControl':
return new Control_Type_Box_Shadow( $domain );
case 'TypographyControl':
return new Control_Type_Typography( $domain );
case 'ImageSizeControl':
return new Control_Type_Image_Size( $domain );
default:
return new Control_Type_Border( $domain );
}
} elseif ( $group == 'responsive' ) {
}
return new Control_Type_Input( $domain );
}
}
@@ -0,0 +1,537 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder\Controls;
use ElementsKit_Lite\Modules\Widget_Builder\Widget_File;
defined( 'ABSPATH' ) || exit;
class Widget_Writer {
private $widget_name;
private $widget_id;
private $file_handler = '';
private $file_name;
private $enqueue_handler_prefix;
private $widget_class_name;
private $folder_name;
private $control_prefix;
private $name_prefix = 'ekit_wb_';
private $class_name_prefix = 'Ekit_Wb_';
private $widget_obj;
private $prepared_content = '';
public $text_domain = 'elementskit-lite';
const TAB_CONTENT = 'Controls_Manager::TAB_CONTENT';
const TAB_STYLE = 'Controls_Manager::TAB_STYLE';
const TAB_ADVANCE = 'Controls_Manager::TAB_ADVANCED';
const CONTROL_GROUP_TYPE_SINGLE = 'single';
const CONTROL_GROUP_TYPE_RESPONSIVE = 'responsive';
const CONTROL_GROUP_TYPE_GROUPED = 'group';
public function __construct( $widget, $widget_id, $txt_domain = 'elementskit-lite' ) {
$this->widget_obj = $widget;
$this->file_name = '';
$this->text_domain = $txt_domain;
$this->widget_id = $widget_id;
$this->folder_name = $this->name_prefix . $this->widget_id;
$this->widget_name = $this->name_prefix . $this->widget_id;
$this->widget_class_name = $this->class_name_prefix . $this->widget_id;
$this->control_prefix = $this->folder_name . '_';
$this->enqueue_handler_prefix = 'ekit-wb-' . $this->widget_id;
}
public function start_backing( $wp_filesystem ) {
$css_enqueue = $this->prepare_css_file( $this->widget_obj->css, $wp_filesystem );
$js_enqueue = $this->prepare_js_file( $this->widget_obj->js, $wp_filesystem );
$include_js = ! empty( $this->widget_obj->js_includes ) || ! empty( $this->widget_obj->css_includes );
$content = $this->prepare_php_file();
if ( $css_enqueue === true || $js_enqueue === true || $include_js === true ) {
$content .= $this->write_construct_method( $css_enqueue, $js_enqueue );
}
$content .= $this->write_name_method();
$content .= $this->write_title_method( $this->widget_obj->title );
$content .= $this->write_categories_method( $this->widget_obj->categories );
$content .= $this->write_icon_method( $this->widget_obj->icon );
$content .= $this->write_register_control_method( $this->widget_obj->tabs );
$content .= $this->write_render_method( $this->widget_obj->markup );
$content .= $this->close_widget_class();
$this->prepared_content = $content;
}
private function get_url_path() {
$upload = wp_upload_dir();
return $upload['baseurl'] . '/elementskit/custom_widgets/' . $this->folder_name;
}
private function get_file_path() {
$upload = wp_upload_dir();
$upload_dir = $upload['basedir'];
$upload_dir = $upload_dir . '/elementskit/custom_widgets/' . $this->folder_name;
if ( ! is_dir( $upload_dir ) ) {
wp_mkdir_p( $upload_dir );
}
return $upload_dir;
}
public static function delete_widget( $widget_id ) {
$fl_sys = Widget_File::get_wp_filesystem_pointer();
$wb = new self( array(), $widget_id );
$dir = $wb->get_file_path();
if ( file_exists( $dir ) ) {
$fl_sys->delete( $dir, true );
}
return true; // :P
}
private function prepare_css_file( $content, $file_system ) {
if ( empty( $content ) ) {
return false;
}
$trimmed = trim( $content );
if ( empty( $trimmed ) ) {
return false;
}
$path = $this->get_file_path();
return $file_system->put_contents( $path . '/style.css', $trimmed );
}
private function prepare_js_file( $content, $file_system ) {
if ( empty( $content ) ) {
return false;
}
$trimmed = trim( $content );
if ( empty( $trimmed ) ) {
return false;
}
$path = $this->get_file_path();
return $file_system->put_contents( $path . '/script.js', $trimmed );
}
public function finish_backing( $file_system ) {
$path = $this->get_file_path();
return $file_system->put_contents( $path . '/widget.php', $this->prepared_content );
}
private function prepare_php_file() {
$ret = '<?php' . PHP_EOL . PHP_EOL;
$ret .= 'namespace Elementor;' . PHP_EOL . PHP_EOL;
$ret .= 'defined(\'ABSPATH\') || exit;' . PHP_EOL . PHP_EOL;
$ret .= 'class ' . $this->widget_class_name . ' extends Widget_Base {' . PHP_EOL . PHP_EOL;
return $ret;
}
private function write_construct_method( $css = false, $js = false ) {
$nm = $this->enqueue_handler_prefix;
$url_path = $this->get_url_path();
$ret = "\t" . 'public function __construct($data = [], $args = null) {' . PHP_EOL;
$ret .= "\t\t" . 'parent::__construct($data, $args);' . PHP_EOL . PHP_EOL;
if ( $css === true ) {
$ret .= "\t\t" . 'wp_register_style( \'' . $nm . '-style-handle\', \'' . $url_path . '/style.css\');' . PHP_EOL;
}
if ( $js === true ) {
$ret .= "\t\t" . 'wp_register_script( \'' . $nm . '-script-handle\', \'' . $url_path . '/script.js\', [ \'elementor-frontend\' ], \'1.0.0\', true );' . PHP_EOL;
}
if ( ! empty( $this->widget_obj->css_includes ) ) {
$ret .= PHP_EOL;
foreach ( $this->widget_obj->css_includes as $idx => $cssInclude ) {
$ret .= "\t\t" . 'wp_enqueue_style( \'' . $nm . '-' . $idx . '-style-handle\', \'' . $cssInclude . '\');' . PHP_EOL;
}
}
if ( ! empty( $this->widget_obj->js_includes ) ) {
$ret .= PHP_EOL;
foreach ( $this->widget_obj->js_includes as $idx => $jsInclude ) {
$ret .= "\t\t" . 'wp_enqueue_script( \'' . $nm . '-' . $idx . '-script-handle\', \'' . $jsInclude . '\', [ \'elementor-frontend\' ], \'1.0.0\', true );' . PHP_EOL;
}
}
$ret .= "\t" . '}' . PHP_EOL . PHP_EOL;
if ( $css === true ) {
$ret .= "\n\t" . 'public function get_style_depends() {' . PHP_EOL;
$ret .= "\t\t" . 'return [ \'' . $nm . '-style-handle\' ];' . PHP_EOL;
$ret .= "\t" . '}' . PHP_EOL . PHP_EOL;
}
if ( $js === true ) {
$ret .= "\n\t" . 'public function get_script_depends() {' . PHP_EOL;
$ret .= "\t\t" . 'return [ \'' . $nm . '-script-handle\' ];' . PHP_EOL;
$ret .= "\t" . '}' . PHP_EOL . PHP_EOL;
}
return $ret;
}
private function write_name_method() {
$ret = "\t" . 'public function get_name() {' . PHP_EOL;
$ret .= "\t\t" . 'return \'' . $this->widget_name . '\';' . PHP_EOL;
$ret .= "\t" . '}' . PHP_EOL . PHP_EOL;
return $ret;
}
private function write_title_method( $title = 'empty_title' ) {
$ret = "\n\t" . 'public function get_title() {' . PHP_EOL;
$ret .= "\t\t" . 'return esc_html__( \'' . esc_html($title) . '\', \'' . $this->text_domain . '\' );' . PHP_EOL;
$ret .= "\t" . '}' . PHP_EOL . PHP_EOL;
return $ret;
}
private function write_categories_method( $cat = array( 'basic' ) ) {
$cat = empty( $cat ) ? array( 'basic' ) : $cat;
$joined = '\'';
$joined .= implode( '\', \'', $cat );
$joined .= '\'';
$ret = "\n\t" . 'public function get_categories() {' . PHP_EOL;
$ret .= "\t\t" . 'return [' . $joined . '];' . PHP_EOL;
$ret .= "\t" . '}' . PHP_EOL . PHP_EOL;
return $ret;
}
private function write_icon_method( $icon = 'eicon-cog' ) {
$ret = "\n\t" . 'public function get_icon() {' . PHP_EOL;
$ret .= "\t\t" . 'return \'' . $icon . '\';' . PHP_EOL;
$ret .= "\t" . '}' . PHP_EOL . PHP_EOL;
return $ret;
}
private function write_register_control_method( $conf = array() ) {
$ret = "\n\t" . 'protected function register_controls() {' . PHP_EOL;
if ( ! empty( $conf->content ) ) {
foreach ( $conf->content as $indx => $section ) {
$ret .= $this->write_section( $section->title, self::TAB_CONTENT, 'content', $indx );
if ( ! empty( $section->controls ) ) {
$ret .= $this->write_add_control( $section->controls );
}
$ret .= $this->close_section();
}
}
if ( ! empty( $conf->style ) ) {
foreach ( $conf->style as $indx => $section ) {
$ret .= $this->write_section( $section->title, self::TAB_STYLE, 'style', $indx );
if ( ! empty( $section->controls ) ) {
$ret .= $this->write_add_control( $section->controls );
}
$ret .= $this->close_section();
}
}
if ( ! empty( $conf->advanced ) ) {
foreach ( $conf->advanced as $indx => $section ) {
$ret .= $this->write_section( $section->title, self::TAB_ADVANCE, 'advance', $indx );
if ( ! empty( $section->controls ) ) {
$ret .= $this->write_add_control( $section->controls );
}
$ret .= $this->close_section();
}
}
$ret .= "\t" . '}' . PHP_EOL . PHP_EOL;
return $ret;
}
private function write_section( $label, $tab = 'Controls_Manager::TAB_CONTENT', $tab_name = 'content', $indx = '' ) {
$key = $tab_name . '_section_' . $this->widget_id . '_' . $indx;
$ret = "\n\t\t" . '$this->start_controls_section(' . PHP_EOL;
$ret .= "\t\t\t" . '\'' . $key . '\',' . PHP_EOL;
$ret .= "\t\t\t" . 'array(' . PHP_EOL;
$ret .= "\t\t\t\t" . '\'label\' => esc_html__( \'' . esc_html($label) . '\', \'' . $this->text_domain . '\' ),' . PHP_EOL;
$ret .= "\t\t\t\t" . '\'tab\' => ' . $tab . ',' . PHP_EOL;
$ret .= "\t\t\t" . ')' . PHP_EOL;
$ret .= "\t\t" . ');' . PHP_EOL;
return $ret;
}
private function write_add_control( $controls = array() ) {
$ret = '';
foreach ( $controls as $controlObj ) {
if ( $controlObj->control_group === self::CONTROL_GROUP_TYPE_SINGLE ) {
$ret .= $this->prepare_add_control( $controlObj );
} elseif ( $controlObj->control_group === self::CONTROL_GROUP_TYPE_RESPONSIVE ) {
$ret .= $this->prepare_responsive_control( $controlObj );
} elseif ( $controlObj->control_group === self::CONTROL_GROUP_TYPE_GROUPED ) {
$ret .= $this->prepare_group_control( $controlObj );
}
}
return $ret;
}
private function prepare_add_control( $controlObj ) {
$factory = new CT_Factory();
$cnt_obj = $factory->make( $controlObj->controlType, $this->text_domain );
$ret = "\n\t\t" . '$this->add_control(' . PHP_EOL;
$ret .= "\t\t\t" . '\'' . $this->control_prefix . $controlObj->key . '\',' . PHP_EOL;
$ret .= "\t\t\t" . 'array(' . PHP_EOL;
$ret .= "\t\t\t\t" . '\'label\' => esc_html__( \'' . esc_html($controlObj->label) . '\', \'' . $this->text_domain . '\' ),' . PHP_EOL;
$ret .= "\t\t\t\t" . '\'type\' => ' . $controlObj->control_type . ',' . PHP_EOL;
$ret .= $cnt_obj->start_writing_conf( $this->file_handler, $controlObj );
$ret .= "\t\t\t" . ')' . PHP_EOL;
$ret .= "\t\t" . ');' . PHP_EOL;
return $ret;
}
private function prepare_responsive_control( $controlObj ) {
$factory = new CT_Factory();
$cnt_obj = $factory->make( $controlObj->controlType, $this->text_domain, 'responsive' );
$ret = "\n\t\t" . '$this->add_responsive_control(' . PHP_EOL;
$ret .= "\t\t\t" . '\'' . $this->control_prefix . $controlObj->key . '\',' . PHP_EOL;
$ret .= "\t\t\t" . 'array(' . PHP_EOL;
$ret .= "\t\t\t\t" . '\'label\' => esc_html__( \'' . esc_html($controlObj->label) . '\', \'' . $this->text_domain . '\' ),' . PHP_EOL;
$ret .= "\t\t\t\t" . '\'type\' => ' . $controlObj->control_type . ',' . PHP_EOL;
//$cnt_obj->start_writing_conf($this->file_handler, $controlObj);
$ret .= "\t\t\t" . ')' . PHP_EOL;
$ret .= "\t\t" . ');' . PHP_EOL;
return $ret;
}
private function prepare_group_control( $controlObj ) {
$factory = new CT_Factory();
$cnt_obj = $factory->make( $controlObj->controlType, $this->text_domain, 'group' );
$ret = "\n\t\t" . '$this->add_group_control(' . PHP_EOL;
$ret .= "\t\t\t" . '' . $controlObj->control_type . ',' . PHP_EOL;
$ret .= "\t\t\t" . 'array(' . PHP_EOL;
$ret .= "\t\t\t\t" . '\'name\' => \'' . $this->control_prefix . $controlObj->key . '\',' . PHP_EOL;
$ret .= $cnt_obj->start_writing_conf( $this->file_handler, $controlObj );
$ret .= "\t\t\t" . ')' . PHP_EOL;
$ret .= "\t\t" . ');' . PHP_EOL;
return $ret;
}
private function close_section() {
return "\n\t\t" . '$this->end_controls_section();' . PHP_EOL . PHP_EOL;
}
/**
* Apply proper security escaping to widget markup
*
* @param string $markup The widget markup template
* @return string The processed markup with proper escaping
*/
private function apply_escaping($markup) {
// Array of regex patterns and their replacements
$patterns = [
// Pattern 1: URL attributes in href, src, action with array access ["url"]
'/(href|src|action)=["\']\s*<\?php\s+echo\s+isset\s*\(\s*\$settings\s*\[\s*["\']([^"\']+)["\']\s*\]\s*\[\s*["\']url["\']\s*\]\s*\)\s*\?\s*\$settings\s*\[\s*["\']([^"\']+)["\']\s*\]\s*\[\s*["\']url["\']\s*\]\s*:\s*["\'][^"\']*["\']\s*;\s*\?>/i'
=> '$1="<?php echo isset($settings["$2"]["url"]) ? esc_url($settings["$3"]["url"]) : ""; ?>"',
// Pattern 2: URL attributes in href, src, action (standard, not arrays)
'/(href|src|action)=["\']\s*<\?php\s+echo\s+isset\s*\(\s*\$settings\s*\[\s*["\']([^"\']+)["\']\s*\]\s*\)\s*\?\s*\$settings\s*\[\s*["\']([^"\']+)["\']\s*\]\s*:\s*["\'][^"\']*["\']\s*;\s*\?>/i'
=> '$1="<?php echo isset($settings["$2"]) ? esc_url($settings["$3"]) : ""; ?>"',
// Pattern 3: Non-URL attributes (class, data-*, etc.) with array access
'/(?<!href|src|action)=["\']\s*<\?php\s+echo\s+isset\s*\(\s*\$settings\s*\[\s*["\']([^"\']+)["\']\s*\]\s*\[\s*["\'](?!url)([^"\']+)["\']\s*\]\s*\)\s*\?\s*\$settings\s*\[\s*["\']([^"\']+)["\']\s*\]\s*\[\s*["\']([^"\']+)["\']\s*\]\s*:\s*["\'][^"\']*["\']\s*;\s*\?>/i'
=> '="<?php echo isset($settings["$1"]["$2"]) ? esc_attr($settings["$3"]["$4"]) : ""; ?>"',
// Pattern 4: Non-URL attributes (class, data-*, etc.) standard access
'/(?<!href|src|action)=["\']\s*<\?php\s+echo\s+isset\s*\(\s*\$settings\s*\[\s*["\']([^"\']+)["\']\s*\]\s*\)\s*\?\s*\$settings\s*\[\s*["\']([^"\']+)["\']\s*\]\s*:\s*["\'][^"\']*["\']\s*;\s*\?>/i'
=> '="<?php echo isset($settings["$1"]) ? esc_attr($settings["$2"]) : ""; ?>"',
// Pattern 5: Text content (not in attributes) - use wp_kses_post()
'/>\s*<\?php\s+echo\s+isset\s*\(\s*\$settings\s*\[\s*["\']([^"\']+)["\']\s*\]\s*\)\s*\?\s*\$settings\s*\[\s*["\']([^"\']+)["\']\s*\]\s*:\s*["\'][^"\']*["\']\s*;\s*\?>\s*</i'
=> '><?php echo isset($settings["$1"]) ? wp_kses_post($settings["$2"]) : ""; ?><',
];
// Apply patterns in order
foreach ($patterns as $pattern => $replacement) {
$markup = preg_replace($pattern, $replacement, $markup);
}
// Additional safety check for any remaining URL array references
$markup = preg_replace_callback(
'/<\?php.*?\$settings\s*\[\s*["\']([^"\']+)["\']\s*\]\s*\[\s*["\']url["\']\s*\].*?\?>/i',
function($matches) {
$fullMatch = $matches[0];
// Only modify if it doesn't already have proper array checking
if (strpos($fullMatch, 'isset') === false || strpos($fullMatch, 'esc_url') === false) {
// Extract setting key
preg_match('/\$settings\s*\[\s*["\']([^"\']+)["\']\s*\]/', $fullMatch, $keyMatches);
$key = isset($keyMatches[1]) ? $keyMatches[1] : '';
if (!empty($key)) {
return '<?php echo isset($settings["' . $key . '"]["url"]) ? esc_url($settings["' . $key . '"]["url"]) : ""; ?>';
}
}
return $fullMatch;
},
$markup
);
return $markup;
}
private function write_render_method( $markup = '' ) {
$markup = \ElementsKit_Lite\Libs\Template\Loader::instance()->replace_tags( $markup, $this->control_prefix );
// Apply security escaping
$markup = $this->apply_escaping($markup);
$ret = "\n\t" . 'protected function render() {' . PHP_EOL;
if ( ! empty( $markup ) ) {
$ret .= "\t\t" . '$settings = $this->get_settings_for_display();' . PHP_EOL . PHP_EOL;
$ret .= "\t\t" . '?>' . PHP_EOL;
$ret .= $markup . PHP_EOL;
$ret .= "\t\t" . '<?php' . PHP_EOL;
}
$ret .= "\t" . '}' . PHP_EOL . PHP_EOL;
return $ret;
}
private function close_widget_class() {
return PHP_EOL . '}' . PHP_EOL;
}
private function close_php_writer() {
fclose( $this->file_handler ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
return true;
}
/**
* @return string
*/
public function get_widget_class_name() {
return $this->widget_class_name;
}
}
@@ -0,0 +1,53 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder;
defined( 'ABSPATH' ) || exit;
class Cpt {
public function __construct() {
$this->post_type();
add_action( 'admin_menu', array( $this, 'cpt_menu' ) );
}
public function post_type() {
$labels = array(
'name' => esc_html__( 'Widgets', 'elementskit-lite' ),
'singular_name' => esc_html__( 'Widget', 'elementskit-lite' ),
'menu_name' => esc_html__( 'Widget Builder', 'elementskit-lite' ),
'name_admin_bar' => esc_html__( 'Widgets', 'elementskit-lite' ),
'add_new' => esc_html__( 'Add New', 'elementskit-lite' ),
'add_new_item' => esc_html__( 'Add New Widget', 'elementskit-lite' ),
'new_item' => esc_html__( 'New Widget', 'elementskit-lite' ),
'edit_item' => esc_html__( 'Edit Widget', 'elementskit-lite' ),
'view_item' => esc_html__( 'View Widget', 'elementskit-lite' ),
'all_items' => esc_html__( 'All Widgets', 'elementskit-lite' ),
'search_items' => esc_html__( 'Search Widgets', 'elementskit-lite' ),
'parent_item_colon' => esc_html__( 'Parent Widgets:', 'elementskit-lite' ),
'not_found' => esc_html__( 'No Widgets found.', 'elementskit-lite' ),
'not_found_in_trash' => esc_html__( 'No Widgets found in Trash.', 'elementskit-lite' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'rewrite' => false,
'show_ui' => true,
'show_in_menu' => false,
'show_in_nav_menus' => false,
'exclude_from_search' => true,
'capability_type' => 'page',
'hierarchical' => false,
'supports' => array( 'title', 'elementor' ),
);
register_post_type( 'elementskit_widget', $args );
}
public function cpt_menu() {
$link_our_new_cpt = 'edit.php?post_type=elementskit_widget';
add_submenu_page( 'elementskit', esc_html__( 'Widget Builder', 'elementskit-lite' ), esc_html__( 'Widget Builder', 'elementskit-lite' ), 'manage_options', $link_our_new_cpt );
}
}
@@ -0,0 +1,136 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder;
use ElementsKit_Lite\Modules\Widget_Builder\Controls\Widget_Writer;
defined( 'ABSPATH' ) || exit;
class Init {
private $dir;
private $url;
public function __construct() {
// get current directory path
$this->dir = dirname( __FILE__ ) . '/';
// get current module's url
$this->url = \ElementsKit_Lite::plugin_url() . 'modules/widget-builder/';
// include all necessary files
$this->include_files();
//hooks
add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts' ) );
add_action( 'add_meta_boxes', array( $this, 'register_meta_boxes' ) );
// add_action('elementor/init', [$this, 'elementor_widget_category']);
add_action( 'elementor/widgets/register', array( $this, 'register_widgets' ) );
add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'editor_css' ) );
add_action( 'elementor/frontend/after_enqueue_styles', array( $this, 'frontend_css' ) );
add_action( 'admin_init', array( $this, 'on_empty_trash_delete_files' ) );
//add_action('wp_trash_post', [$this, 'on_trash_delete_files']);
// calling necessary classess
new Api\Common();
new Cpt();
new Live_Action();
}
public function include_files() {
// include $this->dir . 'extend-controls.php';
}
public function register_widgets( $widgets_manager ) {
$widgets = get_posts(
array(
'post_type' => 'elementskit_widget',
'post_status' => 'publish',
'numberposts' => -1,
)
);
$upload = wp_upload_dir();
foreach ( $widgets as $widget ) {
$slug = 'ekit_wb_' . $widget->ID;
$dir = $upload['basedir'] . '/elementskit/custom_widgets/' . $slug . '/';
$file = $dir . 'widget.php';
$class_name = '\Elementor\Ekit_Wb_' . $widget->ID;
if ( file_exists( $file ) ) {
include $file;
$widgets_manager->register( new $class_name() );
}
}
}
public function elementor_widget_category( $widgets_manager ) {
$widgets_manager->register(
'elementskit-lite',
array(
'title' => esc_html__( 'ElementsKit Custom', 'elementskit-lite' ),
'icon' => 'fa fa-plug',
),
1
);
}
public function frontend_css() {
if ( ! is_singular( 'elementskit_widget' ) ) {
return;
}
wp_enqueue_style( 'elementskit-widget-builder-common-css', $this->url . 'assets/css/ekit-widget-builder-common.css', array(), \ElementsKit_Lite::version() );
}
public function editor_css() {
$screen = get_current_screen();
if ( $screen->id != 'elementskit_widget' ) {
return;
}
wp_enqueue_style( 'elementskit-widget-builder-common-css', $this->url . 'assets/css/ekit-widget-builder-common.css', array(), \ElementsKit_Lite::version() );
}
public function load_scripts() {
$screen = get_current_screen();
if ( $screen->id != 'elementskit_widget' ) {
return;
}
wp_enqueue_style( 'google-fonts-roboto', 'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700', array(), null ); // PHPCS:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
wp_enqueue_style( 'font-awesome', ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/all.min.css', array(), null ); // PHPCS:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
wp_enqueue_style( 'elementskit-widget-builder-editor-css', $this->url . 'assets/css/ekit-widget-builder-editor.css', array(), \ElementsKit_Lite::version() );
wp_enqueue_style( 'elementskit-widget-builder-common-css', $this->url . 'assets/css/ekit-widget-builder-common.css', array(), \ElementsKit_Lite::version() );
wp_enqueue_script( 'elementskit-widget-builder-editor-js', $this->url . 'assets/js/ekit-widget-builder-editor.js', array(), \ElementsKit_Lite::version(), true );
}
public function register_meta_boxes() {
add_meta_box( 'elementskit-widget-builder-markup', __( 'Builder', 'elementskit-lite' ), array( $this, 'metabox_display_callback' ), 'elementskit_widget' );
}
public function metabox_display_callback( $post ) {
include $this->dir . 'views/builder.php';
}
public function on_empty_trash_delete_files() {
if ( !empty( $_GET['post'] ) && !empty($_GET['_wpnonce']) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'delete-post_' . intval( $_GET['post'] ) ) ) {
$post_id = intval( $_GET['post'] );
$post_type = get_post_type( $post_id );
if ( $post_type == 'elementskit_widget' ) {
Widget_Writer::delete_widget( $post_id );
}
} elseif (
isset( $_GET['post_type'] ) && $_GET['post_type'] == 'elementskit_widget' &&
isset( $_GET['action'] ) && $_GET['action'] == -1 &&
isset( $_GET['post_status'] ) && $_GET['post_status'] == 'trash' ) {
}
}
}
@@ -0,0 +1,36 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder;
defined( 'ABSPATH' ) || exit;
class Live_Action {
private $id;
public function __construct() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We are taking the post id from the URL. The page only can access admin. So nonce verification is not required.
$this->id = ( ! isset( $_GET['post'] ) ? 0 : intval( wp_unslash( $_GET['post'] ) ) );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We are checking the page action. The page only can access admin. So nonce verification is not required.
if ( $this->id == 0 || ! isset( $_GET['action'] ) || $_GET['action'] != 'elementor' ) {
return;
}
if ( get_post_type( $this->id ) != 'elementskit_widget' ) {
return;
}
add_action( 'init', array( $this, 'reset' ) );
}
public function reset() {
update_post_meta( $this->id, '_wp_page_template', 'elementor_canvas' );
update_post_meta(
$this->id,
'_elementor_data',
'[{"id":"e3a6ad6","elType":"section","settings":[],"elements":[{"id":"77605d8","elType":"column","settings":{"_column_size":100,"_inline_size":null},"elements":[{"id":"0d8eeb3","elType":"widget","settings":{},"elements":[],"widgetType":"ekit_wb_' . $this->id . '"}],"isInner":false}],"isInner":false}]'
);
}
}
@@ -0,0 +1,22 @@
<?php
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We are taking the post id from the URL. The page only can access admin. So nonce verification is not required.
$id = ( isset( $_GET['post'] ) ? intval( wp_unslash( $_GET['post'] ) ) : 0 );
?>
<script>
var ekitWidgetBuilder = {
api: '<?php echo esc_url( get_rest_url() . 'elementskit/v1/widget-builder/' ); ?>',
pull_id: <?php echo intval( $id ); ?>,
nonce: '<?php echo esc_js( wp_create_nonce( 'wp_rest' ) ); ?>',
live_url: '<?php echo esc_url( str_replace( array( '&amp;', 'action=edit' ), array( '&', 'action=elementor' ), get_edit_post_link( $id ) ) ); ?>',
pro: <?php echo \ElementsKit_Lite::package_type() == 'pro' ? 'true' : 'false'; ?>,
assets: {
'wysiwyg': '<?php echo esc_url( $this->url . 'assets/img/wysiwyg.png' ); ?>',
'noImagePreview': '<?php echo esc_url( $this->url . 'assets/img/no-image.png' ); ?>',
'imagePreviewTrans': '<?php echo esc_url( $this->url . 'assets/img/transparent_bg.png' ); ?>'
}
};
</script>
<div id="ekitWidgetBuilderApp"></div>
@@ -0,0 +1,68 @@
<?php
namespace ElementsKit_Lite\Modules\Widget_Builder;
use ElementsKit_Lite\Modules\Widget_Builder\Controls\Widget_Writer;
defined( 'ABSPATH' ) || exit;
class Widget_File {
private static $instance;
public function get_file_path() {
$uploads = wp_upload_dir();
$upload_dir = $uploads['basedir'];
$upload_dir = $upload_dir . '/elementskit/custom_widgets';
if ( ! is_dir( $upload_dir ) ) {
wp_mkdir_p( $upload_dir );
}
return $upload_dir;
}
public static function load_filesystem() {
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
}
public function create( $wObj, $id ) {
self::load_filesystem();
global $wp_filesystem;
$writer = new Widget_Writer( $wObj, $id, 'elementskit-lite' );
$writer->start_backing( $wp_filesystem );
$writer->finish_backing( $wp_filesystem );
return true;
}
public static function get_wp_filesystem_pointer() {
self::load_filesystem();
global $wp_filesystem;
return $wp_filesystem;
}
public static function instance() {
if ( self::$instance == null ) {
self::$instance = new self();
}
return self::$instance;
}
}