├── .gitignore
├── README.md
├── all-export
├── pmxe_after_export.php
├── pmxe_after_iteration.php
├── pmxe_before_export.php
├── pmxe_exported_post.php
├── pmxe_woo_field.php
├── wp_all_export_additional_data.php
├── wp_all_export_after_csv_line.php
├── wp_all_export_config_options.php
├── wp_all_export_csv_headers.php
├── wp_all_export_csv_rows.php
├── wp_all_export_export_file_name.php
├── wp_all_export_generate_bundle.php
├── wp_all_export_implode_delimiter.php
├── wp_all_export_is_csv_headers_enabled.php
├── wp_all_export_order_item.php
├── wp_all_export_pre_csv_headers.php
├── wp_all_export_product_variation_mode.php
├── wp_all_export_raw_prices.php
├── wp_all_export_repeater_delimiter.php
├── wp_all_export_use_csv_compliant_line_endings.php
├── wp_all_export_xml_rows.php
└── wp_all_export_zapier_response.php
├── all-import
├── pmxi_acf_custom_field.php
├── pmxi_after_post_import.php
├── pmxi_after_xml_import.php
├── pmxi_article_data.php
├── pmxi_attachment_uploaded.php
├── pmxi_before_delete_post.php
├── pmxi_before_xml_import.php
├── pmxi_custom_field.php
├── pmxi_delete_post.php
├── pmxi_gallery_image.php
├── pmxi_saved_post.php
├── pmxi_single_category.php
├── pmxi_update_post_meta.php
├── wp_all_import_attachments_uploads_dir.php
├── wp_all_import_auto_create_csv_headers.php
├── wp_all_import_copy_uploaded_file_into_files_folder.php
├── wp_all_import_curl_download_only.php
├── wp_all_import_feed_type.php
├── wp_all_import_get_image_from_gallery.php
├── wp_all_import_handle_upload.php
├── wp_all_import_image_filename.php
├── wp_all_import_images_uploads_dir.php
├── wp_all_import_is_check_duplicates.php
├── wp_all_import_is_php_allowed.php
├── wp_all_import_is_post_to_create.php
├── wp_all_import_is_post_to_delete.php
├── wp_all_import_is_post_to_update.php
├── wp_all_import_is_unlink_missing_posts.php
├── wp_all_import_multi_glue.php
├── wp_all_import_phpexcel_object.php
├── wp_all_import_search_image_by_wp_attached_file.php
├── wp_all_import_set_post_terms.php
├── wp_all_import_skip_x_csv_rows.php
├── wp_all_import_specified_records.php
├── wp_all_import_use_wp_set_object_terms.php
├── wpallimport_after_images_import.php
└── wpallimport_xml_row.php
└── woocommerce-add-on
├── pmxi_product_variation_saved.php
├── wp_all_import_get_prices_from_first_variation.php
├── wp_all_import_make_product_simple.php
├── wp_all_import_product_attributes_delimiter.php
├── wp_all_import_variable_product_imported.php
├── wp_all_import_variation_any_attribute.php
└── wp_all_import_variation_taxonomies.php
/.gitignore:
--------------------------------------------------------------------------------
1 | /.DS_Store
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WP All Import/Export Action Reference
2 |
3 | This GitHub repo serves as documentation for WP All Import and WP All Export's actions. For support, questions, concerns, or anything else, please submit a support request: http://www.wpallimport.com/support/
4 |
5 | #### __Note: Check [Issues](https://github.com/soflyy/wp-all-import-action-reference/issues) for latest undocumented hooks.__
6 |
7 | ## WP-All-Import
8 |
9 | ### Before and after import
10 | * [pmxi_before_xml_import](all-import/pmxi_before_xml_import.php) - Executed just before the import begins.
11 | * [pmxi_after_xml_import](all-import/pmxi_after_xml_import.php) - Executed when the entire import completes.
12 | * [pmxi_before_delete_post](all-import/pmxi_before_delete_post.php) - This fires just before a post is deleted.
13 | * [wp_all_import_auto_create_csv_headers](all-import/wp_all_import_auto_create_csv_headers.php) - Auto generate headers, or use header in file.
14 | * [wp_all_import_feed_type](all-import/wp_all_import_feed_type.php) - Can be used to define the feed type.
15 | * [wp_all_import_is_check_duplicates](all-import/wp_all_import_is_check_duplicates.php) - Turn duplicate checking on/off.
16 | * [wp_all_import_is_unlink_missing_posts](all-import/wp_all_import_is_unlink_missing_posts.php) - Used to completely remove the relationship between import and post from pmxi_posts database table.
17 | * [wp_all_import_skip_x_csv_rows](all-import/wp_all_import_skip_x_csv_rows.php) - Specifies the amount of rows to be skipped.
18 | * [wp_all_import_curl_download_only](all-import/wp_all_import_curl_download_only.php) - Force WP All Import to download the feed on the first request.
19 |
20 | ### Modifying post data during import
21 | * [wpallimport_xml_row](all-import/wpallimport_xml_row.php) - Allows modification of each data record from the file before import.
22 | * [pmxi_saved_post](all-import/pmxi_saved_post.php) - Invoked right after saving a post.
23 | * [pmxi_after_post_import](all-import/pmxi_after_post_import.php) - Invoked after saving a post (??)
24 | * [pmxi_article_data](all-import/pmxi_article_data.php) - Allows modifying the post body content before save.
25 | * [pmxi_delete_post](all-import/pmxi_delete_post.php) - Triggered before posts are deleted.
26 | * [pmxi_single_category](all-import/pmxi_single_category.php) -
27 | * [wp_all_import_set_post_terms](all-import/wp_all_import_set_post_terms.php) - Called when WP All Import is setting the post taxonomy terms.
28 | * [wp_all_import_multi_glue](all-import/wp_all_import_multi_glue.php) - Change the delimiter that's used when querying multiple values with XPath.
29 | * [wp_all_import_phpexcel_object](all-import/wp_all_import_phpexcel_object.php) - Access/modify the import PHPExcel object.
30 | * [wp_all_import_use_wp_set_object_terms](all-import/wp_all_import_use_wp_set_object_terms.php) - Determines behavior of assigment taxonomy term to a post.
31 | * [wp_all_import_copy_uploaded_file_into_files_folder](all-import/wp_all_import_copy_uploaded_file_into_files_folder.php) - In case of TRUE value WP All Import will copy uploaded XML files into /wp-content/uploads/wpallimport/files folder.
32 | * [wp_all_import_is_php_allowed](all-import/wp_all_import_is_php_allowed.php) - In case of TRUE value WP All Import will execute PHP functions in import template, e.q.: ```[str_replace("a", "b", {title[1]})]```.
33 |
34 | ### Custom fields (post meta)
35 | * [pmxi_custom_field](all-import/pmxi_custom_field.php) - Custom field values can be modified *before* save using this hook.
36 | * [pmxi_update_post_meta](all-import/pmxi_update_post_meta.php) - Called right *after* a custom field is saved. Use this if you need access to meta_id.
37 | * [pmxi_acf_custom_field](all-import/pmxi_acf_custom_field.php) - Filter for "Advanced Custom Field" values.
38 |
39 | ### Choosing which records to import/update
40 | * [wp_all_import_specified_records](all-import/wp_all_import_specified_records.php) - Allows specifing a list/range of records to import.
41 | * [wp_all_import_is_post_to_create](all-import/wp_all_import_is_post_to_create.php) - Indicate whether the post is to be created.
42 | * [wp_all_import_is_post_to_update](all-import/wp_all_import_is_post_to_update.php) - Indicate whether the post is to be updated.
43 | * [wp_all_import_is_post_to_delete](all-import/wp_all_import_is_post_to_delete.php) - Indicate whether the post is to be deleted.
44 |
45 | ### Images and attachments
46 | * [pmxi_attachment_uploaded](all-import/pmxi_attachment_uploaded.php) - Invoked right after an attachment was uploaded.
47 | * [pmxi_gallery_image](all-import/pmxi_gallery_image.php) - Invoked right after an image was imported. Usefull if working with 3rd party plugins/themes that have a custom gallery format.
48 | * [wp_all_import_image_filename](all-import/wp_all_import_image_filename.php) - Allows customizing the names of imported images.
49 | * [wp_all_import_images_uploads_dir](all-import/wp_all_import_images_uploads_dir.php) - Allows customizing the path in which images & ACF field uploads are uploaded.
50 | * [wp_all_import_attachments_uploads_dir](all-import/wp_all_import_attachments_uploads_dir.php) - Allows customizing the path in which attachments are uploaded.
51 | * [wp_all_import_handle_upload](all-import/wp_all_import_handle_upload.php) - Filters the data array for attachments & images uploaded through WP All Import.
52 | * [wpallimport_after_images_import](all-import/wpallimport_after_images_import.php) - Called after images are imported, but only when "Keep images currently in Media Library" is enabled.
53 | * [wp_all_import_get_image_from_gallery](all-import/wp_all_import_get_image_from_gallery.php) - Called after an existing image is found in the Media Library. Doesn't work with "Download images hosted elsewhere".
54 | * [wp_all_import_search_image_by_wp_attached_file](all-import/wp_all_import_search_image_by_wp_attached_file.php) - Can be used to stop WP All Import from looking for existing images via _wp_attached_file.
55 |
56 |
57 | ## WooCommerce Add-On
58 | * [pmxi_product_variation_saved](woocommerce-add-on/pmxi_product_variation_saved.php) - Called when WP All Import saves a variable product with the "Link all variations" option selected.
59 | * [wp_all_import_get_prices_from_first_variation](woocommerce-add-on/wp_all_import_get_prices_from_first_variation.php) - Can be used to set price from first variation and set it to parent product in case when variable product converting to simple.
60 | * [wp_all_import_variation_any_attribute](woocommerce-add-on/wp_all_import_variation_any_attribute.php) - Can be used to set variation attributes to 'Any' value.
61 | * [wp_all_import_product_attributes_delimiter](woocommerce-add-on/wp_all_import_product_attributes_delimiter.php) - Can be used to set product attributes delimiter.
62 | * [wp_all_import_variation_taxonomies](woocommerce-add-on/wp_all_import_variation_taxonomies.php) - Can be used to add taxonomies to WooCommerce product variations.
63 | * [wp_all_import_variable_product_imported](woocommerce-add-on/wp_all_import_variable_product_imported.php) - Called when WP All Import saves a variable product.
64 | * [wp_all_import_make_product_simple](woocommerce-add-on/wp_all_import_make_product_simple.php) - Called after a product is converted into a Simple product by our WooCommerce Add-On, due to a lack of variations.
65 |
66 | ## WP-All-Export
67 |
68 | ### Modifying post data during export
69 | * [pmxe_exported_post](all-export/pmxe_exported_post.php) - Invoked right after exporting a post.
70 |
71 | ### Modify exported data rows
72 | * [wp_all_export_csv_rows](all-export/wp_all_export_csv_rows.php) - Filter CSV rows to export.
73 | * [wp_all_export_xml_rows](all-export/wp_all_export_xml_rows.php) - Filter XML rows to export.
74 | * [wp_all_export_after_csv_line](all-export/wp_all_export_after_csv_line.php) - Filters CSV lines.
75 | * [pmxe_woo_field](all-export/pmxe_woo_field.php) - Filters WooCommerce fields.
76 | * [wp_all_export_order_item](all-export/wp_all_export_order_item.php) - Filters WooCommerce Order Items.
77 | * [wp_all_export_implode_delimiter](all-export/wp_all_export_implode_delimiter.php) - Modify the implode delimiter for export fields.
78 |
79 | ### Modify name or format of export file
80 | * [wp_all_export_additional_data](all-export/wp_all_export_additional_data.php) - Create additional XML nodes for export
81 | * [wp_all_export_is_csv_headers_enabled](all-export/wp_all_export_is_csv_headers_enabled.php) - Can be used to completely remove the CSV header.
82 | * [wp_all_export_export_file_name](all-export/wp_all_export_export_file_name.php) - Specify the export file name.
83 | * [wp_all_export_csv_headers](all-export/wp_all_export_csv_headers.php) - Manipulate export file headers.
84 | * [wp_all_export_pre_csv_headers](all-export/wp_all_export_pre_csv_headers.php) - Allows for CSV headers to be added above the default headers.
85 |
86 | ### WooCommerce
87 | * [wp_all_export_raw_prices](all-export/wp_all_export_raw_prices.php) - Can be used to disable price formatting for WooCommerce exports.
88 |
89 | ### ACF
90 | * [wp_all_export_repeater_delimiter](all-export/wp_all_export_repeater_delimiter.php) - Define the delimiter used for ACF Repeater fields.
91 |
92 | ### Misc
93 | * [wp_all_export_config_options](all-export/wp_all_export_config_options.php) - Set export options
94 | * [wp_all_export_product_variation_mode](all-export/wp_all_export_product_variation_mode.php) - Choose whether to export parent products or just variations.
95 | * [pmxe_before_export](all-export/pmxe_before_export.php) - Perform some action before the export starts.
96 | * [pmxe_after_export](all-export/pmxe_after_export.php) - Perform some action after the export is complete.
97 | * [wp_all_export_generate_bundle](all-export/wp_all_export_generate_bundle.php) - Determine whether the bundle file should be generated.
98 | * [wp_all_export_zapier_response](all-export/wp_all_export_zapier_response.php) -
99 | * [wp_all_export_use_csv_compliant_line_endings](all-export/wp_all_export_use_csv_compliant_line_endings.php) - Use custom CSV writer when affected by https://bugs.php.net/bug.php?id=43225.
100 | * [pmxe_after_iteration](all-export/pmxe_after_iteration.php) - Runs after each cron processing iteration finishes.
101 |
--------------------------------------------------------------------------------
/all-export/pmxe_after_export.php:
--------------------------------------------------------------------------------
1 | Settings
35 | $is_secure_export = PMXE_Plugin::getInstance()->getOption('secure');
36 |
37 | if (!$is_secure_export) {
38 | $filepath = get_attached_file($exportObj->attch_id);
39 | } else {
40 | $filepath = wp_all_export_get_absolute_path($exportObj->options['filepath']);
41 | }
42 | // Code to handle $filepath here
43 | // e.g., rename( $filepath, "/path/to/new/folder/export-file-name.csv" );
44 | }
45 |
46 | /**
47 | * Move export file to /wp-content/uploads once the export is complete
48 | */
49 |
50 | add_action('pmxe_after_export', 'wpae_move_export_file_to_root_upload_folder', 10, 2);
51 |
52 | function wpae_move_export_file_to_root_upload_folder ($export_id, $exportObj){
53 |
54 | // Get WordPress's upload directory information
55 | $upload_dir = wp_get_upload_dir();
56 |
57 | // Check whether "Secure Mode" is enabled in All Export -> Settings
58 | $is_secure_export = PMXE_Plugin::getInstance()->getOption('secure');
59 |
60 | if (!$is_secure_export) {
61 | $filepath = get_attached_file($exportObj->attch_id);
62 | } else {
63 | $filepath = wp_all_export_get_absolute_path($exportObj->options['filepath']);
64 | }
65 |
66 | // Get the filename
67 | $filename = basename( $filepath );
68 |
69 | // Code to move export file into /wp-content/uploads
70 | rename( $filepath, $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $filename );
71 | }
72 |
--------------------------------------------------------------------------------
/all-export/pmxe_after_iteration.php:
--------------------------------------------------------------------------------
1 | update_status('completed', 'export_completed');
21 | }
22 |
23 | add_action('pmxe_exported_post', 'wpae_pmxe_exported_post', 10, 2);
24 |
25 | /**
26 | * Example that checks the export ID
27 | */
28 | function wpae_pmxe_exported_post($post_id, $exportObject)
29 | {
30 | $export_id = ( isset( $_GET['id'] ) ? $_GET['id'] : ( isset( $_GET['export_id'] ) ? $_GET['export_id'] : 'new' ) );
31 |
32 | if ($export_id == "1") {
33 | $order = new WC_Order($post_id);
34 | $order->update_status('completed', 'export_completed');
35 | }
36 | }
37 | add_action('pmxe_exported_post', 'wpae_pmxe_exported_post', 10, 2);
38 |
--------------------------------------------------------------------------------
/all-export/pmxe_woo_field.php:
--------------------------------------------------------------------------------
1 | $header ) {
33 | if ( $header == 'Rate Name' ) {
34 | unset( $headers[ $key ] );
35 | }
36 | }
37 | return $headers;
38 | }
39 |
--------------------------------------------------------------------------------
/all-export/wp_all_export_csv_rows.php:
--------------------------------------------------------------------------------
1 | $article) {
23 | // if ($article["Title"] == "Something") {
24 | // unset($articles[$key]);
25 | // }
26 | // }
27 |
28 | return $articles; // Return the array of records to export
29 | }
30 |
31 | add_filter('wp_all_export_csv_rows', 'wp_all_export_csv_rows', 10, 3);
32 |
33 |
34 | // ----------------------------
35 | // Example uses below
36 | // ----------------------------
37 |
38 | /**
39 | * Export based on some criteria. In this case pricing.
40 | *
41 | */
42 | function my_export_csv_rows($articles, $options, $export_id)
43 | {
44 | foreach ($articles as $key => $article) {
45 | if (!empty($article['Regular Price'] && !empty($article['Sale Price']))) {
46 | if ($article['Sale Price'] < ($article['Regular Price'] / 2)) {
47 | unset($articles[$key]);
48 | }
49 | }
50 | }
51 |
52 | return $articles;
53 | }
54 |
55 | add_filter('wp_all_export_csv_rows', 'my_export_csv_rows', 10, 3);
56 |
57 |
58 | /**
59 | * Export based on date in the "_my_time" field
60 | *
61 | */
62 | function wp_all_export_csv_rows($articles, $options, $export_id)
63 | {
64 | // Loop through the array and unset() any entries you don't want exported
65 | foreach ($articles as $key => $article) {
66 | $date = date(strtotime("tomorrow"));
67 | $my_time = strtotime($article["_my_time"]);
68 | if ($my_time < $date) {
69 | unset($articles[$key]);
70 | }
71 | }
72 | return $articles; // Return the array of records to export
73 | }
74 | add_filter('wp_all_export_csv_rows', 'wp_all_export_csv_rows', 10, 3);
75 |
76 |
77 | /*
78 | * Export all posts from the previous calendar month
79 | *
80 | */
81 | function wp_all_export_csv_rows($articles, $options, $export_id) {
82 | // Get start date of previous month
83 | $start_date = date("Y-m-d", strtotime("first day of previous month"));
84 | // Get end date of previous month
85 | $end_date = date("Y-m-d", strtotime("last day of previous month"));
86 | // Loop through the array and unset() any entries you don't want exported
87 | foreach ($articles as $key => $article) {
88 | // Get post date from export data
89 | $post_date = $article["_my_post_date"];
90 | // Compare the dates
91 | if ( ( $post_date >= $start_date ) && ( $post_date <= $end_date ) ) {
92 | // Don't unset the $articles
93 | } else {
94 | // Unset the $articles
95 | unset($articles[$key]);
96 | }
97 | }
98 | // Return the array of records to export
99 | return $articles;
100 | }
101 | add_filter('wp_all_export_csv_rows', 'wp_all_export_csv_rows', 10, 3);
102 |
103 | /*
104 | * Exclude variations from Google Merchant Center export when the parent product is in "Draft" status
105 | *
106 | */
107 |
108 | function my_exclude_drafts_from_gmc_export($articles, $options, $export_id) {
109 |
110 | if ($options["xml_template_type"] == "XmlGoogleMerchants") {
111 |
112 | foreach ($articles as $key => $article) {
113 | if ( ! empty($article['id']) ) {
114 |
115 | $post_id = $article['id'];
116 |
117 | $parent_id = wp_get_post_parent_id($post_id);
118 |
119 | if ( get_post_status($parent_id) == "draft" ) {
120 | unset($articles[$key]);
121 | }
122 |
123 | }
124 | }
125 |
126 | }
127 |
128 | return $articles;
129 | }
130 | add_filter('wp_all_export_csv_rows', 'my_exclude_drafts_from_gmc_export', 10, 3);
131 |
--------------------------------------------------------------------------------
/all-export/wp_all_export_export_file_name.php:
--------------------------------------------------------------------------------
1 | ID;
41 | $stock_status = get_post_meta( $product_id, "_stock_status", true );
42 | $stock = get_post_meta( $product_id, "_stock", true );
43 |
44 | // Now, we can conditionally export the records.
45 |
46 | // Example A: Don't export records that are out of stock:
47 |
48 | // if ( $stock_status == 'outofstock' ) {
49 | // $is_export_record = false;
50 | // }
51 |
52 | // Example B: Only export records with a positive stock value:
53 |
54 | // if ( empty( $stock ) ) {
55 | // $is_export_record = false;
56 | // }
57 |
58 | // Now, we let WP All Export know whether we should export the record.
59 | return $is_export_record;
60 | }
61 | add_filter( 'wp_all_export_xml_rows', 'my_wp_all_export_xml_rows', 10, 4 );
62 |
63 | /*
64 | *
65 | * Limit XML Export to a certain number of records
66 | *
67 | */
68 |
69 | add_filter('wp_all_export_xml_rows', function($shouldExport, $record, $exportOptions, $exportId) {
70 |
71 | // THE ID OF THE EXPORT YOU WANT TO APPLY THE FILTER TO
72 | $exportToApplyFilterTo = 3;
73 |
74 | // THE NUMBER OF POSTS TO EXPORT
75 | $lastNumberOfPostsToExport = 200;
76 |
77 | if($exportId == $exportToApplyFilterTo) {
78 |
79 | // GET THE LATEST POSTS
80 | $posts = get_posts(
81 | array(
82 | 'numberposts' => $lastNumberOfPostsToExport,
83 | 'post_status' => 'publish', // ONLY RETURN PUBLISHED
84 | // START TAXONOMY QUERY, REMOVE IF NOT FILTERING BY TAXONOMY
85 | 'tax_query' => array(
86 | array(
87 | 'taxonomy' => 'property_status', // CHANGE TO THE TAXONOMY SLUG FOR YOUR TAXONOMY
88 | 'field' => 'term_id',
89 | 'terms' => 575, // CHANGE TO THE term_id OF YOUR TAXONOMY TERM THAT YOU WANT TO MATCH
90 | 'include_children' => false
91 | )
92 | ),
93 | // END TAXONOMY QUERY
94 | 'fields' => 'ids',
95 | 'order' => 'desc',
96 | 'orderby' => 'ID',
97 | 'post_type' => $record->post_type
98 | )
99 | );
100 |
101 | // IF THE CURRENT POST'S ID WAS RETURNED BY THE QUERY ABOVE THEN EXPORT IT.
102 | if(in_array($record->ID, $posts)) {
103 | return true;
104 | } else {
105 | return false;
106 | }
107 | }
108 |
109 | // RETURN THE DEFAULT IF EXPORT ID DOESN'T MATCH
110 | return $shouldExport;
111 | }, 11, 4);
112 |
--------------------------------------------------------------------------------
/all-export/wp_all_export_zapier_response.php:
--------------------------------------------------------------------------------
1 | getById($response['export_id'])->isEmpty())
32 | {
33 | if ( ! empty($export->options['bundlepath']) )
34 | {
35 | $bundle_path = wp_all_export_get_absolute_path($export->options['bundlepath']);
36 |
37 | $uploads = wp_upload_dir();
38 |
39 | if ( @file_exists($bundle_path) )
40 | {
41 | $response['export_file_url'] = $uploads['baseurl'] . str_replace($uploads['basedir'], '', $bundle_path);
42 | }
43 | }
44 | }
45 |
46 | return $response;
47 | }
48 |
--------------------------------------------------------------------------------
/all-import/pmxi_acf_custom_field.php:
--------------------------------------------------------------------------------
1 | prefix . 'pmxi_imports';
33 | $data = $wpdb->get_row( 'SELECT * FROM `' . $table . '` WHERE `ID` = "' . $import_id . '"' );
34 | if ( $data ) {
35 | $msg = "Import Report for Import ID " . $import_id . "\r\n\r\n";
36 | $msg .= "Created: " . $data->created . "\r\n";
37 | $msg .= "Updated: " . $data->updated . "\r\n";
38 | $msg .= "Skipped: " . $data->skipped . "\r\n";
39 | $msg .= "Deleted: " . $data->deleted . "\r\n";
40 | wp_mail( 'youremail@domain.com', 'Import Report', $msg );
41 | }
42 | }
43 |
44 | add_action( 'pmxi_after_xml_import', 'email_results', 10, 1 );
45 |
46 |
47 | /**
48 | * Delete import file once the import completes
49 | *
50 | */
51 | function wp_all_import_after_xml_import( $import_id ) {
52 | $import = new PMXI_Import_Record();
53 | $import->getById( $import_id );
54 | if ( ! $import->isEmpty() ) {
55 | $path = wp_all_import_get_absolute_path( $import->path );
56 | @unlink( $path );
57 | }
58 | }
59 |
60 | add_action( 'pmxi_after_xml_import', 'wp_all_import_after_xml_import', 10, 1 );
61 |
--------------------------------------------------------------------------------
/all-import/pmxi_article_data.php:
--------------------------------------------------------------------------------
1 | post_content
14 | * @param $current_xml_node array - Parsed data of current XML node
15 | *
16 | * @return mixed
17 | */
18 | function my_pmxi_article_data($articleData, $import, $post_to_update, $current_xml_node)
19 | {
20 | // Add new content to the top of old content
21 | // $articleData['post_content'] .= $post_to_update->post_content;
22 |
23 | return $articleData;
24 | }
25 |
26 | add_filter('pmxi_article_data', 'my_pmxi_article_data', 10, 4);
27 |
--------------------------------------------------------------------------------
/all-import/pmxi_attachment_uploaded.php:
--------------------------------------------------------------------------------
1 | $attach_id,
32 | 'post_mime_type' => 'application/pdf'
33 | ));
34 | update_attached_file($attach_id,$new_file);
35 | }
36 | }
37 | add_action('pmxi_attachment_uploaded', 'wpai_pmxi_attachment_uploaded', 10, 3);
38 |
--------------------------------------------------------------------------------
/all-import/pmxi_before_delete_post.php:
--------------------------------------------------------------------------------
1 | getById($importID);
31 | if ( !$import->isEmpty() && $import->count < 100 ) {
32 | $history_file = new PMXI_File_Record();
33 | $history_file->getBy( 'import_id', $importID );
34 | if ( !$history_file->isEmpty() ) {
35 | $file_to_import = wp_all_import_get_absolute_path( $history_file->path );
36 | // here you can add you check to determine is file valid or not
37 | if ( file_exists( $file_to_import ) and filesize( $file_to_import ) === 0 or $import->count < 100 ) {
38 | // reset import data
39 | $import->set( array(
40 | 'queue_chunk_number' => 0,
41 | 'processing' => 0,
42 | 'imported' => 0,
43 | 'created' => 0,
44 | 'updated' => 0,
45 | 'skipped' => 0,
46 | 'deleted' => 0,
47 | 'triggered' => 0,
48 | 'executing' => 0
49 | ))->update();
50 | echo 'Import skipped because of empty file / < 100 records';
51 | // stop import processing
52 | die();
53 | }
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/all-import/pmxi_custom_field.php:
--------------------------------------------------------------------------------
1 | "image_url_1",
34 | * image_id_2 => "image_url_2",
35 | * ...
36 | * );
37 | *
38 | */
39 | function gallery_id_url($post_id, $att_id, $filepath, $is_keep_existing_images = '')
40 | {
41 | $key = '_gallery'; // Edit this: Set meta key for gallery array here
42 | $size = 'full'; // Edit this: Set WordPress image size for the URL here (e.g. "full" or "thumb")
43 |
44 | $gallery = get_post_meta($post_id, $key, TRUE);
45 | if (empty($gallery)) {
46 | $gallery = array();
47 | }
48 |
49 | if (!isset($gallery[$att_id])) {
50 | $src = wp_get_attachment_image_src($att_id, $size);
51 | $gallery[$att_id] = $src[0];
52 | update_post_meta($post_id, $key, $gallery);
53 | }
54 | }
55 |
56 | add_action('pmxi_gallery_image', 'gallery_id_url', 10, 4);
57 |
58 | /**
59 | * For image galleries with the format:
60 | *
61 | * array (
62 | * 0 => image_id_1,
63 | * 1 => image_id_2,
64 | * ...
65 | * );
66 | *
67 | */
68 | function gallery_n_id($post_id, $att_id, $filepath, $is_keep_existing_images = '')
69 | {
70 | $key = '_gallery'; // Edit this: Set meta key for gallery array here
71 |
72 | $gallery = get_post_meta($post_id, $key, TRUE);
73 | if (empty($gallery)) {
74 | $gallery = array();
75 | }
76 |
77 | if (!in_array($att_id, $gallery)) {
78 | $gallery[] = $att_id;
79 | update_post_meta($post_id, $key, $gallery);
80 | }
81 | }
82 |
83 | add_action('pmxi_gallery_image', 'gallery_n_id', 10, 4);
84 |
85 |
86 | /**
87 | * For image galleries where each image id is saved as an individual post meta value with the same key (ie. No arrays)
88 | *
89 | */
90 | function gallery_meta_id($post_id, $att_id, $filepath, $is_keep_existing_images = '')
91 | {
92 | $key = '_gallery'; // Edit this: Set meta key for gallery array here
93 |
94 | $result = get_post_meta($post_id, $key, FALSE);
95 | if (is_array($result)) {
96 | if (!in_array($att_id, $result)) {
97 | add_post_meta($post_id, $key, $att_id);
98 | }
99 | }
100 | }
101 |
102 | add_action('pmxi_gallery_image', 'gallery_meta_id', 10, 4);
103 |
104 |
105 | /**
106 | * For galleries where image id's are saved as a single string
107 | * with a comma or other separators:
108 | *
109 | * "23,25,31"
110 | *
111 | */
112 | function gallery_ids_in_string($post_id, $att_id, $filepath, $is_keep_existing_images = '')
113 | {
114 | $key = '_gallery'; // Edit this: Set meta key for gallery array here
115 | $separator = ",";
116 |
117 | $gallery = get_post_meta($post_id, $key, true);
118 | if (is_string($gallery) || is_empty($gallery) || ($gallery == false)) {
119 | $gallery = explode($separator, $gallery);
120 | if (!in_array($att_id, $gallery)) {
121 | if ($gallery[0] == '') unset($gallery[0]);
122 | $gallery[] = $att_id;
123 | update_post_meta($post_id, $key, implode($separator, $gallery));
124 | }
125 | }
126 | }
127 |
128 | add_action('pmxi_gallery_image', 'gallery_ids_in_string', 10, 4);
129 |
130 |
131 |
--------------------------------------------------------------------------------
/all-import/pmxi_saved_post.php:
--------------------------------------------------------------------------------
1 | prefix . "your_table_name";
131 | $wpdb->insert($table_name, array('post_id' => $id, 'column_name' => $value), array('%s','%s'));
132 | delete_post_meta($id, '_your_temp_field');
133 | }
134 |
135 |
136 | /*
137 | * Only perform an action if the post is created
138 | *
139 | */
140 |
141 | function soflyy_save_post( $post_id, $xml, $is_update ) {
142 | if ( !$is_update ) {
143 | // the post is being created, rather than updated.
144 | }
145 | }
146 | add_action( 'pmxi_saved_post', 'soflyy_save_post', 10, 3 );
147 |
148 |
149 | /*
150 | * Add a new stock value to an existing stock value
151 | *
152 | */
153 | function my_add_stock($post_id) {
154 | $new_stock = get_post_meta($post_id, "_new_stock", true);
155 | $current_stock = get_post_meta($post_id, "_stock", true);
156 | $all_stock = ($new_stock + $current_stock);
157 | update_post_meta($post_id, "_stock", $all_stock);
158 | delete_post_meta($post_id, "_new_stock");
159 | }
160 | add_action('pmxi_saved_post', 'my_add_stock', 10, 1);
161 |
162 |
163 | /*
164 | * Import prices to product variations using an import file that
165 | * contains the parent SKU and the price only. The parent price
166 | * needs to be added to a custom field called "_parent_price".
167 | */
168 | function my_set_price($post_id) {
169 | // Get the parent price
170 | $parent_price = get_post_meta($post_id, "_parent_price", true);
171 | // Get the parent
172 | $parent = new WC_Product_Variable($post_id);
173 | // Get the variations
174 | $variations = $parent->get_children();
175 | // Loop through the variations and set the price
176 | foreach ($variations as $variation) {
177 | $single_variation = new WC_Product_Variation($variation);
178 | $variation_id = $single_variation->get_variation_id();
179 | update_post_meta($variation_id, "_price", $parent_price);
180 | update_post_meta($variation_id, "_regular_price", $parent_price);
181 | }
182 | delete_post_meta($post_id, "_parent_price");
183 | }
184 | add_action('pmxi_saved_post', 'my_set_price', 10, 1);
185 |
--------------------------------------------------------------------------------
/all-import/pmxi_single_category.php:
--------------------------------------------------------------------------------
1 | array( 'post' ),
46 | 'meta_query' => array(array(
47 | 'key' => $key_to_look_up,
48 | 'value' => $value_to_look_up,
49 | )),
50 | );
51 |
52 | $query = new WP_Query( $args );
53 | return !($query->have_posts());
54 | }
55 | else {
56 | return true;
57 | }
58 | }
59 |
60 | add_filter('wp_all_import_is_post_to_create', 'create_only_if_unique_custom_field', 10, 3);
61 |
62 |
63 | /**
64 | * Compare a date from your import file to a date specified within the function
65 | * and only import posts if they are newer than the specified date
66 | */
67 | function my_is_post_to_create( $continue_import, $data, $import_id ) {
68 | if ( $import_id == 3 ) { // Change this to the ID of your import
69 | $date_in_file = strtotime( $data['column_4'] ); // Change this to the column name
70 | $date = "2018-10-10"; // Change this to the date you want to import records from
71 | $current_date = strtotime($date);
72 | if ( $date_in_file >= $current_date ) {
73 | return true;
74 | } else {
75 | return false;
76 | }
77 | }
78 | return true;
79 | }
80 | add_filter('wp_all_import_is_post_to_create', 'my_is_post_to_create', 10, 3);
81 |
82 |
83 | /**
84 | * Check if a product SKU already exists on the site.
85 | * If it does, skip importing the record.
86 | */
87 | function my_is_post_to_create( $continue_import, $data, $import_id ) {
88 | // Get the SKU from the import file
89 | $sku = $data['sku']; // Change this to the column name that contains your SKU
90 |
91 | global $wpdb;
92 | // Check if the SKU already exists
93 | $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku ) );
94 |
95 | if ( $product_id ) {
96 | // If product ID exists then skip importing
97 | return false;
98 | } else {
99 | // Else, import the product
100 | return true;
101 | }
102 | }
103 | add_filter('wp_all_import_is_post_to_create', 'my_is_post_to_create', 10, 3);
104 |
--------------------------------------------------------------------------------
/all-import/wp_all_import_is_post_to_delete.php:
--------------------------------------------------------------------------------
1 | id === 5) { ... }
19 | return true;
20 | }
21 |
22 | add_filter('wp_all_import_is_post_to_delete', 'my_is_post_to_delete', 10, 3);
23 |
24 |
25 | // ----------------------------
26 | // Example uses below
27 | // ----------------------------
28 |
29 |
30 | /**
31 | * Example: Delete based on post meta value
32 | *
33 | */
34 | function is_post_to_delete_on_meta($is_post_to_delete, $pid, $import)
35 | {
36 | return ($var = get_post_meta($pid, 'do_not_delete', true)) ? false : true;
37 | }
38 |
39 | add_filter('wp_all_import_is_post_to_delete', 'is_post_to_delete_on_meta', 10, 3);
40 |
41 |
42 | /**
43 | * Example: Delete orphaned variations
44 | *
45 | */
46 | function is_post_to_delete_orphans($to_delete, $pid, $import)
47 | {
48 | if ($import->options['custom_type'] == 'product') {
49 | $post_to_delete = get_post($pid);
50 | switch ($post_to_delete->post_type) {
51 | case 'product':
52 | $to_delete = true;
53 | break;
54 | case 'product_variation':
55 | $parent_product = get_post($post_to_delete->post_parent);
56 | // delete variation only when parent product doesn't exist
57 | $to_delete = empty($parent_product) ? true : false;
58 | break;
59 | }
60 | }
61 | return $to_delete;
62 | }
63 |
64 | add_filter('wp_all_import_is_post_to_delete', 'is_post_to_delete_orphans', 11, 3);
65 |
66 | /**
67 | * Example: Send posts to trash, instead of deleting them
68 | *
69 | */
70 | function import_send_removed_to_trash($is_post_to_delete, $pid, $import) {
71 | wp_update_post(
72 | array(
73 | 'ID' => $pid,
74 | 'post_status' => 'trash'
75 | )
76 | );
77 | }
78 | add_filter('wp_all_import_is_post_to_delete', 'import_send_removed_to_trash', 10, 3);
79 |
--------------------------------------------------------------------------------
/all-import/wp_all_import_is_post_to_update.php:
--------------------------------------------------------------------------------
1 | name == 'Featured'){
38 | $term_taxonomy_ids[] = $cat->term_taxonomy_id;
39 | break;
40 | }
41 | }
42 | }
43 | }
44 | return $term_taxonomy_ids;
45 | }
--------------------------------------------------------------------------------
/all-import/wp_all_import_skip_x_csv_rows.php:
--------------------------------------------------------------------------------
1 | xpath('//mydata[1]/*[1]');
41 |
42 | if (!empty($result[0])) {
43 | $name = $result[0]->getName();
44 | $node->addChild('title', $name);
45 | }
46 |
47 | return $node;
48 | }
49 |
50 | add_filter('wpallimport_xml_row', 'add_title_node', 10, 1);
51 |
52 | /**
53 | * Example of converting HTML or XML embeded within a specific tag into HTML usable for import
54 | *
55 | */
56 | function parse_content($node){
57 | $result = $node->xpath('//content'); // replace this with the XPath of the node
58 | if (!empty($result[0])) {
59 | // Optional replacements to convert custom XML tags to HTML equivalent
60 | $find_xml = array('section_title','section_content','section', 'texteparagraphe','titreparagraphe');
61 | $replace_html = array('h1','p','div','p','h2');
62 | $html = str_replace($find_xml, $replace_html, $result[0]->asXML());
63 | $node->addChild('content_html', $html);
64 | }
65 | return $node;
66 | }
67 |
68 | add_filter('wpallimport_xml_row', 'parse_content', 10, 1);
69 |
70 |
71 | /**
72 | * Example getting the tag names "Commerciale" or "Residenziale" when they
73 | * don't contain any data. These can be called from the import using
74 | * {TYPE[1]}
75 | */
76 | function add_property_type($node) {
77 | // Selects Commerciale in file
78 | $commerciale = $node->xpath('//Commerciale[1]');
79 | // If Commerciale exists add Commerciale to entry
80 | if (!empty($commerciale[0])) {
81 | $node->addChild('TYPE', 'Commerciale');
82 | };
83 |
84 | // Selects Residenziale in file
85 | $residenziale = $node->xpath('//Residenziale[1]');
86 | // If Residenziale exists add Residenziale to entry
87 | if (!empty($residenziale[0])) {
88 | $node->addChild('TYPE', 'Residenziale');
89 | };
90 |
91 | return $node;
92 | };
93 |
94 | add_filter('wpallimport_xml_row', 'add_property_type', 10, 1);
95 |
--------------------------------------------------------------------------------
/woocommerce-add-on/pmxi_product_variation_saved.php:
--------------------------------------------------------------------------------
1 | posts;
31 | $variation = $wpdb->get_row( "SELECT * FROM $table WHERE ID = " . $variation_id );
32 | $parent_post = $variation->post_parent;
33 | }
34 |
--------------------------------------------------------------------------------
/woocommerce-add-on/wp_all_import_get_prices_from_first_variation.php:
--------------------------------------------------------------------------------
1 | posts;
31 | $variations = $wpdb->get_results("SELECT * FROM $table WHERE post_parent = " . $post_parent );
32 | if ( ! empty($variations)){
33 | $empty_variation = array_shift($variations);
34 | if ( ! empty($variations)){
35 | foreach($variations as $variation){
36 | wp_delete_post($variation->ID);
37 | }
38 | }
39 | $table = _get_meta_table('post');
40 | $post_meta = $wpdb->get_results("SELECT meta_key, meta_value FROM $table WHERE post_id = " . $empty_variation->ID . " AND meta_key LIKE 'attribute%';" );
41 | if ( ! empty($post_meta)){
42 | foreach ($post_meta as $meta) {
43 | update_post_meta($empty_variation->ID, $meta->meta_key, '');
44 | }
45 | }
46 | }
47 | }
48 |
49 | /**
50 | * Example: Copy the featured image to the product gallery.
51 | *
52 | */
53 | add_action('wp_all_import_variable_product_imported', 'copy_featured_img_to_gallery', 10, 1);
54 |
55 | function copy_featured_img_to_gallery($post_id)
56 | {
57 | $gallery = explode(",",get_post_meta($post_id, "_product_image_gallery", true));
58 | array_unshift($gallery, get_post_thumbnail_id( $post_id ));
59 | $gallery = array_unique($gallery);
60 | update_post_meta($post_id, "_product_image_gallery", implode(",",$gallery));
61 | }
62 |
--------------------------------------------------------------------------------
/woocommerce-add-on/wp_all_import_variation_any_attribute.php:
--------------------------------------------------------------------------------
1 |