Changeset 3084521
- Timestamp:
- 05/10/2024 12:10:43 PM (23 months ago)
- Location:
- simple-export-import-for-acf-data/trunk
- Files:
-
- 9 edited
-
app.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
src/SeipEnqueue.php (modified) (1 diff)
-
src/SeipExport.php (modified) (1 diff)
-
src/SeipFront.php (modified) (2 diffs)
-
src/SeipImport.php (modified) (17 diffs)
-
view/_import.php (modified) (2 diffs)
-
view/_license.php (modified) (1 diff)
-
view/export_import.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-export-import-for-acf-data/trunk/app.php
r3078598 r3084521 5 5 Plugin URI: https://www.opcodespace.com 6 6 Author: Opcodespace <mehedee@opcodespace.com> 7 Version: 1.3.1 77 Version: 1.3.18 8 8 Text Domain: simple-export-import-for-acf-data 9 9 */ … … 13 13 define("SEIP_VIEW_PATH", wp_normalize_path(plugin_dir_path(__FILE__) . "view/")); 14 14 define("SEIP_ASSETSURL", plugins_url("assets/", __FILE__)); 15 define('SEIP_PLUGIN_VERSION', '1.3.1 7');15 define('SEIP_PLUGIN_VERSION', '1.3.18'); 16 16 define('PAID_TEXT', '<small class="paid_text">(This is for paid user)</small>'); 17 17 -
simple-export-import-for-acf-data/trunk/readme.txt
r3078598 r3084521 5 5 Tested up to: 6.5.2 6 6 Requires PHP: 7.0 7 Stable tag: 1.3.1 77 Stable tag: 1.3.18 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 96 96 97 97 == Changelog == 98 = 1.3.18 (May 10, 2024) = 99 * Enhancement: Bulk import in background for large data 100 98 101 = 1.3.17 (April 23, 2024) = 99 102 * Enhancement: Splitting Bulk Export -
simple-export-import-for-acf-data/trunk/src/SeipEnqueue.php
r2997056 r3084521 31 31 wp_localize_script( 32 32 'admin-script', 33 ' frontend_form_object',33 'seip_frontend_form_object', 34 34 array( 35 'ajaxurl' => admin_url('admin-ajax.php') 35 'ajaxurl' => admin_url('admin-ajax.php'), 36 'seip_background_import_status' => get_option('seip_background_import_status'), 36 37 ) 37 38 ); -
simple-export-import-for-acf-data/trunk/src/SeipExport.php
r3078598 r3084521 85 85 86 86 return [ 87 'ID' => $post->ID, 87 88 'post_date' => $post->post_date, 88 89 'post_title' => $post->post_title, -
simple-export-import-for-acf-data/trunk/src/SeipFront.php
r3078598 r3084521 14 14 add_action('wp_ajax_seip_get_all_terms', [$self, 'seip_get_all_terms']); 15 15 add_action('wp_ajax_seip_save_license_key', [$self, 'seip_save_license_key']); 16 add_action('wp_ajax_seip_banckground_import', [$self, 'seip_banckground_import']); 16 17 17 18 } … … 140 141 141 142 } 143 144 public function seip_banckground_import() 145 { 146 if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'seip_export_import' ) ) { 147 wp_send_json_error(['message' => 'You are not allowed to submit data.']); 148 } 149 150 (new SeipImport())->seip_import_background(); 151 } 142 152 } 143 153 } -
simple-export-import-for-acf-data/trunk/src/SeipImport.php
r3049001 r3084521 66 66 } 67 67 68 $post_id = (int)$_POST['post_id'];68 $post_id = (int)$_POST['post_id']; 69 69 $settings = [ 70 'bulk_import' => isset($_POST['bulk_import']),71 'update_post_page_ttl' => isset($_POST['update_post_page_ttl']),70 'bulk_import' => isset($_POST['bulk_import']), 71 'update_post_page_ttl' => isset($_POST['update_post_page_ttl']), 72 72 'update_post_page_slug' => isset($_POST['update_post_page_slug']), 73 'single_post_id' => $post_id,74 'post_type' => sanitize_text_field($_POST['post_type'])73 'single_post_id' => $post_id, 74 'post_type' => sanitize_text_field($_POST['post_type']) 75 75 ]; 76 76 … … 79 79 if (isset($_POST['bulk_import'])) { 80 80 $this->execution_time = time(); 81 82 if (isset($_POST['background_import'])) { 83 $result = $this->saveOnDisk($posts); 84 if ($result) { 85 update_option('seip_background_import_status', 'processing'); 86 update_option('seip_bulk_settings', $settings); 87 seip_notices_with_redirect('msg1', __('Importing data in background', 'simple-export-import-for-acf-data'), 88 'success'); 89 } 90 else { 91 seip_notices_with_redirect('msg1', __('Error while saving file', 'simple-export-import-for-acf-data'), 92 'error'); 93 } 94 } 81 95 } 82 96 83 97 foreach ($posts as $post) { 84 if (empty($post)){98 if (empty($post)) { 85 99 continue; 86 100 } … … 92 106 seip_notices_with_redirect('msg1', __('Successfully imported', 'simple-export-import-for-acf-data'), 93 107 'success'); 108 } 109 110 public function seip_import_background() 111 { 112 $posts = $this->readFromDisk(); 113 114 if (empty($posts)) { 115 delete_option('seip_background_import_status'); 116 delete_option('seip_bulk_settings'); 117 wp_send_json_success(['imported_posts' => [], 'message' => 'No data found']); 118 } 119 120 $settings = get_option('seip_bulk_settings'); 121 122 $cnt = 0; 123 $imported_posts = []; 124 foreach ($posts as $key => $post) { 125 if (empty($post)) { 126 continue; 127 } 128 129 if($cnt > 5){ 130 break; 131 } 132 133 $this->post_data($post, $settings); 134 135 $imported_posts[] = $post['ID']; 136 137 unset($posts[$key]); 138 139 $cnt++; 140 } 141 142 $this->saveOnDisk($posts); 143 144 wp_send_json_success(['imported_posts' => $imported_posts]); 94 145 } 95 146 … … 121 172 $SeipImportEditorMediaFile = new SeipImportEditorMediaFile($data['source_domain']); 122 173 $content = wp_kses_post($SeipImportEditorMediaFile->download_editor_media_files($data['post_content'])); 123 } 124 else{ 174 } else { 125 175 $content = wp_kses_post($data['post_content']); 126 176 } 127 177 128 178 $post_data = [ 129 'post_content' => $content,130 'post_status' => sanitize_text_field($data['post_status']),131 'post_excerpt' => sanitize_textarea_field($data['post_excerpt']),179 'post_content' => $content, 180 'post_status' => sanitize_text_field($data['post_status']), 181 'post_excerpt' => sanitize_textarea_field($data['post_excerpt']), 132 182 'post_password' => sanitize_text_field($data['post_password']), 133 183 ]; … … 150 200 151 201 $post = get_posts([ 152 'name' => sanitize_title($data['post_name']),202 'name' => sanitize_title($data['post_name']), 153 203 'post_type' => sanitize_text_field($settings['post_type']) 154 204 ]); … … 156 206 if (empty($post)) { 157 207 $primary_data = [ 158 'post_date' => sanitize_text_field($data['post_date']),159 'post_content' => $content,160 'post_title' => sanitize_text_field($data['post_title']),161 'post_status' => sanitize_text_field($data['post_status']),162 'post_excerpt' => sanitize_textarea_field($data['post_excerpt']),208 'post_date' => sanitize_text_field($data['post_date']), 209 'post_content' => $content, 210 'post_title' => sanitize_text_field($data['post_title']), 211 'post_status' => sanitize_text_field($data['post_status']), 212 'post_excerpt' => sanitize_textarea_field($data['post_excerpt']), 163 213 'post_password' => sanitize_text_field($data['post_password']), 164 'post_type' => sanitize_text_field($settings['post_type'])214 'post_type' => sanitize_text_field($settings['post_type']) 165 215 ]; 166 216 167 217 $post_id = wp_insert_post($primary_data); 168 218 } else { 169 $post_id = $post[0]->ID;219 $post_id = $post[0]->ID; 170 220 $post_data['ID'] = $post_id; 171 221 wp_update_post($post_data); 172 222 } 173 223 } else { 174 $post_id = (int)$settings['single_post_id'];224 $post_id = (int)$settings['single_post_id']; 175 225 $post_data['ID'] = $post_id; 176 226 … … 181 231 182 232 $this->current_post_id = $post_id; 183 $this->post_metas = $data['metas'];184 185 if (isset($data['metas']) && !empty($data['metas'])){233 $this->post_metas = $data['metas']; 234 235 if (isset($data['metas']) && !empty($data['metas'])) { 186 236 foreach ($data['metas'] as $key => $value) { 187 237 update_post_meta($post_id, $key, $this->get_field_value($key, $value)); … … 190 240 191 241 # Adding Featured image 192 $featured_image = (array) $data['featured_image'];242 $featured_image = (array)$data['featured_image']; 193 243 194 244 if (!empty($featured_image) && isset($featured_image['url'])) { … … 198 248 199 249 # Setting Terms 200 if (!empty($data['terms'])){250 if (!empty($data['terms'])) { 201 251 $this->set_terms($post_id, $data['terms']); 202 252 } … … 214 264 } 215 265 216 if (empty($value)){266 if (empty($value)) { 217 267 return $value; 218 268 } 219 269 220 if (!isset($this->post_metas['_' .$key]) || empty($this->post_metas['_'.$key])) {270 if (!isset($this->post_metas['_' . $key]) || empty($this->post_metas['_' . $key])) { 221 271 return $value; 222 272 } 223 273 224 $keys = explode('_field_', $this->post_metas['_' .$key]);274 $keys = explode('_field_', $this->post_metas['_' . $key]); 225 275 $no_of_keys = count($keys); 226 if($no_of_keys > 1){ 227 $related_field = get_field_object('field_'.$keys[$no_of_keys - 1]); 228 } 229 else{ 230 $related_field = get_field_object($this->post_metas['_'.$key]); 276 if ($no_of_keys > 1) { 277 $related_field = get_field_object('field_' . $keys[$no_of_keys - 1]); 278 } else { 279 $related_field = get_field_object($this->post_metas['_' . $key]); 231 280 } 232 281 … … 249 298 $total_uploaded_images = $seip_settings['import_images']; 250 299 251 if ($total_uploaded_images >= 10){300 if ($total_uploaded_images >= 10) { 252 301 return $value; 253 302 } … … 255 304 $total_uploaded_images++; 256 305 $seip_settings['import_images'] = $total_uploaded_images; 257 update_option( 'seip_settings', $seip_settings);306 update_option('seip_settings', $seip_settings); 258 307 259 308 $upload = $this->download($value['url']); … … 289 338 $new_images = []; 290 339 foreach ($images as $image) { 291 if (empty($image['url'])){340 if (empty($image['url'])) { 292 341 continue; 293 342 } 294 $upload = $this->download($image['url']);343 $upload = $this->download($image['url']); 295 344 $new_images[] = $this->attach($upload, $image); 296 345 } … … 316 365 $value, 317 366 array( 318 'timeout' => 300,367 'timeout' => 300, 319 368 'filename' => basename($value) 320 369 ) … … 322 371 323 372 $response_code = wp_remote_retrieve_response_code($response); 324 $content = wp_remote_retrieve_body($response);373 $content = wp_remote_retrieve_body($response); 325 374 326 375 if ($response_code != 200) { … … 352 401 $attachment = array( 353 402 'post_mime_type' => $upload['type'], 354 'guid' => $upload['url'],355 'post_title' => empty($media_data['post_title']) ? sanitize_title(basename($upload['file'])) : sanitize_text_field($media_data['post_title']),356 'post_content' => isset($media_data['post_content']) ? sanitize_text_field($media_data['post_content']) : '',357 'post_excerpt' => isset($media_data['post_excerpt']) ? sanitize_text_field($media_data['post_excerpt']) : '',358 'post_parent' => $this->current_post_id > 0 ? $this->current_post_id : 0,403 'guid' => $upload['url'], 404 'post_title' => empty($media_data['post_title']) ? sanitize_title(basename($upload['file'])) : sanitize_text_field($media_data['post_title']), 405 'post_content' => isset($media_data['post_content']) ? sanitize_text_field($media_data['post_content']) : '', 406 'post_excerpt' => isset($media_data['post_excerpt']) ? sanitize_text_field($media_data['post_excerpt']) : '', 407 'post_parent' => $this->current_post_id > 0 ? $this->current_post_id : 0, 359 408 ); 360 $attach_id = wp_insert_attachment($attachment, $upload['file']);409 $attach_id = wp_insert_attachment($attachment, $upload['file']); 361 410 362 411 if (is_wp_error($attach_id)) { … … 433 482 protected function link_field($value) 434 483 { 435 if (empty($value['link']['url'])){484 if (empty($value['link']['url'])) { 436 485 return $value; 437 486 } 438 $url = str_replace($value['source_domain'], home_url(), $value['link']['url']);439 $link = $value['link'];487 $url = str_replace($value['source_domain'], home_url(), $value['link']['url']); 488 $link = $value['link']; 440 489 $link['url'] = $url; 441 490 return $link; 442 491 } 492 493 protected function saveOnDisk($posts) 494 { 495 $upload_dir = wp_upload_dir(); 496 $file_name = 'seip_export_' . time() . '.json'; 497 $file_path = $upload_dir['basedir'] . '/seip/' . $file_name; 498 $file_url = $upload_dir['baseurl'] . '/seip/' . $file_name; 499 500 if (!file_exists($upload_dir['basedir'] . '/seip')) { 501 wp_mkdir_p($upload_dir['basedir'] . '/seip'); 502 } 503 504 update_option('seip_export_file', $file_path); 505 $result = file_put_contents($file_path, json_encode($posts)); 506 507 return $result ? $file_url : $result; 508 } 509 510 protected function readFromDisk() 511 { 512 $file_path = get_option('seip_export_file'); 513 return wp_json_file_decode($file_path, ['associative' => true]); 514 } 443 515 } 444 445 516 } -
simple-export-import-for-acf-data/trunk/view/_import.php
r2989857 r3084521 17 17 name="bulk_import" <?php echo !SeipOpcodespace::isPaid() ? 'disabled' : '' ?>><label 18 18 for="bulk_import" class="checkbox_label">Bulk Import</label> <br> 19 <?php echo !SeipOpcodespace::isPaid() ? PAID_TEXT : ' (If slug is matched, it will update that post/page. Otherwise, it creates a new post.)' ?>19 <?php echo !SeipOpcodespace::isPaid() ? PAID_TEXT : 'If slug is matched, it will update that post/page. Otherwise, it creates a new post.' ?> 20 20 </div> 21 21 <div class="block_imports"> … … 89 89 </tr> 90 90 <tr class=""> 91 <td><label for="file" >Upload File</label></td>91 <td><label for="file" class="label_block">Upload File</label></td> 92 92 <td> 93 93 <input type="file" name="file" id="file" accept="application/json"> 94 94 <br><span class="description">Only JSON format is supported.</span> 95 </td> 96 </tr> 97 <tr class=""> 98 <td colspan="2"> 99 <div> 100 <input type="checkbox" id="background_import" name="background_import"> 101 <label for="background_import"><strong>Import in Background</strong></label> 102 </div> 103 <p>If you have a large number of posts and images, and you have a timeout issue, you can select background upload. You should open this browser window until complete the process. Otherwise, importing will not work.</p></td> 104 </tr> 105 <tr> 106 <td></td> 107 <td> 108 95 109 </td> 96 110 </tr> -
simple-export-import-for-acf-data/trunk/view/_license.php
r2758968 r3084521 29 29 $.ajax({ 30 30 method: 'POST', 31 url: frontend_form_object.ajaxurl,31 url: seip_frontend_form_object.ajaxurl, 32 32 data: { action: 'seip_save_license_key', _wpnonce: $('#_wpnonce').val(), seip_license_key: $('[name="seip_license_key"]').val()} 33 33 }) -
simple-export-import-for-acf-data/trunk/view/export_import.php
r3078598 r3084521 52 52 } 53 53 54 .simple_imported_items { 55 background: #000; 56 padding: 15px; 57 color: green; 58 height: 150px; 59 display: block; 60 overflow-y: scroll; 61 } 62 63 .loading_animation { 64 display: flex; 65 } 66 67 .loading_animation svg path, 68 .loading_animation svg rect { 69 fill: #FF6700; 70 } 71 54 72 /* Tablet Layout: 768px. */ 55 73 @media only screen and (min-width: 768px) and (max-width: 991px) { … … 76 94 <div class="export_import_wrapper"> 77 95 <h5 class="main_title">Simple Export Import for ACF Data</h5> 96 97 <!-- // Background Process--> 98 <?php if (get_option('seip_background_import_status') === 'processing'): ?> 99 <div class="notice notice-warning"> 100 <div class="loading_animation"> 101 <div class="loader" title="0"> 102 <svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" 103 xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" 104 width="40px" height="40px" viewBox="0 0 40 40" enable-background="new 0 0 40 40" 105 xml:space="preserve"> 106 <path opacity="0.2" fill="#000" d="M20.201,5.169c-8.254,0-14.946,6.692-14.946,14.946c0,8.255,6.692,14.946,14.946,14.946 107 s14.946-6.691,14.946-14.946C35.146,11.861,28.455,5.169,20.201,5.169z M20.201,31.749c-6.425,0-11.634-5.208-11.634-11.634 108 c0-6.425,5.209-11.634,11.634-11.634c6.425,0,11.633,5.209,11.633,11.634C31.834,26.541,26.626,31.749,20.201,31.749z"/> 109 <path fill="#000" d="M26.013,10.047l1.654-2.866c-2.198-1.272-4.743-2.012-7.466-2.012h0v3.312h0 110 C22.32,8.481,24.301,9.057,26.013,10.047z"> 111 <animateTransform attributeType="xml" 112 attributeName="transform" 113 type="rotate" 114 from="0 20 20" 115 to="360 20 20" 116 dur="0.5s" 117 repeatCount="indefinite"/> 118 </path> 119 </svg> 120 </div> 121 <p style="color: tomato; font-weight: bold">Importing process is running. Please don't close 122 this window.</p> 123 </div> 124 <div class="seip_background_import_status"> 125 <ul class="simple_imported_items"> 126 127 </ul> 128 </div> 129 </div> 130 <?php endif; ?> 131 <!-- // End Background Process --> 132 78 133 <?php $tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'export' ?> 79 134 <nav class="nav-tab-wrapper"> … … 164 219 165 220 221 if (seip_frontend_form_object.seip_background_import_status === 'processing') { 222 seip_banckground_import(); 223 } 224 225 function seip_banckground_import() { 226 $.ajax({ 227 method: "POST", 228 url: "<?php echo esc_url(admin_url('/admin-ajax.php')); ?>", 229 data: { 230 action: "seip_banckground_import", 231 _wpnonce: $('#seip_export_import_nonce').val() 232 } 233 }) 234 .done(function (response) { 235 if (response.success) { 236 if (response.data.imported_posts.length > 0) { 237 response.data.imported_posts.map(post => { 238 $('.seip_background_import_status ul').append(`<li>Imported: #${post}</li>`); 239 }) 240 $(".seip_background_import_status ul").scrollTop($(".seip_background_import_status ul")[0].scrollHeight); 241 seip_banckground_import(); 242 } else { 243 $('.seip_background_import_status ul').append(`<li>Completed</li>`); 244 $('.export_import_wrapper .loading_animation').html('<p style="color: green; font-weight: bold">Importing process is completed.</p>'); 245 } 246 } 247 }); 248 } 249 250 166 251 function seip_get_all_posts(_this) { 167 252 let _this_parent = _this.parents('form'); … … 194 279 _this_parent.find('[name="post_id"]').html(options).trigger("chosen:updated"); 195 280 196 if ($('#export_mulit_pages').length > 0){281 if ($('#export_mulit_pages').length > 0) { 197 282 $('#export_mulit_pages').html(options); 198 283 … … 259 344 } 260 345 261 $('[name="terms[]"]').on('change', function () {346 $('[name="terms[]"]').on('change', function () { 262 347 seip_get_all_posts($(this)); 263 348 })
Note: See TracChangeset
for help on using the changeset viewer.