posts} WHERE post_type = 'attachment' AND post_mime_type IN ('image/jpeg', 'image/png') "; $results = $wpdb->get_col($query); // Lọc những ID chưa có meta _aio_webp_converted $convertible_ids = []; foreach ($results as $id) { if (!get_post_meta($id, '_aio_webp_converted', true)) { $convertible_ids[] = $id; } } wp_send_json_success([ 'ids' => $convertible_ids ]); } public function aio_process_webp_batch_ajax() { check_ajax_referer( 'aio-settings-nonce', 'security' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'Unauthorized', 'aio' ) ); } $ids = isset($_POST['ids']) ? array_map('intval', (array) $_POST['ids']) : []; if (empty($ids)) { wp_send_json_error( __( 'No IDs provided', 'aio' ) ); } if (!function_exists('aio_generate_webp_for_attachment')) { require_once AIO_MODULES_PATH . 'optimizer/public-optimizer.php'; } $log = []; foreach ($ids as $id) { $file = get_attached_file($id); if ($file && file_exists($file)) { $result = aio_generate_webp_for_attachment($id); if ($result) { $log[] = "Optimized ID {$id}: " . basename($file); } else { $log[] = "Failed or skipped ID {$id}"; } // Đánh dấu là đã xử lý update_post_meta($id, '_aio_webp_converted', true); } else { update_post_meta($id, '_aio_webp_converted', 'not_found'); } } wp_send_json_success([ 'log' => implode("\n", $log) ]); } public function aio_update_redirect_rules_ajax() { check_ajax_referer( 'aio-settings-nonce', 'security' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'Unauthorized', 'aio' ) ); } $raw_rules = isset($_POST['rules']) ? $_POST['rules'] : ''; $rules = json_decode(wp_unslash($raw_rules), true); if ( !is_array($rules) && !empty($raw_rules) ) { $rules = json_decode($raw_rules, true); } if ( !is_array($rules) ) { $rules = []; } $sanitized_rules = []; foreach ($rules as $old => $new) { $sanitized_rules[sanitize_text_field($old)] = sanitize_text_field($new); } update_option('aio_redirect_rules', $sanitized_rules); wp_send_json_success(); } public function aio_scan_file_integrity_ajax() { check_ajax_referer( 'aio-settings-nonce', 'security' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'Unauthorized', 'aio' ) ); } if (!function_exists('aio_scan_core_files')) { require_once AIO_MODULES_PATH . 'security/public-security.php'; } $result = aio_scan_core_files(); if ($result['success']) { wp_send_json_success($result['modified']); } else { wp_send_json_error($result['message']); } } }