tpg_category = RT_THE_POST_GRID_PLUGIN_SLUG . '-elements'; // Category /@dev $this->tpg_archive_category = 'tpg-block-builder-widgets'; $this->tpg_icon = 'eicon-gallery-grid tpg-grid-icon'; $this->tpg_dir = dirname( ( new ReflectionClass( $this ) )->getFileName() ); $this->tpg_pro_dir = null; $this->pro_label = null; $this->is_post_layout = null; $this->get_pro_message = null; $this->last_post_id = $this->get_last_post_id(); if ( ! rtTPG()->hasPro() ) { $this->pro_label = __( 'Pro', 'the-post-grid' ); $this->is_post_layout = ' the-post-grid-pro-needed'; $this->get_pro_message = 'Please upgrade to pro for more options'; } parent::__construct( $data, $args ); } public function get_pro_message( $message = 'more options.' ) { if ( rtTPG()->hasPro() ) { return; } return 'Please upgrade to pro for ' . esc_html( $message ); } public function get_name() { return $this->tpg_base; } public function get_title() { return $this->tpg_name; } public function get_icon() { return $this->tpg_icon; } public function get_categories() { return [ $this->tpg_category ]; } /** * * Get last post id * * @param string $post_type * @param false $all_content * * @return int */ public function get_last_post_id( $post_type = 'post' ): int { if ( is_singular( $post_type ) ) { return get_the_ID(); } global $wpdb; $cache_key = 'tpg_last_post_id'; $_post_id = get_transient( $cache_key ); if ( false === $_post_id || 'publish' !== get_post_status( $_post_id ) ) { delete_transient( $cache_key ); $_post_id = $wpdb->get_var( $wpdb->prepare( "SELECT MAX(ID) FROM {$wpdb->prefix}posts WHERE post_type = %s AND post_status = %s", $post_type, 'publish' ) ); set_transient( $cache_key, $_post_id, 12 * HOUR_IN_SECONDS ); } return absint( $_post_id ); } //post category list function tpg_category_list() { $categories = get_categories( [ 'hide_empty' => false ] ); $lists = []; foreach ( $categories as $category ) { $lists[ $category->cat_ID ] = $category->name; } return $lists; } // post tags lists. public function tpg_tag_list() { $tags = get_tags( [ 'hide_empty' => false ] ); $tag_list = []; foreach ( $tags as $tag ) { $tag_list[ $tag->slug ] = $tag->name; } return $tag_list; } // Get Custom post category:. protected function tpg_get_categories_by_slug( $cat ) { $terms = get_terms( [ 'taxonomy' => $cat, 'hide_empty' => true, ] ); $options = [ '0' => esc_html__( 'All Categories', 'the-post-grid' ) ]; if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { foreach ( $terms as $term ) { $options[ $term->slug ] = $term->name; } } return $options; } public function get_all_post_type() { $post_types = get_post_types( [], 'objects' ); $pt_list = []; foreach ( $post_types as $type ) { if ( isset( $type->rewrite->slug ) ) { $pt_list[ $type->rewrite->slug ] = $type->rewrite->name; } } return $pt_list; } public static function get_post_types() { $post_types = get_post_types( [ 'public' => true, 'show_in_nav_menus' => true, ], 'objects' ); $post_types = wp_list_pluck( $post_types, 'label', 'name' ); return array_diff_key( $post_types, [ 'elementor_library', 'attachment' ] ); } /** * Get Excluded Taxonomy * * @return string[] */ public static function get_excluded_taxonomy() { return [ 'post_format', 'nav_menu', 'link_category', 'wp_theme', 'elementor_library_type', 'elementor_library_type', 'elementor_library_category', 'product_visibility', 'product_shipping_class', ]; } /** * Get Filter markup * * @param $data * * @return string */ public function get_frontend_filter_markup( $data ) { if ( ! rtTPG()->hasPro() || ! ( $data['show_taxonomy_filter'] == 'show' || $data['show_author_filter'] == 'show' || $data['show_order_by'] == 'show' || $data['show_sort_order'] == 'show' || $data['show_search'] == 'show' ) ) { return; } $html = null; $wrapperContainer = $wrapperClass = $itemClass = $filter_btn_item_per_page = ''; if ( 'carousel' === $data['filter_btn_style'] ) { $wrapperContainer = 'swiper'; $wrapperClass = 'swiper-wrapper'; $itemClass = 'swiper-slide'; $filter_btn_mobile = isset( $data['filter_btn_item_per_page_mobile'] ) ? $data['filter_btn_item_per_page_mobile'] : 'auto'; $filter_btn_tablet = isset( $data['filter_btn_item_per_page_tablet'] ) ? $data['filter_btn_item_per_page_tablet'] : 'auto'; $filter_btn_item_per_page = "data-per-page = '{$data['filter_btn_item_per_page']}' data-per-page-mobile = '{$filter_btn_mobile}' data-per-tablet = '{$filter_btn_tablet}'"; } $html .= "