-
Notifications
You must be signed in to change notification settings - Fork 27
/
pmxi_after_xml_import.php
60 lines (53 loc) · 1.8 KB
/
pmxi_after_xml_import.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* ==================================
* Action: pmxi_after_xml_import
* ==================================
*
* Called after an import is complete.
* Useful for any cleanup or other task that needs to be performed after an import.
* For hooks to execute after a post is saved see pmxi_after_post_import & pmxi_saved_post
*
* @param $import_id int - The import in progress
* @param $import - The import object
*/
function after_xml_import($import_id, $import)
{
// Unless you want this code to execute for every import, check the import id
// if ($import_id == 5) { ... }
}
add_action('pmxi_after_xml_import', 'after_xml_import', 10, 2);
// ----------------------------
// Example uses below
// ----------------------------
/**
* Send an email containing the import results after the import has finished.
*
*/
function email_results( $import_id ) {
global $wpdb;
$table = $wpdb->prefix . 'pmxi_imports';
$data = $wpdb->get_row( 'SELECT * FROM `' . $table . '` WHERE `ID` = "' . $import_id . '"' );
if ( $data ) {
$msg = "Import Report for Import ID " . $import_id . "\r\n\r\n";
$msg .= "Created: " . $data->created . "\r\n";
$msg .= "Updated: " . $data->updated . "\r\n";
$msg .= "Skipped: " . $data->skipped . "\r\n";
$msg .= "Deleted: " . $data->deleted . "\r\n";
wp_mail( '[email protected]', 'Import Report', $msg );
}
}
add_action( 'pmxi_after_xml_import', 'email_results', 10, 1 );
/**
* Delete import file once the import completes
*
*/
function wp_all_import_after_xml_import( $import_id ) {
$import = new PMXI_Import_Record();
$import->getById( $import_id );
if ( ! $import->isEmpty() ) {
$path = wp_all_import_get_absolute_path( $import->path );
@unlink( $path );
}
}
add_action( 'pmxi_after_xml_import', 'wp_all_import_after_xml_import', 10, 1 );