| 1 |
<?php |
| 2 |
// TODO: Delete this file in v3.27.0 - It is not in use anymore [ED-15717]. |
| 3 |
namespace Elementor\Core\Files\CSS; |
| 4 |
|
| 5 |
use Elementor\Core\Kits\Manager; |
| 6 |
use Elementor\Plugin; |
| 7 |
use Elementor\Settings; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Elementor global CSS file. |
| 15 |
* |
| 16 |
* Elementor CSS file handler class is responsible for generating the global CSS |
| 17 |
* file. |
| 18 |
* |
| 19 |
* @since 1.2.0 |
| 20 |
*/ |
| 21 |
class Global_CSS extends Base { |
| 22 |
|
| 23 |
/** |
| 24 |
* Elementor global CSS file handler ID. |
| 25 |
*/ |
| 26 |
const FILE_HANDLER_ID = 'elementor-global'; |
| 27 |
|
| 28 |
const META_KEY = '_elementor_global_css'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Get CSS file name. |
| 32 |
* |
| 33 |
* Retrieve the CSS file name. |
| 34 |
* |
| 35 |
* @since 1.6.0 |
| 36 |
* @access public |
| 37 |
* |
| 38 |
* @return string CSS file name. |
| 39 |
*/ |
| 40 |
public function get_name() { |
| 41 |
return 'global'; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Get file handle ID. |
| 46 |
* |
| 47 |
* Retrieve the handle ID for the global post CSS file. |
| 48 |
* |
| 49 |
* @since 1.2.0 |
| 50 |
* @access protected |
| 51 |
* |
| 52 |
* @return string CSS file handle ID. |
| 53 |
*/ |
| 54 |
protected function get_file_handle_id() { |
| 55 |
return self::FILE_HANDLER_ID; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Render CSS. |
| 60 |
* |
| 61 |
* Parse the CSS for all the widgets and all the scheme controls. |
| 62 |
* |
| 63 |
* @since 1.2.0 |
| 64 |
* @access protected |
| 65 |
*/ |
| 66 |
protected function render_css() { |
| 67 |
$this->render_schemes_and_globals_css(); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Get inline dependency. |
| 72 |
* |
| 73 |
* Retrieve the name of the stylesheet used by `wp_add_inline_style()`. |
| 74 |
* |
| 75 |
* @since 1.2.0 |
| 76 |
* @access protected |
| 77 |
* |
| 78 |
* @return string Name of the stylesheet. |
| 79 |
*/ |
| 80 |
protected function get_inline_dependency() { |
| 81 |
return 'elementor-frontend'; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Is update required. |
| 86 |
* |
| 87 |
* Whether the CSS requires an update. When there are new schemes or settings |
| 88 |
* updates. |
| 89 |
* |
| 90 |
* @since 1.2.0 |
| 91 |
* @access protected |
| 92 |
* |
| 93 |
* @return bool True if the CSS requires an update, False otherwise. |
| 94 |
*/ |
| 95 |
protected function is_update_required() { |
| 96 |
return $this->get_meta( 'time' ) < get_option( Settings::UPDATE_TIME_FIELD ); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Render schemes CSS. |
| 101 |
* |
| 102 |
* Parse the CSS for all the widgets and all the scheme controls. |
| 103 |
* |
| 104 |
* @since 1.2.0 |
| 105 |
* @access private |
| 106 |
*/ |
| 107 |
private function render_schemes_and_globals_css() { |
| 108 |
$elementor = Plugin::$instance; |
| 109 |
|
| 110 |
/** @var Manager $module */ |
| 111 |
$kits_manager = Plugin::$instance->kits_manager; |
| 112 |
$custom_colors_enabled = $kits_manager->is_custom_colors_enabled(); |
| 113 |
$custom_typography_enabled = $kits_manager->is_custom_typography_enabled(); |
| 114 |
|
| 115 |
// If both default colors and typography are disabled, there is no need to render schemes and default global css. |
| 116 |
if ( ! $custom_colors_enabled && ! $custom_typography_enabled ) { |
| 117 |
return; |
| 118 |
} |
| 119 |
|
| 120 |
foreach ( $elementor->widgets_manager->get_widget_types() as $widget ) { |
| 121 |
$controls = $widget->get_controls(); |
| 122 |
|
| 123 |
$global_controls = []; |
| 124 |
|
| 125 |
$global_values['__globals__'] = []; |
| 126 |
|
| 127 |
foreach ( $controls as $control ) { |
| 128 |
$is_color_control = 'color' === $control['type']; |
| 129 |
$is_typography_control = isset( $control['groupType'] ) && 'typography' === $control['groupType']; |
| 130 |
|
| 131 |
// If it is a color/typography control and default colors/typography are disabled, |
| 132 |
// don't add the default CSS. |
| 133 |
if ( ( $is_color_control && ! $custom_colors_enabled ) || ( $is_typography_control && ! $custom_typography_enabled ) ) { |
| 134 |
continue; |
| 135 |
} |
| 136 |
|
| 137 |
$global_control = $control; |
| 138 |
|
| 139 |
// Handle group controls that don't have a default global property. |
| 140 |
if ( ! empty( $control['groupType'] ) ) { |
| 141 |
$global_control = $controls[ $control['groupPrefix'] . $control['groupType'] ]; |
| 142 |
} |
| 143 |
|
| 144 |
// If the control has a default global defined, add it to the globals array |
| 145 |
// that is used in add_control_rules. |
| 146 |
if ( ! empty( $control['global']['default'] ) ) { |
| 147 |
$global_values['__globals__'][ $control['name'] ] = $global_control['global']['default']; |
| 148 |
} |
| 149 |
|
| 150 |
if ( ! empty( $global_control['global']['default'] ) ) { |
| 151 |
$global_controls[] = $control; |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
foreach ( $global_controls as $control ) { |
| 156 |
$this->add_control_rules( $control, $controls, function( $control ) {}, [ '{{WRAPPER}}' ], [ '.elementor-widget-' . $widget->get_name() ], $global_values ); |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
|