/**
* ============================================================
* SYMBOLIC CACHE PURGE CONSOLE โ FULL DASHBOARD WIDGET
* ============================================================
*/
add_action('wp_dashboard_setup', function () {
wp_add_dashboard_widget(
'symbolic_thumbnail_dashboard_widget',
'๐ Thumbnail Overlay + Symbolic Purge',
'symbolic_render_thumbnail_dashboard_widget'
);
});
/**
* ------------------------------------------------------------
* WIDGET RENDERER
* ------------------------------------------------------------
*/
function symbolic_render_thumbnail_dashboard_widget() {
// Run scan
$scan = symbolic_scan_uploads();
echo "
";
echo "
๐ Symbolic Thumbnail Overlay + Purge Console
";
// Action buttons
echo "
";
// Entropy summary
echo "
Entropy Summary
";
foreach ($scan['summary'] as $glyph => $count) {
$class = symbolic_entropy_class($glyph);
echo "
{$glyph} โ
{$count} flagged
";
}
// Regrowth list
echo "
๐ฟ Regrowth Candidates (" . count($scan['regrowth']) . ")
";
if (!empty($scan['regrowth'])) {
echo "
";
foreach ($scan['regrowth'] as $item) {
$class = symbolic_entropy_class($item['entropy']);
echo "- {$item['entropy']} {$item['path']}
";
}
echo "
";
} else {
echo "
None eligible yet.
";
}
// Timestamp
$stamp = symbolic_timestamp();
echo "
Last scan: {$stamp['local']} ({$stamp['relative']})
";
echo "
";
// Inline JS
echo symbolic_
_js();
// Inline CSS
echo symbolic_widget_css();
}
/**
* ------------------------------------------------------------
* SCANNER
* ------------------------------------------------------------
*/
function symbolic_scan_uploads() {
$baseUploads = WP_CONTENT_DIR . '/uploads';
$startYear = 2016;
$endYear = (int) date('Y');
$summary = ['๐ฑ'=>0,'๐'=>0,'๐ชฆ'=>0];
$regrowthList = [];
for ($year = $startYear; $year <= $endYear; $year++) {
for ($month = 1; $month <= 12; $month++) {
$folder = sprintf('%s/%d/%02d', $baseUploads, $year, $month);
if (!is_dir($folder)) continue;
$files = glob($folder . '/*.{jpg,jpeg,png,avif,webp}', GLOB_BRACE);
if (empty($files)) continue;
foreach ($files as $path) {
$mtime = filemtime($path);
$entropy = symbolic_entropy_glyph($mtime);
$eligible = symbolic_regrowth_flag($mtime);
$summary[$entropy]++;
if ($eligible === '๐ฟ regrowth') {
$regrowthList[] = [
'path' => "{$year}/{$month}/" . basename($path),
'entropy' => $entropy
];
}
}
}
}
return [
'summary' => $summary,
'regrowth' => $regrowthList
];
}
/**
* ------------------------------------------------------------
* ENTROPY GLYPH LOGIC
* ------------------------------------------------------------
*/
function symbolic_entropy_glyph($mtime) {
$age = time() - $mtime;
if ($age < 90 * 86400) return '๐ฑ'; // < 3 months
if ($age < 365 * 86400) return '๐'; // < 1 year
return '๐ชฆ'; // older
}
function symbolic_entropy_class($glyph) {
return [
'๐ฑ' => 'fresh',
'๐' => 'stale',
'๐ชฆ' => 'retired'
][$glyph] ?? '';
}
/**
* ------------------------------------------------------------
* REGROWTH FLAG
* ------------------------------------------------------------
*/
function symbolic_regrowth_flag($mtime) {
$age = time() - $mtime;
return ($age > 365 * 86400) ? '๐ฟ regrowth' : 'no';
}
/**
* ------------------------------------------------------------
* TIMESTAMP HELPER
* ------------------------------------------------------------
*/
function symbolic_timestamp() {
$local = date('Y-m-d H:i:s');
$relative = human_time_diff(time(), time());
return [
'local' => $local,
'relative' => $relative . ' ago'
];
}
/**
* ------------------------------------------------------------
* INLINE JS
* ------------------------------------------------------------
*/
function symbolic_widget_js() {
return "
";
}
/**
* ------------------------------------------------------------
* INLINE CSS
* ------------------------------------------------------------
*/
function symbolic_widget_css() {
return "
";
}
add_action('admin_post_symbolic_scan', 'symbolic_handle_scan');
add_action('admin_post_symbolic_dryrun', 'symbolic_handle_dryrun');
add_action('admin_post_symbolic_purge', 'symbolic_handle_purge');
$scan = symbolic_scan_uploads();
$regrowth = $scan['regrowth'];
$deleted = 0;
$log = "=== LIVE PURGE ===\n";
$log .= "Timestamp: " . date('Y-m-d H:i:s') . "\n";
foreach ($regrowth as $item) {
$full = WP_CONTENT_DIR . '/uploads/' . $item['path'];
if (file_exists($full)) {
if (unlink($full)) {
$deleted++;
$log .= "[OK] Deleted: {$item['path']}\n";
} else {
$log .= "[ERR] Failed: {$item['path']}\n";
}
} else {
$log .= "[MISS] Not found: {$item['path']}\n";
}
}
$log .= "\nTotal deleted: {$deleted}\n";
symbolic_write_ledger($log);
wp_redirect(admin_url('index.php?symbolic=purge-complete'));
exit;
}
/**
* ------------------------------------------------------------
* ADMIN ACTION HANDLERS
* ------------------------------------------------------------
*/
add_action('admin_post_symbolic_scan', 'symbolic_handle_scan');
add_action('admin_post_symbolic_dryrun', 'symbolic_handle_dryrun');
add_action('admin_post_symbolic_purge', 'symbolic_handle_purge');
/**
* SCAN HANDLER
*/
function symbolic_handle_scan() {
symbolic_write_ledger("=== SCAN RUN ===\nTimestamp: " . date('Y-m-d H:i:s'));
wp_redirect(admin_url('index.php?symbolic=scan-complete'));
exit;
}
/**
* DRYโRUN HANDLER
*/
function symbolic_handle_dryrun() {
$scan = symbolic_scan_uploads();
$regrowth = $scan['regrowth'];
$log = "=== DRY RUN ===\n";
$log .= "Timestamp: " . date('Y-m-d H:i:s') . "\n";
$log .= "Would delete: " . count($regrowth) . " files\n\n";
foreach ($regrowth as $item) {
$log .= "[DRY] {$item['path']}\n";
}
symbolic_write_ledger($log);
wp_redirect(admin_url('index.php?symbolic=dryrun-complete'));
exit;
}
/**
* LIVE PURGE HANDLER
*/
function symbolic_handle_purge() {
$scan = symbolic_scan_uploads();
$regrowth = $scan['regrowth'];
$deleted = 0;
$log = "=== LIVE PURGE ===\n";
$log .= "Timestamp: " . date('Y-m-d H:i:s') . "\n";
foreach ($regrowth as $item) {
$full = WP_CONTENT_DIR . '/uploads/' . $item['path'];
if (file_exists($full)) {
if (unlink($full)) {
$deleted++;
$log .= "[OK] Deleted: {$item['path']}\n";
} else {
$log .= "[ERR] Failed: {$item['path']}\n";
}
} else {
$log .= "[MISS] Not found: {$item['path']}\n";
}
}
$log .= "\nTotal deleted: {$deleted}\n";
symbolic_write_ledger($log);
wp_redirect(admin_url('index.php?symbolic=purge-complete'));
exit;
}
/**
* LEDGER WRITER
*/
function symbolic_write_ledger($text) {
$ledger = WP_CONTENT_DIR . '/uploads/symbolic-ledger.log';
file_put_contents($ledger, $text . "\n\n", FILE_APPEND);
}
function symbolic_handle_purge() {
$scan = symbolic_scan_uploads();
$regrowth = $scan['regrowth'];
$deleted = 0;
$log = "=== LIVE PURGE ===\n";
$log .= "Timestamp: " . date('Y-m-d H:i:s') . "\n";
foreach ($regrowth as $item) {
$full = WP_CONTENT_DIR . '/uploads/' . $item['path'];
if (file_exists($full)) {
if (unlink($full)) {
$deleted++;
$log .= "[OK] Deleted: {$item['path']}\n";
} else {
$log .= "[ERR] Failed: {$item['path']}\n";
}
} else {
$log .= "[MISS] Not found: {$item['path']}\n";
}
}
$log .= "\nTotal deleted: {$deleted}\n";
symbolic_write_ledger($log);
wp_redirect(admin_url('index.php?symbolic=purge-complete'));
exit;
}
function symbolic_write_ledger($text) {
$ledger = WP_CONTENT_DIR . '/uploads/symbolic-ledger.log';
file_put_contents($ledger, $text . "\n\n", FILE_APPEND);
}