'forbidden'], 403); global $wpdb; // %i identifier placeholder (WP 6.2+); prepare() inlined so PluginCheck's // NotPrepared sniff can see it. // phpcs:ignore WordPress.DB.DirectDatabaseQuery $rows = $wpdb->get_results($wpdb->prepare( "SELECT post_id, meta_value AS hash FROM %i WHERE meta_key = %s LIMIT %d", $wpdb->postmeta, '_acpimg_phash', 2000 )); $groups = []; foreach ($rows as $r) { $matched = false; foreach ($groups as &$g) { if (Acpimg_Perceptual_Hash::distance($g['hash'], $r->hash) < 8) { $g['ids'][] = (int) $r->post_id; $matched = true; break; } } if (!$matched) $groups[] = ['hash' => $r->hash, 'ids' => [(int) $r->post_id]]; } $dupes = array_values(array_filter($groups, function ($g) { return count($g['ids']) > 1; })); wp_send_json_success(['groups' => $dupes, 'total_scanned' => count($rows)]); } }