From 7c08d2421f13afbb05eaf6588855d636be0a3fa9 Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Tue, 29 Oct 2024 19:39:11 +0100 Subject: [PATCH 01/20] add logic for advanced tab --- .../js/hello-plus-template-parts-editor.js | 15 ++++ .../hello-plus-template-parts-preview.scss | 10 +++ .../template-parts/components/document.php | 9 ++- .../documents/document-base.php | 62 ++++++++++++++-- .../{footer.php => footer-document.php} | 2 +- .../{header.php => header-document.php} | 3 +- modules/template-parts/templates/footer.php | 4 +- modules/template-parts/templates/header.php | 4 +- .../widgets/abstract-ehp-widget.php | 70 +++++++++++++++++++ modules/template-parts/widgets/footer.php | 9 ++- modules/template-parts/widgets/header.php | 13 ++-- 11 files changed, 180 insertions(+), 21 deletions(-) rename modules/template-parts/documents/{footer.php => footer-document.php} (95%) rename modules/template-parts/documents/{header.php => header-document.php} (95%) create mode 100644 modules/template-parts/widgets/abstract-ehp-widget.php diff --git a/modules/template-parts/assets/js/hello-plus-template-parts-editor.js b/modules/template-parts/assets/js/hello-plus-template-parts-editor.js index a32e3654..c3521722 100644 --- a/modules/template-parts/assets/js/hello-plus-template-parts-editor.js +++ b/modules/template-parts/assets/js/hello-plus-template-parts-editor.js @@ -1,12 +1,27 @@ export default class helloPlusLogo { constructor() { elementor.channels.editor.on( 'helloPlusLogo:change', this.openSiteIdentity ); + elementor.channels.editor.on( 'section:activated', this.hideAdvancedTab.bind( this ) ); } async openSiteIdentity() { await $e.run( 'panel/global/open' ); $e.route( 'panel/global/settings-site-identity' ); } + + hideAdvancedTab( sectionName, editor ) { + const widgetType = editor?.model?.get( 'widgetType' ) || ''; + + if ( 'header' === ! widgetType || 'footer' === ! widgetType ) { + return; + } + + const advancedTab = editor?.el.querySelector( '.elementor-tab-control-advanced' ) || false; + + if ( advancedTab ) { + advancedTab.style.display = 'none'; + } + } } const HelloPlusLogoClass = new helloPlusLogo(); diff --git a/modules/template-parts/assets/scss/hello-plus-template-parts-preview.scss b/modules/template-parts/assets/scss/hello-plus-template-parts-preview.scss index 3ddf87c5..b14f9bd1 100644 --- a/modules/template-parts/assets/scss/hello-plus-template-parts-preview.scss +++ b/modules/template-parts/assets/scss/hello-plus-template-parts-preview.scss @@ -8,3 +8,13 @@ display: block; } } +.elementor-tab-control-advanced-tab-ehp-footer, +.elementor-tab-control-advanced-tab-ehp-header { + span:before { + content: '\e916'; + } + + & + .elementor-tab-control-advanced { + display: none; + } +} diff --git a/modules/template-parts/components/document.php b/modules/template-parts/components/document.php index 069d60a3..5578e9c2 100644 --- a/modules/template-parts/components/document.php +++ b/modules/template-parts/components/document.php @@ -15,8 +15,8 @@ class Document { private function get_documents_list(): array { return [ - 'Header', - 'Footer', + 'Header_Document', + 'Footer_Document', ]; } /** @@ -30,9 +30,14 @@ public function register( Documents_Manager $documents_manager ) { $documents = $this->get_documents_list(); foreach ( $documents as $document ) { + /** @var \HelloPlus\Modules\TemplateParts\Documents\Document_Base $doc_class */ $doc_class = '\HelloPlus\Modules\TemplateParts\Documents\\' . $document; + + $doc_class::register(); + // add the doc type to Elementor documents: $documents_manager->register_document_type( $doc_class::get_type(), $doc_class ); + $doc_class::register_hooks(); } } diff --git a/modules/template-parts/documents/document-base.php b/modules/template-parts/documents/document-base.php index d3edbf94..7f8e30fe 100644 --- a/modules/template-parts/documents/document-base.php +++ b/modules/template-parts/documents/document-base.php @@ -6,10 +6,11 @@ exit; // Exit if accessed directly. } -use Elementor\{ + +use Elementor\{Controls_Manager, TemplateLibrary\Source_Local, - Modules\Library\Documents\Library_Document -}; + Modules\Library\Documents\Library_Document, + Utils as ElementorUtils}; use HelloPlus\Includes\Utils as Theme_Utils; use WP_Query; @@ -45,6 +46,29 @@ public function print_content() { } } + public static function register( ) { + add_filter( 'elementor/widget/common/register_css_attributes_control', function ( $common_controls ) { + if ( static::is_creating_document() || static::is_editing_existing_document() ) { + return false; + } + + return $common_controls; + } ); + + if ( static::is_creating_document() || static::is_editing_existing_document() ) { + Controls_Manager::add_tab( + Header_Document::get_advanced_tab_id(), + esc_html__( 'Advanced', 'elementor' ) + ); + + Controls_Manager::add_tab( + Footer_Document::get_advanced_tab_id(), + esc_html__( 'Advanced', 'elementor' ) + ); + + } + } + public function get_css_wrapper_selector(): string { return '.ehp-' . $this->get_main_id(); } @@ -78,6 +102,31 @@ protected static function get_templates_path(): string { return HELLO_PLUS_PATH . '/modules/template-parts/templates/'; } + public static function get_advanced_tab_id() { + return 'advanced-tab-' . static::get_type(); + } + + public static function is_editing_existing_document() { + $action = ElementorUtils::get_super_global_value( $_GET, 'action' ); + $post_id = ElementorUtils::get_super_global_value( $_GET, 'post' ); + error_log( 'is_editing_existing_document: ' . $action . ' ' . $post_id ); + return 'elementor' === $action && static::is_current_doc_meta_key( $post_id ); + } + + public static function is_creating_document() { + $action = ElementorUtils::get_super_global_value( $_POST, 'action' ); //phpcs:ignore WordPress.Security.NonceVerification.Missing + $post_id = ElementorUtils::get_super_global_value( $_POST, 'editor_post_id' ); //phpcs:ignore WordPress.Security.NonceVerification.Missing + + return 'elementor_ajax' === $action && static::is_current_doc_meta_key( $post_id ); + } + + public static function is_current_doc_meta_key( $post_id ) { + error_log( + 'is_current_doc_meta_key: ' . get_post_meta( $post_id, \Elementor\Core\Base\Document::TYPE_META_KEY, true ) . ' ' . static::get_type() + ); + return static::get_type() === get_post_meta( $post_id, \Elementor\Core\Base\Document::TYPE_META_KEY, true ); + } + /** * Retrieve the template-document post. * There should be only one, so return null if not found, or found too many. @@ -88,21 +137,22 @@ public static function get_document_post(): ?int { static $posts = null; if ( is_null( $posts ) ) { - $args = array( + $args = array( 'post_type' => 'elementor_library', 'fields' => 'ids', 'lazy_load_term_meta' => true, 'tax_query' => [ [ 'taxonomy' => self::TAXONOMY_TYPE_SLUG, - 'field' => 'slug', - 'terms' => static::get_type(), + 'field' => 'slug', + 'terms' => static::get_type(), ], ], ); $query = new WP_Query( $args ); $posts = $query->posts; } + return ( 1 !== count( $posts ) ) ? null : $posts[0]; } diff --git a/modules/template-parts/documents/footer.php b/modules/template-parts/documents/footer-document.php similarity index 95% rename from modules/template-parts/documents/footer.php rename to modules/template-parts/documents/footer-document.php index abaf8bc9..c69e55fd 100644 --- a/modules/template-parts/documents/footer.php +++ b/modules/template-parts/documents/footer-document.php @@ -9,7 +9,7 @@ /** * class Footer **/ -class Footer extends Document_Base { +class Footer_Document extends Document_Base { const LOCATION = 'footer'; public static function get_template_hook(): string { diff --git a/modules/template-parts/documents/header.php b/modules/template-parts/documents/header-document.php similarity index 95% rename from modules/template-parts/documents/header.php rename to modules/template-parts/documents/header-document.php index b882f01b..1b6c5490 100644 --- a/modules/template-parts/documents/header.php +++ b/modules/template-parts/documents/header-document.php @@ -9,7 +9,8 @@ /** * class Header **/ -class Header extends Document_Base { +class Header_Document extends Document_Base { + public static function get_template_hook(): string { return 'get_header'; } diff --git a/modules/template-parts/templates/footer.php b/modules/template-parts/templates/footer.php index b239c609..6574ae3a 100644 --- a/modules/template-parts/templates/footer.php +++ b/modules/template-parts/templates/footer.php @@ -1,11 +1,11 @@ print_content(); wp_footer(); ?> diff --git a/modules/template-parts/templates/header.php b/modules/template-parts/templates/header.php index 0d9b6996..ef09ccf2 100644 --- a/modules/template-parts/templates/header.php +++ b/modules/template-parts/templates/header.php @@ -7,10 +7,10 @@ use HelloPlus\Includes\Utils as Theme_Utils; use Elementor\Utils as Elementor_Utils; -use HelloPlus\Modules\TemplateParts\Documents\Header; +use HelloPlus\Modules\TemplateParts\Documents\Header_Document; // Header template is validated earlier, so if we got this far, there is only one template-document post: -$header_doc_post = Header::get_document_post(); +$header_doc_post = Header_Document::get_document_post(); $header = Theme_Utils::elementor()->documents->get( $header_doc_post ); ?> diff --git a/modules/template-parts/widgets/abstract-ehp-widget.php b/modules/template-parts/widgets/abstract-ehp-widget.php new file mode 100644 index 00000000..fd76932f --- /dev/null +++ b/modules/template-parts/widgets/abstract-ehp-widget.php @@ -0,0 +1,70 @@ +get_advanced_tab_id(); + + Controls_Manager::add_tab( + $advanced_tab_id, + esc_html__( 'Advanced', 'elementor' ) + ); + + $this->start_controls_section( + 'advanced_custom_controls_section', + [ + 'label' => esc_html__( 'CSS', 'elementor' ), + 'tab' => $advanced_tab_id, + ] + ); + + $this->add_control( + 'advanced_custom_css_id', + [ + 'label' => esc_html__( 'CSS ID', 'elementor' ), + 'type' => Controls_Manager::TEXT, + 'default' => '', + 'ai' => [ + 'active' => false, + ], + 'dynamic' => [ + 'active' => true, + ], + 'title' => esc_html__( 'Add your custom id WITHOUT the Pound key. e.g: my-id', 'elementor' ), + 'style_transfer' => false, + ] + ); + + $this->add_control( + 'advanced_custom_css_classes', + [ + 'label' => esc_html__( 'CSS Classes', 'elementor' ), + 'type' => Controls_Manager::TEXT, + 'default' => '', + 'ai' => [ + 'active' => false, + ], + 'dynamic' => [ + 'active' => true, + ], + 'title' => esc_html__( 'Add your custom class WITHOUT the dot. e.g: my-class', 'elementor' ), + ] + ); + + $this->end_controls_section(); + + Plugin::$instance->controls_manager->add_custom_css_controls( $this, $advanced_tab_id ); + + Plugin::$instance->controls_manager->add_custom_attributes_controls( $this, $advanced_tab_id ); + } +} diff --git a/modules/template-parts/widgets/footer.php b/modules/template-parts/widgets/footer.php index fbce165f..1d66207d 100644 --- a/modules/template-parts/widgets/footer.php +++ b/modules/template-parts/widgets/footer.php @@ -16,6 +16,7 @@ use Elementor\Core\Kits\Documents\Tabs\Global_Typography; use HelloPlus\Includes\Utils as Theme_Utils; +use HelloPlus\Modules\TemplateParts\Documents\Footer_Document; use HelloPlus\Modules\Theme\Classes\Control_Media_Preview; use HelloPlus\Modules\TemplateParts\Classes\{ Traits\Shared_Header_Traits, @@ -24,8 +25,7 @@ use HelloPlus\Modules\Theme\Module as Theme_Module; -class Footer extends Widget_Base { - use Shared_Header_Traits; +class Footer extends Abstract_Ehp_Widget { public function get_name(): string { return 'footer'; @@ -67,6 +67,7 @@ protected function render(): void { protected function register_controls(): void { $this->add_content_section(); $this->add_style_section(); + $this->add_advanced_tab(); } public function add_content_section(): void { @@ -1071,4 +1072,8 @@ public function add_style_box_section(): void { $this->end_controls_section(); } + + public function get_advanced_tab_id() { + return Footer_Document::get_advanced_tab_id(); + } } diff --git a/modules/template-parts/widgets/header.php b/modules/template-parts/widgets/header.php index d2e2b85f..492d7da6 100644 --- a/modules/template-parts/widgets/header.php +++ b/modules/template-parts/widgets/header.php @@ -6,25 +6,23 @@ exit; // Exit if accessed directly. } +use HelloPlus\Modules\TemplateParts\Documents\Header_Document; use Elementor\{ - Widget_Base, Controls_Manager, Group_Control_Background, Group_Control_Box_Shadow, - Group_Control_Typography, + Group_Control_Typography }; use Elementor\Core\Kits\Documents\Tabs\Global_Typography; use HelloPlus\Modules\TemplateParts\Classes\{ - Traits\Shared_Header_Traits, Render\Widget_Header_Render, Control_Media_Preview, }; use HelloPlus\Modules\Theme\Module as Theme_Module; -class Header extends Widget_Base { - use Shared_Header_Traits; +class Header extends Abstract_Ehp_Widget { public function get_name(): string { return 'header'; @@ -63,6 +61,7 @@ protected function render(): void { protected function register_controls() { $this->add_content_tab(); $this->add_style_tab(); + $this->add_advanced_tab(); } protected function add_content_tab() { @@ -1820,4 +1819,8 @@ private function add_style_behavior_section(): void { $this->end_controls_section(); } + + public function get_advanced_tab_id() { + return Header_Document::get_advanced_tab_id(); + } } From e15f9771cdacbf7402d7f0ca9df17f3f5177bc9d Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Tue, 29 Oct 2024 19:40:32 +0100 Subject: [PATCH 02/20] remove logs --- modules/template-parts/documents/document-base.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/modules/template-parts/documents/document-base.php b/modules/template-parts/documents/document-base.php index 7f8e30fe..8d8a0412 100644 --- a/modules/template-parts/documents/document-base.php +++ b/modules/template-parts/documents/document-base.php @@ -73,12 +73,6 @@ public function get_css_wrapper_selector(): string { return '.ehp-' . $this->get_main_id(); } - //phpcs:disable -// protected static function get_editor_panel_categories(): array { -// return [ Module::HELLO_PLUS_EDITOR_CATEGORY_SLUG ]; -// } - //phpcs:enable - protected function get_remote_library_config(): array { $config = parent::get_remote_library_config(); @@ -109,7 +103,7 @@ public static function get_advanced_tab_id() { public static function is_editing_existing_document() { $action = ElementorUtils::get_super_global_value( $_GET, 'action' ); $post_id = ElementorUtils::get_super_global_value( $_GET, 'post' ); - error_log( 'is_editing_existing_document: ' . $action . ' ' . $post_id ); + return 'elementor' === $action && static::is_current_doc_meta_key( $post_id ); } @@ -121,9 +115,6 @@ public static function is_creating_document() { } public static function is_current_doc_meta_key( $post_id ) { - error_log( - 'is_current_doc_meta_key: ' . get_post_meta( $post_id, \Elementor\Core\Base\Document::TYPE_META_KEY, true ) . ' ' . static::get_type() - ); return static::get_type() === get_post_meta( $post_id, \Elementor\Core\Base\Document::TYPE_META_KEY, true ); } From c7389a116fc75d35c052a96dc65d61a593205e1d Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Tue, 29 Oct 2024 19:45:08 +0100 Subject: [PATCH 03/20] linting --- modules/template-parts/documents/document-base.php | 6 +++--- .../template-parts/widgets/abstract-ehp-widget.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/template-parts/documents/document-base.php b/modules/template-parts/documents/document-base.php index cec61c29..7b9dee52 100644 --- a/modules/template-parts/documents/document-base.php +++ b/modules/template-parts/documents/document-base.php @@ -46,7 +46,7 @@ public function print_content() { } } - public static function register( ) { + public static function register() { add_filter( 'elementor/widget/common/register_css_attributes_control', function ( $common_controls ) { if ( static::is_creating_document() || static::is_editing_existing_document() ) { return false; @@ -58,12 +58,12 @@ public static function register( ) { if ( static::is_creating_document() || static::is_editing_existing_document() ) { Controls_Manager::add_tab( Header_Document::get_advanced_tab_id(), - esc_html__( 'Advanced', 'elementor' ) + esc_html__( 'Advanced', 'hello-plus' ) ); Controls_Manager::add_tab( Footer_Document::get_advanced_tab_id(), - esc_html__( 'Advanced', 'elementor' ) + esc_html__( 'Advanced', 'hello-plus' ) ); } diff --git a/modules/template-parts/widgets/abstract-ehp-widget.php b/modules/template-parts/widgets/abstract-ehp-widget.php index fd76932f..ba377e84 100644 --- a/modules/template-parts/widgets/abstract-ehp-widget.php +++ b/modules/template-parts/widgets/abstract-ehp-widget.php @@ -17,13 +17,13 @@ protected function add_advanced_tab() { Controls_Manager::add_tab( $advanced_tab_id, - esc_html__( 'Advanced', 'elementor' ) + esc_html__( 'Advanced', 'hello-plus' ) ); $this->start_controls_section( 'advanced_custom_controls_section', [ - 'label' => esc_html__( 'CSS', 'elementor' ), + 'label' => esc_html__( 'CSS', 'hello-plus' ), 'tab' => $advanced_tab_id, ] ); @@ -31,7 +31,7 @@ protected function add_advanced_tab() { $this->add_control( 'advanced_custom_css_id', [ - 'label' => esc_html__( 'CSS ID', 'elementor' ), + 'label' => esc_html__( 'CSS ID', 'hello-plus' ), 'type' => Controls_Manager::TEXT, 'default' => '', 'ai' => [ @@ -40,7 +40,7 @@ protected function add_advanced_tab() { 'dynamic' => [ 'active' => true, ], - 'title' => esc_html__( 'Add your custom id WITHOUT the Pound key. e.g: my-id', 'elementor' ), + 'title' => esc_html__( 'Add your custom id WITHOUT the Pound key. e.g: my-id', 'hello-plus' ), 'style_transfer' => false, ] ); @@ -48,7 +48,7 @@ protected function add_advanced_tab() { $this->add_control( 'advanced_custom_css_classes', [ - 'label' => esc_html__( 'CSS Classes', 'elementor' ), + 'label' => esc_html__( 'CSS Classes', 'hello-plus' ), 'type' => Controls_Manager::TEXT, 'default' => '', 'ai' => [ @@ -57,7 +57,7 @@ protected function add_advanced_tab() { 'dynamic' => [ 'active' => true, ], - 'title' => esc_html__( 'Add your custom class WITHOUT the dot. e.g: my-class', 'elementor' ), + 'title' => esc_html__( 'Add your custom class WITHOUT the dot. e.g: my-class', 'hello-plus' ), ] ); From 72b1c7e312f934b05452333ee9eaea1cc6b04f17 Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Wed, 30 Oct 2024 12:21:42 +0100 Subject: [PATCH 04/20] rename docs --- modules/template-parts/components/document.php | 4 ++-- modules/template-parts/documents/document-base.php | 6 +++--- .../documents/{footer-document.php => footer.php} | 2 +- .../documents/{header-document.php => header.php} | 2 +- modules/template-parts/templates/footer.php | 4 ++-- modules/template-parts/templates/header.php | 4 ++-- modules/template-parts/widgets/ehp-footer.php | 4 ++-- modules/template-parts/widgets/ehp-header.php | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) rename modules/template-parts/documents/{footer-document.php => footer.php} (95%) rename modules/template-parts/documents/{header-document.php => header.php} (96%) diff --git a/modules/template-parts/components/document.php b/modules/template-parts/components/document.php index 5578e9c2..049ef2d7 100644 --- a/modules/template-parts/components/document.php +++ b/modules/template-parts/components/document.php @@ -15,8 +15,8 @@ class Document { private function get_documents_list(): array { return [ - 'Header_Document', - 'Footer_Document', + 'Header', + 'Footer', ]; } /** diff --git a/modules/template-parts/documents/document-base.php b/modules/template-parts/documents/document-base.php index 0fe43a33..816b7a31 100644 --- a/modules/template-parts/documents/document-base.php +++ b/modules/template-parts/documents/document-base.php @@ -27,7 +27,7 @@ public static function get_properties(): array { $properties['support_conditions'] = true; $properties['support_lazyload'] = false; $properties['condition_type'] = 'general'; - $properties['allow_adding_widgets'] = true; + $properties['allow_adding_widgets'] = false; $properties['support_page_layout'] = false; $properties['allow_closing_remote_library'] = false; @@ -57,12 +57,12 @@ public static function register() { if ( static::is_creating_document() || static::is_editing_existing_document() ) { Controls_Manager::add_tab( - Header_Document::get_advanced_tab_id(), + Header::get_advanced_tab_id(), esc_html__( 'Advanced', 'hello-plus' ) ); Controls_Manager::add_tab( - Footer_Document::get_advanced_tab_id(), + Footer::get_advanced_tab_id(), esc_html__( 'Advanced', 'hello-plus' ) ); diff --git a/modules/template-parts/documents/footer-document.php b/modules/template-parts/documents/footer.php similarity index 95% rename from modules/template-parts/documents/footer-document.php rename to modules/template-parts/documents/footer.php index 6fa840cc..eb6c9be8 100644 --- a/modules/template-parts/documents/footer-document.php +++ b/modules/template-parts/documents/footer.php @@ -9,7 +9,7 @@ /** * class Footer **/ -class Footer_Document extends Document_Base { +class Footer extends Document_Base { const LOCATION = 'footer'; public static function get_template_hook(): string { diff --git a/modules/template-parts/documents/header-document.php b/modules/template-parts/documents/header.php similarity index 96% rename from modules/template-parts/documents/header-document.php rename to modules/template-parts/documents/header.php index 1b6c5490..bb32966b 100644 --- a/modules/template-parts/documents/header-document.php +++ b/modules/template-parts/documents/header.php @@ -9,7 +9,7 @@ /** * class Header **/ -class Header_Document extends Document_Base { +class Header extends Document_Base { public static function get_template_hook(): string { return 'get_header'; diff --git a/modules/template-parts/templates/footer.php b/modules/template-parts/templates/footer.php index baad8ec0..5e1e0ac4 100644 --- a/modules/template-parts/templates/footer.php +++ b/modules/template-parts/templates/footer.php @@ -1,13 +1,13 @@ documents->get( $footer_doc_post ); $footer->print_content(); diff --git a/modules/template-parts/templates/header.php b/modules/template-parts/templates/header.php index ef09ccf2..0d9b6996 100644 --- a/modules/template-parts/templates/header.php +++ b/modules/template-parts/templates/header.php @@ -7,10 +7,10 @@ use HelloPlus\Includes\Utils as Theme_Utils; use Elementor\Utils as Elementor_Utils; -use HelloPlus\Modules\TemplateParts\Documents\Header_Document; +use HelloPlus\Modules\TemplateParts\Documents\Header; // Header template is validated earlier, so if we got this far, there is only one template-document post: -$header_doc_post = Header_Document::get_document_post(); +$header_doc_post = Header::get_document_post(); $header = Theme_Utils::elementor()->documents->get( $header_doc_post ); ?> diff --git a/modules/template-parts/widgets/ehp-footer.php b/modules/template-parts/widgets/ehp-footer.php index ba626126..e512a034 100644 --- a/modules/template-parts/widgets/ehp-footer.php +++ b/modules/template-parts/widgets/ehp-footer.php @@ -14,7 +14,7 @@ use Elementor\Core\Kits\Documents\Tabs\Global_Typography; use HelloPlus\Includes\Utils as Theme_Utils; -use HelloPlus\Modules\TemplateParts\Documents\Footer_Document; +use HelloPlus\Modules\TemplateParts\Documents\Footer; use HelloPlus\Modules\TemplateParts\Classes\{ Render\Widget_Footer_Render }; @@ -1071,6 +1071,6 @@ public function add_style_box_section(): void { } public function get_advanced_tab_id() { - return Footer_Document::get_advanced_tab_id(); + return Footer::get_advanced_tab_id(); } } diff --git a/modules/template-parts/widgets/ehp-header.php b/modules/template-parts/widgets/ehp-header.php index da39b287..8fd20aec 100644 --- a/modules/template-parts/widgets/ehp-header.php +++ b/modules/template-parts/widgets/ehp-header.php @@ -6,7 +6,7 @@ exit; // Exit if accessed directly. } -use HelloPlus\Modules\TemplateParts\Documents\Header_Document; +use HelloPlus\Modules\TemplateParts\Documents\Header; use Elementor\{ Controls_Manager, Group_Control_Background, @@ -1821,6 +1821,6 @@ private function add_style_behavior_section(): void { } public function get_advanced_tab_id() { - return Header_Document::get_advanced_tab_id(); + return Header::get_advanced_tab_id(); } } From 35c721130c2857dda4721b02c12128b2751c48b6 Mon Sep 17 00:00:00 2001 From: Nurit Date: Wed, 30 Oct 2024 14:35:40 +0200 Subject: [PATCH 05/20] TMZ-91 - tweaks --- .../template-parts/components/document.php | 5 ++- .../documents/document-base.php | 43 ++++++++++--------- modules/template-parts/widgets/ehp-footer.php | 2 +- modules/template-parts/widgets/ehp-header.php | 2 +- ...act-ehp-widget.php => ehp-widget-base.php} | 16 ++++--- 5 files changed, 38 insertions(+), 30 deletions(-) rename modules/template-parts/widgets/{abstract-ehp-widget.php => ehp-widget-base.php} (78%) diff --git a/modules/template-parts/components/document.php b/modules/template-parts/components/document.php index 049ef2d7..4f3575e7 100644 --- a/modules/template-parts/components/document.php +++ b/modules/template-parts/components/document.php @@ -30,14 +30,15 @@ public function register( Documents_Manager $documents_manager ) { $documents = $this->get_documents_list(); foreach ( $documents as $document ) { - /** @var \HelloPlus\Modules\TemplateParts\Documents\Document_Base $doc_class */ $doc_class = '\HelloPlus\Modules\TemplateParts\Documents\\' . $document; - $doc_class::register(); // add the doc type to Elementor documents: $documents_manager->register_document_type( $doc_class::get_type(), $doc_class ); + /** @var \HelloPlus\Modules\TemplateParts\Documents\Document_Base $doc_class */ + $doc_class::register(); + $doc_class::register_hooks(); } } diff --git a/modules/template-parts/documents/document-base.php b/modules/template-parts/documents/document-base.php index 816b7a31..38834e9d 100644 --- a/modules/template-parts/documents/document-base.php +++ b/modules/template-parts/documents/document-base.php @@ -7,10 +7,12 @@ } -use Elementor\{Controls_Manager, +use Elementor\{ + Controls_Manager, TemplateLibrary\Source_Local, Modules\Library\Documents\Library_Document, - Utils as ElementorUtils}; + Utils as ElementorUtils +}; use HelloPlus\Includes\Utils as Theme_Utils; use WP_Query; @@ -47,25 +49,11 @@ public function print_content() { } public static function register() { - add_filter( 'elementor/widget/common/register_css_attributes_control', function ( $common_controls ) { - if ( static::is_creating_document() || static::is_editing_existing_document() ) { - return false; - } - - return $common_controls; - } ); - if ( static::is_creating_document() || static::is_editing_existing_document() ) { Controls_Manager::add_tab( - Header::get_advanced_tab_id(), - esc_html__( 'Advanced', 'hello-plus' ) - ); - - Controls_Manager::add_tab( - Footer::get_advanced_tab_id(), + static::get_advanced_tab_id(), esc_html__( 'Advanced', 'hello-plus' ) ); - } } @@ -100,21 +88,21 @@ public static function get_advanced_tab_id() { return 'advanced-tab-' . static::get_type(); } - public static function is_editing_existing_document() { + public static function is_editing_existing_document(): bool { $action = ElementorUtils::get_super_global_value( $_GET, 'action' ); $post_id = ElementorUtils::get_super_global_value( $_GET, 'post' ); return 'elementor' === $action && static::is_current_doc_meta_key( $post_id ); } - public static function is_creating_document() { + public static function is_creating_document(): bool { $action = ElementorUtils::get_super_global_value( $_POST, 'action' ); //phpcs:ignore WordPress.Security.NonceVerification.Missing $post_id = ElementorUtils::get_super_global_value( $_POST, 'editor_post_id' ); //phpcs:ignore WordPress.Security.NonceVerification.Missing return 'elementor_ajax' === $action && static::is_current_doc_meta_key( $post_id ); } - public static function is_current_doc_meta_key( $post_id ) { + public static function is_current_doc_meta_key( $post_id ): bool { return static::get_type() === get_post_meta( $post_id, \Elementor\Core\Base\Document::TYPE_META_KEY, true ); } @@ -152,6 +140,21 @@ public static function register_hooks(): void { } add_action( static::get_template_hook(), [ static::get_class_full_name(), 'get_template' ], 10, 2 ); + add_filter( 'elementor/widget/common/register_css_attributes_control', [ static::get_class_full_name(), 'register_css_attributes_control' ], 10, 2 ); + } + + /** + * @param bool $common_controls + * @param \Elementor\Widget_Common $common_widget + * + * @return bool + */ + public static function register_css_attributes_control ( bool $common_controls, \Elementor\Widget_Common $common_widget ): bool { + if ( static::is_creating_document() || static::is_editing_existing_document() ) { + return false; + } + + return $common_controls; } /** diff --git a/modules/template-parts/widgets/ehp-footer.php b/modules/template-parts/widgets/ehp-footer.php index e512a034..3330dd58 100644 --- a/modules/template-parts/widgets/ehp-footer.php +++ b/modules/template-parts/widgets/ehp-footer.php @@ -22,7 +22,7 @@ use HelloPlus\Modules\Theme\Module as Theme_Module; -class Ehp_Footer extends Abstract_Ehp_Widget { +class Ehp_Footer extends Ehp_Widget_Base { public function get_name(): string { return 'emp-footer'; diff --git a/modules/template-parts/widgets/ehp-header.php b/modules/template-parts/widgets/ehp-header.php index 8fd20aec..c21d65f4 100644 --- a/modules/template-parts/widgets/ehp-header.php +++ b/modules/template-parts/widgets/ehp-header.php @@ -22,7 +22,7 @@ use HelloPlus\Modules\Theme\Module as Theme_Module; -class Ehp_Header extends Abstract_Ehp_Widget { +class Ehp_Header extends Ehp_Widget_Base { public function get_name(): string { return 'emp-header'; diff --git a/modules/template-parts/widgets/abstract-ehp-widget.php b/modules/template-parts/widgets/ehp-widget-base.php similarity index 78% rename from modules/template-parts/widgets/abstract-ehp-widget.php rename to modules/template-parts/widgets/ehp-widget-base.php index ba377e84..03cde0ab 100644 --- a/modules/template-parts/widgets/abstract-ehp-widget.php +++ b/modules/template-parts/widgets/ehp-widget-base.php @@ -3,11 +3,11 @@ namespace HelloPlus\Modules\TemplateParts\Widgets; use Elementor\Controls_Manager; -use Elementor\Plugin; use Elementor\Widget_Base; use HelloPlus\Modules\TemplateParts\Classes\Traits\Shared_Header_Traits; +use HelloPlus\Includes\Utils as Theme_Utils; -abstract class Abstract_Ehp_Widget extends Widget_Base { +abstract class Ehp_Widget_Base extends Widget_Base { use Shared_Header_Traits; abstract public function get_advanced_tab_id(); @@ -20,6 +20,14 @@ protected function add_advanced_tab() { esc_html__( 'Advanced', 'hello-plus' ) ); + $this->add_basic_css_controls_section( $advanced_tab_id ); + + $elementor_plugin = Theme_Utils::elementor(); + $elementor_plugin->controls_manager->add_custom_css_controls( $this, $advanced_tab_id ); + $elementor_plugin->controls_manager->add_custom_attributes_controls( $this, $advanced_tab_id ); + } + + protected function add_basic_css_controls_section( $advanced_tab_id ) { $this->start_controls_section( 'advanced_custom_controls_section', [ @@ -62,9 +70,5 @@ protected function add_advanced_tab() { ); $this->end_controls_section(); - - Plugin::$instance->controls_manager->add_custom_css_controls( $this, $advanced_tab_id ); - - Plugin::$instance->controls_manager->add_custom_attributes_controls( $this, $advanced_tab_id ); } } From c44b02658e2bb72042d12a9b8b771093865073c4 Mon Sep 17 00:00:00 2001 From: Nurit Date: Sun, 3 Nov 2024 17:00:00 +0200 Subject: [PATCH 06/20] lint --- modules/template-parts/documents/document-base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/template-parts/documents/document-base.php b/modules/template-parts/documents/document-base.php index 38834e9d..599c285f 100644 --- a/modules/template-parts/documents/document-base.php +++ b/modules/template-parts/documents/document-base.php @@ -149,7 +149,7 @@ public static function register_hooks(): void { * * @return bool */ - public static function register_css_attributes_control ( bool $common_controls, \Elementor\Widget_Common $common_widget ): bool { + public static function register_css_attributes_control( bool $common_controls, \Elementor\Widget_Common $common_widget ): bool { if ( static::is_creating_document() || static::is_editing_existing_document() ) { return false; } From 9ba8b16dcf9c26ea27fe1e29182cc6bbbd38ad3b Mon Sep 17 00:00:00 2001 From: Nurit Date: Sun, 3 Nov 2024 17:04:00 +0200 Subject: [PATCH 07/20] more lint --- modules/template-parts/components/document.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/template-parts/components/document.php b/modules/template-parts/components/document.php index 4f3575e7..ed3a23c0 100644 --- a/modules/template-parts/components/document.php +++ b/modules/template-parts/components/document.php @@ -32,7 +32,6 @@ public function register( Documents_Manager $documents_manager ) { foreach ( $documents as $document ) { $doc_class = '\HelloPlus\Modules\TemplateParts\Documents\\' . $document; - // add the doc type to Elementor documents: $documents_manager->register_document_type( $doc_class::get_type(), $doc_class ); From 1dfedd5057a075fecd76627c97b57e8616a0ccfe Mon Sep 17 00:00:00 2001 From: Nurit Date: Sun, 3 Nov 2024 17:10:41 +0200 Subject: [PATCH 08/20] lint --- modules/template-parts/documents/document-base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/template-parts/documents/document-base.php b/modules/template-parts/documents/document-base.php index 599c285f..7a2af741 100644 --- a/modules/template-parts/documents/document-base.php +++ b/modules/template-parts/documents/document-base.php @@ -89,8 +89,8 @@ public static function get_advanced_tab_id() { } public static function is_editing_existing_document(): bool { - $action = ElementorUtils::get_super_global_value( $_GET, 'action' ); - $post_id = ElementorUtils::get_super_global_value( $_GET, 'post' ); + $action = ElementorUtils::get_super_global_value( $_GET, 'action' ); //phpcs: ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required. + $post_id = ElementorUtils::get_super_global_value( $_GET, 'post' ); //phpcs: ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required. return 'elementor' === $action && static::is_current_doc_meta_key( $post_id ); } From 918a782e73a49efe8a9196c68b7d0e4f1b6f43e5 Mon Sep 17 00:00:00 2001 From: Nurit Date: Sun, 3 Nov 2024 17:15:46 +0200 Subject: [PATCH 09/20] space --- modules/template-parts/documents/document-base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/template-parts/documents/document-base.php b/modules/template-parts/documents/document-base.php index 7a2af741..613ab81f 100644 --- a/modules/template-parts/documents/document-base.php +++ b/modules/template-parts/documents/document-base.php @@ -89,8 +89,8 @@ public static function get_advanced_tab_id() { } public static function is_editing_existing_document(): bool { - $action = ElementorUtils::get_super_global_value( $_GET, 'action' ); //phpcs: ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required. - $post_id = ElementorUtils::get_super_global_value( $_GET, 'post' ); //phpcs: ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required. + $action = ElementorUtils::get_super_global_value( $_GET, 'action' ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required. + $post_id = ElementorUtils::get_super_global_value( $_GET, 'post' ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required. return 'elementor' === $action && static::is_current_doc_meta_key( $post_id ); } From 8a8b3db031f341cae9d194883e22cc8de81ea849 Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Mon, 4 Nov 2024 17:21:03 +0400 Subject: [PATCH 10/20] fixes --- modules/template-parts/documents/document-base.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/template-parts/documents/document-base.php b/modules/template-parts/documents/document-base.php index 613ab81f..d70a9161 100644 --- a/modules/template-parts/documents/document-base.php +++ b/modules/template-parts/documents/document-base.php @@ -30,6 +30,7 @@ public static function get_properties(): array { $properties['support_lazyload'] = false; $properties['condition_type'] = 'general'; $properties['allow_adding_widgets'] = false; + $properties['show_navigator'] = false; $properties['support_page_layout'] = false; $properties['allow_closing_remote_library'] = false; @@ -51,7 +52,12 @@ public function print_content() { public static function register() { if ( static::is_creating_document() || static::is_editing_existing_document() ) { Controls_Manager::add_tab( - static::get_advanced_tab_id(), + Header::get_advanced_tab_id(), + esc_html__( 'Advanced', 'hello-plus' ) + ); + + Controls_Manager::add_tab( + Footer::get_advanced_tab_id(), esc_html__( 'Advanced', 'hello-plus' ) ); } @@ -140,7 +146,7 @@ public static function register_hooks(): void { } add_action( static::get_template_hook(), [ static::get_class_full_name(), 'get_template' ], 10, 2 ); - add_filter( 'elementor/widget/common/register_css_attributes_control', [ static::get_class_full_name(), 'register_css_attributes_control' ], 10, 2 ); + add_filter( 'elementor/widget/common/register_css_attributes_control', [ static::get_class_full_name(), 'register_css_attributes_control' ] ); } /** @@ -149,7 +155,7 @@ public static function register_hooks(): void { * * @return bool */ - public static function register_css_attributes_control( bool $common_controls, \Elementor\Widget_Common $common_widget ): bool { + public static function register_css_attributes_control( bool $common_controls ): bool { if ( static::is_creating_document() || static::is_editing_existing_document() ) { return false; } From fed88ca91cc5ddaf44d61686b6e8012e151a9091 Mon Sep 17 00:00:00 2001 From: Nurit Date: Mon, 4 Nov 2024 20:23:47 +0200 Subject: [PATCH 11/20] advanced tab [TMZ-91] --- .../js/hello-plus-template-parts-editor.js | 14 ++--- .../classes/control-media-preview.php | 2 +- .../classes/render/widget-footer-render.php | 17 ++++++- .../classes/render/widget-header-render.php | 16 +++++- .../template-parts/components/document.php | 2 +- .../documents/document-base.php | 51 ------------------- modules/template-parts/widgets/ehp-footer.php | 5 +- modules/template-parts/widgets/ehp-header.php | 6 +-- .../widgets/ehp-widget-base.php | 14 +++-- 9 files changed, 47 insertions(+), 80 deletions(-) diff --git a/modules/template-parts/assets/js/hello-plus-template-parts-editor.js b/modules/template-parts/assets/js/hello-plus-template-parts-editor.js index 98786266..c200c06f 100644 --- a/modules/template-parts/assets/js/hello-plus-template-parts-editor.js +++ b/modules/template-parts/assets/js/hello-plus-template-parts-editor.js @@ -1,7 +1,7 @@ export default class helloPlusLogo { constructor() { elementor.channels.editor.on( 'helloPlusLogo:change', this.openSiteIdentity ); - elementor.channels.editor.on( 'section:activated', this.hideAdvancedTab.bind( this ) ); + elementor.hooks.addFilter( 'elements/widget/controls/common/default', this.resetCommonControls.bind( this ) ); } async openSiteIdentity() { @@ -9,18 +9,12 @@ export default class helloPlusLogo { $e.route( 'panel/global/settings-site-identity' ); } - hideAdvancedTab( sectionName, editor ) { - const widgetType = editor?.model?.get( 'widgetType' ) || ''; - + resetCommonControls( commonControls, widgetType ) { if ( widgetType.startsWith( 'ehp-' ) ) { - return; + return null; } - const advancedTab = editor?.el.querySelector( '.elementor-tab-control-advanced' ) || false; - - if ( advancedTab ) { - advancedTab.style.display = 'none'; - } + return commonControls; } } diff --git a/modules/template-parts/classes/control-media-preview.php b/modules/template-parts/classes/control-media-preview.php index 40bb99db..3b7fc893 100644 --- a/modules/template-parts/classes/control-media-preview.php +++ b/modules/template-parts/classes/control-media-preview.php @@ -9,7 +9,7 @@ class Control_Media_Preview extends Control_Media { - const CONTROL_TYPE = 'emp-media-preview'; + const CONTROL_TYPE = 'ehp-media-preview'; public function get_type() { return self::CONTROL_TYPE; diff --git a/modules/template-parts/classes/render/widget-footer-render.php b/modules/template-parts/classes/render/widget-footer-render.php index 497ad1b5..e3936c5a 100644 --- a/modules/template-parts/classes/render/widget-footer-render.php +++ b/modules/template-parts/classes/render/widget-footer-render.php @@ -27,14 +27,27 @@ class Widget_Footer_Render { public function render(): void { $layout_classnames = self::LAYOUT_CLASSNAME; $box_border = $this->settings['footer_box_border'] ?? ''; + $advanced_css_id = $this->settings['advanced_custom_css_id']; + $advanced_css_classes = $this->settings['advanced_custom_css_classes']; if ( 'yes' === $box_border ) { $layout_classnames .= ' has-box-border'; } - $this->widget->add_render_attribute( 'layout', [ + if ( ! empty( $advanced_css_classes ) ) { + $layout_classnames .= ' ' . $advanced_css_classes; + } + + $render_attributes = [ 'class' => $layout_classnames, - ] ); + ]; + + if ( ! empty( $advanced_css_id ) ) { + $render_attributes['id'] = $advanced_css_id; + } + + $this->widget->add_render_attribute( 'layout', $render_attributes ); + ?>
widget->print_render_attribute_string( 'layout' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>