| @@ -1,10 +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; |
| 11 | +use Elementor\Modules\Home\Module as Home_Module; | |
| 7 | 12 | use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; |
| 8 | 13 | use Elementor\Includes\Settings\AdminMenuItems\Editor_One_Home_Menu; |
| 9 | 14 | use Elementor\Includes\Settings\AdminMenuItems\Editor_One_Settings_Menu; |
| 10 | 15 | |
| @@ -42,8 +47,13 @@ | ||
| 42 | 47 | */ |
| 43 | 48 | const TAB_GENERAL = 'general'; |
| 44 | 49 | |
| 45 | 50 | /** |
| 51 | + * Settings page style tab slug. | |
| 52 | + */ | |
| 53 | + const TAB_STYLE = 'style'; | |
| 54 | + | |
| 55 | + /** | |
| 46 | 56 | * Settings page integrations tab slug. |
| 47 | 57 | */ |
| 48 | 58 | const TAB_INTEGRATIONS = 'integrations'; |
| 49 | 59 | |
| @@ -58,10 +68,14 @@ | ||
| 58 | 68 | const TAB_PERFORMANCE = 'performance'; |
| 59 | 69 | |
| 60 | 70 | const ADMIN_MENU_PRIORITY = 10; |
| 61 | 71 | |
| 72 | + const MENU_CAPABILITY_MANAGE_OPTIONS = 'manage_options'; | |
| 73 | + | |
| 62 | 74 | const MENU_CAPABILITY_EDIT_POSTS = 'edit_posts'; |
| 63 | 75 | |
| 76 | + public Home_Module $home_module; | |
| 77 | + | |
| 64 | 78 | /** |
| 65 | 79 | * Register admin menu. |
| 66 | 80 | * |
| 67 | 81 | * Add new Elementor Settings admin menu. |
| @@ -71,9 +85,15 @@ | ||
| 71 | 85 | * @since 1.0.0 |
| 72 | 86 | * @access public |
| 73 | 87 | */ |
| 74 | 88 | public function register_admin_menu() { |
| 75 | - if ( ! current_user_can( self::MENU_CAPABILITY_EDIT_POSTS ) ) { | |
| 89 | + global $menu; | |
| 90 | + | |
| 91 | + $menu[] = [ '', 'read', 'separator-elementor', '', 'wp-menu-separator elementor' ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited | |
| 92 | + | |
| 93 | + $required_capability = $this->get_menu_capability(); | |
| 94 | + | |
| 95 | + if ( ! current_user_can( $required_capability ) ) { | |
| 76 | 96 | return; |
| 77 | 97 | } |
| 78 | 98 | |
| 79 | 99 | add_menu_page( |
| @@ -78,14 +98,25 @@ | ||
| 78 | 98 | |
| 79 | 99 | add_menu_page( |
| 80 | 100 | esc_html__( 'Elementor', 'elementor' ), |
| 81 | 101 | esc_html__( 'Elementor', 'elementor' ), |
| 82 | - self::MENU_CAPABILITY_EDIT_POSTS, | |
| 102 | + $required_capability, | |
| 83 | 103 | self::PAGE_ID, |
| 84 | - [ $this, 'display_home_screen' ], | |
| 104 | + [ | |
| 105 | + $this, | |
| 106 | + $this->home_module->is_experiment_active() ? 'display_home_screen' : 'display_settings_page', | |
| 107 | + ], | |
| 85 | 108 | '', |
| 86 | 109 | '58.5' |
| 87 | 110 | ); |
| 111 | + | |
| 112 | + if ( $this->home_module->is_experiment_active() ) { | |
| 113 | + add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) { | |
| 114 | + if ( ! $this->is_editor_one_active() ) { | |
| 115 | + $admin_menu->register( 'elementor-settings', new Admin_Menu_Item( $this ) ); | |
| 116 | + } | |
| 117 | + }, 0 ); | |
| 118 | + } | |
| 88 | 119 | } |
| 89 | 120 | |
| 90 | 121 | public function display_home_screen() { |
| 91 | 122 | echo '<div id="e-home-screen"></div>'; |
| @@ -90,8 +121,62 @@ | ||
| 90 | 121 | public function display_home_screen() { |
| 91 | 122 | echo '<div id="e-home-screen"></div>'; |
| 92 | 123 | } |
| 93 | 124 | |
| 125 | + /** | |
| 126 | + * Reorder the Elementor menu items in admin. | |
| 127 | + * Based on WC. | |
| 128 | + * | |
| 129 | + * @since 2.4.0 | |
| 130 | + * | |
| 131 | + * @param array $menu_order Menu order. | |
| 132 | + * @return array | |
| 133 | + */ | |
| 134 | + public function menu_order( $menu_order ) { | |
| 135 | + // Initialize our custom order array. | |
| 136 | + $elementor_menu_order = []; | |
| 137 | + | |
| 138 | + // Get the index of our custom separator. | |
| 139 | + $elementor_separator = array_search( 'separator-elementor', $menu_order, true ); | |
| 140 | + | |
| 141 | + // Get index of library menu. | |
| 142 | + $elementor_library = array_search( Source_Local::ADMIN_MENU_SLUG, $menu_order, true ); | |
| 143 | + | |
| 144 | + // Loop through menu order and do some rearranging. | |
| 145 | + foreach ( $menu_order as $index => $item ) { | |
| 146 | + if ( 'elementor' === $item ) { | |
| 147 | + $elementor_menu_order[] = 'separator-elementor'; | |
| 148 | + $elementor_menu_order[] = $item; | |
| 149 | + $elementor_menu_order[] = Source_Local::ADMIN_MENU_SLUG; | |
| 150 | + | |
| 151 | + unset( $menu_order[ $elementor_separator ] ); | |
| 152 | + unset( $menu_order[ $elementor_library ] ); | |
| 153 | + } elseif ( ! in_array( $item, [ 'separator-elementor' ], true ) ) { | |
| 154 | + $elementor_menu_order[] = $item; | |
| 155 | + } | |
| 156 | + } | |
| 157 | + | |
| 158 | + // Return order. | |
| 159 | + return $elementor_menu_order; | |
| 160 | + } | |
| 161 | + | |
| 162 | + /** | |
| 163 | + * Register Elementor knowledge base sub-menu. | |
| 164 | + * | |
| 165 | + * Add new Elementor knowledge base sub-menu under the main Elementor menu. | |
| 166 | + * | |
| 167 | + * Fired by `admin_menu` action. | |
| 168 | + * | |
| 169 | + * @since 2.0.3 | |
| 170 | + * @access private | |
| 171 | + */ | |
| 172 | + private function register_knowledge_base_menu( Admin_Menu_Manager $admin_menu ) { | |
| 173 | + if ( ! Plugin::instance()->modules_manager->get_modules( 'editor-one' ) ) { | |
| 174 | + $admin_menu->register( 'elementor-getting-started', new Getting_Started_Menu_Item() ); | |
| 175 | + $admin_menu->register( 'go_knowledge_base_site', new Get_Help_Menu_Item() ); | |
| 176 | + } | |
| 177 | + } | |
| 178 | + | |
| 94 | 179 | private function register_editor_one_settings_menu( Menu_Data_Provider $menu_data_provider ) { |
| 95 | 180 | $menu_data_provider->register_menu( new Editor_One_Settings_Menu() ); |
| 96 | 181 | } |
| 97 | 182 | |
| @@ -98,9 +183,38 @@ | ||
| 98 | 183 | private function register_editor_one_home_menu( Menu_Data_Provider $menu_data_provider ) { |
| 99 | 184 | $menu_data_provider->register_menu( new Editor_One_Home_Menu() ); |
| 100 | 185 | } |
| 101 | 186 | |
| 187 | + private function is_editor_one_active(): bool { | |
| 188 | + return (bool) Plugin::instance()->modules_manager->get_modules( 'editor-one' ); | |
| 189 | + } | |
| 190 | + | |
| 191 | + private function get_menu_capability(): string { | |
| 192 | + return $this->is_editor_one_active() ? self::MENU_CAPABILITY_EDIT_POSTS : self::MENU_CAPABILITY_MANAGE_OPTIONS; | |
| 193 | + } | |
| 194 | + | |
| 102 | 195 | /** |
| 196 | + * Go Elementor Pro. | |
| 197 | + * | |
| 198 | + * Redirect the Elementor Pro page the clicking the Elementor Pro menu link. | |
| 199 | + * | |
| 200 | + * Fired by `admin_init` action. | |
| 201 | + * | |
| 202 | + * @since 2.0.3 | |
| 203 | + * @access public | |
| 204 | + */ | |
| 205 | + public function handle_external_redirects() { | |
| 206 | + if ( empty( $_GET['page'] ) ) { | |
| 207 | + return; | |
| 208 | + } | |
| 209 | + | |
| 210 | + if ( 'go_knowledge_base_site' === $_GET['page'] ) { | |
| 211 | + wp_redirect( Get_Help_Menu_Item::URL ); | |
| 212 | + die; | |
| 213 | + } | |
| 214 | + } | |
| 215 | + | |
| 216 | + /** | |
| 103 | 217 | * On admin init. |
| 104 | 218 | * |
| 105 | 219 | * Preform actions on WordPress admin initialization. |
| 106 | 220 | * |
| @@ -109,12 +223,32 @@ | ||
| 109 | 223 | * @since 2.0.0 |
| 110 | 224 | * @access public |
| 111 | 225 | */ |
| 112 | 226 | public function on_admin_init() { |
| 227 | + $this->handle_external_redirects(); | |
| 228 | + | |
| 113 | 229 | $this->maybe_remove_all_admin_notices(); |
| 114 | 230 | } |
| 115 | 231 | |
| 116 | 232 | /** |
| 233 | + * Change "Settings" menu name. | |
| 234 | + * | |
| 235 | + * Update the name of the Settings admin menu from "Elementor" to "Settings". | |
| 236 | + * | |
| 237 | + * Fired by `admin_menu` action. | |
| 238 | + * | |
| 239 | + * @since 1.0.0 | |
| 240 | + * @access public | |
| 241 | + */ | |
| 242 | + public function admin_menu_change_name() { | |
| 243 | + $menu_name = $this->home_module->is_experiment_active() | |
| 244 | + ? esc_html__( 'Home', 'elementor' ) | |
| 245 | + : esc_html__( 'Settings', 'elementor' ); | |
| 246 | + | |
| 247 | + Utils::change_submenu_first_item_label( 'elementor', $menu_name ); | |
| 248 | + } | |
| 249 | + | |
| 250 | + /** | |
| 117 | 251 | * Update CSS print method. |
| 118 | 252 | * |
| 119 | 253 | * Clear post CSS cache. |
| 120 | 254 | * |
| @@ -400,8 +534,9 @@ | ||
| 400 | 534 | * @access private |
| 401 | 535 | */ |
| 402 | 536 | private function maybe_remove_all_admin_notices() { |
| 403 | 537 | $elementor_pages = [ |
| 538 | + 'elementor-getting-started', | |
| 404 | 539 | 'elementor-system-info', |
| 405 | 540 | 'e-form-submissions', |
| 406 | 541 | 'elementor_custom_fonts', |
| 407 | 542 | 'elementor_custom_icons', |
| @@ -441,8 +576,10 @@ | ||
| 441 | 576 | */ |
| 442 | 577 | public function __construct() { |
| 443 | 578 | parent::__construct(); |
| 444 | 579 | |
| 580 | + $this->home_module = new Home_Module(); | |
| 581 | + | |
| 445 | 582 | add_action( 'admin_init', [ $this, 'on_admin_init' ] ); |
| 446 | 583 | add_filter( 'elementor/generator_tag/settings', [ $this, 'add_generator_tag_settings' ] ); |
| 447 | 584 | |
| 448 | 585 | add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 20 ); |
| @@ -447,11 +584,22 @@ | ||
| 447 | 584 | |
| 448 | 585 | add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 20 ); |
| 449 | 586 | |
| 450 | 587 | 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 ); | |
| 588 | + if ( $this->home_module->is_experiment_active() ) { | |
| 589 | + $this->register_editor_one_settings_menu( $menu_data_provider ); | |
| 590 | + $this->register_editor_one_home_menu( $menu_data_provider ); | |
| 591 | + } | |
| 453 | 592 | } ); |
| 593 | + | |
| 594 | + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) { | |
| 595 | + $this->register_knowledge_base_menu( $admin_menu ); | |
| 596 | + }, Promotions_Module::ADMIN_MENU_PRIORITY - 1 ); | |
| 597 | + | |
| 598 | + add_action( 'admin_menu', [ $this, 'admin_menu_change_name' ], 200 ); | |
| 599 | + | |
| 600 | + add_filter( 'custom_menu_order', '__return_true' ); | |
| 601 | + add_filter( 'menu_order', [ $this, 'menu_order' ] ); | |
| 454 | 602 | |
| 455 | 603 | $clear_cache_callback = [ Plugin::$instance->files_manager, 'clear_cache' ]; |
| 456 | 604 | |
| 457 | 605 | // Clear CSS Meta after change css related methods. |