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

585 lines 18.0 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 /* translators: 1: Link opening tag, 2: Link closing tag */
375 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' ),
376 '<a href="' . admin_url( 'admin.php?page=elementor_custom_fonts' ) . '">',
377 '</a>'
378 ),
379 ],
380 ],
381 'font_display' => [
382 'label' => esc_html__( 'Google Fonts Load', 'elementor' ),
383 'field_args' => [
384 'type' => 'select',
385 'std' => 'auto',
386 'options' => [
387 'auto' => esc_html__( 'Default', 'elementor' ),
388 'block' => esc_html__( 'Blocking', 'elementor' ),
389 'swap' => esc_html__( 'Swap', 'elementor' ),
390 'fallback' => esc_html__( 'Fallback', 'elementor' ),
391 'optional' => esc_html__( 'Optional', 'elementor' ),
392 ],
393 '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' ),
394 ],
395 ],
396 ],
397 ],
398 ],
399 ],
400 self::TAB_PERFORMANCE => [
401 'label' => esc_html__( 'Performance', 'elementor' ),
402 'sections' => [
403 'performance' => [
404 'label' => esc_html__( 'Performance', 'elementor' ),
405 'callback' => function() {
406 printf(
407 '<p>%s</p><br><hr><br>',
408 esc_html__( 'Improve loading times on your site by selecting the optimization tools that best fit your requirements.', 'elementor' )
409 );
410 },
411 'fields' => [
412 'css_print_method' => [
413 'label' => esc_html__( 'CSS Print Method', 'elementor' ),
414 'field_args' => [
415 'class' => 'elementor_css_print_method',
416 'type' => 'select',
417 'std' => 'external',
418 'options' => [
419 'external' => esc_html__( 'External File', 'elementor' ),
420 'internal' => esc_html__( 'Internal Embedding', 'elementor' ),
421 ],
422 'desc' => sprintf(
423 /* translators: %s: <head> tag. */
424 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' ),
425 '<code>&lt;head&gt;</code>',
426 ),
427 ],
428 ],
429 'optimized_image_loading' => [
430 'label' => esc_html__( 'Optimized Image Loading', 'elementor' ),
431 'field_args' => [
432 'type' => 'select',
433 'std' => '1',
434 'options' => [
435 '1' => esc_html__( 'Enable', 'elementor' ),
436 '0' => esc_html__( 'Disable', 'elementor' ),
437 ],
438 'desc' => sprintf(
439 /* translators: 1: fetchpriority attribute, 2: lazy loading attribute. */
440 esc_html__( 'Improve performance by applying %1$s on LCP image and %2$s on images below the fold.', 'elementor' ),
441 '<code>fetchpriority="high"</code>',
442 '<code>loading="lazy"</code>'
443 ),
444 ],
445 ],
446 'optimized_gutenberg_loading' => [
447 'label' => esc_html__( 'Optimized Gutenberg Loading', 'elementor' ),
448 'field_args' => [
449 'type' => 'select',
450 'std' => '1',
451 'options' => [
452 '1' => esc_html__( 'Enable', 'elementor' ),
453 '0' => esc_html__( 'Disable', 'elementor' ),
454 ],
455 'desc' => esc_html__( 'Reduce unnecessary render-blocking loads by dequeuing unused Gutenberg block editor scripts and styles.', 'elementor' ),
456 ],
457 ],
458 'lazy_load_background_images' => [
459 'label' => esc_html__( 'Lazy Load Background Images', 'elementor' ),
460 'field_args' => [
461 'type' => 'select',
462 'std' => '1',
463 'options' => [
464 '1' => esc_html__( 'Enable', 'elementor' ),
465 '0' => esc_html__( 'Disable', 'elementor' ),
466 ],
467 'desc' => esc_html__( 'Improve initial page load performance by lazy loading all background images except the first one.', 'elementor' ),
468 ],
469 ],
470 'local_google_fonts' => [
471 'label' => esc_html__( 'Load Google Fonts Locally', 'elementor' ),
472 'field_args' => [
473 'type' => 'select',
474 'std' => '0',
475 'options' => [
476 '1' => esc_html__( 'Enable', 'elementor' ),
477 '0' => esc_html__( 'Disable', 'elementor' ),
478 ],
479 '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' ),
480 ],
481 ],
482 ],
483 ],
484 ],
485 ],
486 ];
487 }
488
489 /**
490 * Get settings page title.
491 *
492 * Retrieve the title for the settings page.
493 *
494 * @since 1.5.0
495 * @access protected
496 *
497 * @return string Settings page title.
498 */
499 protected function get_page_title() {
500 return esc_html__( 'Elementor', 'elementor' );
501 }
502
503 /**
504 * @since 2.2.0
505 * @access private
506 */
507 private function maybe_remove_all_admin_notices() {
508 $elementor_pages = [
509 'elementor-getting-started',
510 'elementor-system-info',
511 'e-form-submissions',
512 'elementor_custom_fonts',
513 'elementor_custom_icons',
514 'elementor-license',
515 'elementor_custom_code',
516 'popup_templates',
517 'elementor-apps',
518 ];
519
520 if ( empty( $_GET['page'] ) || ! in_array( $_GET['page'], $elementor_pages, true ) ) {
521 return;
522 }
523
524 remove_all_actions( 'admin_notices' );
525 }
526
527 public function add_generator_tag_settings( $settings ) {
528 $css_print_method = get_option( 'elementor_css_print_method', 'external' );
529 $settings[] = 'css_print_method-' . $css_print_method;
530
531 $google_font = Fonts::is_google_fonts_enabled() ? 'enabled' : 'disabled';
532 $settings[] = 'google_font-' . $google_font;
533
534 $font_display = Fonts::get_font_display_setting();
535 $settings[] = 'font_display-' . $font_display;
536
537 return $settings;
538 }
539
540 /**
541 * Settings page constructor.
542 *
543 * Initializing Elementor "Settings" page.
544 *
545 * @since 1.0.0
546 * @access public
547 */
548 public function __construct() {
549 parent::__construct();
550
551 $this->home_module = new Home_Module();
552
553 add_action( 'admin_init', [ $this, 'on_admin_init' ] );
554 add_filter( 'elementor/generator_tag/settings', [ $this, 'add_generator_tag_settings' ] );
555
556 add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 20 );
557
558 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
559 $this->register_knowledge_base_menu( $admin_menu );
560 }, Promotions_Module::ADMIN_MENU_PRIORITY - 1 );
561
562 add_action( 'admin_menu', [ $this, 'admin_menu_change_name' ], 200 );
563
564 add_filter( 'custom_menu_order', '__return_true' );
565 add_filter( 'menu_order', [ $this, 'menu_order' ] );
566
567 $clear_cache_callback = [ Plugin::$instance->files_manager, 'clear_cache' ];
568
569 // Clear CSS Meta after change css related methods.
570 $css_settings = [
571 'elementor_disable_color_schemes',
572 'elementor_disable_typography_schemes',
573 'elementor_css_print_method',
574 'elementor_local_google_fonts',
575 ];
576
577 foreach ( $css_settings as $option_name ) {
578 add_action( "add_option_{$option_name}", $clear_cache_callback );
579 add_action( "update_option_{$option_name}", $clear_cache_callback );
580 }
581
582 add_action( 'update_option_elementor_font_display', [ Google_Font::class, 'clear_cache' ] );
583 }
584 }
585