| @@ -1,9 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor; |
| 3 | 3 | |
| 4 | -use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager; | |
| 5 | -use Elementor\Utils; | |
| 4 | +use Elementor\Core\Page_Assets\Data_Managers\Widgets_Css as Widgets_Css_Data_Manager; | |
| 6 | 5 | |
| 7 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | 7 | exit; // Exit if accessed directly. |
| 9 | 8 | } |
| @@ -33,10 +32,8 @@ | ||
| 33 | 32 | * @var bool |
| 34 | 33 | */ |
| 35 | 34 | protected $_has_template_content = true; |
| 36 | 35 | |
| 37 | - private $is_first_section = true; | |
| 38 | - | |
| 39 | 36 | /** |
| 40 | 37 | * Registered Runtime Widgets. |
| 41 | 38 | * |
| 42 | 39 | * Registering in runtime all widgets that are being used on the page. |
| @@ -48,8 +45,12 @@ | ||
| 48 | 45 | * @var array |
| 49 | 46 | */ |
| 50 | 47 | public static $registered_runtime_widgets = []; |
| 51 | 48 | |
| 49 | + public static $registered_inline_css_widgets = []; | |
| 50 | + | |
| 51 | + private static $widgets_css_data_manager; | |
| 52 | + | |
| 52 | 53 | /** |
| 53 | 54 | * Get element type. |
| 54 | 55 | * |
| 55 | 56 | * Retrieve the element type, in this case `widget`. |
| @@ -106,22 +107,8 @@ | ||
| 106 | 107 | return [ 'general' ]; |
| 107 | 108 | } |
| 108 | 109 | |
| 109 | 110 | /** |
| 110 | - * Get widget upsale data. | |
| 111 | - * | |
| 112 | - * Retrieve the widget promotion data. | |
| 113 | - * | |
| 114 | - * @since 3.18.0 | |
| 115 | - * @access protected | |
| 116 | - * | |
| 117 | - * @return array|null Widget promotion data. | |
| 118 | - */ | |
| 119 | - protected function get_upsale_data() { | |
| 120 | - return null; | |
| 121 | - } | |
| 122 | - | |
| 123 | - /** | |
| 124 | 111 | * Widget base constructor. |
| 125 | 112 | * |
| 126 | 113 | * Initializing the widget base class. |
| 127 | 114 | * |
| @@ -139,9 +126,9 @@ | ||
| 139 | 126 | |
| 140 | 127 | $is_type_instance = $this->is_type_instance(); |
| 141 | 128 | |
| 142 | 129 | if ( ! $is_type_instance && null === $args ) { |
| 143 | - throw new \Exception( 'An `$args` argument is required when initializing a full widget instance.' ); | |
| 130 | + throw new \Exception( '`$args` argument is required when initializing a full widget instance.' ); | |
| 144 | 131 | } |
| 145 | 132 | |
| 146 | 133 | if ( $is_type_instance ) { |
| 147 | 134 | if ( $this->has_own_method( '_register_skins', self::class ) ) { |
| @@ -183,11 +170,11 @@ | ||
| 183 | 170 | */ |
| 184 | 171 | public function get_stack( $with_common_controls = true ) { |
| 185 | 172 | $stack = parent::get_stack(); |
| 186 | 173 | |
| 187 | - if ( $with_common_controls && ! $this instanceof Widget_Common_Base ) { | |
| 188 | - /** @var Widget_Common_Base $common_widget */ | |
| 189 | - $common_widget = Plugin::$instance->widgets_manager->get_widget_types( $this->get_common_widget_name() ); | |
| 174 | + if ( $with_common_controls && 'common' !== $this->get_unique_name() ) { | |
| 175 | + /** @var Widget_Common $common_widget */ | |
| 176 | + $common_widget = Plugin::$instance->widgets_manager->get_widget_types( 'common' ); | |
| 190 | 177 | |
| 191 | 178 | $stack['controls'] = array_merge( $stack['controls'], $common_widget->get_controls() ); |
| 192 | 179 | |
| 193 | 180 | $stack['tabs'] = array_merge( $stack['tabs'], $common_widget->get_tabs_controls() ); |
| @@ -195,16 +182,8 @@ | ||
| 195 | 182 | |
| 196 | 183 | return $stack; |
| 197 | 184 | } |
| 198 | 185 | |
| 199 | - private function get_common_widget_name() { | |
| 200 | - if ( Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ) ) { | |
| 201 | - return $this->has_widget_inner_wrapper() ? 'common' : 'common-optimized'; | |
| 202 | - } | |
| 203 | - | |
| 204 | - return 'common'; | |
| 205 | - } | |
| 206 | - | |
| 207 | 186 | /** |
| 208 | 187 | * Get widget controls pointer index. |
| 209 | 188 | * |
| 210 | 189 | * Retrieve widget pointer index where the next control should be added. |
| @@ -241,21 +220,8 @@ | ||
| 241 | 220 | return true; |
| 242 | 221 | } |
| 243 | 222 | |
| 244 | 223 | /** |
| 245 | - * Hide on search. | |
| 246 | - * | |
| 247 | - * Whether to hide the widget on search in the panel or not. By default returns false. | |
| 248 | - * | |
| 249 | - * @access public | |
| 250 | - * | |
| 251 | - * @return bool Whether to hide the widget when searching for widget or not. | |
| 252 | - */ | |
| 253 | - public function hide_on_search() { | |
| 254 | - return false; | |
| 255 | - } | |
| 256 | - | |
| 257 | - /** | |
| 258 | 224 | * Start widget controls section. |
| 259 | 225 | * |
| 260 | 226 | * Used to add a new section of controls to the widget. Regular controls and |
| 261 | 227 | * skin controls. |
| @@ -271,12 +237,14 @@ | ||
| 271 | 237 | */ |
| 272 | 238 | public function start_controls_section( $section_id, array $args = [] ) { |
| 273 | 239 | parent::start_controls_section( $section_id, $args ); |
| 274 | 240 | |
| 275 | - if ( $this->is_first_section ) { | |
| 241 | + static $is_first_section = true; | |
| 242 | + | |
| 243 | + if ( $is_first_section ) { | |
| 276 | 244 | $this->register_skin_control(); |
| 277 | 245 | |
| 278 | - $this->is_first_section = false; | |
| 246 | + $is_first_section = false; | |
| 279 | 247 | } |
| 280 | 248 | } |
| 281 | 249 | |
| 282 | 250 | /** |
| @@ -300,9 +268,9 @@ | ||
| 300 | 268 | foreach ( $skins as $skin_id => $skin ) { |
| 301 | 269 | $skin_options[ $skin_id ] = $skin->get_title(); |
| 302 | 270 | } |
| 303 | 271 | |
| 304 | - // Get the first item for default value. | |
| 272 | + // Get the first item for default value | |
| 305 | 273 | $default_value = array_keys( $skin_options ); |
| 306 | 274 | $default_value = array_shift( $default_value ); |
| 307 | 275 | |
| 308 | 276 | if ( 1 >= count( $skin_options ) ) { |
| @@ -332,12 +300,12 @@ | ||
| 332 | 300 | * Register widget skins - deprecated prefixed method |
| 333 | 301 | * |
| 334 | 302 | * @since 1.7.12 |
| 335 | 303 | * @access protected |
| 336 | - * @deprecated 3.1.0 Use `register_skins()` method instead. | |
| 304 | + * @deprecated 3.1.0 | |
| 337 | 305 | */ |
| 338 | 306 | protected function _register_skins() { |
| 339 | - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'register_skins()' ); | |
| 307 | + Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', __CLASS__ . '::register_skins()' ); | |
| 340 | 308 | |
| 341 | 309 | $this->register_skins(); |
| 342 | 310 | } |
| 343 | 311 | |
| @@ -378,23 +346,10 @@ | ||
| 378 | 346 | 'keywords' => $this->get_keywords(), |
| 379 | 347 | 'categories' => $this->get_categories(), |
| 380 | 348 | 'html_wrapper_class' => $this->get_html_wrapper_class(), |
| 381 | 349 | 'show_in_panel' => $this->show_in_panel(), |
| 382 | - 'hide_on_search' => $this->hide_on_search(), | |
| 383 | - 'upsale_data' => $this->get_upsale_data(), | |
| 384 | - 'is_dynamic_content' => $this->is_dynamic_content(), | |
| 385 | - 'has_widget_inner_wrapper' => $this->has_widget_inner_wrapper(), | |
| 386 | 350 | ]; |
| 387 | 351 | |
| 388 | - if ( isset( $config['upsale_data'] ) && is_array( $config['upsale_data'] ) ) { | |
| 389 | - $filter_name = 'elementor/widgets/' . $this->get_name() . '/custom_promotion'; | |
| 390 | - $config['upsale_data'] = Filtered_Promotions_Manager::get_filtered_promotion_data( $config['upsale_data'], $filter_name, 'upgrade_url' ); | |
| 391 | - } | |
| 392 | - | |
| 393 | - if ( isset( $config['upsale_data']['image'] ) ) { | |
| 394 | - $config['upsale_data']['image'] = esc_url( $config['upsale_data']['image'] ); | |
| 395 | - } | |
| 396 | - | |
| 397 | 352 | $stack = Plugin::$instance->controls_manager->get_element_stack( $this ); |
| 398 | 353 | |
| 399 | 354 | if ( $stack ) { |
| 400 | 355 | $config['controls'] = $this->get_stack( false )['controls']; |
| @@ -400,9 +355,9 @@ | ||
| 400 | 355 | $config['controls'] = $this->get_stack( false )['controls']; |
| 401 | 356 | $config['tabs_controls'] = $this->get_tabs_controls(); |
| 402 | 357 | } |
| 403 | 358 | |
| 404 | - return array_replace_recursive( parent::get_initial_config(), $config ); | |
| 359 | + return array_merge( parent::get_initial_config(), $config ); | |
| 405 | 360 | } |
| 406 | 361 | |
| 407 | 362 | /** |
| 408 | 363 | * @since 2.3.1 |
| @@ -423,15 +378,15 @@ | ||
| 423 | 378 | * |
| 424 | 379 | * @param string $template_content Template content. |
| 425 | 380 | */ |
| 426 | 381 | protected function print_template_content( $template_content ) { |
| 427 | - if ( $this->has_widget_inner_wrapper() ) : ?> | |
| 382 | + ?> | |
| 428 | 383 | <div class="elementor-widget-container"> |
| 429 | - <?php endif; | |
| 430 | - Utils::print_unescaped_internal_string( $template_content ); | |
| 431 | - if ( $this->has_widget_inner_wrapper() ) : ?> | |
| 384 | + <?php | |
| 385 | + echo $template_content; // XSS ok. | |
| 386 | + ?> | |
| 432 | 387 | </div> |
| 433 | - <?php endif; | |
| 388 | + <?php | |
| 434 | 389 | } |
| 435 | 390 | |
| 436 | 391 | /** |
| 437 | 392 | * Parse text editor. |
| @@ -541,17 +496,18 @@ | ||
| 541 | 496 | * |
| 542 | 497 | * Used to add Light-Box-related data attributes to links that open media files. |
| 543 | 498 | * |
| 544 | 499 | * @param array|string $element The link HTML element. |
| 545 | - * @param int $id The ID of the image. | |
| 546 | - * @param string $lightbox_setting_key The setting key that dictates whether to open the image in a lightbox. | |
| 547 | - * @param string $group_id Unique ID for a group of lightbox images. | |
| 548 | - * @param bool $overwrite Optional. Whether to overwrite existing | |
| 549 | - * attribute. Default is false, not to overwrite. | |
| 500 | + * @param int $id The ID of the image | |
| 501 | + * @param string $lightbox_setting_key The setting key that dictates weather to open the image in a lightbox | |
| 502 | + * @param string $group_id Unique ID for a group of lightbox images | |
| 503 | + * @param bool $overwrite Optional. Whether to overwrite existing | |
| 504 | + * attribute. Default is false, not to overwrite. | |
| 550 | 505 | * |
| 551 | 506 | * @return Widget_Base Current instance of the widget. |
| 552 | 507 | * @since 2.9.0 |
| 553 | 508 | * @access public |
| 509 | + * | |
| 554 | 510 | */ |
| 555 | 511 | public function add_lightbox_data_attributes( $element, $id = null, $lightbox_setting_key = null, $group_id = null, $overwrite = false ) { |
| 556 | 512 | $kit = Plugin::$instance->kits_manager->get_active_kit(); |
| 557 | 513 | |
| @@ -570,19 +526,10 @@ | ||
| 570 | 526 | } |
| 571 | 527 | |
| 572 | 528 | $attributes['data-elementor-open-lightbox'] = 'yes'; |
| 573 | 529 | |
| 574 | - $action_hash_params = []; | |
| 575 | - | |
| 576 | - if ( $id ) { | |
| 577 | - $action_hash_params['id'] = $id; | |
| 578 | - $action_hash_params['url'] = wp_get_attachment_url( $id ); | |
| 579 | - } | |
| 580 | - | |
| 581 | 530 | if ( $group_id ) { |
| 582 | 531 | $attributes['data-elementor-lightbox-slideshow'] = $group_id; |
| 583 | - | |
| 584 | - $action_hash_params['slideshow'] = $group_id; | |
| 585 | 532 | } |
| 586 | 533 | |
| 587 | 534 | if ( $id ) { |
| 588 | 535 | $lightbox_image_attributes = Plugin::$instance->images_manager->get_lightbox_image_attributes( $id ); |
| @@ -595,10 +542,8 @@ | ||
| 595 | 542 | $attributes['data-elementor-lightbox-description'] = $lightbox_image_attributes['description']; |
| 596 | 543 | } |
| 597 | 544 | } |
| 598 | 545 | |
| 599 | - $attributes['data-e-action-hash'] = Plugin::instance()->frontend->create_action_hash( 'lightbox', $action_hash_params ); | |
| 600 | - | |
| 601 | 546 | $this->add_render_attribute( $element, $attributes, null, $overwrite ); |
| 602 | 547 | |
| 603 | 548 | return $this; |
| 604 | 549 | } |
| @@ -640,16 +585,19 @@ | ||
| 640 | 585 | |
| 641 | 586 | if ( empty( $widget_content ) ) { |
| 642 | 587 | return; |
| 643 | 588 | } |
| 644 | - if ( $this->has_widget_inner_wrapper() ) : ?> | |
| 589 | + ?> | |
| 645 | 590 | <div class="elementor-widget-container"> |
| 646 | - <?php endif; ?> | |
| 647 | 591 | <?php |
| 648 | 592 | if ( $this->is_widget_first_render( $this->get_group_name() ) ) { |
| 649 | 593 | $this->register_runtime_widget( $this->get_group_name() ); |
| 650 | 594 | } |
| 651 | 595 | |
| 596 | + $this->print_widget_css(); | |
| 597 | + | |
| 598 | + // get_name | |
| 599 | + | |
| 652 | 600 | /** |
| 653 | 601 | * Render widget content. |
| 654 | 602 | * |
| 655 | 603 | * Filters the widget content before it's rendered. |
| @@ -659,13 +607,13 @@ | ||
| 659 | 607 | * @param string $widget_content The content of the widget. |
| 660 | 608 | * @param Widget_Base $this The widget. |
| 661 | 609 | */ |
| 662 | 610 | $widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this ); |
| 663 | - Utils::print_unescaped_internal_string( $widget_content ); | |
| 611 | + | |
| 612 | + echo $widget_content; // XSS ok. | |
| 664 | 613 | ?> |
| 665 | - <?php if ( $this->has_widget_inner_wrapper() ) : ?> | |
| 666 | 614 | </div> |
| 667 | - <?php endif; | |
| 615 | + <?php | |
| 668 | 616 | } |
| 669 | 617 | |
| 670 | 618 | protected function is_widget_first_render( $widget_name ) { |
| 671 | 619 | return ! in_array( $widget_name, self::$registered_runtime_widgets, true ); |
| @@ -696,16 +644,8 @@ | ||
| 696 | 644 | public function render_plain_content() { |
| 697 | 645 | $this->render_content(); |
| 698 | 646 | } |
| 699 | 647 | |
| 700 | - public function render_markdown(): string { | |
| 701 | - ob_start(); | |
| 702 | - $this->render_content(); | |
| 703 | - $html = ob_get_clean(); | |
| 704 | - | |
| 705 | - return wp_strip_all_tags( $html ); | |
| 706 | - } | |
| 707 | - | |
| 708 | 648 | /** |
| 709 | 649 | * Before widget rendering. |
| 710 | 650 | * |
| 711 | 651 | * Used to add stuff before the widget `_wrapper` element. |
| @@ -787,12 +727,12 @@ | ||
| 787 | 727 | * |
| 788 | 728 | * Script tags are allowed on frontend according to the WP theme securing policy. |
| 789 | 729 | * |
| 790 | 730 | * @param string $setting |
| 791 | - * @param null $repeater_name | |
| 792 | - * @param null $index | |
| 731 | + * @param null $repeater_name | |
| 732 | + * @param null $index | |
| 793 | 733 | */ |
| 794 | - final public function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) { | |
| 734 | + final protected function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) { | |
| 795 | 735 | if ( $repeater_name ) { |
| 796 | 736 | $repeater = $this->get_settings_for_display( $repeater_name ); |
| 797 | 737 | $output = $repeater[ $index ][ $setting ]; |
| 798 | 738 | } else { |
| @@ -855,9 +795,9 @@ | ||
| 855 | 795 | * @access protected |
| 856 | 796 | * |
| 857 | 797 | * @param string $setting_key The current setting key inside the repeater item (e.g. `tab_title`). |
| 858 | 798 | * @param string $repeater_key The repeater key containing the array of all the items in the repeater (e.g. `tabs`). |
| 859 | - * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`). | |
| 799 | + * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`). | |
| 860 | 800 | * |
| 861 | 801 | * @return string The repeater setting key (e.g. `tabs.3.tab_title`). |
| 862 | 802 | */ |
| 863 | 803 | protected function get_repeater_setting_key( $setting_key, $repeater_key, $repeater_item_index ) { |
| @@ -1014,13 +954,27 @@ | ||
| 1014 | 954 | return $this->get_name(); |
| 1015 | 955 | } |
| 1016 | 956 | |
| 1017 | 957 | /** |
| 1018 | - * @param string $plugin_title Plugin's title. | |
| 1019 | - * @param string $since Plugin version widget was deprecated. | |
| 1020 | - * @param string $last Plugin version in which the widget will be removed. | |
| 1021 | - * @param string $replacement Widget replacement. | |
| 958 | + * Get Inline CSS dependencies. | |
| 959 | + * | |
| 960 | + * Retrieve a list of inline CSS dependencies that the element requires. | |
| 961 | + * | |
| 962 | + * @since 3.3.0 | |
| 963 | + * @access public | |
| 964 | + * | |
| 965 | + * @return array. | |
| 1022 | 966 | */ |
| 967 | + public function get_inline_css_depends() { | |
| 968 | + return []; | |
| 969 | + } | |
| 970 | + | |
| 971 | + /** | |
| 972 | + * @param string $plugin_title Plugin's title | |
| 973 | + * @param string $since Plugin version widget was deprecated | |
| 974 | + * @param string $last Plugin version in which the widget will be removed | |
| 975 | + * @param string $replacement Widget replacement | |
| 976 | + */ | |
| 1023 | 977 | protected function deprecated_notice( $plugin_title, $since, $last = '', $replacement = '' ) { |
| 1024 | 978 | $this->start_controls_section( |
| 1025 | 979 | 'Deprecated', |
| 1026 | 980 | [ |
| @@ -1040,22 +994,9 @@ | ||
| 1040 | 994 | ] |
| 1041 | 995 | ); |
| 1042 | 996 | |
| 1043 | 997 | $this->end_controls_section(); |
| 1044 | - } | |
| 1045 | 998 | |
| 1046 | - /** | |
| 1047 | - * Init controls. | |
| 1048 | - * | |
| 1049 | - * Reset the `is_first_section` flag to true, so when the Stacks are cleared | |
| 1050 | - * all the controls will be registered again with their skins and settings. | |
| 1051 | - * | |
| 1052 | - * @since 3.14.0 | |
| 1053 | - * @access protected | |
| 1054 | - */ | |
| 1055 | - protected function init_controls() { | |
| 1056 | - $this->is_first_section = true; | |
| 1057 | - parent::init_controls(); | |
| 1058 | 999 | } |
| 1059 | 1000 | |
| 1060 | 1001 | public function register_runtime_widget( $widget_name ) { |
| 1061 | 1002 | self::$registered_runtime_widgets[] = $widget_name; |
| @@ -1060,32 +1001,88 @@ | ||
| 1060 | 1001 | public function register_runtime_widget( $widget_name ) { |
| 1061 | 1002 | self::$registered_runtime_widgets[] = $widget_name; |
| 1062 | 1003 | } |
| 1063 | 1004 | |
| 1064 | - /** | |
| 1065 | - * Mark widget as deprecated. | |
| 1066 | - * | |
| 1067 | - * Use `get_deprecation_message()` method to print the message control at specific location in register_controls(). | |
| 1068 | - * | |
| 1069 | - * @param string $version The version of Elementor that deprecated the widget. | |
| 1070 | - * @param string $message A message regarding the deprecation. | |
| 1071 | - * @param string $replacement The widget that should be used instead. | |
| 1072 | - */ | |
| 1073 | - protected function add_deprecation_message( $version, $message, $replacement ) { | |
| 1074 | - // Expose the config for handling in JS. | |
| 1075 | - $this->set_config( 'deprecation', [ | |
| 1076 | - 'version' => $version, | |
| 1077 | - 'message' => $message, | |
| 1078 | - 'replacement' => $replacement, | |
| 1079 | - ] ); | |
| 1005 | + public function get_widget_css_config( $widget_name ) { | |
| 1006 | + $direction = is_rtl() ? '-rtl' : ''; | |
| 1080 | 1007 | |
| 1081 | - $this->add_control( | |
| 1082 | - 'deprecation_message', | |
| 1083 | - [ | |
| 1084 | - 'type' => Controls_Manager::ALERT, | |
| 1085 | - 'alert_type' => 'info', | |
| 1086 | - 'content' => $message, | |
| 1087 | - 'separator' => 'after', | |
| 1088 | - ] | |
| 1089 | - ); | |
| 1008 | + $css_file_path = 'css/widget-' . $widget_name . $direction . '.min.css'; | |
| 1009 | + | |
| 1010 | + return [ | |
| 1011 | + 'key' => $widget_name, | |
| 1012 | + 'version' => ELEMENTOR_VERSION, | |
| 1013 | + 'file_path' => ELEMENTOR_ASSETS_PATH . $css_file_path, | |
| 1014 | + 'data' => [ | |
| 1015 | + 'file_url' => ELEMENTOR_ASSETS_URL . $css_file_path, | |
| 1016 | + ], | |
| 1017 | + ]; | |
| 1018 | + } | |
| 1019 | + | |
| 1020 | + public function get_css_config() { | |
| 1021 | + return $this->get_widget_css_config( $this->get_group_name() ); | |
| 1022 | + } | |
| 1023 | + | |
| 1024 | + private function get_widget_css() { | |
| 1025 | + $widgets_css_data_manager = $this->get_widgets_css_data_manager(); | |
| 1026 | + | |
| 1027 | + $widgets_list = $this->get_inline_css_depends(); | |
| 1028 | + | |
| 1029 | + $widgets_list[] = $this->get_group_name(); | |
| 1030 | + | |
| 1031 | + $widget_css = ''; | |
| 1032 | + | |
| 1033 | + foreach ( $widgets_list as $widget_data ) { | |
| 1034 | + $widget_name = isset( $widget_data['name'] ) ? $widget_data['name'] : $widget_data; | |
| 1035 | + | |
| 1036 | + if ( ! in_array( $widget_name, self::$registered_inline_css_widgets, true ) ) { | |
| 1037 | + if ( $this->get_group_name() === $widget_name ) { | |
| 1038 | + $config = $this->get_css_config(); | |
| 1039 | + } else { | |
| 1040 | + /** | |
| 1041 | + * The core-dependency allowing to create a dependency specifically with the core widgets. | |
| 1042 | + * Otherwise, the config will be taken from the class that inherits from Widget_Base. | |
| 1043 | + */ | |
| 1044 | + $is_core_dependency = isset( $widget_data['is_core_dependency'] ) ? true : false; | |
| 1045 | + | |
| 1046 | + $config = $is_core_dependency ? self::get_widget_css_config( $widget_name ) : $this->get_widget_css_config( $widget_name ); | |
| 1047 | + } | |
| 1048 | + | |
| 1049 | + $widget_css .= $widgets_css_data_manager->get_asset_data( $config ); | |
| 1050 | + | |
| 1051 | + self::$registered_inline_css_widgets[] = $widget_name; | |
| 1052 | + } | |
| 1053 | + } | |
| 1054 | + | |
| 1055 | + return $widget_css; | |
| 1056 | + | |
| 1057 | + } | |
| 1058 | + | |
| 1059 | + private function is_inline_css_mode() { | |
| 1060 | + static $is_active; | |
| 1061 | + | |
| 1062 | + if ( null === $is_active ) { | |
| 1063 | + $is_edit_mode = Plugin::$instance->editor->is_edit_mode(); | |
| 1064 | + $is_preview_mode = Plugin::$instance->preview->is_preview_mode(); | |
| 1065 | + $is_optimized_mode = Plugin::$instance->experiments->is_feature_active( 'e_optimized_css_loading' ); | |
| 1066 | + | |
| 1067 | + $is_active = ( Utils::is_script_debug() || $is_edit_mode || $is_preview_mode || ! $is_optimized_mode ) ? false : true; | |
| 1068 | + } | |
| 1069 | + | |
| 1070 | + return $is_active; | |
| 1071 | + } | |
| 1072 | + | |
| 1073 | + private function print_widget_css() { | |
| 1074 | + if ( ! $this->is_inline_css_mode() ) { | |
| 1075 | + return; | |
| 1076 | + } | |
| 1077 | + | |
| 1078 | + Utils::print_unescaped_internal_string( $this->get_widget_css() ); | |
| 1079 | + } | |
| 1080 | + | |
| 1081 | + private function get_widgets_css_data_manager() { | |
| 1082 | + if ( ! self::$widgets_css_data_manager ) { | |
| 1083 | + self::$widgets_css_data_manager = new Widgets_Css_Data_Manager(); | |
| 1084 | + } | |
| 1085 | + | |
| 1086 | + return self::$widgets_css_data_manager; | |
| 1090 | 1087 | } |
| 1091 | 1088 | } |