| @@ -1,252 +1,237 @@ | ||
| 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 | -class Easyel_Free_Excerpt_Widget extends \Elementor\Widget_Base { | |
| 11 | - | |
| 12 | - | |
| 13 | - public function get_name() { | |
| 14 | - return 'eel-excerpt'; | |
| 15 | - } | |
| 16 | - | |
| 17 | - public function get_title() { | |
| 18 | - return __( 'Post Excerpt', 'easy-elements' ); | |
| 19 | - } | |
| 20 | - | |
| 21 | - public function get_icon() { | |
| 22 | - return 'easyicon easyelIcon-post-excerpt'; | |
| 23 | - } | |
| 24 | - | |
| 25 | - public function get_categories() { | |
| 26 | - return [ 'easyelements_category' ]; | |
| 27 | - } | |
| 28 | - | |
| 29 | - public function get_keywords() { | |
| 30 | - return [ 'excerpt', 'content', 'link', 'text', 'post-excerpt' ]; | |
| 31 | - } | |
| 32 | - | |
| 33 | - public function get_style_depends() { | |
| 34 | - return [ | |
| 35 | - 'eel-excerpt', | |
| 36 | - ]; | |
| 37 | - } | |
| 38 | - | |
| 39 | - protected function register_controls() { | |
| 40 | - | |
| 41 | - $this->start_controls_section( | |
| 42 | - 'content_section', | |
| 43 | - [ | |
| 44 | - 'label' => esc_html__('Excerpt Settings', 'easy-elements'), | |
| 45 | - 'tab' => Controls_Manager::TAB_CONTENT, | |
| 46 | - ] | |
| 47 | - ); | |
| 48 | - | |
| 49 | - $this->add_control( | |
| 50 | - 'excerpt_length', | |
| 51 | - [ | |
| 52 | - 'label' => esc_html__('Excerpt Length', 'easy-elements'), | |
| 53 | - 'type' => Controls_Manager::NUMBER, | |
| 54 | - 'default' => 55, | |
| 55 | - ] | |
| 56 | - ); | |
| 57 | - | |
| 58 | - $this->add_control( | |
| 59 | - 'excerpt_color', | |
| 60 | - [ | |
| 61 | - 'label' => esc_html__('Excerpt Color', 'easy-elements'), | |
| 62 | - 'type' => Controls_Manager::COLOR, | |
| 63 | - 'selectors' => [ | |
| 64 | - '{{WRAPPER}} .eel-excerpt' => 'color: {{VALUE}};', | |
| 65 | - ], | |
| 66 | - ] | |
| 67 | - ); | |
| 68 | - | |
| 69 | - $this->add_group_control( | |
| 70 | - \Elementor\Group_Control_Typography::get_type(), | |
| 71 | - [ | |
| 72 | - 'name' => 'excerpt_typography', | |
| 73 | - 'selector' => '{{WRAPPER}} .eel-excerpt', | |
| 74 | - ] | |
| 75 | - ); | |
| 76 | - | |
| 77 | - // Read More Button | |
| 78 | - $this->add_control( | |
| 79 | - 'display_button', | |
| 80 | - [ | |
| 81 | - 'label' => esc_html__('Read More Enable', 'easy-elements'), | |
| 82 | - 'type' => Controls_Manager::SWITCHER, | |
| 83 | - 'label_on' => esc_html__('Show', 'easy-elements'), | |
| 84 | - 'label_off' => esc_html__('Hide', 'easy-elements'), | |
| 85 | - 'return_value' => 'yes', | |
| 86 | - 'default' => 'yes', | |
| 87 | - ] | |
| 88 | - ); | |
| 89 | - $this->add_control( | |
| 90 | - 'read_more_text', | |
| 91 | - [ | |
| 92 | - 'label' => esc_html__('Read More', 'easy-elements'), | |
| 93 | - 'type' => Controls_Manager::TEXT, | |
| 94 | - 'default' => esc_html__('Read More', 'easy-elements'), | |
| 95 | - 'condition' => [ | |
| 96 | - 'display_button' => 'yes', | |
| 97 | - ], | |
| 98 | - ] | |
| 99 | - ); | |
| 100 | - | |
| 101 | - // Start Button Style Tabs | |
| 102 | - $this->start_controls_tabs('button_style_tabs', [ | |
| 103 | - 'condition' => ['display_button' => 'yes'], | |
| 104 | - ]); | |
| 105 | - // Normal State Tab | |
| 106 | - $this->start_controls_tab( | |
| 107 | - 'button_normal_tab', | |
| 108 | - [ | |
| 109 | - 'label' => esc_html__('Normal', 'easy-elements'), | |
| 110 | - ] | |
| 111 | - ); | |
| 112 | - | |
| 113 | - $this->add_control( | |
| 114 | - 'button_color', | |
| 115 | - [ | |
| 116 | - 'label' => esc_html__('Button Color', 'easy-elements'), | |
| 117 | - 'type' => Controls_Manager::COLOR, | |
| 118 | - 'selectors' => [ | |
| 119 | - '{{WRAPPER}} .eel-excerpt-readmore' => 'color: {{VALUE}};', | |
| 120 | - ], | |
| 121 | - ] | |
| 122 | - ); | |
| 123 | - $this->add_group_control( | |
| 124 | - \Elementor\Group_Control_Background::get_type(), | |
| 125 | - [ | |
| 126 | - 'name' => 'background_buttpm', | |
| 127 | - 'types' => [ 'classic', 'gradient', 'video' ], | |
| 128 | - 'selector' => '{{WRAPPER}} .eel-excerpt-readmore', | |
| 129 | - ] | |
| 130 | - ); | |
| 131 | - $this->add_group_control( | |
| 132 | - \Elementor\Group_Control_Border::get_type(), | |
| 133 | - [ | |
| 134 | - 'name' => 'button_border', | |
| 135 | - 'selector' => '{{WRAPPER}} .eel-excerpt-readmore', | |
| 136 | - ] | |
| 137 | - ); | |
| 138 | - $this->end_controls_tab(); | |
| 139 | - | |
| 140 | - // Hover State Tab | |
| 141 | - $this->start_controls_tab( | |
| 142 | - 'button_hover_tab', | |
| 143 | - [ | |
| 144 | - 'label' => esc_html__('Hover', 'easy-elements'), | |
| 145 | - ] | |
| 146 | - ); | |
| 147 | - $this->add_control( | |
| 148 | - 'button_hover_color', | |
| 149 | - [ | |
| 150 | - 'label' => esc_html__('Button Hover Color', 'easy-elements'), | |
| 151 | - 'type' => Controls_Manager::COLOR, | |
| 152 | - 'selectors' => [ | |
| 153 | - '{{WRAPPER}} .eel-excerpt-readmore:hover' => 'color: {{VALUE}};', | |
| 154 | - ], | |
| 155 | - ] | |
| 156 | - ); | |
| 157 | - $this->add_group_control( | |
| 158 | - \Elementor\Group_Control_Background::get_type(), | |
| 159 | - [ | |
| 160 | - 'name' => 'button_hover_background', | |
| 161 | - 'types' => [ 'classic', 'gradient' ], | |
| 162 | - 'selector' => '{{WRAPPER}} .eel-excerpt-readmore:hover', | |
| 163 | - ] | |
| 164 | - ); | |
| 165 | - $this->add_group_control( | |
| 166 | - \Elementor\Group_Control_Border::get_type(), | |
| 167 | - [ | |
| 168 | - 'name' => 'button_hover_border', | |
| 169 | - 'selector' => '{{WRAPPER}} .eel-excerpt-readmore:hover', | |
| 170 | - ] | |
| 171 | - ); | |
| 172 | - $this->end_controls_tab(); | |
| 173 | - | |
| 174 | - $this->end_controls_tabs(); | |
| 175 | - | |
| 176 | - // Add Padding control for the button | |
| 177 | - $this->add_responsive_control( | |
| 178 | - 'button_padding', | |
| 179 | - [ | |
| 180 | - 'label' => esc_html__('Button Padding', 'easy-elements'), | |
| 181 | - 'type' => Controls_Manager::DIMENSIONS, | |
| 182 | - 'size_units' => [ 'px', 'em', '%' ], | |
| 183 | - 'selectors' => [ | |
| 184 | - '{{WRAPPER}} .eel-excerpt-readmore' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', | |
| 185 | - ], | |
| 186 | - 'separator' => 'before', | |
| 187 | - 'condition' => [ | |
| 188 | - 'display_button' => 'yes', | |
| 189 | - ], | |
| 190 | - ] | |
| 191 | - ); | |
| 192 | - | |
| 193 | - // Add Margin control for the button | |
| 194 | - $this->add_responsive_control( | |
| 195 | - 'button_margin', | |
| 196 | - [ | |
| 197 | - 'label' => esc_html__('Button Margin', 'easy-elements'), | |
| 198 | - 'type' => Controls_Manager::DIMENSIONS, | |
| 199 | - 'size_units' => [ 'px', 'em', '%' ], | |
| 200 | - 'selectors' => [ | |
| 201 | - '{{WRAPPER}} .eel-excerpt-readmore' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', | |
| 202 | - ], | |
| 203 | - 'condition' => [ | |
| 204 | - 'display_button' => 'yes', | |
| 205 | - ], | |
| 206 | - ] | |
| 207 | - ); | |
| 208 | - | |
| 209 | - $this->end_controls_section(); | |
| 210 | - | |
| 211 | - } | |
| 212 | - | |
| 213 | - protected function render() { | |
| 214 | - $settings = $this->get_settings_for_display(); | |
| 215 | - $excerpt_length = !empty($settings['excerpt_length']) ? intval($settings['excerpt_length']) : 55; | |
| 216 | - $read_more_text = !empty($settings['read_more_text']) ? $settings['read_more_text'] : esc_html__('Read More', 'easy-elements'); | |
| 217 | - $display_button = !isset($settings['display_button']) || $settings['display_button'] === 'yes'; | |
| 218 | - | |
| 219 | - $post_id = function_exists('easyel_get_prepared_post_id') | |
| 220 | - ? easyel_get_prepared_post_id() | |
| 221 | - : get_the_ID(); | |
| 222 | - | |
| 223 | - $post_obj = get_post( $post_id ); | |
| 224 | - if ( ! $post_obj instanceof \WP_Post ) { | |
| 225 | - echo '<p>' . esc_html__('No valid post found.', 'easy-elements') . '</p>'; | |
| 226 | - return; | |
| 227 | - } | |
| 228 | - | |
| 229 | - global $post; | |
| 230 | - $original_post = $post; | |
| 231 | - $post = $post_obj; | |
| 232 | - setup_postdata( $post ); | |
| 233 | - | |
| 234 | - $excerpt = get_the_excerpt(); | |
| 235 | - $post_url = get_permalink(); | |
| 236 | - | |
| 237 | - $excerpt = wp_trim_words( $excerpt, $excerpt_length, '...' ); | |
| 238 | - | |
| 239 | - ?> | |
| 240 | - <div class="eel-excerpt"> | |
| 241 | - <div class="eel-excerpt-text"><?php echo esc_html($excerpt); ?></div> | |
| 242 | - <?php if ( !empty($read_more_text) && $display_button ) : ?> | |
| 243 | - <a href="<?php echo esc_url($post_url); ?>" class="eel-excerpt-readmore"><?php echo esc_html($read_more_text); ?></a> | |
| 244 | - <?php endif; ?> | |
| 245 | - </div> | |
| 246 | - <?php | |
| 247 | - | |
| 248 | - wp_reset_postdata(); | |
| 249 | - $post = $original_post; | |
| 250 | - } | |
| 251 | - | |
| 252 | -} | |
| 1 | +<?php | |
| 2 | +use Elementor\Controls_Manager; | |
| 3 | +use Elementor\Widget_Base; | |
| 4 | + | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | + exit; | |
| 7 | +} | |
| 8 | + | |
| 9 | +if( class_exists("Easyel_Excerpt_Widget")) { | |
| 10 | + return; | |
| 11 | +} | |
| 12 | + | |
| 13 | +class Easyel_Excerpt_Widget extends \Elementor\Widget_Base { | |
| 14 | + | |
| 15 | + public function get_style_depends() { | |
| 16 | + $handle = 'eel-excerpt'; | |
| 17 | + $css_path = plugin_dir_path( __FILE__ ) . 'css/excerpt.css'; | |
| 18 | + | |
| 19 | + if ( ! wp_style_is( $handle, 'registered' ) && file_exists( $css_path ) ) { | |
| 20 | + wp_register_style( $handle, plugins_url( 'css/excerpt.css', __FILE__ ), [], defined( 'WP_DEBUG' ) && WP_DEBUG ? filemtime( $css_path ) : '1.0.0' ); | |
| 21 | + } | |
| 22 | + | |
| 23 | + return [ $handle ]; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public function get_name() { | |
| 27 | + return 'eel-excerpt'; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public function get_title() { | |
| 31 | + return __( 'Post Excerpt', 'easy-elements' ); | |
| 32 | + } | |
| 33 | + | |
| 34 | + public function get_icon() { | |
| 35 | + return 'easyicon easyelIcon-post-excerpt'; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public function get_categories() { | |
| 39 | + return [ 'easyelements_category_pro' ]; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public function get_keywords() { | |
| 43 | + return [ 'excerpt', 'content', 'link', 'text' ]; | |
| 44 | + } | |
| 45 | + | |
| 46 | + protected function register_controls() { | |
| 47 | + | |
| 48 | + $this->start_controls_section( | |
| 49 | + 'content_section', | |
| 50 | + [ | |
| 51 | + 'label' => esc_html__('Excerpt Settings', 'easy-elements'), | |
| 52 | + 'tab' => Controls_Manager::TAB_CONTENT, | |
| 53 | + ] | |
| 54 | + ); | |
| 55 | + | |
| 56 | + $this->add_control( | |
| 57 | + 'excerpt_length', | |
| 58 | + [ | |
| 59 | + 'label' => esc_html__('Excerpt Length', 'easy-elements'), | |
| 60 | + 'type' => Controls_Manager::NUMBER, | |
| 61 | + 'default' => 55, | |
| 62 | + ] | |
| 63 | + ); | |
| 64 | + | |
| 65 | + $this->add_control( | |
| 66 | + 'read_more_text', | |
| 67 | + [ | |
| 68 | + 'label' => esc_html__('Read More', 'easy-elements'), | |
| 69 | + 'type' => Controls_Manager::TEXT, | |
| 70 | + 'default' => esc_html__('Read More', 'easy-elements'), | |
| 71 | + ] | |
| 72 | + ); | |
| 73 | + | |
| 74 | + | |
| 75 | + $this->add_control( | |
| 76 | + 'excerpt_color', | |
| 77 | + [ | |
| 78 | + 'label' => esc_html__('Excerpt Color', 'easy-elements'), | |
| 79 | + 'type' => Controls_Manager::COLOR, | |
| 80 | + 'selectors' => [ | |
| 81 | + '{{WRAPPER}} .eel-excerpt' => 'color: {{VALUE}};', | |
| 82 | + ], | |
| 83 | + ] | |
| 84 | + ); | |
| 85 | + | |
| 86 | + $this->add_group_control( | |
| 87 | + \Elementor\Group_Control_Typography::get_type(), | |
| 88 | + [ | |
| 89 | + 'name' => 'excerpt_typography', | |
| 90 | + 'selector' => '{{WRAPPER}} .eel-excerpt', | |
| 91 | + ] | |
| 92 | + ); | |
| 93 | + | |
| 94 | + // Add Padding control for the button | |
| 95 | + $this->add_responsive_control( | |
| 96 | + 'button_padding', | |
| 97 | + [ | |
| 98 | + 'label' => esc_html__('Button Padding', 'easy-elements'), | |
| 99 | + 'type' => Controls_Manager::DIMENSIONS, | |
| 100 | + 'size_units' => [ 'px', 'em', '%' ], | |
| 101 | + 'selectors' => [ | |
| 102 | + '{{WRAPPER}} .eel-excerpt-readmore' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', | |
| 103 | + ], | |
| 104 | + ] | |
| 105 | + ); | |
| 106 | + | |
| 107 | + // Add Margin control for the button | |
| 108 | + $this->add_responsive_control( | |
| 109 | + 'button_margin', | |
| 110 | + [ | |
| 111 | + 'label' => esc_html__('Button Margin', 'easy-elements'), | |
| 112 | + 'type' => Controls_Manager::DIMENSIONS, | |
| 113 | + 'size_units' => [ 'px', 'em', '%' ], | |
| 114 | + 'selectors' => [ | |
| 115 | + '{{WRAPPER}} .eel-excerpt-readmore' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', | |
| 116 | + ], | |
| 117 | + ] | |
| 118 | + ); | |
| 119 | + | |
| 120 | + // Start Button Style Tabs | |
| 121 | + $this->start_controls_tabs('button_style_tabs'); | |
| 122 | + | |
| 123 | + // Normal State Tab | |
| 124 | + $this->start_controls_tab( | |
| 125 | + 'button_normal_tab', | |
| 126 | + [ | |
| 127 | + 'label' => esc_html__('Normal', 'easy-elements'), | |
| 128 | + ] | |
| 129 | + ); | |
| 130 | + | |
| 131 | + $this->add_control( | |
| 132 | + 'button_color', | |
| 133 | + [ | |
| 134 | + 'label' => esc_html__('Button Color', 'easy-elements'), | |
| 135 | + 'type' => Controls_Manager::COLOR, | |
| 136 | + 'selectors' => [ | |
| 137 | + '{{WRAPPER}} .eel-excerpt-readmore' => 'color: {{VALUE}};', | |
| 138 | + ], | |
| 139 | + ] | |
| 140 | + ); | |
| 141 | + $this->add_group_control( | |
| 142 | + \Elementor\Group_Control_Background::get_type(), | |
| 143 | + [ | |
| 144 | + 'name' => 'background_buttpm', | |
| 145 | + 'types' => [ 'classic', 'gradient', 'video' ], | |
| 146 | + 'selector' => '{{WRAPPER}} .eel-excerpt-readmore', | |
| 147 | + ] | |
| 148 | + ); | |
| 149 | + $this->add_group_control( | |
| 150 | + \Elementor\Group_Control_Border::get_type(), | |
| 151 | + [ | |
| 152 | + 'name' => 'button_border', | |
| 153 | + 'selector' => '{{WRAPPER}} .eel-excerpt-readmore', | |
| 154 | + ] | |
| 155 | + ); | |
| 156 | + $this->end_controls_tab(); | |
| 157 | + | |
| 158 | + // Hover State Tab | |
| 159 | + $this->start_controls_tab( | |
| 160 | + 'button_hover_tab', | |
| 161 | + [ | |
| 162 | + 'label' => esc_html__('Hover', 'easy-elements'), | |
| 163 | + ] | |
| 164 | + ); | |
| 165 | + $this->add_control( | |
| 166 | + 'button_hover_color', | |
| 167 | + [ | |
| 168 | + 'label' => esc_html__('Button Hover Color', 'easy-elements'), | |
| 169 | + 'type' => Controls_Manager::COLOR, | |
| 170 | + 'selectors' => [ | |
| 171 | + '{{WRAPPER}} .eel-excerpt-readmore:hover' => 'color: {{VALUE}};', | |
| 172 | + ], | |
| 173 | + ] | |
| 174 | + ); | |
| 175 | + $this->add_group_control( | |
| 176 | + \Elementor\Group_Control_Background::get_type(), | |
| 177 | + [ | |
| 178 | + 'name' => 'button_hover_background', | |
| 179 | + 'types' => [ 'classic', 'gradient' ], | |
| 180 | + 'selector' => '{{WRAPPER}} .eel-excerpt-readmore:hover', | |
| 181 | + ] | |
| 182 | + ); | |
| 183 | + $this->add_group_control( | |
| 184 | + \Elementor\Group_Control_Border::get_type(), | |
| 185 | + [ | |
| 186 | + 'name' => 'button_hover_border', | |
| 187 | + 'selector' => '{{WRAPPER}} .eel-excerpt-readmore:hover', | |
| 188 | + ] | |
| 189 | + ); | |
| 190 | + $this->end_controls_tab(); | |
| 191 | + | |
| 192 | + $this->end_controls_tabs(); | |
| 193 | + | |
| 194 | + $this->add_control( | |
| 195 | + 'display_button', | |
| 196 | + [ | |
| 197 | + 'label' => esc_html__('Read More Enable', 'easy-elements'), | |
| 198 | + 'type' => Controls_Manager::SWITCHER, | |
| 199 | + 'label_on' => esc_html__('Show', 'easy-elements'), | |
| 200 | + 'label_off' => esc_html__('Hide', 'easy-elements'), | |
| 201 | + 'return_value' => 'yes', | |
| 202 | + 'default' => 'yes', | |
| 203 | + ] | |
| 204 | + ); | |
| 205 | + | |
| 206 | + | |
| 207 | + $this->end_controls_section(); | |
| 208 | + | |
| 209 | + } | |
| 210 | + | |
| 211 | + protected function render() { | |
| 212 | + $settings = $this->get_settings_for_display(); | |
| 213 | + $editor_mode = ( \Elementor\Plugin::instance()->editor->is_edit_mode() ); | |
| 214 | + $excerpt_length = !empty($settings['excerpt_length']) ? intval($settings['excerpt_length']) : 55; | |
| 215 | + $read_more_text = !empty($settings['read_more_text']) ? $settings['read_more_text'] : esc_html__('Read More', 'easy-elements'); | |
| 216 | + $display_button = !isset($settings['display_button']) || $settings['display_button'] === 'yes'; | |
| 217 | + | |
| 218 | + if ( $editor_mode ) { | |
| 219 | + // Show a sample excerpt in editor mode | |
| 220 | + $excerpt = esc_html__('This is a preview of the post excerpt. The actual excerpt will appear here on the frontend.', 'easy-elements'); | |
| 221 | + $post_url = '#'; | |
| 222 | + } else { | |
| 223 | + $excerpt = get_the_excerpt(); | |
| 224 | + $post_url = get_permalink(); | |
| 225 | + } | |
| 226 | + // Trim excerpt to desired length | |
| 227 | + $excerpt = wp_trim_words( $excerpt, $excerpt_length, '...' ); | |
| 228 | + ?> | |
| 229 | + <div class="eel-excerpt"> | |
| 230 | + <div class="eel-excerpt-text"><?php echo esc_html($excerpt); ?></div> | |
| 231 | + <?php if ( !empty($read_more_text) && $display_button ) : ?> | |
| 232 | + <a href="<?php echo esc_url($post_url); ?>" class="eel-excerpt-readmore"> <?php echo esc_html($read_more_text); ?> </a> | |
| 233 | + <?php endif; ?> | |
| 234 | + </div> | |
| 235 | + <?php | |
| 236 | + } | |
| 237 | +} | |