post_type ) { return false; } $alt = sanitize_text_field( $alt ); $title = sanitize_text_field( $title ); update_post_meta( $attachment_id, '_wp_attachment_image_alt', $alt ); if ( '' !== $title ) { wp_update_post( array( 'ID' => $attachment_id, 'post_title' => $title ) ); } $results = (array) get_option( Adbear_Alt_Text_Generator_Helpers::get_scan_option_key(), array() ); if ( isset( $results[ $attachment_id ] ) ) { $results[ $attachment_id ]['current_alt'] = $alt; $results[ $attachment_id ]['current_title'] = $title; $results[ $attachment_id ]['missing_alt'] = '' === trim( $alt ) ? 1 : 0; $results[ $attachment_id ]['missing_title'] = '' === trim( $title ) ? 1 : 0; if ( 0 === (int) $results[ $attachment_id ]['missing_alt'] && 0 === (int) $results[ $attachment_id ]['missing_title'] ) { unset( $results[ $attachment_id ] ); } update_option( Adbear_Alt_Text_Generator_Helpers::get_scan_option_key(), $results, false ); } $report = (array) get_option( Adbear_Alt_Text_Generator_Helpers::get_scan_report_option_key(), array() ); if ( isset( $report[ $attachment_id ] ) ) { $report[ $attachment_id ]['current_alt'] = $alt; $report[ $attachment_id ]['current_title'] = $title; $report[ $attachment_id ]['missing_alt'] = '' === trim( $alt ) ? 1 : 0; $report[ $attachment_id ]['missing_title'] = '' === trim( $title ) ? 1 : 0; update_option( Adbear_Alt_Text_Generator_Helpers::get_scan_report_option_key(), $report, false ); } return true; } public function update_bulk( $items ) { $updated = 0; foreach ( $items as $item ) { $attachment_id = isset( $item['attachment_id'] ) ? absint( $item['attachment_id'] ) : 0; $alt_text = isset( $item['alt_text'] ) ? sanitize_text_field( $item['alt_text'] ) : ''; $title_text = isset( $item['title_text'] ) ? sanitize_text_field( $item['title_text'] ) : ''; if ( $attachment_id > 0 && $this->update_single( $attachment_id, $alt_text, $title_text ) ) { ++$updated; } } return $updated; } }