← All changes
|
backend/src/Controllers/Cloud/Libraries/LibraryItemImageController.php
+13
-1
1.0
→
1.4.7
View file →
| @@ -57,8 +57,12 @@ | ||
| 57 | 57 | $media = (object) $item['media']['file']; |
| 58 | 58 | $service = new MediaLibraryService(); |
| 59 | 59 | $response = $service->import_cloud_media( $media ); |
| 60 | 60 | |
| 61 | + if ( $response && isset( $response['id'] ) && !empty( $item['data']['alt'] ) ) { | |
| 62 | + update_post_meta( $response['id'], '_wp_attachment_image_alt', $item['data']['alt'] ); | |
| 63 | + } | |
| 64 | + | |
| 61 | 65 | return rest_ensure_response( $response ); |
| 62 | 66 | } |
| 63 | 67 | |
| 64 | 68 | /** |
| @@ -71,14 +75,22 @@ | ||
| 71 | 75 | $client = new CloudClient; |
| 72 | 76 | $path = get_attached_file( $id ); |
| 73 | 77 | $ext = pathinfo( $path, PATHINFO_EXTENSION ); |
| 74 | 78 | |
| 79 | + $data = []; | |
| 80 | + | |
| 81 | + $alt = get_post_meta( $id, '_wp_attachment_image_alt', true); | |
| 82 | + | |
| 83 | + if ( !empty( $alt ) ) { | |
| 84 | + $data['alt'] = $alt; | |
| 85 | + } | |
| 86 | + | |
| 75 | 87 | return $client->libraries->create_item( |
| 76 | 88 | $library_id, |
| 77 | 89 | [ |
| 78 | 90 | 'name' => $attachment->post_title, |
| 79 | 91 | 'type' => 'svg' === $ext ? 'svg' : 'image', |
| 80 | - 'data' => [], | |
| 92 | + 'data' => $data, | |
| 81 | 93 | 'media' => [ |
| 82 | 94 | 'file' => $path, |
| 83 | 95 | ], |
| 84 | 96 | ] |