'attachment', 'post_mime_type' => $supported_mime_types, 'post_status' => 'inherit', 'posts_per_page' => $limit, 'meta_query' => [ [ 'key' => '_wp_attachment_image_alt', 'compare' => 'NOT EXISTS' ] ] ]; $attachments = get_posts($query_args); $updated = 0; foreach ($attachments as $attachment) { $mime = get_post_mime_type($attachment->ID); if (! AIT_IAT_Media_Handler::mime_is_supported($mime, $supported_mime_types)) continue; $json_alt_fields = apply_filters('ait_iat_generate_alt_text', [], $attachment->ID, null); if ( ! empty( $json_alt_fields ) ) { update_post_meta($attachment->ID, '_wp_attachment_image_alt', $json_alt_fields['alt_text']); do_action('ait_iat_alt_generated', $attachment->ID, $json_alt_fields['alt_text']); if ( ! empty( $json_alt_fields['caption'] ) || ! empty( $json_alt_fields['title'] ) || ! empty( $json_alt_fields['description'] ) ) { $args = ['ID' => $attachment->ID]; if ( ! empty( $json_alt_fields['title'] ) ) { $args['post_title'] = $json_alt_fields['title']; } if ( ! empty( $json_alt_fields['caption'] ) ) { $args['post_excerpt'] = $json_alt_fields['caption']; } if ( ! empty( $json_alt_fields['description'] ) ) { $args['post_content'] = $json_alt_fields['description']; } wp_update_post( $args ); if ( ! empty( $json_alt_fields['filename'] ) ) { AIT_IAT_Alt_Generator::maybe_rename_attachment_file( $attachment->ID, $json_alt_fields['filename'] ); } } $updated++; } } if (is_admin()) { /* translators: number of images updated */ update_option('ait_iat_admin_notice', sprintf(__('Scheduled alt text generation completed: %d images updated.', 'ai-image-alt-text'), $updated)); } } }