post-list-handler.php
64 lines
| 1 | <?php |
| 2 | namespace Elementor; |
| 3 | |
| 4 | |
| 5 | class ElementsKit_Widget_Post_List_Handler extends \ElementsKit_Lite\Core\Handler_Widget{ |
| 6 | |
| 7 | public function wp_init(){ |
| 8 | // post view count based on single page visit |
| 9 | add_action( 'wp_head', array($this, 'ekit_track_post_views')); |
| 10 | } |
| 11 | |
| 12 | public function ekit_track_post_views ($post_id) { |
| 13 | if ( !is_single() ) return; |
| 14 | if ( empty ( $post_id) ) { |
| 15 | global $post; |
| 16 | $post_id = $post->ID; |
| 17 | } |
| 18 | $this->ekit_set_post_views($post_id); |
| 19 | } |
| 20 | |
| 21 | |
| 22 | public function ekit_set_post_views($postID) { |
| 23 | $count_key = 'ekit_post_views_count'; |
| 24 | $count = get_post_meta($postID, $count_key, true); |
| 25 | if($count==''){ |
| 26 | $count = 1; |
| 27 | delete_post_meta($postID, $count_key); |
| 28 | add_post_meta($postID, $count_key, '1'); |
| 29 | }else{ |
| 30 | $count++; |
| 31 | update_post_meta($postID, $count_key, $count); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | static function get_name() { |
| 36 | return 'elementskit-post-list'; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | static function get_title() { |
| 41 | return esc_html__( 'Post List', 'elementskit-lite' ); |
| 42 | } |
| 43 | |
| 44 | |
| 45 | static function get_icon() { |
| 46 | return 'ekit ekit-widget-icon ekit-post-list'; |
| 47 | } |
| 48 | |
| 49 | static function get_keywords() { |
| 50 | return ['ekit', 'list', 'post list', 'post', 'elementskit post list']; |
| 51 | } |
| 52 | |
| 53 | static function get_categories() { |
| 54 | return [ 'elementskit' ]; |
| 55 | } |
| 56 | |
| 57 | static function get_dir() { |
| 58 | return \ElementsKit_Lite::widget_dir() . 'post-list/'; |
| 59 | } |
| 60 | |
| 61 | static function get_url() { |
| 62 | return \ElementsKit_Lite::widget_url() . 'post-list/'; |
| 63 | } |
| 64 | } |