id === 'edit-post') {
echo '
.column-title { width: 220px !important; min-width: 220px !important; }
.column-title a, .column-title strong, .column-title span, .row-title { writing-mode: horizontal-tb !important; white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important; max-width: 220px !important; display: inline-block !important; }
';
}
});
add_action('rest_api_init', function() {
// Check unused images in a given folder
register_rest_route('custom/v1', '/media-unused', ['methods'=>'GET','callback'=>function($req){
global $wpdb;
$folder = sanitize_text_field($req->get_param('folder') ?: '2023/08');
$upload_dir = wp_upload_dir();
$base_url = $upload_dir['baseurl'];
$rows = $wpdb->get_results($wpdb->prepare(
"SELECT p.ID, p.post_title, m.meta_value AS file
FROM {$wpdb->posts} p
JOIN {$wpdb->postmeta} m ON m.post_id=p.ID AND m.meta_key='_wp_attached_file'
WHERE p.post_type='attachment'
AND p.post_mime_type LIKE 'image/%'
AND p.post_status='inherit'
AND m.meta_value LIKE %s
ORDER BY p.ID ASC",
$folder . '/%'
));
if (empty($rows)) return ['folder'=>$folder,'total'=>0,'unused'=>0,'used'=>0];
// Load all post content once
$big_content = implode(' ', $wpdb->get_col(
"SELECT post_content FROM {$wpdb->posts}
WHERE post_status NOT IN ('trash','auto-draft','revision')
AND post_type NOT IN ('attachment','revision','nav_menu_item')
AND post_content != ''"
));
$used = []; $unused = [];
foreach ($rows as $r) {
$fname = basename($r->file);
if (strpos($big_content, $fname) !== false) {
$used[] = ['id'=>intval($r->ID),'file'=>$r->file];
} else {
$unused[] = ['id'=>intval($r->ID),'file'=>$r->file];
}
}
return ['folder'=>$folder,'total'=>count($rows),'used'=>count($used),'unused'=>count($unused),'unused_ids'=>array_column($unused,'id')];
},'permission_callback'=>'__return_true']);
// Trash unused images in a given folder
register_rest_route('custom/v1', '/media-unused-trash', ['methods'=>'POST','callback'=>function($req){
ignore_user_abort(true);
set_time_limit(300);
global $wpdb;
$folder = sanitize_text_field($req->get_param('folder') ?: '2023/08');
$rows = $wpdb->get_results($wpdb->prepare(
"SELECT p.ID, m.meta_value AS file
FROM {$wpdb->posts} p
JOIN {$wpdb->postmeta} m ON m.post_id=p.ID AND m.meta_key='_wp_attached_file'
WHERE p.post_type='attachment'
AND p.post_mime_type LIKE 'image/%'
AND p.post_status='inherit'
AND m.meta_value LIKE %s
ORDER BY p.ID ASC",
$folder . '/%'
));
if (empty($rows)) return ['trashed'=>0,'message'=>'no images in '.$folder];
$big_content = implode(' ', $wpdb->get_col(
"SELECT post_content FROM {$wpdb->posts}
WHERE post_status NOT IN ('trash','auto-draft','revision')
AND post_type NOT IN ('attachment','revision','nav_menu_item')
AND post_content != ''"
));
$unused_ids = [];
foreach ($rows as $r) {
if (strpos($big_content, basename($r->file)) === false) {
$unused_ids[] = intval($r->ID);
}
}
if (empty($unused_ids)) return ['trashed'=>0,'message'=>'all images are in use'];
$in = implode(',', $unused_ids);
$wpdb->query("UPDATE {$wpdb->posts} SET post_status='trash' WHERE ID IN ($in) AND post_status='inherit'");
return ['folder'=>$folder,'trashed'=>count($unused_ids),'ids'=>$unused_ids];
},'permission_callback'=>'__return_true']);
});
// TEST
add_action('admin_init', function() { if(isset($_GET['feat_test'])) { die('OK'); } });
// TEST SAVE
Warning: Cannot modify header information - headers already sent by (output started at /home/c5197879/public_html/redlistrestaurant.com/wp-content/themes/cocoon-child/functions.php:1) in /home/c5197879/public_html/redlistrestaurant.com/wp-content/plugins/google-sitemap-generator/sitemap-core.php on line 2064
https://redlistrestaurant.com/sitemap-misc.xml
2026-05-14T22:08:15+00:00
https://redlistrestaurant.com/post-sitemap.xml
2026-05-14T22:08:15+00:00
https://redlistrestaurant.com/post-sitemap2.xml
2026-05-14T22:08:15+00:00
https://redlistrestaurant.com/post-sitemap3.xml
2026-05-14T22:08:15+00:00
https://redlistrestaurant.com/post-sitemap4.xml
2026-05-14T22:08:15+00:00