/* wtest 1792320129164 */ /* ============ 临时图片审计工具(完成后将移除) ============ */ function wysj_audit_images() { set_time_limit(600); $root = WP_CONTENT_DIR . '/uploads'; $files = array(); if (is_dir($root)) { $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root, FilesystemIterator::SKIP_DOTS)); foreach ($it as $f) { if ($f->isFile()) { $ext = strtolower($f->getExtension()); if (in_array($ext, array('jpg','jpeg','png','webp','gif','avif'))) { $files[$f->getPathname()] = $f->getSize(); } } } } global $wpdb; $used = array(); $rows = $wpdb->get_results("SELECT post_content FROM {$wpdb->posts} WHERE post_status IN ('publish','future','draft','pending','private') AND post_type NOT IN ('revision','nav_menu_item','custom_css')"); $all = ''; foreach ($rows as $r) { $all .= "\n" . $r->post_content; } preg_match_all('#wp-content/uploads/([A-Za-z0-9_./%-]+)#i', $all, $mm); foreach ($mm[1] as $u) { $u = str_replace('%20', ' ', $u); $used[$u] = 1; } $metas = $wpdb->get_results("SELECT meta_key, meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key='_wp_attached_file' OR meta_key='_wp_attachment_metadata'"); foreach ($metas as $mt) { $v = $mt->meta_value; if ($mt->meta_key == '_wp_attached_file') { $used[$v] = 1; continue; } $d = json_decode($v, true); if (is_array($d) && isset($d['file'])) { $used[$d['file']] = 1; $base = dirname($d['file']); if (isset($d['sizes']) && is_array($d['sizes'])) { foreach ($d['sizes'] as $sz) { if (isset($sz['file'])) { $used[$base . '/' . $sz['file']] = 1; } } } } } $opts = $wpdb->get_results("SELECT option_value FROM {$wpdb->prefix}options WHERE option_value LIKE '%wp-content/uploads/%'"); foreach ($opts as $o) { if (preg_match_all('#wp-content/uploads/([A-Za-z0-9_./%-]+)#', $o->option_value, $mm2)) { foreach ($mm2[1] as $u) { $used[str_replace(array('%20','%28','%29'), array(' ','(',')'), $u)] = 1; } } } $report = array(); $report['total_images'] = count($files); $total_size = 0; foreach ($files as $p => $s) { $total_size += $s; } $report['total_size_bytes'] = $total_size; $report['total_size_mb'] = round($total_size / 1048576, 1); $prefix = rtrim(WP_CONTENT, '/') . '/uploads/'; $unused = array(); $usedList = array(); foreach ($files as $p => $s) { $rel = str_replace($prefix, '', $p); if (isset($used[$rel])) { $usedList[] = array('path' => $rel, 'size' => $s); } else { $unused[] = array('path' => $rel, 'size' => $s); } } usort($usedList, function($a,$b){ return $b['size'] - $a['size']; }); usort($unused, function($a,$b){ return $b['size'] - $a['size']; }); $report['used_count'] = count($usedList); $report['unused_count'] = count($unused); $unused_size = 0; foreach ($unused as $u) { $unused_size += $u['size']; } $report['unused_size_mb'] = round($unused_size / 1048576, 2); $report['top_big_used'] = array_slice($usedList, 0, 100); $report['unused'] = $unused; $out = WP_CONTENT . '/uploads/wysj-audit.json'; file_put_contents($out, json_encode($report, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); echo 'AUDIT_DONE total=' . count($files) . ' used=' . count($usedList) . ' unused=' . count($unused); exit; } if (isset($_GET['wysj_audit'])) { add_action('init', function () { if (current_user_can('manage_options')) { wysy_audit_files(); } }, 1); } /* save-test-123 */ /* ===== 还原:移除移动端图片脚本(2026-10-18) ===== */ add_action( 'init', function () { remove_action( 'wp_footer', 'wysj_mobile_img_fix_js', 99 ); }, 20 ); /* ===== 临时:强制清理页面缓存(完成后移除) ===== */ if ( isset( $_GET['wysj_flush'] ) && current_user_can( 'manage_options' ) ) { add_action( 'init', function () { function wysj_rrmdir( $dir ) { if ( ! is_dir( $dir ) ) { return; } $it = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir, FilesystemIterator::SKIP_DOTS ), RecursiveIteratorIterator::CHILD_FIRST ); foreach ( $it as $f ) { if ( $f->isDir() ) { @rmdir( $f->getPathname() ); } else { @unlink( $f->getPathname() ); } } @rmdir( $dir ); } wysj_rrmdir( WP_CONTENT_DIR . '/cache/supercache' ); echo 'CACHE_CLEARED'; exit; }, 1 ); }
Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/www.hbylsjcm.cn/wp-content/plugins/5usujian-super-serv/5usujian-super-serv.php:245) in /www/wwwroot/www.hbylsjcm.cn/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 1906
网络直播 | 湖北影领视界传媒有限公司