-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathpmxe_after_export.php
71 lines (57 loc) · 2.35 KB
/
pmxe_after_export.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
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* ======================================
* Action: pmxe_after_export
* ======================================
* Perform some action after the export is complete.
*
* Note: In the case of this hook, the code needs to be added elsewhere.
* For example, your theme's functions.php file or a plugin like "Code Snippets".
*
* @param $export_id int - The ID of the export that's running
* @param $exportObj object - Contains all of the data related to the export (export stats, export settings, the data being exported, etc.).
*
*/
function wp_all_export_after_export($export_id, $exportObj)
{
// Unless you want this to execute for every export you should check the id here:
// if ($export_id === 5) {
}
add_action('pmxe_after_export', 'wp_all_export_after_export', 10, 2);
// ----------------------------
// Example uses below
// ----------------------------
/**
* Gets the export file once the export is complete
*/
add_action('pmxe_after_export', 'wpae_get_file_after_export', 10, 2);
function wpae_get_file_after_export($export_id, $exportObj){
// Check whether "Secure Mode" is enabled in All Export -> Settings
$is_secure_export = PMXE_Plugin::getInstance()->getOption('secure');
if (!$is_secure_export) {
$filepath = get_attached_file($exportObj->attch_id);
} else {
$filepath = wp_all_export_get_absolute_path($exportObj->options['filepath']);
}
// Code to handle $filepath here
// e.g., rename( $filepath, "/path/to/new/folder/export-file-name.csv" );
}
/**
* Move export file to /wp-content/uploads once the export is complete
*/
add_action('pmxe_after_export', 'wpae_move_export_file_to_root_upload_folder', 10, 2);
function wpae_move_export_file_to_root_upload_folder ($export_id, $exportObj){
// Get WordPress's upload directory information
$upload_dir = wp_get_upload_dir();
// Check whether "Secure Mode" is enabled in All Export -> Settings
$is_secure_export = PMXE_Plugin::getInstance()->getOption('secure');
if (!$is_secure_export) {
$filepath = get_attached_file($exportObj->attch_id);
} else {
$filepath = wp_all_export_get_absolute_path($exportObj->options['filepath']);
}
// Get the filename
$filename = basename( $filepath );
// Code to move export file into /wp-content/uploads
rename( $filepath, $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $filename );
}