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