Skip to content

Commit

Permalink
Tweak: Add basic inline editing to flex hero text elements [TMZ-290](#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mserino authored Jan 12, 2025
1 parent 0372884 commit e6e6c7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
40 changes: 14 additions & 26 deletions modules/content/classes/render/widget-flex-hero-render.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
?>
<?php if ( $has_intro ) {
$intro_output = sprintf( '<%1$s %2$s>%3$s</%1$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 );
} ?>
<?php if ( $has_heading ) {
$heading_output = sprintf( '<%1$s %2$s>%3$s</%1$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 );
} ?>
<?php if ( $has_subheading ) {
$subheading_output = sprintf( '<%1$s %2$s>%3$s</%1$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 );
} ?>
<?php
$element = wp_kses_post( $settings_text );

$element_html = sprintf( '<%1$s %2$s>%3$s</%1$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() {
Expand Down
4 changes: 4 additions & 0 deletions modules/content/widgets/flex-hero.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit e6e6c7f

Please sign in to comment.