| @@ -1,13 +1,15 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor; |
| 3 | 3 | |
| 4 | +use Elementor\Core\Admin\Menu\Admin_Menu_Manager; | |
| 4 | 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; | |
| 5 | 9 | use Elementor\Modules\Promotions\Module as Promotions_Module; |
| 6 | 10 | use Elementor\TemplateLibrary\Source_Local; |
| 7 | -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; | |
| 8 | -use Elementor\Includes\Settings\AdminMenuItems\Editor_One_Home_Menu; | |
| 9 | -use Elementor\Includes\Settings\AdminMenuItems\Editor_One_Settings_Menu; | |
| 11 | +use Elementor\Modules\Home\Module as Home_Module; | |
| 10 | 12 | |
| 11 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | 14 | exit; // Exit if accessed directly. |
| 13 | 15 | } |
| @@ -42,8 +44,13 @@ | ||
| 42 | 44 | */ |
| 43 | 45 | const TAB_GENERAL = 'general'; |
| 44 | 46 | |
| 45 | 47 | /** |
| 48 | + * Settings page style tab slug. | |
| 49 | + */ | |
| 50 | + const TAB_STYLE = 'style'; | |
| 51 | + | |
| 52 | + /** | |
| 46 | 53 | * Settings page integrations tab slug. |
| 47 | 54 | */ |
| 48 | 55 | const TAB_INTEGRATIONS = 'integrations'; |
| 49 | 56 | |
| @@ -58,9 +65,9 @@ | ||
| 58 | 65 | const TAB_PERFORMANCE = 'performance'; |
| 59 | 66 | |
| 60 | 67 | const ADMIN_MENU_PRIORITY = 10; |
| 61 | 68 | |
| 62 | - const MENU_CAPABILITY_EDIT_POSTS = 'edit_posts'; | |
| 69 | + public Home_Module $home_module; | |
| 63 | 70 | |
| 64 | 71 | /** |
| 65 | 72 | * Register admin menu. |
| 66 | 73 | * |
| @@ -71,9 +78,13 @@ | ||
| 71 | 78 | * @since 1.0.0 |
| 72 | 79 | * @access public |
| 73 | 80 | */ |
| 74 | 81 | public function register_admin_menu() { |
| 75 | - if ( ! current_user_can( self::MENU_CAPABILITY_EDIT_POSTS ) ) { | |
| 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' ) ) { | |
| 76 | 87 | return; |
| 77 | 88 | } |
| 78 | 89 | |
| 79 | 90 | add_menu_page( |
| @@ -78,14 +89,23 @@ | ||
| 78 | 89 | |
| 79 | 90 | add_menu_page( |
| 80 | 91 | esc_html__( 'Elementor', 'elementor' ), |
| 81 | 92 | esc_html__( 'Elementor', 'elementor' ), |
| 82 | - self::MENU_CAPABILITY_EDIT_POSTS, | |
| 93 | + 'manage_options', | |
| 83 | 94 | self::PAGE_ID, |
| 84 | - [ $this, 'display_home_screen' ], | |
| 95 | + [ | |
| 96 | + $this, | |
| 97 | + $this->home_module->is_experiment_active() ? 'display_home_screen' : 'display_settings_page', | |
| 98 | + ], | |
| 85 | 99 | '', |
| 86 | 100 | '58.5' |
| 87 | 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 | + } | |
| 88 | 108 | } |
| 89 | 109 | |
| 90 | 110 | public function display_home_screen() { |
| 91 | 111 | echo '<div id="e-home-screen"></div>'; |
| @@ -90,17 +110,82 @@ | ||
| 90 | 110 | public function display_home_screen() { |
| 91 | 111 | echo '<div id="e-home-screen"></div>'; |
| 92 | 112 | } |
| 93 | 113 | |
| 94 | - private function register_editor_one_settings_menu( Menu_Data_Provider $menu_data_provider ) { | |
| 95 | - $menu_data_provider->register_menu( new Editor_One_Settings_Menu() ); | |
| 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; | |
| 96 | 149 | } |
| 97 | 150 | |
| 98 | - private function register_editor_one_home_menu( Menu_Data_Provider $menu_data_provider ) { | |
| 99 | - $menu_data_provider->register_menu( new Editor_One_Home_Menu() ); | |
| 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() ); | |
| 100 | 164 | } |
| 101 | 165 | |
| 102 | 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 | + /** | |
| 103 | 188 | * On admin init. |
| 104 | 189 | * |
| 105 | 190 | * Preform actions on WordPress admin initialization. |
| 106 | 191 | * |
| @@ -109,12 +194,32 @@ | ||
| 109 | 194 | * @since 2.0.0 |
| 110 | 195 | * @access public |
| 111 | 196 | */ |
| 112 | 197 | public function on_admin_init() { |
| 198 | + $this->handle_external_redirects(); | |
| 199 | + | |
| 113 | 200 | $this->maybe_remove_all_admin_notices(); |
| 114 | 201 | } |
| 115 | 202 | |
| 116 | 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 | + /** | |
| 117 | 222 | * Update CSS print method. |
| 118 | 223 | * |
| 119 | 224 | * Clear post CSS cache. |
| 120 | 225 | * |
| @@ -400,8 +505,9 @@ | ||
| 400 | 505 | * @access private |
| 401 | 506 | */ |
| 402 | 507 | private function maybe_remove_all_admin_notices() { |
| 403 | 508 | $elementor_pages = [ |
| 509 | + 'elementor-getting-started', | |
| 404 | 510 | 'elementor-system-info', |
| 405 | 511 | 'e-form-submissions', |
| 406 | 512 | 'elementor_custom_fonts', |
| 407 | 513 | 'elementor_custom_icons', |
| @@ -441,18 +547,24 @@ | ||
| 441 | 547 | */ |
| 442 | 548 | public function __construct() { |
| 443 | 549 | parent::__construct(); |
| 444 | 550 | |
| 551 | + $this->home_module = new Home_Module(); | |
| 552 | + | |
| 445 | 553 | add_action( 'admin_init', [ $this, 'on_admin_init' ] ); |
| 446 | 554 | add_filter( 'elementor/generator_tag/settings', [ $this, 'add_generator_tag_settings' ] ); |
| 447 | 555 | |
| 448 | 556 | add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 20 ); |
| 449 | 557 | |
| 450 | - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { | |
| 451 | - $this->register_editor_one_settings_menu( $menu_data_provider ); | |
| 452 | - $this->register_editor_one_home_menu( $menu_data_provider ); | |
| 453 | - } ); | |
| 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 ); | |
| 454 | 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 | + | |
| 455 | 567 | $clear_cache_callback = [ Plugin::$instance->files_manager, 'clear_cache' ]; |
| 456 | 568 | |
| 457 | 569 | // Clear CSS Meta after change css related methods. |
| 458 | 570 | $css_settings = [ |
| @@ -458,9 +570,8 @@ | ||
| 458 | 570 | $css_settings = [ |
| 459 | 571 | 'elementor_disable_color_schemes', |
| 460 | 572 | 'elementor_disable_typography_schemes', |
| 461 | 573 | 'elementor_css_print_method', |
| 462 | - 'elementor_local_google_fonts', | |
| 463 | 574 | ]; |
| 464 | 575 | |
| 465 | 576 | foreach ( $css_settings as $option_name ) { |
| 466 | 577 | add_action( "add_option_{$option_name}", $clear_cache_callback ); |