Completed
Push — develop ( 158ffc...1707c4 )
by David
03:00
created
src/admin/WL_Metabox/class-wl-metabox-field.php 2 patches
Indentation   +322 added lines, -322 removed lines patch added patch discarded remove patch
@@ -19,335 +19,335 @@
 block discarded – undo
19 19
  */
20 20
 class WL_Metabox_Field {
21 21
 
22
-	/**
23
-	 * A {@link Wordlift_Log_Service} instance.
24
-	 *
25
-	 * @since  3.15.0
26
-	 * @access protected
27
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
28
-	 */
29
-	protected $log;
30
-
31
-	/**
32
-	 * The meta name for this field's value.
33
-	 *
34
-	 * @var string $meta_name The meta name for this field's value.
35
-	 */
36
-	public $meta_name;
37
-
38
-	/**
39
-	 * The custom field settings.
40
-	 *
41
-	 * @var null|array $raw_custom_field The custom field settings.
42
-	 */
43
-	public $raw_custom_field;
44
-
45
-	/**
46
-	 * The schema.org predicate.
47
-	 *
48
-	 * @var string $predicate The schema.org predicate.
49
-	 */
50
-	public $predicate;
51
-
52
-	/**
53
-	 * The field's label.
54
-	 *
55
-	 * @var string $label The field's label.
56
-	 */
57
-	public $label;
58
-
59
-	/**
60
-	 * The WordLift data type.
61
-	 *
62
-	 * @var string $expected_wl_type The WordLift data type.
63
-	 */
64
-	public $expected_wl_type;
65
-
66
-	/**
67
-	 * The RDF data type.
68
-	 *
69
-	 * @var string $expected_uri_type The RDF data type.
70
-	 */
71
-	public $expected_uri_type;
72
-
73
-	/**
74
-	 * The cardinality.
75
-	 *
76
-	 * @var int $cardinality The cardinality.
77
-	 */
78
-	public $cardinality;
79
-
80
-	/**
81
-	 * The current value.
82
-	 *
83
-	 * @var array $data The current value.
84
-	 */
85
-	public $data;
86
-
87
-	/**
88
-	 * Create a {@link WL_Metabox_Field} instance.
89
-	 *
90
-	 * @param array $args An array of parameters.
91
-	 */
92
-	public function __construct( $args ) {
93
-
94
-		$this->log = Wordlift_Log_Service::get_logger( 'WL_Metabox_Field' );
95
-
96
-		if ( empty( $args ) ) {
97
-			return;
98
-		}
99
-
100
-		// Save a copy of the custom field's params.
101
-		$this->raw_custom_field = reset( $args );
102
-
103
-		// Extract meta name (post_meta key for the DB).
104
-		$this->meta_name = key( $args );
105
-
106
-		// Extract linked data predicate.
107
-		if ( isset( $this->raw_custom_field['predicate'] ) ) {
108
-			$this->predicate = $this->raw_custom_field['predicate'];
109
-		} else {
110
-			return;
111
-		}
112
-
113
-		// Extract human readable label.
114
-		$exploded_predicate = explode( '/', $this->predicate );
115
-
116
-		// Use the label defined for the property if set, otherwise the last part of the schema.org/xyz predicate.
117
-		$this->label = isset( $this->raw_custom_field['metabox']['label'] ) ? $this->raw_custom_field['metabox']['label'] : end( $exploded_predicate );
118
-
119
-		// Extract field constraints (numerosity, expected type).
120
-		// Default constaints: accept one string..
121
-		if ( isset( $this->raw_custom_field['type'] ) ) {
122
-			$this->expected_wl_type = $this->raw_custom_field['type'];
123
-		} else {
124
-			$this->expected_wl_type = Wordlift_Schema_Service::DATA_TYPE_STRING;
125
-		}
126
-
127
-		$this->cardinality = 1;
128
-		if ( isset( $this->raw_custom_field['constraints'] ) ) {
129
-
130
-			$constraints = $this->raw_custom_field['constraints'];
131
-
132
-			// Extract cardinality.
133
-			if ( isset( $constraints['cardinality'] ) ) {
134
-				$this->cardinality = $constraints['cardinality'];
135
-			}
136
-
137
-			// Which type of entity can we accept (e.g. Place, Event, ecc.)? .
138
-			if ( Wordlift_Schema_Service::DATA_TYPE_URI === $this->expected_wl_type
139
-			     && isset( $constraints['uri_type'] ) ) {
140
-				$this->expected_uri_type = is_array( $constraints['uri_type'] )
141
-					? $constraints['uri_type']
142
-					: array( $constraints['uri_type'] );
143
-			}
144
-
145
-		}
146
-	}
147
-
148
-	/**
149
-	 * Return nonce HTML.
150
-	 *
151
-	 * Overwrite this method in a child class to obtain custom behaviour.
152
-	 */
153
-	public function html_nonce() {
154
-
155
-		return wp_nonce_field( 'wordlift_' . $this->meta_name . '_entity_box', 'wordlift_' . $this->meta_name . '_entity_box_nonce', true, false );
156
-	}
157
-
158
-	/**
159
-	 * Verify nonce.
160
-	 *
161
-	 * Overwrite this method in a child class to obtain custom behaviour.
162
-	 *
163
-	 * @return boolean Nonce verification.
164
-	 */
165
-	public function verify_nonce() {
166
-
167
-		$nonce_name   = 'wordlift_' . $this->meta_name . '_entity_box_nonce';
168
-		$nonce_verify = 'wordlift_' . $this->meta_name . '_entity_box';
169
-
170
-		if ( ! isset( $_POST[ $nonce_name ] ) ) {
171
-			return false;
172
-		}
173
-
174
-		// Verify that the nonce is valid.
175
-		return wp_verify_nonce( $_POST[ $nonce_name ], $nonce_verify );
176
-	}
177
-
178
-	/**
179
-	 * Load data from DB and store the resulting array in $this->data.
180
-	 *
181
-	 * Overwrite this method in a child class to obtain custom behaviour.
182
-	 */
183
-	public function get_data() {
184
-
185
-		$data = get_post_meta( get_the_ID(), $this->meta_name );
186
-
187
-		// Values are always contained in an array (makes it easier to manage cardinality).
188
-		if ( ! is_array( $data ) ) {
189
-			$data = array( $data );
190
-		}
191
-
192
-		$this->data = $data;
193
-	}
194
-
195
-	/**
196
-	 * Sanitizes data before saving to DB. Default sanitization trashes empty
197
-	 * values.
198
-	 *
199
-	 * Stores the sanitized values into $this->data so they can be later processed.
200
-	 * Overwrite this method in a child class to obtain custom behaviour.
201
-	 *
202
-	 * @param array $values Array of values to be sanitized and then stored into $this->data
203
-	 */
204
-	public function sanitize_data( $values ) {
205
-
206
-		$sanitized_data = array();
207
-
208
-		if ( ! is_array( $values ) ) {
209
-			$values = array( $values );
210
-		}
211
-
212
-		foreach ( $values as $value ) {
213
-			$sanitized_value = $this->sanitize_data_filter( $value );
214
-			if ( ! is_null( $sanitized_value ) ) {
215
-				$sanitized_data[] = $sanitized_value;
216
-			}
217
-		}
218
-
219
-		$this->data = $sanitized_data;
220
-	}
221
-
222
-	/**
223
-	 * Sanitize a single value. Called from $this->sanitize_data. Default
224
-	 * sanitization excludes empty values.
225
-	 *
226
-	 * Overwrite this method in a child class to obtain custom behaviour.
227
-	 *
228
-	 * @return mixed Returns sanitized value, or null.
229
-	 */
230
-	public function sanitize_data_filter( $value ) {
231
-
232
-		// TODO: all fields should provide their own sanitize which shouldn't be part of a UI class.
233
-		// If the field provides its own validation, use it.
234
-		if ( isset( $this->raw_custom_field['sanitize'] ) ) {
235
-			return call_user_func( $this->raw_custom_field['sanitize'], $value );
236
-		}
237
-
238
-		if ( ! is_null( $value ) && $value !== '' ) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ .
239
-			return $value;
240
-		}
241
-
242
-		return null;
243
-	}
244
-
245
-	/**
246
-	 * Save data to DB.
247
-	 *
248
-	 * Overwrite this method in a child class to obtain custom behaviour.
249
-	 *
250
-	 * @param array $values Array of values to be sanitized and then stored into $this->data.
251
-	 */
252
-	public function save_data( $values ) {
253
-
254
-		// Will sanitize data and store them in $field->data.
255
-		$this->sanitize_data( $values );
256
-
257
-		$entity_id = get_the_ID();
258
-
259
-		// Take away old values.
260
-		delete_post_meta( $entity_id, $this->meta_name );
261
-
262
-		// insert new values, respecting cardinality.
263
-		$single = ( $this->cardinality == 1 );
264
-		foreach ( $this->data as $value ) {
265
-			add_post_meta( $entity_id, $this->meta_name, $value, $single );
266
-		}
267
-	}
268
-
269
-	/**
270
-	 * Returns the HTML tag that will contain the Field. By default the we
271
-	 * return a <div> with data- attributes on cardinality and expected types.
272
-	 *
273
-	 * It is useful to provide data- attributes for the JS scripts.
274
-	 *
275
-	 * Overwrite this method in a child class to obtain custom behaviour.
276
-	 */
277
-	public function html_wrapper_open() {
278
-
279
-		return "<div class='wl-field' data-cardinality='$this->cardinality'>";
280
-	}
281
-
282
-	/**
283
-	 * Returns Field HTML (nonce included).
284
-	 *
285
-	 * Overwrite this method (or methods called from this method) in a child
286
-	 * class to obtain custom behaviour.
287
-	 */
288
-	public function html() {
289
-
290
-		// Open main <div> for the Field.
291
-		$html = $this->html_wrapper_open();
292
-
293
-		// Label.
294
-		$html .= "<h3>$this->label</h3>";
295
-
296
-		// print nonce.
297
-		$html .= $this->html_nonce();
298
-
299
-		// print data loaded from DB.
300
-		$count = 0;
301
-		if ( $this->data ) {
302
-			foreach ( $this->data as $value ) {
303
-				if ( $count < $this->cardinality ) {
304
-					$html .= $this->html_input( $value );
305
-				}
306
-				$count ++;
307
-			}
308
-		}
309
-
310
-		// Print the empty <input> to add new values.
311
-		if ( $count === 0 ) { // } || $count < $this->cardinality ) { DO NOT print empty inputs unless requested by the editor since fields might support empty strings.
312
-			$html .= $this->html_input( '' );    // Will print an empty <input>
313
-			$count ++;
314
-		}
315
-
316
-		// If cardiality allows it, print button to add new values.
317
-		if ( $count < $this->cardinality ) {
318
-			$html .= '<button class="button wl-add-input wl-button" type="button">Add</button>';
319
-		}
320
-
321
-		// Close the HTML wrapper.
322
-		$html .= $this->html_wrapper_close();
323
-
324
-		return $html;
325
-	}
326
-
327
-	/**
328
-	 * Return a single <input> tag for the Field.
329
-	 *
330
-	 * @param mixed $value Input value
331
-	 *
332
-	 * @return string
333
-	 */
334
-	public function html_input( $value ) {
335
-		$html = <<<EOF
22
+    /**
23
+     * A {@link Wordlift_Log_Service} instance.
24
+     *
25
+     * @since  3.15.0
26
+     * @access protected
27
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
28
+     */
29
+    protected $log;
30
+
31
+    /**
32
+     * The meta name for this field's value.
33
+     *
34
+     * @var string $meta_name The meta name for this field's value.
35
+     */
36
+    public $meta_name;
37
+
38
+    /**
39
+     * The custom field settings.
40
+     *
41
+     * @var null|array $raw_custom_field The custom field settings.
42
+     */
43
+    public $raw_custom_field;
44
+
45
+    /**
46
+     * The schema.org predicate.
47
+     *
48
+     * @var string $predicate The schema.org predicate.
49
+     */
50
+    public $predicate;
51
+
52
+    /**
53
+     * The field's label.
54
+     *
55
+     * @var string $label The field's label.
56
+     */
57
+    public $label;
58
+
59
+    /**
60
+     * The WordLift data type.
61
+     *
62
+     * @var string $expected_wl_type The WordLift data type.
63
+     */
64
+    public $expected_wl_type;
65
+
66
+    /**
67
+     * The RDF data type.
68
+     *
69
+     * @var string $expected_uri_type The RDF data type.
70
+     */
71
+    public $expected_uri_type;
72
+
73
+    /**
74
+     * The cardinality.
75
+     *
76
+     * @var int $cardinality The cardinality.
77
+     */
78
+    public $cardinality;
79
+
80
+    /**
81
+     * The current value.
82
+     *
83
+     * @var array $data The current value.
84
+     */
85
+    public $data;
86
+
87
+    /**
88
+     * Create a {@link WL_Metabox_Field} instance.
89
+     *
90
+     * @param array $args An array of parameters.
91
+     */
92
+    public function __construct( $args ) {
93
+
94
+        $this->log = Wordlift_Log_Service::get_logger( 'WL_Metabox_Field' );
95
+
96
+        if ( empty( $args ) ) {
97
+            return;
98
+        }
99
+
100
+        // Save a copy of the custom field's params.
101
+        $this->raw_custom_field = reset( $args );
102
+
103
+        // Extract meta name (post_meta key for the DB).
104
+        $this->meta_name = key( $args );
105
+
106
+        // Extract linked data predicate.
107
+        if ( isset( $this->raw_custom_field['predicate'] ) ) {
108
+            $this->predicate = $this->raw_custom_field['predicate'];
109
+        } else {
110
+            return;
111
+        }
112
+
113
+        // Extract human readable label.
114
+        $exploded_predicate = explode( '/', $this->predicate );
115
+
116
+        // Use the label defined for the property if set, otherwise the last part of the schema.org/xyz predicate.
117
+        $this->label = isset( $this->raw_custom_field['metabox']['label'] ) ? $this->raw_custom_field['metabox']['label'] : end( $exploded_predicate );
118
+
119
+        // Extract field constraints (numerosity, expected type).
120
+        // Default constaints: accept one string..
121
+        if ( isset( $this->raw_custom_field['type'] ) ) {
122
+            $this->expected_wl_type = $this->raw_custom_field['type'];
123
+        } else {
124
+            $this->expected_wl_type = Wordlift_Schema_Service::DATA_TYPE_STRING;
125
+        }
126
+
127
+        $this->cardinality = 1;
128
+        if ( isset( $this->raw_custom_field['constraints'] ) ) {
129
+
130
+            $constraints = $this->raw_custom_field['constraints'];
131
+
132
+            // Extract cardinality.
133
+            if ( isset( $constraints['cardinality'] ) ) {
134
+                $this->cardinality = $constraints['cardinality'];
135
+            }
136
+
137
+            // Which type of entity can we accept (e.g. Place, Event, ecc.)? .
138
+            if ( Wordlift_Schema_Service::DATA_TYPE_URI === $this->expected_wl_type
139
+                 && isset( $constraints['uri_type'] ) ) {
140
+                $this->expected_uri_type = is_array( $constraints['uri_type'] )
141
+                    ? $constraints['uri_type']
142
+                    : array( $constraints['uri_type'] );
143
+            }
144
+
145
+        }
146
+    }
147
+
148
+    /**
149
+     * Return nonce HTML.
150
+     *
151
+     * Overwrite this method in a child class to obtain custom behaviour.
152
+     */
153
+    public function html_nonce() {
154
+
155
+        return wp_nonce_field( 'wordlift_' . $this->meta_name . '_entity_box', 'wordlift_' . $this->meta_name . '_entity_box_nonce', true, false );
156
+    }
157
+
158
+    /**
159
+     * Verify nonce.
160
+     *
161
+     * Overwrite this method in a child class to obtain custom behaviour.
162
+     *
163
+     * @return boolean Nonce verification.
164
+     */
165
+    public function verify_nonce() {
166
+
167
+        $nonce_name   = 'wordlift_' . $this->meta_name . '_entity_box_nonce';
168
+        $nonce_verify = 'wordlift_' . $this->meta_name . '_entity_box';
169
+
170
+        if ( ! isset( $_POST[ $nonce_name ] ) ) {
171
+            return false;
172
+        }
173
+
174
+        // Verify that the nonce is valid.
175
+        return wp_verify_nonce( $_POST[ $nonce_name ], $nonce_verify );
176
+    }
177
+
178
+    /**
179
+     * Load data from DB and store the resulting array in $this->data.
180
+     *
181
+     * Overwrite this method in a child class to obtain custom behaviour.
182
+     */
183
+    public function get_data() {
184
+
185
+        $data = get_post_meta( get_the_ID(), $this->meta_name );
186
+
187
+        // Values are always contained in an array (makes it easier to manage cardinality).
188
+        if ( ! is_array( $data ) ) {
189
+            $data = array( $data );
190
+        }
191
+
192
+        $this->data = $data;
193
+    }
194
+
195
+    /**
196
+     * Sanitizes data before saving to DB. Default sanitization trashes empty
197
+     * values.
198
+     *
199
+     * Stores the sanitized values into $this->data so they can be later processed.
200
+     * Overwrite this method in a child class to obtain custom behaviour.
201
+     *
202
+     * @param array $values Array of values to be sanitized and then stored into $this->data
203
+     */
204
+    public function sanitize_data( $values ) {
205
+
206
+        $sanitized_data = array();
207
+
208
+        if ( ! is_array( $values ) ) {
209
+            $values = array( $values );
210
+        }
211
+
212
+        foreach ( $values as $value ) {
213
+            $sanitized_value = $this->sanitize_data_filter( $value );
214
+            if ( ! is_null( $sanitized_value ) ) {
215
+                $sanitized_data[] = $sanitized_value;
216
+            }
217
+        }
218
+
219
+        $this->data = $sanitized_data;
220
+    }
221
+
222
+    /**
223
+     * Sanitize a single value. Called from $this->sanitize_data. Default
224
+     * sanitization excludes empty values.
225
+     *
226
+     * Overwrite this method in a child class to obtain custom behaviour.
227
+     *
228
+     * @return mixed Returns sanitized value, or null.
229
+     */
230
+    public function sanitize_data_filter( $value ) {
231
+
232
+        // TODO: all fields should provide their own sanitize which shouldn't be part of a UI class.
233
+        // If the field provides its own validation, use it.
234
+        if ( isset( $this->raw_custom_field['sanitize'] ) ) {
235
+            return call_user_func( $this->raw_custom_field['sanitize'], $value );
236
+        }
237
+
238
+        if ( ! is_null( $value ) && $value !== '' ) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ .
239
+            return $value;
240
+        }
241
+
242
+        return null;
243
+    }
244
+
245
+    /**
246
+     * Save data to DB.
247
+     *
248
+     * Overwrite this method in a child class to obtain custom behaviour.
249
+     *
250
+     * @param array $values Array of values to be sanitized and then stored into $this->data.
251
+     */
252
+    public function save_data( $values ) {
253
+
254
+        // Will sanitize data and store them in $field->data.
255
+        $this->sanitize_data( $values );
256
+
257
+        $entity_id = get_the_ID();
258
+
259
+        // Take away old values.
260
+        delete_post_meta( $entity_id, $this->meta_name );
261
+
262
+        // insert new values, respecting cardinality.
263
+        $single = ( $this->cardinality == 1 );
264
+        foreach ( $this->data as $value ) {
265
+            add_post_meta( $entity_id, $this->meta_name, $value, $single );
266
+        }
267
+    }
268
+
269
+    /**
270
+     * Returns the HTML tag that will contain the Field. By default the we
271
+     * return a <div> with data- attributes on cardinality and expected types.
272
+     *
273
+     * It is useful to provide data- attributes for the JS scripts.
274
+     *
275
+     * Overwrite this method in a child class to obtain custom behaviour.
276
+     */
277
+    public function html_wrapper_open() {
278
+
279
+        return "<div class='wl-field' data-cardinality='$this->cardinality'>";
280
+    }
281
+
282
+    /**
283
+     * Returns Field HTML (nonce included).
284
+     *
285
+     * Overwrite this method (or methods called from this method) in a child
286
+     * class to obtain custom behaviour.
287
+     */
288
+    public function html() {
289
+
290
+        // Open main <div> for the Field.
291
+        $html = $this->html_wrapper_open();
292
+
293
+        // Label.
294
+        $html .= "<h3>$this->label</h3>";
295
+
296
+        // print nonce.
297
+        $html .= $this->html_nonce();
298
+
299
+        // print data loaded from DB.
300
+        $count = 0;
301
+        if ( $this->data ) {
302
+            foreach ( $this->data as $value ) {
303
+                if ( $count < $this->cardinality ) {
304
+                    $html .= $this->html_input( $value );
305
+                }
306
+                $count ++;
307
+            }
308
+        }
309
+
310
+        // Print the empty <input> to add new values.
311
+        if ( $count === 0 ) { // } || $count < $this->cardinality ) { DO NOT print empty inputs unless requested by the editor since fields might support empty strings.
312
+            $html .= $this->html_input( '' );    // Will print an empty <input>
313
+            $count ++;
314
+        }
315
+
316
+        // If cardiality allows it, print button to add new values.
317
+        if ( $count < $this->cardinality ) {
318
+            $html .= '<button class="button wl-add-input wl-button" type="button">Add</button>';
319
+        }
320
+
321
+        // Close the HTML wrapper.
322
+        $html .= $this->html_wrapper_close();
323
+
324
+        return $html;
325
+    }
326
+
327
+    /**
328
+     * Return a single <input> tag for the Field.
329
+     *
330
+     * @param mixed $value Input value
331
+     *
332
+     * @return string
333
+     */
334
+    public function html_input( $value ) {
335
+        $html = <<<EOF
336 336
 			<div class="wl-input-wrapper">
337 337
 				<input type="text" id="$this->meta_name" name="wl_metaboxes[$this->meta_name][]" value="$value" style="width:88%" />
338 338
 				<button class="button wl-remove-input wl-button" type="button">Remove</button>
339 339
 			</div>
340 340
 EOF;
341 341
 
342
-		return $html;
343
-	}
342
+        return $html;
343
+    }
344 344
 
