| 1 |
<?php |
| 2 |
namespace Easyel\EasyElements\Widgets; |
| 3 |
use Elementor\Controls_Manager; |
| 4 |
use Elementor\Widget_Base; |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
|
| 11 |
class Easyel_Free_Post_Title_Widget extends \Elementor\Widget_Base { |
| 12 |
|
| 13 |
public function get_name() { |
| 14 |
return 'eel-post-title'; |
| 15 |
} |
| 16 |
|
| 17 |
public function get_title() { |
| 18 |
return __( 'Post Title', 'easy-elements' ); |
| 19 |
} |
| 20 |
|
| 21 |
public function get_icon() { |
| 22 |
return 'easyicon easyelIcon-post-title'; |
| 23 |
} |
| 24 |
|
| 25 |
public function get_categories() { |
| 26 |
return [ 'easyelements_category' ]; |
| 27 |
} |
| 28 |
|
| 29 |
public function get_keywords() { |
| 30 |
return [ 'post', 'title', 'link', 'click', 'text', 'heading' ]; |
| 31 |
} |
| 32 |
|
| 33 |
public function get_style_depends() { |
| 34 |
return [ |
| 35 |
'eel-post-title', |
| 36 |
]; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
protected function register_controls() { |
| 41 |
|
| 42 |
$this->start_controls_section( |
| 43 |
'content_section', |
| 44 |
[ |
| 45 |
'label' => esc_html__('Post Title Settings', 'easy-elements'), |
| 46 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 47 |
] |
| 48 |
); |
| 49 |
|
| 50 |
$this->add_control( |
| 51 |
'title_tag', |
| 52 |
[ |
| 53 |
'label' => esc_html__('HTML Tag', 'easy-elements'), |
| 54 |
'type' => Controls_Manager::SELECT, |
| 55 |
'default' => 'h1', |
| 56 |
'options' => [ |
| 57 |
'h1' => 'H1', |
| 58 |
'h2' => 'H2', |
| 59 |
'h3' => 'H3', |
| 60 |
'h4' => 'H4', |
| 61 |
'h5' => 'H5', |
| 62 |
'h6' => 'H6', |
| 63 |
'div' => 'div', |
| 64 |
'span' => 'span', |
| 65 |
'p' => 'p', |
| 66 |
], |
| 67 |
] |
| 68 |
); |
| 69 |
|
| 70 |
$this->add_control( |
| 71 |
'link_to_post', |
| 72 |
[ |
| 73 |
'label' => esc_html__('Link to Post', 'easy-elements'), |
| 74 |
'type' => Controls_Manager::SWITCHER, |
| 75 |
'label_on' => esc_html__('Yes', 'easy-elements'), |
| 76 |
'label_off' => esc_html__('No', 'easy-elements'), |
| 77 |
'default' => '', |
| 78 |
] |
| 79 |
); |
| 80 |
|
| 81 |
$this->add_control( |
| 82 |
'align', |
| 83 |
[ |
| 84 |
'label' => esc_html__('Alignment', 'easy-elements'), |
| 85 |
'type' => Controls_Manager::CHOOSE, |
| 86 |
'options' => [ |
| 87 |
'left' => [ |
| 88 |
'title' => esc_html__('Left', 'easy-elements'), |
| 89 |
'icon' => 'eicon-text-align-left', |
| 90 |
], |
| 91 |
'center' => [ |
| 92 |
'title' => esc_html__('Center', 'easy-elements'), |
| 93 |
'icon' => 'eicon-text-align-center', |
| 94 |
], |
| 95 |
'right' => [ |
| 96 |
'title' => esc_html__('Right', 'easy-elements'), |
| 97 |
'icon' => 'eicon-text-align-right', |
| 98 |
], |
| 99 |
], |
| 100 |
'default' => 'left', |
| 101 |
'toggle' => true, |
| 102 |
] |
| 103 |
); |
| 104 |
|
| 105 |
$this->add_control( |
| 106 |
'title_color', |
| 107 |
[ |
| 108 |
'label' => esc_html__('Title Color', 'easy-elements'), |
| 109 |
'type' => Controls_Manager::COLOR, |
| 110 |
'selectors' => [ |
| 111 |
'{{WRAPPER}} .eel-post-title' => 'color: {{VALUE}};', |
| 112 |
], |
| 113 |
] |
| 114 |
); |
| 115 |
|
| 116 |
$this->add_group_control( |
| 117 |
\Elementor\Group_Control_Typography::get_type(), |
| 118 |
[ |
| 119 |
'name' => 'content_typography', |
| 120 |
'selector' => '{{WRAPPER}} .eel-post-title', |
| 121 |
] |
| 122 |
); |
| 123 |
$this->add_responsive_control( |
| 124 |
'margin', |
| 125 |
[ |
| 126 |
'label' => esc_html__('Margin', 'easy-elements'), |
| 127 |
'type' => Controls_Manager::DIMENSIONS, |
| 128 |
'size_units' => [ 'px', 'em', '%' ], |
| 129 |
'selectors' => [ |
| 130 |
'{{WRAPPER}} .eel-post-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 131 |
], |
| 132 |
] |
| 133 |
); |
| 134 |
|
| 135 |
$this->end_controls_section(); |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
protected function render() { |
| 140 |
|
| 141 |
$settings = $this->get_settings_for_display(); |
| 142 |
$tag = $settings['title_tag'] ?? 'h1'; |
| 143 |
$align = $settings['align'] ?? 'left'; |
| 144 |
$link = ! empty( $settings['link_to_post'] ); |
| 145 |
$post_id = null; |
| 146 |
$post_id = function_exists('easyel_get_prepared_post_id') |
| 147 |
? easyel_get_prepared_post_id() |
| 148 |
: null; |
| 149 |
|
| 150 |
|
| 151 |
if ( ! $post_id ) { |
| 152 |
return; |
| 153 |
} |
| 154 |
|
| 155 |
$post_obj = get_post( $post_id ); |
| 156 |
if ( ! $post_obj instanceof \WP_Post ) { |
| 157 |
return; |
| 158 |
} |
| 159 |
|
| 160 |
global $post; |
| 161 |
$original_post = $post; |
| 162 |
|
| 163 |
$post = $post_obj; |
| 164 |
setup_postdata( $post ); |
| 165 |
|
| 166 |
$title = get_the_title(); |
| 167 |
$post_url = get_permalink(); |
| 168 |
?> |
| 169 |
|
| 170 |
<<?php echo esc_attr( $tag ); ?> |
| 171 |
class="eel-post-title" |
| 172 |
style="text-align:<?php echo esc_attr( $align ); ?>;"> |
| 173 |
|
| 174 |
<?php if ( $link ) : ?> |
| 175 |
<a href="<?php echo esc_url( $post_url ); ?>"> |
| 176 |
<?php echo esc_html( $title ); ?> |
| 177 |
</a> |
| 178 |
<?php else : ?> |
| 179 |
<?php echo esc_html( $title ); ?> |
| 180 |
<?php endif; ?> |
| 181 |
|
| 182 |
</<?php echo esc_attr( $tag ); ?>> |
| 183 |
|
| 184 |
<?php |
| 185 |
|
| 186 |
$post = $original_post; |
| 187 |
wp_reset_postdata(); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
} |
| 193 |
|