PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.0
Elementor Website Builder – more than just a page builder v3.1.0
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
elementor / core / files / css / post.php

post.php in Elementor Website Builder – more than just a page builder 3.1.0, at core/files/css/post.php

311 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Files\CSS;
3
4 use Elementor\Base_Data_Control;
5 use Elementor\Control_Repeater;
6 use Elementor\Controls_Stack;
7 use Elementor\Element_Base;
8 use Elementor\Plugin;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 /**
15 * Elementor post CSS file.
16 *
17 * Elementor CSS file handler class is responsible for generating the single
18 * post CSS file.
19 *
20 * @since 1.2.0
21 */
22 class Post extends Base {
23
24 /**
25 * Elementor post CSS file prefix.
26 */
27 const FILE_PREFIX = 'post-';
28
29 const META_KEY = '_elementor_css';
30
31 /**
32 * Post ID.
33 *
34 * Holds the current post ID.
35 *
36 * @var int
37 */
38 private $post_id;
39
40 protected function is_global_parsing_supported() {
41 return true;
42 }
43
44 /**
45 * Post CSS file constructor.
46 *
47 * Initializing the CSS file of the post. Set the post ID and initiate the stylesheet.
48 *
49 * @since 1.2.0
50 * @access public
51 *
52 * @param int $post_id Post ID.
53 */
54 public function __construct( $post_id ) {
55 $this->post_id = $post_id;
56
57 parent::__construct( static::FILE_PREFIX . $post_id . '.css' );
58 }
59
60 /**
61 * Get CSS file name.
62 *
63 * Retrieve the CSS file name.
64 *
65 * @since 1.6.0
66 * @access public
67 *
68 * @return string CSS file name.
69 */
70 public function get_name() {
71 return 'post';
72 }
73
74 /**
75 * Get post ID.
76 *
77 * Retrieve the ID of current post.
78 *
79 * @since 1.2.0
80 * @access public
81 *
82 * @return int Post ID.
83 */
84 public function get_post_id() {
85 return $this->post_id;
86 }
87
88 /**
89 * Get unique element selector.
90 *
91 * Retrieve the unique selector for any given element.
92 *
93 * @since 1.2.0
94 * @access public
95 *
96 * @param Element_Base $element The element.
97 *
98 * @return string Unique element selector.
99 */
100 public function get_element_unique_selector( Element_Base $element ) {
101 return '.elementor-' . $this->post_id . ' .elementor-element' . $element->get_unique_selector();
102 }
103
104 /**
105 * Load meta data.
106 *
107 * Retrieve the post CSS file meta data.
108 *
109 * @since 1.2.0
110 * @access protected
111 *
112 * @return array Post CSS file meta data.
113 */
114 protected function load_meta() {
115 return get_post_meta( $this->post_id, static::META_KEY, true );
116 }
117
118 /**
119 * Update meta data.
120 *
121 * Update the global CSS file meta data.
122 *
123 * @since 1.2.0
124 * @access protected
125 *
126 * @param array $meta New meta data.
127 */
128 protected function update_meta( $meta ) {
129 update_post_meta( $this->post_id, static::META_KEY, $meta );
130 }
131
132 /**
133 * Delete meta.
134 *
135 * Delete the file meta data.
136 *
137 * @since 2.1.0
138 * @access protected
139 */
140 protected function delete_meta() {
141 delete_post_meta( $this->post_id, static::META_KEY );
142 }
143
144 /**
145 * Get post data.
146 *
147 * Retrieve raw post data from the database.
148 *
149 * @since 1.9.0
150 * @access protected
151 *
152 * @return array Post data.
153 */
154 protected function get_data() {
155 $document = Plugin::$instance->documents->get( $this->post_id );
156 return $document ? $document->get_elements_data() : [];
157 }
158
159 /**
160 * Render CSS.
161 *
162 * Parse the CSS for all the elements.
163 *
164 * @since 1.2.0
165 * @access protected
166 */
167 protected function render_css() {
168 $data = $this->get_data();
169
170 if ( ! empty( $data ) ) {
171 foreach ( $data as $element_data ) {
172 $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
173
174 if ( ! $element ) {
175 continue;
176 }
177
178 $this->render_styles( $element );
179 }
180 }
181 }
182
183 /**
184 * Enqueue CSS.
185 *
186 * Enqueue the post CSS file in Elementor.
187 *
188 * This method ensures that the post was actually built with elementor before
189 * enqueueing the post CSS file.
190 *
191 * @since 1.2.2
192 * @access public
193 */
194 public function enqueue() {
195 if ( ! Plugin::$instance->db->is_built_with_elementor( $this->post_id ) ) {
196 return;
197 }
198
199 parent::enqueue();
200 }
201
202 /**
203 * Add controls-stack style rules.
204 *
205 * Parse the CSS for all the elements inside any given controls stack.
206 *
207 * This method recursively renders the CSS for all the child elements in the stack.
208 *
209 * @since 1.6.0
210 * @access public
211 *
212 * @param Controls_Stack $controls_stack The controls stack.
213 * @param array $controls Controls array.
214 * @param array $values Values array.
215 * @param array $placeholders Placeholders.
216 * @param array $replacements Replacements.
217 * @param array $all_controls All controls.
218 */
219 public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, array $all_controls = null ) {
220 parent::add_controls_stack_style_rules( $controls_stack, $controls, $values, $placeholders, $replacements, $all_controls );
221
222 if ( $controls_stack instanceof Element_Base ) {
223 foreach ( $controls_stack->get_children() as $child_element ) {
224 $this->render_styles( $child_element );
225 }
226 }
227 }
228
229 /**
230 * Get enqueue dependencies.
231 *
232 * Retrieve the name of the stylesheet used by `wp_enqueue_style()`.
233 *
234 * @since 1.2.0
235 * @access protected
236 *
237 * @return array Name of the stylesheet.
238 */
239 protected function get_enqueue_dependencies() {
240 return [ 'elementor-frontend' ];
241 }
242
243 /**
244 * Get inline dependency.
245 *
246 * Retrieve the name of the stylesheet used by `wp_add_inline_style()`.
247 *
248 * @since 1.2.0
249 * @access protected
250 *
251 * @return string Name of the stylesheet.
252 */
253 protected function get_inline_dependency() {
254 return 'elementor-frontend';
255 }
256
257 /**
258 * Get file handle ID.
259 *
260 * Retrieve the handle ID for the post CSS file.
261 *
262 * @since 1.2.0
263 * @access protected
264 *
265 * @return string CSS file handle ID.
266 */
267 protected function get_file_handle_id() {
268 return 'elementor-post-' . $this->post_id;
269 }
270
271 /**
272 * Render styles.
273 *
274 * Parse the CSS for any given element.
275 *
276 * @since 1.2.0
277 * @access protected
278 *
279 * @param Element_Base $element The element.
280 */
281 protected function render_styles( Element_Base $element ) {
282 /**
283 * Before element parse CSS.
284 *
285 * Fires before the CSS of the element is parsed.
286 *
287 * @since 1.2.0
288 *
289 * @param Post $this The post CSS file.
290 * @param Element_Base $element The element.
291 */
292 do_action( 'elementor/element/before_parse_css', $this, $element );
293
294 $element_settings = $element->get_settings();
295
296 $this->add_controls_stack_style_rules( $element, $this->get_style_controls( $element, null, $element->get_parsed_dynamic_settings() ), $element_settings, [ '{{ID}}', '{{WRAPPER}}' ], [ $element->get_id(), $this->get_element_unique_selector( $element ) ] );
297
298 /**
299 * After element parse CSS.
300 *
301 * Fires after the CSS of the element is parsed.
302 *
303 * @since 1.2.0
304 *
305 * @param Post $this The post CSS file.
306 * @param Element_Base $element The element.
307 */
308 do_action( 'elementor/element/parse_css', $this, $element );
309 }
310 }
311