PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.3
Elementor Website Builder – more than just a page builder v3.2.3
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.2.3, at core/kits/documents/kit.php

210 lines 5.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 function get_name() {
40 return 'kit';
41 }
42
43 public static function get_title() {
44 return __( 'Kit', 'elementor' );
45 }
46
47 /**
48 * @return Tabs\Tab_Base[]
49 */
50 public function get_tabs() {
51 return $this->tabs;
52 }
53
54 protected function get_have_a_look_url() {
55 return '';
56 }
57
58 public static function get_editor_panel_config() {
59 $config = parent::get_editor_panel_config();
60 $config['default_route'] = 'panel/global/menu';
61
62 $config['needHelpUrl'] = 'https://go.elementor.com/global-settings';
63
64 return $config;
65 }
66
67 public function get_css_wrapper_selector() {
68 return '.elementor-kit-' . $this->get_main_id();
69 }
70
71 public function save( $data ) {
72 foreach ( $this->tabs as $tab ) {
73 $data = $tab->before_save( $data );
74 }
75
76 $saved = parent::save( $data );
77
78 if ( ! $saved ) {
79 return false;
80 }
81
82 // Should set is_saving to true, to avoid infinite loop when updating
83 // settings like: 'site_name" or "site_description".
84 $this->set_is_saving( true );
85
86 foreach ( $this->tabs as $tab ) {
87 $tab->on_save( $data );
88 }
89
90 $this->set_is_saving( false );
91
92 // When deleting a global color or typo, the css variable still exists in the frontend
93 // but without any value and it makes the element to be un styled even if there is a default style for the base element,
94 // for that reason this method removes css files of the entire site.
95 Plugin::instance()->files_manager->clear_cache();
96
97 return $saved;
98 }
99
100 /**
101 * Register a kit settings menu.
102 *
103 * @param $id
104 * @param $class
105 */
106 public function register_tab( $id, $class ) {
107 $this->tabs[ $id ] = new $class( $this );
108 }
109
110 /**
111 * @inheritDoc
112 */
113 protected function get_initial_config() {
114 $config = parent::get_initial_config();
115
116 foreach ( $this->tabs as $id => $tab ) {
117 $config['tabs'][ $id ] = [
118 'title' => $tab->get_title(),
119 'icon' => $tab->get_icon(),
120 'group' => $tab->get_group(),
121 'helpUrl' => $tab->get_help_url(),
122 'additionalContent' => $tab->get_additional_tab_content(),
123 ];
124 }
125
126 return $config;
127 }
128
129 /**
130 * @since 3.1.0
131 * @access protected
132 */
133 protected function register_controls() {
134 $this->register_document_controls();
135
136 foreach ( $this->tabs as $tab ) {
137 $tab->register_controls();
138 }
139 }
140
141 protected function get_post_statuses() {
142 return [
143 'draft' => sprintf( '%s (%s)', __( 'Disabled', 'elementor' ), __( 'Draft', 'elementor' ) ),
144 'publish' => __( 'Published', 'elementor' ),
145 ];
146 }
147
148 public function add_repeater_row( $control_id, $item ) {
149 $meta_key = PageManager::META_KEY;
150 $document_settings = $this->get_meta( $meta_key );
151
152 if ( ! $document_settings ) {
153 $document_settings = [];
154 }
155
156 if ( ! isset( $document_settings[ $control_id ] ) ) {
157 $document_settings[ $control_id ] = [];
158 }
159
160 $document_settings[ $control_id ][] = $item;
161
162 $page_settings_manager = SettingsManager::get_settings_managers( 'page' );
163 $page_settings_manager->save_settings( $document_settings, $this->get_id() );
164
165 /** @var Kit $autosave **/
166 $autosave = $this->get_autosave();
167
168 if ( $autosave ) {
169 $autosave->add_repeater_row( $control_id, $item );
170 }
171
172 // Remove Post CSS.
173 $post_css = Post_CSS::create( $this->post->ID );
174
175 $post_css->delete();
176
177 // Refresh Cache.
178 Plugin::$instance->documents->get( $this->post->ID, false );
179
180 $post_css = Post_CSS::create( $this->post->ID );
181
182 $post_css->enqueue();
183 }
184
185 /**
186 * Register default tabs (menu pages) for site settings.
187 */
188 private function register_tabs() {
189 $tabs = [
190 'global-colors' => Tabs\Global_Colors::class,
191 'global-typography' => Tabs\Global_Typography::class,
192 'theme-style-typography' => Tabs\Theme_Style_Typography::class,
193 'theme-style-buttons' => Tabs\Theme_Style_Buttons::class,
194 'theme-style-images' => Tabs\Theme_Style_Images::class,
195 'theme-style-form-fields' => Tabs\Theme_Style_Form_Fields::class,
196 'settings-site-identity' => Tabs\Settings_Site_Identity::class,
197 'settings-background' => Tabs\Settings_Background::class,
198 'settings-layout' => Tabs\Settings_Layout::class,
199 'settings-lightbox' => Tabs\Settings_Lightbox::class,
200 'settings-custom-css' => Tabs\Settings_Custom_CSS::class,
201 ];
202
203 foreach ( $tabs as $id => $class ) {
204 $this->register_tab( $id, $class );
205 }
206
207 do_action( 'elementor/kit/register_tabs', $this );
208 }
209 }
210