Website Building
WP All Import
4min
With WP All Import modules in Make, you can watch for new imports and exports.
To use the WP All Import modules, you must have a WP All Import account. You can create an account at wpallimport.com. You must also have a WordPress account with WP All Import and WP All Export plugins.
- Optional: Enter a name for the webhook in the Webhook name field.
- Click Save > Copy address to clipboard.
- Depending on the instant module you chose in Step 1, click on either the All Import or All Export plugin > Settings.
- Depending on the plugin you are using, paste the relevant function in the Function Editor field.
- Locate the wp_remote_post("https://hook.make.com/<webhook_id>", $args); line in the function you pasted and replace https://hook.make.com/<webhook_id> with the address copied in Step 3.
- Click Save Functions.
Import
1<?php
2
3function after_import($import_id, $import)
4
5{
6
7global $wpdb;
8
9$table = $wpdb->prefix . "pmxi_imports";
10
11// Retrieve the import data from the database
12
13$import_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `$table` WHERE `id` = %d", $import_id), ARRAY_A);
14
15// Check if the import data was found
16
17if ($import_data) {
18
19// Check if the 'options' field is set and unserialize it
20
21if (isset($import_data['options'])) {
22
23$import_data['options'] = unserialize($import_data['options']);
24
25}
26
27}
28
29// Define the HTTP request arguments
30
31$args = array(
32
33'timeout' => 5,
34
35'redirection' => 5,
36
37'httpversion' => '1.0',
38
39'blocking' => true,
40
41'headers' => array(),
42
43'cookies' => array(),
44
45'body' => $import_data,
46
47);
48
49// Sends import data to the webhook URL specified.
50
51wp_remote_post("https://hook.make.com/<webhook_id>", $args);
52
53}
54
55 add_action('pmxi_after_xml_import', 'after_import', 10, 2);
56
57?>
Export
1<?php
2
3function after_export($export_id, $export)
4
5{
6
7// Check whether "Secure Mode" is enabled in All Export -> Settings
8
9$is_secure_export = PMXE_Plugin::getInstance()->getOption('secure');
10
11if (!$is_secure_export) {
12
13$filepath = get_attached_file($export->attch_id);
14
15} else {
16
17$filepath = wp_all_export_get_absolute_path($export->options['filepath']);
18
19}
20
21$wp_uploads = wp_upload_dir();
22
23$fileurl = str_replace($wp_uploads['basedir'], $wp_uploads['baseurl'], $filepath);
24
25$body = (array) $export;
26
27// Add export file details to the body if the file exists
28
29if (file_exists($filepath))
30
31{
32
33$body['export_file_url'] = $fileurl;
34
35$body['file_name'] = basename($filepath);
36
37$body['file_type'] = wp_all_export_get_export_format($export->options);
38
39$body['export_trigger_type'] = empty($_GET['export_key']) ? 'manual' : 'cron';
40
41}
42
43// Define the HTTP request arguments
44
45$args = array(
46
47'method'=> 'POST',
48
49'body'=> $body,
50
51'timeout' => 5,
52
53'redirection' => 5,
54
55'httpversion' => '1.0',
56
57'blocking'=> true,
58
59'headers'=> array(),
60
61'cookies'=> array(),
62
63);
64
65// Sends export data to the webhook URL specified
66
67wp_remote_post("https://hook.make.com/<webhook_id>", $args);
68
69}
70
71add_action('pmxe_after_export', 'after_export', 10, 2);
72
73?>
WP All Import will now send data to through the webhook when the selected event occurs.
You can perform the following acti with WP All Import modules:
Triggers
- Watch New Import
- Watch New Export