From e6e6c7f2e3d50cc5890fac7ed0aad1a83b83303a Mon Sep 17 00:00:00 2001 From: Maggie Serino <7341759+mserino@users.noreply.github.com> Date: Sun, 12 Jan 2025 09:57:48 +0100 Subject: [PATCH] Tweak: Add basic inline editing to flex hero text elements [TMZ-290](#160) --- .../render/widget-flex-hero-render.php | 40 +++++++------------ modules/content/widgets/flex-hero.php | 4 ++ 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/modules/content/classes/render/widget-flex-hero-render.php b/modules/content/classes/render/widget-flex-hero-render.php index 82165ab..f510013 100644 --- a/modules/content/classes/render/widget-flex-hero-render.php +++ b/modules/content/classes/render/widget-flex-hero-render.php @@ -111,34 +111,22 @@ public function render_content_container() { } public function render_text_container() { - $intro_text = $this->settings['intro_text']; - $intro_tag = $this->settings['intro_tag']; - $has_intro = '' !== $intro_text; + $this->maybe_render_text_html( 'intro_text', 'ehp-flex-hero__intro', $this->settings['intro_text'], $this->settings['intro_tag'] ); + $this->maybe_render_text_html( 'heading_text', 'ehp-flex-hero__heading', $this->settings['heading_text'], $this->settings['heading_tag'] ); + $this->maybe_render_text_html( 'subheading_text', 'ehp-flex-hero__subheading', $this->settings['subheading_text'], $this->settings['subheading_tag'] ); + } - $heading_text = $this->settings['heading_text']; - $heading_tag = $this->settings['heading_tag']; - $has_heading = '' !== $heading_text; + public function maybe_render_text_html( $render_key, $css_class, $settings_text, $settings_tag ) { + if ( '' !== $settings_text ) { + $this->widget->add_render_attribute( $render_key, 'class', $css_class ); - $subheading_text = $this->settings['subheading_text']; - $subheading_tag = $this->settings['subheading_tag']; - $has_subheading = '' !== $subheading_text; - ?> - %3$s', Utils::validate_html_tag( $intro_tag ), 'class="ehp-flex-hero__intro"', esc_html( $intro_text ) ); - // Escaped above - Utils::print_unescaped_internal_string( $intro_output ); - } ?> - %3$s', Utils::validate_html_tag( $heading_tag ), 'class="ehp-flex-hero__heading"', esc_html( $heading_text ) ); - // Escaped above - Utils::print_unescaped_internal_string( $heading_output ); - } ?> - %3$s', Utils::validate_html_tag( $subheading_tag ), 'class="ehp-flex-hero__subheading"', esc_html( $subheading_text ) ); - // Escaped above - Utils::print_unescaped_internal_string( $subheading_output ); - } ?> - %3$s', Utils::validate_html_tag( $settings_tag ), $this->widget->get_render_attribute_string( $render_key ), $element ); + + // PHPCS - the variable $element_html holds safe data. + echo $element_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + } } protected function render_ctas_container() { diff --git a/modules/content/widgets/flex-hero.php b/modules/content/widgets/flex-hero.php index 95b4d71..c773aca 100644 --- a/modules/content/widgets/flex-hero.php +++ b/modules/content/widgets/flex-hero.php @@ -52,6 +52,10 @@ public function get_style_depends(): array { protected function render(): void { $render_strategy = new Widget_Flex_Hero_Render( $this ); + $this->add_inline_editing_attributes( 'intro_text', 'basic' ); + $this->add_inline_editing_attributes( 'heading_text', 'basic' ); + $this->add_inline_editing_attributes( 'subheading_text', 'basic' ); + $render_strategy->render(); }