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 4.8.6 4.8.7 4.8.8 4.8.9 4.9.0 4.9.1 4.9.10 4.9.11 4.9.12 4.9.13 4.9.14 4.9.15 4.9.16 4.9.17 4.9.18 4.9.19 4.9.2 4.9.20 4.9.21 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 trunk 1.1.5 1.2.1 1.2.3 1.2.4 1.2.5 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8
mailchimp-for-wp / includes / class-field-formatter.php
mailchimp-for-wp / includes Last commit date
admin 2 months ago api 2 months ago forms 2 months ago integrations 2 months ago views 6 months ago class-container.php 1 year ago class-debug-log-reader.php 2 months ago class-debug-log.php 2 months ago class-dynamic-content-tags.php 10 months ago class-field-formatter.php 1 year ago class-field-guesser.php 1 year ago class-list-data-mapper.php 4 months ago class-mailchimp-subscriber.php 2 months ago class-mailchimp.php 2 months ago class-personal-data-exporter.php 1 year ago class-plugin.php 1 year ago class-queue-job.php 1 year ago class-queue.php 1 year ago class-tools.php 1 year ago default-actions.php 1 year ago default-filters.php 1 year ago deprecated-functions.php 3 years ago functions.php 1 year ago
class-field-formatter.php
149 lines
1 <?php
2
3 /**
4 * Class MC4WP_Field_Formatter
5 *
6 * Formats values based on what the Mailchimp API expects or accepts for the given field types.
7 */
8 class MC4WP_Field_Formatter
9 {
10 /**
11 * @param mixed $value
12 * @param object $options
13 * @return array
14 */
15 public function address($value, $options = null)
16 {
17 // auto-format if this is a string
18 if (is_string($value)) {
19 // addr1, addr2, city, state, zip, country
20 $address_pieces = explode(',', $value);
21 $address_pieces = array_filter($address_pieces);
22 $address_pieces = array_values($address_pieces);
23
24 // try to fill it.... this is a long shot
25 $value = [
26 'addr1' => $address_pieces[0],
27 'city' => isset($address_pieces[1]) ? $address_pieces[1] : '',
28 'state' => isset($address_pieces[2]) ? $address_pieces[2] : '',
29 'zip' => isset($address_pieces[3]) ? $address_pieces[3] : '',
30 ];
31
32 if (! empty($address_pieces[4])) {
33 $value['country'] = $address_pieces[4];
34 }
35 } elseif (is_array($value)) {
36 // merge with array of empty defaults to allow skipping certain fields
37 $default = array_fill_keys([ 'addr1', 'city', 'state', 'zip' ], '');
38 $value = array_merge($default, $value);
39 }
40
41 return $value;
42 }
43
44 /**
45 * @param mixed $value
46 * @param object $options
47 * @return string
48 */
49 public function birthday($value, $options = null)
50 {
51 $format = is_object($options) && isset($options->date_format) ? $options->date_format : 'MM/DD';
52
53 if (is_array($value)) {
54 // allow for "day" and "month" fields
55 if (isset($value['month']) && isset($value['day'])) {
56 $value = $value['month'] . '/' . $value['day'];
57 } else {
58 // if other array, just join together
59 $value = join('/', $value);
60 }
61 }
62
63 $value = trim($value);
64 if (empty($value)) {
65 return $value;
66 }
67
68 // always use slashes as delimiter, so next part works
69 $value = str_replace([ '.', '-' ], '/', $value);
70
71 // if format = DD/MM OR if first part is definitely a day value (>12), then flip order
72 // this allows `strtotime` to understand `dd/mm` values
73 $values = explode('/', $value);
74 if ($format === 'DD/MM' || ( $values[0] > 12 && $values[0] <= 31 && isset($values[1]) && $values[1] <= 12 )) {
75 $values = array_reverse($values);
76 $value = join('/', $values);
77 }
78
79 // Mailchimp expects a MM/DD format, regardless of their display preference
80 $value = (string) gmdate('m/d', strtotime($value));
81 return $value;
82 }
83
84 /**
85 * @param mixed $value
86 * @param object $options
87 * @return string
88 */
89 public function date($value, $options = null)
90 {
91 if (is_array($value)) {
92 // allow for "year", "month" and "day" keys
93 if (isset($value['year']) && isset($value['month']) && isset($value['day'])) {
94 $value = $value['year'] . '/' . $value['month'] . '/' . $value['day'];
95 } else {
96 // if other array, just join together
97 $value = join('/', $value);
98 }
99 }
100
101 $value = trim($value);
102 if (empty($value)) {
103 return $value;
104 }
105
106 // Mailchimp expects a Y-m-d format no matter the display preference
107 return (string) gmdate('Y-m-d', strtotime($value));
108 }
109
110 /**
111 * @param string $value
112 * @param object $options
113 * @return string
114 */
115 public function language($value, $options = null)
116 {
117 $value = trim($value);
118
119 $exceptions = [
120 'pt_PT',
121 'es_ES',
122 'fr_CA',
123 ];
124
125 if (! in_array($value, $exceptions, true)) {
126 $value = substr($value, 0, 2);
127 }
128
129 return $value;
130 }
131
132 /**
133 * @param mixed $value
134 * @param object $options
135 * @return bool
136 */
137 public function boolean($value, $options = null)
138 {
139 $falsey = [ 'false', '0' ];
140
141 if (in_array($value, $falsey, true)) {
142 return false;
143 }
144
145 // otherwise, just cast.
146 return (bool) $value;
147 }
148 }
149