start_controls_section('section_content', [ 'label' => __('Guide', 'thinkrank'), ]); $this->add_control('heading', [ 'label' => __('Title', 'thinkrank'), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => __('How to …', 'thinkrank'), 'label_block' => true, ]); $this->add_control('heading_tag', [ 'label' => __('Heading tag', 'thinkrank'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'h2', 'options' => ['h2' => 'H2', 'h3' => 'H3', 'h4' => 'H4', 'p' => __('Paragraph', 'thinkrank')], ]); $this->add_control('description', [ 'label' => __('Description', 'thinkrank'), 'type' => \Elementor\Controls_Manager::TEXTAREA, ]); $repeater = new \Elementor\Repeater(); $repeater->add_control('title', [ 'label' => __('Step title', 'thinkrank'), 'type' => \Elementor\Controls_Manager::TEXT, 'label_block' => true, ]); $repeater->add_control('text', [ 'label' => __('Step description', 'thinkrank'), 'type' => \Elementor\Controls_Manager::WYSIWYG, ]); $repeater->add_control('image', [ 'label' => __('Step image', 'thinkrank'), 'type' => \Elementor\Controls_Manager::MEDIA, ]); $this->add_control('steps', [ 'label' => __('Steps', 'thinkrank'), 'type' => \Elementor\Controls_Manager::REPEATER, 'fields' => $repeater->get_controls(), 'default' => [['title' => '', 'text' => '']], 'title_field' => '{{{ title }}}', ]); $this->add_control('show_numbers', [ 'label' => __('Numbered steps', 'thinkrank'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => 'yes', ]); $this->end_controls_section(); $this->start_controls_section('section_duration', [ 'label' => __('Total time', 'thinkrank'), ]); foreach (['days' => __('Days', 'thinkrank'), 'hours' => __('Hours', 'thinkrank'), 'minutes' => __('Minutes', 'thinkrank')] as $key => $label) { $this->add_control("total_{$key}", [ 'label' => $label, 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'default' => 0, ]); } $this->end_controls_section(); $this->start_controls_section('section_schema', [ 'label' => __('Schema', 'thinkrank'), ]); $this->add_control('output_schema', [ 'label' => __('Output HowTo schema (JSON-LD)', 'thinkrank'), 'description' => __('Adds HowTo structured data for rich results.', 'thinkrank'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => 'yes', ]); $this->end_controls_section(); } protected function render(): void { $settings = $this->get_settings_for_display(); $steps = is_array($settings['steps'] ?? null) ? $settings['steps'] : []; $items = array_values(array_filter($steps, static function ($step) { return !empty($step['title']) || !empty($step['text']) || !empty($step['image']['url']); })); if (empty($items)) { return; } $heading_tag = in_array($settings['heading_tag'] ?? 'h2', ['h2', 'h3', 'h4', 'p'], true) ? $settings['heading_tag'] : 'h2'; $numbered = 'yes' === ($settings['show_numbers'] ?? 'yes'); $list_tag = $numbered ? 'ol' : 'ul'; echo '
' . esc_html($settings['description']) . '
'; } $duration = $this->format_duration($settings); if ('' !== $duration) { echo '' . esc_html__('Total time:', 'thinkrank') . ' ' . esc_html($duration) . '
'; } echo '<' . $list_tag . ' class="thinkrank-howto__steps">'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped foreach ($items as $step) { echo '