345
-	/**
346
-	 * Returns closing for the wrapper HTML tag.
347
-	 */
348
-	public function html_wrapper_close() {
345
+    /**
346
+     * Returns closing for the wrapper HTML tag.
347
+     */
348
+    public function html_wrapper_close() {
349 349
 
350
-		return '</div><hr>';
351
-	}
350
+        return '</div><hr>';
351
+    }
352 352
 
353 353
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -89,57 +89,57 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @param array $args An array of parameters.
91 91
 	 */
92
-	public function __construct( $args ) {
92
+	public function __construct($args) {
93 93
 
94
-		$this->log = Wordlift_Log_Service::get_logger( 'WL_Metabox_Field' );
94
+		$this->log = Wordlift_Log_Service::get_logger('WL_Metabox_Field');
95 95
 
96
-		if ( empty( $args ) ) {
96
+		if (empty($args)) {
97 97
 			return;
98 98
 		}
99 99
 
100 100
 		// Save a copy of the custom field's params.
101
-		$this->raw_custom_field = reset( $args );
101
+		$this->raw_custom_field = reset($args);
102 102
 
103 103
 		// Extract meta name (post_meta key for the DB).
104
-		$this->meta_name = key( $args );
104
+		$this->meta_name = key($args);
105 105
 
106 106
 		// Extract linked data predicate.
107
-		if ( isset( $this->raw_custom_field['predicate'] ) ) {
107
+		if (isset($this->raw_custom_field['predicate'])) {
108 108
 			$this->predicate = $this->raw_custom_field['predicate'];
109 109
 		} else {
110 110
 			return;
111 111
 		}
112 112
 
113 113
 		// Extract human readable label.
114
-		$exploded_predicate = explode( '/', $this->predicate );
114
+		$exploded_predicate = explode('/', $this->predicate);
115 115
 
116 116
 		// Use the label defined for the property if set, otherwise the last part of the schema.org/xyz predicate.
117
-		$this->label = isset( $this->raw_custom_field['metabox']['label'] ) ? $this->raw_custom_field['metabox']['label'] : end( $exploded_predicate );
117
+		$this->label = isset($this->raw_custom_field['metabox']['label']) ? $this->raw_custom_field['metabox']['label'] : end($exploded_predicate);
118 118
 
119 119
 		// Extract field constraints (numerosity, expected type).
120 120
 		// Default constaints: accept one string..
121
-		if ( isset( $this->raw_custom_field['type'] ) ) {
121
+		if (isset($this->raw_custom_field['type'])) {
122 122
 			$this->expected_wl_type = $this->raw_custom_field['type'];
123 123
 		} else {
124 124
 			$this->expected_wl_type = Wordlift_Schema_Service::DATA_TYPE_STRING;
125 125
 		}
126 126
 
127 127
 		$this->cardinality = 1;
128
-		if ( isset( $this->raw_custom_field['constraints'] ) ) {
128
+		if (isset($this->raw_custom_field['constraints'])) {
129 129
 
130 130
 			$constraints = $this->raw_custom_field['constraints'];
131 131
 
132 132
 			// Extract cardinality.
133
-			if ( isset( $constraints['cardinality'] ) ) {
133
+			if (isset($constraints['cardinality'])) {
134 134
 				$this->cardinality = $constraints['cardinality'];
135 135
 			}
136 136
 
137 137
 			// Which type of entity can we accept (e.g. Place, Event, ecc.)? .
138
-			if ( Wordlift_Schema_Service::DATA_TYPE_URI === $this->expected_wl_type
139
-			     && isset( $constraints['uri_type'] ) ) {
140
-				$this->expected_uri_type = is_array( $constraints['uri_type'] )
138
+			if (Wordlift_Schema_Service::DATA_TYPE_URI === $this->expected_wl_type
139
+			     && isset($constraints['uri_type'])) {
140
+				$this->expected_uri_type = is_array($constraints['uri_type'])
141 141
 					? $constraints['uri_type']
142
-					: array( $constraints['uri_type'] );
142
+					: array($constraints['uri_type']);
143 143
 			}
144 144
 
145 145
 		}
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function html_nonce() {
154 154
 
155
-		return wp_nonce_field( 'wordlift_' . $this->meta_name . '_entity_box', 'wordlift_' . $this->meta_name . '_entity_box_nonce', true, false );
155
+		return wp_nonce_field('wordlift_'.$this->meta_name.'_entity_box', 'wordlift_'.$this->meta_name.'_entity_box_nonce', true, false);
156 156
 	}
157 157
 
158 158
 	/**
@@ -164,15 +164,15 @@  discard block
 block discarded – undo
164 164
 	 */
165 165
 	public function verify_nonce() {
166 166
 
167
-		$nonce_name   = 'wordlift_' . $this->meta_name . '_entity_box_nonce';
168
-		$nonce_verify = 'wordlift_' . $this->meta_name . '_entity_box';
167
+		$nonce_name   = 'wordlift_'.$this->meta_name.'_entity_box_nonce';
168
+		$nonce_verify = 'wordlift_'.$this->meta_name.'_entity_box';
169 169
 
170
-		if ( ! isset( $_POST[ $nonce_name ] ) ) {
170
+		if ( ! isset($_POST[$nonce_name])) {
171 171
 			return false;
172 172
 		}
173 173
 
174 174
 		// Verify that the nonce is valid.
175
-		return wp_verify_nonce( $_POST[ $nonce_name ], $nonce_verify );
175
+		return wp_verify_nonce($_POST[$nonce_name], $nonce_verify);
176 176
 	}
177 177
 
178 178
 	/**
@@ -182,11 +182,11 @@  discard block
 block discarded – undo
182 182
 	 */
183 183
 	public function get_data() {
184 184
 
185
-		$data = get_post_meta( get_the_ID(), $this->meta_name );
185
+		$data = get_post_meta(get_the_ID(), $this->meta_name);
186 186
 
187 187
 		// Values are always contained in an array (makes it easier to manage cardinality).
188
-		if ( ! is_array( $data ) ) {
189
-			$data = array( $data );
188
+		if ( ! is_array($data)) {
189
+			$data = array($data);
190 190
 		}
191 191
 
192 192
 		$this->data = $data;
@@ -201,17 +201,17 @@  discard block
 block discarded – undo
201 201
 	 *
202 202
 	 * @param array $values Array of values to be sanitized and then stored into $this->data
203 203
 	 */
204
-	public function sanitize_data( $values ) {
204
+	public function sanitize_data($values) {
205 205
 
206 206
 		$sanitized_data = array();
207 207
 
208
-		if ( ! is_array( $values ) ) {
209
-			$values = array( $values );
208
+		if ( ! is_array($values)) {
209
+			$values = array($values);
210 210
 		}
211 211
 
212
-		foreach ( $values as $value ) {
213
-			$sanitized_value = $this->sanitize_data_filter( $value );
214
-			if ( ! is_null( $sanitized_value ) ) {
212
+		foreach ($values as $value) {
213
+			$sanitized_value = $this->sanitize_data_filter($value);
214
+			if ( ! is_null($sanitized_value)) {
215 215
 				$sanitized_data[] = $sanitized_value;
216 216
 			}
217 217
 		}
@@ -227,15 +227,15 @@  discard block
 block discarded – undo
227 227
 	 *
228 228
 	 * @return mixed Returns sanitized value, or null.
229 229
 	 */
230
-	public function sanitize_data_filter( $value ) {
230
+	public function sanitize_data_filter($value) {
231 231
 
232 232
 		// TODO: all fields should provide their own sanitize which shouldn't be part of a UI class.
233 233
 		// If the field provides its own validation, use it.
234
-		if ( isset( $this->raw_custom_field['sanitize'] ) ) {
235
-			return call_user_func( $this->raw_custom_field['sanitize'], $value );
234
+		if (isset($this->raw_custom_field['sanitize'])) {
235
+			return call_user_func($this->raw_custom_field['sanitize'], $value);
236 236
 		}
237 237
 
238
-		if ( ! is_null( $value ) && $value !== '' ) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ .
238
+		if ( ! is_null($value) && $value !== '') {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ .
239 239
 			return $value;
240 240
 		}
241 241
 
@@ -249,20 +249,20 @@  discard block
 block discarded – undo
249 249
 	 *
250 250
 	 * @param array $values Array of values to be sanitized and then stored into $this->data.
251 251
 	 */
252
-	public function save_data( $values ) {
252
+	public function save_data($values) {
253 253
 
254 254
 		// Will sanitize data and store them in $field->data.
255
-		$this->sanitize_data( $values );
255
+		$this->sanitize_data($values);
256 256
 
257 257
 		$entity_id = get_the_ID();
258 258
 
259 259
 		// Take away old values.
260
-		delete_post_meta( $entity_id, $this->meta_name );
260
+		delete_post_meta($entity_id, $this->meta_name);
261 261
 
262 262
 		// insert new values, respecting cardinality.
263
-		$single = ( $this->cardinality == 1 );
264
-		foreach ( $this->data as $value ) {
265
-			add_post_meta( $entity_id, $this->meta_name, $value, $single );
263
+		$single = ($this->cardinality == 1);
264
+		foreach ($this->data as $value) {
265
+			add_post_meta($entity_id, $this->meta_name, $value, $single);
266 266
 		}
267 267
 	}
268 268
 
@@ -298,23 +298,23 @@  discard block
 block discarded – undo
298 298
 
299 299
 		// print data loaded from DB.
300 300
 		$count = 0;
301
-		if ( $this->data ) {
302
-			foreach ( $this->data as $value ) {
303
-				if ( $count < $this->cardinality ) {
304
-					$html .= $this->html_input( $value );
301
+		if ($this->data) {
302
+			foreach ($this->data as $value) {
303
+				if ($count < $this->cardinality) {
304
+					$html .= $this->html_input($value);
305 305
 				}
306
-				$count ++;
306
+				$count++;
307 307
 			}
308 308
 		}
309 309
 
310 310
 		// Print the empty <input> to add new values.
311
-		if ( $count === 0 ) { // } || $count < $this->cardinality ) { DO NOT print empty inputs unless requested by the editor since fields might support empty strings.
312
-			$html .= $this->html_input( '' );    // Will print an empty <input>
313
-			$count ++;
311
+		if ($count === 0) { // } || $count < $this->cardinality ) { DO NOT print empty inputs unless requested by the editor since fields might support empty strings.
312
+			$html .= $this->html_input(''); // Will print an empty <input>
313
+			$count++;
314 314
 		}
315 315
 
316 316
 		// If cardiality allows it, print button to add new values.
317
-		if ( $count < $this->cardinality ) {
317
+		if ($count < $this->cardinality) {
318 318
 			$html .= '<button class="button wl-add-input wl-button" type="button">Add</button>';
319 319
 		}
320 320
 
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	 *
332 332
 	 * @return string
333 333
 	 */
334
-	public function html_input( $value ) {
334
+	public function html_input($value) {
335 335
 		$html = <<<EOF
336 336
 			<div class="wl-input-wrapper">
337 337
 				<input type="text" id="$this->meta_name" name="wl_metaboxes[$this->meta_name][]" value="$value" style="width:88%" />
Please login to merge, or discard this patch.