Update elementor pro
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\AtomicWidgets;
|
||||
|
||||
use ElementorPro\Base\Module_Base;
|
||||
use ElementorPro\Plugin;
|
||||
use Elementor\Modules\AtomicWidgets\Module as AtomicWidgetsModule;
|
||||
use Elementor\Modules\AtomicWidgets\PropsResolver\Transformers_Registry;
|
||||
use ElementorPro\Modules\AtomicWidgets\PropTypes\Display_Conditions\Display_Conditions_Prop_Type;
|
||||
use ElementorPro\Modules\AtomicWidgets\PropTypes\Display_Conditions\Condition_Group_Prop_Type;
|
||||
use ElementorPro\Modules\AtomicWidgets\Transformers\Display_Conditions as Display_Conditions_Transformer;
|
||||
use ElementorPro\Modules\AtomicWidgets\Transformers\Condition_Group as Condition_Group_Transformer;
|
||||
use ElementorPro\License\API;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Module extends Module_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'atomic';
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
if ( ! Plugin::elementor()->experiments->is_feature_active( AtomicWidgetsModule::EXPERIMENT_NAME ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_filter(
|
||||
'elementor/atomic-widgets/props-schema',
|
||||
fn( $schema ) => $this->inject_props_schema( $schema ),
|
||||
10,
|
||||
1
|
||||
);
|
||||
|
||||
add_action(
|
||||
'elementor/atomic-widgets/settings/transformers/register',
|
||||
fn ( $transformers ) => $this->register_settings_transformers( $transformers ),
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'elementor/atomic_widgets/editor_data/element_styles',
|
||||
fn( $styles_without_custom_css, $styles ) => $this->get_license_based_custom_css_value( $styles_without_custom_css, $styles ),
|
||||
10,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
private function inject_props_schema( $schema ) {
|
||||
$display_conditions_prop_type = Display_Conditions_Prop_Type::make();
|
||||
|
||||
$components_module = 'Elementor\\Modules\\Components\\Module';
|
||||
$overridable_prop_type = 'Elementor\\Modules\\Components\\PropTypes\\Overridable_Prop_Type';
|
||||
|
||||
$is_components_experiment_active = false;
|
||||
if ( class_exists( $components_module ) ) {
|
||||
$is_components_experiment_active = Plugin::elementor()->experiments->is_feature_active( $components_module::EXPERIMENT_NAME );
|
||||
}
|
||||
|
||||
if (
|
||||
$is_components_experiment_active &&
|
||||
class_exists( $overridable_prop_type )
|
||||
) {
|
||||
$display_conditions_prop_type->meta( $overridable_prop_type::ignore() );
|
||||
}
|
||||
|
||||
$schema[ Display_Conditions_Prop_Type::get_key() ] = $display_conditions_prop_type;
|
||||
return $schema;
|
||||
}
|
||||
|
||||
private function register_settings_transformers( Transformers_Registry $transformers ): Transformers_Registry {
|
||||
$transformers->register( Display_Conditions_Prop_Type::get_key(), new Display_Conditions_Transformer() );
|
||||
$transformers->register( Condition_Group_Prop_Type::get_key(), new Condition_Group_Transformer() );
|
||||
|
||||
return $transformers;
|
||||
}
|
||||
|
||||
private function get_license_based_custom_css_value( $styles_without_custom_css, $styles ) {
|
||||
if ( $this->has_custom_css_feature_in_license() ) {
|
||||
return $styles;
|
||||
}
|
||||
|
||||
return $styles_without_custom_css;
|
||||
}
|
||||
|
||||
private function has_custom_css_feature_in_license() {
|
||||
return API::is_license_active() && API::is_licence_has_feature( 'atomic-custom-css' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AtomicWidgets\PropTypes\Display_Conditions;
|
||||
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Base\Array_Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Condition_Group_Prop_Type extends Array_Prop_Type {
|
||||
public static function get_key(): string {
|
||||
return 'condition-group';
|
||||
}
|
||||
|
||||
protected function define_item_type(): Prop_Type {
|
||||
return String_Prop_Type::make();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AtomicWidgets\PropTypes\Display_Conditions;
|
||||
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Base\Array_Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Display_Conditions_Prop_Type extends Array_Prop_Type {
|
||||
public static function get_key(): string {
|
||||
return 'display-conditions';
|
||||
}
|
||||
|
||||
protected function define_item_type(): Prop_Type {
|
||||
return Condition_Group_Prop_Type::make();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AtomicWidgets\PropTypes\Display_Conditions;
|
||||
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Base\Object_Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Page_Title_Condition_Prop_Type extends Object_Prop_Type {
|
||||
|
||||
public static function get_key(): string {
|
||||
return 'page-title-condition';
|
||||
}
|
||||
|
||||
protected function validate_value( $value ): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function define_shape(): array {
|
||||
return [
|
||||
'operator' => String_Prop_Type::make()
|
||||
->enum( [ '==', '!=' ] )
|
||||
->default( '==' )
|
||||
->required(),
|
||||
'value' => String_Prop_Type::make()
|
||||
->required(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AtomicWidgets\PropTypes\Display_Conditions;
|
||||
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Base\Object_Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Date_Time_Prop_Type;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Boolean_Prop_Type;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Time_Of_Day_Condition_Prop_Type extends Object_Prop_Type {
|
||||
|
||||
public static function get_key(): string {
|
||||
return 'time-of-day-condition';
|
||||
}
|
||||
|
||||
protected function validate_value( $value ): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function define_shape(): array {
|
||||
return [
|
||||
'operator' => String_Prop_Type::make()
|
||||
->enum( [ '==', '!=', '>', '<', '>=', '<=' ] )
|
||||
->default( '==' )
|
||||
->required(),
|
||||
'server_time' => Boolean_Prop_Type::make()
|
||||
->default( true )
|
||||
->required(),
|
||||
'value' => Date_Time_Prop_Type::make()
|
||||
->required(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AtomicWidgets\Transformers;
|
||||
|
||||
use Elementor\Modules\AtomicWidgets\PropsResolver\Props_Resolver_Context;
|
||||
use Elementor\Modules\AtomicWidgets\PropsResolver\Transformer_Base;
|
||||
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Condition_Group extends Transformer_Base {
|
||||
public function transform( $conditions, Props_Resolver_Context $context ) {
|
||||
if ( ! is_array( $conditions ) || empty( $conditions ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return array_map( function( $condition ) {
|
||||
return json_decode( $condition, true );
|
||||
}, $conditions );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AtomicWidgets\Transformers;
|
||||
|
||||
use Elementor\Modules\AtomicWidgets\PropsResolver\Props_Resolver_Context;
|
||||
use Elementor\Modules\AtomicWidgets\PropsResolver\Render_Props_Resolver;
|
||||
use Elementor\Modules\AtomicWidgets\PropsResolver\Transformer_Base;
|
||||
use ElementorPro\Modules\AtomicWidgets\PropTypes\Display_Conditions\Display_Conditions_Prop_Type;
|
||||
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Display_Conditions extends Transformer_Base {
|
||||
public function transform( $value, Props_Resolver_Context $context ) {
|
||||
return ! is_array( $value ) || empty( $value )
|
||||
? []
|
||||
: $value;
|
||||
}
|
||||
|
||||
public static function extract_from_settings( $settings ) {
|
||||
$prop_key = Display_Conditions_Prop_Type::get_key();
|
||||
|
||||
if ( ! isset( $settings[ $prop_key ]['value'] ) ) {
|
||||
return '[]';
|
||||
}
|
||||
|
||||
$params = self::create_params_from_settings( $settings );
|
||||
$resolved = Render_Props_Resolver::for_settings()->resolve( ...$params );
|
||||
|
||||
return [ json_encode( $resolved[ $prop_key ] ) ];
|
||||
}
|
||||
|
||||
private static function create_params_from_settings( $settings ) {
|
||||
$prop_key = Display_Conditions_Prop_Type::get_key();
|
||||
$prop_type = Display_Conditions_Prop_Type::make();
|
||||
$value = $settings[ $prop_key ];
|
||||
$schema = [
|
||||
$prop_key => $prop_type,
|
||||
];
|
||||
$props = [
|
||||
$prop_key => $value,
|
||||
];
|
||||
|
||||
return [ $schema, $props ];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user