← All changes
|
backend/src/Controllers/PostsExportController.php
+15
-1
1.5.5.1
→
1.4.7
View file →
| @@ -38,8 +38,9 @@ | ||
| 38 | 38 | /** |
| 39 | 39 | * Export a single post. |
| 40 | 40 | */ |
| 41 | 41 | public function export_post( $request ) { |
| 42 | + $this->delete_exports(); | |
| 42 | 43 | |
| 43 | 44 | /* Get requested post data */ |
| 44 | 45 | $post_id = absint( $request->get_param( 'id' ) ); |
| 45 | 46 | $post = get_post( $post_id ); |
| @@ -135,11 +136,24 @@ | ||
| 135 | 136 | ] |
| 136 | 137 | ); |
| 137 | 138 | |
| 138 | 139 | file_put_contents( $file, $export_data ); |
| 139 | - update_option( 'fl_assistant_export_file', true ); | |
| 140 | + | |
| 140 | 141 | return $file_url; |
| 141 | 142 | } |
| 143 | + | |
| 144 | + /** | |
| 145 | + * Remove temporary export files. | |
| 146 | + */ | |
| 147 | + public function delete_exports() { | |
| 148 | + $upload_dir = wp_upload_dir( null, false ); | |
| 149 | + $files = glob( trailingslashit( $upload_dir['basedir'] ) . 'assistant_export_*.xml' ); | |
| 150 | + | |
| 151 | + foreach ( $files as $file ) { | |
| 152 | + unlink( $file ); | |
| 153 | + } | |
| 154 | + } | |
| 155 | + | |
| 142 | 156 | |
| 143 | 157 | function wxr_cdata( $str ) { |
| 144 | 158 | if ( ! seems_utf8( $str ) ) { |
| 145 | 159 | $str = utf8_encode( $str ); |