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 / frontend / render-modes / render-mode-base.php

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

111 lines 2.1 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 * @return string
39 * @throws \Exception
40 */
41 public static function get_name() {
42 throw new \Exception( 'You must implements `get_name` static method in ' . static::class );
43 }
44
45 /**
46 * @param $post_id
47 *
48 * @return string
49 * @throws \Exception
50 */
51 public static function get_url( $post_id ) {
52 return Render_Mode_Manager::get_base_url( $post_id, static::get_name() );
53 }
54
55 /**
56 * Runs before the render, by default load scripts and styles.
57 */
58 public function prepare_render() {
59 add_action( 'wp_enqueue_scripts', function () {
60 $this->enqueue_scripts();
61 }, static::ENQUEUE_SCRIPTS_PRIORITY );
62
63 add_action( 'wp_enqueue_scripts', function () {
64 $this->enqueue_styles();
65 }, static::ENQUEUE_STYLES_PRIORITY );
66 }
67
68 /**
69 * By default do not do anything.
70 */
71 protected function enqueue_scripts() {
72 //
73 }
74
75 /**
76 * By default do not do anything.
77 */
78 protected function enqueue_styles() {
79 //
80 }
81
82 /**
83 * Check if the current user has permissions for the current render mode.
84 *
85 * @return bool
86 */
87 public function get_permissions_callback() {
88 return $this->get_document()->is_editable_by_current_user();
89 }
90
91 /**
92 * Checks if the current render mode is static render, By default returns false.
93 *
94 * @return bool
95 */
96 public function is_static() {
97 return false;
98 }
99
100 /**
101 * @return Document
102 */
103 public function get_document() {
104 if ( ! $this->document ) {
105 $this->document = Plugin::$instance->documents->get( $this->post_id );
106 }
107
108 return $this->document;
109 }
110 }
111