'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'fields' => 'ids', 'orderby' => 'ID', 'order' => 'ASC', ); /* * Page over ALL images (ordered by ID) rather than only those with empty alt * text: "filename-style / low-quality" alt text cannot be expressed in SQL, * so each image is examined once via the offset cursor and only missing or * low-quality alt text triggers a provider call. Genuine descriptions are * scanned cheaply and skipped. */ $count_query = new WP_Query( $base + array( 'posts_per_page' => 1, 'no_found_rows' => false, ) ); $total = (int) $count_query->found_posts; wp_reset_postdata(); $batch_ids = get_posts( $base + array( 'posts_per_page' => $batch_size, 'offset' => $offset, ) ); $processed = 0; $issues = array(); foreach ( $batch_ids as $att_id ) { $alt = get_post_meta( $att_id, '_wp_attachment_image_alt', true ); if ( ! aatg_is_low_quality_alt( $alt, $att_id ) ) { continue; // genuine alt text — leave it untouched. } $result = aatg_generate_text_and_title( $att_id, null, 'bulk' ); if ( is_wp_error( $result ) ) { $issues[] = array( 'attachment_id' => $att_id, 'type' => 'aatg_unsupported_format' === $result->get_error_code() ? 'warning' : 'error', 'message' => $result->get_error_message(), ); } elseif ( ! empty( $result['warning'] ) ) { $issues[] = array( 'attachment_id' => $att_id, 'type' => 'warning', 'message' => $result['warning'], ); } $processed++; } $scanned = count( $batch_ids ); $next_offset = $offset + $scanned; $remaining = max( 0, $total - $next_offset ); wp_send_json_success( array( 'processed' => $processed, 'scanned' => $scanned, 'next_offset' => $next_offset, 'remaining' => $remaining, 'total' => $total, 'issues' => $issues, ) ); } add_action( 'wp_ajax_aatg_bulk_update', 'aatg_bulk_update_ajax' );