Completed
Push — master ( 99bfa0...934407 )
by Naveen
01:11
created
src/includes/class-wordlift-schema-service.php 2 patches
Indentation   +1239 added lines, -1239 removed lines patch added patch discarded remove patch
@@ -18,1244 +18,1244 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Schema_Service {
20 20
 
21
-	/**
22
-	 * The 'location created' field name.
23
-	 *
24
-	 * @since 3.5.0
25
-	 */
26
-	const FIELD_LOCATION_CREATED = 'wl_location_created';
27
-
28
-	/**
29
-	 * The 'topic' field name.
30
-	 *
31
-	 * @since 3.5.0
32
-	 */
33
-	const FIELD_TOPIC = 'wl_topic';
34
-
35
-	/**
36
-	 * The 'author' field name.
37
-	 *
38
-	 * @since 3.1.0
39
-	 */
40
-	const FIELD_AUTHOR = 'wl_author';
41
-
42
-	/**
43
-	 * The 'same as' field name.
44
-	 *
45
-	 * @since 3.1.0
46
-	 */
47
-	const FIELD_SAME_AS = 'entity_same_as';
48
-
49
-	/**
50
-	 * The 'date start' field name.
51
-	 *
52
-	 * @since 3.1.0
53
-	 */
54
-	const FIELD_DATE_START = 'wl_cal_date_start';
55
-
56
-	/**
57
-	 * The 'date end' field name.
58
-	 *
59
-	 * @since 3.1.0
60
-	 */
61
-	const FIELD_DATE_END = 'wl_cal_date_end';
62
-
63
-	/**
64
-	 * The 'location' field name.
65
-	 *
66
-	 * @since 3.1.0
67
-	 */
68
-	const FIELD_LOCATION = 'wl_location';
69
-
70
-	/**
71
-	 * The 'founder' field name.
72
-	 *
73
-	 * @since 3.1.0
74
-	 */
75
-	const FIELD_FOUNDER = 'wl_founder';
76
-
77
-	/**
78
-	 * The 'knows' field name.
79
-	 *
80
-	 * @since 3.1.0
81
-	 */
82
-	const FIELD_KNOWS = 'wl_knows';
83
-
84
-	/**
85
-	 * The 'birth date' field name.
86
-	 *
87
-	 * @since 3.1.0
88
-	 */
89
-	const FIELD_BIRTH_DATE = 'wl_birth_date';
90
-
91
-	/**
92
-	 * The 'birth place' field name.
93
-	 *
94
-	 * @since 3.1.0
95
-	 */
96
-	const FIELD_BIRTH_PLACE = 'wl_birth_place';
97
-
98
-	/**
99
-	 * The 'latitude' field name.
100
-	 *
101
-	 * @since 3.1.0
102
-	 */
103
-	const FIELD_GEO_LATITUDE = 'wl_geo_latitude';
104
-
105
-	/**
106
-	 * The 'longitude' field name.
107
-	 *
108
-	 * @since 3.1.0
109
-	 */
110
-	const FIELD_GEO_LONGITUDE = 'wl_geo_longitude';
111
-
112
-	/**
113
-	 * The 'streetAddress' field name.
114
-	 *
115
-	 * @since 3.1.0
116
-	 */
117
-	const FIELD_ADDRESS = 'wl_address';
118
-
119
-	/**
120
-	 * The 'postOfficeBoxNumber' field name.
121
-	 *
122
-	 * @since 3.3.0
123
-	 */
124
-	const FIELD_ADDRESS_PO_BOX = 'wl_address_post_office_box';
125
-
126
-	/**
127
-	 * The 'postalCode' field name.
128
-	 *
129
-	 * @since 3.3.0
130
-	 */
131
-	const FIELD_ADDRESS_POSTAL_CODE = 'wl_address_postal_code';
132
-
133
-	/**
134
-	 * The 'addressLocality' field name.
135
-	 *
136
-	 * @since 3.3.0
137
-	 */
138
-	const FIELD_ADDRESS_LOCALITY = 'wl_address_locality';
139
-	/**
140
-	 * The 'addressRegion' field name.
141
-	 *
142
-	 * @since 3.3.0
143
-	 */
144
-	const FIELD_ADDRESS_REGION = 'wl_address_region';
145
-
146
-	/**
147
-	 * The 'addressCountry' field name.
148
-	 *
149
-	 * @since 3.3.0
150
-	 */
151
-	const FIELD_ADDRESS_COUNTRY = 'wl_address_country';
152
-
153
-	/**
154
-	 * The 'entity type' field name.
155
-	 *
156
-	 * @since 3.1.0
157
-	 */
158
-	const FIELD_ENTITY_TYPE = 'wl_entity_type_uri';
159
-
160
-	/**
161
-	 * The 'email' field name.
162
-	 *
163
-	 * @since 3.2.0
164
-	 */
165
-	const FIELD_EMAIL = 'wl_email';
166
-
167
-	/**
168
-	 * The 'affiliation' field name.
169
-	 *
170
-	 * @since 3.2.0
171
-	 */
172
-	const FIELD_AFFILIATION = 'wl_affiliation';
173
-
174
-	/**
175
-	 * The 'telephone' field name.
176
-	 *
177
-	 * @since 3.8.0
178
-	 */
179
-	const FIELD_TELEPHONE = 'wl_schema_telephone';
180
-
181
-	/**
182
-	 * The 'legalName' field name.
183
-	 *
184
-	 * @since 3.12.0
185
-	 */
186
-	const FIELD_LEGAL_NAME = 'wl_schema_legal_name';
187
-
188
-	/**
189
-	 * The 'recipeCuisine' field name.
190
-	 *
191
-	 * @since 3.14.0
192
-	 */
193
-	const FIELD_RECIPE_CUISINE = 'wl_schema_recipe_cuisine';
194
-
195
-	/**
196
-	 * The 'recipeIngredient' field name.
197
-	 *
198
-	 * @since 3.14.0
199
-	 */
200
-	const FIELD_RECIPE_INGREDIENT = 'wl_schema_recipe_ingredient';
201
-
202
-	/**
203
-	 * The 'calories' field name.
204
-	 *
205
-	 * @since 3.14.0
206
-	 */
207
-	const FIELD_NUTRITION_INFO_CALORIES = 'wl_schema_nutrition_information_calories';
208
-
209
-	/**
210
-	 * The 'recipeInstructions' field name.
211
-	 *
212
-	 * @since 3.14.0
213
-	 */
214
-	const FIELD_RECIPE_INSTRUCTIONS = 'wl_schema_recipe_instructions';
215
-
216
-	/**
217
-	 * The 'recipeYield' field name.
218
-	 *
219
-	 * @since 3.14.0
220
-	 */
221
-	const FIELD_RECIPE_YIELD = 'wl_schema_recipe_yield';
222
-
223
-	/**
224
-	 * The 'prepTime' field name.
225
-	 *
226
-	 * @since 3.14.0
227
-	 */
228
-	const FIELD_PREP_TIME = 'wl_schema_prep_time';
229
-
230
-	/**
231
-	 * The 'cookTime' field name.
232
-	 *
233
-	 * @since 3.14.0
234
-	 */
235
-	const FIELD_COOK_TIME = 'wl_schema_cook_time';
236
-
237
-	/**
238
-	 * The 'totalTime' field name.
239
-	 *
240
-	 * @since 3.14.0
241
-	 */
242
-	const FIELD_TOTAL_TIME = 'wl_schema_total_time';
243
-
244
-	/**
245
-	 * The 'performer' field name.
246
-	 *
247
-	 * @since 3.18.0
248
-	 */
249
-	const FIELD_PERFORMER = 'wl_schema_performer';
250
-
251
-	/**
252
-	 * The 'offers' field name.
253
-	 *
254
-	 * @since 3.18.0
255
-	 */
256
-	const FIELD_OFFERS = 'wl_schema_offers';
257
-
258
-	/**
259
-	 * The 'availablity' field name.
260
-	 *
261
-	 * @since 3.18.0
262
-	 */
263
-	const FIELD_AVAILABILITY = 'wl_schema_availability';
264
-
265
-	/**
266
-	 * The 'inventoryLevel' field name.
267
-	 *
268
-	 * @since 3.18.0
269
-	 */
270
-	const FIELD_INVENTORY_LEVEL = 'wl_schema_inventory_level';
271
-
272
-	/**
273
-	 * The 'price' field name.
274
-	 *
275
-	 * @since 3.18.0
276
-	 */
277
-	const FIELD_PRICE = 'wl_schema_price';
278
-
279
-	/**
280
-	 * The 'priceCurrency' field name.
281
-	 *
282
-	 * @since 3.18.0
283
-	 */
284
-	const FIELD_PRICE_CURRENCY = 'wl_schema_price_currency';
285
-
286
-	/**
287
-	 * The 'availabilityStarts' field name.
288
-	 *
289
-	 * @since 3.18.0
290
-	 */
291
-	const FIELD_AVAILABILITY_STARTS = 'wl_schema_availability_starts';
292
-
293
-	/**
294
-	 * The 'availabilityEnds' field name.
295
-	 *
296
-	 * @since 3.18.0
297
-	 */
298
-	const FIELD_AVAILABILITY_ENDS = 'wl_schema_availability_ends';
299
-
300
-	/**
301
-	 * The 'validFrom' field name.
302
-	 *
303
-	 * @since 3.18.0
304
-	 */
305
-	const FIELD_VALID_FROM = 'wl_schema_valid_from';
306
-
307
-	/**
308
-	 * The 'priceValidUntil' field name.
309
-	 *
310
-	 * @since 3.18.0
311
-	 */
312
-	const FIELD_PRICE_VALID_UNTIL = 'wl_schema_valid_until';
313
-
314
-	/**
315
-	 * The 'itemOffered' field name.
316
-	 *
317
-	 * @since 3.18.0
318
-	 */
319
-	const FIELD_ITEM_OFFERED = 'wl_schema_item_offered';
320
-
321
-	/**
322
-	 * The 'URI' data type name.
323
-	 *
324
-	 * @since 3.1.0
325
-	 */
326
-	const DATA_TYPE_URI = 'uri';
327
-
328
-	/**
329
-	 * The 'date' data type name.
330
-	 *
331
-	 * @since 3.1.0
332
-	 */
333
-	const DATA_TYPE_DATE = 'date';
334
-
335
-	/**
336
-	 * The 'time' data type name.
337
-	 *
338
-	 * @since 3.14.0
339
-	 */
340
-	const DATA_TYPE_DURATION = 'duration';
341
-
342
-	/**
343
-	 * The 'double' data type name.
344
-	 *
345
-	 * @since 3.1.0
346
-	 */
347
-	const DATA_TYPE_DOUBLE = 'double';
348
-
349
-	/**
350
-	 * The 'string' data type name.
351
-	 *
352
-	 * @since 3.1.0
353
-	 */
354
-	const DATA_TYPE_STRING = 'string';
355
-
356
-	/**
357
-	 * The multiline text data type name.
358
-	 *
359
-	 * @since 3.14.0
360
-	 */
361
-	const DATA_TYPE_MULTILINE = 'multiline';
362
-
363
-	/**
364
-	 * The schema.org Event type URI.
365
-	 *
366
-	 * @since 3.1.0
367
-	 */
368
-	const SCHEMA_EVENT_TYPE = 'http://schema.org/Event';
369
-
370
-	/**
371
-	 * The schema.org Offer type URI.
372
-	 *
373
-	 * @since 3.18.0
374
-	 */
375
-	const SCHEMA_OFFER_TYPE = 'http://schema.org/Offer';
376
-
377
-	/**
378
-	 * WordLift's schema.
379
-	 *
380
-	 * @since  3.1.0
381
-	 * @access private
382
-	 * @var array $schema WordLift's schema.
383
-	 */
384
-	private $schema;
385
-
386
-	/**
387
-	 * The Log service.
388
-	 *
389
-	 * @since  3.1.0
390
-	 * @access private
391
-	 * @var \Wordlift_Log_Service $log The Log service.
392
-	 */
393
-	private $log;
394
-
395
-	/**
396
-	 * Wordlift_Schema_Service constructor.
397
-	 *
398
-	 * @since 3.1.0
399
-	 */
400
-	protected function __construct() {
401
-
402
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
403
-
404
-		/**
405
-		 * Alter the configured schemas.
406
-		 *
407
-		 * Enable 3rd parties to alter WordLift's schemas array.
408
-		 *
409
-		 * @param array $schemas The array of schemas.
410
-		 *
411
-		 * @since  3.19.1
412
-		 */
413
-		$this->schema = apply_filters(
414
-			'wl_schemas',
415
-			array(
416
-				'article'        => $this->get_article_schema(),
417
-				'thing'          => $this->get_thing_schema(),
418
-				'creative-work'  => $this->get_creative_work_schema(),
419
-				'event'          => $this->get_event_schema(),
420
-				'organization'   => $this->get_organization_schema(),
421
-				'person'         => $this->get_person_schema(),
422
-				'place'          => $this->get_place_schema(),
423
-				'local-business' => $this->get_local_business_schema(),
424
-				'recipe'         => $this->get_recipe_schema(),
425
-				'web-page'       => $this->get_web_page_schema(),
426
-				'offer'          => $this->get_offer_schema(),
427
-			)
428
-		);
429
-
430
-		// Create a singleton instance of the Schema service, useful to provide static functions to global functions.
431
-		self::$instance = $this;
432
-
433
-	}
434
-
435
-	public function get_all_schema_slugs() {
436
-		return array_keys( $this->schema );
437
-	}
438
-
439
-	/**
440
-	 * The Schema service singleton instance.
441
-	 *
442
-	 * @since  3.1.0
443
-	 * @access private
444
-	 * @var Wordlift_Schema_Service $instance The Schema service singleton instance.
445
-	 */
446
-	private static $instance = null;
447
-
448
-	/**
449
-	 * Get a reference to the Schema service.
450
-	 *
451
-	 * @return Wordlift_Schema_Service A reference to the Schema service.
452
-	 * @since 3.1.0
453
-	 */
454
-	public static function get_instance() {
455
-		if ( ! isset( self::$instance ) ) {
456
-			self::$instance = new self();
457
-		}
458
-
459
-		return self::$instance;
460
-	}
461
-
462
-	/**
463
-	 * Get the properties for a field with the specified key. The key is used as
464
-	 * meta key when the field's value is stored in WordPress meta data table.
465
-	 *
466
-	 * @param string $key The field's key.
467
-	 *
468
-	 * @return null|array An array of field's properties or null if the field is not found.
469
-	 * @since 3.6.0
470
-	 */
471
-	public function get_field( $key ) {
472
-
473
-		// Parse each schema's fields until we find the one we're looking for, then
474
-		// return its properties.
475
-		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
476
-		foreach ( $this->schema as $_ => $schema ) {
477
-
478
-			if ( ! isset( $schema['custom_fields'] ) ) {
479
-				break;
480
-			}
481
-
482
-			foreach ( $schema['custom_fields'] as $field => $props ) {
483
-				if ( $key === $field ) {
484
-					return $props;
485
-				}
486
-			}
487
-		}
488
-
489
-		return null;
490
-	}
491
-
492
-	/**
493
-	 * Get the WordLift's schema.
494
-	 *
495
-	 * @param string $name The schema name.
496
-	 *
497
-	 * @return array|null An array with the schema configuration or NULL if the schema is not found.
498
-	 *
499
-	 * @since 3.1.0
500
-	 */
501
-	public function get_schema( $name ) {
502
-		// Check if the schema exists and, if not, return NULL.
503
-		if ( ! isset( $this->schema[ $name ] ) ) {
504
-			return null;
505
-		}
506
-
507
-		// Return the requested schema.
508
-		return $this->schema[ $name ];
509
-	}
510
-
511
-	/**
512
-	 * Get the WordLift's schema trough schema type uri.
513
-	 *
514
-	 * @param string $uri The schema uri.
515
-	 *
516
-	 * @return array|null An array with the schema configuration or NULL if the schema is not found.
517
-	 *
518
-	 * @since 3.3.0
519
-	 */
520
-	public function get_schema_by_uri( $uri ) {
521
-
522
-		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
523
-		foreach ( $this->schema as $name => $schema ) {
524
-			if ( $schema['uri'] === $uri ) {
525
-				return $schema;
526
-			}
527
-		}
528
-
529
-		return null;
530
-	}
531
-
532
-	/**
533
-	 * Get the 'thing' schema.
534
-	 *
535
-	 * @return array An array with the schema configuration.
536
-	 *
537
-	 * @since 3.1.0
538
-	 */
539
-	private function get_thing_schema() {
540
-
541
-		return array(
542
-			'css_class'     => 'wl-thing',
543
-			'uri'           => 'http://schema.org/Thing',
544
-			'same_as'       => array( '*' ),
545
-			// set as default.
546
-			'custom_fields' => array(
547
-				self::FIELD_SAME_AS => array(
548
-					'predicate'   => 'http://schema.org/sameAs',
549
-					'type'        => self::DATA_TYPE_URI,
550
-					'export_type' => 'http://schema.org/Thing',
551
-					'constraints' => array(
552
-						'cardinality' => INF,
553
-					),
554
-					// We need a custom metabox.
555
-					'input_field' => 'sameas',
556
-				),
557
-				// Add the schema:url property.
558
-				Wordlift_Schema_Url_Property_Service::META_KEY => Wordlift_Schema_Url_Property_Service::get_instance()
559
-																									  ->get_compat_definition(),
560
-			),
561
-			// {{sameAs}} not present in the microdata template,
562
-			// because it is treated separately in *wl_content_embed_item_microdata*
563
-			'templates'     => array(
564
-				'subtitle' => '{{id}}',
565
-			),
566
-		);
567
-
568
-	}
569
-
570
-	/**
571
-	 * Get the 'web-page' schema.
572
-	 *
573
-	 * @return array An array with the schema configuration.
574
-	 *
575
-	 * @since 3.18.0
576
-	 */
577
-	private function get_web_page_schema() {
578
-
579
-		return array(
580
-			'css_class' => 'wl-webpage',
581
-			'uri'       => 'http://schema.org/WebPage',
582
-		);
583
-
584
-	}
585
-
586
-	/**
587
-	 * Get the 'creative work' schema.
588
-	 *
589
-	 * @return array An array with the schema configuration.
590
-	 *
591
-	 * @since 3.1.0
592
-	 */
593
-	private function get_creative_work_schema() {
594
-
595
-		$schema = array(
596
-			'label'         => 'CreativeWork',
597
-			'description'   => 'A creative work (or a Music Album).',
598
-			'parents'       => array( 'thing' ),
599
-			// Give term slug as parent.
600
-			'css_class'     => 'wl-creative-work',
601
-			'uri'           => 'http://schema.org/CreativeWork',
602
-			'same_as'       => array(
603
-				'http://schema.org/MusicAlbum',
604
-				'http://schema.org/Product',
605
-			),
606
-			'custom_fields' => array(
607
-				self::FIELD_AUTHOR => array(
608
-					'predicate'   => 'http://schema.org/author',
609
-					'type'        => self::DATA_TYPE_URI,
610
-					'export_type' => 'http://schema.org/Person',
611
-					'constraints' => array(
612
-						'uri_type'    => array( 'Person', 'Organization' ),
613
-						'cardinality' => INF,
614
-					),
615
-				),
616
-			),
617
-			'templates'     => array(
618
-				'subtitle' => '{{id}}',
619
-			),
620
-		);
621
-
622
-		// Merge the custom fields with those provided by the thing schema.
623
-		$parent_schema           = $this->get_thing_schema();
624
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
625
-
626
-		return $schema;
627
-	}
628
-
629
-	/**
630
-	 * Get the 'event' schema.
631
-	 *
632
-	 * @return array An array with the schema configuration.
633
-	 *
634
-	 * @since 3.1.0
635
-	 */
636
-	private function get_event_schema() {
637
-
638
-		$schema = array(
639
-			'label'         => 'Event',
640
-			'description'   => 'An event . ',
641
-			'parents'       => array( 'thing' ),
642
-			'css_class'     => 'wl-event',
643
-			'uri'           => self::SCHEMA_EVENT_TYPE,
644
-			'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
645
-			'custom_fields' => array(
646
-				self::FIELD_DATE_START => array(
647
-					'predicate'   => 'http://schema.org/startDate',
648
-					'type'        => self::DATA_TYPE_DATE,
649
-					'export_type' => 'xsd:dateTime',
650
-					'constraints' => '',
651
-				),
652
-				self::FIELD_DATE_END   => array(
653
-					'predicate'   => 'http://schema.org/endDate',
654
-					'type'        => self::DATA_TYPE_DATE,
655
-					'export_type' => 'xsd:dateTime',
656
-					'constraints' => '',
657
-				),
658
-				self::FIELD_LOCATION   => array(
659
-					'predicate'   => 'http://schema.org/location',
660
-					'type'        => self::DATA_TYPE_URI,
661
-					'export_type' => 'http://schema.org/PostalAddress',
662
-					'constraints' => array(
663
-						'uri_type'    => array( 'Place', 'LocalBusiness' ),
664
-						'cardinality' => INF,
665
-					),
666
-				),
667
-				self::FIELD_PERFORMER  => array(
668
-					'predicate'   => 'http://schema.org/performer',
669
-					'type'        => self::DATA_TYPE_URI,
670
-					'export_type' => 'http://schema.org/Person',
671
-					'constraints' => array(
672
-						'uri_type'    => array( 'Person', 'Organization' ),
673
-						'cardinality' => INF,
674
-					),
675
-				),
676
-				self::FIELD_OFFERS     => array(
677
-					'predicate'   => 'http://schema.org/offers',
678
-					'type'        => self::DATA_TYPE_URI,
679
-					'export_type' => 'http://schema.org/Offer',
680
-					'constraints' => array(
681
-						'uri_type'    => array( 'Offer' ),
682
-						'cardinality' => INF,
683
-					),
684
-				),
685
-			),
686
-			'templates'     => array(
687
-				'subtitle' => '{{id}}',
688
-			),
689
-		);
690
-
691
-		// Merge the custom fields with those provided by the thing schema.
692
-		$parent_schema           = $this->get_thing_schema();
693
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
694
-
695
-		return $schema;
696
-	}
697
-
698
-	/**
699
-	 * Get the 'organization' schema.
700
-	 *
701
-	 * @return array An array with the schema configuration.
702
-	 *
703
-	 * @since 3.1.0
704
-	 */
705
-	private function get_organization_schema() {
706
-
707
-		$schema = array(
708
-			'label'         => 'Organization',
709
-			'description'   => 'An organization, including a government or a newspaper.',
710
-			'parents'       => array( 'thing' ),
711
-			'css_class'     => 'wl-organization',
712
-			'uri'           => 'http://schema.org/Organization',
713
-			'same_as'       => array(
714
-				'http://rdf.freebase.com/ns/organization.organization',
715
-				'http://rdf.freebase.com/ns/government.government',
716
-				'http://schema.org/Newspaper',
717
-			),
718
-			'custom_fields' => array(
719
-				self::FIELD_LEGAL_NAME          => array(
720
-					'predicate'   => 'http://schema.org/legalName',
721
-					'type'        => self::DATA_TYPE_STRING,
722
-					'export_type' => 'xsd:string',
723
-					'constraints' => '',
724
-				),
725
-				self::FIELD_FOUNDER             => array(
726
-					'predicate'   => 'http://schema.org/founder',
727
-					'type'        => self::DATA_TYPE_URI,
728
-					'export_type' => 'http://schema.org/Person',
729
-					'constraints' => array(
730
-						'uri_type'    => 'Person',
731
-						'cardinality' => INF,
732
-					),
733
-				),
734
-				self::FIELD_ADDRESS             => array(
735
-					'predicate'   => 'http://schema.org/streetAddress',
736
-					'type'        => self::DATA_TYPE_STRING,
737
-					'export_type' => 'xsd:string',
738
-					'constraints' => '',
739
-					// To build custom metabox.
740
-					'input_field' => 'address',
741
-				),
742
-				self::FIELD_ADDRESS_PO_BOX      => array(
743
-					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
744
-					'type'        => self::DATA_TYPE_STRING,
745
-					'export_type' => 'xsd:string',
746
-					'constraints' => '',
747
-					// To build custom metabox.
748
-					'input_field' => 'address',
749
-				),
750
-				self::FIELD_ADDRESS_POSTAL_CODE => array(
751
-					'predicate'   => 'http://schema.org/postalCode',
752
-					'type'        => self::DATA_TYPE_STRING,
753
-					'export_type' => 'xsd:string',
754
-					'constraints' => '',
755
-					// To build custom metabox.
756
-					'input_field' => 'address',
757
-				),
758
-				self::FIELD_ADDRESS_LOCALITY    => array(
759
-					'predicate'   => 'http://schema.org/addressLocality',
760
-					'type'        => self::DATA_TYPE_STRING,
761
-					'export_type' => 'xsd:string',
762
-					'constraints' => '',
763
-					// To build custom metabox.
764
-					'input_field' => 'address',
765
-				),
766
-				self::FIELD_ADDRESS_REGION      => array(
767
-					'predicate'   => 'http://schema.org/addressRegion',
768
-					'type'        => self::DATA_TYPE_STRING,
769
-					'export_type' => 'xsd:string',
770
-					'constraints' => '',
771
-					// To build custom metabox.
772
-					'input_field' => 'address',
773
-				),
774
-				self::FIELD_ADDRESS_COUNTRY     => array(
775
-					'predicate'   => 'http://schema.org/addressCountry',
776
-					'type'        => self::DATA_TYPE_STRING,
777
-					'export_type' => 'xsd:string',
778
-					'constraints' => '',
779
-					// To build custom metabox.
780
-					'input_field' => 'address',
781
-				),
782
-				self::FIELD_EMAIL               => array(
783
-					'predicate'   => 'http://schema.org/email',
784
-					'type'        => self::DATA_TYPE_STRING,
785
-					'export_type' => 'xsd:string',
786
-					'constraints' => '',
787
-				),
788
-				self::FIELD_TELEPHONE           => array(
789
-					'predicate'   => 'http://schema.org/telephone',
790
-					'type'        => self::DATA_TYPE_STRING,
791
-					'export_type' => 'xsd:string',
792
-					'constraints' => '',
793
-				),
794
-			),
795
-			'templates'     => array(
796
-				'subtitle' => '{{id}}',
797
-			),
798
-		);
799
-
800
-		// Merge the custom fields with those provided by the thing schema.
801
-		$parent_schema           = $this->get_thing_schema();
802
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
803
-
804
-		return $schema;
805
-	}
806
-
807
-	/**
808
-	 * Get the 'person' schema.
809
-	 *
810
-	 * @return array An array with the schema configuration.
811
-	 *
812
-	 * @since 3.1.0
813
-	 */
814
-	private function get_person_schema() {
815
-
816
-		$schema = array(
817
-			'label'         => 'Person',
818
-			'description'   => 'A person (or a music artist).',
819
-			'parents'       => array( 'thing' ),
820
-			'css_class'     => 'wl-person',
821
-			'uri'           => 'http://schema.org/Person',
822
-			'same_as'       => array(
823
-				'http://rdf.freebase.com/ns/people.person',
824
-				'http://rdf.freebase.com/ns/music.artist',
825
-				'http://dbpedia.org/class/yago/LivingPeople',
826
-			),
827
-			'custom_fields' => array(
828
-				self::FIELD_KNOWS       => array(
829
-					'predicate'   => 'http://schema.org/knows',
830
-					'type'        => self::DATA_TYPE_URI,
831
-					'export_type' => 'http://schema.org/Person',
832
-					'constraints' => array(
833
-						'uri_type'    => 'Person',
834
-						'cardinality' => INF,
835
-					),
836
-				),
837
-				self::FIELD_BIRTH_DATE  => array(
838
-					'predicate'   => 'http://schema.org/birthDate',
839
-					'type'        => self::DATA_TYPE_DATE,
840
-					'export_type' => 'xsd:date',
841
-					'constraints' => '',
842
-				),
843
-				self::FIELD_BIRTH_PLACE => array(
844
-					'predicate'   => 'http://schema.org/birthPlace',
845
-					'type'        => self::DATA_TYPE_URI,
846
-					'export_type' => 'http://schema.org/Place',
847
-					'constraints' => array(
848
-						'uri_type' => 'Place',
849
-					),
850
-				),
851
-				self::FIELD_AFFILIATION => array(
852
-					'predicate'   => 'http://schema.org/affiliation',
853
-					'type'        => self::DATA_TYPE_URI,
854
-					'export_type' => 'http://schema.org/Organization',
855
-					'constraints' => array(
856
-						'uri_type'    => array(
857
-							'Organization',
858
-							'LocalBusiness',
859
-						),
860
-						'cardinality' => INF,
861
-					),
862
-				),
863
-				self::FIELD_EMAIL       => array(
864
-					'predicate'   => 'http://schema.org/email',
865
-					'type'        => self::DATA_TYPE_STRING,
866
-					'export_type' => 'xsd:string',
867
-					'constraints' => array(
868
-						'cardinality' => INF,
869
-					),
870
-				),
871
-			),
872
-			'templates'     => array(
873
-				'subtitle' => '{{id}}',
874
-			),
875
-		);
876
-
877
-		// Merge the custom fields with those provided by the thing schema.
878
-		$parent_schema           = $this->get_thing_schema();
879
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
880
-
881
-		return $schema;
882
-
883
-	}
884
-
885
-	/**
886
-	 * Get the 'place' schema.
887
-	 *
888
-	 * @return array An array with the schema configuration.
889
-	 *
890
-	 * @since 3.1.0
891
-	 */
892
-	private function get_place_schema() {
893
-
894
-		$schema = array(
895
-			'label'         => 'Place',
896
-			'description'   => 'A place.',
897
-			'parents'       => array( 'thing' ),
898
-			'css_class'     => 'wl-place',
899
-			'uri'           => 'http://schema.org/Place',
900
-			'same_as'       => array(
901
-				'http://rdf.freebase.com/ns/location.location',
902
-				'http://www.opengis.net/gml/_Feature',
903
-			),
904
-			'custom_fields' => array(
905
-				self::FIELD_GEO_LATITUDE        => array(
906
-					'predicate'   => 'http://schema.org/latitude',
907
-					'type'        => self::DATA_TYPE_DOUBLE,
908
-					'export_type' => 'xsd:double',
909
-					'constraints' => '',
910
-					// To build custom metabox.
911
-					'input_field' => 'coordinates',
912
-				),
913
-				self::FIELD_GEO_LONGITUDE       => array(
914
-					'predicate'   => 'http://schema.org/longitude',
915
-					'type'        => self::DATA_TYPE_DOUBLE,
916
-					'export_type' => 'xsd:double',
917
-					'constraints' => '',
918
-					// To build custom metabox.
919
-					'input_field' => 'coordinates',
920
-				),
921
-				self::FIELD_ADDRESS             => array(
922
-					'predicate'   => 'http://schema.org/streetAddress',
923
-					'type'        => self::DATA_TYPE_STRING,
924
-					'export_type' => 'xsd:string',
925
-					'constraints' => '',
926
-					// To build custom metabox.
927
-					'input_field' => 'address',
928
-				),
929
-				self::FIELD_ADDRESS_PO_BOX      => array(
930
-					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
931
-					'type'        => self::DATA_TYPE_STRING,
932
-					'export_type' => 'xsd:string',
933
-					'constraints' => '',
934
-					// To build custom metabox.
935
-					'input_field' => 'address',
936
-				),
937
-				self::FIELD_ADDRESS_POSTAL_CODE => array(
938
-					'predicate'   => 'http://schema.org/postalCode',
939
-					'type'        => self::DATA_TYPE_STRING,
940
-					'export_type' => 'xsd:string',
941
-					'constraints' => '',
942
-					// To build custom metabox.
943
-					'input_field' => 'address',
944
-				),
945
-				self::FIELD_ADDRESS_LOCALITY    => array(
946
-					'predicate'   => 'http://schema.org/addressLocality',
947
-					'type'        => self::DATA_TYPE_STRING,
948
-					'export_type' => 'xsd:string',
949
-					'constraints' => '',
950
-					// To build custom metabox.
951
-					'input_field' => 'address',
952
-				),
953
-				self::FIELD_ADDRESS_REGION      => array(
954
-					'predicate'   => 'http://schema.org/addressRegion',
955
-					'type'        => self::DATA_TYPE_STRING,
956
-					'export_type' => 'xsd:string',
957
-					'constraints' => '',
958
-					// To build custom metabox.
959
-					'input_field' => 'address',
960
-				),
961
-				self::FIELD_ADDRESS_COUNTRY     => array(
962
-					'predicate'   => 'http://schema.org/addressCountry',
963
-					'type'        => self::DATA_TYPE_STRING,
964
-					'export_type' => 'xsd:string',
965
-					'constraints' => '',
966
-					// To build custom metabox.
967
-					'input_field' => 'address',
968
-				),
969
-			),
970
-			'templates'     => array(
971
-				'subtitle' => '{{id}}',
972
-			),
973
-		);
974
-
975
-		// Merge the custom fields with those provided by the thing schema.
976
-		$parent_schema           = $this->get_thing_schema();
977
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
978
-
979
-		return $schema;
980
-	}
981
-
982
-	/**
983
-	 * Get the 'local business' schema.
984
-	 *
985
-	 * @return array An array with the schema configuration.
986
-	 *
987
-	 * @since 3.1.0
988
-	 */
989
-	private function get_local_business_schema() {
990
-
991
-		$schema = array(
992
-			'label'         => 'LocalBusiness',
993
-			'description'   => 'A local business.',
994
-			'parents'       => array( 'place', 'organization' ),
995
-			'css_class'     => 'wl-local-business',
996
-			'uri'           => 'http://schema.org/LocalBusiness',
997
-			'same_as'       => array(
998
-				'http://rdf.freebase.com/ns/business/business_location',
999
-				'https://schema.org/Store',
1000
-			),
1001
-			'custom_fields' => array(),
1002
-			'templates'     => array(
1003
-				'subtitle' => '{{id}}',
1004
-			),
1005
-		);
1006
-
1007
-		// Merge the custom fields with those provided by the place and organization schema.
1008
-		$place_schema            = $this->get_place_schema();
1009
-		$organization_schema     = $this->get_organization_schema();
1010
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
1011
-
1012
-		return $schema;
1013
-	}
1014
-
1015
-	/**
1016
-	 * Get the 'recipe' schema.
1017
-	 *
1018
-	 * @return array An array with the schema configuration.
1019
-	 *
1020
-	 * @since 3.14.0
1021
-	 */
1022
-	private function get_recipe_schema() {
1023
-
1024
-		$schema = array(
1025
-			'label'         => 'Recipe',
1026
-			'description'   => 'A Recipe.',
1027
-			'parents'       => array( 'CreativeWork' ),
1028
-			'css_class'     => 'wl-recipe',
1029
-			'uri'           => 'http://schema.org/Recipe',
1030
-			'same_as'       => array(),
1031
-			'templates'     => array(
1032
-				'subtitle' => '{{id}}',
1033
-			),
1034
-			'custom_fields' => array(
1035
-				self::FIELD_RECIPE_CUISINE          => array(
1036
-					'predicate'   => 'http://schema.org/recipeCuisine',
1037
-					'type'        => self::DATA_TYPE_STRING,
1038
-					'export_type' => 'xsd:string',
1039
-					'constraints' => '',
1040
-					'metabox'     => array(
1041
-						'label' => __( 'Recipe cuisine', 'wordlift' ),
1042
-					),
1043
-				),
1044
-				self::FIELD_RECIPE_INGREDIENT       => array(
1045
-					'predicate'   => 'http://schema.org/recipeIngredient',
1046
-					'type'        => self::DATA_TYPE_STRING,
1047
-					'export_type' => 'xsd:string',
1048
-					'constraints' => array(
1049
-						'cardinality' => INF,
1050
-					),
1051
-					'metabox'     => array(
1052
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
1053
-					),
1054
-				),
1055
-				self::FIELD_RECIPE_INSTRUCTIONS     => array(
1056
-					'predicate'   => 'http://schema.org/recipeInstructions',
1057
-					'type'        => self::DATA_TYPE_MULTILINE,
1058
-					'export_type' => 'xsd:string',
1059
-					'constraints' => '',
1060
-					'metabox'     => array(
1061
-						'class' => 'Wordlift_Metabox_Field_Multiline',
1062
-						'label' => __( 'Recipe instructions', 'wordlift' ),
1063
-					),
1064
-				),
1065
-				self::FIELD_RECIPE_YIELD            => array(
1066
-					'predicate'   => 'http://schema.org/recipeYield',
1067
-					'type'        => self::DATA_TYPE_STRING,
1068
-					'export_type' => 'xsd:string',
1069
-					'constraints' => '',
1070
-					'metabox'     => array(
1071
-						'label' => __( 'Recipe number of servings', 'wordlift' ),
1072
-					),
1073
-				),
1074
-				self::FIELD_RECIPE_INGREDIENT       => array(
1075
-					'predicate'   => 'http://schema.org/recipeIngredient',
1076
-					'type'        => self::DATA_TYPE_STRING,
1077
-					'export_type' => 'xsd:string',
1078
-					'constraints' => array(
1079
-						'cardinality' => INF,
1080
-					),
1081
-					'metabox'     => array(
1082
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
1083
-					),
1084
-				),
1085
-				self::FIELD_NUTRITION_INFO_CALORIES => array(
1086
-					'predicate'   => 'http://schema.org/calories',
1087
-					'type'        => self::DATA_TYPE_STRING,
1088
-					'export_type' => 'xsd:string',
1089
-					'constraints' => '',
1090
-					'metabox'     => array(
1091
-						'label' => __( 'Calories (e.g. 240 calories)', 'wordlift' ),
1092
-					),
1093
-				),
1094
-				self::FIELD_PREP_TIME               => array(
1095
-					'predicate'   => 'http://schema.org/prepTime',
1096
-					'type'        => self::DATA_TYPE_DURATION,
1097
-					'export_type' => 'xsd:time',
1098
-					'constraints' => '',
1099
-					'metabox'     => array(
1100
-						'class' => 'Wordlift_Metabox_Field_Duration',
1101
-						'label' => __( 'Recipe preparation time (e.g. 1:30)', 'wordlift' ),
1102
-					),
1103
-				),
1104
-				self::FIELD_COOK_TIME               => array(
1105
-					'predicate'   => 'http://schema.org/cookTime',
1106
-					'type'        => self::DATA_TYPE_DURATION,
1107
-					'export_type' => 'xsd:time',
1108
-					'constraints' => '',
1109
-					'metabox'     => array(
1110
-						'class' => 'Wordlift_Metabox_Field_Duration',
1111
-						'label' => __( 'Recipe cook time (e.g. 1:30)', 'wordlift' ),
1112
-					),
1113
-				),
1114
-				self::FIELD_TOTAL_TIME              => array(
1115
-					'predicate'   => 'http://schema.org/totalTime',
1116
-					'type'        => self::DATA_TYPE_DURATION,
1117
-					'export_type' => 'xsd:time',
1118
-					'constraints' => '',
1119
-					'metabox'     => array(
1120
-						'class' => 'Wordlift_Metabox_Field_Duration',
1121
-						'label' => __( 'Recipe total time (e.g. 1:30)', 'wordlift' ),
1122
-					),
1123
-				),
1124
-			),
1125
-		);
1126
-
1127
-		// Merge the custom fields with those provided by the parent schema.
1128
-		$parent_schema           = $this->get_creative_work_schema();
1129
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1130
-
1131
-		return $schema;
1132
-	}
1133
-
1134
-	/**
1135
-	 * Get the 'offer' schema.
1136
-	 *
1137
-	 * @return array An array with the schema configuration.
1138
-	 *
1139
-	 * @since 3.18.0
1140
-	 */
1141
-	private function get_offer_schema() {
1142
-
1143
-		$schema = array(
1144
-			'label'         => 'Offer',
1145
-			'description'   => 'An offer. ',
1146
-			'parents'       => array( 'thing' ),
1147
-			'css_class'     => 'wl-offer',
1148
-			'uri'           => self::SCHEMA_OFFER_TYPE,
1149
-			'same_as'       => array(),
1150
-			'templates'     => array(
1151
-				'subtitle' => '{{id}}',
1152
-			),
1153
-			'custom_fields' => array(
1154
-				self::FIELD_AVAILABILITY        => array(
1155
-					'predicate'   => 'http://schema.org/availability',
1156
-					'type'        => self::DATA_TYPE_STRING,
1157
-					'export_type' => 'xsd:string',
1158
-					'metabox'     => array(
1159
-						'class' => 'Wordlift_Metabox_Field_Select',
1160
-					),
1161
-					'options'     => array(
1162
-						'Discontinued'        => esc_html__( 'Discontinued', 'wordlift' ),
1163
-						'InStock'             => esc_html__( 'In Stock', 'wordlift' ),
1164
-						'InStoreOnly'         => esc_html__( 'In Store Only', 'wordlift' ),
1165
-						'LimitedAvailability' => esc_html__( 'Limited Availability', 'wordlift' ),
1166
-						'OnlineOnly'          => esc_html__( 'Online Only', 'wordlift' ),
1167
-						'OutOfStock'          => esc_html__( 'Out of Stock', 'wordlift' ),
1168
-						'PreOrder'            => esc_html__( 'Pre Order', 'wordlift' ),
1169
-						'PreSale'             => esc_html__( 'Pre Sale', 'wordlift' ),
1170
-						'SoldOut'             => esc_html__( 'Sold Out', 'wordlift' ),
1171
-					),
1172
-				),
1173
-				self::FIELD_PRICE               => array(
1174
-					'predicate'   => 'http://schema.org/price',
1175
-					'type'        => self::DATA_TYPE_STRING,
1176
-					'export_type' => 'xsd:integer',
1177
-					'metabox'     => array(
1178
-						'class' => 'Wordlift_Metabox_Field_Integer',
1179
-					),
1180
-				),
1181
-				self::FIELD_PRICE_CURRENCY      => array(
1182
-					'predicate'   => 'http://schema.org/priceCurrency',
1183
-					'type'        => self::DATA_TYPE_STRING,
1184
-					'export_type' => 'xsd:string',
1185
-				),
1186
-				self::FIELD_AVAILABILITY_STARTS => array(
1187
-					'predicate'   => 'http://schema.org/availabilityStarts',
1188
-					'type'        => self::DATA_TYPE_DATE,
1189
-					'export_type' => 'xsd:dateTime',
1190
-				),
1191
-				self::FIELD_AVAILABILITY_ENDS   => array(
1192
-					'predicate'   => 'http://schema.org/availabilityEnds',
1193
-					'type'        => self::DATA_TYPE_DATE,
1194
-					'export_type' => 'xsd:dateTime',
1195
-				),
1196
-				self::FIELD_INVENTORY_LEVEL     => array(
1197
-					'predicate'   => 'http://schema.org/inventoryLevel',
1198
-					'type'        => self::DATA_TYPE_STRING,
1199
-					'export_type' => 'xsd:integer',
1200
-					'metabox'     => array(
1201
-						'class' => 'Wordlift_Metabox_Field_Integer',
1202
-					),
1203
-				),
1204
-				self::FIELD_VALID_FROM          => array(
1205
-					'predicate'   => 'http://schema.org/validFrom',
1206
-					'type'        => self::DATA_TYPE_DATE,
1207
-					'export_type' => 'xsd:dateTime',
1208
-				),
1209
-				self::FIELD_PRICE_VALID_UNTIL   => array(
1210
-					'predicate'   => 'http://schema.org/priceValidUntil',
1211
-					'type'        => self::DATA_TYPE_DATE,
1212
-					'export_type' => 'xsd:dateTime',
1213
-				),
1214
-				self::FIELD_ITEM_OFFERED        => array(
1215
-					'predicate'   => 'http://schema.org/itemOffered',
1216
-					'type'        => self::DATA_TYPE_URI,
1217
-					'export_type' => 'http://schema.org/Thing',
1218
-					'constraints' => array(
1219
-						'uri_type'    => array(
1220
-							'Event',
1221
-							'Thing',
1222
-						),
1223
-						'cardinality' => INF,
1224
-					),
1225
-				),
1226
-			),
1227
-		);
1228
-
1229
-		// Merge the custom fields with those provided by the thing schema.
1230
-		$parent_schema           = $this->get_thing_schema();
1231
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1232
-
1233
-		return $schema;
1234
-	}
1235
-
1236
-	/**
1237
-	 * Get the 'article' schema.
1238
-	 *
1239
-	 * @return array An array with the schema configuration.
1240
-	 *
1241
-	 * @since 3.15.0
1242
-	 */
1243
-	private function get_article_schema() {
1244
-
1245
-		$schema = array(
1246
-			'label'         => 'Article',
1247
-			'description'   => 'An Article.',
1248
-			'parents'       => array(),
1249
-			'css_class'     => 'wl-article',
1250
-			'uri'           => 'http://schema.org/Article',
1251
-			'same_as'       => array(),
1252
-			'templates'     => array(
1253
-				'subtitle' => '{{id}}',
1254
-			),
1255
-			'custom_fields' => array(),
1256
-		);
1257
-
1258
-		return $schema;
1259
-	}
21
+    /**
22
+     * The 'location created' field name.
23
+     *
24
+     * @since 3.5.0
25
+     */
26
+    const FIELD_LOCATION_CREATED = 'wl_location_created';
27
+
28
+    /**
29
+     * The 'topic' field name.
30
+     *
31
+     * @since 3.5.0
32
+     */
33
+    const FIELD_TOPIC = 'wl_topic';
34
+
35
+    /**
36
+     * The 'author' field name.
37
+     *
38
+     * @since 3.1.0
39
+     */
40
+    const FIELD_AUTHOR = 'wl_author';
41
+
42
+    /**
43
+     * The 'same as' field name.
44
+     *
45
+     * @since 3.1.0
46
+     */
47
+    const FIELD_SAME_AS = 'entity_same_as';
48
+
49
+    /**
50
+     * The 'date start' field name.
51
+     *
52
+     * @since 3.1.0
53
+     */
54
+    const FIELD_DATE_START = 'wl_cal_date_start';
55
+
56
+    /**
57
+     * The 'date end' field name.
58
+     *
59
+     * @since 3.1.0
60
+     */
61
+    const FIELD_DATE_END = 'wl_cal_date_end';
62
+
63
+    /**
64
+     * The 'location' field name.
65
+     *
66
+     * @since 3.1.0
67
+     */
68
+    const FIELD_LOCATION = 'wl_location';
69
+
70
+    /**
71
+     * The 'founder' field name.
72
+     *
73
+     * @since 3.1.0
74
+     */
75
+    const FIELD_FOUNDER = 'wl_founder';
76
+
77
+    /**
78
+     * The 'knows' field name.
79
+     *
80
+     * @since 3.1.0
81
+     */
82
+    const FIELD_KNOWS = 'wl_knows';
83
+
84
+    /**
85
+     * The 'birth date' field name.
86
+     *
87
+     * @since 3.1.0
88
+     */
89
+    const FIELD_BIRTH_DATE = 'wl_birth_date';
90
+
91
+    /**
92
+     * The 'birth place' field name.
93
+     *
94
+     * @since 3.1.0
95
+     */
96
+    const FIELD_BIRTH_PLACE = 'wl_birth_place';
97
+
98
+    /**
99
+     * The 'latitude' field name.
100
+     *
101
+     * @since 3.1.0
102
+     */
103
+    const FIELD_GEO_LATITUDE = 'wl_geo_latitude';
104
+
105
+    /**
106
+     * The 'longitude' field name.
107
+     *
108
+     * @since 3.1.0
109
+     */
110
+    const FIELD_GEO_LONGITUDE = 'wl_geo_longitude';
111
+
112
+    /**
113
+     * The 'streetAddress' field name.
114
+     *
115
+     * @since 3.1.0
116
+     */
117
+    const FIELD_ADDRESS = 'wl_address';
118
+
119
+    /**
120
+     * The 'postOfficeBoxNumber' field name.
121
+     *
122
+     * @since 3.3.0
123
+     */
124
+    const FIELD_ADDRESS_PO_BOX = 'wl_address_post_office_box';
125
+
126
+    /**
127
+     * The 'postalCode' field name.
128
+     *
129
+     * @since 3.3.0
130
+     */
131
+    const FIELD_ADDRESS_POSTAL_CODE = 'wl_address_postal_code';
132
+
133
+    /**
134
+     * The 'addressLocality' field name.
135
+     *
136
+     * @since 3.3.0
137
+     */
138
+    const FIELD_ADDRESS_LOCALITY = 'wl_address_locality';
139
+    /**
140
+     * The 'addressRegion' field name.
141
+     *
142
+     * @since 3.3.0
143
+     */
144
+    const FIELD_ADDRESS_REGION = 'wl_address_region';
145
+
146
+    /**
147
+     * The 'addressCountry' field name.
148
+     *
149
+     * @since 3.3.0
150
+     */
151
+    const FIELD_ADDRESS_COUNTRY = 'wl_address_country';
152
+
153
+    /**
154
+     * The 'entity type' field name.
155
+     *
156
+     * @since 3.1.0
157
+     */
158
+    const FIELD_ENTITY_TYPE = 'wl_entity_type_uri';
159
+
160
+    /**
161
+     * The 'email' field name.
162
+     *
163
+     * @since 3.2.0
164
+     */
165
+    const FIELD_EMAIL = 'wl_email';
166
+
167
+    /**
168
+     * The 'affiliation' field name.
169
+     *
170
+     * @since 3.2.0
171
+     */
172
+    const FIELD_AFFILIATION = 'wl_affiliation';
173
+
174
+    /**
175
+     * The 'telephone' field name.
176
+     *
177
+     * @since 3.8.0
178
+     */
179
+    const FIELD_TELEPHONE = 'wl_schema_telephone';
180
+
181
+    /**
182
+     * The 'legalName' field name.
183
+     *
184
+     * @since 3.12.0
185
+     */
186
+    const FIELD_LEGAL_NAME = 'wl_schema_legal_name';
187
+
188
+    /**
189
+     * The 'recipeCuisine' field name.
190
+     *
191
+     * @since 3.14.0
192
+     */
193
+    const FIELD_RECIPE_CUISINE = 'wl_schema_recipe_cuisine';
194
+
195
+    /**
196
+     * The 'recipeIngredient' field name.
197
+     *
198
+     * @since 3.14.0
199
+     */
200
+    const FIELD_RECIPE_INGREDIENT = 'wl_schema_recipe_ingredient';
201
+
202
+    /**
203
+     * The 'calories' field name.
204
+     *
205
+     * @since 3.14.0
206
+     */
207
+    const FIELD_NUTRITION_INFO_CALORIES = 'wl_schema_nutrition_information_calories';
208
+
209
+    /**
210
+     * The 'recipeInstructions' field name.
211
+     *
212
+     * @since 3.14.0
213
+     */
214
+    const FIELD_RECIPE_INSTRUCTIONS = 'wl_schema_recipe_instructions';
215
+
216
+    /**
217
+     * The 'recipeYield' field name.
218
+     *
219
+     * @since 3.14.0
220
+     */
221
+    const FIELD_RECIPE_YIELD = 'wl_schema_recipe_yield';
222
+
223
+    /**
224
+     * The 'prepTime' field name.
225
+     *
226
+     * @since 3.14.0
227
+     */
228
+    const FIELD_PREP_TIME = 'wl_schema_prep_time';
229
+
230
+    /**
231
+     * The 'cookTime' field name.
232
+     *
233
+     * @since 3.14.0
234
+     */
235
+    const FIELD_COOK_TIME = 'wl_schema_cook_time';
236
+
237
+    /**
238
+     * The 'totalTime' field name.
239
+     *
240
+     * @since 3.14.0
241
+     */
242
+    const FIELD_TOTAL_TIME = 'wl_schema_total_time';
243
+
244
+    /**
245
+     * The 'performer' field name.
246
+     *
247
+     * @since 3.18.0
248
+     */
249
+    const FIELD_PERFORMER = 'wl_schema_performer';
250
+
251
+    /**
252
+     * The 'offers' field name.
253
+     *
254
+     * @since 3.18.0
255
+     */
256
+    const FIELD_OFFERS = 'wl_schema_offers';
257
+
258
+    /**
259
+     * The 'availablity' field name.
260
+     *
261
+     * @since 3.18.0
262
+     */
263
+    const FIELD_AVAILABILITY = 'wl_schema_availability';
264
+
265
+    /**
266
+     * The 'inventoryLevel' field name.
267
+     *
268
+     * @since 3.18.0
269
+     */
270
+    const FIELD_INVENTORY_LEVEL = 'wl_schema_inventory_level';
271
+
272
+    /**
273
+     * The 'price' field name.
274
+     *
275
+     * @since 3.18.0
276
+     */
277
+    const FIELD_PRICE = 'wl_schema_price';
278
+
279
+    /**
280
+     * The 'priceCurrency' field name.
281
+     *
282
+     * @since 3.18.0
283
+     */
284
+    const FIELD_PRICE_CURRENCY = 'wl_schema_price_currency';
285
+
286
+    /**
287
+     * The 'availabilityStarts' field name.
288
+     *
289
+     * @since 3.18.0
290
+     */
291
+    const FIELD_AVAILABILITY_STARTS = 'wl_schema_availability_starts';
292
+
293
+    /**
294
+     * The 'availabilityEnds' field name.
295
+     *
296
+     * @since 3.18.0
297
+     */
298
+    const FIELD_AVAILABILITY_ENDS = 'wl_schema_availability_ends';
299
+
300
+    /**
301
+     * The 'validFrom' field name.
302
+     *
303
+     * @since 3.18.0
304
+     */
305
+    const FIELD_VALID_FROM = 'wl_schema_valid_from';
306
+
307
+    /**
308
+     * The 'priceValidUntil' field name.
309
+     *
310
+     * @since 3.18.0
311
+     */
312
+    const FIELD_PRICE_VALID_UNTIL = 'wl_schema_valid_until';
313
+
314
+    /**
315
+     * The 'itemOffered' field name.
316
+     *
317
+     * @since 3.18.0
318
+     */
319
+    const FIELD_ITEM_OFFERED = 'wl_schema_item_offered';
320
+
321
+    /**
322
+     * The 'URI' data type name.
323
+     *
324
+     * @since 3.1.0
325
+     */
326
+    const DATA_TYPE_URI = 'uri';
327
+
328
+    /**
329
+     * The 'date' data type name.
330
+     *
331
+     * @since 3.1.0
332
+     */
333
+    const DATA_TYPE_DATE = 'date';
334
+
335
+    /**
336
+     * The 'time' data type name.
337
+     *
338
+     * @since 3.14.0
339
+     */
340
+    const DATA_TYPE_DURATION = 'duration';
341
+
342
+    /**
343
+     * The 'double' data type name.
344
+     *
345
+     * @since 3.1.0
346
+     */
347
+    const DATA_TYPE_DOUBLE = 'double';
348
+
349
+    /**
350
+     * The 'string' data type name.
351
+     *
352
+     * @since 3.1.0
353
+     */
354
+    const DATA_TYPE_STRING = 'string';
355
+
356
+    /**
357
+     * The multiline text data type name.
358
+     *
359
+     * @since 3.14.0
360
+     */
361
+    const DATA_TYPE_MULTILINE = 'multiline';
362
+
363
+    /**
364
+     * The schema.org Event type URI.
365
+     *
366
+     * @since 3.1.0
367
+     */
368
+    const SCHEMA_EVENT_TYPE = 'http://schema.org/Event';
369
+
370
+    /**
371
+     * The schema.org Offer type URI.
372
+     *
373
+     * @since 3.18.0
374
+     */
375
+    const SCHEMA_OFFER_TYPE = 'http://schema.org/Offer';
376
+
377
+    /**
378
+     * WordLift's schema.
379
+     *
380
+     * @since  3.1.0
381
+     * @access private
382
+     * @var array $schema WordLift's schema.
383
+     */
384
+    private $schema;
385
+
386
+    /**
387
+     * The Log service.
388
+     *
389
+     * @since  3.1.0
390
+     * @access private
391
+     * @var \Wordlift_Log_Service $log The Log service.
392
+     */
393
+    private $log;
394
+
395
+    /**
396
+     * Wordlift_Schema_Service constructor.
397
+     *
398
+     * @since 3.1.0
399
+     */
400
+    protected function __construct() {
401
+
402
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
403
+
404
+        /**
405
+         * Alter the configured schemas.
406
+         *
407
+         * Enable 3rd parties to alter WordLift's schemas array.
408
+         *
409
+         * @param array $schemas The array of schemas.
410
+         *
411
+         * @since  3.19.1
412
+         */
413
+        $this->schema = apply_filters(
414
+            'wl_schemas',
415
+            array(
416
+                'article'        => $this->get_article_schema(),
417
+                'thing'          => $this->get_thing_schema(),
418
+                'creative-work'  => $this->get_creative_work_schema(),
419
+                'event'          => $this->get_event_schema(),
420
+                'organization'   => $this->get_organization_schema(),
421
+                'person'         => $this->get_person_schema(),
422
+                'place'          => $this->get_place_schema(),
423
+                'local-business' => $this->get_local_business_schema(),
424
+                'recipe'         => $this->get_recipe_schema(),
425
+                'web-page'       => $this->get_web_page_schema(),
426
+                'offer'          => $this->get_offer_schema(),
427
+            )
428
+        );
429
+
430
+        // Create a singleton instance of the Schema service, useful to provide static functions to global functions.
431
+        self::$instance = $this;
432
+
433
+    }
434
+
435
+    public function get_all_schema_slugs() {
436
+        return array_keys( $this->schema );
437
+    }
438
+
439
+    /**
440
+     * The Schema service singleton instance.
441
+     *
442
+     * @since  3.1.0
443
+     * @access private
444
+     * @var Wordlift_Schema_Service $instance The Schema service singleton instance.
445
+     */
446
+    private static $instance = null;
447
+
448
+    /**
449
+     * Get a reference to the Schema service.
450
+     *
451
+     * @return Wordlift_Schema_Service A reference to the Schema service.
452
+     * @since 3.1.0
453
+     */
454
+    public static function get_instance() {
455
+        if ( ! isset( self::$instance ) ) {
456
+            self::$instance = new self();
457
+        }
458
+
459
+        return self::$instance;
460
+    }
461
+
462
+    /**
463
+     * Get the properties for a field with the specified key. The key is used as
464
+     * meta key when the field's value is stored in WordPress meta data table.
465
+     *
466
+     * @param string $key The field's key.
467
+     *
468
+     * @return null|array An array of field's properties or null if the field is not found.
469
+     * @since 3.6.0
470
+     */
471
+    public function get_field( $key ) {
472
+
473
+        // Parse each schema's fields until we find the one we're looking for, then
474
+        // return its properties.
475
+        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
476
+        foreach ( $this->schema as $_ => $schema ) {
477
+
478
+            if ( ! isset( $schema['custom_fields'] ) ) {
479
+                break;
480
+            }
481
+
482
+            foreach ( $schema['custom_fields'] as $field => $props ) {
483
+                if ( $key === $field ) {
484
+                    return $props;
485
+                }
486
+            }
487
+        }
488
+
489
+        return null;
490
+    }
491
+
492
+    /**
493
+     * Get the WordLift's schema.
494
+     *
495
+     * @param string $name The schema name.
496
+     *
497
+     * @return array|null An array with the schema configuration or NULL if the schema is not found.
498
+     *
499
+     * @since 3.1.0
500
+     */
501
+    public function get_schema( $name ) {
502
+        // Check if the schema exists and, if not, return NULL.
503
+        if ( ! isset( $this->schema[ $name ] ) ) {
504
+            return null;
505
+        }
506
+
507
+        // Return the requested schema.
508
+        return $this->schema[ $name ];
509
+    }
510
+
511
+    /**
512
+     * Get the WordLift's schema trough schema type uri.
513
+     *
514
+     * @param string $uri The schema uri.
515
+     *
516
+     * @return array|null An array with the schema configuration or NULL if the schema is not found.
517
+     *
518
+     * @since 3.3.0
519
+     */
520
+    public function get_schema_by_uri( $uri ) {
521
+
522
+        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
523
+        foreach ( $this->schema as $name => $schema ) {
524
+            if ( $schema['uri'] === $uri ) {
525
+                return $schema;
526
+            }
527
+        }
528
+
529
+        return null;
530
+    }
531
+
532
+    /**
533
+     * Get the 'thing' schema.
534
+     *
535
+     * @return array An array with the schema configuration.
536
+     *
537
+     * @since 3.1.0
538
+     */
539
+    private function get_thing_schema() {
540
+
541
+        return array(
542
+            'css_class'     => 'wl-thing',
543
+            'uri'           => 'http://schema.org/Thing',
544
+            'same_as'       => array( '*' ),
545
+            // set as default.
546
+            'custom_fields' => array(
547
+                self::FIELD_SAME_AS => array(
548
+                    'predicate'   => 'http://schema.org/sameAs',
549
+                    'type'        => self::DATA_TYPE_URI,
550
+                    'export_type' => 'http://schema.org/Thing',
551
+                    'constraints' => array(
552
+                        'cardinality' => INF,
553
+                    ),
554
+                    // We need a custom metabox.
555
+                    'input_field' => 'sameas',
556
+                ),
557
+                // Add the schema:url property.
558
+                Wordlift_Schema_Url_Property_Service::META_KEY => Wordlift_Schema_Url_Property_Service::get_instance()
559
+                                                                                                        ->get_compat_definition(),
560
+            ),
561
+            // {{sameAs}} not present in the microdata template,
562
+            // because it is treated separately in *wl_content_embed_item_microdata*
563
+            'templates'     => array(
564
+                'subtitle' => '{{id}}',
565
+            ),
566
+        );
567
+
568
+    }
569
+
570
+    /**
571
+     * Get the 'web-page' schema.
572
+     *
573
+     * @return array An array with the schema configuration.
574
+     *
575
+     * @since 3.18.0
576
+     */
577
+    private function get_web_page_schema() {
578
+
579
+        return array(
580
+            'css_class' => 'wl-webpage',
581
+            'uri'       => 'http://schema.org/WebPage',
582
+        );
583
+
584
+    }
585
+
586
+    /**
587
+     * Get the 'creative work' schema.
588
+     *
589
+     * @return array An array with the schema configuration.
590
+     *
591
+     * @since 3.1.0
592
+     */
593
+    private function get_creative_work_schema() {
594
+
595
+        $schema = array(
596
+            'label'         => 'CreativeWork',
597
+            'description'   => 'A creative work (or a Music Album).',
598
+            'parents'       => array( 'thing' ),
599
+            // Give term slug as parent.
600
+            'css_class'     => 'wl-creative-work',
601
+            'uri'           => 'http://schema.org/CreativeWork',
602
+            'same_as'       => array(
603
+                'http://schema.org/MusicAlbum',
604
+                'http://schema.org/Product',
605
+            ),
606
+            'custom_fields' => array(
607
+                self::FIELD_AUTHOR => array(
608
+                    'predicate'   => 'http://schema.org/author',
609
+                    'type'        => self::DATA_TYPE_URI,
610
+                    'export_type' => 'http://schema.org/Person',
611
+                    'constraints' => array(
612
+                        'uri_type'    => array( 'Person', 'Organization' ),
613
+                        'cardinality' => INF,
614
+                    ),
615
+                ),
616
+            ),
617
+            'templates'     => array(
618
+                'subtitle' => '{{id}}',
619
+            ),
620
+        );
621
+
622
+        // Merge the custom fields with those provided by the thing schema.
623
+        $parent_schema           = $this->get_thing_schema();
624
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
625
+
626
+        return $schema;
627
+    }
628
+
629
+    /**
630
+     * Get the 'event' schema.
631
+     *
632
+     * @return array An array with the schema configuration.
633
+     *
634
+     * @since 3.1.0
635
+     */
636
+    private function get_event_schema() {
637
+
638
+        $schema = array(
639
+            'label'         => 'Event',
640
+            'description'   => 'An event . ',
641
+            'parents'       => array( 'thing' ),
642
+            'css_class'     => 'wl-event',
643
+            'uri'           => self::SCHEMA_EVENT_TYPE,
644
+            'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
645
+            'custom_fields' => array(
646
+                self::FIELD_DATE_START => array(
647
+                    'predicate'   => 'http://schema.org/startDate',
648
+                    'type'        => self::DATA_TYPE_DATE,
649
+                    'export_type' => 'xsd:dateTime',
650
+                    'constraints' => '',
651
+                ),
652
+                self::FIELD_DATE_END   => array(
653
+                    'predicate'   => 'http://schema.org/endDate',
654
+                    'type'        => self::DATA_TYPE_DATE,
655
+                    'export_type' => 'xsd:dateTime',
656
+                    'constraints' => '',
657
+                ),
658
+                self::FIELD_LOCATION   => array(
659
+                    'predicate'   => 'http://schema.org/location',
660
+                    'type'        => self::DATA_TYPE_URI,
661
+                    'export_type' => 'http://schema.org/PostalAddress',
662
+                    'constraints' => array(
663
+                        'uri_type'    => array( 'Place', 'LocalBusiness' ),
664
+                        'cardinality' => INF,
665
+                    ),
666
+                ),
667
+                self::FIELD_PERFORMER  => array(
668
+                    'predicate'   => 'http://schema.org/performer',
669
+                    'type'        => self::DATA_TYPE_URI,
670
+                    'export_type' => 'http://schema.org/Person',
671
+                    'constraints' => array(
672
+                        'uri_type'    => array( 'Person', 'Organization' ),
673
+                        'cardinality' => INF,
674
+                    ),
675
+                ),
676
+                self::FIELD_OFFERS     => array(
677
+                    'predicate'   => 'http://schema.org/offers',
678
+                    'type'        => self::DATA_TYPE_URI,
679
+                    'export_type' => 'http://schema.org/Offer',
680
+                    'constraints' => array(
681
+                        'uri_type'    => array( 'Offer' ),
682
+                        'cardinality' => INF,
683
+                    ),
684
+                ),
685
+            ),
686
+            'templates'     => array(
687
+                'subtitle' => '{{id}}',
688
+            ),
689
+        );
690
+
691
+        // Merge the custom fields with those provided by the thing schema.
692
+        $parent_schema           = $this->get_thing_schema();
693
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
694
+
695
+        return $schema;
696
+    }
697
+
698
+    /**
699
+     * Get the 'organization' schema.
700
+     *
701
+     * @return array An array with the schema configuration.
702
+     *
703
+     * @since 3.1.0
704
+     */
705
+    private function get_organization_schema() {
706
+
707
+        $schema = array(
708
+            'label'         => 'Organization',
709
+            'description'   => 'An organization, including a government or a newspaper.',
710
+            'parents'       => array( 'thing' ),
711
+            'css_class'     => 'wl-organization',
712
+            'uri'           => 'http://schema.org/Organization',
713
+            'same_as'       => array(
714
+                'http://rdf.freebase.com/ns/organization.organization',
715
+                'http://rdf.freebase.com/ns/government.government',
716
+                'http://schema.org/Newspaper',
717
+            ),
718
+            'custom_fields' => array(
719
+                self::FIELD_LEGAL_NAME          => array(
720
+                    'predicate'   => 'http://schema.org/legalName',
721
+                    'type'        => self::DATA_TYPE_STRING,
722
+                    'export_type' => 'xsd:string',
723
+                    'constraints' => '',
724
+                ),
725
+                self::FIELD_FOUNDER             => array(
726
+                    'predicate'   => 'http://schema.org/founder',
727
+                    'type'        => self::DATA_TYPE_URI,
728
+                    'export_type' => 'http://schema.org/Person',
729
+                    'constraints' => array(
730
+                        'uri_type'    => 'Person',
731
+                        'cardinality' => INF,
732
+                    ),
733
+                ),
734
+                self::FIELD_ADDRESS             => array(
735
+                    'predicate'   => 'http://schema.org/streetAddress',
736
+                    'type'        => self::DATA_TYPE_STRING,
737
+                    'export_type' => 'xsd:string',
738
+                    'constraints' => '',
739
+                    // To build custom metabox.
740
+                    'input_field' => 'address',
741
+                ),
742
+                self::FIELD_ADDRESS_PO_BOX      => array(
743
+                    'predicate'   => 'http://schema.org/postOfficeBoxNumber',
744
+                    'type'        => self::DATA_TYPE_STRING,
745
+                    'export_type' => 'xsd:string',
746
+                    'constraints' => '',
747
+                    // To build custom metabox.
748
+                    'input_field' => 'address',
749
+                ),
750
+                self::FIELD_ADDRESS_POSTAL_CODE => array(
751
+                    'predicate'   => 'http://schema.org/postalCode',
752
+                    'type'        => self::DATA_TYPE_STRING,
753
+                    'export_type' => 'xsd:string',
754
+                    'constraints' => '',
755
+                    // To build custom metabox.
756
+                    'input_field' => 'address',
757
+                ),
758
+                self::FIELD_ADDRESS_LOCALITY    => array(
759
+                    'predicate'   => 'http://schema.org/addressLocality',
760
+                    'type'        => self::DATA_TYPE_STRING,
761
+                    'export_type' => 'xsd:string',
762
+                    'constraints' => '',
763
+                    // To build custom metabox.
764
+                    'input_field' => 'address',
765
+                ),
766
+                self::FIELD_ADDRESS_REGION      => array(
767
+                    'predicate'   => 'http://schema.org/addressRegion',
768
+                    'type'        => self::DATA_TYPE_STRING,
769
+                    'export_type' => 'xsd:string',
770
+                    'constraints' => '',
771
+                    // To build custom metabox.
772
+                    'input_field' => 'address',
773
+                ),
774
+                self::FIELD_ADDRESS_COUNTRY     => array(
775
+                    'predicate'   => 'http://schema.org/addressCountry',
776
+                    'type'        => self::DATA_TYPE_STRING,
777
+                    'export_type' => 'xsd:string',
778
+                    'constraints' => '',
779
+                    // To build custom metabox.
780
+                    'input_field' => 'address',
781
+                ),
782
+                self::FIELD_EMAIL               => array(
783
+                    'predicate'   => 'http://schema.org/email',
784
+                    'type'        => self::DATA_TYPE_STRING,
785
+                    'export_type' => 'xsd:string',
786
+                    'constraints' => '',
787
+                ),
788
+                self::FIELD_TELEPHONE           => array(
789
+                    'predicate'   => 'http://schema.org/telephone',
790
+                    'type'        => self::DATA_TYPE_STRING,
791
+                    'export_type' => 'xsd:string',
792
+                    'constraints' => '',
793
+                ),
794
+            ),
795
+            'templates'     => array(
796
+                'subtitle' => '{{id}}',
797
+            ),
798
+        );
799
+
800
+        // Merge the custom fields with those provided by the thing schema.
801
+        $parent_schema           = $this->get_thing_schema();
802
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
803
+
804
+        return $schema;
805
+    }
806
+
807
+    /**
808
+     * Get the 'person' schema.
809
+     *
810
+     * @return array An array with the schema configuration.
811
+     *
812
+     * @since 3.1.0
813
+     */
814
+    private function get_person_schema() {
815
+
816
+        $schema = array(
817
+            'label'         => 'Person',
818
+            'description'   => 'A person (or a music artist).',
819
+            'parents'       => array( 'thing' ),
820
+            'css_class'     => 'wl-person',
821
+            'uri'           => 'http://schema.org/Person',
822
+            'same_as'       => array(
823
+                'http://rdf.freebase.com/ns/people.person',
824
+                'http://rdf.freebase.com/ns/music.artist',
825
+                'http://dbpedia.org/class/yago/LivingPeople',
826
+            ),
827
+            'custom_fields' => array(
828
+                self::FIELD_KNOWS       => array(
829
+                    'predicate'   => 'http://schema.org/knows',
830
+                    'type'        => self::DATA_TYPE_URI,
831
+                    'export_type' => 'http://schema.org/Person',
832
+                    'constraints' => array(
833
+                        'uri_type'    => 'Person',
834
+                        'cardinality' => INF,
835
+                    ),
836
+                ),
837
+                self::FIELD_BIRTH_DATE  => array(
838
+                    'predicate'   => 'http://schema.org/birthDate',
839
+                    'type'        => self::DATA_TYPE_DATE,
840
+                    'export_type' => 'xsd:date',
841
+                    'constraints' => '',
842
+                ),
843
+                self::FIELD_BIRTH_PLACE => array(
844
+                    'predicate'   => 'http://schema.org/birthPlace',
845
+                    'type'        => self::DATA_TYPE_URI,
846
+                    'export_type' => 'http://schema.org/Place',
847
+                    'constraints' => array(
848
+                        'uri_type' => 'Place',
849
+                    ),
850
+                ),
851
+                self::FIELD_AFFILIATION => array(
852
+                    'predicate'   => 'http://schema.org/affiliation',
853
+                    'type'        => self::DATA_TYPE_URI,
854
+                    'export_type' => 'http://schema.org/Organization',
855
+                    'constraints' => array(
856
+                        'uri_type'    => array(
857
+                            'Organization',
858
+                            'LocalBusiness',
859
+                        ),
860
+                        'cardinality' => INF,
861
+                    ),
862
+                ),
863
+                self::FIELD_EMAIL       => array(
864
+                    'predicate'   => 'http://schema.org/email',
865
+                    'type'        => self::DATA_TYPE_STRING,
866
+                    'export_type' => 'xsd:string',
867
+                    'constraints' => array(
868
+                        'cardinality' => INF,
869
+                    ),
870
+                ),
871
+            ),
872
+            'templates'     => array(
873
+                'subtitle' => '{{id}}',
874
+            ),
875
+        );
876
+
877
+        // Merge the custom fields with those provided by the thing schema.
878
+        $parent_schema           = $this->get_thing_schema();
879
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
880
+
881
+        return $schema;
882
+
883
+    }
884
+
885
+    /**
886
+     * Get the 'place' schema.
887
+     *
888
+     * @return array An array with the schema configuration.
889
+     *
890
+     * @since 3.1.0
891
+     */
892
+    private function get_place_schema() {
893
+
894
+        $schema = array(
895
+            'label'         => 'Place',
896
+            'description'   => 'A place.',
897
+            'parents'       => array( 'thing' ),
898
+            'css_class'     => 'wl-place',
899
+            'uri'           => 'http://schema.org/Place',
900
+            'same_as'       => array(
901
+                'http://rdf.freebase.com/ns/location.location',
902
+                'http://www.opengis.net/gml/_Feature',
903
+            ),
904
+            'custom_fields' => array(
905
+                self::FIELD_GEO_LATITUDE        => array(
906
+                    'predicate'   => 'http://schema.org/latitude',
907
+                    'type'        => self::DATA_TYPE_DOUBLE,
908
+                    'export_type' => 'xsd:double',
909
+                    'constraints' => '',
910
+                    // To build custom metabox.
911
+                    'input_field' => 'coordinates',
912
+                ),
913
+                self::FIELD_GEO_LONGITUDE       => array(
914
+                    'predicate'   => 'http://schema.org/longitude',
915
+                    'type'        => self::DATA_TYPE_DOUBLE,
916
+                    'export_type' => 'xsd:double',
917
+                    'constraints' => '',
918
+                    // To build custom metabox.
919
+                    'input_field' => 'coordinates',
920
+                ),
921
+                self::FIELD_ADDRESS             => array(
922
+                    'predicate'   => 'http://schema.org/streetAddress',
923
+                    'type'        => self::DATA_TYPE_STRING,
924
+                    'export_type' => 'xsd:string',
925
+                    'constraints' => '',
926
+                    // To build custom metabox.
927
+                    'input_field' => 'address',
928
+                ),
929
+                self::FIELD_ADDRESS_PO_BOX      => array(
930
+                    'predicate'   => 'http://schema.org/postOfficeBoxNumber',
931
+                    'type'        => self::DATA_TYPE_STRING,
932
+                    'export_type' => 'xsd:string',
933
+                    'constraints' => '',
934
+                    // To build custom metabox.
935
+                    'input_field' => 'address',
936
+                ),
937
+                self::FIELD_ADDRESS_POSTAL_CODE => array(
938
+                    'predicate'   => 'http://schema.org/postalCode',
939
+                    'type'        => self::DATA_TYPE_STRING,
940
+                    'export_type' => 'xsd:string',
941
+                    'constraints' => '',
942
+                    // To build custom metabox.
943
+                    'input_field' => 'address',
944
+                ),
945
+                self::FIELD_ADDRESS_LOCALITY    => array(
946
+                    'predicate'   => 'http://schema.org/addressLocality',
947
+                    'type'        => self::DATA_TYPE_STRING,
948
+                    'export_type' => 'xsd:string',
949
+                    'constraints' => '',
950
+                    // To build custom metabox.
951
+                    'input_field' => 'address',
952
+                ),
953
+                self::FIELD_ADDRESS_REGION      => array(
954
+                    'predicate'   => 'http://schema.org/addressRegion',
955
+                    'type'        => self::DATA_TYPE_STRING,
956
+                    'export_type' => 'xsd:string',
957
+                    'constraints' => '',
958
+                    // To build custom metabox.
959
+                    'input_field' => 'address',
960
+                ),
961
+                self::FIELD_ADDRESS_COUNTRY     => array(
962
+                    'predicate'   => 'http://schema.org/addressCountry',
963
+                    'type'        => self::DATA_TYPE_STRING,
964
+                    'export_type' => 'xsd:string',
965
+                    'constraints' => '',
966
+                    // To build custom metabox.
967
+                    'input_field' => 'address',
968
+                ),
969
+            ),
970
+            'templates'     => array(
971
+                'subtitle' => '{{id}}',
972
+            ),
973
+        );
974
+
975
+        // Merge the custom fields with those provided by the thing schema.
976
+        $parent_schema           = $this->get_thing_schema();
977
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
978
+
979
+        return $schema;
980
+    }
981
+
982
+    /**
983
+     * Get the 'local business' schema.
984
+     *
985
+     * @return array An array with the schema configuration.
986
+     *
987
+     * @since 3.1.0
988
+     */
989
+    private function get_local_business_schema() {
990
+
991
+        $schema = array(
992
+            'label'         => 'LocalBusiness',
993
+            'description'   => 'A local business.',
994
+            'parents'       => array( 'place', 'organization' ),
995
+            'css_class'     => 'wl-local-business',
996
+            'uri'           => 'http://schema.org/LocalBusiness',
997
+            'same_as'       => array(
998
+                'http://rdf.freebase.com/ns/business/business_location',
999
+                'https://schema.org/Store',
1000
+            ),
1001
+            'custom_fields' => array(),
1002
+            'templates'     => array(
1003
+                'subtitle' => '{{id}}',
1004
+            ),
1005
+        );
1006
+
1007
+        // Merge the custom fields with those provided by the place and organization schema.
1008
+        $place_schema            = $this->get_place_schema();
1009
+        $organization_schema     = $this->get_organization_schema();
1010
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
1011
+
1012
+        return $schema;
1013
+    }
1014
+
1015
+    /**
1016
+     * Get the 'recipe' schema.
1017
+     *
1018
+     * @return array An array with the schema configuration.
1019
+     *
1020
+     * @since 3.14.0
1021
+     */
1022
+    private function get_recipe_schema() {
1023
+
1024
+        $schema = array(
1025
+            'label'         => 'Recipe',
1026
+            'description'   => 'A Recipe.',
1027
+            'parents'       => array( 'CreativeWork' ),
1028
+            'css_class'     => 'wl-recipe',
1029
+            'uri'           => 'http://schema.org/Recipe',
1030
+            'same_as'       => array(),
1031
+            'templates'     => array(
1032
+                'subtitle' => '{{id}}',
1033
+            ),
1034
+            'custom_fields' => array(
1035
+                self::FIELD_RECIPE_CUISINE          => array(
1036
+                    'predicate'   => 'http://schema.org/recipeCuisine',
1037
+                    'type'        => self::DATA_TYPE_STRING,
1038
+                    'export_type' => 'xsd:string',
1039
+                    'constraints' => '',
1040
+                    'metabox'     => array(
1041
+                        'label' => __( 'Recipe cuisine', 'wordlift' ),
1042
+                    ),
1043
+                ),
1044
+                self::FIELD_RECIPE_INGREDIENT       => array(
1045
+                    'predicate'   => 'http://schema.org/recipeIngredient',
1046
+                    'type'        => self::DATA_TYPE_STRING,
1047
+                    'export_type' => 'xsd:string',
1048
+                    'constraints' => array(
1049
+                        'cardinality' => INF,
1050
+                    ),
1051
+                    'metabox'     => array(
1052
+                        'label' => __( 'Recipe ingredient', 'wordlift' ),
1053
+                    ),
1054
+                ),
1055
+                self::FIELD_RECIPE_INSTRUCTIONS     => array(
1056
+                    'predicate'   => 'http://schema.org/recipeInstructions',
1057
+                    'type'        => self::DATA_TYPE_MULTILINE,
1058
+                    'export_type' => 'xsd:string',
1059
+                    'constraints' => '',
1060
+                    'metabox'     => array(
1061
+                        'class' => 'Wordlift_Metabox_Field_Multiline',
1062
+                        'label' => __( 'Recipe instructions', 'wordlift' ),
1063
+                    ),
1064
+                ),
1065
+                self::FIELD_RECIPE_YIELD            => array(
1066
+                    'predicate'   => 'http://schema.org/recipeYield',
1067
+                    'type'        => self::DATA_TYPE_STRING,
1068
+                    'export_type' => 'xsd:string',
1069
+                    'constraints' => '',
1070
+                    'metabox'     => array(
1071
+                        'label' => __( 'Recipe number of servings', 'wordlift' ),
1072
+                    ),
1073
+                ),
1074
+                self::FIELD_RECIPE_INGREDIENT       => array(
1075
+                    'predicate'   => 'http://schema.org/recipeIngredient',
1076
+                    'type'        => self::DATA_TYPE_STRING,
1077
+                    'export_type' => 'xsd:string',
1078
+                    'constraints' => array(
1079
+                        'cardinality' => INF,
1080
+                    ),
1081
+                    'metabox'     => array(
1082
+                        'label' => __( 'Recipe ingredient', 'wordlift' ),
1083
+                    ),
1084
+                ),
1085
+                self::FIELD_NUTRITION_INFO_CALORIES => array(
1086
+                    'predicate'   => 'http://schema.org/calories',
1087
+                    'type'        => self::DATA_TYPE_STRING,
1088
+                    'export_type' => 'xsd:string',
1089
+                    'constraints' => '',
1090
+                    'metabox'     => array(
1091
+                        'label' => __( 'Calories (e.g. 240 calories)', 'wordlift' ),
1092
+                    ),
1093
+                ),
1094
+                self::FIELD_PREP_TIME               => array(
1095
+                    'predicate'   => 'http://schema.org/prepTime',
1096
+                    'type'        => self::DATA_TYPE_DURATION,
1097
+                    'export_type' => 'xsd:time',
1098
+                    'constraints' => '',
1099
+                    'metabox'     => array(
1100
+                        'class' => 'Wordlift_Metabox_Field_Duration',
1101
+                        'label' => __( 'Recipe preparation time (e.g. 1:30)', 'wordlift' ),
1102
+                    ),
1103
+                ),
1104
+                self::FIELD_COOK_TIME               => array(
1105
+                    'predicate'   => 'http://schema.org/cookTime',
1106
+                    'type'        => self::DATA_TYPE_DURATION,
1107
+                    'export_type' => 'xsd:time',
1108
+                    'constraints' => '',
1109
+                    'metabox'     => array(
1110
+                        'class' => 'Wordlift_Metabox_Field_Duration',
1111
+                        'label' => __( 'Recipe cook time (e.g. 1:30)', 'wordlift' ),
1112
+                    ),
1113
+                ),
1114
+                self::FIELD_TOTAL_TIME              => array(
1115
+                    'predicate'   => 'http://schema.org/totalTime',
1116
+                    'type'        => self::DATA_TYPE_DURATION,
1117
+                    'export_type' => 'xsd:time',
1118
+                    'constraints' => '',
1119
+                    'metabox'     => array(
1120
+                        'class' => 'Wordlift_Metabox_Field_Duration',
1121
+                        'label' => __( 'Recipe total time (e.g. 1:30)', 'wordlift' ),
1122
+                    ),
1123
+                ),
1124
+            ),
1125
+        );
1126
+
1127
+        // Merge the custom fields with those provided by the parent schema.
1128
+        $parent_schema           = $this->get_creative_work_schema();
1129
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1130
+
1131
+        return $schema;
1132
+    }
1133
+
1134
+    /**
1135
+     * Get the 'offer' schema.
1136
+     *
1137
+     * @return array An array with the schema configuration.
1138
+     *
1139
+     * @since 3.18.0
1140
+     */
1141
+    private function get_offer_schema() {
1142
+
1143
+        $schema = array(
1144
+            'label'         => 'Offer',
1145
+            'description'   => 'An offer. ',
1146
+            'parents'       => array( 'thing' ),
1147
+            'css_class'     => 'wl-offer',
1148
+            'uri'           => self::SCHEMA_OFFER_TYPE,
1149
+            'same_as'       => array(),
1150
+            'templates'     => array(
1151
+                'subtitle' => '{{id}}',
1152
+            ),
1153
+            'custom_fields' => array(
1154
+                self::FIELD_AVAILABILITY        => array(
1155
+                    'predicate'   => 'http://schema.org/availability',
1156
+                    'type'        => self::DATA_TYPE_STRING,
1157
+                    'export_type' => 'xsd:string',
1158
+                    'metabox'     => array(
1159
+                        'class' => 'Wordlift_Metabox_Field_Select',
1160
+                    ),
1161
+                    'options'     => array(
1162
+                        'Discontinued'        => esc_html__( 'Discontinued', 'wordlift' ),
1163
+                        'InStock'             => esc_html__( 'In Stock', 'wordlift' ),
1164
+                        'InStoreOnly'         => esc_html__( 'In Store Only', 'wordlift' ),
1165
+                        'LimitedAvailability' => esc_html__( 'Limited Availability', 'wordlift' ),
1166
+                        'OnlineOnly'          => esc_html__( 'Online Only', 'wordlift' ),
1167
+                        'OutOfStock'          => esc_html__( 'Out of Stock', 'wordlift' ),
1168
+                        'PreOrder'            => esc_html__( 'Pre Order', 'wordlift' ),
1169
+                        'PreSale'             => esc_html__( 'Pre Sale', 'wordlift' ),
1170
+                        'SoldOut'             => esc_html__( 'Sold Out', 'wordlift' ),
1171
+                    ),
1172
+                ),
1173
+                self::FIELD_PRICE               => array(
1174
+                    'predicate'   => 'http://schema.org/price',
1175
+                    'type'        => self::DATA_TYPE_STRING,
1176
+                    'export_type' => 'xsd:integer',
1177
+                    'metabox'     => array(
1178
+                        'class' => 'Wordlift_Metabox_Field_Integer',
1179
+                    ),
1180
+                ),
1181
+                self::FIELD_PRICE_CURRENCY      => array(
1182
+                    'predicate'   => 'http://schema.org/priceCurrency',
1183
+                    'type'        => self::DATA_TYPE_STRING,
1184
+                    'export_type' => 'xsd:string',
1185
+                ),
1186
+                self::FIELD_AVAILABILITY_STARTS => array(
1187
+                    'predicate'   => 'http://schema.org/availabilityStarts',
1188
+                    'type'        => self::DATA_TYPE_DATE,
1189
+                    'export_type' => 'xsd:dateTime',
1190
+                ),
1191
+                self::FIELD_AVAILABILITY_ENDS   => array(
1192
+                    'predicate'   => 'http://schema.org/availabilityEnds',
1193
+                    'type'        => self::DATA_TYPE_DATE,
1194
+                    'export_type' => 'xsd:dateTime',
1195
+                ),
1196
+                self::FIELD_INVENTORY_LEVEL     => array(
1197
+                    'predicate'   => 'http://schema.org/inventoryLevel',
1198
+                    'type'        => self::DATA_TYPE_STRING,
1199
+                    'export_type' => 'xsd:integer',
1200
+                    'metabox'     => array(
1201
+                        'class' => 'Wordlift_Metabox_Field_Integer',
1202
+                    ),
1203
+                ),
1204
+                self::FIELD_VALID_FROM          => array(
1205
+                    'predicate'   => 'http://schema.org/validFrom',
1206
+                    'type'        => self::DATA_TYPE_DATE,
1207
+                    'export_type' => 'xsd:dateTime',
1208
+                ),
1209
+                self::FIELD_PRICE_VALID_UNTIL   => array(
1210
+                    'predicate'   => 'http://schema.org/priceValidUntil',
1211
+                    'type'        => self::DATA_TYPE_DATE,
1212
+                    'export_type' => 'xsd:dateTime',
1213
+                ),
1214
+                self::FIELD_ITEM_OFFERED        => array(
1215
+                    'predicate'   => 'http://schema.org/itemOffered',
1216
+                    'type'        => self::DATA_TYPE_URI,
1217
+                    'export_type' => 'http://schema.org/Thing',
1218
+                    'constraints' => array(
1219
+                        'uri_type'    => array(
1220
+                            'Event',
1221
+                            'Thing',
1222
+                        ),
1223
+                        'cardinality' => INF,
1224
+                    ),
1225
+                ),
1226
+            ),
1227
+        );
1228
+
1229
+        // Merge the custom fields with those provided by the thing schema.
1230
+        $parent_schema           = $this->get_thing_schema();
1231
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1232
+
1233
+        return $schema;
1234
+    }
1235
+
1236
+    /**
1237
+     * Get the 'article' schema.
1238
+     *
1239
+     * @return array An array with the schema configuration.
1240
+     *
1241
+     * @since 3.15.0
1242
+     */
1243
+    private function get_article_schema() {
1244
+
1245
+        $schema = array(
1246
+            'label'         => 'Article',
1247
+            'description'   => 'An Article.',
1248
+            'parents'       => array(),
1249
+            'css_class'     => 'wl-article',
1250
+            'uri'           => 'http://schema.org/Article',
1251
+            'same_as'       => array(),
1252
+            'templates'     => array(
1253
+                'subtitle' => '{{id}}',
1254
+            ),
1255
+            'custom_fields' => array(),
1256
+        );
1257
+
1258
+        return $schema;
1259
+    }
1260 1260
 
1261 1261
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 	 */
400 400
 	protected function __construct() {
401 401
 
402
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
402
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Schema_Service');
403 403
 
404 404
 		/**
405 405
 		 * Alter the configured schemas.
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	}
434 434
 
435 435
 	public function get_all_schema_slugs() {
436
-		return array_keys( $this->schema );
436
+		return array_keys($this->schema);
437 437
 	}
438 438
 
439 439
 	/**
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 	 * @since 3.1.0
453 453
 	 */
454 454
 	public static function get_instance() {
455
-		if ( ! isset( self::$instance ) ) {
455
+		if ( ! isset(self::$instance)) {
456 456
 			self::$instance = new self();
457 457
 		}
458 458
 
@@ -468,19 +468,19 @@  discard block
 block discarded – undo
468 468
 	 * @return null|array An array of field's properties or null if the field is not found.
469 469
 	 * @since 3.6.0
470 470
 	 */
471
-	public function get_field( $key ) {
471
+	public function get_field($key) {
472 472
 
473 473
 		// Parse each schema's fields until we find the one we're looking for, then
474 474
 		// return its properties.
475 475
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
476
-		foreach ( $this->schema as $_ => $schema ) {
476
+		foreach ($this->schema as $_ => $schema) {
477 477
 
478
-			if ( ! isset( $schema['custom_fields'] ) ) {
478
+			if ( ! isset($schema['custom_fields'])) {
479 479
 				break;
480 480
 			}
481 481
 
482
-			foreach ( $schema['custom_fields'] as $field => $props ) {
483
-				if ( $key === $field ) {
482
+			foreach ($schema['custom_fields'] as $field => $props) {
483
+				if ($key === $field) {
484 484
 					return $props;
485 485
 				}
486 486
 			}
@@ -498,14 +498,14 @@  discard block
 block discarded – undo
498 498
 	 *
499 499
 	 * @since 3.1.0
500 500
 	 */
501
-	public function get_schema( $name ) {
501
+	public function get_schema($name) {
502 502
 		// Check if the schema exists and, if not, return NULL.
503
-		if ( ! isset( $this->schema[ $name ] ) ) {
503
+		if ( ! isset($this->schema[$name])) {
504 504
 			return null;
505 505
 		}
506 506
 
507 507
 		// Return the requested schema.
508
-		return $this->schema[ $name ];
508
+		return $this->schema[$name];
509 509
 	}
510 510
 
511 511
 	/**
@@ -517,11 +517,11 @@  discard block
 block discarded – undo
517 517
 	 *
518 518
 	 * @since 3.3.0
519 519
 	 */
520
-	public function get_schema_by_uri( $uri ) {
520
+	public function get_schema_by_uri($uri) {
521 521
 
522 522
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
523
-		foreach ( $this->schema as $name => $schema ) {
524
-			if ( $schema['uri'] === $uri ) {
523
+		foreach ($this->schema as $name => $schema) {
524
+			if ($schema['uri'] === $uri) {
525 525
 				return $schema;
526 526
 			}
527 527
 		}
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
 		return array(
542 542
 			'css_class'     => 'wl-thing',
543 543
 			'uri'           => 'http://schema.org/Thing',
544
-			'same_as'       => array( '*' ),
544
+			'same_as'       => array('*'),
545 545
 			// set as default.
546 546
 			'custom_fields' => array(
547 547
 				self::FIELD_SAME_AS => array(
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
 		$schema = array(
596 596
 			'label'         => 'CreativeWork',
597 597
 			'description'   => 'A creative work (or a Music Album).',
598
-			'parents'       => array( 'thing' ),
598
+			'parents'       => array('thing'),
599 599
 			// Give term slug as parent.
600 600
 			'css_class'     => 'wl-creative-work',
601 601
 			'uri'           => 'http://schema.org/CreativeWork',
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 					'type'        => self::DATA_TYPE_URI,
610 610
 					'export_type' => 'http://schema.org/Person',
611 611
 					'constraints' => array(
612
-						'uri_type'    => array( 'Person', 'Organization' ),
612
+						'uri_type'    => array('Person', 'Organization'),
613 613
 						'cardinality' => INF,
614 614
 					),
615 615
 				),
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
 
622 622
 		// Merge the custom fields with those provided by the thing schema.
623 623
 		$parent_schema           = $this->get_thing_schema();
624
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
624
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
625 625
 
626 626
 		return $schema;
627 627
 	}
@@ -638,10 +638,10 @@  discard block
 block discarded – undo
638 638
 		$schema = array(
639 639
 			'label'         => 'Event',
640 640
 			'description'   => 'An event . ',
641
-			'parents'       => array( 'thing' ),
641
+			'parents'       => array('thing'),
642 642
 			'css_class'     => 'wl-event',
643 643
 			'uri'           => self::SCHEMA_EVENT_TYPE,
644
-			'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
644
+			'same_as'       => array('http://dbpedia.org/ontology/Event'),
645 645
 			'custom_fields' => array(
646 646
 				self::FIELD_DATE_START => array(
647 647
 					'predicate'   => 'http://schema.org/startDate',
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
 					'type'        => self::DATA_TYPE_URI,
661 661
 					'export_type' => 'http://schema.org/PostalAddress',
662 662
 					'constraints' => array(
663
-						'uri_type'    => array( 'Place', 'LocalBusiness' ),
663
+						'uri_type'    => array('Place', 'LocalBusiness'),
664 664
 						'cardinality' => INF,
665 665
 					),
666 666
 				),
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
 					'type'        => self::DATA_TYPE_URI,
670 670
 					'export_type' => 'http://schema.org/Person',
671 671
 					'constraints' => array(
672
-						'uri_type'    => array( 'Person', 'Organization' ),
672
+						'uri_type'    => array('Person', 'Organization'),
673 673
 						'cardinality' => INF,
674 674
 					),
675 675
 				),
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
 					'type'        => self::DATA_TYPE_URI,
679 679
 					'export_type' => 'http://schema.org/Offer',
680 680
 					'constraints' => array(
681
-						'uri_type'    => array( 'Offer' ),
681
+						'uri_type'    => array('Offer'),
682 682
 						'cardinality' => INF,
683 683
 					),
684 684
 				),
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 
691 691
 		// Merge the custom fields with those provided by the thing schema.
692 692
 		$parent_schema           = $this->get_thing_schema();
693
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
693
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
694 694
 
695 695
 		return $schema;
696 696
 	}
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 		$schema = array(
708 708
 			'label'         => 'Organization',
709 709
 			'description'   => 'An organization, including a government or a newspaper.',
710
-			'parents'       => array( 'thing' ),
710
+			'parents'       => array('thing'),
711 711
 			'css_class'     => 'wl-organization',
712 712
 			'uri'           => 'http://schema.org/Organization',
713 713
 			'same_as'       => array(
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
 
800 800
 		// Merge the custom fields with those provided by the thing schema.
801 801
 		$parent_schema           = $this->get_thing_schema();
802
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
802
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
803 803
 
804 804
 		return $schema;
805 805
 	}
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
 		$schema = array(
817 817
 			'label'         => 'Person',
818 818
 			'description'   => 'A person (or a music artist).',
819
-			'parents'       => array( 'thing' ),
819
+			'parents'       => array('thing'),
820 820
 			'css_class'     => 'wl-person',
821 821
 			'uri'           => 'http://schema.org/Person',
822 822
 			'same_as'       => array(
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
 
877 877
 		// Merge the custom fields with those provided by the thing schema.
878 878
 		$parent_schema           = $this->get_thing_schema();
879
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
879
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
880 880
 
881 881
 		return $schema;
882 882
 
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
 		$schema = array(
895 895
 			'label'         => 'Place',
896 896
 			'description'   => 'A place.',
897
-			'parents'       => array( 'thing' ),
897
+			'parents'       => array('thing'),
898 898
 			'css_class'     => 'wl-place',
899 899
 			'uri'           => 'http://schema.org/Place',
900 900
 			'same_as'       => array(
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
 
975 975
 		// Merge the custom fields with those provided by the thing schema.
976 976
 		$parent_schema           = $this->get_thing_schema();
977
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
977
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
978 978
 
979 979
 		return $schema;
980 980
 	}
@@ -991,7 +991,7 @@  discard block
 block discarded – undo
991 991
 		$schema = array(
992 992
 			'label'         => 'LocalBusiness',
993 993
 			'description'   => 'A local business.',
994
-			'parents'       => array( 'place', 'organization' ),
994
+			'parents'       => array('place', 'organization'),
995 995
 			'css_class'     => 'wl-local-business',
996 996
 			'uri'           => 'http://schema.org/LocalBusiness',
997 997
 			'same_as'       => array(
@@ -1007,7 +1007,7 @@  discard block
 block discarded – undo
1007 1007
 		// Merge the custom fields with those provided by the place and organization schema.
1008 1008
 		$place_schema            = $this->get_place_schema();
1009 1009
 		$organization_schema     = $this->get_organization_schema();
1010
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
1010
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields']);
1011 1011
 
1012 1012
 		return $schema;
1013 1013
 	}
@@ -1024,7 +1024,7 @@  discard block
 block discarded – undo
1024 1024
 		$schema = array(
1025 1025
 			'label'         => 'Recipe',
1026 1026
 			'description'   => 'A Recipe.',
1027
-			'parents'       => array( 'CreativeWork' ),
1027
+			'parents'       => array('CreativeWork'),
1028 1028
 			'css_class'     => 'wl-recipe',
1029 1029
 			'uri'           => 'http://schema.org/Recipe',
1030 1030
 			'same_as'       => array(),
@@ -1038,7 +1038,7 @@  discard block
 block discarded – undo
1038 1038
 					'export_type' => 'xsd:string',
1039 1039
 					'constraints' => '',
1040 1040
 					'metabox'     => array(
1041
-						'label' => __( 'Recipe cuisine', 'wordlift' ),
1041
+						'label' => __('Recipe cuisine', 'wordlift'),
1042 1042
 					),
1043 1043
 				),
1044 1044
 				self::FIELD_RECIPE_INGREDIENT       => array(
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
 						'cardinality' => INF,
1050 1050
 					),
1051 1051
 					'metabox'     => array(
1052
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
1052
+						'label' => __('Recipe ingredient', 'wordlift'),
1053 1053
 					),
1054 1054
 				),
1055 1055
 				self::FIELD_RECIPE_INSTRUCTIONS     => array(
@@ -1059,7 +1059,7 @@  discard block
 block discarded – undo
1059 1059
 					'constraints' => '',
1060 1060
 					'metabox'     => array(
1061 1061
 						'class' => 'Wordlift_Metabox_Field_Multiline',
1062
-						'label' => __( 'Recipe instructions', 'wordlift' ),
1062
+						'label' => __('Recipe instructions', 'wordlift'),
1063 1063
 					),
1064 1064
 				),
1065 1065
 				self::FIELD_RECIPE_YIELD            => array(
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
 					'export_type' => 'xsd:string',
1069 1069
 					'constraints' => '',
1070 1070
 					'metabox'     => array(
1071
-						'label' => __( 'Recipe number of servings', 'wordlift' ),
1071
+						'label' => __('Recipe number of servings', 'wordlift'),
1072 1072
 					),
1073 1073
 				),
1074 1074
 				self::FIELD_RECIPE_INGREDIENT       => array(
@@ -1079,7 +1079,7 @@  discard block
 block discarded – undo
1079 1079
 						'cardinality' => INF,
1080 1080
 					),
1081 1081
 					'metabox'     => array(
1082
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
1082
+						'label' => __('Recipe ingredient', 'wordlift'),
1083 1083
 					),
1084 1084
 				),
1085 1085
 				self::FIELD_NUTRITION_INFO_CALORIES => array(
@@ -1088,7 +1088,7 @@  discard block
 block discarded – undo
1088 1088
 					'export_type' => 'xsd:string',
1089 1089
 					'constraints' => '',
1090 1090
 					'metabox'     => array(
1091
-						'label' => __( 'Calories (e.g. 240 calories)', 'wordlift' ),
1091
+						'label' => __('Calories (e.g. 240 calories)', 'wordlift'),
1092 1092
 					),
1093 1093
 				),
1094 1094
 				self::FIELD_PREP_TIME               => array(
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
 					'constraints' => '',
1099 1099
 					'metabox'     => array(
1100 1100
 						'class' => 'Wordlift_Metabox_Field_Duration',
1101
-						'label' => __( 'Recipe preparation time (e.g. 1:30)', 'wordlift' ),
1101
+						'label' => __('Recipe preparation time (e.g. 1:30)', 'wordlift'),
1102 1102
 					),
1103 1103
 				),
1104 1104
 				self::FIELD_COOK_TIME               => array(
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
 					'constraints' => '',
1109 1109
 					'metabox'     => array(
1110 1110
 						'class' => 'Wordlift_Metabox_Field_Duration',
1111
-						'label' => __( 'Recipe cook time (e.g. 1:30)', 'wordlift' ),
1111
+						'label' => __('Recipe cook time (e.g. 1:30)', 'wordlift'),
1112 1112
 					),
1113 1113
 				),
1114 1114
 				self::FIELD_TOTAL_TIME              => array(
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
 					'constraints' => '',
1119 1119
 					'metabox'     => array(
1120 1120
 						'class' => 'Wordlift_Metabox_Field_Duration',
1121
-						'label' => __( 'Recipe total time (e.g. 1:30)', 'wordlift' ),
1121
+						'label' => __('Recipe total time (e.g. 1:30)', 'wordlift'),
1122 1122
 					),
1123 1123
 				),
1124 1124
 			),
@@ -1126,7 +1126,7 @@  discard block
 block discarded – undo
1126 1126
 
1127 1127
 		// Merge the custom fields with those provided by the parent schema.
1128 1128
 		$parent_schema           = $this->get_creative_work_schema();
1129
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1129
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
1130 1130
 
1131 1131
 		return $schema;
1132 1132
 	}
@@ -1143,7 +1143,7 @@  discard block
 block discarded – undo
1143 1143
 		$schema = array(
1144 1144
 			'label'         => 'Offer',
1145 1145
 			'description'   => 'An offer. ',
1146
-			'parents'       => array( 'thing' ),
1146
+			'parents'       => array('thing'),
1147 1147
 			'css_class'     => 'wl-offer',
1148 1148
 			'uri'           => self::SCHEMA_OFFER_TYPE,
1149 1149
 			'same_as'       => array(),
@@ -1159,15 +1159,15 @@  discard block
 block discarded – undo
1159 1159
 						'class' => 'Wordlift_Metabox_Field_Select',
1160 1160
 					),
1161 1161
 					'options'     => array(
1162
-						'Discontinued'        => esc_html__( 'Discontinued', 'wordlift' ),
1163
-						'InStock'             => esc_html__( 'In Stock', 'wordlift' ),
1164
-						'InStoreOnly'         => esc_html__( 'In Store Only', 'wordlift' ),
1165
-						'LimitedAvailability' => esc_html__( 'Limited Availability', 'wordlift' ),
1166
-						'OnlineOnly'          => esc_html__( 'Online Only', 'wordlift' ),
1167
-						'OutOfStock'          => esc_html__( 'Out of Stock', 'wordlift' ),
1168
-						'PreOrder'            => esc_html__( 'Pre Order', 'wordlift' ),
1169
-						'PreSale'             => esc_html__( 'Pre Sale', 'wordlift' ),
1170
-						'SoldOut'             => esc_html__( 'Sold Out', 'wordlift' ),
1162
+						'Discontinued'        => esc_html__('Discontinued', 'wordlift'),
1163
+						'InStock'             => esc_html__('In Stock', 'wordlift'),
1164
+						'InStoreOnly'         => esc_html__('In Store Only', 'wordlift'),
1165
+						'LimitedAvailability' => esc_html__('Limited Availability', 'wordlift'),
1166
+						'OnlineOnly'          => esc_html__('Online Only', 'wordlift'),
1167
+						'OutOfStock'          => esc_html__('Out of Stock', 'wordlift'),
1168
+						'PreOrder'            => esc_html__('Pre Order', 'wordlift'),
1169
+						'PreSale'             => esc_html__('Pre Sale', 'wordlift'),
1170
+						'SoldOut'             => esc_html__('Sold Out', 'wordlift'),
1171 1171
 					),
1172 1172
 				),
1173 1173
 				self::FIELD_PRICE               => array(
@@ -1228,7 +1228,7 @@  discard block
 block discarded – undo
1228 1228
 
1229 1229
 		// Merge the custom fields with those provided by the thing schema.
1230 1230
 		$parent_schema           = $this->get_thing_schema();
1231
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1231
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
1232 1232
 
1233 1233
 		return $schema;
1234 1234
 	}
Please login to merge, or discard this patch.
src/wordlift/vocabulary-terms/class-entity-type.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -14,114 +14,114 @@
 block discarded – undo
14 14
 
15 15
 class Entity_Type {
16 16
 
17
-	public function __construct() {
18
-
19
-		$that = $this;
20
-
21
-		add_action(
22
-			'init',
23
-			function () use ( $that ) {
24
-				$that->init_ui_and_save_handlers();
25
-			}
26
-		);
27
-	}
28
-
29
-	/**
30
-	 * @param $term  \WP_Term
31
-	 */
32
-	public function render_ui( $term ) {
33
-
34
-		$selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
35
-
36
-		/**
37
-		 * Thing should be the default selected entity type
38
-		 * when this feature is activated.
39
-		 */
40
-		if ( count( $selected_entity_types ) === 0 ) {
41
-			$selected_entity_types[] = 'thing';
42
-		}
43
-
44
-		$entity_type_taxonomy = Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME;
45
-		$types                = Terms_Compat::get_terms(
46
-			$entity_type_taxonomy,
47
-			array(
48
-				'taxonomy'   => $entity_type_taxonomy,
49
-				'parent'     => 0,
50
-				'hide_empty' => false,
51
-			)
52
-		);
53
-		?>
17
+    public function __construct() {
18
+
19
+        $that = $this;
20
+
21
+        add_action(
22
+            'init',
23
+            function () use ( $that ) {
24
+                $that->init_ui_and_save_handlers();
25
+            }
26
+        );
27
+    }
28
+
29
+    /**
30
+     * @param $term  \WP_Term
31
+     */
32
+    public function render_ui( $term ) {
33
+
34
+        $selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
35
+
36
+        /**
37
+         * Thing should be the default selected entity type
38
+         * when this feature is activated.
39
+         */
40
+        if ( count( $selected_entity_types ) === 0 ) {
41
+            $selected_entity_types[] = 'thing';
42
+        }
43
+
44
+        $entity_type_taxonomy = Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME;
45
+        $types                = Terms_Compat::get_terms(
46
+            $entity_type_taxonomy,
47
+            array(
48
+                'taxonomy'   => $entity_type_taxonomy,
49
+                'parent'     => 0,
50
+                'hide_empty' => false,
51
+            )
52
+        );
53
+        ?>
54 54
 		<?php wp_nonce_field( 'wordlift_vocabulary_terms_entity_type', 'wordlift_vocabulary_terms_entity_type_nonce' ); ?>
55 55
 		<tr class="form-field term-name-wrap">
56 56
 			<th scope="row"><label for="wl-entity-type__checklist"><?php esc_html_e( 'Entity Types', 'wordlift' ); ?></label></th>
57 57
 			<td>
58 58
 				<div id="wl-entity-type__checklist">
59 59
 					<?php
60
-					echo wp_kses(
61
-						Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types ),
62
-						array(
63
-							'li'    => array( 'id' => array() ),
64
-							'ul'    => array( 'id' => array() ),
65
-							'label' => array( 'class' => array() ),
66
-							'input' => array(
67
-								'value'       => array(),
68
-								'type'        => array(),
69
-								'name'        => array(),
70
-								'id'          => array(),
71
-								'placeholder' => array(),
72
-								'checked'     => array(),
73
-							),
74
-						)
75
-					);
76
-					?>
60
+                    echo wp_kses(
61
+                        Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types ),
62
+                        array(
63
+                            'li'    => array( 'id' => array() ),
64
+                            'ul'    => array( 'id' => array() ),
65
+                            'label' => array( 'class' => array() ),
66
+                            'input' => array(
67
+                                'value'       => array(),
68
+                                'type'        => array(),
69
+                                'name'        => array(),
70
+                                'id'          => array(),
71
+                                'placeholder' => array(),
72
+                                'checked'     => array(),
73
+                            ),
74
+                        )
75
+                    );
76
+                    ?>
77 77
 				</div>
78 78
 			</td>
79 79
 		</tr>
80 80
 		<?php
81
-		$this->enqueue_script_and_style();
82
-	}
83
-
84
-	public function save_field( $term_id ) {
85
-
86
-		if ( ! isset( $_REQUEST['tax_input'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
87
-			return;
88
-		}
89
-		$entity_types = array();
90
-		if ( isset( $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
91
-			$entity_types_data = filter_var_array( $_REQUEST, array( 'tax_input' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
92
-			$entity_types      = $entity_types_data['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ];
93
-		}
94
-
95
-		if ( isset( $entity_types ) && is_array( $entity_types ) ) {
96
-			// Save the taxonomies.
97
-			delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
98
-			foreach ( $entity_types as $entity_type ) {
99
-				add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type );
100
-			}
101
-		}
102
-	}
103
-
104
-	public function init_ui_and_save_handlers() {
105
-		$taxonomies = Terms_Compat::get_public_taxonomies();
106
-		foreach ( $taxonomies as $taxonomy ) {
107
-			add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 );
108
-			add_action( "edited_${taxonomy}", array( $this, 'save_field' ) );
109
-		}
110
-	}
111
-
112
-	private function enqueue_script_and_style() {
113
-
114
-		Scripts_Helper::enqueue_based_on_wordpress_version(
115
-			'wl-vocabulary-term',
116
-			plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term',
117
-			array( 'wp-polyfill' )
118
-		);
119
-		wp_enqueue_style(
120
-			'wl-vocabulary-term',
121
-			plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term.css',
122
-			array(),
123
-			WORDLIFT_VERSION
124
-		);
125
-	}
81
+        $this->enqueue_script_and_style();
82
+    }
83
+
84
+    public function save_field( $term_id ) {
85
+
86
+        if ( ! isset( $_REQUEST['tax_input'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
87
+            return;
88
+        }
89
+        $entity_types = array();
90
+        if ( isset( $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
91
+            $entity_types_data = filter_var_array( $_REQUEST, array( 'tax_input' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
92
+            $entity_types      = $entity_types_data['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ];
93
+        }
94
+
95
+        if ( isset( $entity_types ) && is_array( $entity_types ) ) {
96
+            // Save the taxonomies.
97
+            delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
98
+            foreach ( $entity_types as $entity_type ) {
99
+                add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type );
100
+            }
101
+        }
102
+    }
103
+
104
+    public function init_ui_and_save_handlers() {
105
+        $taxonomies = Terms_Compat::get_public_taxonomies();
106
+        foreach ( $taxonomies as $taxonomy ) {
107
+            add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 );
108
+            add_action( "edited_${taxonomy}", array( $this, 'save_field' ) );
109
+        }
110
+    }
111
+
112
+    private function enqueue_script_and_style() {
113
+
114
+        Scripts_Helper::enqueue_based_on_wordpress_version(
115
+            'wl-vocabulary-term',
116
+            plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term',
117
+            array( 'wp-polyfill' )
118
+        );
119
+        wp_enqueue_style(
120
+            'wl-vocabulary-term',
121
+            plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term.css',
122
+            array(),
123
+            WORDLIFT_VERSION
124
+        );
125
+    }
126 126
 
127 127
 }
Please login to merge, or discard this patch.
src/wordlift/entity/query/class-entity.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	 * @param $schema_type
19 19
 	 * @param $content Wordpress_Content
20 20
 	 */
21
-	public function __construct( $schema_type, $content ) {
21
+	public function __construct($schema_type, $content) {
22 22
 		$this->schema_type = $schema_type;
23 23
 		$this->content     = $content;
24 24
 	}
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
 	}
36 36
 
37 37
 	public function get_title() {
38
-		if ( Object_Type_Enum::POST === $this->content->get_object_type_enum() ) {
38
+		if (Object_Type_Enum::POST === $this->content->get_object_type_enum()) {
39 39
 			return $this->content->get_bag()->post_title;
40 40
 		}
41
-		if ( Object_Type_Enum::TERM === $this->content->get_object_type_enum() ) {
41
+		if (Object_Type_Enum::TERM === $this->content->get_object_type_enum()) {
42 42
 			return $this->content->get_bag()->name;
43 43
 		}
44 44
 		return '';
Please login to merge, or discard this patch.
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@
 block discarded – undo
7 7
 
8 8
 class Entity {
9 9
 
10
-	private $schema_type;
11
-	/**
12
-	 * @var Wordpress_Content
13
-	 */
14
-	private $content;
15
-
16
-	/**
17
-	 * @param $schema_type
18
-	 * @param $content Wordpress_Content
19
-	 */
20
-	public function __construct( $schema_type, $content ) {
21
-		$this->schema_type = $schema_type;
22
-		$this->content     = $content;
23
-	}
24
-
25
-	/**
26
-	 * @return Wordpress_Content
27
-	 */
28
-	public function get_content() {
29
-		return $this->content;
30
-	}
31
-
32
-	public function get_schema_type() {
33
-		return $this->schema_type;
34
-	}
35
-
36
-	public function get_title() {
37
-		if ( Object_Type_Enum::POST === $this->content->get_object_type_enum() ) {
38
-			return $this->content->get_bag()->post_title;
39
-		}
40
-		if ( Object_Type_Enum::TERM === $this->content->get_object_type_enum() ) {
41
-			return $this->content->get_bag()->name;
42
-		}
43
-		return '';
44
-	}
10
+    private $schema_type;
11
+    /**
12
+     * @var Wordpress_Content
13
+     */
14
+    private $content;
15
+
16
+    /**
17
+     * @param $schema_type
18
+     * @param $content Wordpress_Content
19
+     */
20
+    public function __construct( $schema_type, $content ) {
21
+        $this->schema_type = $schema_type;
22
+        $this->content     = $content;
23
+    }
24
+
25
+    /**
26
+     * @return Wordpress_Content
27
+     */
28
+    public function get_content() {
29
+        return $this->content;
30
+    }
31
+
32
+    public function get_schema_type() {
33
+        return $this->schema_type;
34
+    }
35
+
36
+    public function get_title() {
37
+        if ( Object_Type_Enum::POST === $this->content->get_object_type_enum() ) {
38
+            return $this->content->get_bag()->post_title;
39
+        }
40
+        if ( Object_Type_Enum::TERM === $this->content->get_object_type_enum() ) {
41
+            return $this->content->get_bag()->name;
42
+        }
43
+        return '';
44
+    }
45 45
 
46 46
 }
Please login to merge, or discard this patch.
src/modules/pods/includes/FieldDefinition/FieldDefinitionFactory.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 	 */
13 13
 	private $schema;
14 14
 
15
-	public function __construct( $schema ) {
15
+	public function __construct($schema) {
16 16
 		$this->schema = $schema;
17 17
 	}
18 18
 
@@ -21,13 +21,13 @@  discard block
 block discarded – undo
21 21
 
22 22
 		$context_type = $this->schema->get_context_type();
23 23
 
24
-		switch ( $context_type ) {
24
+		switch ($context_type) {
25 25
 			case Context::POST:
26
-				return new PostTypeDefinition( $this->schema );
26
+				return new PostTypeDefinition($this->schema);
27 27
 			case Context::TERM:
28
-				return new TaxonomyDefinition( $this->schema );
28
+				return new TaxonomyDefinition($this->schema);
29 29
 			default:
30
-				return new AllPodsDefiniton( $this->schema );
30
+				return new AllPodsDefiniton($this->schema);
31 31
 		}
32 32
 	}
33 33
 
Please login to merge, or discard this patch.
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -7,27 +7,27 @@
 block discarded – undo
7 7
 
8 8
 class FieldDefinitionFactory {
9 9
 
10
-	/**
11
-	 * @var $schema Schema
12
-	 */
13
-	private $schema;
14
-
15
-	public function __construct( $schema ) {
16
-		$this->schema = $schema;
17
-	}
18
-
19
-	public function get_field_definition() {
20
-
21
-		$context_type = $this->schema->get_context_type();
22
-
23
-		switch ( $context_type ) {
24
-			case Context::POST:
25
-				return new PostTypeDefinition( $this->schema );
26
-			case Context::TERM:
27
-				return new TaxonomyDefinition( $this->schema );
28
-			default:
29
-				return new AllPodsDefiniton( $this->schema );
30
-		}
31
-	}
10
+    /**
11
+     * @var $schema Schema
12
+     */
13
+    private $schema;
14
+
15
+    public function __construct( $schema ) {
16
+        $this->schema = $schema;
17
+    }
18
+
19
+    public function get_field_definition() {
20
+
21
+        $context_type = $this->schema->get_context_type();
22
+
23
+        switch ( $context_type ) {
24
+            case Context::POST:
25
+                return new PostTypeDefinition( $this->schema );
26
+            case Context::TERM:
27
+                return new TaxonomyDefinition( $this->schema );
28
+            default:
29
+                return new AllPodsDefiniton( $this->schema );
30
+        }
31
+    }
32 32
 
33 33
 }
Please login to merge, or discard this patch.
src/modules/pods/includes/FieldDefinition/PostTypeDefinition.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -4,14 +4,14 @@
 block discarded – undo
4 4
 
5 5
 class PostTypeDefinition extends AbstractFieldDefiniton {
6 6
 
7
-	public function register() {
8
-		$that = $this;
9
-		add_action(
10
-			'init',
11
-			function () use ( $that ) {
12
-				$context = $that->schema->get();
13
-				$that->register_pod( $context->get_pod_name(), $context->get_pod_type(), $context );
14
-			}
15
-		);
16
-	}
7
+    public function register() {
8
+        $that = $this;
9
+        add_action(
10
+            'init',
11
+            function () use ( $that ) {
12
+                $context = $that->schema->get();
13
+                $that->register_pod( $context->get_pod_name(), $context->get_pod_type(), $context );
14
+            }
15
+        );
16
+    }
17 17
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,9 +8,9 @@
 block discarded – undo
8 8
 		$that = $this;
9 9
 		add_action(
10 10
 			'init',
11
-			function () use ( $that ) {
11
+			function() use ($that) {
12 12
 				$context = $that->schema->get();
13
-				$that->register_pod( $context->get_pod_name(), $context->get_pod_type(), $context );
13
+				$that->register_pod($context->get_pod_name(), $context->get_pod_type(), $context);
14 14
 			}
15 15
 		);
16 16
 	}
Please login to merge, or discard this patch.
src/modules/pods/includes/FieldDefinition/TaxonomyDefinition.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -4,14 +4,14 @@
 block discarded – undo
4 4
 
5 5
 class TaxonomyDefinition extends AbstractFieldDefiniton {
6 6
 
7
-	public function register() {
8
-		$that = $this;
9
-		add_action(
10
-			'setup_theme',
11
-			function () use ( $that ) {
12
-				$context = $that->schema->get();
13
-				$that->register_pod( $context->get_pod_name(), $context->get_pod_type(), $context );
14
-			}
15
-		);
16
-	}
7
+    public function register() {
8
+        $that = $this;
9
+        add_action(
10
+            'setup_theme',
11
+            function () use ( $that ) {
12
+                $context = $that->schema->get();
13
+                $that->register_pod( $context->get_pod_name(), $context->get_pod_type(), $context );
14
+            }
15
+        );
16
+    }
17 17
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,9 +8,9 @@
 block discarded – undo
8 8
 		$that = $this;
9 9
 		add_action(
10 10
 			'setup_theme',
11
-			function () use ( $that ) {
11
+			function() use ($that) {
12 12
 				$context = $that->schema->get();
13
-				$that->register_pod( $context->get_pod_name(), $context->get_pod_type(), $context );
13
+				$that->register_pod($context->get_pod_name(), $context->get_pod_type(), $context);
14 14
 			}
15 15
 		);
16 16
 	}
Please login to merge, or discard this patch.
src/modules/pods/includes/Notices.php 2 patches
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
 	 */
10 10
 	private $pods_plugin;
11 11
 
12
-	public function __construct( Plugin $plugin ) {
12
+	public function __construct(Plugin $plugin) {
13 13
 		$this->pods_plugin = $plugin;
14 14
 	}
15 15
 
16 16
 	public function register_hooks() {
17
-		add_action( 'wl_metabox_before_html', array( $this, 'admin_notices' ) );
17
+		add_action('wl_metabox_before_html', array($this, 'admin_notices'));
18 18
 	}
19 19
 
20 20
 	public function admin_notices() {
@@ -22,29 +22,29 @@  discard block
 block discarded – undo
22 22
 		/**
23 23
 		 * When pods not installed or activated then the notice should appear.
24 24
 		 */
25
-		if ( ! $this->pods_plugin->is_plugin_installed() ) {
25
+		if ( ! $this->pods_plugin->is_plugin_installed()) {
26 26
 			$this->display_notice(
27
-				__( 'WordLift detected that <b>Pods – Custom Content Types and Fields</b> is not installed.', 'wordlift' ),
28
-				__( 'Reinstall & Activate', 'wordlift' )
27
+				__('WordLift detected that <b>Pods – Custom Content Types and Fields</b> is not installed.', 'wordlift'),
28
+				__('Reinstall & Activate', 'wordlift')
29 29
 			);
30 30
 
31 31
 			// Dont display notice.
32 32
 			return;
33 33
 		}
34 34
 
35
-		if ( ! $this->pods_plugin->is_plugin_activated() ) {
35
+		if ( ! $this->pods_plugin->is_plugin_activated()) {
36 36
 			$this->display_notice(
37
-				__( 'WordLift detected that <b>Pods – Custom Content Types and Fields</b> is deactivated.', 'wordlift' ),
38
-				__( 'Reactivate', 'wordlift' )
37
+				__('WordLift detected that <b>Pods – Custom Content Types and Fields</b> is deactivated.', 'wordlift'),
38
+				__('Reactivate', 'wordlift')
39 39
 			);
40 40
 
41 41
 			return;
42 42
 		}
43 43
 	}
44 44
 
45
-	private function display_notice( $message, $button_text ) {
45
+	private function display_notice($message, $button_text) {
46 46
 
47
-		$kses_options                 = array(
47
+		$kses_options = array(
48 48
 			'p'      => array(),
49 49
 			'b'      => array(),
50 50
 			'button' => array(
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
 			'wordlift'
58 58
 		);
59 59
 
60
-		$installing_message          = __( 'Installing', 'wordlift' ) . ' <span class="spinner is-active"></span>';
61
-		$installation_failed_message = '<p>' .
62
-			__( 'Wordlift: Pods – Custom Content Types and Fields installation failed, please retry or contact [email protected]', 'wordlift' )
60
+		$installing_message          = __('Installing', 'wordlift').' <span class="spinner is-active"></span>';
61
+		$installation_failed_message = '<p>'.
62
+			__('Wordlift: Pods – Custom Content Types and Fields installation failed, please retry or contact [email protected]', 'wordlift')
63 63
 			. '</p><button class="button action" onclick="wordliftInstallPods(this)">'
64
-			. __( 'Retry', 'wordlift' )
64
+			. __('Retry', 'wordlift')
65 65
 			. '</button>';
66 66
 		?>
67 67
 
@@ -70,15 +70,15 @@  discard block
 block discarded – undo
70 70
 				const pluginInstallationNotice = document.getElementById("wordlift_pods_plugin_installation_notice")
71 71
 				const installPlugin = (ajaxUrl) => fetch(`${ajaxUrl}?action=wl_install_and_activate_pods`)
72 72
 					.then(response => response.ok ? response.json() : Promise.reject())
73
-				const ajaxUrl = "<?php echo esc_html( wp_parse_url( admin_url( 'admin-ajax.php' ), PHP_URL_PATH ) ); ?>"
73
+				const ajaxUrl = "<?php echo esc_html(wp_parse_url(admin_url('admin-ajax.php'), PHP_URL_PATH)); ?>"
74 74
 				window.wordliftInstallPods = function (installBtn) {
75
-					installBtn.innerHTML = `<?php echo wp_kses( $installing_message, array( 'span' => array( 'class' => array() ) ) ); ?>`
75
+					installBtn.innerHTML = `<?php echo wp_kses($installing_message, array('span' => array('class' => array()))); ?>`
76 76
 					installPlugin(ajaxUrl)
77 77
 						.catch(e => {
78
-							pluginInstallationNotice.innerHTML = `<?php echo wp_kses( $installation_failed_message, $kses_options ); ?>`
78
+							pluginInstallationNotice.innerHTML = `<?php echo wp_kses($installation_failed_message, $kses_options); ?>`
79 79
 						})
80 80
 						.then(() => {
81
-							pluginInstallationNotice.innerHTML = `<?php echo wp_kses( $installation_success_message, $kses_options ); ?>`
81
+							pluginInstallationNotice.innerHTML = `<?php echo wp_kses($installation_success_message, $kses_options); ?>`
82 82
 							pluginInstallationNotice.classList.remove('notice-error')
83 83
 							pluginInstallationNotice.classList.add('notice-success')
84 84
 						})
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
 
91 91
 		<div class="wl-notice notice-error" id="wordlift_pods_plugin_installation_notice">
92 92
 			<p>
93
-				<?php echo wp_kses( $message, array( 'b' => array() ) ); ?>
93
+				<?php echo wp_kses($message, array('b' => array())); ?>
94 94
 				<button class="button action right" onclick="wordliftInstallPods(this)">
95
-					<?php echo esc_html( $button_text ); ?>
95
+					<?php echo esc_html($button_text); ?>
96 96
 				</button>
97 97
 			</p>
98 98
 			<br/>
Please login to merge, or discard this patch.
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -6,66 +6,66 @@  discard block
 block discarded – undo
6 6
 
7 7
 class Notices {
8 8
 
9
-	/**
10
-	 * @var Plugin
11
-	 */
12
-	private $pods_plugin;
13
-
14
-	public function __construct( Plugin $plugin ) {
15
-		$this->pods_plugin = $plugin;
16
-	}
17
-
18
-	public function register_hooks() {
19
-		add_action( 'wl_metabox_before_html', array( $this, 'admin_notices' ) );
20
-	}
21
-
22
-	public function admin_notices() {
23
-
24
-		/**
25
-		 * When pods not installed or activated then the notice should appear.
26
-		 */
27
-		if ( ! $this->pods_plugin->is_plugin_installed() ) {
28
-			$this->display_notice(
29
-				__( 'WordLift detected that <b>Pods – Custom Content Types and Fields</b> is not installed.', 'wordlift' ),
30
-				__( 'Reinstall & Activate', 'wordlift' )
31
-			);
32
-
33
-			// Dont display notice.
34
-			return;
35
-		}
36
-
37
-		if ( ! $this->pods_plugin->is_plugin_activated() ) {
38
-			$this->display_notice(
39
-				__( 'WordLift detected that <b>Pods – Custom Content Types and Fields</b> is deactivated.', 'wordlift' ),
40
-				__( 'Reactivate', 'wordlift' )
41
-			);
42
-
43
-			return;
44
-		}
45
-	}
46
-
47
-	private function display_notice( $message, $button_text ) {
48
-
49
-		$kses_options                 = array(
50
-			'p'      => array(),
51
-			'b'      => array(),
52
-			'button' => array(
53
-				'class'   => array(),
54
-				'onclick' => array(),
55
-			),
56
-		);
57
-		$installation_success_message = __(
58
-			'<p>WordLift: <b>Pods – Custom Content Types and Fields</b> plugin installed and activated.</p>', // phpcs:ignore WordPress.WP.I18n.NoHtmlWrappedStrings
59
-			'wordlift'
60
-		);
61
-
62
-		$installing_message          = __( 'Installing', 'wordlift' ) . ' <span class="spinner is-active"></span>';
63
-		$installation_failed_message = '<p>' .
64
-			__( 'Wordlift: Pods – Custom Content Types and Fields installation failed, please retry or contact [email protected]', 'wordlift' )
65
-			. '</p><button class="button action" onclick="wordliftInstallPods(this)">'
66
-			. __( 'Retry', 'wordlift' )
67
-			. '</button>';
68
-		?>
9
+    /**
10
+     * @var Plugin
11
+     */
12
+    private $pods_plugin;
13
+
14
+    public function __construct( Plugin $plugin ) {
15
+        $this->pods_plugin = $plugin;
16
+    }
17
+
18
+    public function register_hooks() {
19
+        add_action( 'wl_metabox_before_html', array( $this, 'admin_notices' ) );
20
+    }
21
+
22
+    public function admin_notices() {
23
+
24
+        /**
25
+         * When pods not installed or activated then the notice should appear.
26
+         */
27
+        if ( ! $this->pods_plugin->is_plugin_installed() ) {
28
+            $this->display_notice(
29
+                __( 'WordLift detected that <b>Pods – Custom Content Types and Fields</b> is not installed.', 'wordlift' ),
30
+                __( 'Reinstall & Activate', 'wordlift' )
31
+            );
32
+
33
+            // Dont display notice.
34
+            return;
35
+        }
36
+
37
+        if ( ! $this->pods_plugin->is_plugin_activated() ) {
38
+            $this->display_notice(
39
+                __( 'WordLift detected that <b>Pods – Custom Content Types and Fields</b> is deactivated.', 'wordlift' ),
40
+                __( 'Reactivate', 'wordlift' )
41
+            );
42
+
43
+            return;
44
+        }
45
+    }
46
+
47
+    private function display_notice( $message, $button_text ) {
48
+
49
+        $kses_options                 = array(
50
+            'p'      => array(),
51
+            'b'      => array(),
52
+            'button' => array(
53
+                'class'   => array(),
54
+                'onclick' => array(),
55
+            ),
56
+        );
57
+        $installation_success_message = __(
58
+            '<p>WordLift: <b>Pods – Custom Content Types and Fields</b> plugin installed and activated.</p>', // phpcs:ignore WordPress.WP.I18n.NoHtmlWrappedStrings
59
+            'wordlift'
60
+        );
61
+
62
+        $installing_message          = __( 'Installing', 'wordlift' ) . ' <span class="spinner is-active"></span>';
63
+        $installation_failed_message = '<p>' .
64
+            __( 'Wordlift: Pods – Custom Content Types and Fields installation failed, please retry or contact [email protected]', 'wordlift' )
65
+            . '</p><button class="button action" onclick="wordliftInstallPods(this)">'
66
+            . __( 'Retry', 'wordlift' )
67
+            . '</button>';
68
+        ?>
69 69
 
70 70
 		<script>
71 71
 			window.addEventListener("load", function () {
@@ -100,5 +100,5 @@  discard block
 block discarded – undo
100 100
 			<br/>
101 101
 		</div>
102 102
 		<?php
103
-	}
103
+    }
104 104
 }
Please login to merge, or discard this patch.
src/wordlift/metabox/class-wl-abstract-metabox.php 2 patches
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -16,385 +16,385 @@
 block discarded – undo
16 16
  * @subpackage Wordlift/admin/WL_Metabox
17 17
  */
18 18
 class Wl_Abstract_Metabox {
19
-	/**
20
-	 * The metabox custom fields for the current {@link WP_Post}.
21
-	 *
22
-	 * @since  3.1.0
23
-	 * @access public
24
-	 * @var array $fields The metabox custom fields.
25
-	 */
26
-	public $fields;
27
-
28
-	/**
29
-	 * A {@link Wordlift_Log_Service} instance.
30
-	 *
31
-	 * @since 3.15.4
32
-	 *
33
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
34
-	 */
35
-	private $log;
36
-
37
-	/**
38
-	 * WL_Metabox constructor.
39
-	 *
40
-	 * @since 3.1.0
41
-	 */
42
-	public function __construct() {
43
-
44
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
45
-	}
46
-
47
-	/**
48
-	 * Add a callback to print the metabox in page.
49
-	 * WordPress will fire the $this->html() callback at the right time.
50
-	 */
51
-	public function add_main_metabox() {
52
-
53
-		// Build the fields we need to print.
54
-		$this->instantiate_fields( get_the_ID(), Object_Type_Enum::POST );
55
-
56
-		// Bailout if there are no actual fields, we do not need a metabox in that case.
57
-		if ( empty( $this->fields ) ) {
58
-			return;
59
-		}
60
-
61
-		// Add main metabox (will print also the inner fields).
62
-		$id    = uniqid( 'wl-metabox-' );
63
-		$title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
64
-
65
-		// WordPress 4.2 do not accept an array of screens as parameter, have to do be explicit.
66
-		foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $screen ) {
67
-			add_meta_box(
68
-				$id,
69
-				esc_html( $title ),
70
-				array(
71
-					$this,
72
-					'html',
73
-				),
74
-				$screen,
75
-				'normal',
76
-				'high'
77
-			);
78
-		}
79
-
80
-		// Add filter to change the metabox CSS class.
81
-		//
82
-		// @since 3.20.0 Since we support post types other than `entity` for entities, we need to set the `screen`
83
-		// dynamically according to the `get_current_screen()` function.
84
-		$current_screen = get_current_screen();
85
-		$screen         = $current_screen ? $current_screen->post_type : 'entity';
86
-		add_filter( "postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class' );
87
-
88
-	}
89
-
90
-	/**
91
-	 * Render the metabox html.
92
-	 *
93
-	 * @since 3.1.0
94
-	 */
95
-	public function html() {
96
-
97
-		// HTML Code Before MetaBox Content.
98
-		do_action( 'wl_metabox_before_html' );
99
-
100
-		// Loop over the fields.
101
-		foreach ( $this->fields as $field ) {
102
-
103
-			// load data from DB (values will be available in $field->data).
104
-			$field->get_data();
105
-
106
-			// print field HTML (nonce included).
107
-			echo $field->html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaping happens in `$field->html()`.
108
-		}
109
-
110
-	}
111
-
112
-	/**
113
-	 * Read the WL <-> Schema mapping and build the Fields for the entity being edited.
114
-	 *
115
-	 * Note: the first function that calls this method will instantiate the fields.
116
-	 * Why it isn't called from the constructor? Because we need to hook this process as late as possible.
117
-	 *
118
-	 * @param int                   $id | $term_id The post id or term id.
119
-	 *
120
-	 * @param $type int Post or Term
121
-	 *
122
-	 * @since 3.1.0
123
-	 */
124
-	public function instantiate_fields( $id, $type ) {
125
-
126
-		$this->log->trace( "Instantiating fields for entity post $id..." );
127
-
128
-		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
129
-		if ( isset( $this->fields ) ) {
130
-			return;
131
-		}
132
-		if ( Object_Type_Enum::POST === $type ) {
133
-			$entity_type = wl_entity_taxonomy_get_custom_fields( $id );
134
-		} elseif ( Object_Type_Enum::TERM === $type ) {
135
-			$term_entity_types = get_term_meta( $id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
136
-			$term_entity_types = array_map(
137
-				function ( $term ) {
138
-					return get_term_by(
139
-						'slug',
140
-						$term,
141
-						Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME
142
-					);
143
-				},
144
-				$term_entity_types
145
-			);
146
-			$entity_type       = wl_get_custom_fields_by_entity_type( $term_entity_types );
147
-		}
148
-		if ( isset( $entity_type ) ) {
149
-
150
-			/*
19
+    /**
20
+     * The metabox custom fields for the current {@link WP_Post}.
21
+     *
22
+     * @since  3.1.0
23
+     * @access public
24
+     * @var array $fields The metabox custom fields.
25
+     */
26
+    public $fields;
27
+
28
+    /**
29
+     * A {@link Wordlift_Log_Service} instance.
30
+     *
31
+     * @since 3.15.4
32
+     *
33
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
34
+     */
35
+    private $log;
36
+
37
+    /**
38
+     * WL_Metabox constructor.
39
+     *
40
+     * @since 3.1.0
41
+     */
42
+    public function __construct() {
43
+
44
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
45
+    }
46
+
47
+    /**
48
+     * Add a callback to print the metabox in page.
49
+     * WordPress will fire the $this->html() callback at the right time.
50
+     */
51
+    public function add_main_metabox() {
52
+
53
+        // Build the fields we need to print.
54
+        $this->instantiate_fields( get_the_ID(), Object_Type_Enum::POST );
55
+
56
+        // Bailout if there are no actual fields, we do not need a metabox in that case.
57
+        if ( empty( $this->fields ) ) {
58
+            return;
59
+        }
60
+
61
+        // Add main metabox (will print also the inner fields).
62
+        $id    = uniqid( 'wl-metabox-' );
63
+        $title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
64
+
65
+        // WordPress 4.2 do not accept an array of screens as parameter, have to do be explicit.
66
+        foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $screen ) {
67
+            add_meta_box(
68
+                $id,
69
+                esc_html( $title ),
70
+                array(
71
+                    $this,
72
+                    'html',
73
+                ),
74
+                $screen,
75
+                'normal',
76
+                'high'
77
+            );
78
+        }
79
+
80
+        // Add filter to change the metabox CSS class.
81
+        //
82
+        // @since 3.20.0 Since we support post types other than `entity` for entities, we need to set the `screen`
83
+        // dynamically according to the `get_current_screen()` function.
84
+        $current_screen = get_current_screen();
85
+        $screen         = $current_screen ? $current_screen->post_type : 'entity';
86
+        add_filter( "postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class' );
87
+
88
+    }
89
+
90
+    /**
91
+     * Render the metabox html.
92
+     *
93
+     * @since 3.1.0
94
+     */
95
+    public function html() {
96
+
97
+        // HTML Code Before MetaBox Content.
98
+        do_action( 'wl_metabox_before_html' );
99
+
100
+        // Loop over the fields.
101
+        foreach ( $this->fields as $field ) {
102
+
103
+            // load data from DB (values will be available in $field->data).
104
+            $field->get_data();
105
+
106
+            // print field HTML (nonce included).
107
+            echo $field->html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaping happens in `$field->html()`.
108
+        }
109
+
110
+    }
111
+
112
+    /**
113
+     * Read the WL <-> Schema mapping and build the Fields for the entity being edited.
114
+     *
115
+     * Note: the first function that calls this method will instantiate the fields.
116
+     * Why it isn't called from the constructor? Because we need to hook this process as late as possible.
117
+     *
118
+     * @param int                   $id | $term_id The post id or term id.
119
+     *
120
+     * @param $type int Post or Term
121
+     *
122
+     * @since 3.1.0
123
+     */
124
+    public function instantiate_fields( $id, $type ) {
125
+
126
+        $this->log->trace( "Instantiating fields for entity post $id..." );
127
+
128
+        // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
129
+        if ( isset( $this->fields ) ) {
130
+            return;
131
+        }
132
+        if ( Object_Type_Enum::POST === $type ) {
133
+            $entity_type = wl_entity_taxonomy_get_custom_fields( $id );
134
+        } elseif ( Object_Type_Enum::TERM === $type ) {
135
+            $term_entity_types = get_term_meta( $id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
136
+            $term_entity_types = array_map(
137
+                function ( $term ) {
138
+                    return get_term_by(
139
+                        'slug',
140
+                        $term,
141
+                        Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME
142
+                    );
143
+                },
144
+                $term_entity_types
145
+            );
146
+            $entity_type       = wl_get_custom_fields_by_entity_type( $term_entity_types );
147
+        }
148
+        if ( isset( $entity_type ) ) {
149
+
150
+            /*
151 151
 			 * Might not have any relevant meta box field, for example for articles,
152 152
 			 * therefor make sure fields are at least an empty array to help the considered
153 153
 			 * in other functions using it.
154 154
 			 */
155
-			$this->fields = array();
155
+            $this->fields = array();
156 156
 
157
-			/**
158
-			 * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
159
-			 * We must divide fields in two groups:
160
-			 * - simple: accept values for one property
161
-			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
162
-			 */
163
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
164
-			$simple_metaboxes  = $metaboxes[0];
165
-			$grouped_metaboxes = $metaboxes[1];
166
-
167
-			// Loop over simple entity properties.
168
-			foreach ( $simple_metaboxes as $key => $property ) {
169
-
170
-				// Info passed to the metabox.
171
-				$info         = array();
172
-				$info[ $key ] = $property;
157
+            /**
158
+             * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
159
+             * We must divide fields in two groups:
160
+             * - simple: accept values for one property
161
+             * - grouped: accept values for more properties, or for one property that needs a specific metabox.
162
+             */
163
+            $metaboxes         = $this->group_properties_by_input_field( $entity_type );
164
+            $simple_metaboxes  = $metaboxes[0];
165
+            $grouped_metaboxes = $metaboxes[1];
173 166
 
174
-				// Build the requested field as WL_Metabox_Field_ object.
175
-				$this->add_field( $info, false, $type, $id );
167
+            // Loop over simple entity properties.
168
+            foreach ( $simple_metaboxes as $key => $property ) {
176 169
 
177
-			}
170
+                // Info passed to the metabox.
171
+                $info         = array();
172
+                $info[ $key ] = $property;
178 173
 
179
-			// Loop over grouped properties.
180
-			foreach ( $grouped_metaboxes as $key => $property ) {
174
+                // Build the requested field as WL_Metabox_Field_ object.
175
+                $this->add_field( $info, false, $type, $id );
181 176
 
182
-				// Info passed to the metabox.
183
-				$info         = array();
184
-				$info[ $key ] = $property;
177
+            }
185 178
 
186
-				// Build the requested field group as WL_Metabox_Field_ object.
187
-				$this->add_field( $info, true, $type, $id );
179
+            // Loop over grouped properties.
180
+            foreach ( $grouped_metaboxes as $key => $property ) {
188 181
 
189
-			}
190
-		}
191
-
192
-	}
182
+                // Info passed to the metabox.
183
+                $info         = array();
184
+                $info[ $key ] = $property;
193 185
 
194
-	/**
195
-	 * Separates metaboxes in simple and grouped.
196
-	 *
197
-	 * @param array $custom_fields Information on the entity type.
198
-	 *
199
-	 * @return array
200
-	 */
201
-	public function group_properties_by_input_field( $custom_fields ) {
202
-
203
-		$simple_properties  = array();
204
-		$grouped_properties = array();
205
-
206
-		// Loop over possible entity properties.
207
-		foreach ( $custom_fields as $key => $property ) {
208
-
209
-			// Check presence of predicate and type.
210
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
211
-
212
-				// Check if input_field is defined.
213
-				if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) {
214
-
215
-					$grouped_key = $property['input_field'];
216
-
217
-					// Update list of grouped properties.
218
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
219
-
220
-				} else {
221
-
222
-					// input_field not defined, add simple metabox.
223
-					$simple_properties[ $key ] = $property;
224
-				}
225
-			}
226
-		}
227
-
228
-		return array( $simple_properties, $grouped_properties );
229
-	}
230
-
231
-	/**
232
-	 * Add a Field to the current Metabox, based on the description of the Field.
233
-	 * This method is a rude factory for Field objects.
234
-	 *
235
-	 * @param array $args The field's information.
236
-	 * @param bool  $grouped Flag to distinguish between simple and grouped fields.
237
-	 * @param int   $type Post or Term, based on the correct decorator would be selected.
238
-	 * @param int   $id Identifier for the type.
239
-	 */
240
-	public function add_field( $args, $grouped, $type, $id ) {
241
-
242
-		if ( $grouped ) {
243
-
244
-			// Special fields (sameas, coordinates, etc.).
245
-			//
246
-			// Build Field with a custom class (e.g. WL_Metabox_Field_date).
247
-			$field_class = 'Wl_Metabox_Field_' . key( $args );
248
-
249
-		} else {
250
-
251
-			// Simple fields (string, uri, boolean, etc.).
252
-			//
253
-			// Which field? We want to use the class that is specific for the field.
254
-			$meta      = key( $args );
255
-			$this_meta = $args[ $meta ];
256
-
257
-			// If the field declares what metabox it wants, use that one.
258
-			if ( isset( $this_meta['metabox']['class'] ) ) {
259
-
260
-				$field_class = $this_meta['metabox']['class'];
261
-
262
-			} elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) {
263
-
264
-				// TODO: all fields should explicitly declare the required WL_Metabox.
265
-				// When they will remove this.
266
-				//
267
-				// Use default Wl_Metabox_Field (manages strings).
268
-				$field_class = 'Wl_Metabox_Field';
269
-
270
-			} else {
271
-
272
-				// TODO: all fields should explicitly declare the required WL_Metabox.
273
-				// When they will remove this.
274
-				//
275
-				// Build Field with a custom class (e.g. Wl_Metabox_Field_date).
276
-				$field_class = 'Wl_Metabox_Field_' . $this_meta['type'];
277
-
278
-			}
279
-		}
280
-		/**
281
-		 * @since 3.31.6
282
-		 * Add namespace to initialize class.
283
-		 */
284
-		/**
285
-		 * @since 3.31.6
286
-		 * Add namespace to initialize class.
287
-		 */
288
-		if ( substr( $field_class, 0, 1 ) !== '\\' ) {
289
-			$field_class = 'Wordlift\Metabox\Field\\' . $field_class;
290
-			// End if().
291
-		}
292
-
293
-		if ( class_exists( $field_class ) ) {
294
-			// Get decorator and use it as wrapper for save_data and get_data methods.
295
-			$instance = new $field_class( $args, $id, $type );
296
-			// Call apropriate constructor (e.g. Wl_Metabox_Field... ).
297
-			$this->fields[] = $instance;
298
-		}
299
-
300
-	}
301
-
302
-	/**
303
-	 * Save the form data for the specified entity {@link WP_Post}'s id.
304
-	 *
305
-	 * @param int                   $id The entity's {@link WP_Post}'s id.
306
-	 *
307
-	 * We're being called from WP `save_post` hook, we don't need to check the nonce.
308
-	 *
309
-	 * @param $type int Post or term
310
-	 *
311
-	 * @since 3.5.4
312
-	 */
313
-	public function save_form_data( $id, $type ) {
314
-
315
-		$this->log->trace( "Saving form data for entity post $id..." );
316
-
317
-		// Skip saving if the save is called for a different post.
318
-		// phpcs:ignore WordPress.Security.NonceVerification.Missing
319
-		if ( isset( $_POST['post_ID'] ) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type ) {
320
-			$this->log->debug( '`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.' );
321
-			return;
322
-		}
323
-
324
-		// Build Field objects.
325
-		$this->instantiate_fields( $id, $type );
326
-
327
-		// Check if WL metabox form was posted.
328
-		// phpcs:ignore WordPress.Security.NonceVerification.Missing
329
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
330
-			$this->log->debug( '`wl_metaboxes`, skipping...' );
331
-
332
-			return;
333
-		}
334
-
335
-		// phpcs:ignore WordPress.Security.NonceVerification.Missing
336
-		$posted_data = filter_var_array( $_POST, array( 'wl_metaboxes' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) );
337
-		$posted_data = $posted_data['wl_metaboxes'];
338
-		foreach ( $this->fields as $field ) {
339
-
340
-			// Verify nonce.
341
-			$valid_nonce = $field->verify_nonce();
342
-
343
-			if ( $valid_nonce ) {
344
-				$field_name = $field->meta_name;
345
-				// Each Filed only deals with its values.
346
-				if ( isset( $posted_data[ $field_name ] ) ) {
347
-
348
-					$values = $posted_data[ $field_name ];
349
-					if ( ! is_array( $values ) ) {
350
-						$values = array( $values );
351
-					}
352
-					// Save data permanently
353
-					$field->save_data( $values );
354
-				}
355
-			}
356
-		}
357
-
358
-		/**
359
-		 * Filter: 'wl_save_form_pre_push_entity' - Allow to hook right
360
-		 * before the triples are pushed to the linked dataset.
361
-		 *
362
-		 * @param int $id The entity id.
363
-		 * @param int $id The post data.
364
-		 *
365
-		 * @since  3.18.2
366
-		 */
367
-		// phpcs:ignore WordPress.Security.NonceVerification.Missing
368
-		do_action( 'wl_save_form_pre_push_entity', $id, $_POST );
369
-
370
-	}
371
-
372
-	/**
373
-	 * Enqueue scripts and styles.
374
-	 *
375
-	 * @since 3.0.0
376
-	 */
377
-	public function enqueue_scripts_and_styles() {
378
-
379
-		// Use the minified version if PW_DEBUG isn't set.
380
-		$min = ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ? '.min' : '';
381
-
382
-		// Load the jquery-ui-timepicker-addon library.
383
-		wp_enqueue_style( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6' );
384
-		wp_enqueue_script( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.js", array( 'jquery' ), '3.0.6', true );
385
-
386
-		wl_enqueue_leaflet();
387
-
388
-		// Add AJAX autocomplete to facilitate metabox editing.
389
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false );
390
-		wp_localize_script(
391
-			'wl-entity-metabox-utility',
392
-			'wlEntityMetaboxParams',
393
-			array(
394
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
395
-				'action'   => 'entity_by_title',
396
-			)
397
-		);
398
-
399
-	}
186
+                // Build the requested field group as WL_Metabox_Field_ object.
187
+                $this->add_field( $info, true, $type, $id );
188
+
189
+            }
190
+        }
191
+
192
+    }
193
+
194
+    /**
195
+     * Separates metaboxes in simple and grouped.
196
+     *
197
+     * @param array $custom_fields Information on the entity type.
198
+     *
199
+     * @return array
200
+     */
201
+    public function group_properties_by_input_field( $custom_fields ) {
202
+
203
+        $simple_properties  = array();
204
+        $grouped_properties = array();
205
+
206
+        // Loop over possible entity properties.
207
+        foreach ( $custom_fields as $key => $property ) {
208
+
209
+            // Check presence of predicate and type.
210
+            if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
211
+
212
+                // Check if input_field is defined.
213
+                if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) {
214
+
215
+                    $grouped_key = $property['input_field'];
216
+
217
+                    // Update list of grouped properties.
218
+                    $grouped_properties[ $grouped_key ][ $key ] = $property;
219
+
220
+                } else {
221
+
222
+                    // input_field not defined, add simple metabox.
223
+                    $simple_properties[ $key ] = $property;
224
+                }
225
+            }
226
+        }
227
+
228
+        return array( $simple_properties, $grouped_properties );
229
+    }
230
+
231
+    /**
232
+     * Add a Field to the current Metabox, based on the description of the Field.
233
+     * This method is a rude factory for Field objects.
234
+     *
235
+     * @param array $args The field's information.
236
+     * @param bool  $grouped Flag to distinguish between simple and grouped fields.
237
+     * @param int   $type Post or Term, based on the correct decorator would be selected.
238
+     * @param int   $id Identifier for the type.
239
+     */
240
+    public function add_field( $args, $grouped, $type, $id ) {
241
+
242
+        if ( $grouped ) {
243
+
244
+            // Special fields (sameas, coordinates, etc.).
245
+            //
246
+            // Build Field with a custom class (e.g. WL_Metabox_Field_date).
247
+            $field_class = 'Wl_Metabox_Field_' . key( $args );
248
+
249
+        } else {
250
+
251
+            // Simple fields (string, uri, boolean, etc.).
252
+            //
253
+            // Which field? We want to use the class that is specific for the field.
254
+            $meta      = key( $args );
255
+            $this_meta = $args[ $meta ];
256
+
257
+            // If the field declares what metabox it wants, use that one.
258
+            if ( isset( $this_meta['metabox']['class'] ) ) {
259
+
260
+                $field_class = $this_meta['metabox']['class'];
261
+
262
+            } elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) {
263
+
264
+                // TODO: all fields should explicitly declare the required WL_Metabox.
265
+                // When they will remove this.
266
+                //
267
+                // Use default Wl_Metabox_Field (manages strings).
268
+                $field_class = 'Wl_Metabox_Field';
269
+
270
+            } else {
271
+
272
+                // TODO: all fields should explicitly declare the required WL_Metabox.
273
+                // When they will remove this.
274
+                //
275
+                // Build Field with a custom class (e.g. Wl_Metabox_Field_date).
276
+                $field_class = 'Wl_Metabox_Field_' . $this_meta['type'];
277
+
278
+            }
279
+        }
280
+        /**
281
+         * @since 3.31.6
282
+         * Add namespace to initialize class.
283
+         */
284
+        /**
285
+         * @since 3.31.6
286
+         * Add namespace to initialize class.
287
+         */
288
+        if ( substr( $field_class, 0, 1 ) !== '\\' ) {
289
+            $field_class = 'Wordlift\Metabox\Field\\' . $field_class;
290
+            // End if().
291
+        }
292
+
293
+        if ( class_exists( $field_class ) ) {
294
+            // Get decorator and use it as wrapper for save_data and get_data methods.
295
+            $instance = new $field_class( $args, $id, $type );
296
+            // Call apropriate constructor (e.g. Wl_Metabox_Field... ).
297
+            $this->fields[] = $instance;
298
+        }
299
+
300
+    }
301
+
302
+    /**
303
+     * Save the form data for the specified entity {@link WP_Post}'s id.
304
+     *
305
+     * @param int                   $id The entity's {@link WP_Post}'s id.
306
+     *
307
+     * We're being called from WP `save_post` hook, we don't need to check the nonce.
308
+     *
309
+     * @param $type int Post or term
310
+     *
311
+     * @since 3.5.4
312
+     */
313
+    public function save_form_data( $id, $type ) {
314
+
315
+        $this->log->trace( "Saving form data for entity post $id..." );
316
+
317
+        // Skip saving if the save is called for a different post.
318
+        // phpcs:ignore WordPress.Security.NonceVerification.Missing
319
+        if ( isset( $_POST['post_ID'] ) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type ) {
320
+            $this->log->debug( '`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.' );
321
+            return;
322
+        }
323
+
324
+        // Build Field objects.
325
+        $this->instantiate_fields( $id, $type );
326
+
327
+        // Check if WL metabox form was posted.
328
+        // phpcs:ignore WordPress.Security.NonceVerification.Missing
329
+        if ( ! isset( $_POST['wl_metaboxes'] ) ) {
330
+            $this->log->debug( '`wl_metaboxes`, skipping...' );
331
+
332
+            return;
333
+        }
334
+
335
+        // phpcs:ignore WordPress.Security.NonceVerification.Missing
336
+        $posted_data = filter_var_array( $_POST, array( 'wl_metaboxes' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) );
337
+        $posted_data = $posted_data['wl_metaboxes'];
338
+        foreach ( $this->fields as $field ) {
339
+
340
+            // Verify nonce.
341
+            $valid_nonce = $field->verify_nonce();
342
+
343
+            if ( $valid_nonce ) {
344
+                $field_name = $field->meta_name;
345
+                // Each Filed only deals with its values.
346
+                if ( isset( $posted_data[ $field_name ] ) ) {
347
+
348
+                    $values = $posted_data[ $field_name ];
349
+                    if ( ! is_array( $values ) ) {
350
+                        $values = array( $values );
351
+                    }
352
+                    // Save data permanently
353
+                    $field->save_data( $values );
354
+                }
355
+            }
356
+        }
357
+
358
+        /**
359
+         * Filter: 'wl_save_form_pre_push_entity' - Allow to hook right
360
+         * before the triples are pushed to the linked dataset.
361
+         *
362
+         * @param int $id The entity id.
363
+         * @param int $id The post data.
364
+         *
365
+         * @since  3.18.2
366
+         */
367
+        // phpcs:ignore WordPress.Security.NonceVerification.Missing
368
+        do_action( 'wl_save_form_pre_push_entity', $id, $_POST );
369
+
370
+    }
371
+
372
+    /**
373
+     * Enqueue scripts and styles.
374
+     *
375
+     * @since 3.0.0
376
+     */
377
+    public function enqueue_scripts_and_styles() {
378
+
379
+        // Use the minified version if PW_DEBUG isn't set.
380
+        $min = ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ? '.min' : '';
381
+
382
+        // Load the jquery-ui-timepicker-addon library.
383
+        wp_enqueue_style( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6' );
384
+        wp_enqueue_script( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.js", array( 'jquery' ), '3.0.6', true );
385
+
386
+        wl_enqueue_leaflet();
387
+
388
+        // Add AJAX autocomplete to facilitate metabox editing.
389
+        wp_enqueue_script( 'wl-entity-metabox-utility', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false );
390
+        wp_localize_script(
391
+            'wl-entity-metabox-utility',
392
+            'wlEntityMetaboxParams',
393
+            array(
394
+                'ajax_url' => admin_url( 'admin-ajax.php' ),
395
+                'action'   => 'entity_by_title',
396
+            )
397
+        );
398
+
399
+    }
400 400
 }
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	public function __construct() {
43 43
 
44
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
44
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
45 45
 	}
46 46
 
47 47
 	/**
@@ -51,22 +51,22 @@  discard block
 block discarded – undo
51 51
 	public function add_main_metabox() {
52 52
 
53 53
 		// Build the fields we need to print.
54
-		$this->instantiate_fields( get_the_ID(), Object_Type_Enum::POST );
54
+		$this->instantiate_fields(get_the_ID(), Object_Type_Enum::POST);
55 55
 
56 56
 		// Bailout if there are no actual fields, we do not need a metabox in that case.
57
-		if ( empty( $this->fields ) ) {
57
+		if (empty($this->fields)) {
58 58
 			return;
59 59
 		}
60 60
 
61 61
 		// Add main metabox (will print also the inner fields).
62
-		$id    = uniqid( 'wl-metabox-' );
63
-		$title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
62
+		$id    = uniqid('wl-metabox-');
63
+		$title = get_the_title().' '.__('properties', 'wordlift');
64 64
 
65 65
 		// WordPress 4.2 do not accept an array of screens as parameter, have to do be explicit.
66
-		foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $screen ) {
66
+		foreach (Wordlift_Entity_Service::valid_entity_post_types() as $screen) {
67 67
 			add_meta_box(
68 68
 				$id,
69
-				esc_html( $title ),
69
+				esc_html($title),
70 70
 				array(
71 71
 					$this,
72 72
 					'html',
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 		// dynamically according to the `get_current_screen()` function.
84 84
 		$current_screen = get_current_screen();
85 85
 		$screen         = $current_screen ? $current_screen->post_type : 'entity';
86
-		add_filter( "postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class' );
86
+		add_filter("postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class');
87 87
 
88 88
 	}
89 89
 
@@ -95,10 +95,10 @@  discard block
 block discarded – undo
95 95
 	public function html() {
96 96
 
97 97
 		// HTML Code Before MetaBox Content.
98
-		do_action( 'wl_metabox_before_html' );
98
+		do_action('wl_metabox_before_html');
99 99
 
100 100
 		// Loop over the fields.
101
-		foreach ( $this->fields as $field ) {
101
+		foreach ($this->fields as $field) {
102 102
 
103 103
 			// load data from DB (values will be available in $field->data).
104 104
 			$field->get_data();
@@ -121,20 +121,20 @@  discard block
 block discarded – undo
121 121
 	 *
122 122
 	 * @since 3.1.0
123 123
 	 */
124
-	public function instantiate_fields( $id, $type ) {
124
+	public function instantiate_fields($id, $type) {
125 125
 
126
-		$this->log->trace( "Instantiating fields for entity post $id..." );
126
+		$this->log->trace("Instantiating fields for entity post $id...");
127 127
 
128 128
 		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
129
-		if ( isset( $this->fields ) ) {
129
+		if (isset($this->fields)) {
130 130
 			return;
131 131
 		}
132
-		if ( Object_Type_Enum::POST === $type ) {
133
-			$entity_type = wl_entity_taxonomy_get_custom_fields( $id );
134
-		} elseif ( Object_Type_Enum::TERM === $type ) {
135
-			$term_entity_types = get_term_meta( $id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
132
+		if (Object_Type_Enum::POST === $type) {
133
+			$entity_type = wl_entity_taxonomy_get_custom_fields($id);
134
+		} elseif (Object_Type_Enum::TERM === $type) {
135
+			$term_entity_types = get_term_meta($id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
136 136
 			$term_entity_types = array_map(
137
-				function ( $term ) {
137
+				function($term) {
138 138
 					return get_term_by(
139 139
 						'slug',
140 140
 						$term,
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
 				},
144 144
 				$term_entity_types
145 145
 			);
146
-			$entity_type       = wl_get_custom_fields_by_entity_type( $term_entity_types );
146
+			$entity_type = wl_get_custom_fields_by_entity_type($term_entity_types);
147 147
 		}
148
-		if ( isset( $entity_type ) ) {
148
+		if (isset($entity_type)) {
149 149
 
150 150
 			/*
151 151
 			 * Might not have any relevant meta box field, for example for articles,
@@ -160,31 +160,31 @@  discard block
 block discarded – undo
160 160
 			 * - simple: accept values for one property
161 161
 			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
162 162
 			 */
163
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
163
+			$metaboxes         = $this->group_properties_by_input_field($entity_type);
164 164
 			$simple_metaboxes  = $metaboxes[0];
165 165
 			$grouped_metaboxes = $metaboxes[1];
166 166
 
167 167
 			// Loop over simple entity properties.
168
-			foreach ( $simple_metaboxes as $key => $property ) {
168
+			foreach ($simple_metaboxes as $key => $property) {
169 169
 
170 170
 				// Info passed to the metabox.
171 171
 				$info         = array();
172
-				$info[ $key ] = $property;
172
+				$info[$key] = $property;
173 173
 
174 174
 				// Build the requested field as WL_Metabox_Field_ object.
175
-				$this->add_field( $info, false, $type, $id );
175
+				$this->add_field($info, false, $type, $id);
176 176
 
177 177
 			}
178 178
 
179 179
 			// Loop over grouped properties.
180
-			foreach ( $grouped_metaboxes as $key => $property ) {
180
+			foreach ($grouped_metaboxes as $key => $property) {
181 181
 
182 182
 				// Info passed to the metabox.
183 183
 				$info         = array();
184
-				$info[ $key ] = $property;
184
+				$info[$key] = $property;
185 185
 
186 186
 				// Build the requested field group as WL_Metabox_Field_ object.
187
-				$this->add_field( $info, true, $type, $id );
187
+				$this->add_field($info, true, $type, $id);
188 188
 
189 189
 			}
190 190
 		}
@@ -198,34 +198,34 @@  discard block
 block discarded – undo
198 198
 	 *
199 199
 	 * @return array
200 200
 	 */
201
-	public function group_properties_by_input_field( $custom_fields ) {
201
+	public function group_properties_by_input_field($custom_fields) {
202 202
 
203 203
 		$simple_properties  = array();
204 204
 		$grouped_properties = array();
205 205
 
206 206
 		// Loop over possible entity properties.
207
-		foreach ( $custom_fields as $key => $property ) {
207
+		foreach ($custom_fields as $key => $property) {
208 208
 
209 209
 			// Check presence of predicate and type.
210
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
210
+			if (isset($property['predicate']) && isset($property['type'])) {
211 211
 
212 212
 				// Check if input_field is defined.
213
-				if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) {
213
+				if (isset($property['input_field']) && '' !== $property['input_field']) {
214 214
 
215 215
 					$grouped_key = $property['input_field'];
216 216
 
217 217
 					// Update list of grouped properties.
218
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
218
+					$grouped_properties[$grouped_key][$key] = $property;
219 219
 
220 220
 				} else {
221 221
 
222 222
 					// input_field not defined, add simple metabox.
223
-					$simple_properties[ $key ] = $property;
223
+					$simple_properties[$key] = $property;
224 224
 				}
225 225
 			}
226 226
 		}
227 227
 
228
-		return array( $simple_properties, $grouped_properties );
228
+		return array($simple_properties, $grouped_properties);
229 229
 	}
230 230
 
231 231
 	/**
@@ -237,29 +237,29 @@  discard block
 block discarded – undo
237 237
 	 * @param int   $type Post or Term, based on the correct decorator would be selected.
238 238
 	 * @param int   $id Identifier for the type.
239 239
 	 */
240
-	public function add_field( $args, $grouped, $type, $id ) {
240
+	public function add_field($args, $grouped, $type, $id) {
241 241
 
242
-		if ( $grouped ) {
242
+		if ($grouped) {
243 243
 
244 244
 			// Special fields (sameas, coordinates, etc.).
245 245
 			//
246 246
 			// Build Field with a custom class (e.g. WL_Metabox_Field_date).
247
-			$field_class = 'Wl_Metabox_Field_' . key( $args );
247
+			$field_class = 'Wl_Metabox_Field_'.key($args);
248 248
 
249 249
 		} else {
250 250
 
251 251
 			// Simple fields (string, uri, boolean, etc.).
252 252
 			//
253 253
 			// Which field? We want to use the class that is specific for the field.
254
-			$meta      = key( $args );
255
-			$this_meta = $args[ $meta ];
254
+			$meta      = key($args);
255
+			$this_meta = $args[$meta];
256 256
 
257 257
 			// If the field declares what metabox it wants, use that one.
258
-			if ( isset( $this_meta['metabox']['class'] ) ) {
258
+			if (isset($this_meta['metabox']['class'])) {
259 259
 
260 260
 				$field_class = $this_meta['metabox']['class'];
261 261
 
262
-			} elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) {
262
+			} elseif ( ! isset($this_meta['type']) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type']) {
263 263
 
264 264
 				// TODO: all fields should explicitly declare the required WL_Metabox.
265 265
 				// When they will remove this.
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 				// When they will remove this.
274 274
 				//
275 275
 				// Build Field with a custom class (e.g. Wl_Metabox_Field_date).
276
-				$field_class = 'Wl_Metabox_Field_' . $this_meta['type'];
276
+				$field_class = 'Wl_Metabox_Field_'.$this_meta['type'];
277 277
 
278 278
 			}
279 279
 		}
@@ -285,14 +285,14 @@  discard block
 block discarded – undo
285 285
 		 * @since 3.31.6
286 286
 		 * Add namespace to initialize class.
287 287
 		 */
288
-		if ( substr( $field_class, 0, 1 ) !== '\\' ) {
289
-			$field_class = 'Wordlift\Metabox\Field\\' . $field_class;
288
+		if (substr($field_class, 0, 1) !== '\\') {
289
+			$field_class = 'Wordlift\Metabox\Field\\'.$field_class;
290 290
 			// End if().
291 291
 		}
292 292
 
293
-		if ( class_exists( $field_class ) ) {
293
+		if (class_exists($field_class)) {
294 294
 			// Get decorator and use it as wrapper for save_data and get_data methods.
295
-			$instance = new $field_class( $args, $id, $type );
295
+			$instance = new $field_class($args, $id, $type);
296 296
 			// Call apropriate constructor (e.g. Wl_Metabox_Field... ).
297 297
 			$this->fields[] = $instance;
298 298
 		}
@@ -310,47 +310,47 @@  discard block
 block discarded – undo
310 310
 	 *
311 311
 	 * @since 3.5.4
312 312
 	 */
313
-	public function save_form_data( $id, $type ) {
313
+	public function save_form_data($id, $type) {
314 314
 
315
-		$this->log->trace( "Saving form data for entity post $id..." );
315
+		$this->log->trace("Saving form data for entity post $id...");
316 316
 
317 317
 		// Skip saving if the save is called for a different post.
318 318
 		// phpcs:ignore WordPress.Security.NonceVerification.Missing
319
-		if ( isset( $_POST['post_ID'] ) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type ) {
320
-			$this->log->debug( '`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.' );
319
+		if (isset($_POST['post_ID']) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type) {
320
+			$this->log->debug('`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.');
321 321
 			return;
322 322
 		}
323 323
 
324 324
 		// Build Field objects.
325
-		$this->instantiate_fields( $id, $type );
325
+		$this->instantiate_fields($id, $type);
326 326
 
327 327
 		// Check if WL metabox form was posted.
328 328
 		// phpcs:ignore WordPress.Security.NonceVerification.Missing
329
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
330
-			$this->log->debug( '`wl_metaboxes`, skipping...' );
329
+		if ( ! isset($_POST['wl_metaboxes'])) {
330
+			$this->log->debug('`wl_metaboxes`, skipping...');
331 331
 
332 332
 			return;
333 333
 		}
334 334
 
335 335
 		// phpcs:ignore WordPress.Security.NonceVerification.Missing
336
-		$posted_data = filter_var_array( $_POST, array( 'wl_metaboxes' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) );
336
+		$posted_data = filter_var_array($_POST, array('wl_metaboxes' => array('flags' => FILTER_REQUIRE_ARRAY)));
337 337
 		$posted_data = $posted_data['wl_metaboxes'];
338
-		foreach ( $this->fields as $field ) {
338
+		foreach ($this->fields as $field) {
339 339
 
340 340
 			// Verify nonce.
341 341
 			$valid_nonce = $field->verify_nonce();
342 342
 
343
-			if ( $valid_nonce ) {
343
+			if ($valid_nonce) {
344 344
 				$field_name = $field->meta_name;
345 345
 				// Each Filed only deals with its values.
346
-				if ( isset( $posted_data[ $field_name ] ) ) {
346
+				if (isset($posted_data[$field_name])) {
347 347
 
348
-					$values = $posted_data[ $field_name ];
349
-					if ( ! is_array( $values ) ) {
350
-						$values = array( $values );
348
+					$values = $posted_data[$field_name];
349
+					if ( ! is_array($values)) {
350
+						$values = array($values);
351 351
 					}
352 352
 					// Save data permanently
353
-					$field->save_data( $values );
353
+					$field->save_data($values);
354 354
 				}
355 355
 			}
356 356
 		}
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 		 * @since  3.18.2
366 366
 		 */
367 367
 		// phpcs:ignore WordPress.Security.NonceVerification.Missing
368
-		do_action( 'wl_save_form_pre_push_entity', $id, $_POST );
368
+		do_action('wl_save_form_pre_push_entity', $id, $_POST);
369 369
 
370 370
 	}
371 371
 
@@ -377,21 +377,21 @@  discard block
 block discarded – undo
377 377
 	public function enqueue_scripts_and_styles() {
378 378
 
379 379
 		// Use the minified version if PW_DEBUG isn't set.
380
-		$min = ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ? '.min' : '';
380
+		$min = ! defined('WP_DEBUG') || ! WP_DEBUG ? '.min' : '';
381 381
 
382 382
 		// Load the jquery-ui-timepicker-addon library.
383
-		wp_enqueue_style( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6' );
384
-		wp_enqueue_script( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.js", array( 'jquery' ), '3.0.6', true );
383
+		wp_enqueue_style('wl-flatpickr', dirname(dirname(plugin_dir_url(__FILE__)))."/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6');
384
+		wp_enqueue_script('wl-flatpickr', dirname(dirname(plugin_dir_url(__FILE__)))."/admin/js/flatpickr/flatpickr$min.js", array('jquery'), '3.0.6', true);
385 385
 
386 386
 		wl_enqueue_leaflet();
387 387
 
388 388
 		// Add AJAX autocomplete to facilitate metabox editing.
389
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false );
389
+		wp_enqueue_script('wl-entity-metabox-utility', dirname(dirname(plugin_dir_url(__FILE__))).'/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false);
390 390
 		wp_localize_script(
391 391
 			'wl-entity-metabox-utility',
392 392
 			'wlEntityMetaboxParams',
393 393
 			array(
394
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
394
+				'ajax_url' => admin_url('admin-ajax.php'),
395 395
 				'action'   => 'entity_by_title',
396 396
 			)
397 397
 		);
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-property-entity-reference.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 * @since 3.8.0
56 56
 	 */
57
-	public function __construct( $url, $id, $required = false, $type = Object_Type_Enum::POST ) {
57
+	public function __construct($url, $id, $required = false, $type = Object_Type_Enum::POST) {
58 58
 
59 59
 		$this->url      = $url;
60 60
 		$this->id       = $id;
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 *
119 119
 	 * @since 3.27.1
120 120
 	 */
121
-	public function set_required( $value ) {
121
+	public function set_required($value) {
122 122
 
123 123
 		$this->required = $value;
124 124
 
@@ -126,11 +126,11 @@  discard block
 block discarded – undo
126 126
 
127 127
 	public function to_reference() {
128 128
 
129
-		if ( Object_Type_Enum::POST === $this->type ) {
130
-			return new Post_Reference( $this->id );
129
+		if (Object_Type_Enum::POST === $this->type) {
130
+			return new Post_Reference($this->id);
131 131
 		}
132
-		if ( Object_Type_Enum::TERM === $this->type ) {
133
-			return new Term_Reference( $this->id );
132
+		if (Object_Type_Enum::TERM === $this->type) {
133
+			return new Term_Reference($this->id);
134 134
 		}
135 135
 	}
136 136
 
Please login to merge, or discard this patch.
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -20,119 +20,119 @@
 block discarded – undo
20 20
  */
21 21
 class Wordlift_Property_Entity_Reference {
22 22
 
23
-	/**
24
-	 * The URL associated with this entity reference.
25
-	 *
26
-	 * @since  3.8.0
27
-	 * @access private
28
-	 * @var string $url The URL associated with the entity reference.
29
-	 */
30
-	private $url;
31
-
32
-	/**
33
-	 * The entity post id.
34
-	 *
35
-	 * @since  3.10.0
36
-	 * @access private
37
-	 * @var int $id The entity post id.
38
-	 */
39
-	private $id;
40
-
41
-	private $required;
42
-	/**
43
-	 * @var int
44
-	 */
45
-	private $type;
46
-
47
-	/**
48
-	 * Create a Wordlift_Property_Entity_Reference instance with the provided URL.
49
-	 *
50
-	 * @param string $url The URL.
51
-	 * @param int    $id The entity post id.
52
-	 * @param bool   $required Whether this property is always required in SD output, default false.
53
-	 * @param int    $type Instance of Object_Enum_Type
54
-	 *
55
-	 * @since 3.8.0
56
-	 */
57
-	public function __construct( $url, $id, $required = false, $type = Object_Type_Enum::POST ) {
58
-
59
-		$this->url      = $url;
60
-		$this->id       = $id;
61
-		$this->required = $required;
62
-		$this->type     = $type;
63
-
64
-	}
65
-
66
-	/**
67
-	 * Return the type of the reference, one of the values in Object_Type_Enum
68
-	 *
69
-	 * @return int
70
-	 * @since 3.38.0
71
-	 */
72
-	public function get_type() {
73
-		return $this->type;
74
-	}
75
-
76
-	/**
77
-	 * Get the URL associated with this entity reference.
78
-	 *
79
-	 * @return string The URL associated with the entity reference.
80
-	 * @since 3.8.0
81
-	 */
82
-	public function get_url() {
83
-
84
-		return $this->url;
85
-	}
86
-
87
-	/**
88
-	 * Get the entity id.
89
-	 *
90
-	 * @return int The entity id.
91
-	 * @since 3.10.0
92
-	 */
93
-	public function get_id() {
94
-
95
-		return $this->id;
96
-	}
97
-
98
-	/**
99
-	 * Get the required flag for this {@link Wordlift_Property_Entity_Reference}.
100
-	 *
101
-	 * The required flag may tell converters or consumers (like {@link \Wordlift\Jsonld\Jsonld_Service} that this
102
-	 * property needs to be output to SD (JSON-LD).
103
-	 *
104
-	 * @since 3.27.1
105
-	 */
106
-	public function get_required() {
107
-
108
-		return $this->required;
109
-
110
-	}
111
-
112
-	/**
113
-	 * Set the required flag for this {@link Wordlift_Property_Entity_Reference}.
114
-	 *
115
-	 * The required flag may tell converters or consumers (like {@link \Wordlift\Jsonld\Jsonld_Service} that this
116
-	 * property needs to be output to SD (JSON-LD).
117
-	 *
118
-	 * @param bool $value
119
-	 *
120
-	 * @since 3.27.1
121
-	 */
122
-	public function set_required( $value ) {
123
-
124
-		$this->required = $value;
125
-
126
-	}
127
-
128
-	public function to_reference() {
129
-
130
-		if ( Object_Type_Enum::POST === $this->type ) {
131
-			return new Post_Reference( $this->id );
132
-		}
133
-		if ( Object_Type_Enum::TERM === $this->type ) {
134
-			return new Term_Reference( $this->id );
135
-		}
136
-	}
23
+    /**
24
+     * The URL associated with this entity reference.
25
+     *
26
+     * @since  3.8.0
27
+     * @access private
28
+     * @var string $url The URL associated with the entity reference.
29
+     */
30
+    private $url;
31
+
32
+    /**
33
+     * The entity post id.
34
+     *
35
+     * @since  3.10.0
36
+     * @access private
37
+     * @var int $id The entity post id.
38
+     */
39
+    private $id;
40
+
41
+    private $required;
42
+    /**
43
+     * @var int
44
+     */
45
+    private $type;
46
+
47
+    /**
48
+     * Create a Wordlift_Property_Entity_Reference instance with the provided URL.
49
+     *
50
+     * @param string $url The URL.
51
+     * @param int    $id The entity post id.
52
+     * @param bool   $required Whether this property is always required in SD output, default false.
53
+     * @param int    $type Instance of Object_Enum_Type
54
+     *
55
+     * @since 3.8.0
56
+     */
57
+    public function __construct( $url, $id, $required = false, $type = Object_Type_Enum::POST ) {
58
+
59
+        $this->url      = $url;
60
+        $this->id       = $id;
61
+        $this->required = $required;
62
+        $this->type     = $type;
63
+
64
+    }
65
+
66
+    /**
67
+     * Return the type of the reference, one of the values in Object_Type_Enum
68
+     *
69
+     * @return int
70
+     * @since 3.38.0
71
+     */
72
+    public function get_type() {
73
+        return $this->type;
74
+    }
75
+
76
+    /**
77
+     * Get the URL associated with this entity reference.
78
+     *
79
+     * @return string The URL associated with the entity reference.
80
+     * @since 3.8.0
81
+     */
82
+    public function get_url() {
83
+
84
+        return $this->url;
85
+    }
86
+
87
+    /**
88
+     * Get the entity id.
89
+     *
90
+     * @return int The entity id.
91
+     * @since 3.10.0
92
+     */
93
+    public function get_id() {
94
+
95
+        return $this->id;
96
+    }
97
+
98
+    /**
99
+     * Get the required flag for this {@link Wordlift_Property_Entity_Reference}.
100
+     *
101
+     * The required flag may tell converters or consumers (like {@link \Wordlift\Jsonld\Jsonld_Service} that this
102
+     * property needs to be output to SD (JSON-LD).
103
+     *
104
+     * @since 3.27.1
105
+     */
106
+    public function get_required() {
107
+
108
+        return $this->required;
109
+
110
+    }
111
+
112
+    /**
113
+     * Set the required flag for this {@link Wordlift_Property_Entity_Reference}.
114
+     *
115
+     * The required flag may tell converters or consumers (like {@link \Wordlift\Jsonld\Jsonld_Service} that this
116
+     * property needs to be output to SD (JSON-LD).
117
+     *
118
+     * @param bool $value
119
+     *
120
+     * @since 3.27.1
121
+     */
122
+    public function set_required( $value ) {
123
+
124
+        $this->required = $value;
125
+
126
+    }
127
+
128
+    public function to_reference() {
129
+
130
+        if ( Object_Type_Enum::POST === $this->type ) {
131
+            return new Post_Reference( $this->id );
132
+        }
133
+        if ( Object_Type_Enum::TERM === $this->type ) {
134
+            return new Term_Reference( $this->id );
135
+        }
136
+    }
137 137
 
138 138
 }
Please login to merge, or discard this patch.