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

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

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