Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/workflows/sync-known-plugins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Sync known-plugins.json to wp.org SVN

on:
schedule:
- cron: '0 3 * * *'
push:
branches:
- main
paths:
- 'known-plugins/known-plugins.json'
workflow_dispatch:

jobs:
sync:
name: Publish known-plugins.json to wp.org assets
runs-on: ubuntu-latest
steps:
- name: Checkout repository (main only)
uses: actions/checkout@v4
with:
ref: main

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none

- name: Validate known-plugins.json
run: php bin/validate-known-plugins.php

- name: Install Subversion
run: sudo apt-get update && sudo apt-get install -y subversion

- name: Sparse-checkout SVN assets
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
run: |
svn checkout \
--depth immediates \
--username "$SVN_USERNAME" \
--password "$SVN_PASSWORD" \
--non-interactive \
--no-auth-cache \
https://plugins.svn.wordpress.org/aaa-option-optimizer/ svn-repo
svn update --set-depth infinity svn-repo/assets

- name: Copy JSON into assets and detect changes
id: diff
run: |
cp known-plugins/known-plugins.json svn-repo/assets/known-plugins.json
cd svn-repo
# Add the file if it's new
if ! svn info assets/known-plugins.json >/dev/null 2>&1; then
svn add assets/known-plugins.json
fi
# Capture status; empty means nothing to commit
STATUS=$(svn status assets/known-plugins.json)
echo "svn-status: '$STATUS'"
if [ -z "$STATUS" ]; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

- name: Commit to SVN
if: steps.diff.outputs.changed == 'true'
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
run: |
cd svn-repo
svn commit assets/known-plugins.json \
--username "$SVN_USERNAME" \
--password "$SVN_PASSWORD" \
--non-interactive \
--no-auth-cache \
-m "Update assets/known-plugins.json"

- name: No changes
if: steps.diff.outputs.changed != 'true'
run: echo "known-plugins.json on SVN is already up to date."
2 changes: 2 additions & 0 deletions aaa-option-optimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ function aaa_option_optimizer_activation() {
function aaa_option_optimizer_deactivation() {
$aaa_option_value = get_option( 'option_optimizer' );
update_option( 'option_optimizer', $aaa_option_value, false );

wp_clear_scheduled_hook( Progress_Planner\OptionOptimizer\Known_Plugins::CRON_HOOK );
}

/**
Expand Down
94 changes: 94 additions & 0 deletions bin/validate-known-plugins.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/**
* Validate known-plugins/known-plugins.json before publishing.
*
* Exits non-zero on any problem so CI can fail.
*
* @package Progress_Planner\OptionOptimizer
*/

$file = dirname( __DIR__ ) . '/known-plugins/known-plugins.json';

if ( ! file_exists( $file ) ) {
fwrite( STDERR, "Missing file: {$file}\n" );
exit( 1 );
}

$raw = file_get_contents( $file );
if ( false === $raw || '' === trim( $raw ) ) {
fwrite( STDERR, "Empty file: {$file}\n" );
exit( 1 );
}

$data = json_decode( $raw, true );
if ( JSON_ERROR_NONE !== json_last_error() ) {
fwrite( STDERR, 'Invalid JSON: ' . json_last_error_msg() . "\n" );
exit( 1 );
}

if ( ! is_array( $data ) || empty( $data ) ) {
fwrite( STDERR, "Top-level JSON must be a non-empty object.\n" );
exit( 1 );
}

$errors = [];
$warnings = [];
$seen_prefixes = [];

foreach ( $data as $slug => $entry ) {
if ( ! is_string( $slug ) || '' === $slug ) {
$errors[] = 'Slug must be a non-empty string.';
continue;
}

if ( ! is_array( $entry ) ) {
$errors[] = "Entry for '{$slug}' must be an object.";
continue;
}

if ( empty( $entry['name'] ) || ! is_string( $entry['name'] ) ) {
$errors[] = "Entry '{$slug}' missing 'name' string.";
}

if ( empty( $entry['option_prefixes'] ) || ! is_array( $entry['option_prefixes'] ) ) {
$errors[] = "Entry '{$slug}' missing non-empty 'option_prefixes' array.";
continue;
}

foreach ( $entry['option_prefixes'] as $prefix ) {
if ( ! is_string( $prefix ) || '' === $prefix ) {
$errors[] = "Entry '{$slug}' has empty/non-string prefix.";
continue;
}

// Reject dangerously generic prefixes that would match thousands of options.
if ( strlen( $prefix ) < 3 ) {
$errors[] = "Entry '{$slug}' prefix '{$prefix}' is too short (<3 chars).";
}

if ( in_array( $prefix, [ 'wp_', 'option_', '_transient_' ], true ) ) {
$errors[] = "Entry '{$slug}' prefix '{$prefix}' is reserved/dangerous.";
}

if ( isset( $seen_prefixes[ $prefix ] ) && $seen_prefixes[ $prefix ] !== $slug ) {
$warnings[] = "Prefix '{$prefix}' claimed by both '{$seen_prefixes[ $prefix ]}' and '{$slug}'.";
}
$seen_prefixes[ $prefix ] = $slug;
}
}

foreach ( $warnings as $warn ) {
fwrite( STDERR, "WARNING: {$warn}\n" );
}

if ( ! empty( $errors ) ) {
fwrite( STDERR, "Validation failed:\n" );
foreach ( $errors as $err ) {
fwrite( STDERR, " - {$err}\n" );
}
exit( 1 );
}

$count = count( $data );
echo "OK: {$count} entries validated.\n";
exit( 0 );
32 changes: 32 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,38 @@ div.dt-container .dt-input {
.aaa-option-optimizer-popover__close:hover {
cursor: pointer;
}
.aaa-report-trigger {
background: none;
border: 0;
padding: 0;
font: inherit;
color: inherit;
cursor: pointer;
line-height: 1.4;
text-align: left;
}
.aaa-report-trigger .aaa-report-trigger__action {
display: block;
color: #2271b1;
text-decoration: underline;
text-underline-offset: 2px;
}
.aaa-report-trigger:hover .aaa-report-trigger__action,
.aaa-report-trigger:focus-visible .aaa-report-trigger__action {
color: #135e96;
}
.aaa-report-popover {
min-width: 380px;
min-height: auto;
}
.aaa-report-popover .aaa-report-input {
width: 100%;
margin-top: 4px;
}
.aaa-report-popover .aaa-report-status {
min-height: 1.2em;
margin: 8px 0;
}
.aaa-option-optimizer-tabs {
clear: both;
display: flex;
Expand Down
Loading
Loading