<?php
/**
* Elementor Single Widget
* @package Prinox Tools
* @since 1.0.0
*/
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
class Prinox_Service extends Widget_Base {
/**
* Get widget name.
*
* Retrieve Elementor widget name.
*
* @since 1.0.0
* @access public
*
* @return string Widget name.
*/
public function get_name() {
return 'prinox-service-id';
}
/**
* Get widget title.
*
* Retrieve Elementor widget title.
*
* @since 1.0.0
* @access public
*
* @return string Widget title.
*/
public function get_title() {
return esc_html__( 'Prinox Service', 'prinox-tools' );
}
/**
* Get widget icon.
*
* Retrieve Elementor widget icon.
*
* @since 1.0.0
* @access public
*
* @return string Widget icon.
*/
public function get_icon() {
return 'mg-custom-icon';
}
/**
* Get widget categories.
*
* Retrieve the list of categories the Elementor widget belongs to.
*
* @since 1.0.0
* @access public
*
* @return array Widget categories.
*/
public function get_categories() {
return [ 'prinox_widgets' ];
}
protected function register_controls() {
$this->start_controls_section(
'prinox_slider_option',
[
'label' => esc_html__( 'Slider Option', 'prinox-tools' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$repeater = new Repeater();
$repeater->add_control(
'service_id', [
'label' => esc_html__( 'Select portfolio', 'prinox-tools' ),
'type' => Controls_Manager::SELECT,
'label_block' => true,
'options' => $this->select_param_posts(),
]
);
$repeater->add_control(
'sercice_icon', [
'label' => esc_html__( 'Service Icon', 'prinox-tools' ),
'type' => Controls_Manager::ICONS,
]
);
$this->add_control(
'services',
[
'label' => esc_html__( 'Add New Service Item', 'prinox-tools' ),
'type' => Controls_Manager::REPEATER,
'fields' => $repeater->get_controls(),
]
);
$this->add_control(
'container_width',
[
'label' => esc_html__( 'Container Width', 'plugin-name' ),
'type' => \Elementor\Controls_Manager::SLIDER,
'size_units' => [ 'px', '%' ],
'range' => [
'px' => [
'min' => 0,
'max' => 1600,
],
'%' => [
'min' => 0,
'max' => 100,
],
],
'default' => [
'unit' => 'px',
'size' => 1460,
],
'selectors' => [
'{{WRAPPER}} .auto-container' => 'max-width: {{SIZE}}{{UNIT}};',
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'service_style',
[
'label' => __( 'Service Style', 'prinox-tools' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'icon_color',
[
'label' => esc_html__( 'Icon Color', 'prinox-tools' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .service-block .icon svg path' => 'fill: {{VALUE}} ',
],
]
);
$this->add_control(
'title_h',
[
'type' => Controls_Manager::HEADING,
'label' => esc_html__( 'Title', 'prinox-tools' ),
'separator' => 'before',
]
);
$this->add_control(
'title_color',
[
'label' => esc_html__( 'Title Color', 'prinox-tools' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .service-block h6 a' => 'color: {{VALUE}} ',
],
]
);
$this->add_control(
'title_color_hover',
[
'label' => esc_html__( 'Title Hover Color', 'prinox-tools' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .service-block h6 a:hover' => 'color: {{VALUE}} ',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'label' => esc_html__( 'Title Typography', 'prinox-tools' ),
'selector' => '{{WRAPPER}} .service-block h6',
]
);
$this->add_control(
'contet_h',
[
'type' => Controls_Manager::HEADING,
'label' => esc_html__( 'Content', 'prinox-tools' ),
'separator' => 'before',
]
);
$this->add_control(
'content_color',
[
'label' => esc_html__( 'Content Color', 'prinox-tools' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .service-block .text' => 'color: {{VALUE}} ',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'content_typography',
'label' => esc_html__( 'Content Typography', 'prinox-tools' ),
'selector' => '{{WRAPPER}} .service-block .text',
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
?>
<!-- Services Section -->
<section class="services-section">
<div class="auto-container">
<div class="inner-container d-flex justify-content-between align-items-center clearfix">
<?php foreach($settings['services'] as $item):
if( $item['service_id'] ) :
?>
<!-- Service Block -->
<div class="service-block">
<div class="inner-box">
<div class="icon"><?php \Elementor\Icons_Manager::render_icon( $item['sercice_icon'], [ 'aria-hidden' => 'true' ] ); ?></div>
<h6><a href="<?php echo get_the_permalink($item['service_id']);?>"><?php echo get_the_title($item['service_id']);?></a></h6>
<div class="text"><?php echo get_the_excerpt($item['service_id']);?></div>
</div>
</div>
<?php endif; endforeach;?>
</div>
</div>
</section>
<!-- End Services Section -->
<?php
}
protected function select_param_posts() {
$args = wp_parse_args( [
'post_type' => 'prinox_service',
'numberposts' => -1,
'orderby' => 'title',
'order' => 'ASC',
] );
$query_query = get_posts( $args );
$posts = [];
if ( $query_query ) {
foreach ( $query_query as $query ) {
$posts[$query->ID] = $query->post_title;
}
}
return $posts;
}
}
Plugin::instance()->widgets_manager->register( new Prinox_Service() );