-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-group-export.php
More file actions
124 lines (103 loc) · 2.53 KB
/
template-group-export.php
File metadata and controls
124 lines (103 loc) · 2.53 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Template Name: Export - Group List
*/
$args = array(
'post_type' => 'initiatives',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC'
);
$posts = get_posts($args);
$column_titles = array(
'ID',
'Name',
'Hub',
'Tags',
'Country',
'Location',
'Description',
'Public Email',
'Author Email',
'Co-Author Emails',
'Website URL',
'Twitter URL',
'Facebook URL',
'Instagram URL',
'Youtube URL'
);
$export_data = array();
$export_data[] = $column_titles;
foreach($posts as $key => $post) {
setup_postdata($post);
$hubs = wp_get_post_terms($post->ID, 'hub');
if($hubs) {
$hub = $hubs[0]->name;
} else {
$hub = null;
}
$countries = wp_get_post_terms($post->ID, 'country');
if($countries) {
$country = $countries[0]->name;
} else {
$country = null;
}
$tags = get_group_tags($post);
$tag_output = array();
if($tags) {
foreach($tags as $tag) {
$tag_output[] = $tag['label'];
}
$tag_output = implode(', ', $tag_output);
}
//Location
$location = null;
if (get_field('address_line_1')) {
$location = array();
if(get_field('address_line_1')) {
$location[] = get_field('address_line_1');
}
if(get_field('city')) {
$location[] = get_field('city');
}
if(get_field('province')) {
$location[] = get_field('province');
}
if(get_field('postal_code')) {
$location[] = get_field('postal_code');
}
$location = implode(', ', $location);
} else if (get_field('map') && get_field('map')['markers']) {
$location = get_field('map')['markers'][0]['default_label'];
}
$co_authors = ma_get_co_authors($post->ID);
$co_author_emails = array();
foreach($co_authors as $co_author_id) {
$co_author_emails[] = get_userdata($co_author_id)->user_email;
}
$co_author_emails = implode(', ', $co_author_emails);
$export_data[] = array(
get_the_ID(),
get_the_title(),
$hub,
$tag_output,
$country,
trim($location),
strip_tags(get_field('description', $post), '<p><em><strong>'),
get_field('email'),
get_the_author_meta('user_email'),
$co_author_emails,
get_field('website'),
get_field('twitter'),
get_field('facebook'),
get_field('instagram'),
get_field('youtube'),
);
wp_reset_postdata();
}
//secure the export
if(is_user_role('administrator') || is_user_role('super_hub')) {
outputCsv(date('Ymd') . '_transition_groups_export.csv', $export_data);
} else {
wp_redirect(esc_url(add_query_arg('error_code', '1', '/error')));
} ?>