PluginProbe
Elementor Website Builder – more than just a page builder / 3.16.2
Elementor Website Builder – more than just a page builder v3.16.2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | includes/managers/controls.php +30 -253 4.2.0-dev23.16.2 View file →
@@ -1,9 +1,7 @@
1 1 <?php
2 2 namespace Elementor;
3 3
4 -use Elementor\Core\Frontend\Performance;
5 -
6 4 if ( ! defined( 'ABSPATH' ) ) {
7 5 exit; // Exit if accessed directly.
8 6 }
9 7
@@ -93,23 +91,13 @@
93 91 */
94 92 const RAW_HTML = 'raw_html';
95 93
96 94 /**
97 - * Notice control.
98 - */
99 - const NOTICE = 'notice';
100 -
101 - /**
102 95 * Deprecated Notice control.
103 96 */
104 97 const DEPRECATED_NOTICE = 'deprecated_notice';
105 98
106 99 /**
107 - * Alert control.
108 - */
109 - const ALERT = 'alert';
110 -
111 - /**
112 100 * Popover Toggle control.
113 101 */
114 102 const POPOVER_TOGGLE = 'popover_toggle';
115 103
@@ -158,13 +146,8 @@
158 146 */
159 147 const CHOOSE = 'choose';
160 148
161 149 /**
162 - * Visual_Choice control.
163 - */
164 - const VISUAL_CHOICE = 'visual_choice';
165 -
166 - /**
167 150 * WYSIWYG control.
168 151 */
169 152 const WYSIWYG = 'wysiwyg';
170 153
@@ -417,10 +400,8 @@
417 400 self::TAB,
418 401 self::TABS,
419 402 self::DIVIDER,
420 403 self::DEPRECATED_NOTICE,
421 - self::ALERT,
422 - self::NOTICE,
423 404
424 405 self::COLOR,
425 406 self::MEDIA,
426 407 self::SLIDER,
@@ -425,9 +406,8 @@
425 406 self::MEDIA,
426 407 self::SLIDER,
427 408 self::DIMENSIONS,
428 409 self::CHOOSE,
429 - self::VISUAL_CHOICE,
430 410 self::WYSIWYG,
431 411 self::CODE,
432 412 self::FONT,
433 413 self::IMAGE_DIMENSIONS,
@@ -494,14 +474,14 @@
494 474 *
495 475 * @param Controls_Manager $this The controls manager.
496 476 */
497 477 // TODO: Uncomment when Pro uses the new hook.
498 - // Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->do_deprecated_action(
499 - // 'elementor/controls/controls_registered',
500 - // [ $this ],
501 - // '3.5.0',
502 - // 'elementor/controls/register'
503 - // );
478 + //Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->do_deprecated_action(
479 + // 'elementor/controls/controls_registered',
480 + // [ $this ],
481 + // '3.5.0',
482 + // 'elementor/controls/register'
483 + //);
504 484
505 485 do_action( 'elementor/controls/controls_registered', $this );
506 486
507 487 /**
@@ -531,13 +511,13 @@
531 511 * current instance.
532 512 */
533 513 public function register_control( $control_id, Base_Control $control_instance ) {
534 514 // TODO: Uncomment when Pro uses the new hook.
535 - // Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
536 - // __METHOD__,
537 - // '3.5.0',
538 - // 'register()'
539 - // );
515 + //Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
516 + // __METHOD__,
517 + // '3.5.0',
518 + // 'register()'
519 + //);
540 520
541 521 $this->register( $control_instance, $control_id );
542 522 }
543 523
@@ -765,10 +745,8 @@
765 745
766 746 $this->stacks[ $stack_id ] = [
767 747 'tabs' => [],
768 748 'controls' => [],
769 - 'style_controls' => [],
770 - 'responsive_control_duplication_mode' => Plugin::$instance->breakpoints->get_responsive_control_duplication_mode(),
771 749 ];
772 750 }
773 751
774 752 /**
@@ -806,13 +784,8 @@
806 784 'overwrite' => false,
807 785 'index' => null,
808 786 ];
809 787
810 - $control_type = 'controls';
811 - if ( Performance::should_optimize_controls() && $this->is_style_control( $control_data ) ) {
812 - $control_type = 'style_controls';
813 - }
814 -
815 788 $options = array_merge( $default_options, $options );
816 789
817 790 $default_args = [
818 791 'type' => self::TEXT,
@@ -829,17 +802,8 @@
829 802 _doing_it_wrong( sprintf( '%1$s::%2$s', __CLASS__, __FUNCTION__ ), sprintf( 'Control type "%s" not found.', esc_html( $control_data['type'] ) ), '1.0.0' );
830 803 return false;
831 804 }
832 805
833 - if ( $control_type_instance instanceof Has_Validation ) {
834 - try {
835 - $control_type_instance->validate( $control_data );
836 - } catch ( \Exception $e ) {
837 - _doing_it_wrong( sprintf( '%1$s::%2$s', __CLASS__, __FUNCTION__ ), esc_html( $e->getMessage() ), '3.23.0' );
838 - return false;
839 - }
840 - }
841 -
842 806 if ( $control_type_instance instanceof Base_Data_Control ) {
843 807 $control_default_value = $control_type_instance->get_default_value();
844 808
845 809 if ( is_array( $control_default_value ) ) {
@@ -850,9 +814,9 @@
850 814 }
851 815
852 816 $stack_id = $element->get_unique_name();
853 817
854 - if ( ! $options['overwrite'] && isset( $this->stacks[ $stack_id ][ $control_type ][ $control_id ] ) ) {
818 + if ( ! $options['overwrite'] && isset( $this->stacks[ $stack_id ]['controls'][ $control_id ] ) ) {
855 819 _doing_it_wrong( sprintf( '%1$s::%2$s', __CLASS__, __FUNCTION__ ), sprintf( 'Cannot redeclare control with same name "%s".', esc_html( $control_id ) ), '1.0.0' );
856 820
857 821 return false;
858 822 }
@@ -864,18 +828,18 @@
864 828 }
865 829
866 830 $this->stacks[ $stack_id ]['tabs'][ $control_data['tab'] ] = $tabs[ $control_data['tab'] ];
867 831
868 - $this->stacks[ $stack_id ][ $control_type ][ $control_id ] = $control_data;
832 + $this->stacks[ $stack_id ]['controls'][ $control_id ] = $control_data;
869 833
870 834 if ( null !== $options['index'] ) {
871 - $controls = $this->stacks[ $stack_id ][ $control_type ];
835 + $controls = $this->stacks[ $stack_id ]['controls'];
872 836
873 837 $controls_keys = array_keys( $controls );
874 838
875 839 array_splice( $controls_keys, $options['index'], 0, $control_id );
876 840
877 - $this->stacks[ $stack_id ][ $control_type ] = array_merge( array_flip( $controls_keys ), $controls );
841 + $this->stacks[ $stack_id ]['controls'] = array_merge( array_flip( $controls_keys ), $controls );
878 842 }
879 843
880 844 return true;
881 845 }
@@ -887,9 +851,9 @@
887 851 *
888 852 * @since 1.0.0
889 853 * @access public
890 854 *
891 - * @param string $stack_id Stack ID.
855 + * @param string $stack_id Stack ID.
892 856 * @param array|string $control_id The ID of the control to remove.
893 857 *
894 858 * @return bool|\WP_Error True if the stack was removed, False otherwise.
895 859 */
@@ -912,9 +876,8 @@
912 876 }
913 877
914 878 /**
915 879 * Has Stacks Cache Been Cleared.
916 - *
917 880 * @since 3.13.0
918 881 * @access public
919 882 * @return bool True if the CSS requires to clear the controls stack cache, False otherwise.
920 883 */
@@ -924,9 +887,8 @@
924 887
925 888 /**
926 889 * Clear stack.
927 890 * This method clears the stack.
928 - *
929 891 * @since 3.13.0
930 892 * @access public
931 893 */
932 894 public function clear_stack_cache() {
@@ -951,19 +913,13 @@
951 913 *
952 914 * @return array|\WP_Error The control, or an error.
953 915 */
954 916 public function get_control_from_stack( $stack_id, $control_id ) {
955 - $stack_data = $this->get_stacks( $stack_id );
956 -
957 - if ( ! empty( $stack_data['controls'][ $control_id ] ) ) {
958 - return $stack_data['controls'][ $control_id ];
917 + if ( empty( $this->stacks[ $stack_id ]['controls'][ $control_id ] ) ) {
918 + return new \WP_Error( 'Cannot get a not-exists control.' );
959 919 }
960 920
961 - if ( ! empty( $stack_data['style_controls'][ $control_id ] ) ) {
962 - return $stack_data['style_controls'][ $control_id ];
963 - }
964 -
965 - return new \WP_Error( 'Cannot get a not-exists control.' );
921 + return $this->stacks[ $stack_id ]['controls'][ $control_id ];
966 922 }
967 923
968 924 /**
969 925 * Update control in stack.
@@ -1036,9 +992,9 @@
1036 992 * @access public
1037 993 *
1038 994 * @param Controls_Stack $controls_stack Controls stack.
1039 995 *
1040 - * @return null|array Stack data if it exists, `null` otherwise.
996 + * @return null|array Stack data if it exist, `null` otherwise.
1041 997 */
1042 998 public function get_element_stack( Controls_Stack $controls_stack ) {
1043 999 $stack_id = $controls_stack->get_unique_name();
1044 1000
@@ -1045,13 +1001,8 @@
1045 1001 if ( ! isset( $this->stacks[ $stack_id ] ) ) {
1046 1002 return null;
1047 1003 }
1048 1004
1049 - if ( $this->should_clean_stack( $this->stacks[ $stack_id ] ) ) {
1050 - $this->delete_stack( $controls_stack );
1051 - return null;
1052 - }
1053 -
1054 1005 return $this->stacks[ $stack_id ];
1055 1006 }
1056 1007
1057 1008 /**
@@ -1064,10 +1015,11 @@
1064 1015 * @since 1.0.0
1065 1016 * @access public
1066 1017 *
1067 1018 * @param Controls_Stack $controls_stack .
1068 - * @param string $tab
1069 - * @param array $additional_messages
1019 + * @param string $tab
1020 + * @param array $additional_messages
1021 + *
1070 1022 */
1071 1023 public function add_custom_css_controls( Controls_Stack $controls_stack, $tab = self::TAB_ADVANCED, $additional_messages = [] ) {
1072 1024 $controls_stack->start_controls_section(
1073 1025 'section_custom_css_pro',
@@ -1107,10 +1059,10 @@
1107 1059 * version of elementor uses this method to display an upgrade message to
1108 1060 * Elementor Pro.
1109 1061 *
1110 1062 * @param Controls_Stack $controls_stack .
1111 - * @param string $tab
1112 - * @param array $additional_messages
1063 + * @param string $tab
1064 + * @param array $additional_messages
1113 1065 *
1114 1066 * @return void
1115 1067 */
1116 1068 public function add_page_transitions_controls( Controls_Stack $controls_stack, $tab = self::TAB_ADVANCED, $additional_messages = [] ) {
@@ -1148,9 +1100,9 @@
1148 1100 public function get_teaser_template( $texts ) {
1149 1101 ob_start();
1150 1102 ?>
1151 1103 <div class="elementor-nerd-box">
1152 - <img class="elementor-nerd-box-icon" src="<?php echo esc_url( ELEMENTOR_ASSETS_URL . 'images/go-pro.svg' ); ?>" loading="lazy" alt="<?php echo esc_attr__( 'Upgrade', 'elementor' ); ?>" />
1104 + <img class="elementor-nerd-box-icon" src="<?php echo esc_url( ELEMENTOR_ASSETS_URL . 'images/go-pro.svg' ); ?>" loading="lazy" />
1153 1105 <div class="elementor-nerd-box-title"><?php Utils::print_unescaped_internal_string( $texts['title'] ); ?></div>
1154 1106 <?php foreach ( $texts['messages'] as $message ) { ?>
1155 1107 <div class="elementor-nerd-box-message"><?php Utils::print_unescaped_internal_string( $message ); ?></div>
1156 1108 <?php }
@@ -1191,19 +1143,19 @@
1191 1143 * This method adds a new control for the "Custom Attributes" feature. The free
1192 1144 * version of elementor uses this method to display an upgrade message to
1193 1145 * Elementor Pro.
1194 1146 *
1195 - * @param Controls_Stack $controls_stack .
1196 - * @param string $tab
1197 1147 * @since 2.8.3
1198 1148 * @access public
1149 + *
1150 + * @param Controls_Stack $controls_stack.
1199 1151 */
1200 - public function add_custom_attributes_controls( Controls_Stack $controls_stack, string $tab = self::TAB_ADVANCED ) {
1152 + public function add_custom_attributes_controls( Controls_Stack $controls_stack ) {
1201 1153 $controls_stack->start_controls_section(
1202 1154 'section_custom_attributes_pro',
1203 1155 [
1204 1156 'label' => esc_html__( 'Attributes', 'elementor' ),
1205 - 'tab' => $tab,
1157 + 'tab' => self::TAB_ADVANCED,
1206 1158 ]
1207 1159 );
1208 1160
1209 1161 $controls_stack->add_control(
@@ -1220,181 +1172,6 @@
1220 1172 ]
1221 1173 );
1222 1174
1223 1175 $controls_stack->end_controls_section();
1224 - }
1225 -
1226 - /**
1227 - * Check if a stack should be cleaned by the current responsive control duplication mode.
1228 - *
1229 - * @param array $stack
1230 - * @return bool
1231 - */
1232 - private function should_clean_stack( $stack ): bool {
1233 - if ( ! isset( $stack['responsive_control_duplication_mode'] ) ) {
1234 - return false;
1235 - }
1236 -
1237 - $stack_duplication_mode = $stack['responsive_control_duplication_mode'];
1238 -
1239 - // This array provides a convenient way to map human-readable mode names to numeric values for comparison.
1240 - // If the current stack's mode is greater than or equal to the current mode, then we shouldn't clean the stack.
1241 - $modes = [
1242 - 'off' => 1,
1243 - 'dynamic' => 2,
1244 - 'on' => 3,
1245 - ];
1246 -
1247 - if ( ! isset( $modes[ $stack_duplication_mode ] ) ) {
1248 - return false;
1249 - }
1250 -
1251 - $current_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode();
1252 -
1253 - if ( $modes[ $stack_duplication_mode ] >= $modes[ $current_duplication_mode ] ) {
1254 - return false;
1255 - }
1256 -
1257 - return true;
1258 - }
1259 -
1260 - public function add_display_conditions_controls( Controls_Stack $controls_stack ) {
1261 - if ( Utils::has_pro() ) {
1262 - return;
1263 - }
1264 -
1265 - ob_start();
1266 - ?>
1267 - <div class="e-control-display-conditions-promotion__wrapper">
1268 - <div class="e-control-display-conditions-promotion__description">
1269 - <span class="e-control-display-conditions-promotion__text">
1270 - <?php echo esc_html__( 'Display Conditions', 'elementor' ); ?>
1271 - </span>
1272 - <span class="e-control-display-conditions-promotion__lock-wrapper">
1273 - <i class="eicon-upgrade-crown-full e-control-display-conditions-promotion"></i>
1274 - </span>
1275 - </div>
1276 - <i class="eicon-flow e-control-display-conditions-promotion"></i>
1277 - </div>
1278 - <?php
1279 - $control_template = ob_get_clean();
1280 -
1281 - $controls_stack->add_control(
1282 - 'display_conditions_pro',
1283 - [
1284 - 'type' => self::RAW_HTML,
1285 - 'separator' => 'before',
1286 - 'raw' => $control_template,
1287 - ]
1288 - );
1289 - }
1290 -
1291 - public function add_motion_effects_promotion_control( Controls_Stack $controls_stack ) {
1292 - if ( Utils::has_pro() ) {
1293 - return;
1294 - }
1295 -
1296 - $controls_stack->add_control(
1297 - 'scrolling_effects_pro',
1298 - [
1299 - 'type' => self::RAW_HTML,
1300 - 'separator' => 'before',
1301 - 'raw' => $this->promotion_switcher_control( esc_html__( 'Scrolling Effects', 'elementor' ), 'scrolling-effects' ),
1302 - ]
1303 - );
1304 -
1305 - $controls_stack->add_control(
1306 - 'mouse_effects_pro',
1307 - [
1308 - 'type' => self::RAW_HTML,
1309 - 'separator' => 'before',
1310 - 'raw' => $this->promotion_switcher_control( esc_html__( 'Mouse Effects', 'elementor' ), 'mouse-effects' ),
1311 - ]
1312 - );
1313 -
1314 - $controls_stack->add_control(
1315 - 'sticky_pro',
1316 - [
1317 - 'type' => self::RAW_HTML,
1318 - 'separator' => 'before',
1319 - 'raw' => $this->promotion_select_control( esc_html__( 'Sticky', 'elementor' ), 'sticky-effects' ),
1320 - ]
1321 - );
1322 -
1323 - $controls_stack->add_control(
1324 - 'motion_effects_promotion_divider',
1325 - [
1326 - 'type' => self::DIVIDER,
1327 - ]
1328 - );
1329 - }
1330 -
1331 - private function promotion_switcher_control( $title, $id ): string {
1332 - return '<div class="elementor-control-type-switcher elementor-label-inline e-control-motion-effects-promotion__wrapper">
1333 - <div class="elementor-control-content">
1334 - <div class="elementor-control-field">
1335 - <label>
1336 - ' . $title . '
1337 - </label>
1338 - <span class="e-control-motion-effects-promotion__lock-wrapper">
1339 - <i class="eicon-upgrade-crown-full"></i>
1340 - </span>
1341 - <div class="elementor-control-input-wrapper">
1342 - <label class="elementor-switch elementor-control-unit-2 e-control-' . $id . '-promotion">
1343 - <input type="checkbox" class="elementor-switch-input" disabled>
1344 - <span class="elementor-switch-label" data-off="Off"></span>
1345 - <span class="elementor-switch-handle"></span>
1346 - </label>
1347 - </div>
1348 - </div>
1349 - </div>
1350 - </div>';
1351 - }
1352 -
1353 - private function promotion_select_control( $title, $id ): string {
1354 - return '<div class="elementor-control-type-select elementor-label-inline e-control-motion-effects-promotion__wrapper">
1355 - <div class="elementor-control-content">
1356 - <div class="elementor-control-field ">
1357 - <label for="sticky-motion-effect-pro">
1358 - ' . $title . '
1359 - </label>
1360 - <span class="e-control-motion-effects-promotion__lock-wrapper">
1361 - <i class="eicon-upgrade-crown-full"></i>
1362 - </span>
1363 - <div class="elementor-control-input-wrapper elementor-control-unit-5 e-control-' . $id . '-promotion">
1364 - <div class="select-promotion elementor-control-unit-5">' . esc_html__( 'None', 'elementor' ) . '</div>
1365 - </div>
1366 - </div>
1367 - </div>
1368 - </div>';
1369 - }
1370 -
1371 - private function is_style_control( $control_data ): bool {
1372 - $frontend_available = $control_data['frontend_available'] ?? false;
1373 - if ( $frontend_available ) {
1374 - return false;
1375 - }
1376 -
1377 - if ( ! empty( $control_data['control_type'] ) && 'content' === $control_data['control_type'] ) {
1378 - return false;
1379 - }
1380 -
1381 - if ( ! empty( $control_data['prefix_class'] ) ) {
1382 - return false;
1383 - }
1384 -
1385 - $render_type = $control_data['render_type'] ?? '';
1386 - if ( 'template' === $render_type ) {
1387 - return false;
1388 - }
1389 -
1390 - if ( 'ui' === $render_type ) {
1391 - return true;
1392 - }
1393 -
1394 - if ( ! empty( $control_data['selectors'] ) ) {
1395 - return true;
1396 - }
1397 -
1398 - return false;
1399 1176 }
1400 1177 }