500 ) { return new \WP_Error( 'altlumen_bad_request', __( 'Choose valid image IDs.', 'altlumen' ) ); } foreach ( $ids as $id ) { if ( ! wp_attachment_is_image( $id ) || ! current_user_can( 'upload_files' ) || ! current_user_can( 'edit_post', $id ) ) { return new \WP_Error( 'altlumen_forbidden', __( 'You cannot edit this image.', 'altlumen' ) ); } } return ( new Queue\BulkJob() )->start( $ids, count( $ids ), sanitize_key( $source ), true ); } /** * Return a nonsecret snapshot for export and import conflict detection. * * @param mixed $result Earlier adapter result. * @param int $id Attachment ID. * @return mixed */ public function image( $result, int $id ) { if ( null !== $result ) { return $result; } if ( ! wp_attachment_is_image( $id ) || ! current_user_can( 'upload_files' ) || ! current_user_can( 'edit_post', $id ) ) { return new \WP_Error( 'altlumen_forbidden', __( 'You cannot edit this image.', 'altlumen' ) ); } $data = array( 'ID' => $id, 'file' => wp_basename( (string) get_attached_file( $id ) ), 'current_alt' => (string) get_post_meta( $id, '_wp_attachment_image_alt', true ), 'suggestion' => (string) get_post_meta( $id, '_altlumen_suggestion', true ), 'status' => (string) get_post_meta( $id, '_altlumen_status', true ), ); $data['fingerprint'] = hash( 'sha256', wp_json_encode( $data ) ); $data['protected'] = Generation\Generator::is_manual( $id ) && ! ( new Settings( new Providers\Registry() ) )->get()['overwrite']; return $data; } /** * Apply only a fresh, explicitly confirmed preview using the canonical F1 path. * * @param mixed $result Earlier adapter result. * @param int $id Attachment ID. * @param string $alt Proposed native alt. * @param string $fingerprint Preview snapshot hash. * @return mixed */ public function import_alt( $result, int $id, string $alt, string $fingerprint ) { if ( null !== $result ) { return $result; } $current = $this->image( null, $id ); if ( is_wp_error( $current ) ) { return $current; } if ( ! hash_equals( $current['fingerprint'], $fingerprint ) ) { return new \WP_Error( 'altlumen_conflict', __( 'This image changed after the preview. Preview the CSV again.', 'altlumen' ) ); } return ( new Generation\Generator( new Settings( new Providers\Registry() ), new Providers\Registry() ) )->review( $id, 'apply', $alt ); } }