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
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