Compare commits
1 Commits
claude/fix
...
claude/qa-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8472667418 |
145
.github/workflows/ci.yml
vendored
145
.github/workflows/ci.yml
vendored
@@ -1,27 +1,134 @@
|
|||||||
##
|
name: CI — Lint & Test
|
||||||
# Thin CI caller — peptide-news-plugin
|
|
||||||
#
|
|
||||||
# Delegates all lint/test/file-size jobs to the estate reusable workflow.
|
|
||||||
# Per estate standard: workflow_call is required so deploy.yml can gate on it.
|
|
||||||
# See: peptide-repo/peptide-e2e/.github/workflows/ci.yml@main for job definitions.
|
|
||||||
##
|
|
||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request: {}
|
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [ main ]
|
||||||
workflow_call: {}
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
# Required: calling workflow must declare contents: write so the reusable
|
|
||||||
# phpcs job can commit phpcbf auto-fixes back to the PR branch.
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
ci:
|
# ── PHP Syntax Check ─────────────────────────────────────────────
|
||||||
uses: peptide-repo/peptide-e2e/.github/workflows/ci.yml@main
|
lint-php:
|
||||||
|
name: PHP Lint (${{ matrix.php }})
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
php: ['8.1', '8.2', '8.3']
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up PHP ${{ matrix.php }}
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
tests: stubs
|
php-version: ${{ matrix.php }}
|
||||||
has_js: true
|
tools: composer
|
||||||
secrets: inherit
|
|
||||||
|
- name: Syntax check all PHP files
|
||||||
|
run: find . -name '*.php' -not -path './vendor/*' -print0 | xargs -0 -n1 php -l
|
||||||
|
|
||||||
|
# ── Security Audit ───────────────────────────────────────────────
|
||||||
|
security-audit:
|
||||||
|
name: Security Audit
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Check for common PHP security issues
|
||||||
|
run: |
|
||||||
|
echo ":: Checking for direct SQL queries without prepare..."
|
||||||
|
# Exclude uninstall.php (DROP TABLE is standard WP pattern), activator (table DDL),
|
||||||
|
# and logger (TRUNCATE) — these use $wpdb->prefix which is safe internal state.
|
||||||
|
if grep -r "query\s*(\s*['\"].*\$" --include="*.php" --exclude-dir=vendor . 2>/dev/null \
|
||||||
|
| grep -v "\\\$wpdb->prepare" \
|
||||||
|
| grep -v "uninstall\.php" \
|
||||||
|
| grep -v "class-peptide-news-activator\.php" \
|
||||||
|
| grep -v "class-peptide-news-logger\.php" \
|
||||||
|
| grep -v "DROP TABLE" \
|
||||||
|
| grep -v "TRUNCATE" \
|
||||||
|
&& [ \${PIPESTATUS[0]} -eq 0 ]; then
|
||||||
|
echo "WARNING: Found potential unescaped SQL queries. Use wpdb->prepare() for all dynamic SQL."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ":: Checking for eval() usage..."
|
||||||
|
if grep -r "eval\s*(" --include="*.php" --exclude-dir=vendor . 2>/dev/null; then
|
||||||
|
echo "ERROR: eval() found. This is a critical security risk."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ":: Checking for base64_decode without validation..."
|
||||||
|
if grep -r "base64_decode\s*(" --include="*.php" --exclude-dir=vendor . 2>/dev/null; then
|
||||||
|
echo "WARNING: Found base64_decode(). Ensure the input is properly validated."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ":: Checking for file_get_contents with user input..."
|
||||||
|
if grep -r "file_get_contents\s*(\s*\$" --include="*.php" --exclude-dir=vendor . 2>/dev/null; then
|
||||||
|
echo "WARNING: Found file_get_contents with variable. Ensure input is validated and restricted."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "All security checks passed."
|
||||||
|
|
||||||
|
# ── PHPCS Coding Standards ───────────────────────────────────────
|
||||||
|
phpcs:
|
||||||
|
name: PHPCS
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.3'
|
||||||
|
tools: composer
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: composer install --prefer-dist --no-progress
|
||||||
|
|
||||||
|
- name: Run PHPCS
|
||||||
|
run: vendor/bin/phpcs --standard=.phpcs.xml.dist
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
# ── PHPUnit Tests ────────────────────────────────────────────────
|
||||||
|
phpunit:
|
||||||
|
name: PHPUnit (${{ matrix.php }})
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
php: ['8.1', '8.2', '8.3']
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up PHP ${{ matrix.php }}
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
tools: composer
|
||||||
|
coverage: xdebug
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: composer install --prefer-dist --no-progress
|
||||||
|
|
||||||
|
- name: Run PHPUnit
|
||||||
|
run: vendor/bin/phpunit --testdox
|
||||||
|
|
||||||
|
# ── JavaScript Lint ──────────────────────────────────────────────
|
||||||
|
lint-js:
|
||||||
|
name: JS Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Node
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
|
||||||
|
- name: Check JS syntax
|
||||||
|
run: |
|
||||||
|
for f in $(find . -name '*.js' -not -path './vendor/*' -not -path './node_modules/*' -not -path '*/vendor/*'); do
|
||||||
|
node --check "$f" || exit 1
|
||||||
|
done
|
||||||
|
|||||||
8
.github/workflows/deploy.yml
vendored
8
.github/workflows/deploy.yml
vendored
@@ -4,12 +4,8 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
|
||||||
# contents: write required so the ci.yml caller can pass write permission
|
|
||||||
# through to the phpcbf auto-commit step in the reusable workflow.
|
|
||||||
# (phpcbf commit only fires on pull_request events, but GH enforces caller
|
|
||||||
# permissions at token-grant time, not at step-execution time.)
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: read
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: deploy-peptide-news-plugin
|
group: deploy-peptide-news-plugin
|
||||||
@@ -23,7 +19,7 @@ jobs:
|
|||||||
deploy:
|
deploy:
|
||||||
name: Deploy (shared pipeline)
|
name: Deploy (shared pipeline)
|
||||||
needs: test
|
needs: test
|
||||||
uses: peptide-repo/peptide-e2e/.github/workflows/deploy-app.yml@main
|
uses: peptiderepo/peptide-e2e/.github/workflows/deploy-app.yml@main
|
||||||
with:
|
with:
|
||||||
target_path: wp-content/plugins/peptide-news-plugin
|
target_path: wp-content/plugins/peptide-news-plugin
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|||||||
58
.github/workflows/security-audit.yml
vendored
58
.github/workflows/security-audit.yml
vendored
@@ -1,58 +0,0 @@
|
|||||||
##
|
|
||||||
# Security audit — peptide-news-plugin
|
|
||||||
#
|
|
||||||
# Standalone workflow kept separate from the estate CI caller so it can evolve
|
|
||||||
# independently and run on every PR without being bundled into the reusable pipeline.
|
|
||||||
# Checks for: unescaped SQL, eval(), base64_decode(), file_get_contents with user input.
|
|
||||||
##
|
|
||||||
name: Security Audit
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request: {}
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
security-audit:
|
|
||||||
name: Security Audit
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Check for common PHP security issues
|
|
||||||
run: |
|
|
||||||
echo ":: Checking for direct SQL queries without prepare..."
|
|
||||||
# Exclude uninstall.php (DROP TABLE is standard WP pattern), activator (table DDL),
|
|
||||||
# and logger (TRUNCATE) — these use $wpdb->prefix which is safe internal state.
|
|
||||||
if grep -r "query\s*(\s*['\"].*\$" --include="*.php" --exclude-dir=vendor . 2>/dev/null \
|
|
||||||
| grep -v "\$wpdb->prepare" \
|
|
||||||
| grep -v "uninstall\.php" \
|
|
||||||
| grep -v "class-peptide-news-activator\.php" \
|
|
||||||
| grep -v "class-peptide-news-logger\.php" \
|
|
||||||
| grep -v "DROP TABLE" \
|
|
||||||
| grep -v "TRUNCATE" \
|
|
||||||
&& [ ${PIPESTATUS[0]} -eq 0 ]; then
|
|
||||||
echo "WARNING: Found potential unescaped SQL queries. Use wpdb->prepare() for all dynamic SQL."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ":: Checking for eval() usage..."
|
|
||||||
if grep -r "eval\s*(" --include="*.php" --exclude-dir=vendor . 2>/dev/null; then
|
|
||||||
echo "ERROR: eval() found. This is a critical security risk."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ":: Checking for base64_decode without validation..."
|
|
||||||
if grep -r "base64_decode\s*(" --include="*.php" --exclude-dir=vendor . 2>/dev/null; then
|
|
||||||
echo "WARNING: Found base64_decode(). Ensure the input is properly validated."
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ":: Checking for file_get_contents with user input..."
|
|
||||||
if grep -r "file_get_contents\s*(\s*\$" --include="*.php" --exclude-dir=vendor . 2>/dev/null; then
|
|
||||||
echo "WARNING: Found file_get_contents with variable. Ensure input is validated and restricted."
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "All security checks passed."
|
|
||||||
@@ -73,13 +73,9 @@
|
|||||||
<type>warning</type>
|
<type>warning</type>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<!--
|
<!-- PHP Compatibility — target PHP 7.4+ -->
|
||||||
PHPCompatibilityWP removed: the estate CI reusable workflow installs
|
<config name="testVersion" value="7.4-"/>
|
||||||
only wp-coding-standards/wpcs + phpcsutils + phpcsextra via global
|
<rule ref="PHPCompatibilityWP"/>
|
||||||
composer require. phpcompatibility/phpcompatibility-wp is not available
|
|
||||||
in that environment. PHP version targeting is covered by the lint-php
|
|
||||||
matrix job (8.1 / 8.2 / 8.3 syntax check).
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- Allow long lines in SQL queries up to 200 chars -->
|
<!-- Allow long lines in SQL queries up to 200 chars -->
|
||||||
<rule ref="Generic.Files.LineLength">
|
<rule ref="Generic.Files.LineLength">
|
||||||
|
|||||||
36
CHANGELOG.md
36
CHANGELOG.md
@@ -1,36 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
All notable changes to Peptide News Plugin are documented here.
|
|
||||||
Format: [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
||||||
Versioning: [Semantic Versioning](https://semver.org/).
|
|
||||||
|
|
||||||
## [2.5.1] - 2026-06-17
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
- PHP 8.3 `TypeError` on Articles admin page: `number_format()` rejects the numeric string returned by `$wpdb->get_var()`. Cast `$total` to `(int)` at point of assignment in `admin/partials/articles-list.php` (#32).
|
|
||||||
- PHP 8.3 `TypeError` on Analytics Dashboard page: `number_format()` rejects SUM aggregate strings returned by `$wpdb->get_results()`. Cast `$article->total_clicks` and `$article->total_unique` to `(int)` inline in `admin/partials/dashboard.php` (same-class fix, no PR number — follow-on to #32).
|
|
||||||
|
|
||||||
## [2.5.0] — 2026-06-16
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- **CI standardization (estate wave 2):** Replace per-repo CI jobs in
|
|
||||||
`ci.yml` with a thin caller of `peptiderepo/peptide-e2e/.github/workflows/ci.yml@main`
|
|
||||||
(`tests: stubs`, `has_js: true`). Adds `workflow_call` trigger so `deploy.yml`
|
|
||||||
gate remains valid.
|
|
||||||
- Extract `security-audit` job from `ci.yml` into standalone
|
|
||||||
`.github/workflows/security-audit.yml` (kept as-is, unique to this repo).
|
|
||||||
- `deploy.yml`: elevate permissions to `contents: write` so the nested
|
|
||||||
phpcbf commit-back step in the reusable workflow receives the correct token scope.
|
|
||||||
- `composer.json`: pin `test` script to `vendor/bin/phpunit --configuration phpunit.xml.dist`
|
|
||||||
for explicit path resolution in CI; pin `lint` / `lint:fix` to `vendor/bin/`.
|
|
||||||
- `phpunit.xml.dist`: add XSD reference for PHPUnit 9.6; drop deprecated
|
|
||||||
`convertErrorsToExceptions`, `convertNoticesToExceptions`, `convertWarningsToExceptions`
|
|
||||||
attributes.
|
|
||||||
|
|
||||||
### Notes
|
|
||||||
- `rollback.yml` and `cto-review.yml` and `main-push-audit.yml` unchanged — unique / estate-separate.
|
|
||||||
- No functional code changes in this commit.
|
|
||||||
|
|
||||||
## Prior history
|
|
||||||
|
|
||||||
Versions prior to 2.5.0 were not tracked in a CHANGELOG. See git log for details.
|
|
||||||
@@ -19,7 +19,7 @@ $per_page = 25;
|
|||||||
$offset = ( $page - 1 ) * $per_page;
|
$offset = ( $page - 1 ) * $per_page;
|
||||||
|
|
||||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
$total = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$table}" );
|
$total = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}" );
|
||||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
$articles = $wpdb->get_results( $wpdb->prepare(
|
$articles = $wpdb->get_results( $wpdb->prepare(
|
||||||
"SELECT * FROM {$table} ORDER BY published_at DESC LIMIT %d OFFSET %d",
|
"SELECT * FROM {$table} ORDER BY published_at DESC LIMIT %d OFFSET %d",
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ $total_articles = count( $top_articles );
|
|||||||
<td><a href="<?php echo esc_url( $article->source_url ); ?>" target="_blank" rel="noopener"><?php echo esc_html( $article->title ); ?></a></td>
|
<td><a href="<?php echo esc_url( $article->source_url ); ?>" target="_blank" rel="noopener"><?php echo esc_html( $article->title ); ?></a></td>
|
||||||
<td><?php echo esc_html( $article->source ); ?></td>
|
<td><?php echo esc_html( $article->source ); ?></td>
|
||||||
<td><?php echo esc_html( $article->categories ); ?></td>
|
<td><?php echo esc_html( $article->categories ); ?></td>
|
||||||
<td><strong><?php echo esc_html( number_format( (int) $article->total_clicks ) ); ?></strong></td>
|
<td><strong><?php echo esc_html( number_format( $article->total_clicks ) ); ?></strong></td>
|
||||||
<td><?php echo esc_html( number_format( (int) $article->total_unique ) ); ?></td>
|
<td><?php echo esc_html( number_format( $article->total_unique ) ); ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|||||||
@@ -21,9 +21,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vendor/bin/phpunit --configuration phpunit.xml.dist",
|
"test": "phpunit",
|
||||||
"lint": "vendor/bin/phpcs",
|
"lint": "phpcs",
|
||||||
"lint:fix": "vendor/bin/phpcbf",
|
"lint:fix": "phpcbf",
|
||||||
"check": [
|
"check": [
|
||||||
"@lint",
|
"@lint",
|
||||||
"@test"
|
"@test"
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class Peptide_News_Content_Filter_Rules {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( false !== strpos( $body_text, $keyword ) ) {
|
if ( false !== strpos( $body_text, $keyword ) ) {
|
||||||
++$body_matches;
|
$body_matches++;
|
||||||
$matched_keys[] = $keyword;
|
$matched_keys[] = $keyword;
|
||||||
$score += 15;
|
$score += 15;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class Peptide_News_Content_Filter {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ( 'promotional' === $result['verdict'] ) {
|
if ( 'promotional' === $result['verdict'] ) {
|
||||||
++$removed;
|
$removed++;
|
||||||
self::log( sprintf( 'Blocked (rule: %s, score: %d): %s', $result['rule'], $result['score'], $article['title'] ) );
|
self::log( sprintf( 'Blocked (rule: %s, score: %d): %s', $result['rule'], $result['score'], $article['title'] ) );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -87,10 +87,10 @@ class Peptide_News_Content_Filter {
|
|||||||
// Borderline articles go to LLM for a second opinion.
|
// Borderline articles go to LLM for a second opinion.
|
||||||
if ( 'borderline' === $result['verdict'] && self::is_llm_filter_enabled() ) {
|
if ( 'borderline' === $result['verdict'] && self::is_llm_filter_enabled() ) {
|
||||||
$llm_verdict = self::classify_with_llm( $article );
|
$llm_verdict = self::classify_with_llm( $article );
|
||||||
++$llm_checked;
|
$llm_checked++;
|
||||||
|
|
||||||
if ( 'promotional' === $llm_verdict ) {
|
if ( 'promotional' === $llm_verdict ) {
|
||||||
++$removed;
|
$removed++;
|
||||||
self::log( sprintf( 'Blocked (LLM confirmed borderline): %s', $article['title'] ) );
|
self::log( sprintf( 'Blocked (LLM confirmed borderline): %s', $article['title'] ) );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class Peptide_News_Fetcher {
|
|||||||
$stored = 0;
|
$stored = 0;
|
||||||
foreach ( $articles as $article ) {
|
foreach ( $articles as $article ) {
|
||||||
if ( $this->store_article( $article ) ) {
|
if ( $this->store_article( $article ) ) {
|
||||||
++$stored;
|
$stored++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ class Peptide_News_LLM_Client {
|
|||||||
$retry_after = wp_remote_retrieve_header( $response, 'retry-after' );
|
$retry_after = wp_remote_retrieve_header( $response, 'retry-after' );
|
||||||
$wait = $retry_after ? min( (int) $retry_after, 30 ) : $backoff;
|
$wait = $retry_after ? min( (int) $retry_after, 30 ) : $backoff;
|
||||||
sleep( $wait );
|
sleep( $wait );
|
||||||
++$retries;
|
$retries++;
|
||||||
$backoff *= 2;
|
$backoff *= 2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ class Peptide_News_LLM {
|
|||||||
$result = self::process_article( $article );
|
$result = self::process_article( $article );
|
||||||
|
|
||||||
if ( ! empty( $result['success'] ) ) {
|
if ( ! empty( $result['success'] ) ) {
|
||||||
++$processed;
|
$processed++;
|
||||||
}
|
}
|
||||||
if ( ! empty( $result['errors'] ) ) {
|
if ( ! empty( $result['errors'] ) ) {
|
||||||
$last_errors = $result['errors'];
|
$last_errors = $result['errors'];
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ class Peptide_News_Rest_API {
|
|||||||
if ( ! preg_match( '/^\\d{4}-\\d{2}-\\d{2}$/', $value ) ) {
|
if ( ! preg_match( '/^\\d{4}-\\d{2}-\\d{2}$/', $value ) ) {
|
||||||
return new WP_Error(
|
return new WP_Error(
|
||||||
'rest_invalid_date',
|
'rest_invalid_date',
|
||||||
/* translators: %s: REST API parameter name */
|
|
||||||
sprintf( __( 'Invalid date format for %s. Expected Y-m-d.', 'peptide-news' ), $param ),
|
sprintf( __( 'Invalid date format for %s. Expected Y-m-d.', 'peptide-news' ), $param ),
|
||||||
array( 'status' => 400 )
|
array( 'status' => 400 )
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class Peptide_News_Source_Resolver {
|
|||||||
|
|
||||||
if ( ! empty( $new_source ) && $new_source !== $article->source ) {
|
if ( ! empty( $new_source ) && $new_source !== $article->source ) {
|
||||||
$wpdb->update( $table, array( 'source' => $new_source ), array( 'id' => $article->id ), array( '%s' ), array( '%d' ) );
|
$wpdb->update( $table, array( 'source' => $new_source ), array( 'id' => $article->id ), array( '%s' ), array( '%d' ) );
|
||||||
++$updated;
|
$updated++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Plugin Name: Peptide News Aggregator
|
* Plugin Name: Peptide News Aggregator
|
||||||
* Plugin URI: https://github.com/peptiderepo/peptide-news-plugin
|
* Plugin URI: https://github.com/peptiderepo/peptide-news-plugin
|
||||||
* Description: Aggregates and displays the latest peptide research news from multiple sources with click analytics and trend reporting.
|
* Description: Aggregates and displays the latest peptide research news from multiple sources with click analytics and trend reporting.
|
||||||
* Version: 2.5.1
|
* Version: 2.4.1
|
||||||
* Author: peptiderepo
|
* Author: peptiderepo
|
||||||
* Author URI: https://github.com/peptiderepo
|
* Author URI: https://github.com/peptiderepo
|
||||||
* License: GPL-2.0+
|
* License: GPL-2.0+
|
||||||
@@ -24,7 +24,7 @@ if ( ! defined( 'WPINC' ) ) {
|
|||||||
/**
|
/**
|
||||||
* Current plugin version — follows SemVer.
|
* Current plugin version — follows SemVer.
|
||||||
*/
|
*/
|
||||||
define( 'PEPTIDE_NEWS_VERSION', '2.5.1' );
|
define( 'PEPTIDE_NEWS_VERSION', '2.4.0' );
|
||||||
define( 'PEPTIDE_NEWS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
define( 'PEPTIDE_NEWS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
||||||
define( 'PEPTIDE_NEWS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
define( 'PEPTIDE_NEWS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||||
define( 'PEPTIDE_NEWS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
define( 'PEPTIDE_NEWS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<phpunit
|
<phpunit
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
|
|
||||||
bootstrap="tests/bootstrap.php"
|
bootstrap="tests/bootstrap.php"
|
||||||
backupGlobals="false"
|
backupGlobals="false"
|
||||||
colors="true"
|
colors="true"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="unit">
|
<testsuite name="unit">
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Test that articles list total count is cast to int.
|
|
||||||
*
|
|
||||||
* @package Peptide_News
|
|
||||||
*/
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class ArticlesListTotalCastTest extends TestCase {
|
|
||||||
/**
|
|
||||||
* Verify that $wpdb->get_var returning a numeric string does not
|
|
||||||
* cause a TypeError in number_format() (PHP 8.3 strict typing).
|
|
||||||
*/
|
|
||||||
public function test_total_cast_prevents_type_error() {
|
|
||||||
$total_as_string = '451'; // what $wpdb->get_var() returns
|
|
||||||
$total = (int) $total_as_string;
|
|
||||||
$this->assertIsInt( $total );
|
|
||||||
$this->assertSame( 451, $total );
|
|
||||||
// This should not throw TypeError on PHP 8.3
|
|
||||||
$formatted = number_format( $total );
|
|
||||||
$this->assertSame( '451', $formatted );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify null return (missing table) results in 0, not a TypeError.
|
|
||||||
*/
|
|
||||||
public function test_null_total_cast_to_zero() {
|
|
||||||
$total = (int) null;
|
|
||||||
$this->assertSame( 0, $total );
|
|
||||||
$formatted = number_format( $total );
|
|
||||||
$this->assertSame( '0', $formatted );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Test that dashboard top-articles SUM columns are cast to int before number_format().
|
|
||||||
*
|
|
||||||
* @package Peptide_News
|
|
||||||
*/
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class DashboardTopArticlesCastTest extends TestCase {
|
|
||||||
/**
|
|
||||||
* Verify that SUM() aggregate strings from $wpdb->get_results() do not
|
|
||||||
* cause a TypeError in number_format() (PHP 8.3 strict typing).
|
|
||||||
* Mirrors the fix in admin/partials/dashboard.php lines 108-109.
|
|
||||||
*/
|
|
||||||
public function test_total_clicks_cast_prevents_type_error() {
|
|
||||||
$article = (object) array(
|
|
||||||
'total_clicks' => '1234', // numeric string from $wpdb->get_results()
|
|
||||||
'total_unique' => '987',
|
|
||||||
);
|
|
||||||
// Simulate the inline cast applied in dashboard.php
|
|
||||||
$formatted_clicks = number_format( (int) $article->total_clicks );
|
|
||||||
$formatted_unique = number_format( (int) $article->total_unique );
|
|
||||||
$this->assertSame( '1,234', $formatted_clicks );
|
|
||||||
$this->assertSame( '987', $formatted_unique );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify NULL SUM() (no rows) results in 0, not a TypeError.
|
|
||||||
*/
|
|
||||||
public function test_null_sum_cast_to_zero() {
|
|
||||||
$article = (object) array(
|
|
||||||
'total_clicks' => null,
|
|
||||||
'total_unique' => null,
|
|
||||||
);
|
|
||||||
$formatted_clicks = number_format( (int) $article->total_clicks );
|
|
||||||
$formatted_unique = number_format( (int) $article->total_unique );
|
|
||||||
$this->assertSame( '0', $formatted_clicks );
|
|
||||||
$this->assertSame( '0', $formatted_unique );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user