HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/dreamssalon-wp/wp-content/plugins/dreamsalon-widgets/widgets/class-testimonial.php
<?php
/**
 * DS Testimonials Widget
 *
 * @since 1.0.0
 */

namespace dreamsalonelementor\Widgets;

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Repeater;

if (!defined('ABSPATH')) {
    exit;
}

class DSTestimonials extends Widget_Base
{
    public function get_name()
    {
        return 'dreamsalon-ds-testimonials';
    }

    public function get_title()
    {
        return __('DS Testimonials', 'dreamsalon_elementor');
    }

    public function get_icon()
    {
        return 'eicon-comments';
    }

    public function get_categories()
    {
        return ['dreamsalon'];
    }

    protected function _register_controls()
    {
        $this->start_controls_section(
            'section_testimonials',
            [
                'label' => __('Testimonials', 'dreamsalon_elementor'),
                'tab'   => Controls_Manager::TAB_CONTENT,
            ]
        );

        $repeater = new Repeater();

        $repeater->add_control(
            'name',
            [
                'label'       => __('Name', 'dreamsalon_elementor'),
                'type'        => Controls_Manager::TEXT,
                'default'     => __('John Doe', 'dreamsalon_elementor'),
                'label_block' => true,
            ]
        );

        $repeater->add_control(
            'country',
            [
                'label'       => __('Country', 'dreamsalon_elementor'),
                'type'        => Controls_Manager::TEXT,
                'default'     => __('USA', 'dreamsalon_elementor'),
                'label_block' => true,
            ]
        );

        $repeater->add_control(
            'image',
            [
                'label'   => __('Image', 'dreamsalon_elementor'),
                'type'    => Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );

        $repeater->add_control(
            'text',
            [
                'label'   => __('Testimonial', 'dreamsalon_elementor'),
                'type'    => Controls_Manager::TEXTAREA,
                'default' => __('This is a sample testimonial text.', 'dreamsalon_elementor'),
            ]
        );

        $repeater->add_control(
            'rating',
            [
                'label'   => __('Rating', 'dreamsalon_elementor'),
                'type'    => Controls_Manager::SELECT,
                'default' => '5',
                'options' => [
                    '5' => '5 - Excellent',
                    '4' => '4 - Good',
                    '3' => '3 - Average',
                    '2' => '2 - Poor',
                    '1' => '1 - Bad',
                ],
            ]
        );

        $this->add_control(
            'testimonials_list',
            [
                'label'       => __('Add Testimonials', 'dreamsalon_elementor'),
                'type'        => Controls_Manager::REPEATER,
                'fields'      => $repeater->get_controls(),
                'title_field' => '{{{ name }}} ({{{ country }}})',
            ]
        );

        $this->end_controls_section();
    }

    protected function render()
    {
        $settings = $this->get_settings_for_display();
        ?>
        <div class="content ds-testimonials">
            <div class="container">
                <div class="row row-gap-4">
                    <?php
                    if (!empty($settings['testimonials_list'])) :
                        foreach ($settings['testimonials_list'] as $t) : ?>
                            <div class="col-xl-4 col-md-6 d-flex">
                                <div class="testimonial-item-five flex-fill p-3 border rounded shadow-sm bg-white">
                                    <div class="d-flex align-items-center gap-2 flex-wrap mb-3">
                                        <div class="avatar">
                                            <img src="<?php echo esc_url($t['image']['url']); ?>" alt="<?php echo esc_attr($t['name']); ?>" class="img-fluid rounded-circle" width="60" height="60">
                                        </div>
                                        <div>
                                            <p class="mb-1 fw-bold"><?php echo esc_html($t['name']); ?></p>
                                            <span class="fs-15 text-muted"><?php echo esc_html($t['country']); ?></span>
                                        </div>
                                    </div>
                                    <p class="mb-3"><?php echo esc_html($t['text']); ?></p>
                                    <div class="d-flex align-items-center gap-1">
                                        <?php for ($i = 0; $i < (int) $t['rating']; $i++) : ?>
                                            <i class="ti ti-star-filled text-warning"></i>
                                        <?php endfor; ?>
                                        <p class="ms-1 fs-14"><?php echo esc_html($t['rating']); ?>.0</p>
                                    </div>
                                </div>
                            </div>
                        <?php
                        endforeach;
                    else :
                        echo '<p class="text-center text-muted">No testimonials added yet.</p>';
                    endif;
                    ?>
                </div>
            </div>
        </div>
        <?php
    }
}