home_module->is_experiment_active() ? 'display_home_screen' : 'display_settings_page', ], '', '58.5' ); if ( $this->home_module->is_experiment_active() ) { add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) { $admin_menu->register( 'elementor-settings', new Admin_Menu_Item( $this ) ); }, 0 ); } } public function display_home_screen() { echo '
'; } /** * Reorder the Elementor menu items in admin. * Based on WC. * * @since 2.4.0 * * @param array $menu_order Menu order. * @return array */ public function menu_order( $menu_order ) { // Initialize our custom order array. $elementor_menu_order = []; // Get the index of our custom separator. $elementor_separator = array_search( 'separator-elementor', $menu_order, true ); // Get index of library menu. $elementor_library = array_search( Source_Local::ADMIN_MENU_SLUG, $menu_order, true ); // Loop through menu order and do some rearranging. foreach ( $menu_order as $index => $item ) { if ( 'elementor' === $item ) { $elementor_menu_order[] = 'separator-elementor'; $elementor_menu_order[] = $item; $elementor_menu_order[] = Source_Local::ADMIN_MENU_SLUG; unset( $menu_order[ $elementor_separator ] ); unset( $menu_order[ $elementor_library ] ); } elseif ( ! in_array( $item, [ 'separator-elementor' ], true ) ) { $elementor_menu_order[] = $item; } } // Return order. return $elementor_menu_order; } /** * Register Elementor knowledge base sub-menu. * * Add new Elementor knowledge base sub-menu under the main Elementor menu. * * Fired by `admin_menu` action. * * @since 2.0.3 * @access private */ private function register_knowledge_base_menu( Admin_Menu_Manager $admin_menu ) { $admin_menu->register( 'elementor-getting-started', new Getting_Started_Menu_Item() ); $admin_menu->register( 'go_knowledge_base_site', new Get_Help_Menu_Item() ); } /** * Go Elementor Pro. * * Redirect the Elementor Pro page the clicking the Elementor Pro menu link. * * Fired by `admin_init` action. * * @since 2.0.3 * @access public */ public function handle_external_redirects() { if ( empty( $_GET['page'] ) ) { return; } if ( 'go_knowledge_base_site' === $_GET['page'] ) { wp_redirect( Get_Help_Menu_Item::URL ); die; } } /** * On admin init. * * Preform actions on WordPress admin initialization. * * Fired by `admin_init` action. * * @since 2.0.0 * @access public */ public function on_admin_init() { $this->handle_external_redirects(); $this->maybe_remove_all_admin_notices(); } /** * Change "Settings" menu name. * * Update the name of the Settings admin menu from "Elementor" to "Settings". * * Fired by `admin_menu` action. * * @since 1.0.0 * @access public */ public function admin_menu_change_name() { $menu_name = $this->home_module->is_experiment_active() ? esc_html__( 'Home', 'elementor' ) : esc_html__( 'Settings', 'elementor' ); Utils::change_submenu_first_item_label( 'elementor', $menu_name ); } /** * Update CSS print method. * * Clear post CSS cache. * * Fired by `add_option_elementor_css_print_method` and * `update_option_elementor_css_print_method` actions. * * @since 1.7.5 * @access public * @deprecated 3.0.0 Use `Plugin::$instance->files_manager->clear_cache()` method instead. */ public function update_css_print_method() { Plugin::$instance->files_manager->clear_cache(); } /** * Create tabs. * * Return the settings page tabs, sections and fields. * * @since 1.5.0 * @access protected * * @return array An array with the settings page tabs, sections and fields. */ protected function create_tabs() { $validations_class_name = __NAMESPACE__ . '\Settings_Validations'; return [ self::TAB_GENERAL => [ 'label' => esc_html__( 'General', 'elementor' ), 'sections' => [ 'general' => [ 'label' => esc_html__( 'General', 'elementor' ), 'callback' => function() { printf( '%s
%s
%s
<head>
',
),
],
],
'optimized_image_loading' => [
'label' => esc_html__( 'Optimized Image Loading', 'elementor' ),
'field_args' => [
'type' => 'select',
'std' => '1',
'options' => [
'1' => esc_html__( 'Enable', 'elementor' ),
'0' => esc_html__( 'Disable', 'elementor' ),
],
'desc' => sprintf(
/* translators: 1: fetchpriority attribute, 2: lazy loading attribute. */
esc_html__( 'Improve performance by applying %1$s on LCP image and %2$s on images below the fold.', 'elementor' ),
'fetchpriority="high"
',
'loading="lazy"
'
),
],
],
'optimized_gutenberg_loading' => [
'label' => esc_html__( 'Optimized Gutenberg Loading', 'elementor' ),
'field_args' => [
'type' => 'select',
'std' => '1',
'options' => [
'1' => esc_html__( 'Enable', 'elementor' ),
'0' => esc_html__( 'Disable', 'elementor' ),
],
'desc' => esc_html__( 'Reduce unnecessary render-blocking loads by dequeuing unused Gutenberg block editor scripts and styles.', 'elementor' ),
],
],
'lazy_load_background_images' => [
'label' => esc_html__( 'Lazy Load Background Images', 'elementor' ),
'field_args' => [
'type' => 'select',
'std' => '1',
'options' => [
'1' => esc_html__( 'Enable', 'elementor' ),
'0' => esc_html__( 'Disable', 'elementor' ),
],
'desc' => esc_html__( 'Improve initial page load performance by lazy loading all background images except the first one.', 'elementor' ),
],
],
],
],
],
],
];
}
/**
* Get settings page title.
*
* Retrieve the title for the settings page.
*
* @since 1.5.0
* @access protected
*
* @return string Settings page title.
*/
protected function get_page_title() {
return esc_html__( 'Elementor', 'elementor' );
}
/**
* @since 2.2.0
* @access private
*/
private function maybe_remove_all_admin_notices() {
$elementor_pages = [
'elementor-getting-started',
'elementor-system-info',
'e-form-submissions',
'elementor_custom_fonts',
'elementor_custom_icons',
'elementor-license',
'elementor_custom_code',
'popup_templates',
'elementor-apps',
];
if ( empty( $_GET['page'] ) || ! in_array( $_GET['page'], $elementor_pages, true ) ) {
return;
}
remove_all_actions( 'admin_notices' );
}
public function add_generator_tag_settings( $settings ) {
$css_print_method = get_option( 'elementor_css_print_method', 'external' );
$settings[] = 'css_print_method-' . $css_print_method;
$google_font = Fonts::is_google_fonts_enabled() ? 'enabled' : 'disabled';
$settings[] = 'google_font-' . $google_font;
$font_display = Fonts::get_font_display_setting();
$settings[] = 'font_display-' . $font_display;
return $settings;
}
/**
* Settings page constructor.
*
* Initializing Elementor "Settings" page.
*
* @since 1.0.0
* @access public
*/
public function __construct() {
parent::__construct();
$this->home_module = new Home_Module();
add_action( 'admin_init', [ $this, 'on_admin_init' ] );
add_filter( 'elementor/generator_tag/settings', [ $this, 'add_generator_tag_settings' ] );
add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 20 );
add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
$this->register_knowledge_base_menu( $admin_menu );
}, Promotions_Module::ADMIN_MENU_PRIORITY - 1 );
add_action( 'admin_menu', [ $this, 'admin_menu_change_name' ], 200 );
add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'menu_order', [ $this, 'menu_order' ] );
$clear_cache_callback = [ Plugin::$instance->files_manager, 'clear_cache' ];
// Clear CSS Meta after change css related methods.
$css_settings = [
'elementor_disable_color_schemes',
'elementor_disable_typography_schemes',
'elementor_css_print_method',
];
foreach ( $css_settings as $option_name ) {
add_action( "add_option_{$option_name}", $clear_cache_callback );
add_action( "update_option_{$option_name}", $clear_cache_callback );
}
}
}