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

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

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