From 6d3dbd1072bfe8b6318ece260f39ecda5a8244dd Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Sun, 5 Jan 2025 14:56:18 +0100 Subject: [PATCH 01/18] For Hello+ Header and Footer, use the library modal --- modules/template-parts/assets/js/editor.js | 4 ++ .../assets/js/editor/component.js | 1 + .../js/editor/hooks/ui/add-library-tab.js | 46 +++++++++++++++++++ .../assets/js/editor/hooks/ui/index.js | 3 ++ .../hooks/ui/open-library-after-delete.js | 24 ++++++++++ .../js/editor/hooks/ui/remove-library-tab.js | 23 ++++++++++ .../documents/document-base.php | 35 +++++++++----- modules/template-parts/module.php | 6 +-- modules/theme/components/theme-overrides.php | 6 +++ 9 files changed, 132 insertions(+), 16 deletions(-) create mode 100644 modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js create mode 100644 modules/template-parts/assets/js/editor/hooks/ui/open-library-after-delete.js create mode 100644 modules/template-parts/assets/js/editor/hooks/ui/remove-library-tab.js diff --git a/modules/template-parts/assets/js/editor.js b/modules/template-parts/assets/js/editor.js index aec7e753..4a8d4c61 100644 --- a/modules/template-parts/assets/js/editor.js +++ b/modules/template-parts/assets/js/editor.js @@ -1,5 +1,9 @@ import TemplatesModule from './editor/module'; +window.addEventListener( 'document/global/templates', () => { + console.log( 'document/global/templates' ); +} ); + const HelloPlusTemplates = new TemplatesModule(); window.helloPlusTemplates = HelloPlusTemplates; diff --git a/modules/template-parts/assets/js/editor/component.js b/modules/template-parts/assets/js/editor/component.js index 1867b9f8..9549f172 100644 --- a/modules/template-parts/assets/js/editor/component.js +++ b/modules/template-parts/assets/js/editor/component.js @@ -6,6 +6,7 @@ export default class Component extends $e.modules.ComponentBase { } defaultHooks() { + console.log( hooks ); return this.importHooks( hooks ); } } diff --git a/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js b/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js new file mode 100644 index 00000000..c76d72b4 --- /dev/null +++ b/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js @@ -0,0 +1,46 @@ +import { __ } from '@wordpress/i18n'; + +export class EhpAddLibraryTab extends $e.modules.hookUI.Before { + getCommand() { + console.log( 'EhpAddLibraryTab' ); + return 'library/open'; + } + + getId() { + return 'ehp-add-library-tab'; + } + + getConditions( args ) { + const document = elementor.documents.get( args.id ); + console.log( elementor?.config?.document?.type, 'getConditions' ); + return [ 'ehp-header', 'ehp-footer' ].includes( elementor?.config?.document?.type ); + } + + getTitle() { + console.log( elementor?.config?.document?.type, 'getTitle' ); + switch ( elementor?.config?.document?.type ) { + case 'ehp-header': + return __( 'Hello+ Header', 'elementor' ); + case 'ehp-footer': + return __( 'Hello+ Footer', 'elementor' ); + default: + return __( 'Hello Plus', 'elementor' ); + } + } + + apply() { + console.log( 'apply' ); + $e.components.get( 'library' ).addTab( 'templates/ehp-elements', { + title: this.getTitle(), + filter: { + source: 'remote', + type: 'floating_button', + }, + }, 2 ); + + $e.components.get( 'library' ).removeTab( 'templates/blocks' ); + $e.components.get( 'library' ).removeTab( 'templates/pages' ); + } +} + +export default EhpAddLibraryTab; diff --git a/modules/template-parts/assets/js/editor/hooks/ui/index.js b/modules/template-parts/assets/js/editor/hooks/ui/index.js index 177a59ff..e9fa6e25 100644 --- a/modules/template-parts/assets/js/editor/hooks/ui/index.js +++ b/modules/template-parts/assets/js/editor/hooks/ui/index.js @@ -1,2 +1,5 @@ export { SelectEhpElementOnOpen } from './attach-preview'; export { SelectAfterContainer } from './select'; +export { EhpAddLibraryTab } from './add-library-tab'; +export { EhpRemoveLibraryTab } from './remove-library-tab'; +export { EhpOpenLibraryAfterDelete } from './open-library-after-delete'; diff --git a/modules/template-parts/assets/js/editor/hooks/ui/open-library-after-delete.js b/modules/template-parts/assets/js/editor/hooks/ui/open-library-after-delete.js new file mode 100644 index 00000000..c0862066 --- /dev/null +++ b/modules/template-parts/assets/js/editor/hooks/ui/open-library-after-delete.js @@ -0,0 +1,24 @@ +export class EhpOpenLibraryAfterDelete extends $e.modules.hookUI.After { + getCommand() { + return 'document/elements/delete'; + } + + getId() { + return 'ehp-open-library-after-delete'; + } + + getConditions( args ) { + let type = args?.container?.document?.config?.type; + if ( ! type ) { + type = args?.containers[ 0 ]?.document?.config?.type; + } + + return [ 'ehp-header', 'ehp-footer' ].includes( type ); + } + + apply() { + $e.run( 'library/open' ); + } +} + +export default EhpOpenLibraryAfterDelete; diff --git a/modules/template-parts/assets/js/editor/hooks/ui/remove-library-tab.js b/modules/template-parts/assets/js/editor/hooks/ui/remove-library-tab.js new file mode 100644 index 00000000..9118bafa --- /dev/null +++ b/modules/template-parts/assets/js/editor/hooks/ui/remove-library-tab.js @@ -0,0 +1,23 @@ +export class EhpRemoveLibraryTab extends $e.modules.hookUI.After { + getCommand() { + return 'editor/documents/unload'; + } + + getId() { + return 'ehp-remove-library-tab'; + } + + getConditions( args ) { + const document = elementor.documents.get( args.id ); + return [ 'ehp-header', 'ehp-footer' ].includes( document.config.type ); + } + + apply() { + $e.components.get( 'library' ).removeTab( 'templates/ehp-elements' ); + + $e.components.get( 'library' ).addTab( 'templates/pages' ); + $e.components.get( 'library' ).addTab( 'templates/blocks' ); + } +} + +export default EhpRemoveLibraryTab; diff --git a/modules/template-parts/documents/document-base.php b/modules/template-parts/documents/document-base.php index 7b8fa0f8..dfda0385 100644 --- a/modules/template-parts/documents/document-base.php +++ b/modules/template-parts/documents/document-base.php @@ -13,6 +13,7 @@ }; use HelloPlus\Includes\Utils as Theme_Utils; +use Elementor\Modules\PageTemplates\Module as Page_Templates_Module; use WP_Query; /** @@ -27,14 +28,13 @@ public static function get_properties(): array { $properties['support_kit'] = true; $properties['show_in_finder'] = true; $properties['support_site_editor'] = false; - $properties['support_conditions'] = true; - $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; - + $properties['library_close_title'] = esc_html__( 'Go To Dashboard', 'elementor' ); + $properties['publish_button_title'] = esc_html__( 'After publishing this widget, you will be able to set it as visible on the entire site in the Admin Table.', 'elementor' ); + $properties['cpt'] = [ 'elementor_library' ]; /** * Filter the document properties. * @@ -62,14 +62,6 @@ public function get_css_wrapper_selector(): string { return '.ehp-' . $this->get_main_id(); } - protected function get_remote_library_config(): array { - $config = parent::get_remote_library_config(); - - $config['category'] = $this->get_name(); //Header_Footer_Base - - return $config; - } - public static function get_create_url(): string { $base_create_url = Theme_Utils::elementor()->documents->get_create_new_post_url( Source_Local::CPT ); @@ -167,6 +159,25 @@ public static function maybe_get_template( ?string $name, array $args ): void { static::get_template( $name, $args ); } + public function save( $data ) { + if ( empty( $data['settings']['template'] ) ) { + $data['settings']['template'] = Page_Templates_Module::TEMPLATE_CANVAS; + } + + return parent::save( $data ); + } + + protected function get_remote_library_config() { + $config = [ + 'type' => $this->get_name(), + 'default_route' => 'templates/ehp-elements', + 'autoImportSettings' => true, + 'category' => $this->get_name(), + ]; + + return array_replace_recursive( parent::get_remote_library_config(), $config ); + } + /** * The WP hook for rendering the relevant template. * diff --git a/modules/template-parts/module.php b/modules/template-parts/module.php index d32920c7..744c6c24 100644 --- a/modules/template-parts/module.php +++ b/modules/template-parts/module.php @@ -44,7 +44,6 @@ protected function get_widget_ids(): array { ]; } - /** * @return void */ @@ -77,7 +76,6 @@ public function register_styles(): void { ); } - /** * @return void */ @@ -85,7 +83,7 @@ public function enqueue_editor_scripts(): void { wp_enqueue_script( 'helloplus-editor', HELLOPLUS_SCRIPTS_URL . 'helloplus-editor.js', - [ 'elementor-editor' ], + [ 'elementor-v2-ui', 'elementor-editor' ], HELLOPLUS_VERSION, true ); @@ -122,7 +120,7 @@ protected function register_hooks(): void { add_action( 'elementor/frontend/after_register_scripts', [ $this, 'register_scripts' ] ); add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] ); add_action( 'elementor/editor/after_enqueue_styles', [ $this, 'enqueue_editor_styles' ] ); - add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] ); + add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] ); add_action( 'elementor/controls/register', [ $this, 'register_controls' ] ); } } diff --git a/modules/theme/components/theme-overrides.php b/modules/theme/components/theme-overrides.php index 6a3814a2..07be81c0 100644 --- a/modules/theme/components/theme-overrides.php +++ b/modules/theme/components/theme-overrides.php @@ -12,6 +12,7 @@ } class Theme_Overrides { + public function admin_config( array $config ): array { if ( ! Setup_Wizard::has_site_wizard_been_completed() ) { return $config; @@ -47,5 +48,10 @@ public function __construct() { add_filter( 'hello-plus-theme/settings/hello_style', '__return_false' ); add_filter( 'hello-plus-theme/customizer/enable', Setup_Wizard::has_site_wizard_been_completed() ? '__return_false' : '__return_true' ); add_filter( 'hello-plus-theme/rest/admin-config', [ $this, 'admin_config' ] ); + add_action( 'requests-requests.before_request', function ( &$url ) { + if ( 'https://my.elementor.com/api/v1/info/' === $url ) { + $url = 'https://ba-templates.stg.elementor.red/api/connect/v1/library/templates?products=ehp'; + } + } ); } } From c9a7d45a5c081fe361e075414e2ee35eafacd75d Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Sun, 5 Jan 2025 15:07:19 +0100 Subject: [PATCH 02/18] remove logging --- modules/template-parts/assets/js/editor.js | 4 ---- modules/template-parts/assets/js/editor/component.js | 1 - .../assets/js/editor/hooks/ui/add-library-tab.js | 7 +------ 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/modules/template-parts/assets/js/editor.js b/modules/template-parts/assets/js/editor.js index 4a8d4c61..aec7e753 100644 --- a/modules/template-parts/assets/js/editor.js +++ b/modules/template-parts/assets/js/editor.js @@ -1,9 +1,5 @@ import TemplatesModule from './editor/module'; -window.addEventListener( 'document/global/templates', () => { - console.log( 'document/global/templates' ); -} ); - const HelloPlusTemplates = new TemplatesModule(); window.helloPlusTemplates = HelloPlusTemplates; diff --git a/modules/template-parts/assets/js/editor/component.js b/modules/template-parts/assets/js/editor/component.js index 9549f172..1867b9f8 100644 --- a/modules/template-parts/assets/js/editor/component.js +++ b/modules/template-parts/assets/js/editor/component.js @@ -6,7 +6,6 @@ export default class Component extends $e.modules.ComponentBase { } defaultHooks() { - console.log( hooks ); return this.importHooks( hooks ); } } diff --git a/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js b/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js index c76d72b4..e0d0add9 100644 --- a/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js +++ b/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js @@ -2,7 +2,6 @@ import { __ } from '@wordpress/i18n'; export class EhpAddLibraryTab extends $e.modules.hookUI.Before { getCommand() { - console.log( 'EhpAddLibraryTab' ); return 'library/open'; } @@ -10,14 +9,11 @@ export class EhpAddLibraryTab extends $e.modules.hookUI.Before { return 'ehp-add-library-tab'; } - getConditions( args ) { - const document = elementor.documents.get( args.id ); - console.log( elementor?.config?.document?.type, 'getConditions' ); + getConditions() { return [ 'ehp-header', 'ehp-footer' ].includes( elementor?.config?.document?.type ); } getTitle() { - console.log( elementor?.config?.document?.type, 'getTitle' ); switch ( elementor?.config?.document?.type ) { case 'ehp-header': return __( 'Hello+ Header', 'elementor' ); @@ -29,7 +25,6 @@ export class EhpAddLibraryTab extends $e.modules.hookUI.Before { } apply() { - console.log( 'apply' ); $e.components.get( 'library' ).addTab( 'templates/ehp-elements', { title: this.getTitle(), filter: { From 1fb0caa01cffd955e51c9f3361ee0f209925932d Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Sun, 5 Jan 2025 16:07:22 +0100 Subject: [PATCH 03/18] implement redirect --- modules/template-parts/assets/js/editor/module.js | 10 ++++++++++ modules/theme/components/theme-overrides.php | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/modules/template-parts/assets/js/editor/module.js b/modules/template-parts/assets/js/editor/module.js index a70d5fd3..5abf3e19 100644 --- a/modules/template-parts/assets/js/editor/module.js +++ b/modules/template-parts/assets/js/editor/module.js @@ -7,6 +7,12 @@ export default class TemplatesModule extends elementorModules.editor.utils.Modul elementor.hooks.addFilter( 'elements/widget/controls/common/default', this.resetCommonControls.bind( this ) ); elementor.hooks.addFilter( 'elements/widget/controls/common-optimized/default', this.resetCommonControls.bind( this ) ); + window.addEventListener( 'core/modal/close', () => { + if ( this.isEhpDocument() ) { + window.location.href = elementor.config.close_modal_redirect_hello_plus; + } + } ); + window.templatesModule = this; } @@ -22,4 +28,8 @@ export default class TemplatesModule extends elementorModules.editor.utils.Modul return commonControls; } + + isEhpDocument() { + return [ 'ehp-footer', 'ehp-header' ].includes( elementor.config.document.type ); + } } diff --git a/modules/theme/components/theme-overrides.php b/modules/theme/components/theme-overrides.php index 07be81c0..2c0e2e14 100644 --- a/modules/theme/components/theme-overrides.php +++ b/modules/theme/components/theme-overrides.php @@ -53,5 +53,11 @@ public function __construct() { $url = 'https://ba-templates.stg.elementor.red/api/connect/v1/library/templates?products=ehp'; } } ); + + add_action( 'elementor/editor/localize_settings', function ( $data ) { + $data['close_modal_redirect_hello_plus'] = admin_url( 'admin.php?page=hello-biz' ); + + return $data; + } ); } } From 619524bac24d36fc5fd4a3cb04a398a57521d157 Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Sun, 5 Jan 2025 17:31:37 +0100 Subject: [PATCH 04/18] more specific events --- modules/template-parts/assets/js/editor/module.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/template-parts/assets/js/editor/module.js b/modules/template-parts/assets/js/editor/module.js index 5abf3e19..f9854fab 100644 --- a/modules/template-parts/assets/js/editor/module.js +++ b/modules/template-parts/assets/js/editor/module.js @@ -7,15 +7,22 @@ export default class TemplatesModule extends elementorModules.editor.utils.Modul elementor.hooks.addFilter( 'elements/widget/controls/common/default', this.resetCommonControls.bind( this ) ); elementor.hooks.addFilter( 'elements/widget/controls/common-optimized/default', this.resetCommonControls.bind( this ) ); - window.addEventListener( 'core/modal/close', () => { - if ( this.isEhpDocument() ) { - window.location.href = elementor.config.close_modal_redirect_hello_plus; - } + const types = [ + 'core/modal/close/ehp-footer', + 'core/modal/close/ehp-header', + ]; + + types.forEach( ( type ) => { + window.addEventListener( type, this.redirectToHelloPlus ); } ); window.templatesModule = this; } + redirectToHelloPlus() { + window.location.href = elementor.config.close_modal_redirect_hello_plus; + } + async openSiteIdentity() { await $e.run( 'panel/global/open' ); $e.route( 'panel/global/settings-site-identity' ); From d04bfa132cbeeecef1a21d8823b517afbff0d917 Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Mon, 6 Jan 2025 11:59:21 +0100 Subject: [PATCH 05/18] linting --- 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 dfda0385..9ff81bae 100644 --- a/modules/template-parts/documents/document-base.php +++ b/modules/template-parts/documents/document-base.php @@ -32,8 +32,8 @@ public static function get_properties(): array { $properties['show_navigator'] = false; $properties['support_page_layout'] = false; $properties['allow_closing_remote_library'] = false; - $properties['library_close_title'] = esc_html__( 'Go To Dashboard', 'elementor' ); - $properties['publish_button_title'] = esc_html__( 'After publishing this widget, you will be able to set it as visible on the entire site in the Admin Table.', 'elementor' ); + $properties['library_close_title'] = esc_html__( 'Go To Dashboard', 'hello-plus' ); + $properties['publish_button_title'] = esc_html__( 'After publishing this widget, you will be able to set it as visible on the entire site in the Admin Table.', 'hello-plus' ); $properties['cpt'] = [ 'elementor_library' ]; /** * Filter the document properties. From c7e5ebddf155899d28e6d689a0c68ed7721294ea Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Mon, 6 Jan 2025 12:04:58 +0100 Subject: [PATCH 06/18] linting --- .../assets/js/editor/hooks/ui/add-library-tab.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js b/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js index e0d0add9..d7e91fa8 100644 --- a/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js +++ b/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js @@ -16,9 +16,9 @@ export class EhpAddLibraryTab extends $e.modules.hookUI.Before { getTitle() { switch ( elementor?.config?.document?.type ) { case 'ehp-header': - return __( 'Hello+ Header', 'elementor' ); + return __( 'Hello+ Header', 'hello-plus' ); case 'ehp-footer': - return __( 'Hello+ Footer', 'elementor' ); + return __( 'Hello+ Footer', 'hello-plus' ); default: return __( 'Hello Plus', 'elementor' ); } From 6839917238a7dfbc1223f17d15e6143c3f539f57 Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Mon, 6 Jan 2025 16:08:03 +0100 Subject: [PATCH 07/18] new url --- modules/theme/components/theme-overrides.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/theme/components/theme-overrides.php b/modules/theme/components/theme-overrides.php index 2c0e2e14..8da754e7 100644 --- a/modules/theme/components/theme-overrides.php +++ b/modules/theme/components/theme-overrides.php @@ -50,7 +50,7 @@ public function __construct() { add_filter( 'hello-plus-theme/rest/admin-config', [ $this, 'admin_config' ] ); add_action( 'requests-requests.before_request', function ( &$url ) { if ( 'https://my.elementor.com/api/v1/info/' === $url ) { - $url = 'https://ba-templates.stg.elementor.red/api/connect/v1/library/templates?products=ehp'; + $url = 'https://my.elementor.com/api/connect/v1/library/templates?products=ehp'; } } ); From 47d18643b379c701e7a0b8dd6bcf67106a404bbc Mon Sep 17 00:00:00 2001 From: Nurit Date: Tue, 7 Jan 2025 16:06:46 +0200 Subject: [PATCH 08/18] minor tweaks --- modules/template-parts/documents/document-base.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/template-parts/documents/document-base.php b/modules/template-parts/documents/document-base.php index 9ff81bae..23a2b6a3 100644 --- a/modules/template-parts/documents/document-base.php +++ b/modules/template-parts/documents/document-base.php @@ -34,7 +34,6 @@ public static function get_properties(): array { $properties['allow_closing_remote_library'] = false; $properties['library_close_title'] = esc_html__( 'Go To Dashboard', 'hello-plus' ); $properties['publish_button_title'] = esc_html__( 'After publishing this widget, you will be able to set it as visible on the entire site in the Admin Table.', 'hello-plus' ); - $properties['cpt'] = [ 'elementor_library' ]; /** * Filter the document properties. * @@ -168,14 +167,13 @@ public function save( $data ) { } protected function get_remote_library_config() { - $config = [ - 'type' => $this->get_name(), - 'default_route' => 'templates/ehp-elements', - 'autoImportSettings' => true, - 'category' => $this->get_name(), - ]; + $config = parent::get_remote_library_config(); + + $config['type'] = $this->get_name(); + $config['default_route'] = 'templates/ehp-elements'; + $config['autoImportSettings'] = true; - return array_replace_recursive( parent::get_remote_library_config(), $config ); + return $config; } /** From 799344c390b9afe0a0742042684b5a2f44f4ada0 Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Sun, 12 Jan 2025 11:18:45 +0100 Subject: [PATCH 09/18] hello plus --- .../js/editor/hooks/ui/add-library-tab.js | 4 +-- .../classes/sources/source-remote-ehp.php | 30 +++++++++++++++++++ modules/theme/components/theme-overrides.php | 25 +++++++++------- 3 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 modules/template-parts/classes/sources/source-remote-ehp.php diff --git a/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js b/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js index d7e91fa8..d6d6e62e 100644 --- a/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js +++ b/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js @@ -28,8 +28,8 @@ export class EhpAddLibraryTab extends $e.modules.hookUI.Before { $e.components.get( 'library' ).addTab( 'templates/ehp-elements', { title: this.getTitle(), filter: { - source: 'remote', - type: 'floating_button', + source: 'remote-ehp', + type: 'block', }, }, 2 ); diff --git a/modules/template-parts/classes/sources/source-remote-ehp.php b/modules/template-parts/classes/sources/source-remote-ehp.php new file mode 100644 index 00000000..5dcff4fd --- /dev/null +++ b/modules/template-parts/classes/sources/source-remote-ehp.php @@ -0,0 +1,30 @@ +get_templates_remotely( $editor_layout_type ); + + error_log( 'templates_data: ' . print_r( $templates_data, true ) ); + + if ( empty( $templates_data ) ) { + return []; + } + + set_transient( $templates_data_cache_key, $templates_data, 12 * HOUR_IN_SECONDS ); + + return $templates_data; + } +} diff --git a/modules/theme/components/theme-overrides.php b/modules/theme/components/theme-overrides.php index 8da754e7..0c498ea4 100644 --- a/modules/theme/components/theme-overrides.php +++ b/modules/theme/components/theme-overrides.php @@ -42,22 +42,25 @@ public function admin_config( array $config ): array { return $config; } + public function register_remote_source( ) { + Utils::elementor()->templates_manager->register_source( + 'HelloPlus\Modules\TemplateParts\Classes\Sources\Source_Remote_Ehp' + ); + } + + public function localize_settings( $data ) { + $data['close_modal_redirect_hello_plus'] = admin_url( 'admin.php?page=hello-biz' ); + + return $data; + } + public function __construct() { add_filter( 'hello-plus-theme/settings/header_footer', '__return_false' ); add_filter( 'hello-plus-theme/settings/hello_theme', '__return_false' ); add_filter( 'hello-plus-theme/settings/hello_style', '__return_false' ); add_filter( 'hello-plus-theme/customizer/enable', Setup_Wizard::has_site_wizard_been_completed() ? '__return_false' : '__return_true' ); add_filter( 'hello-plus-theme/rest/admin-config', [ $this, 'admin_config' ] ); - add_action( 'requests-requests.before_request', function ( &$url ) { - if ( 'https://my.elementor.com/api/v1/info/' === $url ) { - $url = 'https://my.elementor.com/api/connect/v1/library/templates?products=ehp'; - } - } ); - - add_action( 'elementor/editor/localize_settings', function ( $data ) { - $data['close_modal_redirect_hello_plus'] = admin_url( 'admin.php?page=hello-biz' ); - - return $data; - } ); + add_action('elementor/init', [ $this, 'register_remote_source' ] ); + add_action( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] ); } } From 3a2998bc4dd93536150a8c47aa1884262328af7e Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Sun, 12 Jan 2025 11:22:28 +0100 Subject: [PATCH 10/18] linting --- modules/template-parts/classes/sources/source-remote-ehp.php | 2 -- modules/theme/components/theme-overrides.php | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/template-parts/classes/sources/source-remote-ehp.php b/modules/template-parts/classes/sources/source-remote-ehp.php index 5dcff4fd..be96c016 100644 --- a/modules/template-parts/classes/sources/source-remote-ehp.php +++ b/modules/template-parts/classes/sources/source-remote-ehp.php @@ -17,8 +17,6 @@ protected function get_templates( string $editor_layout_type ): array { $templates_data = $this->get_templates_remotely( $editor_layout_type ); - error_log( 'templates_data: ' . print_r( $templates_data, true ) ); - if ( empty( $templates_data ) ) { return []; } diff --git a/modules/theme/components/theme-overrides.php b/modules/theme/components/theme-overrides.php index 0c498ea4..dc74e25e 100644 --- a/modules/theme/components/theme-overrides.php +++ b/modules/theme/components/theme-overrides.php @@ -42,7 +42,7 @@ public function admin_config( array $config ): array { return $config; } - public function register_remote_source( ) { + public function register_remote_source() { Utils::elementor()->templates_manager->register_source( 'HelloPlus\Modules\TemplateParts\Classes\Sources\Source_Remote_Ehp' ); @@ -60,7 +60,7 @@ public function __construct() { add_filter( 'hello-plus-theme/settings/hello_style', '__return_false' ); add_filter( 'hello-plus-theme/customizer/enable', Setup_Wizard::has_site_wizard_been_completed() ? '__return_false' : '__return_true' ); add_filter( 'hello-plus-theme/rest/admin-config', [ $this, 'admin_config' ] ); - add_action('elementor/init', [ $this, 'register_remote_source' ] ); + add_action( 'elementor/init', [ $this, 'register_remote_source' ] ); add_action( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] ); } } From e24dea255af72fc15118f16411ac4d345af2613a Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Sun, 12 Jan 2025 14:59:34 +0100 Subject: [PATCH 11/18] refactoring --- .../template-parts/classes/sources/source-remote-ehp.php | 4 ++++ modules/template-parts/components/document.php | 9 +++++++++ modules/template-parts/module.php | 2 +- modules/theme/components/theme-overrides.php | 7 ------- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/modules/template-parts/classes/sources/source-remote-ehp.php b/modules/template-parts/classes/sources/source-remote-ehp.php index be96c016..56142ecb 100644 --- a/modules/template-parts/classes/sources/source-remote-ehp.php +++ b/modules/template-parts/classes/sources/source-remote-ehp.php @@ -2,6 +2,10 @@ namespace HelloPlus\Modules\TemplateParts\Classes\Sources; +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} + class Source_Remote_Ehp extends \Elementor\TemplateLibrary\Source_Remote { const API_TEMPLATES_URL = 'https://my.stg.elementor.red/api/connect/v1/library/templates?products=ehp'; diff --git a/modules/template-parts/components/document.php b/modules/template-parts/components/document.php index e5ab6b23..16b3d1b3 100644 --- a/modules/template-parts/components/document.php +++ b/modules/template-parts/components/document.php @@ -7,6 +7,7 @@ } use Elementor\Core\Documents_Manager; +use HelloPlus\Includes\Utils; /** * class Document @@ -46,7 +47,15 @@ public function register( Documents_Manager $documents_manager ) { } } + + public function register_remote_source() { + Utils::elementor()->templates_manager->register_source( + 'HelloPlus\Modules\TemplateParts\Classes\Sources\Source_Remote_Ehp' + ); + } + public function __construct() { add_action( 'elementor/documents/register', [ $this, 'register' ] ); + add_action( 'elementor/init', [ $this, 'register_remote_source' ] ); } } diff --git a/modules/template-parts/module.php b/modules/template-parts/module.php index 744c6c24..13e74dde 100644 --- a/modules/template-parts/module.php +++ b/modules/template-parts/module.php @@ -83,7 +83,7 @@ public function enqueue_editor_scripts(): void { wp_enqueue_script( 'helloplus-editor', HELLOPLUS_SCRIPTS_URL . 'helloplus-editor.js', - [ 'elementor-v2-ui', 'elementor-editor' ], + [ 'elementor-editor' ], HELLOPLUS_VERSION, true ); diff --git a/modules/theme/components/theme-overrides.php b/modules/theme/components/theme-overrides.php index dc74e25e..9f7c2d72 100644 --- a/modules/theme/components/theme-overrides.php +++ b/modules/theme/components/theme-overrides.php @@ -42,12 +42,6 @@ public function admin_config( array $config ): array { return $config; } - public function register_remote_source() { - Utils::elementor()->templates_manager->register_source( - 'HelloPlus\Modules\TemplateParts\Classes\Sources\Source_Remote_Ehp' - ); - } - public function localize_settings( $data ) { $data['close_modal_redirect_hello_plus'] = admin_url( 'admin.php?page=hello-biz' ); @@ -60,7 +54,6 @@ public function __construct() { add_filter( 'hello-plus-theme/settings/hello_style', '__return_false' ); add_filter( 'hello-plus-theme/customizer/enable', Setup_Wizard::has_site_wizard_been_completed() ? '__return_false' : '__return_true' ); add_filter( 'hello-plus-theme/rest/admin-config', [ $this, 'admin_config' ] ); - add_action( 'elementor/init', [ $this, 'register_remote_source' ] ); add_action( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] ); } } From aec42b36d49389a457f69c5e48d4186dcf12dd37 Mon Sep 17 00:00:00 2001 From: Nurit Date: Mon, 13 Jan 2025 03:03:34 +0200 Subject: [PATCH 12/18] remote-ehp --- .../classes/sources/source-remote-ehp.php | 206 +++++++++++++++++- 1 file changed, 202 insertions(+), 4 deletions(-) diff --git a/modules/template-parts/classes/sources/source-remote-ehp.php b/modules/template-parts/classes/sources/source-remote-ehp.php index 56142ecb..c2c54b5b 100644 --- a/modules/template-parts/classes/sources/source-remote-ehp.php +++ b/modules/template-parts/classes/sources/source-remote-ehp.php @@ -2,22 +2,165 @@ namespace HelloPlus\Modules\TemplateParts\Classes\Sources; +use Elementor\Api as Elementor_Api; +use Elementor\Core\Common\Modules\Connect\Module as Elementor_Connect_Module; +use HelloPlus\Includes\Utils; + if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -class Source_Remote_Ehp extends \Elementor\TemplateLibrary\Source_Remote { +class Source_Remote_Ehp extends \Elementor\TemplateLibrary\Source_Base { - const API_TEMPLATES_URL = 'https://my.stg.elementor.red/api/connect/v1/library/templates?products=ehp'; + const API_TEMPLATES_URL = 'https://ba-templates-api.platform-prod.elementor.red/v1/templates/'; const TEMPLATES_DATA_TRANSIENT_KEY_PREFIX = 'elementor_remote_templates_ehp_data_'; - public function get_id() { + public function get_id(): string { return 'remote-ehp'; } + /** + * @inheritDoc + */ + public function get_title() { + return esc_html__( 'Remote-Ehp', 'hello-plus' ); + } + + /** + * @inheritDoc + */ + public function register_data() {} + + /** + * @inheritDoc + */ + public function get_items( $args = [] ) { + $force_update = ! empty( $args['force_update'] ) && is_bool( $args['force_update'] ); + + $templates_data = $this->get_templates_data( $force_update ); + + $templates = []; + + foreach ( $templates_data as $template_data ) { + $templates[] = $this->prepare_template( $template_data ); + } + + return $templates; + } + + + protected function prepare_template( array $template_data ) { + $favorite_templates = $this->get_user_meta( 'favorites' ); + + // BC: Support legacy APIs that don't have access tiers. + if ( isset( $template_data['access_tier'] ) ) { + $access_tier = $template_data['access_tier']; + } else { + $access_tier = 0 === $template_data['access_level'] + ? Elementor_Connect_Module::ACCESS_TIER_FREE + : Elementor_Connect_Module::ACCESS_TIER_ESSENTIAL; + } + + return [ + 'template_id' => $template_data['id'], + 'source' => $this->get_id(), + 'type' => $template_data['type'], + 'subtype' => $template_data['subtype'], + 'title' => $template_data['title'], + 'thumbnail' => $template_data['thumbnail'], + 'date' => $template_data['tmpl_created'], + 'author' => $template_data['author'], + 'tags' => json_decode( $template_data['tags'] ), + 'isPro' => ( '1' === $template_data['is_pro'] ), + 'accessLevel' => $template_data['access_level'], + 'accessTier' => $access_tier, + 'popularityIndex' => (int) $template_data['popularity_index'], + 'trendIndex' => (int) $template_data['trend_index'], + 'hasPageSettings' => ( '1' === $template_data['has_page_settings'] ), + 'url' => $template_data['url'], + 'favorite' => ! empty( $favorite_templates[ $template_data['id'] ] ), + ]; + } + + + /** + * @inheritDoc + */ + public function get_item( $template_id ) { + $templates = $this->get_items(); + + return $templates[ $template_id ]; + } + + /** + * @inheritDoc + */ + public function save_item( $template_data ) { + return new \WP_Error( 'invalid_request', 'Cannot save template to a remote source' ); + } + + /** + * @inheritDoc + */ + public function update_item( $new_data ) { + return new \WP_Error( 'invalid_request', 'Cannot update template to a remote source' ); + } + + /** + * @inheritDoc + */ + public function delete_template( $template_id ) { + return new \WP_Error( 'invalid_request', 'Cannot delete template from a remote source' ); + } + + /** + * @inheritDoc + */ + public function get_data( array $args, $context = 'display' ) { + $data = Elementor_Api::get_template_content( $args['template_id'] ); + + if ( is_wp_error( $data ) ) { + return $data; + } + + // Set the Request's state as an Elementor upload request, in order to support unfiltered file uploads. + Utils::elementor()->uploads_manager->set_elementor_upload_state( true ); + + // BC. + $data = (array) $data; + + $data['content'] = $this->replace_elements_ids( $data['content'] ); + $data['content'] = $this->process_export_import_content( $data['content'], 'on_import' ); + + $post_id = $args['editor_post_id']; + $document = Utils::elementor()->documents->get( $post_id ); + if ( $document ) { + $data['content'] = $document->get_elements_raw_data( $data['content'], true ); + } + + // After the upload complete, set the elementor upload state back to false + Utils::elementor()->uploads_manager->set_elementor_upload_state( false ); + + return $data; + } + + protected function get_template_data_transient_key(): string { + return static::TEMPLATES_DATA_TRANSIENT_KEY_PREFIX . HELLO_PLUS_VERSION; + } + + /** + * @inheritDoc + */ + public function export_template( $template_id ) { + return new \WP_Error( 'invalid_request', 'Cannot export template from a remote source' ); + } + + /** + * @inheritDoc + */ protected function get_templates( string $editor_layout_type ): array { - $templates_data_cache_key = static::TEMPLATES_DATA_TRANSIENT_KEY_PREFIX . HELLO_PLUS_VERSION; + $templates_data_cache_key = $this->get_template_data_transient_key(); $templates_data = $this->get_templates_remotely( $editor_layout_type ); @@ -29,4 +172,59 @@ protected function get_templates( string $editor_layout_type ): array { return $templates_data; } + + /** + * @inheritDoc + */ + protected function get_templates_remotely( string $editor_layout_type ) { + $query_args = $this->get_url_params( $editor_layout_type ); + $url = add_query_arg( $query_args, static::API_TEMPLATES_URL ); + + $response = wp_remote_get( $url, [ + 'headers' => apply_filters( 'stg-cf-headers', [] ), + ] ); + + if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { + return false; + } + + $templates_data = json_decode( wp_remote_retrieve_body( $response ), true ); + + if ( empty( $templates_data ) || ! is_array( $templates_data ) ) { + return []; + } + + return $templates_data; + } + + protected function get_templates_body_args( string $editor_layout_type ): array { + return []; + } + protected function get_url_params( string $editor_layout_type ): array { + return [ + 'products' => 'ehp', + 'editor_layout_type' => $editor_layout_type, + ]; + } + + /** + * @inheritDoc + */ + protected function get_templates_data( bool $force_update ) : array { + $templates_data_cache_key = $this->get_template_data_transient_key(); + + $editor_layout_type = 'container_flexbox'; + + if ( $force_update ) { + return $this->get_templates( $editor_layout_type ); + } + + $templates_data = get_transient( $templates_data_cache_key ); + + if ( empty( $templates_data ) ) { + return $this->get_templates( $editor_layout_type ); + } + + return $templates_data; + } } From 88601867b98f7500dee07174e77c9f3afa506d69 Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Thu, 16 Jan 2025 15:55:56 +0100 Subject: [PATCH 13/18] fix --- .../assets/js/editor/hooks/ui/add-library-tab.js | 1 + modules/template-parts/classes/sources/source-remote-ehp.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js b/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js index d6d6e62e..de947932 100644 --- a/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js +++ b/modules/template-parts/assets/js/editor/hooks/ui/add-library-tab.js @@ -30,6 +30,7 @@ export class EhpAddLibraryTab extends $e.modules.hookUI.Before { filter: { source: 'remote-ehp', type: 'block', + subtype: elementor?.config?.document?.type, }, }, 2 ); diff --git a/modules/template-parts/classes/sources/source-remote-ehp.php b/modules/template-parts/classes/sources/source-remote-ehp.php index c2c54b5b..8f1102fa 100644 --- a/modules/template-parts/classes/sources/source-remote-ehp.php +++ b/modules/template-parts/classes/sources/source-remote-ehp.php @@ -12,7 +12,7 @@ class Source_Remote_Ehp extends \Elementor\TemplateLibrary\Source_Base { - const API_TEMPLATES_URL = 'https://ba-templates-api.platform-prod.elementor.red/v1/templates/'; + const API_TEMPLATES_URL = 'https://ba-templates.stg.elementor.red/v1/templates/'; const TEMPLATES_DATA_TRANSIENT_KEY_PREFIX = 'elementor_remote_templates_ehp_data_'; @@ -184,6 +184,7 @@ protected function get_templates_remotely( string $editor_layout_type ) { 'headers' => apply_filters( 'stg-cf-headers', [] ), ] ); + error_log( print_r( $response, true ) ); if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { return false; } @@ -200,6 +201,7 @@ protected function get_templates_remotely( string $editor_layout_type ) { protected function get_templates_body_args( string $editor_layout_type ): array { return []; } + protected function get_url_params( string $editor_layout_type ): array { return [ 'products' => 'ehp', From 871d172189ac8c147123d088d322ffe1fece9483 Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Fri, 17 Jan 2025 22:37:26 +0100 Subject: [PATCH 14/18] refactor remote --- .../classes/sources/source-remote-ehp.php | 174 +----------------- 1 file changed, 1 insertion(+), 173 deletions(-) diff --git a/modules/template-parts/classes/sources/source-remote-ehp.php b/modules/template-parts/classes/sources/source-remote-ehp.php index 8f1102fa..f92e8513 100644 --- a/modules/template-parts/classes/sources/source-remote-ehp.php +++ b/modules/template-parts/classes/sources/source-remote-ehp.php @@ -10,7 +10,7 @@ exit; // Exit if accessed directly } -class Source_Remote_Ehp extends \Elementor\TemplateLibrary\Source_Base { +class Source_Remote_Ehp extends \Elementor\TemplateLibrary\Source_Remote { const API_TEMPLATES_URL = 'https://ba-templates.stg.elementor.red/v1/templates/'; @@ -27,152 +27,6 @@ public function get_title() { return esc_html__( 'Remote-Ehp', 'hello-plus' ); } - /** - * @inheritDoc - */ - public function register_data() {} - - /** - * @inheritDoc - */ - public function get_items( $args = [] ) { - $force_update = ! empty( $args['force_update'] ) && is_bool( $args['force_update'] ); - - $templates_data = $this->get_templates_data( $force_update ); - - $templates = []; - - foreach ( $templates_data as $template_data ) { - $templates[] = $this->prepare_template( $template_data ); - } - - return $templates; - } - - - protected function prepare_template( array $template_data ) { - $favorite_templates = $this->get_user_meta( 'favorites' ); - - // BC: Support legacy APIs that don't have access tiers. - if ( isset( $template_data['access_tier'] ) ) { - $access_tier = $template_data['access_tier']; - } else { - $access_tier = 0 === $template_data['access_level'] - ? Elementor_Connect_Module::ACCESS_TIER_FREE - : Elementor_Connect_Module::ACCESS_TIER_ESSENTIAL; - } - - return [ - 'template_id' => $template_data['id'], - 'source' => $this->get_id(), - 'type' => $template_data['type'], - 'subtype' => $template_data['subtype'], - 'title' => $template_data['title'], - 'thumbnail' => $template_data['thumbnail'], - 'date' => $template_data['tmpl_created'], - 'author' => $template_data['author'], - 'tags' => json_decode( $template_data['tags'] ), - 'isPro' => ( '1' === $template_data['is_pro'] ), - 'accessLevel' => $template_data['access_level'], - 'accessTier' => $access_tier, - 'popularityIndex' => (int) $template_data['popularity_index'], - 'trendIndex' => (int) $template_data['trend_index'], - 'hasPageSettings' => ( '1' === $template_data['has_page_settings'] ), - 'url' => $template_data['url'], - 'favorite' => ! empty( $favorite_templates[ $template_data['id'] ] ), - ]; - } - - - /** - * @inheritDoc - */ - public function get_item( $template_id ) { - $templates = $this->get_items(); - - return $templates[ $template_id ]; - } - - /** - * @inheritDoc - */ - public function save_item( $template_data ) { - return new \WP_Error( 'invalid_request', 'Cannot save template to a remote source' ); - } - - /** - * @inheritDoc - */ - public function update_item( $new_data ) { - return new \WP_Error( 'invalid_request', 'Cannot update template to a remote source' ); - } - - /** - * @inheritDoc - */ - public function delete_template( $template_id ) { - return new \WP_Error( 'invalid_request', 'Cannot delete template from a remote source' ); - } - - /** - * @inheritDoc - */ - public function get_data( array $args, $context = 'display' ) { - $data = Elementor_Api::get_template_content( $args['template_id'] ); - - if ( is_wp_error( $data ) ) { - return $data; - } - - // Set the Request's state as an Elementor upload request, in order to support unfiltered file uploads. - Utils::elementor()->uploads_manager->set_elementor_upload_state( true ); - - // BC. - $data = (array) $data; - - $data['content'] = $this->replace_elements_ids( $data['content'] ); - $data['content'] = $this->process_export_import_content( $data['content'], 'on_import' ); - - $post_id = $args['editor_post_id']; - $document = Utils::elementor()->documents->get( $post_id ); - if ( $document ) { - $data['content'] = $document->get_elements_raw_data( $data['content'], true ); - } - - // After the upload complete, set the elementor upload state back to false - Utils::elementor()->uploads_manager->set_elementor_upload_state( false ); - - return $data; - } - - protected function get_template_data_transient_key(): string { - return static::TEMPLATES_DATA_TRANSIENT_KEY_PREFIX . HELLO_PLUS_VERSION; - } - - /** - * @inheritDoc - */ - public function export_template( $template_id ) { - return new \WP_Error( 'invalid_request', 'Cannot export template from a remote source' ); - } - - /** - * @inheritDoc - */ - protected function get_templates( string $editor_layout_type ): array { - $templates_data_cache_key = $this->get_template_data_transient_key(); - - $templates_data = $this->get_templates_remotely( $editor_layout_type ); - - if ( empty( $templates_data ) ) { - return []; - } - - set_transient( $templates_data_cache_key, $templates_data, 12 * HOUR_IN_SECONDS ); - - return $templates_data; - } - /** * @inheritDoc */ @@ -184,7 +38,6 @@ protected function get_templates_remotely( string $editor_layout_type ) { 'headers' => apply_filters( 'stg-cf-headers', [] ), ] ); - error_log( print_r( $response, true ) ); if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { return false; } @@ -198,35 +51,10 @@ protected function get_templates_remotely( string $editor_layout_type ) { return $templates_data; } - protected function get_templates_body_args( string $editor_layout_type ): array { - return []; - } - protected function get_url_params( string $editor_layout_type ): array { return [ 'products' => 'ehp', 'editor_layout_type' => $editor_layout_type, ]; } - - /** - * @inheritDoc - */ - protected function get_templates_data( bool $force_update ) : array { - $templates_data_cache_key = $this->get_template_data_transient_key(); - - $editor_layout_type = 'container_flexbox'; - - if ( $force_update ) { - return $this->get_templates( $editor_layout_type ); - } - - $templates_data = get_transient( $templates_data_cache_key ); - - if ( empty( $templates_data ) ) { - return $this->get_templates( $editor_layout_type ); - } - - return $templates_data; - } } From 9f03b9035cef42eab88c4240280bc1d12e244735 Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Tue, 21 Jan 2025 13:42:39 +0100 Subject: [PATCH 15/18] refactor --- assets/dev/scss/variables/breakpoints.scss | 11 ++ assets/dev/scss/variables/index.scss | 1 + assets/dev/scss/variables/mixins.scss | 30 ++++ .../template-parts/assets/scss/editor.scss | 3 + .../_hello-plus-template-parts-preview.scss} | 0 .../assets/scss/editor/_template-modal.scss | 159 ++++++++++++++++++ modules/template-parts/module.php | 4 +- webpack.config.js | 2 +- 8 files changed, 207 insertions(+), 3 deletions(-) create mode 100644 assets/dev/scss/variables/mixins.scss create mode 100644 modules/template-parts/assets/scss/editor.scss rename modules/template-parts/assets/scss/{hello-plus-template-parts-preview.scss => editor/_hello-plus-template-parts-preview.scss} (100%) create mode 100644 modules/template-parts/assets/scss/editor/_template-modal.scss diff --git a/assets/dev/scss/variables/breakpoints.scss b/assets/dev/scss/variables/breakpoints.scss index 32c02cfa..491dde66 100644 --- a/assets/dev/scss/variables/breakpoints.scss +++ b/assets/dev/scss/variables/breakpoints.scss @@ -25,3 +25,14 @@ $screen-tablet-extra-next: -1; $screen-laptop-min: -1; $screen-laptop-max: -1; $screen-widescreen-min: -1; + +$editor-screen-xs-max: map_get($breakpoints, sm) - 1; +$editor-screen-sm-min: map_get($breakpoints, sm); +$editor-screen-sm-max: map_get($breakpoints, md) - 1; +$editor-screen-md-min: map_get($breakpoints, md); +$editor-screen-md-max: map_get($breakpoints, lg) - 1; +$editor-screen-lg-min: map_get($breakpoints, lg); +$editor-screen-lg-max: map_get($breakpoints, xl) - 1; +$editor-screen-xl-min: map_get($breakpoints, xl); +$editor-screen-xl-max: map_get($breakpoints, xxl) - 1; +$editor-screen-xxl-min: map_get($breakpoints, xxl); diff --git a/assets/dev/scss/variables/index.scss b/assets/dev/scss/variables/index.scss index 9cb23755..8c118beb 100644 --- a/assets/dev/scss/variables/index.scss +++ b/assets/dev/scss/variables/index.scss @@ -1,3 +1,4 @@ @import "./breakpoints"; @import "./values"; @import "./global-colors"; +@import "./mixins"; diff --git a/assets/dev/scss/variables/mixins.scss b/assets/dev/scss/variables/mixins.scss new file mode 100644 index 00000000..3e7d1681 --- /dev/null +++ b/assets/dev/scss/variables/mixins.scss @@ -0,0 +1,30 @@ +@mixin ellipsis { + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; +} + +@mixin absolute-center { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); +} + +@mixin start($value) { + body.rtl & { + right: $value; + } + body:not(.rtl) & { + left: $value; + } +} + +@mixin end($value) { + body.rtl & { + left: $value; + } + body:not(.rtl) & { + right: $value; + } +} diff --git a/modules/template-parts/assets/scss/editor.scss b/modules/template-parts/assets/scss/editor.scss new file mode 100644 index 00000000..dab56153 --- /dev/null +++ b/modules/template-parts/assets/scss/editor.scss @@ -0,0 +1,3 @@ +@import "../../../../assets/dev/scss/variables"; +@import 'editor/_template-modal'; +@import 'editor/_hello-plus-template-parts-preview'; diff --git a/modules/template-parts/assets/scss/hello-plus-template-parts-preview.scss b/modules/template-parts/assets/scss/editor/_hello-plus-template-parts-preview.scss similarity index 100% rename from modules/template-parts/assets/scss/hello-plus-template-parts-preview.scss rename to modules/template-parts/assets/scss/editor/_hello-plus-template-parts-preview.scss diff --git a/modules/template-parts/assets/scss/editor/_template-modal.scss b/modules/template-parts/assets/scss/editor/_template-modal.scss new file mode 100644 index 00000000..149e506b --- /dev/null +++ b/modules/template-parts/assets/scss/editor/_template-modal.scss @@ -0,0 +1,159 @@ +$remote-templates-items-space: 30px; + +.elementor-template-library-template-remote-ehp { + margin: calc( #{$remote-templates-items-space} / 2 ); + padding: 8px; + border: var(--e-a-border); + border-radius: 3px; + + &:hover { + background-color: var(--e-a-bg-hover); + + .elementor-template-library-template-name { + display: none; + } + } + + &:not(:hover) { + + .elementor-template-library-template-preview { + opacity: 0; + } + + .elementor-template-library-favorite, + .elementor-template-library-template-action { + display: none; + } + } + + &.elementor-template-library-pro-template { + + .elementor-template-library-template-body:before { + content: var( --elementor-template-library-subscription-plan-label ); + background-color: var(--e-a-color-accent); + color: var(--e-a-color-white); + position: absolute; + text-transform: uppercase; + line-height: 1; + top: 5px; + @include end(5px); + padding: 3px 5px; + font-size: 8px; + border-radius: 2px; + } + } + + // For blocks + &:not(.elementor-template-library-template-page):not(.elementor-template-library-template-lp) { + position: relative; + width: calc(33.333% - #{$remote-templates-items-space}); + overflow: hidden; + + img { + display: block; + width: 100%; + } + + .elementor-template-library-template-footer { + position: absolute; + width: 100%; + bottom: 0; + @include start(0); + padding: 10px; + background-color: var(--e-a-bg-default); + transition: transform .5s; + } + + .elementor-template-library-template-name { + display: none; + } + + &:not(:hover) { + + .elementor-template-library-template-footer { + transform: translateY(100%) + } + } + } + + .elementor-template-library-template-body { + position: relative; + } + + @media (max-width: $editor-screen-lg-min) { + + .elementor-template-library-template-body { + height: 300px; + } + } + + .elementor-template-library-template-screenshot { + height: 100%; + background-size: cover; + background-position-x: 50%; + box-shadow: inset 0px -2px 15px -6px rgba(0, 0, 0, 0.07); + } + + .elementor-template-library-template-preview { + position: absolute; + inset: 0; + background-color: rgba(0,0,0,.5); + transition: opacity .5s; + cursor: pointer; + + i { + font-size: 20px; + @include absolute-center; + } + } + + .elementor-template-library-template-footer { + display: flex; + justify-content: space-between; + font-size: 11px; + line-height: 1; + height: 40px; + align-items: center; + } + + .elementor-template-library-template-name { + text-align: start; + flex-grow: 1; + @include ellipsis; + padding-inline-end: 5px; + } + + .elementor-template-library-favorite { + margin-inline-start: auto; + } + + .elementor-template-library-template-favorite-input { + display: none; + + &:checked { + + + .elementor-template-library-template-favorite-label { + + i { + + &:before { + content: '\e93f'; + color: var(--e-a-color-primary-bold); + } + } + } + } + } + + .elementor-template-library-template-favorite-label { + font-size: 15px; + cursor: pointer; + + &:hover { + + i { + color: var(--e-a-color-primary-bold); + } + } + } +} diff --git a/modules/template-parts/module.php b/modules/template-parts/module.php index 13e74dde..4b46ebe6 100644 --- a/modules/template-parts/module.php +++ b/modules/template-parts/module.php @@ -94,8 +94,8 @@ public function enqueue_editor_scripts(): void { */ public function enqueue_editor_styles(): void { wp_enqueue_style( - 'helloplus-template-parts-preview', - HELLOPLUS_STYLE_URL . 'helloplus-template-parts-preview.css', + 'helloplus-template-parts-editor', + HELLOPLUS_STYLE_URL . 'helloplus-template-parts-editor.css', [], HELLOPLUS_VERSION ); diff --git a/webpack.config.js b/webpack.config.js index 6deee0b8..adddbcbf 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -23,7 +23,7 @@ const entryPoints = { 'js/helloplus-zigzag-fe': path.resolve( modulesDir, 'content/assets/js/frontend', 'hello-plus-zigzag-fe.js' ), // Template Parts module - 'css/helloplus-template-parts-preview': path.resolve( modulesDir, 'template-parts/assets/scss', 'hello-plus-template-parts-preview.scss' ), + 'css/helloplus-template-parts-editor': path.resolve( modulesDir, 'template-parts/assets/scss', 'editor.scss' ), 'css/helloplus-header': path.resolve( modulesDir, 'template-parts/assets/scss', 'hello-plus-header.scss' ), 'css/helloplus-footer': path.resolve( modulesDir, 'template-parts/assets/scss', 'hello-plus-footer.scss' ), 'js/helloplus-header': path.resolve( modulesDir, 'template-parts/assets/js', 'hello-plus-header.js' ), From cca1afe4ab60c6dbc60382fa8f184341f3f94b9e Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Wed, 22 Jan 2025 18:38:11 +0100 Subject: [PATCH 16/18] switch to add_filter --- modules/theme/components/theme-overrides.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/theme/components/theme-overrides.php b/modules/theme/components/theme-overrides.php index 9f7c2d72..2d92ba6c 100644 --- a/modules/theme/components/theme-overrides.php +++ b/modules/theme/components/theme-overrides.php @@ -54,6 +54,6 @@ public function __construct() { add_filter( 'hello-plus-theme/settings/hello_style', '__return_false' ); add_filter( 'hello-plus-theme/customizer/enable', Setup_Wizard::has_site_wizard_been_completed() ? '__return_false' : '__return_true' ); add_filter( 'hello-plus-theme/rest/admin-config', [ $this, 'admin_config' ] ); - add_action( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] ); + add_filter( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] ); } } From de4a60ce117f10f16bb6a7f59cc6c3482c23ede4 Mon Sep 17 00:00:00 2001 From: Nicola Peluchetti Date: Wed, 22 Jan 2025 22:49:22 +0100 Subject: [PATCH 17/18] refactor --- modules/theme/components/theme-overrides.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/theme/components/theme-overrides.php b/modules/theme/components/theme-overrides.php index 2d92ba6c..a940a327 100644 --- a/modules/theme/components/theme-overrides.php +++ b/modules/theme/components/theme-overrides.php @@ -43,7 +43,7 @@ public function admin_config( array $config ): array { } public function localize_settings( $data ) { - $data['close_modal_redirect_hello_plus'] = admin_url( 'admin.php?page=hello-biz' ); + $data['close_modal_redirect_hello_plus'] = admin_url( 'admin.php?page=' . Utils::get_theme_slug() ); return $data; } From 2f82346f7011a70da68e66696d22467325b6b7e8 Mon Sep 17 00:00:00 2001 From: Nurit Date: Thu, 23 Jan 2025 18:54:20 +0200 Subject: [PATCH 18/18] Update Elementor core dependency to v 3.27.1 --- hello-plus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hello-plus.php b/hello-plus.php index d74bf81a..bd2ee762 100644 --- a/hello-plus.php +++ b/hello-plus.php @@ -44,7 +44,7 @@ define( 'HELLOPLUS_STYLE_URL', HELLOPLUS_ASSETS_URL . 'css/' ); define( 'HELLOPLUS_IMAGES_PATH', HELLOPLUS_ASSETS_PATH . 'images/' ); define( 'HELLOPLUS_IMAGES_URL', HELLOPLUS_ASSETS_URL . 'images/' ); -define( 'HELLOPLUS_MIN_ELEMENTOR_VERSION', '3.26.4' ); +define( 'HELLOPLUS_MIN_ELEMENTOR_VERSION', '3.27.1' ); // Init the Plugin class require HELLOPLUS_PATH . '/plugin.php';