forked from soflyy/wp-all-import-action-reference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp_all_export_csv_rows.php
More file actions
74 lines (64 loc) · 2.15 KB
/
wp_all_export_csv_rows.php
File metadata and controls
74 lines (64 loc) · 2.15 KB
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
72
73
74
<?php
/**
* ==================================
* Filter: wp_all_export_csv_rows
* ==================================
*
* Filters the records to export.
* This is for CSV formatted exports only. See 'wp_all_export_xml_rows' for filtering XML exports.
*
* @param $articles - An array of records for exporting. Each article is keyed by the column header name for that field.
* @param $options
* @param $export_id int - The export in progress
*
* @return array - the records to export
*/
function wp_all_export_csv_rows($articles, $options, $export_id)
{
// Unless you want this code to execute for every export, be sure to check the export id
// if ($export_id == 5) { ...
// Loop through the array and unset() any entries you don't want exported
// foreach ($articles as $key => $article) {
// if ($article["Title"] == "Something") {
// unset($articles[$key]);
// }
// }
return $articles; // Return the array of records to export
}
add_filter('wp_all_export_csv_rows', 'wp_all_export_csv_rows', 10, 3);
// ----------------------------
// Example uses below
// ----------------------------
/**
* Export based on some criteria. In this case pricing.
*
*/
function my_export_csv_rows($articles, $options, $export_id)
{
foreach ($articles as $key => $article) {
if (!empty($article['Regular Price'] && !empty($article['Sale Price']))) {
if ($article['Sale Price'] < ($article['Regular Price'] / 2)) {
unset($articles[$key]);
}
}
}
return $articles;
}
add_filter('wp_all_export_csv_rows', 'my_export_csv_rows', 10, 3);
/**
* Export based on date in the "_my_time" field
*
*/
function wp_all_export_csv_rows($articles, $options, $export_id)
{
// Loop through the array and unset() any entries you don't want exported
foreach ($articles as $key => $article) {
$date = date(strtotime("tomorrow"));
$my_time = strtotime($article["_my_time"]);
if ($my_time < $date) {
unset($articles[$key]);
}
}
return $articles; // Return the array of records to export
}
add_filter('wp_all_export_csv_rows', 'wp_all_export_csv_rows', 10, 3);