PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 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 All 452 releases
elementor / modules / global-classes / concerns / has-preview-context.php

has-preview-context.php in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at modules/global-classes/concerns/has-preview-context.php

48 lines 961 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\GlobalClasses\Concerns;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 trait Has_Preview_Context {
10 private bool $is_preview = false;
11
12 public function set_preview( bool $is_preview = true ): self {
13 if ( $is_preview === $this->is_preview ) {
14 return $this;
15 }
16
17 $this->is_preview = $is_preview;
18 $this->on_preview_change();
19
20 return $this;
21 }
22
23 protected function is_preview(): bool {
24 return $this->is_preview;
25 }
26
27 protected function get_context_key( string $key ): string {
28 $map = $this->get_context_keys()[ $key ] ?? null;
29
30 if ( null === $map ) {
31 throw new \InvalidArgumentException( sprintf( 'Unknown context key: %s', esc_html( $key ) ) );
32 }
33
34 return $this->is_preview ? $map['preview'] : $map['frontend'];
35 }
36
37 protected function get_context_keys(): array {
38 if ( empty( $this->context_keys ) ) {
39 return [];
40 }
41
42 return $this->context_keys;
43 }
44
45 protected function on_preview_change(): void {
46 }
47 }
48