| @@ -32,21 +32,8 @@ | ||
| 32 | 32 | }, |
| 33 | 33 | ], |
| 34 | 34 | ] |
| 35 | 35 | ); |
| 36 | - | |
| 37 | - $this->route( | |
| 38 | - '/posts/(?P<id>\d+)/export', | |
| 39 | - [ | |
| 40 | - [ | |
| 41 | - 'methods' => WP_REST_Server::DELETABLE, | |
| 42 | - 'callback' => [ $this, 'delete_export' ], | |
| 43 | - 'permission_callback' => function () { | |
| 44 | - return current_user_can( 'export' ); | |
| 45 | - }, | |
| 46 | - ], | |
| 47 | - ] | |
| 48 | - ); | |
| 49 | 36 | } |
| 50 | 37 | |
| 51 | 38 | /** |
| 52 | 39 | * Export a single post. |
| @@ -51,21 +38,19 @@ | ||
| 51 | 38 | /** |
| 52 | 39 | * Export a single post. |
| 53 | 40 | */ |
| 54 | 41 | public function export_post( $request ) { |
| 42 | + $this->delete_exports(); | |
| 43 | + | |
| 55 | 44 | /* Get requested post data */ |
| 56 | 45 | $post_id = absint( $request->get_param( 'id' ) ); |
| 57 | 46 | $post = get_post( $post_id ); |
| 58 | 47 | |
| 59 | 48 | /* Create temporary file */ |
| 60 | - $file_url = WP_CONTENT_URL . '/' . sanitize_file_name( $post->post_title ) . '_' . $post->ID . '.xml'; | |
| 61 | - $file = WP_CONTENT_DIR . '/' . sanitize_file_name( $post->post_title ) . '_' . $post->ID . '.xml'; | |
| 62 | - $current = ''; | |
| 49 | + $upload_dir = wp_upload_dir( null, false ); | |
| 50 | + $file_url = $upload_dir['baseurl'] . '/assistant_export_' . $post->ID . '.xml'; | |
| 51 | + $file = $upload_dir['basedir'] . '/assistant_export_' . $post->ID . '.xml'; | |
| 63 | 52 | |
| 64 | - if ( file_exists( $file ) ) { | |
| 65 | - $current = file_get_contents( $file ); | |
| 66 | - } | |
| 67 | - | |
| 68 | 53 | /* Creates taxonomies string for xml export */ |
| 69 | 54 | $taxonomies = get_taxonomies( '', 'names' ); |
| 70 | 55 | $terms = wp_get_object_terms( $post->ID, $taxonomies ); |
| 71 | 56 | |
| @@ -102,8 +87,12 @@ | ||
| 102 | 87 | $meta_str = ''; |
| 103 | 88 | $meta_values = get_post_meta( $post->ID ); |
| 104 | 89 | foreach ( $meta_values as $key => $values ) { |
| 105 | 90 | foreach ( $values as $value ) { |
| 91 | + /* Ignore BB history meta */ | |
| 92 | + if ( false !== strpos( $key, '_fl_builder_history' ) ) { | |
| 93 | + continue; | |
| 94 | + } | |
| 106 | 95 | $meta_str .= '<wp:postmeta> |
| 107 | 96 | <wp:meta_key>' . $this->wxr_cdata( $key ) . '</wp:meta_key> |
| 108 | 97 | <wp:meta_value>' . $this->wxr_cdata( $value ) . '</wp:meta_value> |
| 109 | 98 | </wp:postmeta> |
| @@ -146,37 +135,22 @@ | ||
| 146 | 135 | 'post_type' => $post_type, |
| 147 | 136 | ] |
| 148 | 137 | ); |
| 149 | 138 | |
| 150 | - file_put_contents( $file, $current . $export_data ); | |
| 139 | + file_put_contents( $file, $export_data ); | |
| 151 | 140 | |
| 152 | 141 | return $file_url; |
| 153 | 142 | } |
| 154 | 143 | |
| 155 | 144 | /** |
| 156 | - * Remove temporary exported file. | |
| 145 | + * Remove temporary export files. | |
| 157 | 146 | */ |
| 158 | - public function delete_export( $request ) { | |
| 147 | + public function delete_exports() { | |
| 148 | + $upload_dir = wp_upload_dir( null, false ); | |
| 149 | + $files = glob( trailingslashit( $upload_dir['basedir'] ) . 'assistant_export_*.xml' ); | |
| 159 | 150 | |
| 160 | - $post_id = absint( $request->get_param( 'id' ) ); | |
| 161 | - $post = get_post( $post_id ); | |
| 162 | - | |
| 163 | - /* Remove temporary file */ | |
| 164 | - $file = WP_CONTENT_DIR . '/' . sanitize_file_name( $post->post_title ) . '_' . $post->ID . '.xml'; | |
| 165 | - | |
| 166 | - if ( file_exists( $file ) ) { | |
| 151 | + foreach ( $files as $file ) { | |
| 167 | 152 | unlink( $file ); |
| 168 | - return rest_ensure_response( | |
| 169 | - [ | |
| 170 | - 'success' => true, | |
| 171 | - ] | |
| 172 | - ); | |
| 173 | - } else { | |
| 174 | - return rest_ensure_response( | |
| 175 | - [ | |
| 176 | - 'error' => true, | |
| 177 | - ] | |
| 178 | - ); | |
| 179 | 153 | } |
| 180 | 154 | } |
| 181 | 155 | |
| 182 | 156 | |