From 08477f9e984a579bdec579337c32bba7dd02d7bd Mon Sep 17 00:00:00 2001
From: peptiderepo
Date: Sun, 12 Apr 2026 17:10:27 +0700
Subject: [PATCH] fix: resolve PHPCS errors in admin class
- Move inline closures to multi-line format (ContentAfterBrace)
- Break associative array onto multiple lines (ArrayDeclarationSpacing)
- Move sprintf arguments after opening parenthesis to new line
- Escape output with intval() and esc_html() (OutputNotEscaped)
- Fix precision alignment on concatenated strings
- Fix operator spacing in ternary expression
Co-Authored-By: Claude Opus 4.6
---
admin/class-peptide-news-admin.php | 74 +++++++++++++++++-------------
1 file changed, 43 insertions(+), 31 deletions(-)
diff --git a/admin/class-peptide-news-admin.php b/admin/class-peptide-news-admin.php
index 98a71b5..eb7465b 100644
--- a/admin/class-peptide-news-admin.php
+++ b/admin/class-peptide-news-admin.php
@@ -244,28 +244,32 @@ class Peptide_News_Admin {
*/
private function get_sanitize_callback( $key ) {
$callbacks = array(
- 'fetch_interval' => 'sanitize_text_field',
- 'articles_count' => 'absint',
- 'search_keywords' => 'sanitize_text_field',
- 'rss_enabled' => 'absint',
- 'rss_feeds' => 'sanitize_textarea_field',
- 'newsapi_enabled' => 'absint',
- 'newsapi_key' => function ( $value ) { return $this->sanitize_api_key( $value, 'peptide_news_newsapi_key' ); },
- 'article_retention' => 'absint',
- 'analytics_retention' => 'absint',
- 'anonymize_ip' => 'absint',
- 'filter_enabled' => 'absint',
- 'filter_sensitivity' => 'sanitize_text_field',
- 'filter_llm_enabled' => 'absint',
- 'filter_llm_model' => array( $this, 'sanitize_model_id' ),
- 'filter_title_keywords' => 'sanitize_textarea_field',
- 'filter_body_keywords' => 'sanitize_textarea_field',
- 'filter_blocked_domains' => 'sanitize_textarea_field',
- 'llm_enabled' => 'absint',
- 'openrouter_api_key' => function ( $value ) { return $this->sanitize_api_key( $value, 'peptide_news_openrouter_api_key' ); },
- 'llm_keywords_model' => array( $this, 'sanitize_model_id' ),
- 'llm_summary_model' => array( $this, 'sanitize_model_id' ),
- 'llm_max_articles' => 'absint',
+ 'fetch_interval' => 'sanitize_text_field',
+ 'articles_count' => 'absint',
+ 'search_keywords' => 'sanitize_text_field',
+ 'rss_enabled' => 'absint',
+ 'rss_feeds' => 'sanitize_textarea_field',
+ 'newsapi_enabled' => 'absint',
+ 'newsapi_key' => function ( $value ) {
+ return $this->sanitize_api_key( $value, 'peptide_news_newsapi_key' );
+ },
+ 'article_retention' => 'absint',
+ 'analytics_retention' => 'absint',
+ 'anonymize_ip' => 'absint',
+ 'filter_enabled' => 'absint',
+ 'filter_sensitivity' => 'sanitize_text_field',
+ 'filter_llm_enabled' => 'absint',
+ 'filter_llm_model' => array( $this, 'sanitize_model_id' ),
+ 'filter_title_keywords' => 'sanitize_textarea_field',
+ 'filter_body_keywords' => 'sanitize_textarea_field',
+ 'filter_blocked_domains' => 'sanitize_textarea_field',
+ 'llm_enabled' => 'absint',
+ 'openrouter_api_key' => function ( $value ) {
+ return $this->sanitize_api_key( $value, 'peptide_news_openrouter_api_key' );
+ },
+ 'llm_keywords_model' => array( $this, 'sanitize_model_id' ),
+ 'llm_summary_model' => array( $this, 'sanitize_model_id' ),
+ 'llm_max_articles' => 'absint',
);
return isset( $callbacks[ $key ] ) ? $callbacks[ $key ] : 'sanitize_text_field';
@@ -550,7 +554,13 @@ class Peptide_News_Admin {
);
echo '' . wp_kses(
__( 'Get an API key at openrouter.ai/keys.', 'peptide-news' ),
- array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array() ) )
+ array(
+ 'a' => array(
+ 'href' => array(),
+ 'target' => array(),
+ 'rel' => array(),
+ ),
+ )
) . '
';
}
@@ -718,13 +728,15 @@ class Peptide_News_Admin {
if ( $last_fetch ) {
$extra_info = '';
if ( isset( $last_fetch['filtered_out'] ) && $last_fetch['filtered_out'] > 0 ) {
- $extra_info .= sprintf( ' | %s: %d',
+ $extra_info .= sprintf(
+ ' | %s: %d',
esc_html__( 'Filtered out', 'peptide-news' ),
$last_fetch['filtered_out']
);
}
if ( isset( $last_fetch['ai_processed'] ) ) {
- $extra_info .= sprintf( ' | %s: %d',
+ $extra_info .= sprintf(
+ ' | %s: %d',
esc_html__( 'AI analyzed', 'peptide-news' ),
$last_fetch['ai_processed']
);
@@ -734,10 +746,10 @@ class Peptide_News_Admin {
esc_html__( 'Last fetch', 'peptide-news' ),
esc_html( $last_fetch['time'] ),
esc_html__( 'Found', 'peptide-news' ),
- $last_fetch['found'],
+ intval( $last_fetch['found'] ),
esc_html__( 'New stored', 'peptide-news' ),
- $last_fetch['new_stored'],
- $extra_info
+ intval( $last_fetch['new_stored'] ),
+ esc_html( $extra_info )
);
}
@@ -751,9 +763,9 @@ class Peptide_News_Admin {
// Shortcode usage info.
echo '' . esc_html__( 'Usage', 'peptide-news' ) . '
';
echo '' . esc_html__( 'Shortcode:', 'peptide-news' ) . ' [peptide_news] ' .
- esc_html__( 'or', 'peptide-news' ) . ' [peptide_news count="5"]
';
+ esc_html__( 'or', 'peptide-news' ) . ' [peptide_news count="5"]
';
echo '' . esc_html__( 'Widget:', 'peptide-news' ) . ' ' .
- esc_html__( 'Add "Peptide News" from Appearance > Widgets.', 'peptide-news' ) . '
';
+ esc_html__( 'Add "Peptide News" from Appearance > Widgets.', 'peptide-news' ) . '';
// ── Plugin Log Viewer ──────────────────────────────────────────
echo '' . esc_html__( 'Plugin Log', 'peptide-news' ) . '
';
@@ -909,7 +921,7 @@ class Peptide_News_Admin {
$raw_start = isset( $_GET['start_date'] ) ? sanitize_text_field( wp_unslash( $_GET['start_date'] ) ) : '';
$raw_end = isset( $_GET['end_date'] ) ? sanitize_text_field( wp_unslash( $_GET['end_date'] ) ) : '';
$start_date = preg_match( '/^\d{4}-\d{2}-\d{2}$/', $raw_start ) ? $raw_start : gmdate( 'Y-m-d', strtotime( '-30 days' ) );
- $end_date = preg_match( '/^\d{4}-\d{2}-\d{2}$/', $raw_end ) ? $raw_end : gmdate( 'Y-m-d' );
+ $end_date = preg_match( '/^\d{4}-\d{2}-\d{2}$/', $raw_end ) ? $raw_end : gmdate( 'Y-m-d' );
$data = Peptide_News_Analytics::export_clicks_csv( $start_date, $end_date );