1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/* |
3
|
|
|
* Get and store our variables |
4
|
|
|
* @since 6.0 |
5
|
|
|
*/ |
6
|
|
|
$list_id = $_GET['mailchimp-list']; |
7
|
|
|
$email_id = (int) esc_attr( $_GET['email-id'] ); |
8
|
|
|
|
9
|
|
|
/* |
10
|
|
|
* Confirm that our data is set |
11
|
|
|
* or abort... |
12
|
|
|
*/ |
13
|
|
|
if( ! isset( $list_id ) || ! isset( $email_id ) ) { |
14
|
|
|
wp_die( "We've encountered an error. Please go back and try again", "yikes-inc-easy-mailchimp-extender" ); |
15
|
|
|
exit; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
// run our API call, to get list data.. |
19
|
|
|
$api_key = trim( get_option( 'yikes-mc-api-key' , '' ) ); |
20
|
|
|
$dash_position = strpos( $api_key, '-' ); |
21
|
|
|
|
22
|
|
|
// get this lists data |
23
|
|
|
if( $dash_position !== false ) { |
24
|
|
|
$api_endpoint = 'https://' . substr( $api_key, $dash_position + 1 ) . '.api.mailchimp.com/2.0/lists/member-info.json'; |
25
|
|
|
} |
26
|
|
|
$user_data = wp_remote_post( $api_endpoint, array( |
27
|
|
|
'body' => array( |
28
|
|
|
'apikey' => $api_key, |
29
|
|
|
'id' => $list_id, |
30
|
|
|
'emails' => array( |
31
|
|
|
array( 'leid' => $email_id ) |
32
|
|
|
), |
33
|
|
|
), |
34
|
|
|
'timeout' => 10, |
35
|
|
|
'sslverify' => apply_filters( 'yikes-mailchimp-sslverify', true ), |
36
|
|
|
) ); |
37
|
|
|
$user_data = json_decode( wp_remote_retrieve_body( $user_data ), true ); |
38
|
|
|
|
39
|
|
|
if( isset( $user_data['error'] ) ) { |
40
|
|
|
if( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status' , '' ) == '1' ) { |
41
|
|
|
require_once YIKES_MC_PATH . 'includes/error_log/class-yikes-inc-easy-mailchimp-error-logging.php'; |
42
|
|
|
$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging(); |
43
|
|
|
$error_logging->yikes_easy_mailchimp_write_to_error_log( $user_data['error'], __( "Get Member Info" , 'yikes-inc-easy-mailchimp-extender' ), "View User Page" ); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/* |
48
|
|
|
* Check for MailChimp returned errors |
49
|
|
|
*/ |
50
|
|
|
if( isset( $user_data['error'] ) ) { |
51
|
|
|
echo '<h4>Error</h4>'; |
52
|
|
|
echo $user_data['error'] . '.'; |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if( isset( $user_data['data'][0] ) ) { |
57
|
|
|
// reset our data so we can easily use it |
58
|
|
|
$user_data = $user_data['data'][0]; |
59
|
|
|
|
60
|
|
|
$other_lists = ( isset( $user_data['lists'] ) && ! empty( $user_data['lists'] ) ) ? $user_data['lists'] : array(); |
61
|
|
|
$merge_data_array = ( $user_data['merges'] && ! empty( $user_data['merges'] ) ) ? $user_data['merges'] : array(); |
62
|
|
|
|
63
|
|
|
// print_r( $user_data ); |
|
|
|
|
64
|
|
|
|
65
|
|
|
/* Empty array to populate with list names */ |
66
|
|
|
$additional_lists = array(); |
67
|
|
|
/* Merge Variable Fields */ |
68
|
|
|
$merge_variable_fields = array(); |
69
|
|
|
|
70
|
|
|
/* Build the array of mailing lists the user is subscribed to */ |
71
|
|
|
if( isset( $other_lists ) && count( $other_lists ) >= 1 ) { |
72
|
|
|
foreach( $other_lists as $list ) { |
73
|
|
|
if( $list['status'] == 'subscribed' ) { |
74
|
|
|
if( $dash_position !== false ) { |
75
|
|
|
$api_endpoint = 'https://' . substr( $api_key, $dash_position + 1 ) . '.api.mailchimp.com/2.0/lists/list.json'; |
76
|
|
|
} |
77
|
|
|
$list_data = wp_remote_post( $api_endpoint, array( |
78
|
|
|
'body' => array( |
79
|
|
|
'apikey' => $api_key, |
80
|
|
|
'filters' => array( |
81
|
|
|
'list_id' => $list['id'] |
82
|
|
|
) |
83
|
|
|
), |
84
|
|
|
'timeout' => 10, |
85
|
|
|
'sslverify' => apply_filters( 'yikes-mailchimp-sslverify', true ) |
86
|
|
|
) ); |
87
|
|
|
$list_data = json_decode( wp_remote_retrieve_body( $list_data ), true ); |
88
|
|
|
if( isset( $list_data['error'] ) ) { |
89
|
|
|
if( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status' , '' ) == '1' ) { |
90
|
|
|
require_once YIKES_MC_PATH . 'includes/error_log/class-yikes-inc-easy-mailchimp-error-logging.php'; |
91
|
|
|
$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging(); |
92
|
|
|
$error_logging->yikes_easy_mailchimp_write_to_error_log( $list_data['error'], __( "Get Account Lists" , 'yikes-inc-easy-mailchimp-extender' ), "View User Page" ); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
if( $list_data && isset( $list_data['data'][0] ) ) { |
96
|
|
|
$additional_lists[$list_data['data'][0]['id']] = $list_data['data'][0]['name']; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/* Build the array of merge variables => value */ |
103
|
|
|
if( isset( $merge_data_array ) && count( $merge_data_array ) >= 1 ) { |
104
|
|
|
if( $dash_position !== false ) { |
105
|
|
|
$api_endpoint = 'https://' . substr( $api_key, $dash_position + 1 ) . '.api.mailchimp.com/2.0/lists/merge-vars.json'; |
106
|
|
|
} |
107
|
|
|
$merge_variables = wp_remote_post( $api_endpoint, array( |
108
|
|
|
'body' => array( |
109
|
|
|
'apikey' => $api_key, |
110
|
|
|
'id' => array( $list_id ), |
111
|
|
|
), |
112
|
|
|
'timeout' => 10, |
113
|
|
|
'sslverify' => apply_filters( 'yikes-mailchimp-sslverify', true ) |
114
|
|
|
) ); |
115
|
|
|
$merge_variables = json_decode( wp_remote_retrieve_body( $merge_variables ), true ); |
116
|
|
|
if( isset( $merge_variables['error'] ) ) { |
117
|
|
|
if( WP_DEBUG || get_option( 'yikes-mailchimp-debug-status' , '' ) == '1' ) { |
118
|
|
|
require_once YIKES_MC_PATH . 'includes/error_log/class-yikes-inc-easy-mailchimp-error-logging.php'; |
119
|
|
|
$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging(); |
120
|
|
|
$error_logging->yikes_easy_mailchimp_write_to_error_log( $merge_variables['error'], __( "Get Merge Variables" , 'yikes-inc-easy-mailchimp-extender' ), "View User Page" ); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
// loop and display |
124
|
|
|
if( $merge_variables ) { |
125
|
|
|
foreach( $merge_variables['data'][0]['merge_vars'] as $merge_variable ) { |
126
|
|
|
if( $merge_variable['tag'] != 'EMAIL' ) { |
127
|
|
|
$merge_variable_fields[$merge_variable['name']] = ( isset( $merge_data_array[$merge_variable['tag']] ) ) ? $merge_data_array[$merge_variable['tag']] : ''; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
// store usable data |
135
|
|
|
$user_email = sanitize_email( $user_data['email'] ); |
136
|
|
|
// prepend our email address to the beginning |
137
|
|
|
$merge_variable_fields = array( 'Email Address' => $user_email ) + $merge_variable_fields; |
138
|
|
|
$gravatar_image = get_avatar( $user_email, 120 ); |
139
|
|
|
$email_type = $user_data['email_type']; |
140
|
|
|
$member_rating = ( ! empty( $user_data['member_rating'] ) ) ? (int) $user_data['member_rating'] : 0; |
141
|
|
|
$member_rating_stars = ''; |
142
|
|
|
if( $member_rating > 0 ) { |
143
|
|
|
$x = 1; |
144
|
|
|
while( $x <= 5 ) { |
145
|
|
|
if( $x <= $member_rating ) { |
146
|
|
|
$member_rating_stars .= '<span class="yikes-mc-member-rating-star dashicons dashicons-star-filled"></span>'; |
147
|
|
|
} else { |
148
|
|
|
$member_rating_stars .= '<span class="yikes-mc-member-rating-star dashicons dashicons-star-empty"></span>'; |
149
|
|
|
} |
150
|
|
|
$x++; |
151
|
|
|
} |
152
|
|
|
} else { |
153
|
|
|
$y = 1; |
154
|
|
|
while( $y <= 5 ) { |
155
|
|
|
$member_rating_stars .= '<span class="yikes-mc-member-rating-star dashicons dashicons-star-empty"></span>'; |
156
|
|
|
$y++; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
$last_changed = strtotime( $user_data['info_changed'] ); |
160
|
|
|
$user_language = ( $user_data['language'] && $user_data['language'] != '' ) ? $user_data['language'] : ''; |
161
|
|
|
$list_name = $user_data['list_name']; |
162
|
|
|
|
163
|
|
|
// Generate our display page |
164
|
|
|
?> |
165
|
|
|
<div class="wrap view-user-data-wrap"> |
166
|
|
|
<!-- Freddie Logo --> |
167
|
|
|
<img src="<?php echo YIKES_MC_URL . 'includes/images/MailChimp_Assets/Freddie_60px.png'; ?>" alt="<?php __( 'Freddie - MailChimp Mascot' , 'yikes-inc-easy-mailchimp-extender' ); ?>" class="yikes-mc-freddie-logo" /> |
168
|
|
|
|
169
|
|
|
<h1>YIKES Easy Forms for MailChimp | <?php _e( 'Subscriber Details' , 'yikes-inc-easy-mailchimp-extender' ); ?></h1> |
170
|
|
|
|
171
|
|
|
<!-- Settings Page Description --> |
172
|
|
|
<p class="yikes-easy-mc-about-text about-text"><?php printf( __( 'View %s subscriber details below.' , 'yikes-inc-easy-mailchimp-extender' ), $user_email ); ?></p> |
173
|
|
|
|
174
|
|
|
<section class="yikes-mc-view-list-breadcrumbs"> |
175
|
|
|
<a href="<?php echo esc_url( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-lists' ) ); ?>" title="<?php _e( 'View List', 'yikes-inc-easy-mailchimp-extender' ); ?>"> |
176
|
|
|
<?php _e( 'Optin Forms', 'yikes-inc-easy-mailchimp-extender' ); ?> |
177
|
|
|
</a> |
178
|
|
|
» |
179
|
|
|
<a href="<?php echo esc_url( admin_url( 'admin.php?page=yikes-mailchimp-view-list&list-id=' . $list_id ) ); ?>" title="<?php echo $list_name; ?>"> |
180
|
|
|
<?php echo $list_name; ?> |
181
|
|
|
</a> |
182
|
|
|
» |
183
|
|
|
<span title="<?php echo $user_email; ?>"> |
184
|
|
|
<?php echo $user_email; ?> |
185
|
|
|
</span> |
186
|
|
|
</section> |
187
|
|
|
|
188
|
|
|
<!-- Customer Container --> |
189
|
|
|
<div id="yikes-mc-subscriber-card-wrapper"> |
190
|
|
|
<section class="yikes-mc-card-top"> |
191
|
|
|
<?php echo $gravatar_image; ?> |
192
|
|
|
<h2><?php echo $user_email; ?></h2> |
193
|
|
|
<?php echo '<span class="member-star-rating-container" title="' . sprintf( _n( 'Member Rating: %s star', 'Member Rating: %s stars', $member_rating, 'yikes-inc-easy-mailchimp-extender' ), $member_rating ) . '">' . $member_rating_stars . '</span>'; ?> |
194
|
|
|
<span class="member-subscription-date"> |
195
|
|
|
<?php echo __( 'Subscribed:', 'yikes-inc-easy-mailchimp-extender' ) . ' ' . get_date_from_gmt( $user_data['info_changed'], 'F jS, Y h:i a' ); ?> |
196
|
|
|
</span> |
197
|
|
|
<?php if( isset( $user_data['geo'] ) && ! empty( $user_data['geo'] ) ) { ?> |
198
|
|
|
<?php if( isset( $user_data['geo']['latitude'] ) && isset( $user_data['geo']['longitude'] ) ) { ?> |
199
|
|
|
<span class="member-location-data"> |
200
|
|
|
<?php echo __( 'Location:', 'yikes-inc-easy-mailchimp-extender' ) . ' ' . yikes_mc_geocode_subscriber_data( $user_data['geo']['latitude'], $user_data['geo']['longitude'] ); ?> |
201
|
|
|
</span> |
202
|
|
|
<?php } else { ?> |
203
|
|
|
<span class="member-location-data"> |
204
|
|
|
<?php echo __( 'Location:', 'yikes-inc-easy-mailchimp-extender' ) . ' ' . $user_data['geo']['region'] . ', ' . $user_data['geo']['cc']; ?> |
205
|
|
|
</span> |
206
|
|
|
<?php |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
?> |
210
|
|
|
</section> |
211
|
|
|
|
212
|
|
|
<hr class="yikes-mc-subscriber-hr" /> |
213
|
|
|
|
214
|
|
|
<?php |
215
|
|
|
if( ! isset( $_GET['section'] ) || ( isset( $_GET['section'] ) && $_GET['section'] == 'subscriber-data' ) ) { |
|
|
|
|
216
|
|
|
?> |
217
|
|
|
<section class="yikes-mc-card-body merge-variable-section"> |
218
|
|
|
<h3><?php _e( 'Fields:', 'yikes-inc-easy-mailchimp-extender' ); ?></h3> |
219
|
|
|
<?php |
220
|
|
|
if( ! empty( $merge_variable_fields ) ) { |
221
|
|
|
?> |
222
|
|
|
<?php foreach( $merge_variable_fields as $field_name => $value ) { ?> |
223
|
|
|
<li> |
224
|
|
|
<label> |
225
|
|
|
<strong class="section-label"><?php echo $field_name; ?></strong> |
226
|
|
|
<p class="section-value"><em><?php echo $value; ?></em></p> |
227
|
|
|
</label> |
228
|
|
|
</li> |
229
|
|
|
<?php } |
230
|
|
|
} else { |
231
|
|
|
?> |
232
|
|
|
<strong><?php _e( 'No Subscriber Data Found', 'yikes-inc-easy-mailchimp-extender' ); ?></strong> |
233
|
|
|
<?php |
234
|
|
|
} |
235
|
|
View Code Duplication |
if( isset( $user_data['ip_signup'] ) && $user_data['ip_signup'] != '' ) { |
|
|
|
|
236
|
|
|
?> |
237
|
|
|
<li> |
238
|
|
|
<label> |
239
|
|
|
<strong class="section-label"><?php echo __( 'Signup IP', 'yikes-inc-easy-mailchimp-extender' ) . '</strong><p class="section-value"><em>' . $user_data['ip_signup']; ?></em></p> |
240
|
|
|
</label> |
241
|
|
|
</li> |
242
|
|
|
<?php |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
?> |
246
|
|
|
</section> |
247
|
|
|
<?php |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
if( isset( $_GET['section'] ) && $_GET['section'] == 'additional-subscriptions' ) { |
251
|
|
|
?> |
252
|
|
|
<section class="yikes-mc-card-body"> |
253
|
|
|
<?php |
254
|
|
|
if( ! empty( $additional_lists ) ) { |
255
|
|
|
// remove this list from the additional lists list |
256
|
|
|
unset( $additional_lists[$list_id] ); |
257
|
|
|
if( ! empty( $additional_lists ) ) { |
258
|
|
|
?> |
259
|
|
|
<h3><?php _e( 'Additional Subscriptions:', 'yikes-inc-easy-mailchimp-extender' ); ?></h3> |
260
|
|
|
<?php foreach( $additional_lists as $listid => $name ) { ?> |
261
|
|
|
<?php |
262
|
|
|
$user_redirect_url = esc_url_raw( admin_url( 'admin.php?page=yikes-mailchimp-view-list&list-id=' . $listid ) ); |
263
|
|
|
?> |
264
|
|
|
<li><a href="<?php echo $user_redirect_url; ?>"><?php echo $name; ?></a></li> |
265
|
|
|
<?php } |
266
|
|
|
} |
267
|
|
|
} else { |
268
|
|
|
?> |
269
|
|
|
<strong><?php _e( 'No Other Subscriptions Found.', 'yikes-inc-easy-mailchimp-extender' ); ?></strong> |
270
|
|
|
<?php |
271
|
|
|
} |
272
|
|
|
?> |
273
|
|
|
</section> |
274
|
|
|
<?php |
275
|
|
|
} |
276
|
|
|
?> |
277
|
|
|
|
278
|
|
|
<?php |
279
|
|
|
if( isset( $_GET['section'] ) && $_GET['section'] == 'delete-subscriber' ) { |
280
|
|
|
$unsubscribe_subscriber_url = esc_url_raw( add_query_arg( array( 'action' => 'yikes-easy-mc-unsubscribe-user', 'mailchimp-list' => $list_id , 'nonce' => wp_create_nonce( 'unsubscribe-user-'.$email_id ), 'email_id' => $email_id ) ) ); |
281
|
|
|
?> |
282
|
|
|
<form id="delete_subscriber" method="POST" action="<?php echo $unsubscribe_subscriber_url; ?>"> |
283
|
|
|
<p class="description"> |
284
|
|
|
<?php printf( __( 'Deleting this subscriber will completely remove %s from the "%s" MailChimp list.', 'yikes-inc-easy-mailchimp-extender' ), '<strong>' . $user_email . '</strong>', '<strong>' . $list_name . '</strong>' ); ?> |
285
|
|
|
</p> |
286
|
|
|
<br /> |
287
|
|
|
<label> |
288
|
|
|
<input type="checkbox" name="confirm_delete_subscriber" value="1" onclick="toggleDeleteSubscriberButton(jQuery(this));"> |
289
|
|
|
<?php printf( __( 'Are you sure you want to delete "%s" from "%s?"', 'yikes-inc-easy-mailchimp-extender' ), '<strong>' . $user_email . '</strong>', '<strong>' . $list_name . '</strong>' ); ?> |
290
|
|
|
</label> |
291
|
|
|
<?php echo submit_button( __( 'Delete Subscriber', 'yikes-inc-easy-mailchimp-extender' ), 'primary', 'delete-mailchimp-subscriber', true, array( 'disabled' => 'disabled' ) ); ?> |
292
|
|
|
</form> |
293
|
|
|
<?php |
294
|
|
|
} |
295
|
|
|
?> |
296
|
|
|
|
297
|
|
|
</div> |
298
|
|
|
|
299
|
|
|
<?php |
300
|
|
|
// setup the redirect url for our additional subscriptions |
301
|
|
|
$subscriber_details = esc_url_raw( |
302
|
|
|
add_query_arg( |
303
|
|
|
array( |
304
|
|
|
'section' => 'subscriber-data' |
305
|
|
|
) |
306
|
|
|
) |
307
|
|
|
); |
308
|
|
|
// setup the redirect url for our additional subscriptions |
309
|
|
|
$additional_subscription_url = esc_url_raw( |
310
|
|
|
add_query_arg( |
311
|
|
|
array( |
312
|
|
|
'section' => 'additional-subscriptions' |
313
|
|
|
) |
314
|
|
|
) |
315
|
|
|
); |
316
|
|
|
// setup the redirect url for our delete subscriber |
317
|
|
|
$delete_subscriber_url = esc_url_raw( |
318
|
|
|
add_query_arg( |
319
|
|
|
array( |
320
|
|
|
'section' => 'delete-subscriber' |
321
|
|
|
) |
322
|
|
|
) |
323
|
|
|
); |
324
|
|
|
?> |
325
|
|
|
<!-- Tabs --> |
326
|
|
|
<div id="customer-tab-wrapper"> |
327
|
|
|
<ul id="customer-tab-wrapper-list"> |
328
|
|
|
|
329
|
|
|
<?php if( isset( $_GET['section'] ) && $_GET['section'] != 'subscriber-data' ) { ?> |
330
|
|
|
<a title="<?php _e( 'Subscriber Details', 'yikes-inc-easy-mailchimp-extender' ); ?>" aria-label="<?php _e( 'Subscriber Details', 'yikes-inc-easy-mailchimp-extender' ); ?>" href="<?php echo $subscriber_details; ?>"> |
331
|
|
|
<?php } ?> |
332
|
|
|
|
333
|
|
|
<li <?php if( ! isset( $_GET['section'] ) || ( isset( $_GET['section'] ) && $_GET['section'] == 'subscriber-data' ) ) { ?>class="active"<?php } else { ?>class="inactive"<?php } ?>><span class="dashicons dashicons-id"></span></li> |
334
|
|
|
|
335
|
|
|
<?php if( isset( $_GET['section'] ) && $_GET['section'] != 'subscriber-data' ) { ?> |
336
|
|
|
</a> |
337
|
|
|
<?php } ?> |
338
|
|
|
|
339
|
|
View Code Duplication |
<?php if( ! isset( $_GET['section'] ) || ( isset( $_GET['section'] ) && $_GET['section'] != 'additional-subscriptions' ) ) { ?> |
|
|
|
|
340
|
|
|
<a title="<?php _e( 'Additional Subscriptions', 'yikes-inc-easy-mailchimp-extender' ); ?>" aria-label="<?php _e( 'Additional Subscriptions', 'yikes-inc-easy-mailchimp-extender' ); ?>" href="<?php echo $additional_subscription_url; ?>"> |
341
|
|
|
<?php } ?> |
342
|
|
|
|
343
|
|
|
<li <?php if( isset( $_GET['section'] ) && $_GET['section'] == 'additional-subscriptions' ) { ?>class="active"<?php } else { ?>class="inactive"<?php } ?>><span class="dashicons dashicons-portfolio"></span></li> |
344
|
|
|
|
345
|
|
|
<?php if( ! isset( $_GET['section'] ) || ( isset( $_GET['section'] ) && $_GET['section'] == 'additional-subscriptions' ) ) { ?> |
346
|
|
|
</a> |
347
|
|
|
<?php } ?> |
348
|
|
|
|
349
|
|
View Code Duplication |
<?php if( ! isset( $_GET['section'] ) || isset( $_GET['section'] ) && $_GET['section'] != 'delete-subscriber' ) { ?> |
|
|
|
|
350
|
|
|
<a title="<?php _e( 'Delete Subscriber', 'yikes-inc-easy-mailchimp-extender' ); ?>" aria-label="<?php _e( 'Delete Subscriber', 'yikes-inc-easy-mailchimp-extender' ); ?>" href="<?php echo $delete_subscriber_url; ?>"> |
351
|
|
|
<?php } ?> |
352
|
|
|
|
353
|
|
|
<li <?php if( isset( $_GET['section'] ) && $_GET['section'] == 'delete-subscriber' ) { ?>class="active"<?php } else { ?>class="inactive"<?php } ?>><span class="dashicons dashicons-trash"></span></li> |
354
|
|
|
|
355
|
|
|
<?php if( ! isset( $_GET['section'] ) || ( isset( $_GET['section'] ) && $_GET['section'] == 'delete-subscriber' ) ) { ?> |
356
|
|
|
</a> |
357
|
|
|
<?php } ?> |
358
|
|
|
|
359
|
|
|
</ul> |
360
|
|
|
</div> |
361
|
|
|
|
362
|
|
|
</div> |
363
|
|
|
<?php |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
|
367
|
|
|
function yikes_mc_geocode_subscriber_data( $latitude, $longitude ) { |
368
|
|
|
$geocode_url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' . $latitude . ',' . $longitude; |
369
|
|
|
$geocode_response = wp_remote_get( $geocode_url ); |
370
|
|
|
if( is_wp_error( $geocode_response ) ) { |
371
|
|
|
return; |
372
|
|
|
} |
373
|
|
|
$geocode_response_body = json_decode( wp_remote_retrieve_body( $geocode_response ), true ); |
374
|
|
|
if( is_wp_error( $geocode_response_body ) ) { |
375
|
|
|
return; |
376
|
|
|
} |
377
|
|
|
$city = $geocode_response_body['results'][0]['address_components'][2]['short_name']; |
378
|
|
|
$state = $geocode_response_body['results'][0]['address_components'][5]['short_name']; |
379
|
|
|
$country = $geocode_response_body['results'][0]['address_components'][6]['short_name']; |
380
|
|
|
return $link = '<a href="http://maps.google.com/maps?q=' . $latitude . ',' . $longitude . '" target="_blank" title="' . __( 'View Google Map', 'yikes-inc-easy-mailchimp-extender' ) . '">' . $city . ', ' . $state . ', ' . $country . '</a> <span class="flag-icon flag-icon-' . strtolower( $country ) . '"></span>'; |
|
|
|
|
381
|
|
|
} |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.