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

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

223 lines 5.4 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 'id' => $id,
130 'title' => $tab->get_title(),
131 'icon' => $tab->get_icon(),
132 'group' => $tab->get_group(),
133 'helpUrl' => $tab->get_help_url(),
134 'additionalContent' => $tab->get_additional_tab_content(),
135 ];
136 }
137
138 return $config;
139 }
140
141 /**
142 * @since 3.1.0
143 * @access protected
144 */
145 protected function register_controls() {
146 $this->register_document_controls();
147
148 foreach ( $this->tabs as $tab ) {
149 $tab->register_controls();
150 }
151 }
152
153 protected function get_post_statuses() {
154 return [
155 'draft' => sprintf( '%s (%s)', esc_html__( 'Disabled', 'elementor' ), esc_html__( 'Draft', 'elementor' ) ),
156 'publish' => esc_html__( 'Published', 'elementor' ),
157 ];
158 }
159
160 public function add_repeater_row( $control_id, $item ) {
161 $meta_key = PageManager::META_KEY;
162 $document_settings = $this->get_meta( $meta_key );
163
164 if ( ! $document_settings ) {
165 $document_settings = [];
166 }
167
168 if ( ! isset( $document_settings[ $control_id ] ) ) {
169 $document_settings[ $control_id ] = [];
170 }
171
172 $document_settings[ $control_id ][] = $item;
173
174 $page_settings_manager = SettingsManager::get_settings_managers( 'page' );
175 $page_settings_manager->save_settings( $document_settings, $this->get_id() );
176
177 /** @var Kit $autosave **/
178 $autosave = $this->get_autosave();
179
180 if ( $autosave ) {
181 $autosave->add_repeater_row( $control_id, $item );
182 }
183
184 // Remove Post CSS.
185 $post_css = Post_CSS::create( $this->post->ID );
186
187 $post_css->delete();
188
189 // Refresh Cache.
190 Plugin::$instance->documents->get( $this->post->ID, false );
191
192 $post_css = Post_CSS::create( $this->post->ID );
193
194 $post_css->enqueue();
195 }
196
197 /**
198 * Register default tabs (menu pages) for site settings.
199 */
200 private function register_tabs() {
201 $tabs = [
202 'global-colors' => Tabs\Global_Colors::class,
203 'global-typography' => Tabs\Global_Typography::class,
204 'theme-style-typography' => Tabs\Theme_Style_Typography::class,
205 'theme-style-buttons' => Tabs\Theme_Style_Buttons::class,
206 'theme-style-images' => Tabs\Theme_Style_Images::class,
207 'theme-style-form-fields' => Tabs\Theme_Style_Form_Fields::class,
208 'settings-site-identity' => Tabs\Settings_Site_Identity::class,
209 'settings-background' => Tabs\Settings_Background::class,
210 'settings-layout' => Tabs\Settings_Layout::class,
211 'settings-lightbox' => Tabs\Settings_Lightbox::class,
212 'settings-page-transitions' => Tabs\Settings_Page_Transitions::class,
213 'settings-custom-css' => Tabs\Settings_Custom_CSS::class,
214 ];
215
216 foreach ( $tabs as $id => $class ) {
217 $this->register_tab( $id, $class );
218 }
219
220 do_action( 'elementor/kit/register_tabs', $this );
221 }
222 }
223