Plugin Directory

Changeset 3453097


Ignore:
Timestamp:
02/03/2026 05:14:32 PM (2 months ago)
Author:
dfactory
Message:

Tagging version 1.7.5

Location:
post-views-counter/tags/1.7.5
Files:
15 deleted
58 copied

Legend:

Unmodified
Added
Removed
  • post-views-counter/tags/1.7.5/includes/class-columns.php

    r3452736 r3453097  
    184184                    // filters
    185185                    add_filter( 'manage_' . $post_type . '_posts_columns', [ $this, 'add_new_column' ] );
     186                    add_filter( 'manage_edit-' . $post_type . '_columns', [ $this, 'add_new_column' ], 20 );
    186187                    add_filter( 'manage_edit-' . $post_type . '_sortable_columns', [ $this, 'register_sortable_custom_column' ] );
    187188
  • post-views-counter/tags/1.7.5/includes/class-traffic-signals.php

    r3452736 r3453097  
    7676                if ( $post_type !== 'attachment' ) {
    7777                    add_filter( 'manage_' . $post_type . '_posts_columns', [ $this, 'add_traffic_signal_column' ], 10, 1 );
     78                    add_filter( 'manage_edit-' . $post_type . '_columns', [ $this, 'add_traffic_signal_column' ], 20 );
    7879                    add_action( 'manage_' . $post_type . '_posts_custom_column', [ $this, 'render_traffic_signal_column' ], 10, 2 );
    7980                }
     
    160161        // get current month views
    161162        $current_date = new DateTime();
    162         $current_year = $current_date->format( 'Y' );
    163         $current_month = $current_date->format( 'm' );
    164 
    165         $current_views = pvc_get_views( [
    166             'post_id'     => $post_id,
    167             'post_type'   => get_post_type( $post_id ),
    168             'fields'      => 'date=>views',
    169             'views_query' => [
    170                 'year'  => $current_year,
    171                 'month' => $current_month
    172             ]
    173         ] );
    174 
    175         $current_total = is_array( $current_views ) ? array_sum( $current_views ) : 0;
     163        $current_period = $current_date->format( 'Ym' );
     164
     165        $current_total = (int) pvc_get_post_views( $post_id, $current_period );
    176166
    177167        // minimum views threshold
     
    181171        }
    182172
    183         // get previous month views
     173        // get previous month views (same number of days as current month-to-date)
    184174        $prev_date = clone $current_date;
    185175        $prev_date->modify( '-1 month' );
    186176        $prev_year = $prev_date->format( 'Y' );
    187177        $prev_month = $prev_date->format( 'm' );
    188 
    189         $prev_views = pvc_get_views( [
    190             'post_id'     => $post_id,
    191             'post_type'   => get_post_type( $post_id ),
    192             'fields'      => 'date=>views',
    193             'views_query' => [
    194                 'year'  => $prev_year,
    195                 'month' => $prev_month
     178        $prev_last_day = (int) $prev_date->format( 't' );
     179        $current_day = (int) $current_date->format( 'd' );
     180        // compare against the same number of days from last month (clamp to last day)
     181        $end_day = min( $current_day, $prev_last_day );
     182
     183        $prev_start = (int) ( $prev_year . $prev_month . '01' );
     184        $prev_end = (int) ( $prev_year . $prev_month . str_pad( (string) $end_day, 2, '0', STR_PAD_LEFT ) );
     185
     186        $prev_total = (int) pvc_get_post_views(
     187            $post_id,
     188            '',
     189            [
     190                'type'         => 0,
     191                'period_range' => [ $prev_start, $prev_end ]
    196192            ]
    197         ] );
    198 
    199         $prev_total = is_array( $prev_views ) ? array_sum( $prev_views ) : 0;
     193        );
    200194
    201195        // need both periods to compare
  • post-views-counter/tags/1.7.5/includes/functions.php

    r3452736 r3453097  
    2020 * @param int|array $post_id
    2121 * @param string $period
     22 * @param array $args Optional arguments to override period parsing
    2223 *
    2324 * @return int
    2425 */
    2526if ( ! function_exists( 'pvc_get_post_views' ) ) {
    26     function pvc_get_post_views( $post_id = 0, $period = 'total' ) {
     27    function pvc_get_post_views( $post_id = 0, $period = 'total', $args = [] ) {
    2728        global $wpdb;
     29
     30        // ensure args is an array
     31        if ( ! is_array( $args ) ) {
     32            $args = [];
     33        }
    2834
    2935        // sanitize period
     
    4652        $where = [ 'type' => 'type = 4' ];
    4753
     54        // override type if explicitly provided in args
     55        if ( isset( $args['type'] ) ) {
     56            $where['type'] = 'type = ' . (int) $args['type'];
     57            if ( ! isset( $args['content'] ) )
     58                $where['content'] = 'content = 0';
     59        } elseif ( isset( $args['period_type'] ) ) {
     60            $period_type = sanitize_key( $args['period_type'] );
     61            $type_map = [
     62                'day'   => 0,
     63                'week'  => 1,
     64                'month' => 2,
     65                'year'  => 3,
     66                'total' => 4
     67            ];
     68            if ( isset( $type_map[ $period_type ] ) ) {
     69                $where['type'] = 'type = ' . $type_map[ $period_type ];
     70                if ( ! isset( $args['content'] ) )
     71                    $where['content'] = 'content = 0';
     72            }
     73        }
     74
     75        // optional period range (e.g., for day-based ranges within a month)
     76        $range_from = null;
     77        $range_to = null;
     78
     79        if ( isset( $args['period_range'] ) && is_array( $args['period_range'] ) ) {
     80            $range = array_values( $args['period_range'] );
     81            if ( isset( $range[0], $range[1] ) ) {
     82                $range_from = (int) $range[0];
     83                $range_to = (int) $range[1];
     84            }
     85        } elseif ( isset( $args['period_from'], $args['period_to'] ) ) {
     86            $range_from = (int) $args['period_from'];
     87            $range_to = (int) $args['period_to'];
     88        }
     89
     90        if ( $range_from && $range_to ) {
     91            $range_min = min( $range_from, $range_to );
     92            $range_max = max( $range_from, $range_to );
     93
     94            $where['period'] = 'CAST( period AS SIGNED ) <= ' . $range_max . ' AND CAST( period AS SIGNED ) >= ' . $range_min;
     95
     96            // default to day type when using explicit ranges and no type set
     97            if ( ! isset( $where['type'] ) ) {
     98                $where['type'] = 'type = 0';
     99                if ( ! isset( $args['content'] ) )
     100                    $where['content'] = 'content = 0';
     101            }
     102        }
     103
    48104        // update where clause
    49         $where = apply_filters( 'pvc_get_post_views_period_where', $where, $period, $post_id );
     105        $where = apply_filters( 'pvc_get_post_views_period_where', $where, $period, $post_id, $args );
    50106
    51107        // updated where clause
     
    120176        }
    121177
    122         return (int) apply_filters( 'pvc_get_post_views', $post_views, $post_id, $period );
     178        return (int) apply_filters( 'pvc_get_post_views', $post_views, $post_id, $period, $args );
    123179    }
    124180}
  • post-views-counter/tags/1.7.5/post-views-counter.php

    r3452736 r3453097  
    33Plugin Name: Post Views Counter
    44Description: Post Views Counter allows you to collect and display how many times a post, page, or other content has been viewed in a simple, fast and reliable way.
    5 Version: 1.7.4
     5Version: 1.7.5
    66Author: dFactory
    77Author URI: https://dfactory.co/
     
    3131     *
    3232     * @class Post_Views_Counter
    33      * @version 1.7.4
     33     * @version 1.7.5
    3434     */
    3535    final class Post_Views_Counter {
     
    110110                'integrations'          => []
    111111            ],
    112             'version'   => '1.7.4'
     112            'version'   => '1.7.5'
    113113        ];
    114114
  • post-views-counter/tags/1.7.5/readme.txt

    r3452736 r3453097  
    55Requires PHP: 7.0
    66Tested up to: 6.9
    7 Stable tag: 1.7.4
     7Stable tag: 1.7.5
    88License: MIT License
    99License URI: http://opensource.org/licenses/MIT
     
    9393== Changelog ==
    9494
     95= 1.7.5 =
     96* Tweak: Optimize traffic signals database query performance.
     97* Tweak: Admin columns display priority and traffic signals comparison alignment.
     98
    9599= 1.7.4 =
    96100* New: Month-over-Month anomaly detection traffic signals in admin columns.
     
    446450== Upgrade Notice ==
    447451
    448 = 1.7.4 =
    449 Adds traffic signal anomaly detection, improves modal architecture.
     452= 1.7.5 =
     453Optimizes traffic signals database performance and tweaks admin columns display.
Note: See TracChangeset for help on using the changeset viewer.