File: /var/www/html/delstar/wp-content/themes/construction/inc/elementors/custom-heading.php
<?php
namespace WPCharming\Widgets;
use Elementor\Widget_Base ;
use Elementor\Controls_Manager ;
use Elementor\Utils ;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WPC_Element_Custom_Heading extends Widget_Base {
public function get_name() {
return 'wpc-custom-heading';
}
public function get_title() {
return __( 'Custom Heading', 'wpcharming' );
}
public function get_icon() {
// Icon name from the Elementor font file, as per http://dtbaker.net/web-development/creating-your-own-custom-elementor-widgets/
return 'eicon-wordpress';
}
public function get_categories() {
return [ 'wpc-elements' ];
}
protected function _register_controls() {
$this->start_controls_section(
'section_content',
[
'label' => esc_html__( 'Custom Heading', 'wpcharming' ),
]
);
$this->add_control(
'heading',
[
'label' => __( 'Heading', 'wpcharming' ),
'label_block' => true,
'type' => Controls_Manager::TEXT,
'default' => ''
]
);
$this->add_control(
'heading_color',
[
'label' => __( 'Heading Color', 'wpcharming' ),
'type' => Controls_Manager::COLOR,
'default' => ''
]
);
$this->add_control(
'colored_line',
[
'label' => __( 'Display a colored line below heading?', 'wpcharming' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => __( 'Show', 'wpcharming' ),
'label_off' => __( 'Hide', 'wpcharming' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'line_color',
[
'label' => __( 'Custom Line Color', 'wpcharming' ),
'type' => Controls_Manager::SELECT,
'default' => 'primary',
'options' => [
'primary' => __( 'Primary Color', 'wpcharming' ),
'secondary' => __( 'Secondary Color', 'wpcharming' ),
'custom' => __( 'Custom Color', 'wpcharming' ),
],
]
);
$this->add_control(
'line_custom_color',
[
'label' => __( 'Custom Line Color', 'wpcharming' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'description' => __( 'Apply when select Custom Line Color.', 'wpcharming' ),
]
);
$this->add_control(
'position',
[
'label' => __( 'Heading Position', 'wpcharming' ),
'type' => Controls_Manager::SELECT,
'default' => 'left',
'options' => [
'primary' => __( 'Left', 'wpcharming' ),
'secondary' => __( 'Right', 'wpcharming' ),
'custom' => __( 'Center', 'wpcharming' ),
],
]
);
$this->add_control(
'size',
[
'label' => __( 'Heading Size', 'wpcharming' ),
'type' => Controls_Manager::SELECT,
'default' => 'large',
'options' => [
'large' => __( 'Large', 'wpcharming' ),
'medium' => __( 'Medium', 'wpcharming' ),
'small' => __( 'Small', 'wpcharming' ),
],
]
);
$this->end_controls_section();
}
protected function render( $instance = [] ) {
$settings = $this->get_settings();
$heading = $settings['heading'];
$heading_color = $settings['heading_color'];
$colored_line = $settings['colored_line'];
$line_color = $settings['line_color'];
$line_custom_color = $settings['line_custom_color'];
$position = $settings['position'];
$size = $settings['size'];
$heading_style_color = '';
if ( $heading_color ) {
$heading_style_color = ' style="color: '. $heading_color .';"';
}
$position_class = '';
if ( $position == 'right' ) $position_class = ' text-right';
if ( $position == 'center' ) $position_class = ' text-center';
$heading_size = '';
if ( $size == 'medium' ) $heading_size = ' heading-medium';
if ( $size == 'small' ) $heading_size = ' heading-small';
$line_class = '';
$line_color_custom = '';
if ( $line_color == 'primary' ) {
$line_class = 'primary';
}
if ( $line_color == 'secondary' ) {
$line_class = 'secondary';
}
if ( $line_color == 'custom' ) {
$line_class = '';
}
if ( $line_custom_color && $line_color == 'custom' ) $line_color_custom = 'style="background-color: '. $line_custom_color .'"';
$output = null;
$output .= '
<div class="custom-heading wpb_content_element '. $heading_size . $position_class .'">';
if ( $heading ) $output .= '
<h2 class="heading-title" '. $heading_style_color .'>'. wp_kses_post($heading) .'</h2>';
if ( $colored_line ) $output .= '
<span class="heading-line '. $line_class .'"'. $line_color_custom .'></span>';
$output .= '
</div>';
echo html_entity_decode($output);
}
protected function _content_template() {}
}