PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.0-dev4
Elementor Website Builder – more than just a page builder v3.35.0-dev4
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 / frontend / render-modes / render-mode-base.php

render-mode-base.php in Elementor Website Builder – more than just a page builder 3.35.0-dev4, at core/frontend/render-modes/render-mode-base.php

106 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Frontend\RenderModes;
3
4 use Elementor\Plugin;
5 use Elementor\Core\Base\Document;
6 use Elementor\Core\Frontend\Render_Mode_Manager;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 abstract class Render_Mode_Base {
13 const ENQUEUE_SCRIPTS_PRIORITY = 10;
14 const ENQUEUE_STYLES_PRIORITY = 10;
15
16 /**
17 * @var int
18 */
19 protected $post_id;
20
21 /**
22 * @var Document
23 */
24 protected $document;
25
26 /**
27 * Render_Mode_Base constructor.
28 *
29 * @param $post_id
30 */
31 public function __construct( $post_id ) {
32 $this->post_id = intval( $post_id );
33 }
34
35 /**
36 * Returns the key name of the class.
37 *
38 * @throws \Exception If the `get_name` method is not implemented.
39 */
40 public static function get_name() {
41 throw new \Exception( 'You must implements `get_name` static method in ' . static::class );
42 }
43
44 /**
45 * @param $post_id
46 *
47 * @return string
48 * @throws \Exception If the `get_name` method is not implemented.
49 */
50 public static function get_url( $post_id ) {
51 return Render_Mode_Manager::get_base_url( $post_id, static::get_name() );
52 }
53
54 /**
55 * Runs before the render, by default load scripts and styles.
56 */
57 public function prepare_render() {
58 add_action( 'wp_enqueue_scripts', function () {
59 $this->enqueue_scripts();
60 }, static::ENQUEUE_SCRIPTS_PRIORITY );
61
62 add_action( 'wp_enqueue_scripts', function () {
63 $this->enqueue_styles();
64 }, static::ENQUEUE_STYLES_PRIORITY );
65 }
66
67 /**
68 * By default do not do anything.
69 */
70 protected function enqueue_scripts() {}
71
72 /**
73 * By default do not do anything.
74 */
75 protected function enqueue_styles() {}
76
77 /**
78 * Check if the current user has permissions for the current render mode.
79 *
80 * @return bool
81 */
82 public function get_permissions_callback() {
83 return $this->get_document()->is_editable_by_current_user();
84 }
85
86 /**
87 * Checks if the current render mode is static render, By default returns false.
88 *
89 * @return bool
90 */
91 public function is_static() {
92 return false;
93 }
94
95 /**
96 * @return Document
97 */
98 public function get_document() {
99 if ( ! $this->document ) {
100 $this->document = Plugin::$instance->documents->get( $this->post_id );
101 }
102
103 return $this->document;
104 }
105 }
106