base_prefix . 'top_ten';
if ( $daily ) {
$table_name .= '_daily'; // If we're viewing daily posts, set this to true.
}
if ( ! $limit ) {
$limit = tptn_get_option( 'limit' );
}
$results = get_tptn_posts(
array(
'is_widget' => 1,
'daily' => $daily,
'limit' => $limit,
'post_types' => 'all',
)
);
$output = '
';
if ( $results ) {
$output .= '
';
foreach ( $results as $result ) {
$output .= '- ' . get_the_title( $result->ID ) . '';
$output .= ' (' . tptn_number_format_i18n( $result->visits ) . ')';
$output .= '
';
}
$output .= '
';
}
$output .= '
';
if ( $daily ) {
$output .= '' . __( 'View all daily popular posts', 'top-10' ) . '';
} else {
$output .= '' . __( 'View all popular posts', 'top-10' ) . '';
}
$output .= '
';
$output .= '
';
/* translators: 1: Top 10 page link. */
$output .= sprintf( __( 'Popular posts by Top 10 plugin', 'top-10' ), esc_url( 'https://webberzone.com/plugins/top-10/' ) );
$output .= '
';
$output .= '
';
/**
* Filters the dashboard widget output
*
* @since 1.3
*
* @param string $output Text output
* @param bool $daily Switch for Daily or Overall popular posts.
* @param int $page Which page of the lists are we on.
* @param int $limit Maximum number of posts per page.
* @param bool $widget Is this a WordPress widget.
*/
return apply_filters( 'tptn_pop_display', $output, $daily, $page, $limit, $widget );
}
/**
* Widget for Popular Posts.
*
* @since 1.1
*/
function tptn_pop_dashboard() {
echo tptn_pop_display( false, 0, 10, true ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Widget for Daily Popular Posts.
*
* @since 1.2
*/
function tptn_pop_daily_dashboard() {
echo tptn_pop_display( true, 0, 10, true ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Function to add the widgets to the Dashboard.
*
* @since 1.1
*/
function tptn_pop_dashboard_setup() {
if ( ( current_user_can( 'manage_options' ) ) || ( tptn_get_option( 'show_count_non_admins' ) ) ) {
wp_add_dashboard_widget(
'tptn_pop_dashboard',
__( 'Popular Posts', 'top-10' ),
'tptn_pop_dashboard'
);
wp_add_dashboard_widget(
'tptn_pop_daily_dashboard',
__( 'Daily Popular Posts', 'top-10' ),
'tptn_pop_daily_dashboard'
);
}
}
add_action( 'wp_dashboard_setup', 'tptn_pop_dashboard_setup' );