add_attachment.php
1 month ago
admin_head.php
1 month ago
admin_init.php
1 month ago
admin_menu.php
1 month ago
admin_notices.php
1 month ago
attachment_updated.php
1 month ago
delete_post.php
1 month ago
pmxi_after_xml_import.php
1 month ago
pmxi_before_xml_import.php
1 month ago
pmxi_extend_options_custom_fields.php
1 month ago
wp_ajax_auto_detect_cf.php
1 month ago
wp_ajax_auto_detect_sf.php
1 month ago
wp_ajax_delete_import.php
1 month ago
wp_ajax_dismiss_notifications.php
1 month ago
wp_ajax_import_failed.php
1 month ago
wp_ajax_test_images.php
1 month ago
wp_ajax_wpai_dismiss_review_modal.php
1 month ago
wp_ajax_wpai_send_feedback.php
1 month ago
wpmu_new_blog.php
1 month ago
pmxi_after_xml_import.php
97 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 3 | function pmxi_pmxi_after_xml_import( $import_id, $import ) |
| 4 | { |
| 5 | if ($import->options['custom_type'] == 'taxonomies') { |
| 6 | $parent_terms = get_option('wp_all_import_taxonomies_hierarchy_' . $import_id); |
| 7 | if (!empty($parent_terms)){ |
| 8 | foreach ($parent_terms as $term_id => $pterm){ |
| 9 | $parent_term = get_term_by('slug', $pterm, $import->options['taxonomy_type']) or $parent_term = get_term_by('name', $pterm, $import->options['taxonomy_type']) or ctype_digit($pterm) and $parent_term = get_term_by('id', $pterm, $import->options['taxonomy_type']); |
| 10 | if (!empty($parent_term) && !is_wp_error($parent_term)){ |
| 11 | wp_update_term($term_id, $import->options['taxonomy_type'], array( |
| 12 | 'parent' => $parent_term->term_id, |
| 13 | )); |
| 14 | } |
| 15 | } |
| 16 | } |
| 17 | delete_option('wp_all_import_taxonomies_hierarchy_' . $import_id); |
| 18 | } |
| 19 | if (in_array($import->options['custom_type'], ['comments', 'woo_reviews'])) { |
| 20 | $parent_comments = get_option('wp_all_import_comments_hierarchy_' . $import_id); |
| 21 | if (!empty($parent_comments)){ |
| 22 | foreach ($parent_comments as $comment_id => $pcomment){ |
| 23 | $parent_comment = get_comment($pcomment); |
| 24 | if (!empty($parent_comment) && !is_wp_error($parent_comment)){ |
| 25 | wp_update_comment(array( |
| 26 | 'comment_ID' => $comment_id, |
| 27 | 'comment_parent' => $parent_comment->comment_ID, |
| 28 | )); |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | delete_option('wp_all_import_taxonomies_hierarchy_' . $import_id); |
| 33 | } |
| 34 | if ( ! in_array($import->options['custom_type'], array('taxonomies', 'import_users', 'shop_customer', 'comments', 'woo_reviews')) ) { |
| 35 | $custom_type = get_post_type_object( $import->options['custom_type'] ); |
| 36 | if ( ! empty($custom_type) && $custom_type->hierarchical ){ |
| 37 | $parent_posts = get_option('wp_all_import_posts_hierarchy_' . $import_id); |
| 38 | if (!empty($parent_posts)){ |
| 39 | foreach ($parent_posts as $pid => $identity){ |
| 40 | $parent_post = wp_all_import_get_parent_post($identity, $import->options['custom_type'], $import->options['type']); |
| 41 | if (!empty($parent_post) && !is_wp_error($parent_post)){ |
| 42 | wp_update_post(array( |
| 43 | 'ID' => $pid, |
| 44 | 'post_parent' => $parent_post |
| 45 | )); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | delete_option('wp_all_import_posts_hierarchy_' . $import_id); |
| 50 | } |
| 51 | |
| 52 | $recount_terms_after_import = TRUE; |
| 53 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound |
| 54 | $recount_terms_after_import = apply_filters('wp_all_import_recount_terms_after_import', $recount_terms_after_import, $import_id); |
| 55 | if ($recount_terms_after_import) { |
| 56 | // Update term count after import process is complete. |
| 57 | $taxonomies = get_object_taxonomies( $import->options['custom_type'] ); |
| 58 | if (!empty($taxonomies)) { |
| 59 | foreach ( (array) $taxonomies as $taxonomy ) { |
| 60 | $term_ids = get_terms( |
| 61 | array( |
| 62 | 'taxonomy' => $taxonomy, |
| 63 | 'hide_empty' => false, |
| 64 | 'fields' => 'tt_ids', |
| 65 | ) |
| 66 | ); |
| 67 | if ( ! empty( $term_ids ) ) { |
| 68 | wp_update_term_count_now( $term_ids, $taxonomy ); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // Update post count only once after import process is completed. |
| 74 | wp_all_import_update_post_count(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // Re-count post comments. |
| 79 | if ( in_array($import->options['custom_type'], array('comments', 'woo_reviews')) ) { |
| 80 | $recount_comments_after_import = TRUE; |
| 81 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound |
| 82 | $recount_comments_after_import = apply_filters('wp_all_import_recount_comments_after_import', $recount_comments_after_import, $import_id); |
| 83 | if ($recount_comments_after_import) { |
| 84 | $comment_posts = get_option('wp_all_import_comment_posts_' . $import_id); |
| 85 | if (!empty($comment_posts)) { |
| 86 | foreach ($comment_posts as $comment_post) { |
| 87 | wp_update_comment_count_now($comment_post); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Add removed action during import. |
| 94 | add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 ); |
| 95 | add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 ); |
| 96 | add_action( 'post_updated', 'wp_save_post_revision', 10, 1 ); |
| 97 | } |