PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.0-dev2
Elementor Website Builder – more than just a page builder v3.28.0-dev2
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 / includes / settings / settings.php

settings.php in Elementor Website Builder – more than just a page builder 3.28.0-dev2, at includes/settings/settings.php

571 lines 17.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
5 use Elementor\Core\Files\Fonts\Google_Font;
6 use Elementor\Includes\Settings\AdminMenuItems\Admin_Menu_Item;
7 use Elementor\Includes\Settings\AdminMenuItems\Get_Help_Menu_Item;
8 use Elementor\Includes\Settings\AdminMenuItems\Getting_Started_Menu_Item;
9 use Elementor\Modules\Promotions\Module as Promotions_Module;
10 use Elementor\TemplateLibrary\Source_Local;
11 use Elementor\Modules\Home\Module as Home_Module;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 /**
18 * Elementor "Settings" page in WordPress Dashboard.
19 *
20 * Elementor settings page handler class responsible for creating and displaying
21 * Elementor "Settings" page in WordPress dashboard.
22 *
23 * @since 1.0.0
24 */
25 class Settings extends Settings_Page {
26
27 /**
28 * Settings page ID for Elementor settings.
29 */
30 const PAGE_ID = 'elementor';
31
32 /**
33 * Upgrade menu priority.
34 */
35 const MENU_PRIORITY_GO_PRO = 502;
36
37 /**
38 * Settings page field for update time.
39 */
40 const UPDATE_TIME_FIELD = '_elementor_settings_update_time';
41
42 /**
43 * Settings page general tab slug.
44 */
45 const TAB_GENERAL = 'general';
46
47 /**
48 * Settings page style tab slug.
49 */
50 const TAB_STYLE = 'style';
51
52 /**
53 * Settings page integrations tab slug.
54 */
55 const TAB_INTEGRATIONS = 'integrations';
56
57 /**
58 * Settings page advanced tab slug.
59 */
60 const TAB_ADVANCED = 'advanced';
61
62 /**
63 * Settings page performance tab slug.
64 */
65 const TAB_PERFORMANCE = 'performance';
66
67 const ADMIN_MENU_PRIORITY = 10;
68
69 public Home_Module $home_module;
70
71 /**
72 * Register admin menu.
73 *
74 * Add new Elementor Settings admin menu.
75 *
76 * Fired by `admin_menu` action.
77 *
78 * @since 1.0.0
79 * @access public
80 */
81 public function register_admin_menu() {
82 global $menu;
83
84 $menu[] = [ '', 'read', 'separator-elementor', '', 'wp-menu-separator elementor' ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
85
86 if ( ! current_user_can( 'manage_options' ) ) {
87 return;
88 }
89
90 add_menu_page(
91 esc_html__( 'Elementor', 'elementor' ),
92 esc_html__( 'Elementor', 'elementor' ),
93 'manage_options',
94 self::PAGE_ID,
95 [
96 $this,
97 $this->home_module->is_experiment_active() ? 'display_home_screen' : 'display_settings_page',
98 ],
99 '',
100 '58.5'
101 );
102
103 if ( $this->home_module->is_experiment_active() ) {
104 add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) {
105 $admin_menu->register( 'elementor-settings', new Admin_Menu_Item( $this ) );
106 }, 0 );
107 }
108 }
109
110 public function display_home_screen() {
111 echo '<div id="e-home-screen"></div>';
112 }
113
114 /**
115 * Reorder the Elementor menu items in admin.
116 * Based on WC.
117 *
118 * @since 2.4.0
119 *
120 * @param array $menu_order Menu order.
121 * @return array
122 */
123 public function menu_order( $menu_order ) {
124 // Initialize our custom order array.
125 $elementor_menu_order = [];
126
127 // Get the index of our custom separator.
128 $elementor_separator = array_search( 'separator-elementor', $menu_order, true );
129
130 // Get index of library menu.
131 $elementor_library = array_search( Source_Local::ADMIN_MENU_SLUG, $menu_order, true );
132
133 // Loop through menu order and do some rearranging.
134 foreach ( $menu_order as $index => $item ) {
135 if ( 'elementor' === $item ) {
136 $elementor_menu_order[] = 'separator-elementor';
137 $elementor_menu_order[] = $item;
138 $elementor_menu_order[] = Source_Local::ADMIN_MENU_SLUG;
139
140 unset( $menu_order[ $elementor_separator ] );
141 unset( $menu_order[ $elementor_library ] );
142 } elseif ( ! in_array( $item, [ 'separator-elementor' ], true ) ) {
143 $elementor_menu_order[] = $item;
144 }
145 }
146
147 // Return order.
148 return $elementor_menu_order;
149 }
150
151 /**
152 * Register Elementor knowledge base sub-menu.
153 *
154 * Add new Elementor knowledge base sub-menu under the main Elementor menu.
155 *
156 * Fired by `admin_menu` action.
157 *
158 * @since 2.0.3
159 * @access private
160 */
161 private function register_knowledge_base_menu( Admin_Menu_Manager $admin_menu ) {
162 $admin_menu->register( 'elementor-getting-started', new Getting_Started_Menu_Item() );
163 $admin_menu->register( 'go_knowledge_base_site', new Get_Help_Menu_Item() );
164 }
165
166 /**
167 * Go Elementor Pro.
168 *
169 * Redirect the Elementor Pro page the clicking the Elementor Pro menu link.
170 *
171 * Fired by `admin_init` action.
172 *
173 * @since 2.0.3
174 * @access public
175 */
176 public function handle_external_redirects() {
177 if ( empty( $_GET['page'] ) ) {
178 return;
179 }
180
181 if ( 'go_knowledge_base_site' === $_GET['page'] ) {
182 wp_redirect( Get_Help_Menu_Item::URL );
183 die;
184 }
185 }
186
187 /**
188 * On admin init.
189 *
190 * Preform actions on WordPress admin initialization.
191 *
192 * Fired by `admin_init` action.
193 *
194 * @since 2.0.0
195 * @access public
196 */
197 public function on_admin_init() {
198 $this->handle_external_redirects();
199
200 $this->maybe_remove_all_admin_notices();
201 }
202
203 /**
204 * Change "Settings" menu name.
205 *
206 * Update the name of the Settings admin menu from "Elementor" to "Settings".
207 *
208 * Fired by `admin_menu` action.
209 *
210 * @since 1.0.0
211 * @access public
212 */
213 public function admin_menu_change_name() {
214 $menu_name = $this->home_module->is_experiment_active()
215 ? esc_html__( 'Home', 'elementor' )
216 : esc_html__( 'Settings', 'elementor' );
217
218 Utils::change_submenu_first_item_label( 'elementor', $menu_name );
219 }
220
221 /**
222 * Update CSS print method.
223 *
224 * Clear post CSS cache.
225 *
226 * Fired by `add_option_elementor_css_print_method` and
227 * `update_option_elementor_css_print_method` actions.
228 *
229 * @since 1.7.5
230 * @access public
231 * @deprecated 3.0.0 Use `Plugin::$instance->files_manager->clear_cache()` method instead.
232 */
233 public function update_css_print_method() {
234 Plugin::$instance->files_manager->clear_cache();
235 }
236
237 /**
238 * Create tabs.
239 *
240 * Return the settings page tabs, sections and fields.
241 *
242 * @since 1.5.0
243 * @access protected
244 *
245 * @return array An array with the settings page tabs, sections and fields.
246 */
247 protected function create_tabs() {
248 $validations_class_name = __NAMESPACE__ . '\Settings_Validations';
249
250 return [
251 self::TAB_GENERAL => [
252 'label' => esc_html__( 'General', 'elementor' ),
253 'sections' => [
254 'general' => [
255 'label' => esc_html__( 'General', 'elementor' ),
256 'callback' => function() {
257 printf(
258 '<p>%s</p><br><hr><br>',
259 esc_html__( 'Tailor how Elementor enhances your site, from post types to other functions.', 'elementor' )
260 );
261 },
262 'fields' => [
263 self::UPDATE_TIME_FIELD => [
264 'full_field_id' => self::UPDATE_TIME_FIELD,
265 'field_args' => [
266 'type' => 'hidden',
267 ],
268 'setting_args' => [ $validations_class_name, 'current_time' ],
269 ],
270 'cpt_support' => [
271 'label' => esc_html__( 'Post Types', 'elementor' ),
272 'field_args' => [
273 'type' => 'checkbox_list_cpt',
274 'std' => [ 'page', 'post' ],
275 'exclude' => [ 'attachment', 'elementor_library' ],
276 ],
277 'setting_args' => [ $validations_class_name, 'checkbox_list' ],
278 ],
279 'disable_color_schemes' => [
280 'label' => esc_html__( 'Disable Default Colors', 'elementor' ),
281 'field_args' => [
282 'type' => 'checkbox',
283 'value' => 'yes',
284 'sub_desc' => esc_html__( 'Checking this box will disable Elementor\'s Default Colors, and make Elementor inherit the colors from your theme.', 'elementor' ),
285 ],
286 ],
287 'disable_typography_schemes' => [
288 'label' => esc_html__( 'Disable Default Fonts', 'elementor' ),
289 'field_args' => [
290 'type' => 'checkbox',
291 'value' => 'yes',
292 'sub_desc' => esc_html__( 'Checking this box will disable Elementor\'s Default Fonts, and make Elementor inherit the fonts from your theme.', 'elementor' ),
293 ],
294 ],
295 ],
296 ],
297 'usage' => [
298 'label' => esc_html__( 'Improve Elementor', 'elementor' ),
299 'fields' => $this->get_usage_fields(),
300 ],
301 ],
302 ],
303 self::TAB_INTEGRATIONS => [
304 'label' => esc_html__( 'Integrations', 'elementor' ),
305 'sections' => [
306 'google_maps' => [
307 'label' => esc_html__( 'Google Maps Embed API', 'elementor' ),
308 'callback' => function() {
309 printf(
310 /* translators: 1: Link open tag, 2: Link close tag */
311 esc_html__( 'Google Maps Embed API is a free service by Google that allows embedding Google Maps in your site. For more details, visit Google Maps\' %1$sUsing API Keys%2$s page.', 'elementor' ),
312 '<a target="_blank" href="https://developers.google.com/maps/documentation/embed/get-api-key">',
313 '</a>'
314 );
315 },
316 'fields' => [
317 'google_maps_api_key' => [
318 'label' => esc_html__( 'API Key', 'elementor' ),
319 'field_args' => [
320 'class' => 'elementor_google_maps_api_key',
321 'type' => 'text',
322 ],
323 ],
324 ],
325 ],
326 ],
327 ],
328 self::TAB_ADVANCED => [
329 'label' => esc_html__( 'Advanced', 'elementor' ),
330 'sections' => [
331 'advanced' => [
332 'label' => esc_html__( 'Advanced', 'elementor' ),
333 'callback' => function() {
334 printf(
335 '<p>%s</p><br><hr><br>',
336 esc_html__( 'Personalize the way Elementor works on your website by choosing the advanced features and how they operate.', 'elementor' )
337 );
338 },
339 'fields' => [
340 'editor_break_lines' => [
341 'label' => esc_html__( 'Switch Editor Loader Method', 'elementor' ),
342 'field_args' => [
343 'type' => 'select',
344 'std' => '',
345 'options' => [
346 '' => esc_html__( 'Disable', 'elementor' ),
347 '1' => esc_html__( 'Enable', 'elementor' ),
348 ],
349 'desc' => esc_html__( 'For troubleshooting server configuration conflicts.', 'elementor' ),
350 ],
351 ],
352 'unfiltered_files_upload' => [
353 'label' => esc_html__( 'Enable Unfiltered File Uploads', 'elementor' ),
354 'field_args' => [
355 'type' => 'select',
356 'std' => '',
357 'options' => [
358 '' => esc_html__( 'Disable', 'elementor' ),
359 '1' => esc_html__( 'Enable', 'elementor' ),
360 ],
361 'desc' => esc_html__( 'Please note! Allowing uploads of any files (SVG & JSON included) is a potential security risk.', 'elementor' ) . '<br>' . esc_html__( 'Elementor will try to sanitize the unfiltered files, removing potential malicious code and scripts.', 'elementor' ) . '<br>' . esc_html__( 'We recommend you only enable this feature if you understand the security risks involved.', 'elementor' ),
362 ],
363 ],
364 'google_font' => [
365 'label' => esc_html__( 'Google Fonts', 'elementor' ),
366 'field_args' => [
367 'type' => 'select',
368 'std' => '1',
369 'options' => [
370 '1' => esc_html__( 'Enable', 'elementor' ),
371 '0' => esc_html__( 'Disable', 'elementor' ),
372 ],
373 'desc' => sprintf(
374 esc_html__( 'Disable this option if you want to prevent Google Fonts from being loaded. This setting is recommended when loading fonts from a different source (plugin, theme or %1$scustom fonts%2$s).', 'elementor' ),
375 '<a href="' . admin_url( 'admin.php?page=elementor_custom_fonts' ) . '">',
376 '</a>'
377 ),
378 ],
379 ],
380 'font_display' => [
381 'label' => esc_html__( 'Google Fonts Load', 'elementor' ),
382 'field_args' => [
383 'type' => 'select',
384 'std' => 'auto',
385 'options' => [
386 'auto' => esc_html__( 'Default', 'elementor' ),
387 'block' => esc_html__( 'Blocking', 'elementor' ),
388 'swap' => esc_html__( 'Swap', 'elementor' ),
389 'fallback' => esc_html__( 'Fallback', 'elementor' ),
390 'optional' => esc_html__( 'Optional', 'elementor' ),
391 ],
392 'desc' => esc_html__( 'Font-display property defines how font files are loaded and displayed by the browser.', 'elementor' ) . '<br>' . esc_html__( 'Set the way Google Fonts are being loaded by selecting the font-display property (Recommended: Swap).', 'elementor' ),
393 ],
394 ],
395 ],
396 ],
397 ],
398 ],
399 self::TAB_PERFORMANCE => [
400 'label' => esc_html__( 'Performance', 'elementor' ),
401 'sections' => [
402 'performance' => [
403 'label' => esc_html__( 'Performance', 'elementor' ),
404 'callback' => function() {
405 printf(
406 '<p>%s</p><br><hr><br>',
407 esc_html__( 'Improve loading times on your site by selecting the optimization tools that best fit your requirements.', 'elementor' )
408 );
409 },
410 'fields' => [
411 'css_print_method' => [
412 'label' => esc_html__( 'CSS Print Method', 'elementor' ),
413 'field_args' => [
414 'class' => 'elementor_css_print_method',
415 'type' => 'select',
416 'std' => 'external',
417 'options' => [
418 'external' => esc_html__( 'External File', 'elementor' ),
419 'internal' => esc_html__( 'Internal Embedding', 'elementor' ),
420 ],
421 'desc' => sprintf(
422 /* translators: %s: <head> tag. */
423 esc_html__( 'Internal Embedding places all CSS in the %s which works great for troubleshooting, while External File uses external CSS file for better performance (recommended).', 'elementor' ),
424 '<code>&lt;head&gt;</code>',
425 ),
426 ],
427 ],
428 'optimized_image_loading' => [
429 'label' => esc_html__( 'Optimized Image Loading', 'elementor' ),
430 'field_args' => [
431 'type' => 'select',
432 'std' => '1',
433 'options' => [
434 '1' => esc_html__( 'Enable', 'elementor' ),
435 '0' => esc_html__( 'Disable', 'elementor' ),
436 ],
437 'desc' => sprintf(
438 /* translators: 1: fetchpriority attribute, 2: lazy loading attribute. */
439 esc_html__( 'Improve performance by applying %1$s on LCP image and %2$s on images below the fold.', 'elementor' ),
440 '<code>fetchpriority="high"</code>',
441 '<code>loading="lazy"</code>'
442 ),
443 ],
444 ],
445 'optimized_gutenberg_loading' => [
446 'label' => esc_html__( 'Optimized Gutenberg Loading', 'elementor' ),
447 'field_args' => [
448 'type' => 'select',
449 'std' => '1',
450 'options' => [
451 '1' => esc_html__( 'Enable', 'elementor' ),
452 '0' => esc_html__( 'Disable', 'elementor' ),
453 ],
454 'desc' => esc_html__( 'Reduce unnecessary render-blocking loads by dequeuing unused Gutenberg block editor scripts and styles.', 'elementor' ),
455 ],
456 ],
457 'lazy_load_background_images' => [
458 'label' => esc_html__( 'Lazy Load Background Images', 'elementor' ),
459 'field_args' => [
460 'type' => 'select',
461 'std' => '1',
462 'options' => [
463 '1' => esc_html__( 'Enable', 'elementor' ),
464 '0' => esc_html__( 'Disable', 'elementor' ),
465 ],
466 'desc' => esc_html__( 'Improve initial page load performance by lazy loading all background images except the first one.', 'elementor' ),
467 ],
468 ],
469 ],
470 ],
471 ],
472 ],
473 ];
474 }
475
476 /**
477 * Get settings page title.
478 *
479 * Retrieve the title for the settings page.
480 *
481 * @since 1.5.0
482 * @access protected
483 *
484 * @return string Settings page title.
485 */
486 protected function get_page_title() {
487 return esc_html__( 'Elementor', 'elementor' );
488 }
489
490 /**
491 * @since 2.2.0
492 * @access private
493 */
494 private function maybe_remove_all_admin_notices() {
495 $elementor_pages = [
496 'elementor-getting-started',
497 'elementor-system-info',
498 'e-form-submissions',
499 'elementor_custom_fonts',
500 'elementor_custom_icons',
501 'elementor-license',
502 'elementor_custom_code',
503 'popup_templates',
504 'elementor-apps',
505 ];
506
507 if ( empty( $_GET['page'] ) || ! in_array( $_GET['page'], $elementor_pages, true ) ) {
508 return;
509 }
510
511 remove_all_actions( 'admin_notices' );
512 }
513
514 public function add_generator_tag_settings( $settings ) {
515 $css_print_method = get_option( 'elementor_css_print_method', 'external' );
516 $settings[] = 'css_print_method-' . $css_print_method;
517
518 $google_font = Fonts::is_google_fonts_enabled() ? 'enabled' : 'disabled';
519 $settings[] = 'google_font-' . $google_font;
520
521 $font_display = Fonts::get_font_display_setting();
522 $settings[] = 'font_display-' . $font_display;
523
524 return $settings;
525 }
526
527 /**
528 * Settings page constructor.
529 *
530 * Initializing Elementor "Settings" page.
531 *
532 * @since 1.0.0
533 * @access public
534 */
535 public function __construct() {
536 parent::__construct();
537
538 $this->home_module = new Home_Module();
539
540 add_action( 'admin_init', [ $this, 'on_admin_init' ] );
541 add_filter( 'elementor/generator_tag/settings', [ $this, 'add_generator_tag_settings' ] );
542
543 add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 20 );
544
545 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
546 $this->register_knowledge_base_menu( $admin_menu );
547 }, Promotions_Module::ADMIN_MENU_PRIORITY - 1 );
548
549 add_action( 'admin_menu', [ $this, 'admin_menu_change_name' ], 200 );
550
551 add_filter( 'custom_menu_order', '__return_true' );
552 add_filter( 'menu_order', [ $this, 'menu_order' ] );
553
554 $clear_cache_callback = [ Plugin::$instance->files_manager, 'clear_cache' ];
555
556 // Clear CSS Meta after change css related methods.
557 $css_settings = [
558 'elementor_disable_color_schemes',
559 'elementor_disable_typography_schemes',
560 'elementor_css_print_method',
561 ];
562
563 foreach ( $css_settings as $option_name ) {
564 add_action( "add_option_{$option_name}", $clear_cache_callback );
565 add_action( "update_option_{$option_name}", $clear_cache_callback );
566 }
567
568 add_action( 'update_option_elementor_font_display', [ Google_Font::class, 'clear_cache' ] );
569 }
570 }
571