| @@ -1,14 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Modules\LandingPages; |
| 3 | 3 | |
| 4 | +use Elementor\Core\Admin\Menu\Admin_Menu_Manager; | |
| 5 | +use Elementor\Core\Admin\Menu\Main as MainMenu; | |
| 4 | 6 | use Elementor\Core\Base\Module as BaseModule; |
| 5 | 7 | use Elementor\Core\Documents_Manager; |
| 6 | 8 | use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 7 | 9 | use Elementor\Modules\LandingPages\Documents\Landing_Page; |
| 8 | -use Elementor\Modules\LandingPages\AdminMenuItems\Editor_One_Landing_Pages_Menu; | |
| 10 | +use Elementor\Modules\LandingPages\AdminMenuItems\Landing_Pages_Menu_Item; | |
| 11 | +use Elementor\Modules\LandingPages\AdminMenuItems\Landing_Pages_Empty_View_Menu_Item; | |
| 9 | 12 | use Elementor\Modules\LandingPages\Module as Landing_Pages_Module; |
| 10 | -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; | |
| 11 | 13 | use Elementor\Plugin; |
| 12 | 14 | use Elementor\TemplateLibrary\Source_Local; |
| 13 | 15 | |
| 14 | 16 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -19,9 +21,8 @@ | ||
| 19 | 21 | |
| 20 | 22 | const DOCUMENT_TYPE = 'landing-page'; |
| 21 | 23 | const CPT = 'e-landing-page'; |
| 22 | 24 | const ADMIN_PAGE_SLUG = 'edit.php?post_type=' . self::CPT; |
| 23 | - const ACTIVATION_KEY = 'elementor_landing_pages_activation'; | |
| 24 | 25 | |
| 25 | 26 | private $has_pages = null; |
| 26 | 27 | private $trashed_posts; |
| 27 | 28 | private $new_lp_url; |
| @@ -52,30 +53,19 @@ | ||
| 52 | 53 | 'deprecated' => true, |
| 53 | 54 | ] ); |
| 54 | 55 | } |
| 55 | 56 | |
| 56 | - /** | |
| 57 | - * Should activate landing pages | |
| 58 | - * | |
| 59 | - * Checks whether the Landing Pages should be activated. | |
| 60 | - * | |
| 61 | - * If the activation key set to `1` in wp_options, the Landing Pages feature should be active. Otherwise not. | |
| 62 | - * This is a backwards compatibility for websites that had Landing Pages, therefore couldn't be deactivated. | |
| 63 | - * When deleting posts in Landing Pages CPT, Elementor checks again whether this feature should be activated. | |
| 64 | - * | |
| 65 | - * @since 3.31.0 | |
| 66 | - */ | |
| 67 | 57 | private function should_activate_landing_pages() { |
| 68 | - if ( '1' === get_option( self::ACTIVATION_KEY ) ) { | |
| 58 | + if ( '1' === get_option( 'elementor_landing_pages_activation' ) ) { | |
| 69 | 59 | return true; |
| 70 | 60 | } |
| 71 | 61 | |
| 72 | 62 | if ( $this->has_landing_pages() ) { |
| 73 | - update_option( self::ACTIVATION_KEY, '1' ); | |
| 63 | + update_option( 'elementor_landing_pages_activation', '1' ); | |
| 74 | 64 | return true; |
| 75 | 65 | } |
| 76 | 66 | |
| 77 | - update_option( self::ACTIVATION_KEY, '0' ); | |
| 67 | + update_option( 'elementor_landing_pages_activation', '0' ); | |
| 78 | 68 | return false; |
| 79 | 69 | } |
| 80 | 70 | |
| 81 | 71 | /** |
| @@ -141,9 +131,9 @@ | ||
| 141 | 131 | public function is_elementor_landing_page( $post ) { |
| 142 | 132 | return self::CPT === $post->post_type; |
| 143 | 133 | } |
| 144 | 134 | |
| 145 | - public function get_menu_args() { | |
| 135 | + private function get_menu_args() { | |
| 146 | 136 | if ( $this->has_landing_pages() ) { |
| 147 | 137 | $menu_slug = self::ADMIN_PAGE_SLUG; |
| 148 | 138 | $function = null; |
| 149 | 139 | } else { |
| @@ -156,13 +146,41 @@ | ||
| 156 | 146 | 'function' => $function, |
| 157 | 147 | ]; |
| 158 | 148 | } |
| 159 | 149 | |
| 160 | - private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ): void { | |
| 161 | - $menu_data_provider->register_menu( new Editor_One_Landing_Pages_Menu( $this ) ); | |
| 150 | + private function register_admin_menu( MainMenu $menu ) { | |
| 151 | + $landing_pages_title = esc_html__( 'Landing Pages', 'elementor' ); | |
| 152 | + | |
| 153 | + $menu_args = array_merge( $this->get_menu_args(), [ | |
| 154 | + 'page_title' => $landing_pages_title, | |
| 155 | + 'menu_title' => $landing_pages_title, | |
| 156 | + 'index' => 20, | |
| 157 | + ] ); | |
| 158 | + | |
| 159 | + $menu->add_submenu( $menu_args ); | |
| 162 | 160 | } |
| 163 | 161 | |
| 164 | 162 | /** |
| 163 | + * Add Submenu Page | |
| 164 | + * | |
| 165 | + * Adds the 'Landing Pages' submenu item to the 'Templates' menu item. | |
| 166 | + * | |
| 167 | + * @since 3.1.0 | |
| 168 | + */ | |
| 169 | + private function register_admin_menu_legacy( Admin_Menu_Manager $admin_menu ) { | |
| 170 | + $menu_args = $this->get_menu_args(); | |
| 171 | + | |
| 172 | + $slug = $menu_args['menu_slug']; | |
| 173 | + $function = $menu_args['function']; | |
| 174 | + | |
| 175 | + if ( is_callable( $function ) ) { | |
| 176 | + $admin_menu->register( $slug, new Landing_Pages_Empty_View_Menu_Item( $function ) ); | |
| 177 | + } else { | |
| 178 | + $admin_menu->register( $slug, new Landing_Pages_Menu_Item() ); | |
| 179 | + } | |
| 180 | + } | |
| 181 | + | |
| 182 | + /** | |
| 165 | 183 | * Get 'Add New' Landing Page URL |
| 166 | 184 | * |
| 167 | 185 | * Retrieves the custom URL for the admin dashboard's 'Add New' button in the Landing Pages admin screen. This URL |
| 168 | 186 | * creates a new Landing Pages and directly opens the Elementor Editor with the Template Library modal open on the |
| @@ -461,20 +479,12 @@ | ||
| 461 | 479 | add_action( 'elementor/documents/register', function( Documents_Manager $documents_manager ) { |
| 462 | 480 | $documents_manager->register_document_type( self::DOCUMENT_TYPE, Landing_Page::get_class_full_name() ); |
| 463 | 481 | } ); |
| 464 | 482 | |
| 465 | - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { | |
| 466 | - $this->register_editor_one_menu( $menu_data_provider ); | |
| 467 | - } ); | |
| 483 | + add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) { | |
| 484 | + $this->register_admin_menu_legacy( $admin_menu ); | |
| 485 | + }, Source_Local::ADMIN_MENU_PRIORITY + 20 ); | |
| 468 | 486 | |
| 469 | - add_filter( 'elementor/editor-one/menu/elementor_post_types', function ( array $elementor_post_types ): array { | |
| 470 | - $elementor_post_types[ static::CPT ] = [ | |
| 471 | - 'menu_slug' => 'elementor-editor-templates', | |
| 472 | - 'child_slug' => 'edit.php?post_type=' . static::CPT, | |
| 473 | - ]; | |
| 474 | - return $elementor_post_types; | |
| 475 | - } ); | |
| 476 | - | |
| 477 | 487 | // Add the custom 'Add New' link for Landing Pages into Elementor's admin config. |
| 478 | 488 | add_action( 'elementor/admin/localize_settings', function( array $settings ) { |
| 479 | 489 | return $this->admin_localize_settings( $settings ); |
| 480 | 490 | } ); |
| @@ -482,13 +492,8 @@ | ||
| 482 | 492 | add_filter( 'elementor/template_library/sources/local/register_taxonomy_cpts', function( array $cpts ) { |
| 483 | 493 | $cpts[] = self::CPT; |
| 484 | 494 | |
| 485 | 495 | return $cpts; |
| 486 | - } ); | |
| 487 | - | |
| 488 | - // When deleting posts in Landing Page CPT, force Elementor to check again whether this feature should be activated. | |
| 489 | - add_action( 'deleted_post_' . self::CPT, function () { | |
| 490 | - delete_option( self::ACTIVATION_KEY ); | |
| 491 | 496 | } ); |
| 492 | 497 | |
| 493 | 498 | // In the Landing Pages Admin Table page - Overwrite Template type column header title. |
| 494 | 499 | add_action( 'manage_' . Landing_Pages_Module::CPT . '_posts_columns', function( $posts_columns ) { |