Fix pre-existing syntax errors in analytics and REST API classes

- analytics.php line 38: mismatched quotes on session_id array key
- analytics.php line 246: invalid escape before concatenation operator
- analytics.php line 250: COuNT typo → COUNT
- analytics.php line 252: NULIF typo → NULLIF
- rest-api.php line 54: stray # commenting out foreach variable

These bugs predate the content filter feature but were caught by the
new CI pipeline's PHP lint job.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Terence Ong
2026-04-06 14:19:15 +07:00
parent e6887e810f
commit c9be4ceb39
2 changed files with 5 additions and 5 deletions

View File

@@ -35,7 +35,7 @@ class Peptide_News_Analytics {
'user_agent' => sanitize_text_field( isset( $meta['user_agent'] ) ? $meta['user_agent'] : '' ), 'user_agent' => sanitize_text_field( isset( $meta['user_agent'] ) ? $meta['user_agent'] : '' ),
'referrer_url' => esc_url_raw( isset( $meta['referrer'] ) ? $meta['referrer'] : '' ), 'referrer_url' => esc_url_raw( isset( $meta['referrer'] ) ? $meta['referrer'] : '' ),
'page_url' => esc_url_raw( isset( $meta['page_url'] ) ? $meta['page_url'] : '' ), 'page_url' => esc_url_raw( isset( $meta['page_url'] ) ? $meta['page_url'] : '' ),
"session_id' => sanitize_text_field( isset( $meta['session_id'] ) ? $meta['session_id'] : '' ), 'session_id' => sanitize_text_field( isset( $meta['session_id'] ) ? $meta['session_id'] : '' ),
'user_id' => is_user_logged_in() ? get_current_user_id() : null, 'user_id' => is_user_logged_in() ? get_current_user_id() : null,
'device_type' => sanitize_text_field( self::detect_device( isset( $meta['user_agent'] ) ? $meta['user_agent'] : '' ) ), 'device_type' => sanitize_text_field( self::detect_device( isset( $meta['user_agent'] ) ? $meta['user_agent'] : '' ) ),
); );
@@ -243,13 +243,13 @@ class Peptide_News_Analytics {
global $wpdb; global $wpdb;
$stats_table = $wpdb->prefix . 'peptide_news_daily_stats'; $stats_table = $wpdb->prefix . 'peptide_news_daily_stats';
$articles_table = $wpdb->prefix \. 'peptide_news_articles'; $articles_table = $wpdb->prefix . 'peptide_news_articles';
return $wpdb->get_results( $wpdb->prepare( return $wpdb->get_results( $wpdb->prepare(
"SELECT a.source, "SELECT a.source,
COuNT(DISTINCT a.id) AS article_count, COUNT(DISTINCT a.id) AS article_count,
SUM(s.click_count) AS total_clicks, SUM(s.click_count) AS total_clicks,
ROUND(IFNULL(SUM(s.click_count) / NULIF(COUNT(DISTINCT a.id), 0), 0), 1) AS avg_clicks_per_article ROUND(IFNULL(SUM(s.click_count) / NULLIF(COUNT(DISTINCT a.id), 0), 0), 1) AS avg_clicks_per_article
FROM {$stats_table} s FROM {$stats_table} s
INNER JOIN {$articles_table} a ON a.id = s.article_id INNER JOIN {$articles_table} a ON a.id = s.article_id
WHERE s.stat_date BETWEEN %s AND %s WHERE s.stat_date BETWEEN %s AND %s

View File

@@ -51,7 +51,7 @@ class Peptide_News_Rest_API {
'/analytics/export' => 'get_export', '/analytics/export' => 'get_export',
); );
foreach( #$analytics_routes as $route => $callback ) { foreach ( $analytics_routes as $route => $callback ) {
register_rest_route( self::API_NAMESPACE, $route, array( register_rest_route( self::API_NAMESPACE, $route, array(
'methods' => 'GET', 'methods' => 'GET',
'callback' => array( $this, $callback ), 'callback' => array( $this, $callback ),