initial commit

This commit is contained in:
2024-04-29 13:12:44 +05:45
commit 34887303c5
19300 changed files with 5268802 additions and 0 deletions

View File

@ -0,0 +1,98 @@
<?php
/**
* Admin Class
*
* Handles admin side functionality of plugin
*
* @package WP Trending Post Slider and Widget
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Wtpsw_Admin {
function __construct() {
// Action to register admin menu
add_action( 'admin_menu', array( $this, 'wtpsw_register_menu' ));
// Action to register plugin settings
add_action ( 'admin_init', array( $this,'wtpsw_admin_processes' ));
}
/**
* Function to register admin menus
*
* @since 1.0.0
*/
function wtpsw_register_menu() {
// Register Setting Page
add_menu_page ( __( 'Trending Post', 'wtpsw' ), __( 'Trending Post', 'wtpsw' ), 'manage_options', 'wtpsw-settings', array( $this, 'wtpsw_settings_page' ), 'dashicons-star-filled' );
// Register How It Work Page
add_submenu_page( 'wtpsw-settings', __( 'Getting Started - WP Trending Post Slider and Widget', 'wtpsw' ), __( 'Getting Started', 'wtpsw' ), 'edit_posts', 'wtpsw-help', array( $this, 'wtpsw_designs_page' ) );
// Register plugin premium page
add_submenu_page( 'wtpsw-settings', __( 'Upgrade To Premium - Trending/Popular Post Slider and Widget', 'wtpsw' ), '<span style="color:#ff2700">'.__( 'Upgrade To Premium', 'wtpsw' ).'</span>', 'manage_options', 'wtpsw-premium', array( $this, 'wtpsw_premium_page' ));
}
/**
* Function to handle the setting page html
*
* @since 1.0.0
*/
function wtpsw_settings_page() {
include_once( WTPSW_DIR . '/includes/admin/form/wtpsw-settings.php' );
}
/**
* How It Work Page
*
* @since 1.0.0
*/
function wtpsw_designs_page() {
include_once( WTPSW_DIR . '/includes/admin/wtpsw-how-it-works.php' );
}
/**
* Upgrade to PRO Vs Free
*
* @since 1.0.0
*/
function wtpsw_premium_page() {
include_once( WTPSW_DIR . '/includes/admin/form/premium.php' );
}
/**
* Function register setings
*
* @since 1.0.0
*/
function wtpsw_admin_processes() {
// If plugin notice is dismissed
if( isset( $_GET['message'] ) && $_GET['message'] == 'wtpsw-plugin-notice' ) {
set_transient( 'wtpsw_install_notice', true, 604800 );
}
register_setting( 'wtpsw_plugin_options', 'wtpsw_options', array( $this, 'wtpsw_validate_options' ));
}
/**
* Validate Settings Options
*
* @since 1.0.0
*/
function wtpsw_validate_options( $input ){
$input['post_types'] = isset( $input['post_types'] ) ? $input['post_types'] : array();
return $input;
}
}
$wtpsw_Admin = new Wtpsw_Admin();

View File

