PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0
Elementor Website Builder – more than just a page builder v4.2.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 / settings / page / model.php

model.php in Elementor Website Builder – more than just a page builder 4.2.0, at core/settings/page/model.php

185 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Settings\Page;
3
4 use Elementor\Core\Settings\Base\CSS_Model;
5 use Elementor\Plugin;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 /**
12 * Elementor page settings model.
13 *
14 * Elementor page settings model handler class is responsible for registering
15 * and managing Elementor page settings models.
16 *
17 * @since 1.6.0
18 */
19 class Model extends CSS_Model {
20
21 /**
22 * WordPress post object.
23 *
24 * Holds an instance of `WP_Post` containing the post object.
25 *
26 * @since 1.6.0
27 * @access public
28 *
29 * @var \WP_Post
30 */
31 private $post;
32
33 /**
34 * @var \WP_Post
35 */
36 private $post_parent;
37
38 /**
39 * Model constructor.
40 *
41 * Initializing Elementor page settings model.
42 *
43 * @since 1.6.0
44 * @access public
45 *
46 * @param array $data Optional. Model data. Default is an empty array.
47 */
48 public function __construct( array $data = [] ) {
49 $this->post = get_post( $data['id'] );
50
51 if ( ! $this->post ) {
52 $this->post = new \WP_Post( (object) [] );
53 }
54
55 if ( wp_is_post_revision( $this->post->ID ) ) {
56 $this->post_parent = get_post( $this->post->post_parent );
57 } else {
58 $this->post_parent = $this->post;
59 }
60
61 parent::__construct( $data );
62 }
63
64 /**
65 * Get model name.
66 *
67 * Retrieve page settings model name.
68 *
69 * @since 1.6.0
70 * @access public
71 *
72 * @return string Model name.
73 */
74 public function get_name() {
75 return 'page-settings';
76 }
77
78 /**
79 * Get model unique name.
80 *
81 * Retrieve page settings model unique name.
82 *
83 * @since 1.6.0
84 * @access public
85 *
86 * @return string Model unique name.
87 */
88 public function get_unique_name() {
89 return $this->get_name() . '-' . $this->post->ID;
90 }
91
92 /**
93 * Get CSS wrapper selector.
94 *
95 * Retrieve the wrapper selector for the page settings model.
96 *
97 * @since 1.6.0
98 * @access public
99 *
100 * @return string CSS wrapper selector.
101 */
102 public function get_css_wrapper_selector() {
103 $document = Plugin::$instance->documents->get( $this->post_parent->ID );
104 return $document->get_css_wrapper_selector();
105 }
106
107 /**
108 * Get panel page settings.
109 *
110 * Retrieve the panel setting for the page settings model.
111 *
112 * @since 1.6.0
113 * @access public
114 *
115 * @return array {
116 * Panel settings.
117 *
118 * @type string $title The panel title.
119 * }
120 */
121 public function get_panel_page_settings() {
122 $document = Plugin::$instance->documents->get( $this->post->ID );
123
124 return [
125 'title' => sprintf(
126 /* translators: %s: Document title. */
127 esc_html__( '%s Settings', 'elementor' ),
128 $document::get_title()
129 ),
130 ];
131 }
132
133 /**
134 * On export post meta.
135 *
136 * When exporting data, check if the post is not using page template and
137 * exclude it from the exported Elementor data.
138 *
139 * @since 1.6.0
140 * @access public
141 *
142 * @param array $element_data Element data.
143 *
144 * @return array Element data to be exported.
145 */
146 public function on_export( $element_data ) {
147 if ( ! empty( $element_data['settings']['template'] ) ) {
148 /**
149 * @var \Elementor\Modules\PageTemplates\Module $page_templates_module
150 */
151 $page_templates_module = Plugin::$instance->modules_manager->get_modules( 'page-templates' );
152 $is_elementor_template = (bool) $page_templates_module->get_template_path( $element_data['settings']['template'] );
153
154 if ( ! $is_elementor_template ) {
155 unset( $element_data['settings']['template'] );
156 }
157 }
158
159 return $element_data;
160 }
161
162 /**
163 * Register model controls.
164 *
165 * Used to add new controls to the page settings model.
166 *
167 * @since 3.1.0
168 * @access protected
169 */
170 protected function register_controls() {
171 // Check if it's a real model, or abstract (for example - on import ).
172 if ( $this->post->ID ) {
173 $document = Plugin::$instance->documents->get_doc_or_auto_save( $this->post->ID );
174
175 if ( $document ) {
176 $controls = $document->get_controls();
177
178 foreach ( $controls as $control_id => $args ) {
179 $this->add_control( $control_id, $args );
180 }
181 }
182 }
183 }
184 }
185