| @@ -4,13 +4,12 @@ | ||
| 4 | 4 | use Elementor\Core\Base\Module as BaseModule; |
| 5 | 5 | use Elementor\Core\Documents_Manager; |
| 6 | 6 | use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 7 | 7 | use Elementor\Modules\LandingPages\Documents\Landing_Page; |
| 8 | -use Elementor\Modules\LandingPages\AdminMenuItems\Editor_One_Landing_Pages_Menu; | |
| 9 | 8 | use Elementor\Modules\LandingPages\Module as Landing_Pages_Module; |
| 10 | -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; | |
| 11 | 9 | use Elementor\Plugin; |
| 12 | 10 | use Elementor\TemplateLibrary\Source_Local; |
| 11 | +use Elementor\Utils; | |
| 13 | 12 | |
| 14 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | 14 | exit; // Exit if accessed directly. |
| 16 | 15 | } |
| @@ -19,11 +18,10 @@ | ||
| 19 | 18 | |
| 20 | 19 | const DOCUMENT_TYPE = 'landing-page'; |
| 21 | 20 | const CPT = 'e-landing-page'; |
| 22 | 21 | const ADMIN_PAGE_SLUG = 'edit.php?post_type=' . self::CPT; |
| 23 | - const ACTIVATION_KEY = 'elementor_landing_pages_activation'; | |
| 24 | 22 | |
| 25 | - private $has_pages = null; | |
| 23 | + private $posts; | |
| 26 | 24 | private $trashed_posts; |
| 27 | 25 | private $new_lp_url; |
| 28 | 26 | private $permalink_structure; |
| 29 | 27 | |
| @@ -31,55 +29,30 @@ | ||
| 31 | 29 | return 'landing-pages'; |
| 32 | 30 | } |
| 33 | 31 | |
| 34 | 32 | /** |
| 35 | - * Register Experimental Feature | |
| 33 | + * Get Experimental Data | |
| 36 | 34 | * |
| 37 | 35 | * Implementation of this method makes the module an experiment. |
| 38 | 36 | * |
| 39 | - * @since 3.28.0 | |
| 37 | + * @since 3.1.0 | |
| 38 | + * | |
| 39 | + * @return array | |
| 40 | 40 | */ |
| 41 | - private function register_experiment() { | |
| 42 | - Plugin::$instance->experiments->add_feature( [ | |
| 41 | + public static function get_experimental_data() { | |
| 42 | + return [ | |
| 43 | 43 | 'name' => 'landing-pages', |
| 44 | - 'title' => esc_html__( 'Landing Pages', 'elementor' ), | |
| 45 | - 'description' => esc_html__( 'Adds a new Elementor content type that allows creating beautiful landing pages instantly in a streamlined workflow.', 'elementor' ), | |
| 44 | + 'title' => __( 'Landing Pages', 'elementor' ), | |
| 45 | + 'description' => __( 'Adds a new Elementor content type that allows creating beautiful landing pages instantly in a streamlined workflow.', 'elementor' ), | |
| 46 | 46 | 'release_status' => Experiments_Manager::RELEASE_STATUS_BETA, |
| 47 | - 'default' => Experiments_Manager::STATE_ACTIVE, | |
| 48 | 47 | 'new_site' => [ |
| 49 | - 'default_inactive' => true, | |
| 50 | - 'minimum_installation_version' => '3.22.0', | |
| 48 | + 'default_active' => true, | |
| 49 | + 'minimum_installation_version' => '3.1.0-beta', | |
| 51 | 50 | ], |
| 52 | - 'deprecated' => true, | |
| 53 | - ] ); | |
| 51 | + ]; | |
| 54 | 52 | } |
| 55 | 53 | |
| 56 | 54 | /** |
| 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 | 55 | * Get Trashed Landing Pages Posts |
| 83 | 56 | * |
| 84 | 57 | * Returns the posts property of a WP_Query run for Landing Pages with post_status of 'trash'. |
| 85 | 58 | * |
| @@ -93,9 +66,8 @@ | ||
| 93 | 66 | } |
| 94 | 67 | |
| 95 | 68 | // `'posts_per_page' => 1` is because this is only used as an indicator to whether there are any trashed landing pages. |
| 96 | 69 | $trashed_posts_query = new \WP_Query( [ |
| 97 | - 'no_found_rows' => true, | |
| 98 | 70 | 'post_type' => self::CPT, |
| 99 | 71 | 'post_status' => 'trash', |
| 100 | 72 | 'posts_per_page' => 1, |
| 101 | 73 | 'meta_key' => '_elementor_template_type', |
| @@ -106,15 +78,24 @@ | ||
| 106 | 78 | |
| 107 | 79 | return $this->trashed_posts; |
| 108 | 80 | } |
| 109 | 81 | |
| 110 | - private function has_landing_pages() { | |
| 111 | - if ( null !== $this->has_pages ) { | |
| 112 | - return $this->has_pages; | |
| 82 | + /** | |
| 83 | + * Get Landing Pages Posts | |
| 84 | + * | |
| 85 | + * Returns the posts property of a WP_Query run for posts with the Landing Pages CPT. | |
| 86 | + * | |
| 87 | + * @since 3.1.0 | |
| 88 | + * | |
| 89 | + * @return array posts | |
| 90 | + */ | |
| 91 | + private function get_landing_page_posts() { | |
| 92 | + if ( $this->posts ) { | |
| 93 | + return $this->posts; | |
| 113 | 94 | } |
| 114 | 95 | |
| 96 | + // `'posts_per_page' => 1` is because this is only used as an indicator to whether there are any landing pages. | |
| 115 | 97 | $posts_query = new \WP_Query( [ |
| 116 | - 'no_found_rows' => true, | |
| 117 | 98 | 'post_type' => self::CPT, |
| 118 | 99 | 'post_status' => 'any', |
| 119 | 100 | 'posts_per_page' => 1, |
| 120 | 101 | 'meta_key' => '_elementor_template_type', |
| @@ -120,11 +101,11 @@ | ||
| 120 | 101 | 'meta_key' => '_elementor_template_type', |
| 121 | 102 | 'meta_value' => self::DOCUMENT_TYPE, |
| 122 | 103 | ] ); |
| 123 | 104 | |
| 124 | - $this->has_pages = $posts_query->post_count > 0; | |
| 105 | + $this->posts = $posts_query->posts; | |
| 125 | 106 | |
| 126 | - return $this->has_pages; | |
| 107 | + return $this->posts; | |
| 127 | 108 | } |
| 128 | 109 | |
| 129 | 110 | /** |
| 130 | 111 | * Is Elementor Landing Page. |
| @@ -133,9 +114,9 @@ | ||
| 133 | 114 | * |
| 134 | 115 | * @since 3.1.0 |
| 135 | 116 | * @access public |
| 136 | 117 | * |
| 137 | - * @param \WP_Post $post Post Object. | |
| 118 | + * @param \WP_Post $post Post Object | |
| 138 | 119 | * |
| 139 | 120 | * @return bool Whether the post was built with Elementor. |
| 140 | 121 | */ |
| 141 | 122 | public function is_elementor_landing_page( $post ) { |
| @@ -141,25 +122,38 @@ | ||
| 141 | 122 | public function is_elementor_landing_page( $post ) { |
| 142 | 123 | return self::CPT === $post->post_type; |
| 143 | 124 | } |
| 144 | 125 | |
| 145 | - public function get_menu_args() { | |
| 146 | - if ( $this->has_landing_pages() ) { | |
| 147 | - $menu_slug = self::ADMIN_PAGE_SLUG; | |
| 148 | - $function = null; | |
| 126 | + /** | |
| 127 | + * Add Submenu Page | |
| 128 | + * | |
| 129 | + * Adds the 'Landing Pages' submenu item to the 'Templates' menu item. | |
| 130 | + * | |
| 131 | + * @since 3.1.0 | |
| 132 | + */ | |
| 133 | + private function add_submenu_page() { | |
| 134 | + $posts = $this->get_landing_page_posts(); | |
| 135 | + | |
| 136 | + // If there are no Landing Pages, show the "Create Your First Landing Page" page. | |
| 137 | + // If there are, show the pages table. | |
| 138 | + if ( ! empty( $posts ) ) { | |
| 139 | + $landing_page_menu_slug = self::ADMIN_PAGE_SLUG; | |
| 140 | + $landing_page_menu_callback = null; | |
| 149 | 141 | } else { |
| 150 | - $menu_slug = self::CPT; | |
| 151 | - $function = [ $this, 'print_empty_landing_pages_page' ]; | |
| 142 | + $landing_page_menu_slug = self::CPT; | |
| 143 | + $landing_page_menu_callback = [ $this, 'print_empty_landing_pages_page' ]; | |
| 152 | 144 | } |
| 153 | 145 | |
| 154 | - return [ | |
| 155 | - 'menu_slug' => $menu_slug, | |
| 156 | - 'function' => $function, | |
| 157 | - ]; | |
| 158 | - } | |
| 146 | + $landing_pages_title = __( 'Landing Pages', 'elementor' ); | |
| 159 | 147 | |
| 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 ) ); | |
| 148 | + add_submenu_page( | |
| 149 | + Source_Local::ADMIN_MENU_SLUG, | |
| 150 | + $landing_pages_title, | |
| 151 | + $landing_pages_title, | |
| 152 | + 'manage_options', | |
| 153 | + $landing_page_menu_slug, | |
| 154 | + $landing_page_menu_callback | |
| 155 | + ); | |
| 162 | 156 | } |
| 163 | 157 | |
| 164 | 158 | /** |
| 165 | 159 | * Get 'Add New' Landing Page URL |
| @@ -173,9 +167,9 @@ | ||
| 173 | 167 | * @return string |
| 174 | 168 | */ |
| 175 | 169 | private function get_add_new_landing_page_url() { |
| 176 | 170 | if ( ! $this->new_lp_url ) { |
| 177 | - $this->new_lp_url = Plugin::$instance->documents->get_create_new_post_url( self::CPT, self::DOCUMENT_TYPE ) . '#library'; | |
| 171 | + $this->new_lp_url = Utils::get_create_new_post_url( self::CPT, self::DOCUMENT_TYPE ) . '#library'; | |
| 178 | 172 | } |
| 179 | 173 | return $this->new_lp_url; |
| 180 | 174 | } |
| 181 | 175 | |
| @@ -195,20 +189,13 @@ | ||
| 195 | 189 | ?> |
| 196 | 190 | <div class="e-landing-pages-empty"> |
| 197 | 191 | <?php |
| 198 | 192 | /** @var Source_Local $source_local */ |
| 199 | - $source_local->print_blank_state_template( esc_html__( 'Landing Page', 'elementor' ), $this->get_add_new_landing_page_url(), esc_html__( 'Build Effective Landing Pages for your business\' marketing campaigns.', 'elementor' ) ); | |
| 193 | + $source_local->print_blank_state_template( __( 'Landing Page', 'elementor' ), $this->get_add_new_landing_page_url(), __( 'Build Effective Landing Pages for your business\' marketing campaigns.', 'elementor' ) ); | |
| 200 | 194 | |
| 201 | 195 | if ( ! empty( $trashed_posts ) ) : ?> |
| 202 | 196 | <div class="e-trashed-items"> |
| 203 | - <?php | |
| 204 | - printf( | |
| 205 | - /* translators: %1$s Link open tag, %2$s: Link close tag. */ | |
| 206 | - esc_html__( 'Or view %1$sTrashed Items%2$s', 'elementor' ), | |
| 207 | - '<a href="' . esc_url( admin_url( 'edit.php?post_status=trash&post_type=' . self::CPT ) ) . '">', | |
| 208 | - '</a>' | |
| 209 | - ); | |
| 210 | - ?> | |
| 197 | + <?php echo sprintf( __( 'Or view <a href="%s">Trashed Items</a>', 'elementor' ), admin_url( 'edit.php?post_status=trash&post_type=' . self::CPT ) ); ?> | |
| 211 | 198 | </div> |
| 212 | 199 | <?php endif; ?> |
| 213 | 200 | </div> |
| 214 | 201 | <?php |
| @@ -245,9 +232,9 @@ | ||
| 245 | 232 | 'urls' => [ |
| 246 | 233 | 'addNewLandingPageUrl' => $this->get_add_new_landing_page_url(), |
| 247 | 234 | ], |
| 248 | 235 | 'landingPages' => [ |
| 249 | - 'landingPagesHasPages' => $this->has_landing_pages(), | |
| 236 | + 'landingPagesHasPages' => [] !== $this->get_landing_page_posts(), | |
| 250 | 237 | 'isLandingPageAdminEdit' => $this->is_landing_page_admin_edit(), |
| 251 | 238 | ], |
| 252 | 239 | ]; |
| 253 | 240 | |
| @@ -260,21 +247,21 @@ | ||
| 260 | 247 | * @since 3.1.0 |
| 261 | 248 | */ |
| 262 | 249 | private function register_landing_page_cpt() { |
| 263 | 250 | $labels = [ |
| 264 | - 'name' => esc_html__( 'Landing Pages', 'elementor' ), | |
| 265 | - 'singular_name' => esc_html__( 'Landing Page', 'elementor' ), | |
| 266 | - 'add_new' => esc_html__( 'Add New', 'elementor' ), | |
| 267 | - 'add_new_item' => esc_html__( 'Add New Landing Page', 'elementor' ), | |
| 268 | - 'edit_item' => esc_html__( 'Edit Landing Page', 'elementor' ), | |
| 269 | - 'new_item' => esc_html__( 'New Landing Page', 'elementor' ), | |
| 270 | - 'all_items' => esc_html__( 'All Landing Pages', 'elementor' ), | |
| 271 | - 'view_item' => esc_html__( 'View Landing Page', 'elementor' ), | |
| 272 | - 'search_items' => esc_html__( 'Search Landing Pages', 'elementor' ), | |
| 273 | - 'not_found' => esc_html__( 'No landing pages found', 'elementor' ), | |
| 274 | - 'not_found_in_trash' => esc_html__( 'No landing pages found in trash', 'elementor' ), | |
| 251 | + 'name' => __( 'Landing Pages', 'elementor' ), | |
| 252 | + 'singular_name' => __( 'Landing Page', 'elementor' ), | |
| 253 | + 'add_new' => __( 'Add New', 'elementor' ), | |
| 254 | + 'add_new_item' => __( 'Add New Landing Page', 'elementor' ), | |
| 255 | + 'edit_item' => __( 'Edit Landing Page', 'elementor' ), | |
| 256 | + 'new_item' => __( 'New Landing Page', 'elementor' ), | |
| 257 | + 'all_items' => __( 'All Landing Pages', 'elementor' ), | |
| 258 | + 'view_item' => __( 'View Landing Page', 'elementor' ), | |
| 259 | + 'search_items' => __( 'Search Landing Pages', 'elementor' ), | |
| 260 | + 'not_found' => __( 'No landing pages found', 'elementor' ), | |
| 261 | + 'not_found_in_trash' => __( 'No landing pages found in trash', 'elementor' ), | |
| 275 | 262 | 'parent_item_colon' => '', |
| 276 | - 'menu_name' => esc_html__( 'Landing Pages', 'elementor' ), | |
| 263 | + 'menu_name' => __( 'Landing Pages', 'elementor' ), | |
| 277 | 264 | ]; |
| 278 | 265 | |
| 279 | 266 | $args = [ |
| 280 | 267 | 'labels' => $labels, |
| @@ -311,9 +298,9 @@ | ||
| 311 | 298 | return $post_link; |
| 312 | 299 | } |
| 313 | 300 | |
| 314 | 301 | // Any slug prefixes need to be removed from the post link. |
| 315 | - return trailingslashit( get_home_url() ) . trailingslashit( $post->post_name ); | |
| 302 | + return get_home_url() . '/' . $post->post_name . '/'; | |
| 316 | 303 | } |
| 317 | 304 | |
| 318 | 305 | /** |
| 319 | 306 | * Adjust Landing Page Query |
| @@ -354,13 +341,9 @@ | ||
| 354 | 341 | } elseif ( ! empty( $query->query['pagename'] ) && false === strpos( $query->query['pagename'], '/' ) ) { |
| 355 | 342 | $query->set( 'post_type', $query_post_types ); |
| 356 | 343 | |
| 357 | 344 | // We also need to set the name query var since redirect_guess_404_permalink() relies on it. |
| 358 | - add_filter( 'pre_redirect_guess_404_permalink', function( $value ) use ( $query ) { | |
| 359 | - set_query_var( 'name', $query->query['pagename'] ); | |
| 360 | - | |
| 361 | - return $value; | |
| 362 | - } ); | |
| 345 | + $query->set( 'name', $query->query['pagename'] ); | |
| 363 | 346 | } |
| 364 | 347 | } |
| 365 | 348 | |
| 366 | 349 | /** |
| @@ -407,9 +390,8 @@ | ||
| 407 | 390 | } |
| 408 | 391 | |
| 409 | 392 | // Search for a Landing Page with the same name passed as the 'category name'. |
| 410 | 393 | $possible_new_query = new \WP_Query( [ |
| 411 | - 'no_found_rows' => true, | |
| 412 | 394 | 'post_type' => self::CPT, |
| 413 | 395 | 'name' => $query->query['category_name'], |
| 414 | 396 | ] ); |
| 415 | 397 | |
| @@ -421,18 +403,8 @@ | ||
| 421 | 403 | return false; |
| 422 | 404 | } |
| 423 | 405 | |
| 424 | 406 | 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 | 407 | $this->permalink_structure = get_option( 'permalink_structure' ); |
| 436 | 408 | |
| 437 | 409 | $this->register_landing_page_cpt(); |
| 438 | 410 | |
| @@ -461,20 +433,12 @@ | ||
| 461 | 433 | add_action( 'elementor/documents/register', function( Documents_Manager $documents_manager ) { |
| 462 | 434 | $documents_manager->register_document_type( self::DOCUMENT_TYPE, Landing_Page::get_class_full_name() ); |
| 463 | 435 | } ); |
| 464 | 436 | |
| 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 | - } ); | |
| 437 | + add_action( 'admin_menu', function() { | |
| 438 | + $this->add_submenu_page(); | |
| 439 | + }, 30 ); | |
| 468 | 440 | |
| 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 | 441 | // Add the custom 'Add New' link for Landing Pages into Elementor's admin config. |
| 478 | 442 | add_action( 'elementor/admin/localize_settings', function( array $settings ) { |
| 479 | 443 | return $this->admin_localize_settings( $settings ); |
| 480 | 444 | } ); |
| @@ -482,13 +446,8 @@ | ||
| 482 | 446 | add_filter( 'elementor/template_library/sources/local/register_taxonomy_cpts', function( array $cpts ) { |
| 483 | 447 | $cpts[] = self::CPT; |
| 484 | 448 | |
| 485 | 449 | 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 | 450 | } ); |
| 492 | 451 | |
| 493 | 452 | // In the Landing Pages Admin Table page - Overwrite Template type column header title. |
| 494 | 453 | add_action( 'manage_' . Landing_Pages_Module::CPT . '_posts_columns', function( $posts_columns ) { |