File: /home/parhudrw/roflma.it/wp-content/plugins/lesya-plugin/elementor/widgets/services-list.php
<?php
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Lesya Services List Widget.
*
* @since 1.0
*/
class Lesya_Services_List_Widget extends Widget_Base {
public function get_name() {
return 'lesya-services-list';
}
public function get_title() {
return esc_html__( 'Services List', 'lesya-plugin' );
}
public function get_icon() {
return 'eicon-parallax';
}
public function get_categories() {
return [ 'lesya-category' ];
}
/**
* Register widget controls.
*
* @since 1.0
*/
protected function register_controls() {
$this->start_controls_section(
'heading_tab',
[
'label' => esc_html__( 'Heading', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'heading',
[
'label' => esc_html__( 'Heading', 'lesya-plugin' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => __( 'Show', 'lesya-plugin' ),
'label_off' => __( 'Hide', 'lesya-plugin' ),
'return_value' => 'yes',
'default' => 'no',
]
);
$this->add_control(
'title',
[
'label' => esc_html__( 'Title', 'lesya-plugin' ),
'type' => Controls_Manager::TEXTAREA,
'placeholder' => esc_html__( 'Enter title', 'lesya-plugin' ),
'default' => esc_html__( 'Title', 'lesya-plugin' ),
'dynamic' => [
'active' => true,
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'items_tab',
[
'label' => esc_html__( 'Items', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'source',
[
'label' => esc_html__( 'Source', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'all',
'options' => [
'all' => __( 'All', 'lesya-plugin' ),
'categories' => __( 'Categories', 'lesya-plugin' ),
],
]
);
$this->add_control(
'source_categories',
[
'label' => esc_html__( 'Source', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT2,
'label_block' => true,
'multiple' => true,
'options' => $this->get_services_categories(),
'condition' => [
'source' => 'categories'
],
]
);
$this->add_control(
'limit',
[
'label' => esc_html__( 'Number of Items', 'lesya-plugin' ),
'type' => Controls_Manager::NUMBER,
'placeholder' => 8,
'default' => 8,
]
);
$this->add_control(
'sort',
[
'label' => esc_html__( 'Sorting By', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'menu_order',
'options' => [
'date' => __( 'Date', 'lesya-plugin' ),
'title' => __( 'Title', 'lesya-plugin' ),
'rand' => __( 'Random', 'lesya-plugin' ),
'menu_order' => __( 'Order', 'lesya-plugin' ),
],
]
);
$this->add_control(
'order',
[
'label' => esc_html__( 'Order', 'lesya-plugin' ),
'type' => Controls_Manager::SELECT,
'default' => 'asc',
'options' => [
'asc' => __( 'ASC', 'lesya-plugin' ),
'desc' => __( 'DESC', 'lesya-plugin' ),
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'heading_styling',
[
'label' => esc_html__( 'Heading Styling', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'title_color',
[
'label' => esc_html__( 'Title Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .category-widget .widget-title' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'label' => esc_html__( 'Title Typography', 'lesya-plugin' ),
'selector' => '{{WRAPPER}} .category-widget .widget-title',
]
);
$this->end_controls_section();
$this->start_controls_section(
'items_styling',
[
'label' => esc_html__( 'Items Styling', 'lesya-plugin' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'item_title_color',
[
'label' => esc_html__( 'Link Color', 'lesya-plugin' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .category-widget ul li a' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'item_title_typography',
'label' => esc_html__( 'Link Typography', 'lesya-plugin' ),
'selector' => '{{WRAPPER}} .category-widget ul li a',
]
);
$this->end_controls_section();
}
/**
* Render Categories List.
*
* @since 1.0
*/
protected function get_services_categories() {
$categories = [];
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'services_categories',
'pad_counts' => false
);
$services_categories = get_categories( $args );
foreach ( $services_categories as $category ) {
$categories[$category->term_id] = $category->name;
}
return $categories;
}
/**
* Render widget output on the frontend.
*
* @since 1.0
*/
protected function render() {
$settings = $this->get_settings_for_display();
$this->add_inline_editing_attributes( 'title', 'basic' );
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$page_id = get_the_ID();
if ( $settings['source'] == 'all' ) {
$cat_ids = '';
} else {
$cat_ids = $settings['source_categories'];
}
$cat_args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'DESC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'services_categories',
'pad_counts' => false,
'include' => $cat_ids
);
$pf_categories = get_categories( $cat_args );
$args = array(
'post_type' => 'services',
'post_status' => 'publish',
'orderby' => $settings['sort'],
'order' => $settings['order'],
'posts_per_page' => $settings['limit'],
'paged' => $paged
);
if( $settings['source'] == 'categories' ) {
$tax_array = array(
array(
'taxonomy' => 'services_categories',
'field' => 'id',
'terms' => $cat_ids
)
);
$args += array('tax_query' => $tax_array);
}
$q = new \WP_Query( $args );
?>
<div class="widget category-widget wow fadeInUp delay-0-2s">
<?php if ( $settings['title'] && $settings['heading'] == 'yes' ) : ?>
<h5 class="widget-title">
<span <?php echo $this->get_render_attribute_string( 'title' ); ?>>
<?php echo wp_kses_post( $settings['title'] ); ?>
</span>
</h5>
<?php endif; ?>
<?php if ( $q->have_posts() ) : ?>
<ul>
<?php while ( $q->have_posts() ) : $q->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?> <span class="fas fa-long-arrow-alt-right"></span></a></li>
<?php endwhile; wp_reset_postdata(); ?>
</ul>
<?php endif; ?>
</div>
<?php
}
}
Plugin::instance()->widgets_manager->register_widget_type( new Lesya_Services_List_Widget() );