PluginProbe
Hello Plus / 1.4.0
Hello Plus v1.4.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 All 30 releases
hello-plus / modules / content / classes / render / widget-flex-hero-render.php

widget-flex-hero-render.php in Hello Plus 1.4.0, at modules/content/classes/render/widget-flex-hero-render.php

171 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace HelloPlus\Modules\Content\Classes\Render;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 use Elementor\Utils;
9 use HelloPlus\Modules\Content\Widgets\Flex_Hero;
10 use HelloPlus\Classes\{
11 Ehp_Button,
12 Ehp_Image,
13 Ehp_Shapes,
14 };
15
16 class Widget_Flex_Hero_Render {
17 protected Flex_Hero $widget;
18 const LAYOUT_CLASSNAME = 'ehp-flex-hero';
19 const CTAS_CONTAINER_CLASSNAME = 'ehp-flex-hero__ctas-container';
20 const BUTTON_CLASSNAME = 'ehp-flex-hero__button';
21 const IMAGE_CLASSNAME = 'ehp-flex-hero__image';
22
23 protected array $settings;
24
25 public function __construct( Flex_Hero $widget ) {
26 $this->widget = $widget;
27 $this->settings = $widget->get_settings_for_display();
28 }
29
30 public function maybe_add_layout_responsive_classes( &$layout_classes ) {
31 $layout_image_position_mobile = $this->settings['layout_image_position_mobile'];
32 $layout_image_position_tablet = $this->settings['layout_image_position_tablet'];
33
34 if ( ! empty( $layout_image_position_mobile ) ) {
35 $layout_classes[] = 'has-image-position-sm-' . $layout_image_position_mobile;
36 }
37
38 if ( ! empty( $layout_image_position_tablet ) ) {
39 $layout_classes[] = 'has-image-position-md-' . $layout_image_position_tablet;
40 }
41 }
42
43 public function render(): void {
44 $layout_classnames = [ self::LAYOUT_CLASSNAME ];
45 $layout_full_height_controls = $this->settings['box_full_screen_height_controls'] ?? '';
46 $layout_preset = $this->settings['layout_preset'];
47 $image_stretch = $this->settings['image_stretch'];
48 $layout_image_position = $this->settings['layout_image_position'];
49 $has_border = $this->settings['show_box_border'];
50
51 if ( ! empty( $layout_full_height_controls ) ) {
52 foreach ( $layout_full_height_controls as $breakpoint ) {
53 $layout_classnames[] = 'is-full-height-' . $breakpoint;
54 }
55 }
56
57 if ( ! empty( $layout_preset ) ) {
58 $layout_classnames[] = 'has-layout-preset-' . $layout_preset;
59 }
60
61 if ( 'yes' === $image_stretch ) {
62 $layout_classnames[] = 'has-image-stretch';
63 }
64
65 if ( 'yes' === $has_border ) {
66 $layout_classnames[] = 'has-border';
67 }
68
69 if ( ! empty( $layout_image_position ) ) {
70 $layout_classnames[] = 'has-image-position-' . $layout_image_position;
71
72 // pass by reference:
73 $this->maybe_add_layout_responsive_classes( $layout_classnames );
74 }
75
76 $shapes = new Ehp_Shapes( $this->widget, [
77 'container_prefix' => 'box',
78 'render_attribute' => 'layout',
79 'widget_name' => $this->widget->get_name(),
80 ] );
81 $shapes->add_shape_attributes();
82
83 $this->widget->add_render_attribute( 'layout', [
84 'class' => $layout_classnames,
85 ] );
86 ?>
87 <div <?php $this->widget->print_render_attribute_string( 'layout' ); ?>>
88 <?php
89 $this->render_content_container();
90 $this->render_image_container();
91 ?>
92 </div>
93 <?php
94 }
95
96 public function render_content_container() {
97 ?>
98 <div class="ehp-flex-hero__overlay"></div>
99 <div class="ehp-flex-hero__content-container">
100 <?php
101 $this->render_text_container();
102 $this->render_ctas_container();
103 ?>
104 </div>
105 <?php
106 }
107
108 public function render_text_container() {
109 $this->maybe_render_text_html( 'intro_text', 'ehp-flex-hero__intro', $this->settings['intro_text'], $this->settings['intro_tag'] );
110 $this->maybe_render_text_html( 'heading_text', 'ehp-flex-hero__heading', $this->settings['heading_text'], $this->settings['heading_tag'] );
111 $this->maybe_render_text_html( 'subheading_text', 'ehp-flex-hero__subheading', $this->settings['subheading_text'], $this->settings['subheading_tag'] );
112 }
113
114 public function maybe_render_text_html( $render_key, $css_class, $settings_text, $settings_tag ) {
115 if ( '' !== $settings_text ) {
116 $this->widget->add_render_attribute( $render_key, 'class', $css_class );
117
118 $element = wp_kses_post( $settings_text );
119
120 $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 );
121
122 // PHPCS - the variable $element_html holds safe data.
123 echo $element_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
124 }
125 }
126
127 protected function render_ctas_container() {
128 $primary_cta_button_text = $this->settings['primary_cta_button_text'];
129 $secondary_cta_button_text = $this->settings['secondary_cta_button_text'];
130 $has_primary_button = ! empty( $primary_cta_button_text );
131 $has_secondary_button = ! empty( $secondary_cta_button_text );
132
133 $ctas_container_classnames = [ self::CTAS_CONTAINER_CLASSNAME ];
134
135 $this->widget->add_render_attribute( 'ctas-container', [
136 'class' => $ctas_container_classnames,
137 ] );
138 ?>
139 <div <?php $this->widget->print_render_attribute_string( 'ctas-container' ); ?>>
140 <?php if ( $has_primary_button ) {
141 $this->render_button( 'primary' );
142 } ?>
143 <?php if ( $has_secondary_button ) {
144 $this->render_button( 'secondary' );
145 } ?>
146 </div>
147 <?php
148 }
149
150 protected function render_button( $type ) {
151 $button = new Ehp_Button( $this->widget, [
152 'type' => $type,
153 'widget_name' => $this->widget->get_name(),
154 ] );
155 $button->render();
156 }
157
158 protected function render_image_container() {
159 ?>
160 <div class="ehp-flex-hero__image-wrapper">
161 <?php
162 $image = new Ehp_Image( $this->widget, [
163 'widget_name' => $this->widget->get_name(),
164 ] );
165 $image->render();
166 ?>
167 </div>
168 <?php
169 }
170 }
171