| @@ -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 | |
| 9 | +if( class_exists("Easyel_Free_Excerpt_Widget")) { | |
| 10 | + return; | |
| 11 | +} | |
| 12 | + | |
| 10 | 13 | class Easyel_Free_Excerpt_Widget extends \Elementor\Widget_Base { |
| 11 | 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 ) : EASYELEMENTS_VER ); | |
| 21 | + } | |
| 12 | 22 | |
| 23 | + return [ $handle ]; | |
| 24 | + } | |
| 25 | + | |
| 13 | 26 | public function get_name() { |
| 14 | 27 | return 'eel-excerpt'; |
| 15 | 28 | } |
| 16 | 29 | |
| @@ -22,9 +35,9 @@ | ||
| 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 | 43 | return [ 'excerpt', 'content', 'link', 'text', 'post-excerpt' ]; |
| @@ -29,14 +42,8 @@ | ||
| 29 | 42 | public function get_keywords() { |
| 30 | 43 | return [ 'excerpt', 'content', 'link', 'text', 'post-excerpt' ]; |
| 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', |
| @@ -211,42 +218,29 @@ | ||
| 211 | 218 | } |
| 212 | 219 | |
| 213 | 220 | protected function render() { |
| 214 | 221 | $settings = $this->get_settings_for_display(); |
| 222 | + $editor_mode = ( \Elementor\Plugin::instance()->editor->is_edit_mode() ); | |
| 215 | 223 | $excerpt_length = !empty($settings['excerpt_length']) ? intval($settings['excerpt_length']) : 55; |
| 216 | 224 | $read_more_text = !empty($settings['read_more_text']) ? $settings['read_more_text'] : esc_html__('Read More', 'easy-elements'); |
| 217 | 225 | $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; | |
| 226 | + | |
| 227 | + if ( $editor_mode ) { | |
| 228 | + // Show a sample excerpt in editor mode | |
| 229 | + $excerpt = esc_html__('This is a preview of the post excerpt. The actual excerpt will appear here on the frontend.', 'easy-elements'); | |
| 230 | + $post_url = '#'; | |
| 231 | + } else { | |
| 232 | + $excerpt = get_the_excerpt(); | |
| 233 | + $post_url = get_permalink(); | |
| 227 | 234 | } |
| 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 | - | |
| 235 | + // Trim excerpt to desired length | |
| 237 | 236 | $excerpt = wp_trim_words( $excerpt, $excerpt_length, '...' ); |
| 238 | - | |
| 239 | 237 | ?> |
| 240 | 238 | <div class="eel-excerpt"> |
| 241 | 239 | <div class="eel-excerpt-text"><?php echo esc_html($excerpt); ?></div> |
| 242 | 240 | <?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> | |
| 241 | + <a href="<?php echo esc_url($post_url); ?>" class="eel-excerpt-readmore"> <?php echo esc_html($read_more_text); ?> </a> | |
| 244 | 242 | <?php endif; ?> |
| 245 | 243 | </div> |
| 246 | 244 | <?php |
| 247 | - | |
| 248 | - wp_reset_postdata(); | |
| 249 | - $post = $original_post; | |
| 250 | 245 | } |
| 251 | - | |
| 252 | 246 | } |