| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
use Elementor\Core\Admin\Menu\Admin_Menu_Manager; |
| 5 |
use Elementor\Includes\Settings\AdminMenuItems\Admin_Menu_Item; |
| 6 |
use Elementor\Includes\Settings\AdminMenuItems\Get_Help_Menu_Item; |
| 7 |
use Elementor\Includes\Settings\AdminMenuItems\Getting_Started_Menu_Item; |
| 8 |
use Elementor\Modules\Promotions\Module as Promotions_Module; |
| 9 |
use Elementor\TemplateLibrary\Source_Local; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly. |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Elementor "Settings" page in WordPress Dashboard. |
| 17 |
* |
| 18 |
* Elementor settings page handler class responsible for creating and displaying |
| 19 |
* Elementor "Settings" page in WordPress dashboard. |
| 20 |
* |
| 21 |
* @since 1.0.0 |
| 22 |
*/ |
| 23 |
class Settings extends Settings_Page { |
| 24 |
|
| 25 |
/** |
| 26 |
* Settings page ID for Elementor settings. |
| 27 |
*/ |
| 28 |
const PAGE_ID = 'elementor'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Upgrade menu priority. |
| 32 |
*/ |
| 33 |
const MENU_PRIORITY_GO_PRO = 502; |
| 34 |
|
| 35 |
/** |
| 36 |
* Settings page field for update time. |
| 37 |
*/ |
| 38 |
const UPDATE_TIME_FIELD = '_elementor_settings_update_time'; |
| 39 |
|
| 40 |
/** |
| 41 |
* Settings page general tab slug. |
| 42 |
*/ |
| 43 |
const TAB_GENERAL = 'general'; |
| 44 |
|
| 45 |
/** |
| 46 |
* Settings page style tab slug. |
| 47 |
*/ |
| 48 |
const TAB_STYLE = 'style'; |
| 49 |
|
| 50 |
/** |
| 51 |
* Settings page integrations tab slug. |
| 52 |
*/ |
| 53 |
const TAB_INTEGRATIONS = 'integrations'; |
| 54 |
|
| 55 |
/** |
| 56 |
* Settings page advanced tab slug. |
| 57 |
*/ |
| 58 |
const TAB_ADVANCED = 'advanced'; |
| 59 |
|
| 60 |
const ADMIN_MENU_PRIORITY = 10; |
| 61 |
|
| 62 |
/** |
| 63 |
* Register admin menu. |
| 64 |
* |
| 65 |
* Add new Elementor Settings admin menu. |
| 66 |
* |
| 67 |
* Fired by `admin_menu` action. |
| 68 |
* |
| 69 |
* @since 1.0.0 |
| 70 |
* @access public |
| 71 |
*/ |
| 72 |
public function register_admin_menu() { |
| 73 |
global $menu; |
| 74 |
|
| 75 |
$menu[] = [ '', 'read', 'separator-elementor', '', 'wp-menu-separator elementor' ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 76 |
|
| 77 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 78 |
return; |
| 79 |
} |
| 80 |
|
| 81 |
add_menu_page( |
| 82 |
esc_html__( 'Elementor', 'elementor' ), |
| 83 |
esc_html__( 'Elementor', 'elementor' ), |
| 84 |
'manage_options', |
| 85 |
self::PAGE_ID, |
| 86 |
[ $this, 'display_settings_page' ], |
| 87 |
'', |
| 88 |
'58.5' |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Reorder the Elementor menu items in admin. |
| 94 |
* Based on WC. |
| 95 |
* |
| 96 |
* @since 2.4.0 |
| 97 |
* |
| 98 |
* @param array $menu_order Menu order. |
| 99 |
* @return array |
| 100 |
*/ |
| 101 |
public function menu_order( $menu_order ) { |
| 102 |
// Initialize our custom order array. |
| 103 |
$elementor_menu_order = []; |
| 104 |
|
| 105 |
// Get the index of our custom separator. |
| 106 |
$elementor_separator = array_search( 'separator-elementor', $menu_order, true ); |
| 107 |
|
| 108 |
// Get index of library menu. |
| 109 |
$elementor_library = array_search( Source_Local::ADMIN_MENU_SLUG, $menu_order, true ); |
| 110 |
|
| 111 |
// Loop through menu order and do some rearranging. |
| 112 |
foreach ( $menu_order as $index => $item ) { |
| 113 |
if ( 'elementor' === $item ) { |
| 114 |
$elementor_menu_order[] = 'separator-elementor'; |
| 115 |
$elementor_menu_order[] = $item; |
| 116 |
$elementor_menu_order[] = Source_Local::ADMIN_MENU_SLUG; |
| 117 |
|
| 118 |
unset( $menu_order[ $elementor_separator ] ); |
| 119 |
unset( $menu_order[ $elementor_library ] ); |
| 120 |
} elseif ( ! in_array( $item, [ 'separator-elementor' ], true ) ) { |
| 121 |
$elementor_menu_order[] = $item; |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
// Return order. |
| 126 |
return $elementor_menu_order; |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Register Elementor knowledge base sub-menu. |
| 131 |
* |
| 132 |
* Add new Elementor knowledge base sub-menu under the main Elementor menu. |
| 133 |
* |
| 134 |
* Fired by `admin_menu` action. |
| 135 |
* |
| 136 |
* @since 2.0.3 |
| 137 |
* @access private |
| 138 |
*/ |
| 139 |
private function register_knowledge_base_menu( Admin_Menu_Manager $admin_menu ) { |
| 140 |
$admin_menu->register( 'elementor-getting-started', new Getting_Started_Menu_Item() ); |
| 141 |
$admin_menu->register( 'go_knowledge_base_site', new Get_Help_Menu_Item() ); |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Go Elementor Pro. |
| 146 |
* |
| 147 |
* Redirect the Elementor Pro page the clicking the Elementor Pro menu link. |
| 148 |
* |
| 149 |
* Fired by `admin_init` action. |
| 150 |
* |
| 151 |
* @since 2.0.3 |
| 152 |
* @access public |
| 153 |
*/ |
| 154 |
public function handle_external_redirects() { |
| 155 |
if ( empty( $_GET['page'] ) ) { |
| 156 |
return; |
| 157 |
} |
| 158 |
|
| 159 |
if ( 'go_knowledge_base_site' === $_GET['page'] ) { |
| 160 |
wp_redirect( Get_Help_Menu_Item::URL ); |
| 161 |
die; |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* On admin init. |
| 167 |
* |
| 168 |
* Preform actions on WordPress admin initialization. |
| 169 |
* |
| 170 |
* Fired by `admin_init` action. |
| 171 |
* |
| 172 |
* @since 2.0.0 |
| 173 |
* @access public |
| 174 |
*/ |
| 175 |
public function on_admin_init() { |
| 176 |
$this->handle_external_redirects(); |
| 177 |
|
| 178 |
$this->maybe_remove_all_admin_notices(); |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Change "Settings" menu name. |
| 183 |
* |
| 184 |
* Update the name of the Settings admin menu from "Elementor" to "Settings". |
| 185 |
* |
| 186 |
* Fired by `admin_menu` action. |
| 187 |
* |
| 188 |
* @since 1.0.0 |
| 189 |
* @access public |
| 190 |
*/ |
| 191 |
public function admin_menu_change_name() { |
| 192 |
Utils::change_submenu_first_item_label( 'elementor', esc_html__( 'Settings', 'elementor' ) ); |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Update CSS print method. |
| 197 |
* |
| 198 |
* Clear post CSS cache. |
| 199 |
* |
| 200 |
* Fired by `add_option_elementor_css_print_method` and |
| 201 |
* `update_option_elementor_css_print_method` actions. |
| 202 |
* |
| 203 |
* @since 1.7.5 |
| 204 |
* @access public |
| 205 |
* @deprecated 3.0.0 |
| 206 |
*/ |
| 207 |
public function update_css_print_method() { |
| 208 |
Plugin::$instance->files_manager->clear_cache(); |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* Create tabs. |
| 213 |
* |
| 214 |
* Return the settings page tabs, sections and fields. |
| 215 |
* |
| 216 |
* @since 1.5.0 |
| 217 |
* @access protected |
| 218 |
* |
| 219 |
* @return array An array with the settings page tabs, sections and fields. |
| 220 |
*/ |
| 221 |
protected function create_tabs() { |
| 222 |
$validations_class_name = __NAMESPACE__ . '\Settings_Validations'; |
| 223 |
|
| 224 |
return [ |
| 225 |
self::TAB_GENERAL => [ |
| 226 |
'label' => esc_html__( 'General', 'elementor' ), |
| 227 |
'sections' => [ |
| 228 |
'general' => [ |
| 229 |
'fields' => [ |
| 230 |
self::UPDATE_TIME_FIELD => [ |
| 231 |
'full_field_id' => self::UPDATE_TIME_FIELD, |
| 232 |
'field_args' => [ |
| 233 |
'type' => 'hidden', |
| 234 |
], |
| 235 |
'setting_args' => [ $validations_class_name, 'current_time' ], |
| 236 |
], |
| 237 |
'cpt_support' => [ |
| 238 |
'label' => esc_html__( 'Post Types', 'elementor' ), |
| 239 |
'field_args' => [ |
| 240 |
'type' => 'checkbox_list_cpt', |
| 241 |
'std' => [ 'page', 'post' ], |
| 242 |
'exclude' => [ 'attachment', 'elementor_library' ], |
| 243 |
], |
| 244 |
'setting_args' => [ $validations_class_name, 'checkbox_list' ], |
| 245 |
], |
| 246 |
'disable_color_schemes' => [ |
| 247 |
'label' => esc_html__( 'Disable Default Colors', 'elementor' ), |
| 248 |
'field_args' => [ |
| 249 |
'type' => 'checkbox', |
| 250 |
'value' => 'yes', |
| 251 |
'sub_desc' => esc_html__( 'Checking this box will disable Elementor\'s Default Colors, and make Elementor inherit the colors from your theme.', 'elementor' ), |
| 252 |
], |
| 253 |
], |
| 254 |
'disable_typography_schemes' => [ |
| 255 |
'label' => esc_html__( 'Disable Default Fonts', 'elementor' ), |
| 256 |
'field_args' => [ |
| 257 |
'type' => 'checkbox', |
| 258 |
'value' => 'yes', |
| 259 |
'sub_desc' => esc_html__( 'Checking this box will disable Elementor\'s Default Fonts, and make Elementor inherit the fonts from your theme.', 'elementor' ), |
| 260 |
], |
| 261 |
], |
| 262 |
], |
| 263 |
], |
| 264 |
'usage' => [ |
| 265 |
'label' => esc_html__( 'Improve Elementor', 'elementor' ), |
| 266 |
'fields' => $this->get_usage_fields(), |
| 267 |
], |
| 268 |
], |
| 269 |
], |
| 270 |
self::TAB_INTEGRATIONS => [ |
| 271 |
'label' => esc_html__( 'Integrations', 'elementor' ), |
| 272 |
'sections' => [ |
| 273 |
'google_maps' => [ |
| 274 |
'label' => esc_html__( 'Google Maps Embed API', 'elementor' ), |
| 275 |
'callback' => function() { |
| 276 |
printf( |
| 277 |
/* translators: 1: Link open tag, 2: Link close tag */ |
| 278 |
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' ), |
| 279 |
'<a target="_blank" href="https://developers.google.com/maps/documentation/embed/get-api-key">', |
| 280 |
'</a>' |
| 281 |
); |
| 282 |
}, |
| 283 |
'fields' => [ |
| 284 |
'google_maps_api_key' => [ |
| 285 |
'label' => esc_html__( 'API Key', 'elementor' ), |
| 286 |
'field_args' => [ |
| 287 |
'class' => 'elementor_google_maps_api_key', |
| 288 |
'type' => 'text', |
| 289 |
], |
| 290 |
], |
| 291 |
], |
| 292 |
], |
| 293 |
], |
| 294 |
], |
| 295 |
self::TAB_ADVANCED => [ |
| 296 |
'label' => esc_html__( 'Advanced', 'elementor' ), |
| 297 |
'sections' => [ |
| 298 |
'advanced' => [ |
| 299 |
'fields' => [ |
| 300 |
'css_print_method' => [ |
| 301 |
'label' => esc_html__( 'CSS Print Method', 'elementor' ), |
| 302 |
'field_args' => [ |
| 303 |
'class' => 'elementor_css_print_method', |
| 304 |
'type' => 'select', |
| 305 |
'std' => 'external', |
| 306 |
'options' => [ |
| 307 |
'external' => esc_html__( 'External File', 'elementor' ), |
| 308 |
'internal' => esc_html__( 'Internal Embedding', 'elementor' ), |
| 309 |
], |
| 310 |
'desc' => '<div class="elementor-css-print-method-description" data-value="external" style="display: none">' . esc_html__( 'Use external CSS files for all generated stylesheets. Choose this setting for better performance (recommended).', 'elementor' ) . '</div><div class="elementor-css-print-method-description" data-value="internal" style="display: none">' . esc_html__( 'Use internal CSS that is embedded in the head of the page. For troubleshooting server configuration conflicts and managing development environments.', 'elementor' ) . '</div>', |
| 311 |
], |
| 312 |
], |
| 313 |
'editor_break_lines' => [ |
| 314 |
'label' => esc_html__( 'Switch Editor Loader Method', 'elementor' ), |
| 315 |
'field_args' => [ |
| 316 |
'type' => 'select', |
| 317 |
'std' => '', |
| 318 |
'options' => [ |
| 319 |
'' => esc_html__( 'Disable', 'elementor' ), |
| 320 |
'1' => esc_html__( 'Enable', 'elementor' ), |
| 321 |
], |
| 322 |
'desc' => esc_html__( 'For troubleshooting server configuration conflicts.', 'elementor' ), |
| 323 |
], |
| 324 |
], |
| 325 |
'unfiltered_files_upload' => [ |
| 326 |
'label' => esc_html__( 'Enable Unfiltered File Uploads', 'elementor' ), |
| 327 |
'field_args' => [ |
| 328 |
'type' => 'select', |
| 329 |
'std' => '', |
| 330 |
'options' => [ |
| 331 |
'' => esc_html__( 'Disable', 'elementor' ), |
| 332 |
'1' => esc_html__( 'Enable', 'elementor' ), |
| 333 |
], |
| 334 |
'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' ), |
| 335 |
], |
| 336 |
], |
| 337 |
'google_font' => [ |
| 338 |
'label' => esc_html__( 'Google Fonts', 'elementor' ), |
| 339 |
'field_args' => [ |
| 340 |
'type' => 'select', |
| 341 |
'std' => '1', |
| 342 |
'options' => [ |
| 343 |
'1' => esc_html__( 'Enable', 'elementor' ), |
| 344 |
'0' => esc_html__( 'Disable', 'elementor' ), |
| 345 |
], |
| 346 |
'desc' => sprintf( |
| 347 |
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' ), |
| 348 |
'<a href="' . admin_url( 'admin.php?page=elementor_custom_fonts' ) . '">', |
| 349 |
'</a>' |
| 350 |
), |
| 351 |
], |
| 352 |
], |
| 353 |
'font_display' => [ |
| 354 |
'label' => esc_html__( 'Google Fonts Load', 'elementor' ), |
| 355 |
'field_args' => [ |
| 356 |
'type' => 'select', |
| 357 |
'std' => 'auto', |
| 358 |
'options' => [ |
| 359 |
'auto' => esc_html__( 'Default', 'elementor' ), |
| 360 |
'block' => esc_html__( 'Blocking', 'elementor' ), |
| 361 |
'swap' => esc_html__( 'Swap', 'elementor' ), |
| 362 |
'fallback' => esc_html__( 'Fallback', 'elementor' ), |
| 363 |
'optional' => esc_html__( 'Optional', 'elementor' ), |
| 364 |
], |
| 365 |
'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 (Default: Auto).', 'elementor' ), |
| 366 |
], |
| 367 |
], |
| 368 |
], |
| 369 |
], |
| 370 |
], |
| 371 |
], |
| 372 |
]; |
| 373 |
} |
| 374 |
|
| 375 |
/** |
| 376 |
* Get settings page title. |
| 377 |
* |
| 378 |
* Retrieve the title for the settings page. |
| 379 |
* |
| 380 |
* @since 1.5.0 |
| 381 |
* @access protected |
| 382 |
* |
| 383 |
* @return string Settings page title. |
| 384 |
*/ |
| 385 |
protected function get_page_title() { |
| 386 |
if ( Plugin::$instance->experiments->is_feature_active( 'admin_menu_rearrangement' ) ) { |
| 387 |
return esc_html__( 'Settings', 'elementor' ); |
| 388 |
} |
| 389 |
|
| 390 |
return esc_html__( 'Elementor', 'elementor' ); |
| 391 |
} |
| 392 |
|
| 393 |
/** |
| 394 |
* @since 2.2.0 |
| 395 |
* @access private |
| 396 |
*/ |
| 397 |
private function maybe_remove_all_admin_notices() { |
| 398 |
$elementor_pages = [ |
| 399 |
'elementor-getting-started', |
| 400 |
'elementor_custom_fonts', |
| 401 |
'elementor_custom_icons', |
| 402 |
'elementor-license', |
| 403 |
'e-form-submissions', |
| 404 |
'elementor_custom_custom_code', |
| 405 |
'popup_templates', |
| 406 |
]; |
| 407 |
|
| 408 |
if ( empty( $_GET['page'] ) || ! in_array( $_GET['page'], $elementor_pages, true ) ) { |
| 409 |
return; |
| 410 |
} |
| 411 |
|
| 412 |
remove_all_actions( 'admin_notices' ); |
| 413 |
} |
| 414 |
|
| 415 |
/** |
| 416 |
* Settings page constructor. |
| 417 |
* |
| 418 |
* Initializing Elementor "Settings" page. |
| 419 |
* |
| 420 |
* @since 1.0.0 |
| 421 |
* @access public |
| 422 |
*/ |
| 423 |
public function __construct() { |
| 424 |
parent::__construct(); |
| 425 |
|
| 426 |
add_action( 'admin_init', [ $this, 'on_admin_init' ] ); |
| 427 |
|
| 428 |
if ( ! Plugin::$instance->experiments->is_feature_active( 'admin_menu_rearrangement' ) ) { |
| 429 |
add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 20 ); |
| 430 |
|
| 431 |
add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) { |
| 432 |
$this->register_knowledge_base_menu( $admin_menu ); |
| 433 |
}, Promotions_Module::ADMIN_MENU_PRIORITY - 1 ); |
| 434 |
|
| 435 |
add_action( 'admin_menu', [ $this, 'admin_menu_change_name' ], 200 ); |
| 436 |
|
| 437 |
add_filter( 'custom_menu_order', '__return_true' ); |
| 438 |
add_filter( 'menu_order', [ $this, 'menu_order' ] ); |
| 439 |
} |
| 440 |
|
| 441 |
$clear_cache_callback = [ Plugin::$instance->files_manager, 'clear_cache' ]; |
| 442 |
|
| 443 |
// Clear CSS Meta after change css related methods. |
| 444 |
$css_settings = [ |
| 445 |
'elementor_disable_color_schemes', |
| 446 |
'elementor_disable_typography_schemes', |
| 447 |
'elementor_css_print_method', |
| 448 |
]; |
| 449 |
|
| 450 |
foreach ( $css_settings as $option_name ) { |
| 451 |
add_action( "add_option_{$option_name}", $clear_cache_callback ); |
| 452 |
add_action( "update_option_{$option_name}", $clear_cache_callback ); |
| 453 |
} |
| 454 |
} |
| 455 |
} |
| 456 |
|