PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.7
Elementor Website Builder – more than just a page builder v3.0.7
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 3.0.7, at core/settings/page/model.php

182 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 /* translators: %s: Document title */
126 'title' => sprintf( __( '%s Settings', 'elementor' ), $document::get_title() ),
127 ];
128 }
129
130 /**
131 * On export post meta.
132 *
133 * When exporting data, check if the post is not using page template and
134 * exclude it from the exported Elementor data.
135 *
136 * @since 1.6.0
137 * @access public
138 *
139 * @param array $element_data Element data.
140 *
141 * @return array Element data to be exported.
142 */
143 public function on_export( $element_data ) {
144 if ( ! empty( $element_data['settings']['template'] ) ) {
145 /**
146 * @var \Elementor\Modules\PageTemplates\Module $page_templates_module
147 */
148 $page_templates_module = Plugin::$instance->modules_manager->get_modules( 'page-templates' );
149 $is_elementor_template = ! ! $page_templates_module->get_template_path( $element_data['settings']['template'] );
150
151 if ( ! $is_elementor_template ) {
152 unset( $element_data['settings']['template'] );
153 }
154 }
155
156 return $element_data;
157 }
158
159 /**
160 * Register model controls.
161 *
162 * Used to add new controls to the page settings model.
163 *
164 * @since 1.6.0
165 * @access protected
166 */
167 protected function _register_controls() {
168 // Check if it's a real model, or abstract (for example - on import )
169 if ( $this->post->ID ) {
170 $document = Plugin::$instance->documents->get_doc_or_auto_save( $this->post->ID );
171
172 if ( $document ) {
173 $controls = $document->get_controls();
174
175 foreach ( $controls as $control_id => $args ) {
176 $this->add_control( $control_id, $args );
177 }
178 }
179 }
180 }
181 }
182