Skip to content

Commit

Permalink
New post_type arg
Browse files Browse the repository at this point in the history
Fixes #10

Implemented as a pro setting unlocked by Top 10 Pro
  • Loading branch information
ajaydsouza committed Jan 11, 2025
1 parent bd4da64 commit 6535572
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
54 changes: 31 additions & 23 deletions includes/admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Admin {
*/
public function __construct() {
add_filter( 'admin_notices', array( $this, 'admin_notices' ) );
add_filter( 'tptn_settings_sections', array( $this, 'add_settings_section' ), 11 );
add_filter( 'tptn_registered_settings', array( $this, 'settings_popular_authors' ), 11 );
add_filter( 'tptn_settings_sections', array( $this, 'add_settings_section' ) );
add_filter( 'tptn_registered_settings', array( $this, 'settings_popular_authors' ) );
}

/**
Expand Down Expand Up @@ -83,8 +83,8 @@ public static function settings_popular_authors( $settings ) {
'popular-authors' => array(
'wzpa_cache' => array(
'id' => 'wzpa_cache',
'name' => esc_html__( 'Cache output', 'top-10' ),
'desc' => esc_html__( 'Turn this ON to cache the HTML output. This option uses the same settings as Top 10 and creates similar cache keys.', 'top-10' ),
'name' => esc_html__( 'Cache output', 'popular-authors' ),
'desc' => esc_html__( 'Turn this ON to cache the HTML output. This option uses the same settings as Top 10 and creates similar cache keys.', 'popular-authors' ),
'type' => 'checkbox',
'options' => true,
),
Expand Down Expand Up @@ -124,62 +124,70 @@ public static function settings_popular_authors( $settings ) {
),
'wzpa_optioncount' => array(
'id' => 'wzpa_optioncount',
'name' => esc_html__( 'Show views', 'top-10' ),
'desc' => esc_html__( "Show the total number of views in parenthesis next to the author's name", 'top-10' ),
'name' => esc_html__( 'Show views', 'popular-authors' ),
'desc' => esc_html__( "Show the total number of views in parenthesis next to the author's name", 'popular-authors' ),
'type' => 'checkbox',
'options' => false,
),
'wzpa_exclude_admin' => array(
'id' => 'wzpa_exclude_admin',
'name' => esc_html__( "Exclude 'admin' account", 'top-10' ),
'name' => esc_html__( "Exclude 'admin' account", 'popular-authors' ),
'desc' => '',
'type' => 'checkbox',
'options' => false,
),
'wzpa_show_fullname' => array(
'id' => 'wzpa_show_fullname',
'name' => esc_html__( 'Show full name', 'top-10' ),
'desc' => esc_html__( "Whether to show the author's full name instead of the display name", 'top-10' ),
'name' => esc_html__( 'Show full name', 'popular-authors' ),
'desc' => esc_html__( "Whether to show the author's full name instead of the display name", 'popular-authors' ),
'type' => 'checkbox',
'options' => false,
),
'wzpa_show_avatar' => array(
'id' => 'wzpa_show_avatar',
'name' => esc_html__( 'Show Avatar', 'top-10' ),
'desc' => esc_html__( "Whether to show the author's avatar", 'top-10' ),
'name' => esc_html__( 'Show Avatar', 'popular-authors' ),
'desc' => esc_html__( "Whether to show the author's avatar", 'popular-authors' ),
'type' => 'checkbox',
'options' => false,
),
'wzpa_post_type' => array(
'id' => 'wzpa_post_type',
'name' => esc_html__( 'Post types to include', 'popular-authors' ),
'desc' => esc_html__( 'At least one option should be selected above. Select which post types you want to include in the list of posts. This field can be overridden using a comma separated list of post types when using the manual display.', 'popular-authors' ),
'type' => 'posttypes',
'options' => 'post',
'pro' => true,
),
'wzpa_html_wrapper_header' => array(
'id' => 'wzpa_html_wrapper_header',
'name' => '<h3>' . esc_html__( 'HTML to display', 'top-10' ) . '</h3>',
'name' => '<h3>' . esc_html__( 'HTML to display', 'popular-authors' ) . '</h3>',
'desc' => '',
'type' => 'header',
),
'wzpa_before_list' => array(
'id' => 'wzpa_before_list',
'name' => esc_html__( 'Before the list of posts', 'top-10' ),
'name' => esc_html__( 'Before the list of posts', 'popular-authors' ),
'desc' => '',
'type' => 'text',
'options' => '<ul>',
),
'wzpa_after_list' => array(
'id' => 'wzpa_after_list',
'name' => esc_html__( 'After the list of posts', 'top-10' ),
'name' => esc_html__( 'After the list of posts', 'popular-authors' ),
'desc' => '',
'type' => 'text',
'options' => '</ul>',
),
'wzpa_before_list_item' => array(
'id' => 'wzpa_before_list_item',
'name' => esc_html__( 'Before each list item', 'top-10' ),
'name' => esc_html__( 'Before each list item', 'popular-authors' ),
'desc' => '',
'type' => 'text',
'options' => '<li>',
),
'wzpa_after_list_item' => array(
'id' => 'wzpa_after_list_item',
'name' => esc_html__( 'After each list item', 'top-10' ),
'name' => esc_html__( 'After each list item', 'popular-authors' ),
'desc' => '',
'type' => 'text',
'options' => '</li>',
Expand All @@ -192,7 +200,7 @@ public static function settings_popular_authors( $settings ) {
),
'wzpa_styles' => array(
'id' => 'wzpa_styles',
'name' => esc_html__( 'Popular Authors style', 'top-10' ),
'name' => esc_html__( 'Popular Authors style', 'popular-authors' ),
'desc' => '',
'type' => 'radiodesc',
'default' => 'no_style',
Expand All @@ -214,18 +222,18 @@ public static function get_styles() {
$styles = array(
array(
'id' => 'no_style',
'name' => esc_html__( 'No styles', 'top-10' ),
'description' => esc_html__( 'Select this option if you plan to add your own styles', 'top-10' ),
'name' => esc_html__( 'No styles', 'popular-authors' ),
'description' => esc_html__( 'Select this option if you plan to add your own styles', 'popular-authors' ),
),
array(
'id' => 'card',
'name' => esc_html__( 'Card Layout', 'top-10' ),
'description' => esc_html__( 'Display the popular authors in a card layout using CSS grid', 'top-10' ),
'name' => esc_html__( 'Card Layout', 'popular-authors' ),
'description' => esc_html__( 'Display the popular authors in a card layout using CSS grid', 'popular-authors' ),
),
array(
'id' => 'left_thumbs',
'name' => esc_html__( 'Left Thumbs', 'top-10' ),
'description' => esc_html__( 'Display the popular authors in a grid with the image to the left of the text', 'top-10' ),
'name' => esc_html__( 'Left Thumbs', 'popular-authors' ),
'description' => esc_html__( 'Display the popular authors in a grid with the image to the left of the text', 'popular-authors' ),
),
);

Expand Down
7 changes: 7 additions & 0 deletions includes/frontend/class-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ public static function get_popular_author_ids( $args = array() ) {
// Parse incomming $args into an array and merge it with $defaults.
$args = wp_parse_args( $args, $defaults );

// Get the table name.
if ( $args['daily'] ) {
$pop_posts_table = $wpdb->base_prefix . 'top_ten_daily';
} else {
Expand Down Expand Up @@ -335,6 +336,11 @@ public static function get_popular_author_ids( $args = array() ) {
$where .= $wpdb->prepare( " AND {$pop_posts_table}.dp_date >= %s ", $from_date ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
}

if ( $args['post_type'] ) {
$post_type = wp_parse_list( $args['post_type'] );
$where .= " AND {$posts_table}.post_type IN ('" . implode( "', '", esc_sql( $post_type ) ) . "')";
}

// Create the base GROUP BY clause.
$groupby = ' author_id ';

Expand Down Expand Up @@ -472,6 +478,7 @@ public static function list_popular_authors_args( $args = array() ) {
'offset' => '',
'optioncount' => true,
'exclude_admin' => false,
'post_type' => 'post',
'show_fullname' => false,
'show_avatar' => false,
'hide_empty' => true,
Expand Down

0 comments on commit 6535572

Please sign in to comment.