← All changes
|
modules/landing-pages/documents/landing-page.php
+31
-51
4.3.0-beta3
→
3.1.0-dev2
View file →
| @@ -1,42 +1,32 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Modules\LandingPages\Documents; |
| 3 | 3 | |
| 4 | -use Elementor\Core\DocumentTypes\PageBase; | |
| 5 | -use Elementor\Modules\LandingPages\Module as Landing_Pages_Module; | |
| 6 | -use Elementor\Modules\Library\Traits\Library; | |
| 7 | -use Elementor\Modules\PageTemplates\Module as Page_Templates_Module; | |
| 8 | -use Elementor\Plugin; | |
| 4 | +use Elementor\Core\DocumentTypes\Page; | |
| 5 | +use Elementor\Modules\LandingPages\Module; | |
| 6 | +use Elementor\Modules\PageTemplates\Module as PageTemplatesModule; | |
| 9 | 7 | use Elementor\TemplateLibrary\Source_Local; |
| 10 | 8 | |
| 11 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | - exit; // Exit if accessed directly. | |
| 10 | + exit; // Exit if accessed directly | |
| 13 | 11 | } |
| 14 | 12 | |
| 15 | -class Landing_Page extends PageBase { | |
| 13 | +class Landing_Page extends Page { | |
| 16 | 14 | |
| 17 | - // Library Document Trait | |
| 18 | - use Library; | |
| 19 | - | |
| 20 | 15 | public static function get_properties() { |
| 21 | 16 | $properties = parent::get_properties(); |
| 22 | 17 | |
| 23 | 18 | $properties['support_kit'] = true; |
| 24 | 19 | $properties['show_in_library'] = true; |
| 25 | - $properties['cpt'] = [ Landing_Pages_Module::CPT ]; | |
| 26 | 20 | |
| 27 | 21 | return $properties; |
| 28 | 22 | } |
| 29 | 23 | |
| 30 | - public static function get_type() { | |
| 31 | - return Landing_Pages_Module::DOCUMENT_TYPE; | |
| 32 | - } | |
| 33 | - | |
| 34 | 24 | /** |
| 35 | 25 | * @access public |
| 36 | 26 | */ |
| 37 | 27 | public function get_name() { |
| 38 | - return Landing_Pages_Module::DOCUMENT_TYPE; | |
| 28 | + return Module::DOCUMENT_TYPE; | |
| 39 | 29 | } |
| 40 | 30 | |
| 41 | 31 | /** |
| 42 | 32 | * @access public |
| @@ -42,57 +32,47 @@ | ||
| 42 | 32 | * @access public |
| 43 | 33 | * @static |
| 44 | 34 | */ |
| 45 | 35 | public static function get_title() { |
| 46 | - return esc_html__( 'Landing Page', 'elementor' ); | |
| 36 | + return __( 'Landing Page', 'elementor' ); | |
| 47 | 37 | } |
| 48 | 38 | |
| 49 | - /** | |
| 50 | - * @access public | |
| 51 | - * @static | |
| 52 | - */ | |
| 53 | - public static function get_plural_title() { | |
| 54 | - return esc_html__( 'Landing Pages', 'elementor' ); | |
| 55 | - } | |
| 39 | + public function save( $data ) { | |
| 40 | + // Load a new Landing Page with Canvas as the default page template. | |
| 41 | + if ( empty( $data['settings']['template'] ) ) { | |
| 42 | + $data['settings']['template'] = PageTemplatesModule::TEMPLATE_CANVAS; | |
| 43 | + } | |
| 56 | 44 | |
| 57 | - public static function get_create_url() { | |
| 58 | - return parent::get_create_url() . '#library'; | |
| 45 | + parent::save( $data ); | |
| 59 | 46 | } |
| 60 | 47 | |
| 61 | 48 | /** |
| 62 | - * Save Document. | |
| 49 | + * Save Template type. | |
| 63 | 50 | * |
| 64 | - * Save an Elementor document. | |
| 51 | + * Set new/updated document type (Page/landing Page). This method is called whenever a page is saved. | |
| 65 | 52 | * |
| 66 | 53 | * @since 3.1.0 |
| 67 | 54 | * @access public |
| 68 | - * | |
| 69 | - * @param $data | |
| 70 | - * | |
| 71 | - * @return bool | |
| 72 | 55 | */ |
| 73 | - public function save( $data ) { | |
| 74 | - // This is for the first time a Landing Page is created. It is done in order to load a new Landing Page with | |
| 75 | - // 'Canvas' as the default page template. | |
| 76 | - if ( empty( $data['settings']['template'] ) ) { | |
| 77 | - $data['settings']['template'] = Page_Templates_Module::TEMPLATE_CANVAS; | |
| 78 | - } | |
| 56 | + public function save_template_type() { | |
| 57 | + $page_settings = $this->settings_to_be_saved; | |
| 79 | 58 | |
| 80 | - return parent::save( $data ); | |
| 81 | - } | |
| 59 | + if ( ! empty( $page_settings ) && isset( $page_settings['page_type'] ) ) { | |
| 60 | + $post_id = $this->get_id(); | |
| 61 | + $page_type_wp_page = parent::get_name(); | |
| 82 | 62 | |
| 83 | - /** | |
| 84 | - * Admin Columns Content | |
| 85 | - * | |
| 86 | - * @since 3.1.0 | |
| 87 | - * | |
| 88 | - * @param $column_name | |
| 89 | - * @access public | |
| 90 | - */ | |
| 91 | - public function admin_columns_content( $column_name ) { | |
| 92 | - if ( 'elementor_library_type' === $column_name ) { | |
| 93 | - $this->print_admin_column_type(); | |
| 63 | + //If 'Page' was selected by the user, since the document is currently a Landing Page - change it to a regular page. | |
| 64 | + if ( $page_type_wp_page === $page_settings['page_type'] ) { | |
| 65 | + // Remove the association to the library taxonomy as a 'landing-page'. | |
| 66 | + wp_remove_object_terms( $post_id, Module::DOCUMENT_TYPE, Source_Local::TAXONOMY_TYPE_SLUG ); | |
| 67 | + | |
| 68 | + // Change the Template Type to 'Page'. | |
| 69 | + return $this->update_main_meta( self::TYPE_META_KEY, $page_type_wp_page ); | |
| 70 | + } | |
| 94 | 71 | } |
| 72 | + | |
| 73 | + // If the selected page type is 'Landing Page', make sure it is saved as a Landing Page. | |
| 74 | + return $this->update_main_meta( self::TYPE_META_KEY, $this->get_name() ); | |
| 95 | 75 | } |
| 96 | 76 | |
| 97 | 77 | protected function get_remote_library_config() { |
| 98 | 78 | $config = [ |