| @@ -1,16 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Modules\LandingPages; |
| 3 | 3 | |
| 4 | +use Elementor\Core\Admin\Menu\Main as MainMenu; | |
| 4 | 5 | use Elementor\Core\Base\Module as BaseModule; |
| 5 | 6 | use Elementor\Core\Documents_Manager; |
| 6 | 7 | use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 7 | 8 | use Elementor\Modules\LandingPages\Documents\Landing_Page; |
| 8 | -use Elementor\Modules\LandingPages\AdminMenuItems\Editor_One_Landing_Pages_Menu; | |
| 9 | 9 | use Elementor\Modules\LandingPages\Module as Landing_Pages_Module; |
| 10 | -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; | |
| 11 | 10 | use Elementor\Plugin; |
| 12 | 11 | use Elementor\TemplateLibrary\Source_Local; |
| 12 | +use Elementor\Utils; | |
| 13 | 13 | |
| 14 | 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | 15 | exit; // Exit if accessed directly. |
| 16 | 16 | } |
| @@ -19,11 +19,10 @@ | ||
| 19 | 19 | |
| 20 | 20 | const DOCUMENT_TYPE = 'landing-page'; |
| 21 | 21 | const CPT = 'e-landing-page'; |
| 22 | 22 | const ADMIN_PAGE_SLUG = 'edit.php?post_type=' . self::CPT; |
| 23 | - const ACTIVATION_KEY = 'elementor_landing_pages_activation'; | |
| 24 | 23 | |
| 25 | - private $has_pages = null; | |
| 24 | + private $posts; | |
| 26 | 25 | private $trashed_posts; |
| 27 | 26 | private $new_lp_url; |
| 28 | 27 | private $permalink_structure; |
| 29 | 28 | |
| @@ -31,55 +30,31 @@ | ||
| 31 | 30 | return 'landing-pages'; |
| 32 | 31 | } |
| 33 | 32 | |
| 34 | 33 | /** |
| 35 | - * Register Experimental Feature | |
| 34 | + * Get Experimental Data | |
| 36 | 35 | * |
| 37 | 36 | * Implementation of this method makes the module an experiment. |
| 38 | 37 | * |
| 39 | - * @since 3.28.0 | |
| 38 | + * @since 3.1.0 | |
| 39 | + * | |
| 40 | + * @return array | |
| 40 | 41 | */ |
| 41 | - private function register_experiment() { | |
| 42 | - Plugin::$instance->experiments->add_feature( [ | |
| 42 | + public static function get_experimental_data() { | |
| 43 | + return [ | |
| 43 | 44 | 'name' => 'landing-pages', |
| 44 | 45 | 'title' => esc_html__( 'Landing Pages', 'elementor' ), |
| 45 | 46 | 'description' => esc_html__( 'Adds a new Elementor content type that allows creating beautiful landing pages instantly in a streamlined workflow.', 'elementor' ), |
| 46 | - 'release_status' => Experiments_Manager::RELEASE_STATUS_BETA, | |
| 47 | + 'release_status' => Experiments_Manager::RELEASE_STATUS_STABLE, | |
| 47 | 48 | 'default' => Experiments_Manager::STATE_ACTIVE, |
| 48 | 49 | 'new_site' => [ |
| 49 | - 'default_inactive' => true, | |
| 50 | - 'minimum_installation_version' => '3.22.0', | |
| 50 | + 'default_active' => true, | |
| 51 | + 'minimum_installation_version' => '3.1.0-beta', | |
| 51 | 52 | ], |
| 52 | - 'deprecated' => true, | |
| 53 | - ] ); | |
| 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 | - private function should_activate_landing_pages() { | |
| 68 | - if ( '1' === get_option( self::ACTIVATION_KEY ) ) { | |
| 69 | - return true; | |
| 70 | - } | |
| 71 | - | |
| 72 | - if ( $this->has_landing_pages() ) { | |
| 73 | - update_option( self::ACTIVATION_KEY, '1' ); | |
| 74 | - return true; | |
| 75 | - } | |
| 76 | - | |
| 77 | - update_option( self::ACTIVATION_KEY, '0' ); | |
| 78 | - return false; | |
| 79 | - } | |
| 80 | - | |
| 81 | - /** | |
| 82 | 57 | * Get Trashed Landing Pages Posts |
| 83 | 58 | * |
| 84 | 59 | * Returns the posts property of a WP_Query run for Landing Pages with post_status of 'trash'. |
| 85 | 60 | * |
| @@ -106,13 +81,23 @@ | ||
| 106 | 81 | |
| 107 | 82 | return $this->trashed_posts; |
| 108 | 83 | } |
| 109 | 84 | |
| 110 | - private function has_landing_pages() { | |
| 111 | - if ( null !== $this->has_pages ) { | |
| 112 | - return $this->has_pages; | |
| 85 | + /** | |
| 86 | + * Get Landing Pages Posts | |
| 87 | + * | |
| 88 | + * Returns the posts property of a WP_Query run for posts with the Landing Pages CPT. | |
| 89 | + * | |
| 90 | + * @since 3.1.0 | |
| 91 | + * | |
| 92 | + * @return array posts | |
| 93 | + */ | |
| 94 | + private function get_landing_page_posts() { | |
| 95 | + if ( $this->posts ) { | |
| 96 | + return $this->posts; | |
| 113 | 97 | } |
| 114 | 98 | |
| 99 | + // `'posts_per_page' => 1` is because this is only used as an indicator to whether there are any landing pages. | |
| 115 | 100 | $posts_query = new \WP_Query( [ |
| 116 | 101 | 'no_found_rows' => true, |
| 117 | 102 | 'post_type' => self::CPT, |
| 118 | 103 | 'post_status' => 'any', |
| @@ -120,11 +105,11 @@ | ||
| 120 | 105 | 'meta_key' => '_elementor_template_type', |
| 121 | 106 | 'meta_value' => self::DOCUMENT_TYPE, |
| 122 | 107 | ] ); |
| 123 | 108 | |
| 124 | - $this->has_pages = $posts_query->post_count > 0; | |
| 109 | + $this->posts = $posts_query->posts; | |
| 125 | 110 | |
| 126 | - return $this->has_pages; | |
| 111 | + return $this->posts; | |
| 127 | 112 | } |
| 128 | 113 | |
| 129 | 114 | /** |
| 130 | 115 | * Is Elementor Landing Page. |
| @@ -133,9 +118,9 @@ | ||
| 133 | 118 | * |
| 134 | 119 | * @since 3.1.0 |
| 135 | 120 | * @access public |
| 136 | 121 | * |
| 137 | - * @param \WP_Post $post Post Object. | |
| 122 | + * @param \WP_Post $post Post Object | |
| 138 | 123 | * |
| 139 | 124 | * @return bool Whether the post was built with Elementor. |
| 140 | 125 | */ |
| 141 | 126 | public function is_elementor_landing_page( $post ) { |
| @@ -141,10 +126,14 @@ | ||
| 141 | 126 | public function is_elementor_landing_page( $post ) { |
| 142 | 127 | return self::CPT === $post->post_type; |
| 143 | 128 | } |
| 144 | 129 | |
| 145 | - public function get_menu_args() { | |
| 146 | - if ( $this->has_landing_pages() ) { | |
| 130 | + private function get_menu_args() { | |
| 131 | + $posts = $this->get_landing_page_posts(); | |
| 132 | + | |
| 133 | + // If there are no Landing Pages, show the "Create Your First Landing Page" page. | |
| 134 | + // If there are, show the pages table. | |
| 135 | + if ( ! empty( $posts ) ) { | |
| 147 | 136 | $menu_slug = self::ADMIN_PAGE_SLUG; |
| 148 | 137 | $function = null; |
| 149 | 138 | } else { |
| 150 | 139 | $menu_slug = self::CPT; |
| @@ -156,13 +145,43 @@ | ||
| 156 | 145 | 'function' => $function, |
| 157 | 146 | ]; |
| 158 | 147 | } |
| 159 | 148 | |
| 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 ) ); | |
| 149 | + private function register_admin_menu( MainMenu $menu ) { | |
| 150 | + $landing_pages_title = esc_html__( 'Landing Pages', 'elementor' ); | |
| 151 | + | |
| 152 | + $menu_args = array_merge( $this->get_menu_args(), [ | |
| 153 | + 'page_title' => $landing_pages_title, | |
| 154 | + 'menu_title' => $landing_pages_title, | |
| 155 | + 'index' => 20, | |
| 156 | + ] ); | |
| 157 | + | |
| 158 | + $menu->add_submenu( $menu_args ); | |
| 162 | 159 | } |
| 163 | 160 | |
| 164 | 161 | /** |
| 162 | + * Add Submenu Page | |
| 163 | + * | |
| 164 | + * Adds the 'Landing Pages' submenu item to the 'Templates' menu item. | |
| 165 | + * | |
| 166 | + * @since 3.1.0 | |
| 167 | + */ | |
| 168 | + private function register_admin_menu_legacy() { | |
| 169 | + $landing_pages_title = esc_html__( 'Landing Pages', 'elementor' ); | |
| 170 | + | |
| 171 | + $menu_args = $this->get_menu_args(); | |
| 172 | + | |
| 173 | + add_submenu_page( | |
| 174 | + Source_Local::ADMIN_MENU_SLUG, | |
| 175 | + $landing_pages_title, | |
| 176 | + $landing_pages_title, | |
| 177 | + 'manage_options', | |
| 178 | + $menu_args['menu_slug'], | |
| 179 | + $menu_args['function'] | |
| 180 | + ); | |
| 181 | + } | |
| 182 | + | |
| 183 | + /** | |
| 165 | 184 | * Get 'Add New' Landing Page URL |
| 166 | 185 | * |
| 167 | 186 | * Retrieves the custom URL for the admin dashboard's 'Add New' button in the Landing Pages admin screen. This URL |
| 168 | 187 | * creates a new Landing Pages and directly opens the Elementor Editor with the Template Library modal open on the |
| @@ -202,9 +221,9 @@ | ||
| 202 | 221 | <div class="e-trashed-items"> |
| 203 | 222 | <?php |
| 204 | 223 | printf( |
| 205 | 224 | /* translators: %1$s Link open tag, %2$s: Link close tag. */ |
| 206 | - esc_html__( 'Or view %1$sTrashed Items%2$s', 'elementor' ), | |
| 225 | + esc_html__( 'Or view %1$sTrashed Items%1$s', 'elementor' ), | |
| 207 | 226 | '<a href="' . esc_url( admin_url( 'edit.php?post_status=trash&post_type=' . self::CPT ) ) . '">', |
| 208 | 227 | '</a>' |
| 209 | 228 | ); |
| 210 | 229 | ?> |
| @@ -245,9 +264,9 @@ | ||
| 245 | 264 | 'urls' => [ |
| 246 | 265 | 'addNewLandingPageUrl' => $this->get_add_new_landing_page_url(), |
| 247 | 266 | ], |
| 248 | 267 | 'landingPages' => [ |
| 249 | - 'landingPagesHasPages' => $this->has_landing_pages(), | |
| 268 | + 'landingPagesHasPages' => [] !== $this->get_landing_page_posts(), | |
| 250 | 269 | 'isLandingPageAdminEdit' => $this->is_landing_page_admin_edit(), |
| 251 | 270 | ], |
| 252 | 271 | ]; |
| 253 | 272 | |
| @@ -311,9 +330,9 @@ | ||
| 311 | 330 | return $post_link; |
| 312 | 331 | } |
| 313 | 332 | |
| 314 | 333 | // Any slug prefixes need to be removed from the post link. |
| 315 | - return trailingslashit( get_home_url() ) . trailingslashit( $post->post_name ); | |
| 334 | + return get_home_url() . '/' . $post->post_name . '/'; | |
| 316 | 335 | } |
| 317 | 336 | |
| 318 | 337 | /** |
| 319 | 338 | * Adjust Landing Page Query |
| @@ -421,18 +440,8 @@ | ||
| 421 | 440 | return false; |
| 422 | 441 | } |
| 423 | 442 | |
| 424 | 443 | public function __construct() { |
| 425 | - if ( ! $this->should_activate_landing_pages() ) { | |
| 426 | - return; | |
| 427 | - } | |
| 428 | - | |
| 429 | - $this->register_experiment(); | |
| 430 | - | |
| 431 | - if ( ! Plugin::$instance->experiments->is_feature_active( 'landing-pages' ) ) { | |
| 432 | - return; | |
| 433 | - } | |
| 434 | - | |
| 435 | 444 | $this->permalink_structure = get_option( 'permalink_structure' ); |
| 436 | 445 | |
| 437 | 446 | $this->register_landing_page_cpt(); |
| 438 | 447 | |
| @@ -461,20 +470,18 @@ | ||
| 461 | 470 | add_action( 'elementor/documents/register', function( Documents_Manager $documents_manager ) { |
| 462 | 471 | $documents_manager->register_document_type( self::DOCUMENT_TYPE, Landing_Page::get_class_full_name() ); |
| 463 | 472 | } ); |
| 464 | 473 | |
| 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 | - } ); | |
| 474 | + if ( Plugin::$instance->experiments->is_feature_active( 'admin_menu_rearrangement' ) ) { | |
| 475 | + add_action( 'elementor/admin/menu_registered/elementor', function( MainMenu $menu ) { | |
| 476 | + $this->register_admin_menu( $menu ); | |
| 477 | + } ); | |
| 478 | + } else { | |
| 479 | + add_action( 'admin_menu', function() { | |
| 480 | + $this->register_admin_menu_legacy(); | |
| 481 | + }, 30 ); | |
| 482 | + } | |
| 468 | 483 | |
| 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 | 484 | // Add the custom 'Add New' link for Landing Pages into Elementor's admin config. |
| 478 | 485 | add_action( 'elementor/admin/localize_settings', function( array $settings ) { |
| 479 | 486 | return $this->admin_localize_settings( $settings ); |
| 480 | 487 | } ); |
| @@ -482,13 +489,8 @@ | ||
| 482 | 489 | add_filter( 'elementor/template_library/sources/local/register_taxonomy_cpts', function( array $cpts ) { |
| 483 | 490 | $cpts[] = self::CPT; |
| 484 | 491 | |
| 485 | 492 | 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 | 493 | } ); |
| 492 | 494 | |
| 493 | 495 | // In the Landing Pages Admin Table page - Overwrite Template type column header title. |
| 494 | 496 | add_action( 'manage_' . Landing_Pages_Module::CPT . '_posts_columns', function( $posts_columns ) { |