false,
'instance_id' => 1,
'is_widget' => false,
'is_shortcode' => false,
'is_manual' => false,
'is_block' => false,
'echo' => false,
'strict_limit' => false,
'heading' => 1,
'offset' => 0,
'extra_class' => '',
);
// 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 );
// Sanitize the attributes.
$args = Helpers::sanitize_args( $args );
// Short circuit flag.
$short_circuit = false;
/**
* Allow a short circuit flag to be set to exit at this stage. Set to true to exit.
*
* @since 4.0.0
*
* @param bool $short_circuit Short circuit filter.
* @param array $args Arguments array.
* @param \WP_Post $post Current Post object.
*/
$short_circuit = apply_filters( 'get_tptn_short_circuit', $short_circuit, $args, $post );
if ( $short_circuit ) {
return ''; // Exit without adding popular posts.
}
$output = '';
/**
* Fires before the output processing begins.
*
* @since 3.1.0
*
* @param string $output Formatted list of top posts.
* @param array $args Array of arguments.
* @param \WP_Post $post Current Post object.
*/
do_action( 'pre_tptn_pop_posts', $output, $args, $post );
// Check exclusions.
if ( self::exclude_on( $post, $args ) ) {
return '';
}
// Check if the cache is enabled and if the output exists. If so, return the output.
if ( $args['cache'] ) {
$cache_name = \WebberZone\Top_Ten\Util\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'] ) = Media_Handler::get_thumb_size( $args['thumb_size'] );
// Retrieve the popular posts.
$results = self::get_posts( $args );
$counter = 0;
// Override tptn_styles if post_thumb_op is text_only.
$args['tptn_styles'] = ( 'text_only' === $args['post_thumb_op'] ) ? 'text_only' : $args['tptn_styles'];
$style_array = Styles_Handler::get_style( $args['tptn_styles'] );
$post_classes = array(
'main' => $args['daily'] ? 'tptn_posts_daily ' : 'tptn_posts ',
'widget' => $args['is_widget'] ? 'tptn_posts_widget tptn_posts_widget-' . $args['instance_id'] : '',
'shortcode' => $args['is_shortcode'] ? 'tptn_posts_shortcode' : '',
'block' => $args['is_block'] ? 'tptn_posts_block' : '',
'extra_class' => $args['extra_class'],
'style' => ! empty( $style_array['name'] ) ? str_replace( '-pro', '', 'tptn-' . $style_array['name'] ) : '',
);
$post_classes = join( ' ', $post_classes );
/**
* 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 .= self::heading_title( $args );
$output .= self::before_list( $args );
foreach ( $results as $result ) {
$switched_blog = false;
if ( is_multisite() && ! empty( $result->blog_id ) && (int) get_current_blog_id() !== (int) $result->blog_id ) {
add_action( 'switch_blog', 'wz_switch_site_rewrite' );
switch_to_blog( $result->blog_id );
$switched_blog = true;
}
// Store the count. We'll need this later.
$count = $args['daily'] ? 'daily' : 'total';
$visits = empty( $result->visits ) ? \WebberZone\Top_Ten\Counter::get_post_count_only( $result->ID, $count ) : (int) $result->visits;
$result = get_post( $result );
$output .= self::before_list_item( $args, $result );
$output .= self::list_link( $args, $result );
if ( $args['show_author'] ) {
$output .= self::get_the_author( $args, $result );
}
if ( $args['show_date'] ) {
$output .= '
' . self::get_the_date( $args, $result ) . ' ';
}
if ( $args['show_excerpt'] ) {
$output .= '
' . self::get_the_excerpt( $result->ID, $args['excerpt_length'] ) . '';
}
if ( $args['disp_list_count'] ) {
$output .= '
' . self::get_list_count( $args, $result, $visits ) . '';
}
$tptn_list = '';
/**
* Filter to add content to the end of each item in the list.
*
* @since 3.3.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 .= self::after_list_item( $args, $result );
++$counter;
if ( $counter === (int) $args['limit'] ) {
break; // End loop when popular posts limit is reached.
}
if ( $switched_blog ) {
restore_current_blog();
remove_action( 'switch_blog', 'wz_switch_site_rewrite' );
}
}
if ( $args['show_credit'] ) {
$output .= self::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/' ),
self::link_attributes( $args, $result )
);
$output .= self::after_list_item( $args, $result );
}
$output .= self::after_list( $args );
$clearfix = '
';
/**
* Filter the clearfix div tag. This is included after the closing tag to clear any miscellaneous floating elements;
*
* @since 3.3.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 3.3.0
*
* @param int $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 .= "