File: /mnt/data/dreamssalon-wp/wp-content/plugins/dreamsalon-widgets/widgets/class-testimonials-two.php
<?php
namespace dreamsalonelementor\Widgets;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Group_Control_Typography;
if ( ! defined( 'ABSPATH' ) ) { exit; }
class DSTestimonialsTwo extends Widget_Base {
public function get_name() { return 'dreamsalon-testimonials-two'; }
public function get_title() { return __( 'DS Testimonials 2', 'dreamsalon_elementor' ); }
public function get_icon() { return 'eicon-testimonial-carousel'; }
public function get_categories() { return [ 'dreamsalonelemetortheme' ]; }
protected function _register_controls() {
// Section header
$this->start_controls_section('section_header', [ 'label' => __( 'Section Header', 'dreamsalon_elementor' ) ]);
$this->add_control('badge_text', [
'label' => __( 'Badge Text', 'dreamsalon_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => 'Testimonials',
]);
$this->add_control('title_text', [
'label' => __( 'Title', 'dreamsalon_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => 'What Our Customers Says',
]);
$this->add_control('stitle_text', [
'label' => __( 'Title 2', 'dreamsalon_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => 'Discover top wellness consultants, read real reviews',
]);
$this->end_controls_section();
// Testimonials repeater
$this->start_controls_section('section_testimonials', [ 'label' => __( 'Testimonials', 'dreamsalon_elementor' ) ]);
$repeater = new Repeater();
$repeater->add_control('author_image', [
'label' => __( 'Author Image', 'dreamsalon_elementor' ),
'type' => Controls_Manager::MEDIA,
'default' => [ 'url' => get_template_directory_uri() . '/assets/img/users/user-03.jpg' ],
]);
$repeater->add_control('author_name', [
'label' => __( 'Author Name', 'dreamsalon_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => 'Mia Taylor',
]);
$repeater->add_control('author_country', [
'label' => __( 'Author Country', 'dreamsalon_elementor' ),
'type' => Controls_Manager::TEXT,
'default' => 'Canada',
]);
$repeater->add_control('content_text', [
'label' => __( 'Content', 'dreamsalon_elementor' ),
'type' => Controls_Manager::TEXTAREA,
'default' => 'My online yoga sessions were life-changing. I feel calmer and more energized every day.The guided meditation helped me.',
]);
$repeater->add_control('rating', [
'label' => __( 'Rating (1-5)', 'dreamsalon_elementor' ),
'type' => Controls_Manager::NUMBER,
'min' => 1,
'max' => 5,
'step' => 1,
'default' => 5,
]);
$this->add_control('items', [
'label' => __( 'Testimonials List', 'dreamsalon_elementor' ),
'type' => Controls_Manager::REPEATER,
'fields'=> $repeater->get_controls(),
'default' => [
[
'author_image' => [ 'url' => get_template_directory_uri() . '/assets/img/users/user-03.jpg' ],
'author_name' => 'Mia Taylor',
'author_country' => 'Canada',
'content_text' => 'My online yoga sessions were life-changing. I feel calmer and more energized every day.The guided meditation helped me.',
'rating' => 5,
],
[
'author_image' => [ 'url' => get_template_directory_uri() . '/assets/img/users/user-04.jpg' ],
'author_name' => 'Aiden Cooper',
'author_country' => 'Australia',
'content_text' => 'Talking to a therapist here gave me the clarity and peace I was searching for feel supported and stronger every week thanks to my counselor.',
'rating' => 5,
],
[
'author_image' => [ 'url' => get_template_directory_uri() . '/assets/img/users/user-25.jpg' ],
'author_name' => 'Stacey Adamson',
'author_country' => 'Canada',
'content_text' => 'This platform has truly been my anchor through difficult times. With every conversation, my therapist helps me feel supported.',
'rating' => 5,
],
],
'title_field' => '{{{ author_name }}}',
]);
$this->end_controls_section();
// Background images
$this->start_controls_section('section_background', [ 'label' => __( 'Background Images', 'dreamsalon_elementor' ) ]);
$this->add_control('bg_image_one', [
'label' => __( 'Background Image 1', 'dreamsalon_elementor' ),
'type' => Controls_Manager::MEDIA,
'default' => [ 'url' => get_template_directory_uri() . '/assets/img/bg/testimonial-bg-01.png' ],
]);
$this->add_control('bg_image_two', [
'label' => __( 'Background Image 2', 'dreamsalon_elementor' ),
'type' => Controls_Manager::MEDIA,
'default' => [ 'url' => get_template_directory_uri() . '/assets/img/bg/testimonial-bg-02.png' ],
]);
$this->end_controls_section();
// Style (title)
$this->start_controls_section(
'section_style',
[
'label' => __( 'Style', 'dreamsalon_elementor' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'label' => __( 'Title Typography', 'dreamsalon_elementor' ),
'selector' => '{{WRAPPER}} .testimonial-section-six .section-header h2',
]
);
$this->end_controls_section();
}
protected function render() {
$s = $this->get_settings_for_display();
$badge = ! empty( $s['badge_text'] ) ? $s['badge_text'] : '';
$title = ! empty( $s['title_text'] ) ? $s['title_text'] : '';
$stitle = isset( $s['stitle_text'] ) ? $s['stitle_text'] : '';
$items = ! empty( $s['items'] ) && is_array( $s['items'] ) ? $s['items'] : [];
$bg1 = ! empty( $s['bg_image_one']['url'] ) ? $s['bg_image_one']['url'] : '';
$bg2 = ! empty( $s['bg_image_two']['url'] ) ? $s['bg_image_two']['url'] : '';
?>
<section class="testimonial-section-six section">
<div class="container">
<div class="section-header d-flex align-items-center justify-content-between flex-wrap gap-3 wow fadeInUp" data-wow-duration="1.2s">
<div>
<?php if ( $badge ) : ?>
<span class="section-badge mb-2"><?php echo esc_html( $badge ); ?></span>
<?php endif; ?>
<?php if ( $title ) : ?>
<h2 class="mb-0 border_bottom"><?php echo esc_html( $title ); ?> <?php if ( $stitle ) : ?>
<span class="subtitle"><?php echo wp_kses_post( $stitle ); ?><span class="borderback"></span></span>
<?php endif; ?></h2>
<?php endif; ?>
</div>
<div class="d-flex align-items-center gap-2">
<button type="button" class="slick-arrow testimonial-prev"><i class="ti ti-chevron-left"></i></button>
<button type="button" class="slick-arrow testimonial-next"><i class="ti ti-chevron-right"></i></button>
</div>
</div>
<div class="testimonials-slider">
<?php if ( ! empty( $items ) ) : ?>
<?php foreach ( $items as $item ) :
$img_url = ! empty( $item['author_image']['url'] ) ? $item['author_image']['url'] : '';
$name = ! empty( $item['author_name'] ) ? $item['author_name'] : '';
$country = ! empty( $item['author_country'] ) ? $item['author_country'] : '';
$text = ! empty( $item['content_text'] ) ? $item['content_text'] : '';
$rating = isset( $item['rating'] ) ? (int) $item['rating'] : 5;
if ( $rating < 1 ) { $rating = 1; }
if ( $rating > 5 ) { $rating = 5; }
?>
<div class="testimonial-slide">
<div class="testimonial-item-four">
<div class="testimonial-user">
<?php if ( $img_url ) : ?>
<img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $name ); ?>" class="img-fluid">
<?php endif; ?>
</div>
<div>
<?php if ( $text ) : ?>
<p class="mb-4"><?php echo esc_html( $text ); ?></p>
<?php endif; ?>
<div class="rating d-flex align-items-center gap-1 mb-4">
<?php for ( $i = 1; $i <= 5; $i++ ) :
$filled = $i <= $rating;
?>
<i class="ti ti-star-filled <?php echo $filled ? 'filled' : ''; ?>"></i>
<?php endfor; ?>
</div>
<div class="d-flex align-items-center justify-content-between">
<div class="text-start">
<?php if ( $name ) : ?>
<p class="mb-1 testimonial-author"><?php echo esc_html( $name ); ?></p>
<?php endif; ?>
<?php if ( $country ) : ?>
<p class="mb-0"><?php echo esc_html( $country ); ?></p>
<?php endif; ?>
</div>
<span class="quote-icon">
<i class="ti ti-quote-filled"></i>
</span>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php if ( $bg1 ) : ?>
<img src="<?php echo esc_url( $bg1 ); ?>" alt="bg" class="img-fluid testimonial-bg-01">
<?php endif; ?>
<?php if ( $bg2 ) : ?>
<img src="<?php echo esc_url( $bg2 ); ?>" alt="bg" class="img-fluid testimonial-bg-02">
<?php endif; ?>
</div>
</section>
<?php
}
}