| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -namespace Easyel\EasyElements\Widgets; | |
| 3 | 2 | use Elementor\Controls_Manager; |
| 4 | 3 | use Elementor\Widget_Base; |
| 5 | 4 | |
| 6 | 5 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -6,11 +5,25 @@ | ||
| 6 | 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | 6 | exit; |
| 8 | 7 | } |
| 9 | 8 | |
| 10 | -class Easyel_Free_Excerpt_Widget extends \Elementor\Widget_Base { | |
| 9 | +if( class_exists("Easyel_Excerpt_Widget")) { | |
| 10 | + return; | |
| 11 | +} | |
| 11 | 12 | |
| 13 | +class Easyel_Excerpt_Widget extends \Elementor\Widget_Base { | |
| 12 | 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 | + | |
| 13 | 26 | public function get_name() { |
| 14 | 27 | return 'eel-excerpt'; |
| 15 | 28 | } |
| 16 | 29 | |
| @@ -22,21 +35,15 @@ | ||
| 22 | 35 | return 'easyicon easyelIcon-post-excerpt'; |
| 23 | 36 | } |
| 24 | 37 | |
| 25 | 38 | public function get_categories() { |
| 26 | - return [ 'easyelements_category' ]; | |
| 39 | + return [ 'easyelements_category_pro' ]; | |
| 27 | 40 | } |
| 28 | 41 | |
| 29 | 42 | public function get_keywords() { |
| 30 | - return [ 'excerpt', 'content', 'link', 'text', 'post-excerpt' ]; | |
| 43 | + return [ 'excerpt', 'content', 'link', 'text' ]; | |
| 31 | 44 | } |
| 32 | 45 | |
| 33 | - public function get_style_depends() { | |
| 34 | - return [ | |
| 35 | - 'eel-excerpt', | |
| 36 | - ]; | |
| 37 | - } | |
| 38 | - | |
| 39 | 46 | protected function register_controls() { |
| 40 | 47 | |
| 41 | 48 | $this->start_controls_section( |
| 42 | 49 | 'content_section', |
| @@ -55,8 +62,18 @@ | ||
| 55 | 62 | ] |
| 56 | 63 | ); |
| 57 | 64 | |
| 58 | 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( | |
| 59 | 76 | 'excerpt_color', |
| 60 | 77 | [ |
| 61 | 78 | 'label' => esc_html__('Excerpt Color', 'easy-elements'), |
| 62 | 79 | 'type' => Controls_Manager::COLOR, |
| @@ -73,107 +90,8 @@ | ||
| 73 | 90 | 'selector' => '{{WRAPPER}} .eel-excerpt', |
| 74 | 91 | ] |
| 75 | 92 | ); |
| 76 | 93 | |
| 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 | 94 | // Add Padding control for the button |
| 177 | 95 | $this->add_responsive_control( |
| 178 | 96 | 'button_padding', |
| 179 | 97 | [ |
| @@ -182,12 +100,8 @@ | ||
| 182 | 100 | 'size_units' => [ 'px', 'em', '%' ], |
| 183 | 101 | 'selectors' => [ |
| 184 | 102 | '{{WRAPPER}} .eel-excerpt-readmore' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 185 | 103 | ], |
| 186 | - 'separator' => 'before', | |
| 187 | - 'condition' => [ | |
| 188 | - 'display_button' => 'yes', | |
| 189 | - ], | |
| 190 | 104 | ] |
| 191 | 105 | ); |
| 192 | 106 | |
| 193 | 107 | // Add Margin control for the button |
| @@ -199,13 +113,97 @@ | ||
| 199 | 113 | 'size_units' => [ 'px', 'em', '%' ], |
| 200 | 114 | 'selectors' => [ |
| 201 | 115 | '{{WRAPPER}} .eel-excerpt-readmore' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 202 | 116 | ], |
| 203 | - 'condition' => [ | |
| 204 | - 'display_button' => 'yes', | |
| 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}};', | |
| 205 | 138 | ], |
| 206 | 139 | ] |
| 207 | - ); | |
| 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 | + | |
| 208 | 206 | |
| 209 | 207 | $this->end_controls_section(); |
| 210 | 208 | |
| 211 | 209 | } |
| @@ -211,42 +209,29 @@ | ||
| 211 | 209 | } |
| 212 | 210 | |
| 213 | 211 | protected function render() { |
| 214 | 212 | $settings = $this->get_settings_for_display(); |
| 213 | + $editor_mode = ( \Elementor\Plugin::instance()->editor->is_edit_mode() ); | |
| 215 | 214 | $excerpt_length = !empty($settings['excerpt_length']) ? intval($settings['excerpt_length']) : 55; |
| 216 | 215 | $read_more_text = !empty($settings['read_more_text']) ? $settings['read_more_text'] : esc_html__('Read More', 'easy-elements'); |
| 217 | 216 | $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; | |
| 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(); | |
| 227 | 225 | } |
| 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 | - | |
| 226 | + // Trim excerpt to desired length | |
| 237 | 227 | $excerpt = wp_trim_words( $excerpt, $excerpt_length, '...' ); |
| 238 | - | |
| 239 | 228 | ?> |
| 240 | 229 | <div class="eel-excerpt"> |
| 241 | 230 | <div class="eel-excerpt-text"><?php echo esc_html($excerpt); ?></div> |
| 242 | 231 | <?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> | |
| 232 | + <a href="<?php echo esc_url($post_url); ?>" class="eel-excerpt-readmore"> <?php echo esc_html($read_more_text); ?> </a> | |
| 244 | 233 | <?php endif; ?> |
| 245 | 234 | </div> |
| 246 | 235 | <?php |
| 247 | - | |
| 248 | - wp_reset_postdata(); | |
| 249 | - $post = $original_post; | |
| 250 | 236 | } |
| 251 | - | |
| 252 | 237 | } |