@ -0,0 +1,137 @@
<?php
/**
* Plugin Premium Offer Page
*
* @package Trending/Popular Post Slider and Widget
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
} ?>
<div class="wrap">
<h2><span class="wtpsw-sf-blue">WP Trending Post Slider and Widget </span>Including in <span class="wtpsw-sf-blue">Essential Plugin Bundle</span></h2>
<style>
/* Table CSS */
table, th, td {border: 1px solid #d1d1d1;}
table.wpos-plugin-list{width:100%; text-align: left; border-spacing: 0; border-collapse: collapse; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; margin-bottom: 50px;}
.wpos-plugin-list th {width: 16%; background: #2271b1; color: #fff; }
.wpos-plugin-list td {vertical-align: top;}
.wpos-plugin-type { text-align: left; color: #fff; font-weight: 700; padding: 0 10px; margin: 15px 0; }
.wpos-slider-list { font-size: 14px; font-weight: 500; padding: 0 10px 0 25px; }
.wpos-slider-list li {text-align: left; font-size: 13px; list-style: disc;}
.wtpsw-sf-blue{color:#6c63ff; font-weight:bold;}
.wtpsw-sf-btn{display: inline-block; font-size: 18px; padding: 10px 25px; border-radius: 100px; background-color: #46b450; border-color: #46b450; color: #fff !important; font-weight: 600; text-decoration: none;}
.wtpsw-sf-btn-orange{ background-color: #FF1000; border-color: #FF1000 ;}
.wtpsw-sf-btn:hover,
.wtpsw-sf-btn:focus{background-color: #3fa548; border-color: #3fa548;}
.wtpsw-sf-btn-orange:hover,
.wtpsw-sf-btn-orange:focus {background-color: #D01003 ; border-color: #D01003 ;}
</style>
<div id="poststuff">
<div id="post-body" class="metabox-holder">
<div id="post-body-content">
<div style="text-align: center; background: #DCDCDC; margin: 30px 0; padding: 10px 30px 30px 30px;">
<p style="font-weight: bold !important; font-size:20px !important;"><span style="color: #50c621;">Essential Plugin Bundle</span> + Any Leading Builders (Avada / Elementor / Divi / <br>VC-WPBakery / Site Origin / Beaver) = <span style="background: #50c621;color: #fff;padding: 2px 10px;">WordPress Magic</span></p>
<h4 style="color: #333; font-size: 14px; font-weight: 700;">Over 15K+ Customers Using <span style="color: #50c621 !important;">Essential Plugin Bundle</span></h4>
<a href="<?php echo esc_url( WTPSW_PLUGIN_LINK_UPGRADE ); ?>" target="_blank" class="wtpsw-sf-btn wtpsw-sf-btn-orange"><span class="dashicons dashicons-cart"></span> View Essential Plugin Bundle</a>
</div>
<h2 style="font-size: 24px; text-align: center; color: #6c63ff;">Bundle Deal Details</h2>
<table class="wpos-plugin-list">
<thead>
<tr>
<th><h3 class="wpos-plugin-type">Image Slider</h3></th>
<th><h3 class="wpos-plugin-type">Marketing</h3></th>
<th><h3 class="wpos-plugin-type">Photo Album</h3></th>
<th><h3 class="wpos-plugin-type">Publication</h3></th>
<th><h3 class="wpos-plugin-type">Showcase</h3></th>
<th><h3 class="wpos-plugin-type">WooCommerce</h3></th>
</tr>
<tr>
<td>
<ul class="wpos-slider-list">
<li>Accordion and Accordion Slider</li>
<li>WP Slick Slider and Image Carousel</li>
<li>WP Responsive Recent Post Slider/Carousel</li>
<li>WP Logo Showcase Responsive Slider and Carousel</li>
<li>WP Featured Content and Slider</li>
<li><span style="color:#2271b1; font-weight: bold;">Trending/Popular Post Slider and Widget</span></li>
<li>Timeline and History slider</li>
<li>Meta slider and carousel with lightbox</li>
<li>Post Category Image With Grid and Slider</li>
</ul>
</td>
<td>
<ul class="wpos-slider-list">
<li>Popup Anything - A Marketing Popup and Lead Generation Conversions</li>
<li>Countdown Timer Ultimate</li>
</ul>
</td>
<td>
<ul class="wpos-slider-list">
<li>Album and Image Gallery plus Lightbox</li>
<li>Portfolio and Projects</li>
<li>Video gallery and Player</li>
</ul>
</td>
<td>
<ul class="wpos-slider-list">
<li>WP Responsive Recent Post Slider/Carousel</li>
<li>WP News and Scrolling Widgets</li>
<li>WP Blog and Widget</li>
<li>Blog Designer - Post and Widget</li>
<li><span style="color:#2271b1; font-weight: bold;">Trending/Popular Post Slider and Widget</span></li>
<li>WP Featured Content and Slider</li>
<li>Timeline and History slider</li>
<li>Testimonial Grid and Testimonial Slider plus Carousel with Rotator Widget</li>
<li>Post Ticker Ultimate</li>
<li>Post grid and filter ultimate</li>
</ul>
</td>
<td>
<ul class="wpos-slider-list">
<li>Testimonial Grid and Testimonial Slider plus Carousel with Rotator Widget</li>
<li>Team Slider and Team Grid Showcase plus Team Carousel</li>
<li>Hero Banner Ultimate</li>
<li>WP Logo Showcase Responsive Slider and Carousel</li>
</ul>
</td>
<td>
<ul class="wpos-slider-list">
<li>Product Slider and Carousel with Category for WooCommerce</li>
<li>Product Categories Designs for WooCommerce</li>
<li>Popup Anything - A Marketing Popup and Lead Generation Conversions</li>
<li>Countdown Timer Ultimate</li>
</ul>
</td>
</tr>
</thead>
</table>
<div style="text-align: center; margin-bottom:30px">
<h3 class="wtpsw-sf-blue" style="margin:0; margin-bottom:10px; font-size:24px; font-weight:bold;">Use Essential Plugin Bundle</h3>
<h1 style="font-size: 28px; font-weight: 700; letter-spacing: -1px; text-align: center; padding:0; margin-bottom: 5px;">With Your Favourite Page Builders</h1>
<span style="font-size: 14px; color: #000;">and see how Essential Plugins can help you.</span>
</div>
<div style="text-align: center;">
<img style="width: 100%; margin-bottom:30px;" src="<?php echo esc_url( WTPSW_URL ); ?>assets/images/image-upgrade.png" alt="image-upgrade" title="image-upgrade" />
<div style="font-size: 14px; margin-bottom:10px;"><span class="wtpsw-sf-blue">Trending/Popular Post Slider </span>Including in <span class="wtpsw-sf-blue">Essential Plugin Bundle</span></div>
<a href="<?php echo esc_url( WTPSW_PLUGIN_LINK_UPGRADE ); ?>" target="_blank" class="wtpsw-sf-btn wtpsw-sf-btn-orange"><span class="dashicons dashicons-cart"></span> View Essential Plugin Bundle</a>
</div>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,98 @@
<?php
/**
* Settings Page
*
* @package WP Trending Post Slider and Widget
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
$reg_post_types = wtpsw_get_post_types();
$tp_support_post_types = wtpsw_get_option( 'post_types', array() );
?>
<div class="wrap wtpsw-settings">
<h2><?php esc_html_e( 'Trending Post - Settings', 'wtpsw' ); ?></h2>
<?php
if( isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' ) {
echo '<div id="message" class="updated notice notice-success is-dismissible">
<p>'.esc_html__( "Your changes saved successfully.", "wtpsw" ).'</p>
</div>';
}
?>
<form action="options.php" method="POST" id="wtpsw-settings-form" class="wtpsw-settings-form">
<?php settings_fields( 'wtpsw_plugin_options' );
global $wtpsw_options; ?>
<div id="wtpsw-general-settings" class="post-box-container wtpsw-general-settings">
<div class="metabox-holder">
<div class="meta-box-sortables ui-sortable">
<div id="general" class="postbox">
<div class="postbox-header">
<h2 class="hndle">
<span><?php esc_html_e( 'General Settings', 'wtpsw' ); ?></span>
</h2>
</div>
<div class="inside">
<table class="form-table wtpsw-general-settings-tbl">
<tbody>
<tr>
<th scope="row">
<label for="wtpsw-post-within"><?php esc_html_e( 'Post Within', 'wtpsw' ); ?></label>
</th>
<td>
<select id="wtpsw-post-within" class="wtpsw-post-within" name="wtpsw_options[post_range]">
<option value=""><?php esc_attr_e( 'All Time', 'wtpsw' ); ?></option>
<option value="daily" <?php selected( $wtpsw_options['post_range'], 'daily' ); ?>><?php esc_html_e( 'Today', 'wtpsw' ); ?></option>
<option value="last_day" <?php selected( $wtpsw_options['post_range'], 'last_day' ); ?>><?php esc_html_e( 'Last Day', 'wtpsw' ); ?></option>
<option value="last_week" <?php selected( $wtpsw_options['post_range'], 'last_week' ); ?>><?php esc_html_e( 'Last 7 Days', 'wtpsw' ); ?></option>
<option value="last_month" <?php selected( $wtpsw_options['post_range'], 'last_month' ); ?>><?php esc_html_e( 'Last Month', 'wtpsw' ); ?></option>
</select><br/>
<span class="description"><?php esc_html_e( 'Select time range for post visibility. Note: The post published within this time range will be visible.', 'wtpsw' ); ?></span>
</td>
</tr>
<tr>
<th>
<label for="select-post-type"><?php esc_html_e( 'Select Post Types', 'wtpsw' ); ?></label>
</th>
<td>
<?php if( ! empty( $reg_post_types )) {
foreach ( $reg_post_types as $post_key => $post_label ) { ?>
<div class="ftpp-post-type-wrap">
<label>
<input type="checkbox" id="ftpp-tp-post-<?php echo esc_attr($post_key); ?>" value="<?php echo esc_attr($post_key); ?>" name="wtpsw_options[post_types][]" <?php checked( in_array( $post_key, $tp_support_post_types ), true ); ?> />
<?php echo esc_attr( $post_label ); ?>( <?php echo esc_attr__('Post Type','wtpsw').' : '.esc_attr( $post_key ); ?> )
</label>
</div>
<?php } } ?>
<span class="description"><?php esc_html_e( 'Select post type box for trending post. You can enter post type name in shortcode parameter.', 'wtpsw' ); ?></span> <br/>
</td>
</tr>
<tr>
<td colspan="2" valign="top" scope="row">
<input type="submit" id="wtpsw-settings-submit" name="wtpsw-settings-submit" class="button button-primary right" value="<?php esc_attr_e( 'Save Changes','wtpsw' ); ?>" />
</td>
</tr>
</tbody>
</table>
</div><!-- .inside -->
</div><!-- #general -->
</div><!-- .meta-box-sortables ui-sortable -->
</div><!-- .metabox-holder -->
</div><!-- #wtpsw-general-settings -->
</form><!-- end .wtpsw-settings-form -->
</div><!-- end .wtpsw-settings -->

View File

@ -0,0 +1,286 @@
<?php
/**
* Blocks Initializer
*
* @package Trending/Popular Post Slider and Widget
* @since 1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
function wtpsw_register_guten_block() {
// Block Editor Script
wp_register_script( 'wtpsw-block-js', WTPSW_URL.'assets/js/blocks.build.js', array( 'wp-blocks', 'wp-block-editor', 'wp-i18n', 'wp-element', 'wp-components' ), WTPSW_VERSION, true );
wp_localize_script( 'wtpsw-block-js', 'Wtpsw_Block', array(
'pro_demo_link' => 'https://demo.essentialplugin.com/prodemo/pro-featured-and-trending-post/',
'free_demo_link' => 'https://demo.essentialplugin.com/trending-post-demo/',
'pro_link' => WTPSW_PLUGIN_LINK_UNLOCK,
));
// Register block and explicit attributes for trending slider
register_block_type( 'wtpsw-free/trending-slider', array(
'attributes' => array(
'align' => array(
'type' => 'string',
'default' => '',
),
'className' => array(
'type' => 'string',
'default' => '',
),
'showdate' => array(
'type' => 'boolean',
'default' => true,
),
'showauthor' => array(
'type' => 'boolean',
'default' => true,
),
'show_comment_count' => array(
'type' => 'boolean',
'default' => true,
),
'hide_empty_comment_count' => array(
'type' => 'boolean',
'default' => false,
),
'showcontent' => array(
'type' => 'boolean',
'default' => false,
),
'words_limit' => array(
'type' => 'number',
'default' => 40,
),
'dots' => array(
'type' => 'string',
'default' => 'true',
),
'arrows' => array(
'type' => 'string',
'default' => 'true',
),
'autoplay' => array(
'type' => 'string',
'default' => 'true',
),
'autoplayinterval' => array(
'type' => 'number',
'default' => 3000,
),
'speed' => array(
'type' => 'number',
'default' => 300,
),
'limit' => array(
'type' => 'number',
'default' => 10,
),
'post_type' => array(
'type' => 'string',
'default' => 'post',
),
'view_by' => array(
'type' => 'string',
'default' => 'views',
),
'order' => array(
'type' => 'string',
'default' => 'desc',
),
),
'render_callback' => 'wtpsw_trending_post_slider',
));
// Register block and explicit attributes for trending carousel
register_block_type( 'wtpsw-free/trending-carousel', array(
'attributes' => array(
'align' => array(
'type' => 'string',
'default' => '',
),
'className' => array(
'type' => 'string',
'default' => '',
),
'showdate' => array(
'type' => 'boolean',
'default' => true,
),
'showauthor' => array(
'type' => 'boolean',
'default' => true,
),
'show_comment_count' => array(
'type' => 'boolean',
'default' => true,
),
'hide_empty_comment_count' => array(
'type' => 'boolean',
'default' => false,
),
'showcontent' => array(
'type' => 'boolean',
'default' => false,
),
'words_limit' => array(
'type' => 'number',
'default' => 40,
),
'slides_to_show' => array(
'type' => 'number',
'default' => 3,
),
'slides_to_scroll' => array(
'type' => 'number',
'default' => 1,
),
'dots' => array(
'type' => 'string',
'default' => 'true',
),
'arrows' => array(
'type' => 'string',
'default' => 'true',
),
'autoplay' => array(
'type' => 'string',
'default' => 'true',
),
'autoplayinterval' => array(
'type' => 'number',
'default' => 3000,
),
'speed' => array(
'type' => 'number',
'default' => 300,
),
'limit' => array(
'type' => 'number',
'default' => 10,
),
'post_type' => array(
'type' => 'string',
'default' => 'post',
),
'view_by' => array(
'type' => 'string',
'default' => 'views',
),
'order' => array(
'type' => 'string',
'default' => 'DESC',
),
),
'render_callback' => 'wtpsw_popular_post_carousel',
));
// Register block and explicit attributes for trending gridbox
register_block_type( 'wtpsw-free/trending-gridbox', array(
'attributes' => array(
'align' => array(
'type' => 'string',
'default' => '',
),
'className' => array(
'type' => 'string',
'default' => '',
),
'showdate' => array(
'type' => 'boolean',
'default' => true,
),
'showauthor' => array(
'type' => 'boolean',
'default' => true,
),
'show_comment_count' => array(
'type' => 'boolean',
'default' => true,
),
'hide_empty_comment_count' => array(
'type' => 'boolean',
'default' => false,
),
'showcontent' => array(
'type' => 'boolean',
'default' => false,
),
'words_limit' => array(
'type' => 'number',
'default' => 40,
),
'limit' => array(
'type' => 'number',
'default' => 5,
),
'post_type' => array(
'type' => 'string',
'default' => 'post',
),
'view_by' => array(
'type' => 'string',
'default' => 'views',
),
'order' => array(
'type' => 'string',
'default' => 'DESC',
),
),
'render_callback' => 'wtpsw_trending_post_gridbox',
));
if ( function_exists( 'wp_set_script_translations' ) ) {
wp_set_script_translations( 'wtpsw-block-js', 'wtpsw', WTPSW_DIR . '/languages' );
}
}
add_action( 'init', 'wtpsw_register_guten_block' );
/**
* Enqueue Gutenberg block assets for backend editor.
*
* @uses {wp-blocks} for block type registration & related functions.
* @uses {wp-element} for WP Element abstraction — structure of blocks.
* @uses {wp-i18n} to internationalize the block's text.
* @uses {wp-editor} for WP editor styles.
*
* @since 1.0
*/
function wtpsw_editor_assets() {
// Block Editor CSS
if( ! wp_style_is( 'wpos-guten-block-css', 'registered' ) ) {
wp_register_style( 'wpos-guten-block-css', WTPSW_URL.'assets/css/blocks.editor.build.css', array( 'wp-edit-blocks' ), WTPSW_VERSION );
}
// Block Editor Script
wp_enqueue_style( 'wpos-guten-block-css' );
wp_enqueue_script( 'wtpsw-block-js' );
}
add_action( 'enqueue_block_editor_assets', 'wtpsw_editor_assets' );
/**
* Adds an extra category to the block inserter
*
* @since 1.0
*/
function wtpsw_add_block_category( $categories ) {
$guten_cats = wp_list_pluck( $categories, 'slug' );
if( ! in_array( 'wpos_guten_block', $guten_cats ) ) {
$categories[] = array(
'slug' => 'wpos_guten_block',
'title' => esc_html__( 'Essential Plugin Blocks', 'wtpsw' ),
'icon' => null,
);
}
return $categories;
}
add_filter( 'block_categories_all', 'wtpsw_add_block_category' );

View File

@ -0,0 +1,163 @@
<?php
/**
* Pro Designs and Plugins Feed
*
* @package WP Trending Post Slider and Widget
* @since 1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
} ?>
<div class="wrap wtpsw-wrap">
<style type="text/css">
.wpos-pro-box .hndle{background-color:#0073AA; color:#fff;}
.wpos-pro-box .postbox{background:#dbf0fa none repeat scroll 0 0; border:1px solid #0073aa; color:#191e23;}
.postbox-container .wpos-list li:before{font-family: dashicons; content: "\f139"; font-size:20px; color: #0073aa; vertical-align: middle;}
.wtpsw-wrap .wpos-button-full{display:block; text-align:center; box-shadow:none; border-radius:0;}
.wtpsw-shortcode-preview{background-color: #e7e7e7; font-weight: bold; padding: 2px 5px; display: inline-block; margin:0 0 2px 0;}
.upgrade-to-pro{font-size:18px; text-align:center; margin-bottom:15px;}
.wpos-copy-clipboard{-webkit-touch-callout: all; -webkit-user-select: all; -khtml-user-select: all; -moz-user-select: all; -ms-user-select: all; user-select: all;}
.wpos-new-feature{ font-size: 10px; margin-left:2px; color: #fff; font-weight: bold; background-color: #03aa29; padding:1px 4px; font-style: normal; }
.button-orange{background: #ff2700 !important;border-color: #ff2700 !important; font-weight: 600;}
</style>
<h2><?php esc_html_e( 'How It Works', 'wtpsw' ); ?></h2>
<div class="post-box-container">
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<!--How it workd HTML -->
<div id="post-body-content">
<div class="metabox-holder">
<div class="meta-box-sortables">
<div class="postbox">
<div class="postbox-header">
<h2 class="hndle">
<span><?php esc_html_e( 'Need Support & Solutions?', 'wtpsw' ); ?></span>
</h2>
</div>
<div class="inside">
<p><?php esc_html_e('Boost design and best solution for your website.', 'wtpsw'); ?></p>
<a class="button button-primary button-orange" href="<?php echo esc_url( WTPSW_PLUGIN_LINK_UNLOCK ); ?>" target="_blank"><?php esc_html_e( 'Grab Now', 'wtpsw' ); ?></a>
</div><!-- .inside -->
</div><!-- #general -->
<div class="postbox">
<div class="postbox-header">
<h2 class="hndle">
<span><?php esc_html_e( 'How It Works - Display and Shortcode', 'wtpsw' ); ?></span>
</h2>
</div>
<div class="inside">
<table class="form-table">
<tr>
<th>
<label><?php esc_html_e( 'Getting Started', 'wtpsw' ); ?></label>
</th>
<td>
<p><?php esc_html_e( 'Trending Post display most visited post on your website. It works with WordPress default post type.', 'wtpsw' ); ?></p>
</td>
</tr>
<tr>
<th>
<label><?php esc_html_e( 'All Shortcodes', 'wtpsw' ); ?></label>
</th>
<td>
<span class="wpos-copy-clipboard wtpsw-shortcode-preview">[wtpsw_popular_post]</span> <?php esc_html_e( 'Trending Post Slider View', 'wtpsw' ); ?><br />
<span class="wpos-copy-clipboard wtpsw-shortcode-preview">[wtpsw_carousel]</span> <?php esc_html_e( 'Trending Post Carousel View', 'wtpsw' ); ?><br />
<span class="wpos-copy-clipboard wtpsw-shortcode-preview">[wtpsw_gridbox]</span> <?php esc_html_e( 'Trending Post Gridbox View', 'wtpsw'); ?>
<br/><br/>
</td>
</tr>
<tr>
<th>
<label><?php esc_html_e('Documentation', 'wtpsw'); ?>:</label>
</th>
<td>
<a class="button button-primary" href="https://docs.essentialplugin.com/trending-popular-post-slider-and-widget/" target="_blank"><?php esc_html_e('Check Documentation', 'wtpsw'); ?></a>
</td>
</tr>
</table>
</div>
</div>
<div class="postbox">
<div class="postbox-header">
<h2 class="hndle">
<span><?php esc_html_e( 'Gutenberg Support', 'wp-testimonial-with-widget' ); ?></span>
</h2>
</div>
<div class="inside">
<table class="form-table">
<tbody>
<tr>
<th>
<label><?php esc_html_e( 'How it Work', 'wp-testimonial-with-widget' ); ?>:</label>
</th>
<td>
<ul>
<li><?php esc_html_e( 'Step-1. Go to the Gutenberg editor of your page.', 'wp-testimonial-with-widget' ); ?></li>
<li><?php esc_html_e( 'Step-2. Search "testimonial" keyword in the gutenberg block list.', 'wp-testimonial-with-widget' ); ?></li>
<li><?php esc_html_e( 'Step-3. Add any block of testimonial and you will find its relative options on the right end side.', 'wp-testimonial-with-widget' ); ?></li>
</ul>
</td>
</tr>
</tbody>
</table>
</div><!-- .inside -->
</div><!-- #general -->
<div class="postbox">
<div class="postbox-header">
<h2 class="hndle">
<span><?php esc_html_e( 'Help to improve this plugin!', 'wtpsw' ); ?></span>
</h2>
</div>
<div class="inside">
<p><?php esc_html_e('Enjoyed this plugin? You can help by rate this plugin', 'wtpsw'); ?> <a href="https://wordpress.org/support/plugin/wp-trending-post-slider-and-widget/reviews#new-post" target="_blank"><?php esc_html_e('5 stars!', 'wtpsw'); ?></a></p>
</div><!-- .inside -->
</div><!-- #general -->
</div>
</div>
</div>
<!--Upgrad to Pro HTML -->
<div id="postbox-container-1" class="postbox-container">
<div class="metabox-holder wpos-pro-box">
<div class="meta-box-sortables">
<div class="postbox">
<h3 class="hndle">
<span><?php esc_html_e( 'Upgrate to Pro', 'wtpsw' ); ?></span>
</h3>
<div class="inside">
<ul class="wpos-list">
<li>40+ stunning and cool designs for Grid, slider, carousel and gridbox</li>
<li>8 shortcodes</li>
<li>Visual Composer Page Builder Support</li>
<li>6 different types of widgets</li>
<li>Custom post type support</li>
<li>Gutenberg Block Supports.</li>
<li>WPBakery Page Builder Supports</li>
<li>Elementor, Beaver and SiteOrigin Page Builder Support. <span class="wpos-new-feature">New</span></li>
<li>Divi Page Builder Native Support. <span class="wpos-new-feature">New</span></li>
<li>Fusion Page Builder (Avada) native support.<span class="wpos-new-feature">New</span></li>
<li>WP Templating Features</li>
<li>Display Desired post include and exclude </li>
<li>Display posts with include categories and exclude categories</li>
<li>Display posts with particular include author and exclude author</li>
<li>Custom CSS</li>
<li>100% Multi language</li>
</ul>
<div class="upgrade-to-pro">Gain access to <strong>WP Trending Post Slider and Widget</strong> included in <br /><strong>Essential Plugin Bundle</div>
<a class="button button-primary wpos-button-full button-orange" href="<?php echo esc_url(WTPSW_PLUGIN_LINK_UNLOCK); ?>" target="_blank"><?php esc_html_e( 'Grab Now', 'wtpsw' ); ?></a>
</div><!-- .inside -->
</div><!-- #general -->
</div><!-- .meta-box-sortables -->
</div><!-- .metabox-holder -->
</div><!-- #post-container-1 -->
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,152 @@
<?php
/**
* Model Class
*
* Handles query related functionality of plugin
*
* @package WP Trending Post Slider and Widget
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Wtpsw_Model {
function __construct(){
}
/**
* Function to get post data
*
* @since 1.0.0
*/
function wtpsw_get_posts( $args = array() ) {
// Taking defaults
$result_data = array();
$postsargs['post_status'] = array( 'publish' );
$postsargs['post_type'] = ! empty( $args['post_type'] ) ? $args['post_type'] : 'post';
$postsargs['posts_per_page'] = ! empty( $args['posts_per_page'] ) ? $args['posts_per_page'] : -1;
// Order by records
$postsargs['order'] = ! empty( $args['order'] ) ? $args['order'] : 'DESC';
$postsargs['orderby'] = ! empty( $args['orderby'] ) ? $args['orderby'] : 'date';
// Meta key
if( isset( $args['meta_key'] ) && ! empty( $args['meta_key'] )) {
$postsargs['meta_key'] = $args['meta_key'];
}
// Per page records
if( isset( $args['paged'] ) && ! empty( $args['paged'] )) {
$postsargs['paged'] = $args['paged'];
}
// Meta query
if( isset( $args['meta_query'] ) && ! empty( $args['meta_query'] )) {
$postsargs['meta_query'] = $args['meta_query'];
}
// Taxonomy query
if( isset( $args['tax_query'] ) && ! empty( $args['tax_query'] )) {
$postsargs['tax_query'] = $args['tax_query'];
}
// Date query
if( isset( $args['date_query'] ) && ! empty( $args['date_query'] )) {
$postsargs['date_query'] = $args['date_query'];
}
// Run WP Query
$result = new WP_Query( $postsargs );
// If only want to get count
if( isset( $args['getcount'] ) && $args['getcount'] == '1' ) {
$result_data = $result->post_count;
} elseif ( isset( $args['list_data'] ) && ! empty( $args['list_data'] )) { // Data with post and count in array format
// Converting retrived post data to array
$result_data = wtpsw_object_to_array( $result->posts );
// Fetch data with count
if( isset( $args['list_data'] ) && ! empty( $args['list_data'] ) ) {
$data_res = array();
$data_res['data'] = $result_data;
// To get total count of post
$data_res['total'] = isset( $result->found_posts ) ? $result->found_posts : '';
// Assigning it in to returned array
$result_data = $data_res;
}
} else { // Simply pass whole query
$result_data = $result;
}
return $result_data;
}
/**
* Function to modify query where
*
* @since 1.0.0
*/
function wtpsw_query_where( $where = '' ) {
global $wpdb, $wtpsw_options, $wtpsw_view_by;
$current_date = current_time( 'timestamp' );
$post_range = isset( $wtpsw_options['post_range'] ) ? $wtpsw_options['post_range'] : '';
switch ( $post_range ) {
case 'daily':
$start_date = date( 'Y-m-d', $current_date );
$where_con = " AND DATE($wpdb->posts.post_date) = '{$start_date}' ";
break;
case 'last_day':
$start_date = date( 'Y-m-d', strtotime( '-1 days', $current_date ) );
$where_con = " AND DATE($wpdb->posts.post_date) = '{$start_date}' ";
break;
case 'last_week':
$start_date = date( 'Y-m-d', strtotime( '-7 days', $current_date ) );
$end_date = date( 'Y-m-d', $current_date );
$where_con = " AND DATE($wpdb->posts.post_date) > '{$start_date}' AND DATE($wpdb->posts.post_date) <= '{$end_date}'";
break;
case 'last_month':
$start_date = date( 'Y-m-d', strtotime( '-1 months', $current_date ) );
$end_date = date( 'Y-m-d', $current_date );
$where_con = " AND DATE($wpdb->posts.post_date) >= '{$start_date}' AND DATE($wpdb->posts.post_date) <= '{$end_date}'";
break;
default:
$where_con = '';
break;
}
// Append where condition
if( isset( $where_con )) {
$where .= $where_con;
}
if( ! empty( $wtpsw_view_by ) && $wtpsw_view_by == 'comment_count' ) {
$where .= " AND $wpdb->posts.comment_count > 0";
}
return $where;
}
}
$wtpsw_model = new Wtpsw_Model();

View File

@ -0,0 +1,53 @@
<?php
/**
* Public Class
*
* Handles the public side functionality of plugin
*
* @package WP Trending Post Slider and Widget
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Wtpsw_Public {
function __construct(){
// Ajax call to update post count
add_action( 'wp_ajax_wtpsw_post_view_count', array( $this, 'wtpsw_post_view_count' ));
add_action( 'wp_ajax_nopriv_wtpsw_post_view_count',array( $this, 'wtpsw_post_view_count' ));
}
/**
* Function to update views of post
*
* @since 1.0.0
*/
function wtpsw_post_view_count(){
$prefix = WTPSW_META_PREFIX;
$post_id = isset( $_POST['post_id'] ) ? esc_attr( $_POST['post_id'] ) : '';
$nonce = ! empty( $_POST['nonce'] ) ? esc_attr( $_POST['nonce'] ) : '';
if( ! empty( $post_id ) && wp_verify_nonce( $nonce, 'wtpsw-post-view-count-data' )) {
// Getting existing views
$views = get_post_meta( $post_id, $prefix.'views', true );
$views = ! empty( $views ) ? $views : 0;
// Update new views
update_post_meta( $post_id, $prefix.'views', ($views+1) );
echo 'Success';
} else {
echo 'Error - Reference Id not found.';
}
die();
}
}
$wtpsw_public = new Wtpsw_Public();

View File

@ -0,0 +1,169 @@
<?php
/**
* Script Class
*
* Handles the script and style functionality of plugin
*
* @package WP Trending Post Slider and Widget
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Wtpsw_Script {
function __construct() {
// Action to add script at admin side
add_action( 'admin_enqueue_scripts', array( $this, 'wtpsw_admin_script' ) );
// Action to add style on frontend
add_action( 'wp_enqueue_scripts', array( $this, 'wtpsw_front_end_style_script' ) );
// Action to add admin script and style when edit with elementor at admin side
add_action( 'elementor/editor/after_enqueue_scripts', array( $this, 'wtpsw_admin_builder_script_style' ) );
// Action to add admin script and style when edit with SiteOrigin at admin side
add_action( 'siteorigin_panel_enqueue_admin_scripts', array( $this, 'wtpsw_admin_builder_script_style' ), 10, 2 );
}
/**
* Function to register admin scripts and styles
*
* @since 1.5
*/
function wtpsw_register_admin_assets() {
/* Styles */
wp_register_style( 'wtpsw-admin-css', WTPSW_URL.'assets/css/wtpsw-admin.css', array(), WTPSW_VERSION );
/* Scripts */
wp_register_script( 'wtpsw-admin-script', WTPSW_URL.'assets/js/wtpsw-admin.js', array( 'jquery' ), WTPSW_VERSION, true );
}
/**
* Function to add script at admin side
*
* @since 1.4
*/
function wtpsw_admin_script( $hook ) {
$this->wtpsw_register_admin_assets();
if( $hook == 'trending-post_page_wtpsw-help' ) {
wp_enqueue_script( 'wtpsw-admin-script' );
}
}
/**
* Enqueue front styles
*
* @since 1.0.0
*/
function wtpsw_front_end_style_script() {
global $post;
// Determine Elementor Preview Screen
// Check elementor preview is there
$elementor_preview = ( defined('ELEMENTOR_PLUGIN_BASE') && isset( $_GET['elementor-preview'] ) && $post->ID == (int) $_GET['elementor-preview'] ) ? 1 : 0;
// Taking post id to update post view count
$post_id = isset( $post->ID ) ? $post->ID : '';
$post_view_count = 0;
$supported_posts = wtpsw_get_option( 'post_types', array() ); // suppoterd post type
if( ! empty( $post_id ) && !is_preview() && ! empty( $supported_posts ) && is_singular( $supported_posts ) && !is_front_page() && !is_home() && !is_feed() && !is_robots() ) {
$post_view_count = $post_id;
}
/* Styles */
// Registring and enqueing slick slider css
if( ! wp_style_is( 'wpos-slick-style', 'registered' ) ) {
wp_register_style( 'wpos-slick-style', WTPSW_URL.'assets/css/slick.css', array(), WTPSW_VERSION );
wp_enqueue_style('wpos-slick-style');
}
// Registring slider style
wp_register_style( 'wtpsw-public-style', WTPSW_URL.'assets/css/wtpsw-public.css', array(), WTPSW_VERSION );
wp_enqueue_style( 'wtpsw-public-style' );
/* Scripts */
// Registring slider script
if( !wp_script_is( 'wpos-slick-jquery', 'registered' ) ) {
wp_register_script( 'wpos-slick-jquery', WTPSW_URL.'assets/js/slick.min.js', array( 'jquery' ), WTPSW_VERSION, true );
}
// Register Elementor script
wp_register_script( 'wtpsw-elementor-js', WTPSW_URL.'assets/js/elementor/wtpsw-elementor.js', array( 'jquery' ), WTPSW_VERSION, true );
// Registering Public Script (Slider Script)
wp_register_script( 'wtpsw-public-script', WTPSW_URL.'assets/js/wtpsw-public.js', array( 'jquery' ), WTPSW_VERSION, true );
wp_localize_script( 'wtpsw-public-script', 'Wtpsw', array(
'elementor_preview' => $elementor_preview,
'ajaxurl' => admin_url( 'admin-ajax.php', ( is_ssl() ? 'https' : 'http' ) ),
'is_mobile' => ( wp_is_mobile() ) ? 1 : 0,
'is_avada' => ( class_exists( 'FusionBuilder' ) ) ? 1 : 0,
'is_rtl' => ( is_rtl() ) ? 1 : 0,
'post_view_count' => $post_view_count,
'data_nonce' => wp_create_nonce( 'wtpsw-post-view-count-data' ),
));
wp_enqueue_script( 'wtpsw-public-script' );
// Enqueue Script for Elementor Preview
if ( defined('ELEMENTOR_PLUGIN_BASE') && isset( $_GET['elementor-preview'] ) && $post->ID == (int) $_GET['elementor-preview'] ) {
// Dequeue public script
wp_dequeue_script( 'wtpsw-public-script' );
wp_enqueue_script( 'wpos-slick-jquery' );
wp_enqueue_script( 'wtpsw-public-script' );
wp_enqueue_script( 'wtpsw-elementor-js' );
}
// Enqueue Style & Script for Beaver Builder
if ( class_exists( 'FLBuilderModel' ) && FLBuilderModel::is_builder_active() ) {
$this->wtpsw_register_admin_assets();
// Dequeue admin style
wp_enqueue_style( 'wtpsw-admin-css' );
wp_enqueue_script( 'wtpsw-admin-script' );
// Dequeue public script
wp_dequeue_script( 'wtpsw-public-script' );
wp_enqueue_script( 'wpos-slick-jquery' );
wp_enqueue_script( 'wtpsw-public-script' );
}
// Enqueue Admin Style & Script for Divi Page Builder
if( function_exists( 'et_core_is_fb_enabled' ) && isset( $_GET['et_fb'] ) && $_GET['et_fb'] == 1 ) {
$this->wtpsw_register_admin_assets();
wp_enqueue_style( 'wtpsw-admin-css' );
}
// Enqueue Admin Style for Fusion Page Builder
if( class_exists( 'FusionBuilder' ) && (( isset( $_GET['builder'] ) && $_GET['builder'] == 'true' ) ) ) {
$this->wtpsw_register_admin_assets();
wp_enqueue_style( 'wtpsw-admin-css' );
}
}
/**
* Function to add script at admin side
*
* @since 1.5
*/
function wtpsw_admin_builder_script_style() {
$this->wtpsw_register_admin_assets();
wp_enqueue_style( 'wtpsw-admin-css' );
wp_enqueue_script( 'wtpsw-admin-script' );
}
}
$wtpsw_script = new Wtpsw_Script();

View File

@ -0,0 +1,158 @@
<?php
/**
* 'wtpsw_carousel' Shortcode
*
* @package WP Trending Post Slider and Widget
* @since 1.5
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Handles Popuplar Post Gridbox
*
* @since 1.5
*/
function wtpsw_popular_post_carousel( $atts, $content = null ) {
// SiteOrigin Page Builder Gutenberg Block Tweak - Do not Display Preview
if( isset( $_POST['action'] ) && ( $_POST['action'] == 'so_panels_layout_block_preview' || $_POST['action'] == 'so_panels_builder_content_json' ) ) {
return '[wtpsw_carousel]';
}
// Divi Frontend Builder - Do not Display Preview
if( function_exists( 'et_core_is_fb_enabled' ) && isset( $_POST['is_fb_preview'] ) && isset( $_POST['shortcode'] ) ) {
return '<div class="wtpsw-builder-shrt-prev">
<div class="wtpsw-builder-shrt-title"><span>'.esc_html__('Trending Post Slider - Shortcode', 'wtpsw').'</span></div>
wtpsw_carousel
</div>';
}
// Fusion Builder Live Editor - Do not Display Preview
if( class_exists( 'FusionBuilder' ) && (( isset( $_GET['builder'] ) && $_GET['builder'] == 'true' ) || ( isset( $_POST['action'] ) && $_POST['action'] == 'get_shortcode_render' )) ) {
return '<div class="wtpsw-builder-shrt-prev">
<div class="wtpsw-builder-shrt-title"><span>'.esc_html__('Trending Post slider - Shortcode', 'wtpsw').'</span></div>
wtpsw_carousel
</div>';
}
global $wtpsw_options, $wtpsw_model, $wtpsw_view_by, $post;
// Enqueue required script
wp_dequeue_script( 'wtpsw-public-script' );
wp_enqueue_script( 'wpos-slick-jquery' );
wp_enqueue_script( 'wtpsw-public-script' );
// Shortcode attributes
extract( shortcode_atts( array(
'limit' => 10,
'post_type' => 'post',
'view_by' => 'views',
'order' => 'DESC',
'design' => 'design-1',
'showdate' => 'true',
'showauthor' => 'true',
'showcontent' => 'false',
'words_limit' => 40,
'slides_to_show' => 3,
'slides_to_scroll' => 1,
'dots' => 'true',
'arrows' => 'true',
'speed' => 300,
'autoplay' => 'true',
'autoplayinterval' => 3000,
'show_comment_count' => 'true',
'hide_empty_comment_count' => 'false',
'className' => '',
'align' => '',
'extra_class' => '',
), $atts, 'wtpsw_carousel' ) );
$prefix = WTPSW_META_PREFIX;
$supported_post_types = wtpsw_get_option( 'post_types', array() );
$unique = wtpsw_get_unique();
$limit = ( ! empty( $limit ) && is_numeric( $limit ) ) ? $limit : 10;
$post_type = ( ! empty( $post_type ) && in_array( $post_type, $supported_post_types ) ) ? $post_type : '';
$view_by = ! empty( $view_by ) ? $view_by : 'views';
$order = ( strtolower($order ) == 'asc' ) ? 'ASC' : 'DESC';
$slides_to_show = ! empty( $slides_to_show ) ? $slides_to_show : 3;
$slides_to_scroll = ! empty( $slides_to_scroll ) ? $slides_to_scroll : 1;
$speed = ! empty( $speed ) ? $speed : 300;
$autoplayinterval = ! empty( $autoplayinterval ) ? $autoplayinterval : 3000;
$hide_empty_comment_count = ( $hide_empty_comment_count == 'true' ) ? true : false;
$align = ! empty( $align ) ? 'align'.$align : '';
$extra_class = $extra_class .' '. $align .' '. $className;
$extra_class = wtpsw_sanitize_html_classes( $extra_class );
// If no valid post type is found
if(empty($post_type) ) {
return $content;
}
// Slider configuration
$slider_conf = compact( 'dots', 'arrows', 'autoplay', 'autoplayinterval', 'speed', 'slides_to_show', 'slides_to_scroll' );
// Order By
if( $view_by == 'comment' ){
$orderby = 'comment_count';
} elseif ( $view_by == 'views' ) {
$orderby = 'meta_value_num';
}
$wtpsw_view_by = $orderby; // Assign to global variable for query filter
$post_args = array(
'post_type' => $post_type,
'posts_per_page' => $limit,
'order' => $order,
'orderby' => $orderby
);
if( $view_by == 'views' ) {
$post_args['meta_key'] = $prefix.'views';
}
// Wrps class variables
$main_wrap = "wtpsw-post-carousel-{$unique}";
$main_wrap .= " {$design}";
$main_wrap .= " {$extra_class}";
// Filter to change query where condition
add_filter( 'posts_where', array( $wtpsw_model, 'wtpsw_query_where' ) );
// Query to get post
$wtpsw_posts = $wtpsw_model->wtpsw_get_posts( $post_args );
// Remove Filter for change query where condition
remove_filter( 'posts_where', array( $wtpsw_model, 'wtpsw_query_where' ) );
ob_start();
if( $wtpsw_posts->have_posts() ) : ?>
<div id="wtpsw-carousel-<?php echo esc_attr($unique); ?>" class="wtpsw-post-carousel wtpsw-post-slider-init <?php echo esc_attr($main_wrap); ?>" data-conf="<?php echo htmlspecialchars(json_encode($slider_conf)); ?>">
<?php while ($wtpsw_posts->have_posts()) : $wtpsw_posts->the_post();
global $post;
$wtpsw_post_stats = array();
$post_id = isset($post->ID) ? $post->ID : '';
$comment_text = wtpsw_get_comments_number( $post->ID, $hide_empty_comment_count );
// Design file
include( WTPSW_DIR . '/templates/carousel/design-1.php' );
endwhile; ?>
</div>
<?php
endif;
wp_reset_postdata(); // Reset WP Query
$content .= ob_get_clean();
return $content;
}
// Trending popular post carousel shortcode
add_shortcode( 'wtpsw_carousel', 'wtpsw_popular_post_carousel' );

View File

@ -0,0 +1,144 @@
<?php
/**
* 'wtpsw_gridbox' Shortcode
*
* @package WP Trending Post Slider and Widget
* @since 1.5
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Handles Popuplar Post Gridbox
*
* @since 1.5
*/
function wtpsw_trending_post_gridbox( $atts, $content = null ) {
// SiteOrigin Page Builder Gutenberg Block Tweak - Do not Display Preview
if( isset( $_POST['action'] ) && ( $_POST['action'] == 'so_panels_layout_block_preview' || $_POST['action'] == 'so_panels_builder_content_json' ) ) {
return '[wtpsw_gridbox]';
}
// Divi Frontend Builder - Do not Display Preview
if( function_exists( 'et_core_is_fb_enabled' ) && isset( $_POST['is_fb_preview'] ) && isset( $_POST['shortcode'] ) ) {
return '<div class="wtpsw-builder-shrt-prev">
<div class="wtpsw-builder-shrt-title"><span>'.esc_html__( 'Trending Post Slider - Shortcode', 'wtpsw' ).'</span></div>
wtpsw_gridbox
</div>';
}
// Fusion Builder Live Editor - Do not Display Preview
if( class_exists( 'FusionBuilder' ) && (( isset( $_GET['builder'] ) && $_GET['builder'] == 'true' ) || ( isset( $_POST['action'] ) && $_POST['action'] == 'get_shortcode_render' )) ) {
return '<div class="wtpsw-builder-shrt-prev">
<div class="wtpsw-builder-shrt-title"><span>'.esc_html__( 'Trending Post slider - Shortcode', 'wtpsw' ).'</span></div>
wtpsw_gridbox
</div>';
}
global $wtpsw_options, $wtpsw_model, $wtpsw_view_by, $post;
// Enqueue required script
wp_enqueue_script('wpos-slick-jquery');
// Shortcode attributes
extract( shortcode_atts( array(
'limit' => 5,
'post_type' => 'post',
'view_by' => 'views',
'order' => 'DESC',
'design' => 'design-1',
'showdate' => 'true',
'showauthor' => 'true',
'showcontent' => 'false',
'words_limit' => 40,
'show_comment_count' => 'true',
'hide_empty_comment_count' => 'false',
'className' => '',
'align' => '',
'extra_class' => '',
), $atts, 'wtpsw_gridbox' ) );
$prefix = WTPSW_META_PREFIX;
$supported_post_types = wtpsw_get_option( 'post_types', array() );
$post_type = ( ! empty( $post_type ) && in_array( $post_type, $supported_post_types ) ) ? $post_type : '';
$limit = ( ! empty( $limit ) && is_numeric( $limit ) ) ? $limit : 10;
$view_by = ! empty( $view_by ) ? $view_by : 'views';
$order = ( strtolower($order ) == 'asc' ) ? 'ASC' : 'DESC';
$hide_empty_comment_count = ( $hide_empty_comment_count == 'true' ) ? true : false;
$align = ! empty( $align ) ? 'align'.$align : '';
$extra_class = $extra_class .' '. $align .' '. $className;
$extra_class = wtpsw_sanitize_html_classes( $extra_class );
// If no valid post type is found
if( empty( $post_type )) {
return $content;
}
// Count variables
$wtpsw_count = 1;
// Order By
if( $view_by == 'comment' ) {
$orderby = 'comment_count';
} elseif ( $view_by == 'views' ) {
$orderby = 'meta_value_num';
}
$wtpsw_view_by = $orderby; // Assign to global variable for query filter
$post_args = array(
'post_type' => $post_type,
'posts_per_page' => $limit,
'order' => $order,
'orderby' => $orderby
);
if( $view_by == 'views' ) {
$post_args['meta_key'] = $prefix.'views';
}
// Wrps class variables
$main_wrap = "{$design}";
$main_wrap .= " {$extra_class}";
// Filter to change query where condition
add_filter( 'posts_where', array( $wtpsw_model, 'wtpsw_query_where' ) );
// Query to get post
$wtpsw_posts = $wtpsw_model->wtpsw_get_posts( $post_args );
// Remove Filter for change query where condition
remove_filter( 'posts_where', array( $wtpsw_model, 'wtpsw_query_where' ) );
ob_start();
if( $wtpsw_posts->have_posts() ) : ?>
<div class="wtpsw-post-grid <?php echo esc_attr($main_wrap); ?> wtpsw-clearfix">
<?php while ($wtpsw_posts->have_posts()) : $wtpsw_posts->the_post();
global $post;
$wtpsw_post_stats = array();
$post_id = isset($post->ID) ? $post->ID : '';
$comment_text = wtpsw_get_comments_number( $post->ID, $hide_empty_comment_count );
// Design file
include( WTPSW_DIR . '/templates/grid-box/design-1.php' );
$wtpsw_count++;
endwhile; ?>
</div>
<?php
endif;
wp_reset_postdata();
$content .= ob_get_clean();
return $content;
}
// Trending popular post gridbox shortcode
add_shortcode( 'wtpsw_gridbox', 'wtpsw_trending_post_gridbox' );

View File

@ -0,0 +1,154 @@
<?php
/**
* 'wtpsw_popular_post' Shortcode
*
* @package WP Trending Post Slider and Widget
* @since 1.5
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Handles Popuplar Post Gridbox
*
* @since 1.5
*/
function wtpsw_trending_post_slider( $atts, $content = null ) {
// SiteOrigin Page Builder Gutenberg Block Tweak - Do not Display Preview
if( isset( $_POST['action'] ) && ( $_POST['action'] == 'so_panels_layout_block_preview' || $_POST['action'] == 'so_panels_builder_content_json' ) ) {
return '[wtpsw_popular_post]';
}
// Divi Frontend Builder - Do not Display Preview
if( function_exists( 'et_core_is_fb_enabled' ) && isset( $_POST['is_fb_preview'] ) && isset( $_POST['shortcode'] ) ) {
return '<div class="wtpsw-builder-shrt-prev">
<div class="wtpsw-builder-shrt-title"><span>'.esc_html__( 'Trending Post Slider - Shortcode', 'wtpsw' ).'</span></div>
wtpsw_popular_post
</div>';
}
// Fusion Builder Live Editor - Do not Display Preview
if( class_exists( 'FusionBuilder' ) && (( isset( $_GET['builder'] ) && $_GET['builder'] == 'true' ) || ( isset( $_POST['action'] ) && $_POST['action'] == 'get_shortcode_render' )) ) {
return '<div class="wtpsw-builder-shrt-prev">
<div class="wtpsw-builder-shrt-title"><span>'.esc_html__( 'Trending Post slider - Shortcode', 'wtpsw' ).'</span></div>
wtpsw_popular_post
</div>';
}
global $wtpsw_options, $wtpsw_model, $wtpsw_view_by, $post;
// Enqueue required script
wp_dequeue_script( 'wtpsw-public-script' );
wp_enqueue_script( 'wpos-slick-jquery' );
wp_enqueue_script( 'wtpsw-public-script' );
// Shortcode attributes
extract( shortcode_atts( array(
'limit' => 10,
'post_type' => 'post',
'view_by' => 'views',
'order' => 'DESC',
'design' => 'design-1',
'showdate' => 'true',
'showauthor' => 'true',
'showcontent' => 'true',
'words_limit' => 40,
'dots' => 'true',
'arrows' => 'true',
'speed' => 300,
'autoplay' => 'true',
'autoplayinterval' => 3000,
'show_comment_count' => 'true',
'hide_empty_comment_count' => 'false',
'className' => '',
'align' => '',
'extra_class' => '',
), $atts, 'wtpsw_popular_post' ) );
$prefix = WTPSW_META_PREFIX;
$unique = wtpsw_get_unique();
$supported_post_types = wtpsw_get_option( 'post_types', array() );
$post_type = ( ! empty( $post_type ) && in_array( $post_type, $supported_post_types ) ) ? $post_type : '';
$limit = ( ! empty( $limit ) && is_numeric( $limit ) ) ? $limit : 10;
$view_by = ! empty( $view_by ) ? $view_by : 'views';
$speed = ! empty( $speed ) ? $speed : 300;
$autoplayinterval = ! empty( $autoplayinterval ) ? $autoplayinterval : 3000;
$order = ( strtolower($order ) == 'asc' ) ? 'ASC' : 'DESC';
$hide_empty_comment_count = ( $hide_empty_comment_count == 'true' ) ? true : false;
$align = ! empty( $align ) ? 'align'.$align : '';
$extra_class = $extra_class .' '. $align .' '. $className;
$extra_class = wtpsw_sanitize_html_classes( $extra_class );
// Return if no valid post type
if( empty( $post_type ) ) {
return $content;
}
// Slider configuration
$slider_conf = compact( 'dots', 'arrows', 'autoplay', 'autoplayinterval', 'speed' );
// Order By
if( $view_by == 'comment' ) {
$orderby = 'comment_count';
} elseif ( $view_by == 'views' ) {
$orderby = 'meta_value_num';
}
$wtpsw_view_by = $orderby; // Assign to global variable for query filter
$post_args = array(
'post_type' => $post_type,
'posts_per_page' => $limit,
'order' => $order,
'orderby' => $orderby
);
if( $view_by == 'views' ) {
$post_args['meta_key'] = $prefix.'views';
}
// Wrps class variables
$main_wrap = "wtpsw-post-slider-{$unique}";
$main_wrap .= " {$design}";
$main_wrap .= " {$extra_class}";
// Filter to change query where condition
add_filter( 'posts_where', array( $wtpsw_model, 'wtpsw_query_where' ) );
// Query to get post
$wtpsw_posts = $wtpsw_model->wtpsw_get_posts( $post_args );
// Remove Filter for change query where condition
remove_filter( 'posts_where', array( $wtpsw_model, 'wtpsw_query_where' ) );
ob_start();
if( $wtpsw_posts->have_posts() ) : ?>
<div id="wtpsw-slider-<?php echo esc_attr( $unique ); ?>" class="wtpsw-post-slider wtpsw-post-slider-init <?php echo esc_attr( $main_wrap ); ?>" data-conf="<?php echo htmlspecialchars( json_encode( $slider_conf )); ?>">
<?php while ($wtpsw_posts->have_posts()) : $wtpsw_posts->the_post();
global $post;
$wtpsw_post_stats = array();
$post_id = isset($post->ID) ? $post->ID : '';
$comment_text = wtpsw_get_comments_number( $post->ID, $hide_empty_comment_count );
// Design file
include( WTPSW_DIR . "/templates/slider/design-1.php" );
endwhile; ?>
</div>
<?php
endif;
wp_reset_postdata(); // Reset WP Query
$content .= ob_get_clean();
return $content;
}
// Trending popular post Slider shortcode
add_shortcode( 'wtpsw_popular_post', 'wtpsw_trending_post_slider' );

View File

@ -0,0 +1,289 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
add_action( 'widgets_init', 'wtpsw_post_list_widget' );
/**
* Register trending post vertical slider widget
*
* @package WP Trending Post Slider and Widget
* @since 1.0.0
*/
function wtpsw_post_list_widget() {
register_widget( 'Wtpsw_Post_List_Widget' );
}
/**
* Vertical Scrolling Post Widget Class
*
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' )) exit;
class Wtpsw_Post_List_Widget extends WP_Widget {
var $model, $defaults;
function __construct() {
global $wtpsw_model;
$this->model = $wtpsw_model;
// Widget settings
$widget_ops = array( 'classname' => 'wtpsw_post_list_widget', 'description' => __( 'Display most popular trending post on your blog.', 'wtpsw' ));
// Create the widget
parent::__construct( 'wtpsw-post-list-widget', __( 'Trending Posts', 'wtpsw' ), $widget_ops );
$this->defaults = array(
'title' => __( 'Trending Posts', 'wtpsw' ),
'limit' => 5,
'post_type' => 'post',
'show_content' => 0,
'show_thumb' => 1,
'show_author' => 1,
'show_date' => 1,
'order' => 'DESC',
'view_by' => 'views',
'content_length' => 20,
'show_comment_count' => 1,
'hide_empty_comment_count' => 0,
);
}
/**
* Updates the widget control options
*
* @since 1.0.0
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
// Input fields
$instance['post_type'] = $new_instance['post_type'];
$instance['view_by'] = $new_instance['view_by'];
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['limit'] = ( empty($new_instance['limit'] ) || ( $new_instance['limit'] < -1 ) ) ? 5 : $new_instance['limit'];
$instance['order'] = ( isset( $new_instance['order'] ) && $new_instance['order'] == 'ASC' ) ? 'ASC' : 'DESC';
$instance['content_length'] = ! empty( $new_instance['content_length'] ) ? $new_instance['content_length'] : 20;
$instance['show_author'] = ! empty( $new_instance['show_author'] ) ? 1 : 0;
$instance['show_comment_count'] = ! empty( $new_instance['show_comment_count'] ) ? 1 : 0;
$instance['show_content'] = ! empty( $new_instance['show_content'] ) ? 1 : 0;
$instance['show_thumb'] = ! empty( $new_instance['show_thumb'] ) ? 1 : 0;
$instance['show_date'] = ! empty( $new_instance['show_date'] ) ? 1 : 0;
$instance['hide_empty_comment_count'] = ! empty( $new_instance['hide_empty_comment_count'] ) ? 1 : 0;
return $instance;
}
/**
* Displays the widget form in widget area
*
* @since 1.0.0
*/
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, $this->defaults );
$post_types = wtpsw_get_post_types();
$support_post_types = wtpsw_get_option( 'post_types', array() );
$sel_post_type = ( ! empty( $instance['post_type'] ) && in_array( $instance['post_type'], $support_post_types ) ) ? $instance['post_type'] : '';
?>
<div class="wtpsw-widget-wrap">
<!-- Title Field -->
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title', 'wtpsw' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
</p>
<!-- Post type -->
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'post_type' ) ); ?>"><?php esc_html_e( 'Post Type', 'wtpsw' ); ?></label>
<select class="widefat ftpp-reg-post-types" id="<?php echo esc_attr( $this->get_field_id( 'post_type' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'post_type' )); ?>" >
<option value="" selected ><?php esc_html_e( 'Select Post Type', 'wtpsw'); ?></option>
<?php
if( !empty($post_types) ) {
foreach ($post_types as $post_key => $post_value) {
if(in_array($post_key, $support_post_types)) {
echo '<option value="'.esc_attr( $post_key ).'" '.selected( $post_key, $instance['post_type'] ).'>'.esc_attr( $post_value ).'</option>';
}
}
}
?>
</select>
</p>
<!-- View By Field -->
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'view_by' )); ?>"><?php esc_html_e( 'Post List By', 'wtpsw'); ?></label>
<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'view_by' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'view_by' )); ?>">
<option value="views" <?php selected( $instance['view_by'], 'views' ); ?> ><?php esc_html_e('Total Views', 'wtpsw') ?></option>
<option value="comment" <?php selected( $instance['view_by'], 'comment' ); ?>><?php esc_html_e( 'Comments Count', 'wtpsw' ); ?></option>
</select>
</p>
<!-- Number of Items Field -->
<p>
<label for="<?php echo esc_attr($this->get_field_id( 'limit' )); ?>"><?php esc_html_e( 'Number of Items', 'wtpsw'); ?></label>
<input class="widefat" min="-1" id="<?php echo esc_attr($this->get_field_id( 'limit' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'limit' )); ?>" type="number" value="<?php echo esc_attr($instance['limit']); ?>" />
</p>
<!-- Order Field -->
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'order' )); ?>"><?php esc_html_e( 'Order', 'wtpsw' ); ?></label>
<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'order' )); ?>" name="<?php echo esc_attr( $this->get_field_name( 'order' )); ?>">
<option value="ASC" <?php selected( $instance['order'], 'ASC' ); ?> ><?php esc_html_e('ASC', 'wtpsw') ?></option>
<option value="DESC" <?php selected( $instance['order'], 'DESC' ); ?>><?php esc_html_e('DESC', 'wtpsw'); ?></option>
</select>
</p>
<!-- Show Content Field -->
<p>
<input type="checkbox" value="1" id="<?php echo esc_attr($this->get_field_id( 'show_content' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'show_content' )); ?>" <?php checked( $instance['show_content'], 1 ); ?> />
<label for="<?php echo esc_attr( $this->get_field_id( 'show_content' )); ?>"><?php esc_html_e( 'Display Short Content', 'wtpsw' ); ?></label><br/>
<span class="description"><em><?php esc_html_e( 'If your post has excerpt then it will take it else post content will be taken.', 'wtpsw' ); ?></em></span>
</p>
<!-- Show Post Content Word Limit -->
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'content_length' )); ?>"><?php esc_html_e( 'Post Content Length', 'wtpsw'); ?></label>
<input class="widefat" id="<?php echo esc_attr($this->get_field_id( 'content_length' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'content_length' )); ?>" type="number" min="1" value="<?php echo esc_attr( $instance['content_length'] ); ?>" />
<span class="description"><em><?php esc_html_e( 'Enter number of words to display in post content.', 'wtpsw' ); ?></em></span>
</p>
<!-- Show Thumbnail Field -->
<p>
<input type="checkbox" value="1" id="<?php echo esc_attr( $this->get_field_id( 'show_thumb' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'show_thumb' )); ?>" <?php checked( $instance['show_thumb'], 1 ); ?> />
<label for="<?php echo esc_attr($this->get_field_id( 'show_thumb' )); ?>"><?php esc_html_e( 'Show Thumbnail', 'wtpsw'); ?></label>
</p>
<!-- Show Author Field -->
<p>
<input type="checkbox" value="1" id="<?php echo esc_attr( $this->get_field_id( 'show_author' )); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_author' )); ?>" <?php checked( $instance['show_author'], 1 ); ?> />
<label for="<?php echo esc_attr( $this->get_field_id( 'show_author' )); ?>"><?php esc_html_e( 'Show Author', 'wtpsw'); ?></label>
</p>
<!-- Show Date Field -->
<p>
<input type="checkbox" value="1" id="<?php echo esc_attr( $this->get_field_id( 'show_date' )); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_date' )); ?>" <?php checked( $instance['show_date'], 1 ); ?> />
<label for="<?php echo esc_attr( $this->get_field_id( 'show_date' )); ?>"><?php esc_html_e( 'Show Date', 'wtpsw'); ?></label>
</p>
<!-- Show Comment Field -->
<p>
<input type="checkbox" value="1" id="<?php echo esc_attr( $this->get_field_id( 'show_comment_count' )); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_comment_count' )); ?>" <?php checked( $instance['show_comment_count'], 1 ); ?> />
<label for="<?php echo esc_attr( $this->get_field_id( 'show_comment_count' )); ?>"><?php esc_html_e( 'Show Comment Count', 'wtpsw' ); ?></label>
</p>
<!-- Show Comment Field -->
<p>
<input type="checkbox" value="1" id="<?php echo esc_attr( $this->get_field_id( 'hide_empty_comment_count' )); ?>" name="<?php echo esc_attr( $this->get_field_name( 'hide_empty_comment_count' )); ?>" <?php checked( $instance['hide_empty_comment_count'], 1 ); ?> />
<label for="<?php echo esc_attr( $this->get_field_id( 'hide_empty_comment_count' )); ?>"><?php esc_html_e( 'Hide Empty Comment Count', 'wtpsw' ); ?></label><br/>
<span class="description"><em><?php esc_html_e( 'Hide comment count if it is empty.', 'wtpsw' ); ?></em></span>
</p>
</div>
<?php
}
/**
* Outputs the content of the widget
*
* @since 1.0.0
*/
function widget( $args, $instance ) {
// SiteOrigin Page Builder Gutenberg Block Tweak - Do not Display Preview
if( isset( $_POST['action'] ) && ( $_POST['action'] == 'so_panels_layout_block_preview' || $_POST['action'] == 'so_panels_builder_content_json' ) ) {
echo "<div class='wtpsw-builder-shrt-prev'><div class='wtpsw-builder-shrt-title'><span>".esc_html__('Trending Post List - Widget', 'wtpsw')."</span></div>WPOS - Trending Post List</div>";
return;
}
global $wtpsw_options, $wtpsw_view_by;
$instance = wp_parse_args( (array) $instance, $this->defaults );
extract( $args );
$prefix = WTPSW_META_PREFIX;
$support_post_types = wtpsw_get_option('post_types', array());
$title = $instance['title'];
$limit = $instance['limit'];
$order = $instance['order'];
$view_by = $instance['view_by'];
$content_length = $instance['content_length'];
$post_type = ( ! empty( $instance['post_type'] ) && in_array( $instance['post_type'], $support_post_types ) ) ? $instance['post_type'] : '';
$post_type = ( ! empty( $instance['post_type'] ) && in_array( $instance['post_type'], $support_post_types ) ) ? $instance['post_type'] : '';
$show_date = ! empty( $instance['show_date'] ) ? true : false;
$show_author = ! empty( $instance['show_author'] ) ? true : false;
$show_comment_count = ! empty( $instance['show_comment_count'] ) ? true : false;
$show_thumb = ! empty( $instance['show_thumb'] ) ? true : false;
$show_content = ! empty( $instance['show_content'] ) ? true : false;
$hide_empty_comment_count = ! empty( $instance['hide_empty_comment_count'] ) ? true : false;
// If no valid post type is found
if( empty( $post_type ) ) {
return;
}
// Order By
if( $view_by == 'comment' ) {
$orderby = 'comment_count';
} elseif ( $view_by == 'views' ) {
$orderby = 'meta_value_num';
}
$wtpsw_view_by = $orderby; // Assign to global variable for query filter
$post_args = array(
'post_type' => $post_type,
'posts_per_page' => $limit,
'order' => $order,
'orderby' => $orderby
);
if( $view_by == 'views' ) {
$post_args['meta_key'] = $prefix.'views';
}
// Filter to change query where condition
add_filter( 'posts_where', array( $this->model, 'wtpsw_query_where' ));
// Query to get post
$wtpsw_posts = $this->model->wtpsw_get_posts( $post_args );
// Remove Filter for change query where condition
remove_filter( 'posts_where', array( $this->model, 'wtpsw_query_where' ));
echo $before_widget;
if ( $title ) {
echo $before_title . wp_kses_post($title) . $after_title;
}
if( $wtpsw_posts->have_posts() ) : ?>
<div class="wtpsw-post-items">
<ul>
<?php while ( $wtpsw_posts->have_posts() ) : $wtpsw_posts->the_post();
global $post;
$wtpsw_stats = array(); // Need to flush
$comment_text = wtpsw_get_comments_number( $post->ID, $hide_empty_comment_count );
// Design file
include( WTPSW_DIR . '/templates/wtpsw-post-lists.php' );
endwhile; ?>
</ul>
</div>
<?php
endif;
wp_reset_postdata(); // Reset WP Query
echo $after_widget;
}
}

View File

@ -0,0 +1,201 @@
<?php
/**
* Functions File
*
* @package WP Trending Post Slider and Widget
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Update default settings
*
* @since 1.0.0
*/
function wtpsw_default_settings(){
global $wtpsw_options;
$wtpsw_options = array(
'post_range' => '',
'post_types' => array( 'post' ),
);
$default_options = apply_filters('wtpsw_options_default_values', $wtpsw_options );
// Update default options
update_option( 'wtpsw_options', $default_options );
// Overwrite global variable when option is update
$wtpsw_options = wtpsw_get_settings();
}
/**
* Get Settings From Option Page
*
* Handles to return all settings value
*
* @since 1.0.0
*/
function wtpsw_get_settings() {
$options = get_option( 'wtpsw_options' );
$settings = is_array( $options ) ? $options : array();
return $settings;
}
/**
* Get an option
* Looks to see if the specified setting exists, returns default if not
*
* @since 1.0
*/
function wtpsw_get_option( $key = '', $default = false ) {
global $wtpsw_options;
$value = ! empty( $wtpsw_options[ $key ] ) ? $wtpsw_options[ $key ] : $default;
$value = apply_filters( 'wtpsw_get_option', $value, $key, $default );
return apply_filters( 'wtpsw_get_option_' . $key, $value, $key, $default );
}
/**
* Sanitize Multiple HTML class
*
* @since 1.5
*/
function wtpsw_sanitize_html_classes($classes, $sep = " ") {
$return = "";
if( ! is_array( $classes ) ) {
$classes = explode( $sep, $classes );
}
if( ! empty( $classes ) ) {
foreach( $classes as $class ){
$return .= sanitize_html_class( $class ) . " ";
}
$return = trim( $return );
}
return $return;
}
/**
* Convert Object To Array
*
* @since 1.0.0
*/
function wtpsw_object_to_array($result) {
$array = array();
foreach ( $result as $key=>$value ) {
if ( is_object( $value )) {
$array[$key] = wtpsw_object_to_array( $value );
} else {
$array[$key] = $value;
}
}
return $array;
}
/**
* Function to unique number value
*
* @since 1.0.0
*/
function wtpsw_get_unique() {
static $unique = 0;
$unique++;
// For Elementor & Beaver Builder
if( ( defined('ELEMENTOR_PLUGIN_BASE') && isset( $_POST['action'] ) && $_POST['action'] == 'elementor_ajax' )
|| ( class_exists('FLBuilderModel') && ! empty( $_POST['fl_builder_data']['action'] ) )
|| ( function_exists('vc_is_inline') && vc_is_inline() ) ) {
$unique = current_time('timestamp') . '-' . rand();
}
return $unique;
}
/**
* Function to get post excerpt
*
* @since 1.0.0
*/
function wtpsw_get_post_excerpt( $post_id = null, $content = '', $word_length = '55', $more = '...' ) {
$word_length = ! empty( $word_length ) ? $word_length : '55';
// If post id is passed
if( ! empty( $post_id )) {
if ( has_excerpt( $post_id )) {
$content = get_the_excerpt();
} else {
$content = ! empty( $content ) ? $content : get_the_content();
}
}
if( ! empty( $content ) ) {
$content = strip_shortcodes( $content ); // Strip shortcodes
$content = wp_trim_words( $content, $word_length, $more );
}
return $content;
}
/**
* Function to get registered post types
*
* @since 1.0.0
*/
function wtpsw_get_post_types( $args = array() ) {
// Taking defaults
$all_post_types = array();
$post_types = array();
$args = array(
'public' => ! empty( $args['public'] ) ? $args['public'] : 'true'
);
$all_post_types = get_post_types( $args, 'object' );
$exclude_post = array( 'attachment' );
foreach ( $all_post_types as $post_type_key => $post_data ) {
if( ! in_array( $post_type_key, $exclude_post )) {
$post_types[$post_type_key] = ! empty( $post_data->label ) ? $post_data->label : $post_type_key;
}
}
return apply_filters( 'wtpsw_get_post_types', $post_types );
}
/**
* Function to get comment count text
*
* @since 1.0.0
*/
function wtpsw_get_comments_number( $post_id = '', $hide_empty = false ) {
$comment_text = '';
if( ! empty( $post_id )) {
$comment_number = get_comments_number( $post_id );
if ( $comment_number == 0 && empty( $hide_empty )) {
$comment_text = esc_html__( '0 Comments', 'wtpsw' );
} elseif ( $comment_number > 1 ) {
$comment_text = $comment_number . esc_html__(' Comments', 'wtpsw');
} elseif ( $comment_number == 1 ) {
$comment_text = esc_html__('1 Comment', 'wtpsw');
}
}
return $comment_text;
}