PluginProbe
Elementor Website Builder – more than just a page builder / 3.5.4
Elementor Website Builder – more than just a page builder v3.5.4
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 / kits / documents / kit.php

kit.php in Elementor Website Builder – more than just a page builder 3.5.4, at core/kits/documents/kit.php

242 lines 6.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\Kits\Documents;
3
4 use Elementor\Core\DocumentTypes\PageBase;
5 use Elementor\Core\Files\CSS\Post as Post_CSS;
6 use Elementor\Core\Kits\Documents\Tabs;
7 use Elementor\Core\Settings\Manager as SettingsManager;
8 use Elementor\Core\Settings\Page\Manager as PageManager;
9 use Elementor\Plugin;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 class Kit extends PageBase {
16 /**
17 * @var Tabs\Tab_Base[]
18 */
19 private $tabs;
20
21 public function __construct( array $data = [] ) {
22 parent::__construct( $data );
23
24 $this->register_tabs();
25 }
26
27 public static function get_properties() {
28 $properties = parent::get_properties();
29
30 $properties['has_elements'] = false;
31 $properties['show_in_finder'] = false;
32 $properties['show_on_admin_bar'] = false;
33 $properties['edit_capability'] = 'edit_theme_options';
34 $properties['support_kit'] = true;
35
36 return $properties;
37 }
38
39 public static function get_type() {
40 return 'kit';
41 }
42
43 public static function get_title() {
44 return esc_html__( 'Kit', 'elementor' );
45 }
46
47 /**
48 * @return Tabs\Tab_Base[]
49 */
50 public function get_tabs() {
51 return $this->tabs;
52 }
53
54 /**
55 * Retrieve a tab by ID.
56 *
57 * @param $id
58 *
59 * @return Tabs\Tab_Base
60 */
61 public function get_tab( $id ) {
62 return self::get_items( $this->get_tabs(), $id );
63 }
64
65 protected function get_have_a_look_url() {
66 return '';
67 }
68
69 public static function get_editor_panel_config() {
70 $config = parent::get_editor_panel_config();
71 $config['default_route'] = 'panel/global/menu';
72
73 $config['needHelpUrl'] = 'https://go.elementor.com/global-settings';
74
75 return $config;
76 }
77
78 public function get_css_wrapper_selector() {
79 return '.elementor-kit-' . $this->get_main_id();
80 }
81
82 public function save( $data ) {
83 foreach ( $this->tabs as $tab ) {
84 $data = $tab->before_save( $data );
85 }
86
87 $saved = parent::save( $data );
88
89 if ( ! $saved ) {
90 return false;
91 }
92
93 // Should set is_saving to true, to avoid infinite loop when updating
94 // settings like: 'site_name" or "site_description".
95 $this->set_is_saving( true );
96
97 foreach ( $this->tabs as $tab ) {
98 $tab->on_save( $data );
99 }
100
101 $this->set_is_saving( false );
102
103 // When deleting a global color or typo, the css variable still exists in the frontend
104 // but without any value and it makes the element to be un styled even if there is a default style for the base element,
105 // for that reason this method removes css files of the entire site.
106 Plugin::instance()->files_manager->clear_cache();
107
108 return $saved;
109 }
110
111 /**
112 * Register a kit settings menu.
113 *
114 * @param $id
115 * @param $class
116 */
117 public function register_tab( $id, $class ) {
118 $this->tabs[ $id ] = new $class( $this );
119 }
120
121 /**
122 * @inheritDoc
123 */
124 protected function get_initial_config() {
125 $config = parent::get_initial_config();
126
127 foreach ( $this->tabs as $id => $tab ) {
128 $config['tabs'][ $id ] = [
129 'title' => $tab->get_title(),
130 'icon' => $tab->get_icon(),
131 'group' => $tab->get_group(),
132 'helpUrl' => $tab->get_help_url(),
133 'additionalContent' => $tab->get_additional_tab_content(),
134 ];
135 }
136
137 return $config;
138 }
139
140 /**
141 * @since 3.1.0
142 * @access protected
143 */
144 protected function register_controls() {
145 $is_edit_mode = Plugin::$instance->editor->is_edit_mode();
146
147 if ( ! $is_edit_mode ) {
148 // In the Front End, the Kit is initialized before CSS is generated, so we always duplicate controls in
149 // the kit.
150 $initial_responsive_controls_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode();
151
152 Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( 'on' );
153 }
154
155 $this->register_document_controls();
156
157 foreach ( $this->tabs as $tab ) {
158 $tab->register_controls();
159 }
160
161 if ( ! $is_edit_mode ) {
162 Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $initial_responsive_controls_duplication_mode );
163 }
164 }
165
166 protected function get_post_statuses() {
167 return [
168 'draft' => sprintf( '%s (%s)', esc_html__( 'Disabled', 'elementor' ), esc_html__( 'Draft', 'elementor' ) ),
169 'publish' => esc_html__( 'Published', 'elementor' ),
170 ];
171 }
172
173 public function add_repeater_row( $control_id, $item ) {
174 $meta_key = PageManager::META_KEY;
175 $document_settings = $this->get_meta( $meta_key );
176
177 if ( ! $document_settings ) {
178 $document_settings = [];
179 }
180
181 if ( ! isset( $document_settings[ $control_id ] ) ) {
182 $document_settings[ $control_id ] = [];
183 }
184
185 $document_settings[ $control_id ][] = $item;
186
187 $page_settings_manager = SettingsManager::get_settings_managers( 'page' );
188 $page_settings_manager->save_settings( $document_settings, $this->get_id() );
189
190 /** @var Kit $autosave **/
191 $autosave = $this->get_autosave();
192
193 if ( $autosave ) {
194 $autosave->add_repeater_row( $control_id, $item );
195 }
196
197 // Remove Post CSS.
198 $post_css = Post_CSS::create( $this->post->ID );
199
200 $post_css->delete();
201
202 // Refresh Cache.
203 Plugin::$instance->documents->get( $this->post->ID, false );
204
205 $post_css = Post_CSS::create( $this->post->ID );
206
207 $post_css->enqueue();
208 }
209
210 /**
211 * Register default tabs (menu pages) for site settings.
212 */
213 private function register_tabs() {
214 $tabs = [
215 'global-colors' => Tabs\Global_Colors::class,
216 'global-typography' => Tabs\Global_Typography::class,
217 'theme-style-typography' => Tabs\Theme_Style_Typography::class,
218 'theme-style-buttons' => Tabs\Theme_Style_Buttons::class,
219 'theme-style-images' => Tabs\Theme_Style_Images::class,
220 'theme-style-form-fields' => Tabs\Theme_Style_Form_Fields::class,
221 'settings-site-identity' => Tabs\Settings_Site_Identity::class,
222 'settings-background' => Tabs\Settings_Background::class,
223 'settings-layout' => Tabs\Settings_Layout::class,
224 'settings-lightbox' => Tabs\Settings_Lightbox::class,
225 ];
226
227 // Add the Page Transitions tab only if the experiment exists.
228 if ( Plugin::instance()->experiments->get_features( 'page-transitions' ) ) {
229 $tabs['settings-page-transitions'] = Tabs\Settings_Page_Transitions::class;
230 }
231
232 // Add the Custom CSS tab at last.
233 $tabs['settings-custom-css'] = Tabs\Settings_Custom_CSS::class;
234
235 foreach ( $tabs as $id => $class ) {
236 $this->register_tab( $id, $class );
237 }
238
239 do_action( 'elementor/kit/register_tabs', $this );
240 }
241 }
242