false,
'is_widget' => false,
'instance_id' => 1,
'is_shortcode' => false,
'is_manual' => false,
'echo' => false,
'strict_limit' => false,
'heading' => 1,
'offset' => 0,
);
// Merge the $defaults array with the $tptn_settings array.
$defaults = array_merge( $defaults, tptn_settings_defaults(), $tptn_settings );
// Parse incomming $args into an array and merge it with $defaults.
$args = wp_parse_args( $args, $defaults );
$output = '';
/**
* Fires before the output processing begins.
*
* @since 2.2.0
*
* @param string $output Formatted list of top posts
* @param array $args Array of arguments
*/
do_action( 'pre_tptn_pop_posts', $output, $args );
// Check if the cache is enabled and if the output exists. If so, return the output.
if ( $args['cache'] ) {
$cache_name = tptn_cache_get_key( $args );
$output = get_transient( $cache_name );
if ( false !== $output ) {
/**
* Filter the output
*
* @since 1.9.8.5
*
* @param string $output Formatted list of top posts
* @param array $args Array of arguments
*/
return apply_filters( 'tptn_pop_posts', $output, $args );
}
}
// Get thumbnail size.
list( $args['thumb_width'], $args['thumb_height'] ) = tptn_get_thumb_size( $args );
// Retrieve the popular posts.
$results = get_tptn_posts( $args );
$counter = 0;
$daily_class = $args['daily'] ? 'tptn_posts_daily ' : 'tptn_posts ';
$widget_class = $args['is_widget'] ? ' tptn_posts_widget tptn_posts_widget' . $args['instance_id'] : '';
$shortcode_class = $args['is_shortcode'] ? ' tptn_posts_shortcode' : '';
$post_classes = $daily_class . $widget_class . $shortcode_class;
/**
* Filter the classes added to the div wrapper of the Top 10.
*
* @since 2.1.0
*
* @param string $post_classes Post classes string.
*/
$post_classes = apply_filters( 'tptn_post_class', $post_classes );
$output .= '
';
if ( $results ) {
$output .= tptn_heading_title( $args );
$output .= tptn_before_list( $args );
// We need this for WPML support.
$processed_results = array();
foreach ( $results as $result ) {
/* Support WPML */
$resultid = tptn_object_id_cur_lang( $result->ID );
// If this is NULL or already processed ID or matches current post then skip processing this loop.
if ( ! $resultid || in_array( $resultid, $processed_results ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
continue;
}
// Push the current ID into the array to ensure we're not repeating it.
array_push( $processed_results, $resultid );
// Store the count. We'll need this later.
$count = $args['daily'] ? 'daily' : 'total';
$visits = empty( $result->visits ) ? get_tptn_post_count_only( $resultid, $count ) : $result->visits;
/**
* Filter the post ID for each result. Allows a custom function to hook in and change the ID if needed.
*
* @since 1.9.8.5
*
* @param int $resultid ID of the post
*/
$resultid = apply_filters( 'tptn_post_id', $resultid );
$result = get_post( $resultid ); // Let's get the Post using the ID.
// Process the category exclusion if passed in the shortcode.
if ( isset( $exclude_categories ) ) {
$categorys = get_the_category( $result->ID ); // Fetch categories of the plugin.
$p_in_c = false; // Variable to check if post exists in a particular category.
foreach ( $categorys as $cat ) { // Loop to check if post exists in excluded category.
$p_in_c = ( in_array( $cat->cat_ID, $exclude_categories ) ) ? true : false; // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
if ( $p_in_c ) {
break; // Skip loop execution and go to the next step.
}
}
if ( $p_in_c ) {
continue; // Skip loop execution and go to the next step.
}
}
$output .= tptn_before_list_item( $args, $result );
$output .= tptn_list_link( $args, $result );
if ( $args['show_author'] ) {
$output .= tptn_author( $args, $result );
}
if ( $args['show_date'] ) {
$output .= '
' . tptn_date( $args, $result ) . ' ';
}
if ( $args['show_excerpt'] ) {
$output .= '
' . tptn_excerpt( $result->ID, $args['excerpt_length'] ) . '';
}
if ( $args['disp_list_count'] ) {
$output .= '
' . tptn_list_count( $args, $result, $visits ) . '';
}
$tptn_list = '';
/**
* Filter to add content to the end of each item in the list.
*
* @since 2.2.0
*
* @param string $tptn_list Empty string at the end of each list item.
* @param object $result Object of the current post result
* @param array $args Array of arguments
*/
$output .= apply_filters( 'tptn_list', $tptn_list, $result, $args );
// Opening span created in tptn_list_link().
if ( 'inline' === $args['post_thumb_op'] || 'text_only' === $args['post_thumb_op'] ) {
$output .= '';
}
$output .= tptn_after_list_item( $args, $result );
$counter++;
if ( $counter === (int) $args['limit'] ) {
break; // End loop when related posts limit is reached.
}
}
if ( $args['show_credit'] ) {
$output .= tptn_before_list_item( $args, $result );
$output .= sprintf(
/* translators: 1. Top 10 plugin page link, 2. Link attributes. */
__( 'Popular posts by
Top 10 plugin', 'top-10' ),
esc_url( 'https://webberzone.com/plugins/top-10/' ),
tptn_link_attributes( $args, $result )
);
$output .= tptn_after_list_item( $args, $result );
}
$output .= tptn_after_list( $args );
$clearfix = '
';
/**
* Filter the clearfix div tag. This is included after the closing tag to clear any miscellaneous floating elements;
*
* @since 2.2.0
*
* @param string $clearfix Contains:
*/
$output .= apply_filters( 'tptn_clearfix', $clearfix );
} else {
$output .= ( $args['blank_output'] ) ? '' : $args['blank_output_text'];
}
$output .= '
';
// Check if the cache is enabled and if the output exists. If so, return the output.
if ( $args['cache'] ) {
/**
* Filter the cache time which allows a function to override this
*
* @since 2.2.0
*
* @param int $args['cache_time'] Cache time in seconds
* @param array $args Array of all the arguments
*/
$cache_time = apply_filters( 'tptn_cache_time', $args['cache_time'], $args );
$output .= "