Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TMZ-290 adding basic inline editing to flex hero text elements #160

Merged
merged 6 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading