Completed
Push — master ( c336cf...9cad87 )
by David
30:41
created
src/includes/class-wordlift-schema-service.php 2 patches
Indentation   +1651 added lines, -1651 removed lines patch added patch discarded remove patch
@@ -18,1656 +18,1656 @@
 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 'dateTime' data type name.
337
-	 *
338
-	 * @since 3.15.0
339
-	 */
340
-	const DATA_TYPE_DATE_TIME = 'dateTime';
341
-
342
-	/**
343
-	 * The 'time' data type name.
344
-	 *
345
-	 * @since 3.14.0
346
-	 */
347
-	const DATA_TYPE_DURATION = 'duration';
348
-
349
-	/**
350
-	 * The 'double' data type name.
351
-	 *
352
-	 * @since 3.1.0
353
-	 */
354
-	const DATA_TYPE_DOUBLE = 'double';
355
-
356
-	/**
357
-	 * The 'string' data type name.
358
-	 *
359
-	 * @since 3.1.0
360
-	 */
361
-	const DATA_TYPE_STRING = 'string';
362
-
363
-	/**
364
-	 * The multiline text data type name.
365
-	 *
366
-	 * @since 3.14.0
367
-	 */
368
-	const DATA_TYPE_MULTILINE = 'multiline';
369
-
370
-	/**
371
-	 * The 'integer' data type name.
372
-	 *
373
-	 * @since 3.1.0
374
-	 */
375
-	const DATA_TYPE_INTEGER = 'int';
376
-
377
-	/**
378
-	 * The 'boolean' data type name.
379
-	 *
380
-	 * @since 3.1.0
381
-	 */
382
-	const DATA_TYPE_BOOLEAN = 'bool';
383
-
384
-	/**
385
-	 * The schema.org Event type URI.
386
-	 *
387
-	 * @since 3.1.0
388
-	 */
389
-	const SCHEMA_EVENT_TYPE = 'http://schema.org/Event';
390
-
391
-	/**
392
-	 * The schema.org Offer type URI.
393
-	 *
394
-	 * @since 3.18.0
395
-	 */
396
-	const SCHEMA_OFFER_TYPE = 'http://schema.org/Offer';
397
-
398
-	/**
399
-	 * The Schema service singleton instance.
400
-	 *
401
-	 * @since  3.1.0
402
-	 * @access private
403
-	 * @var \Wordlift_Schema_Service $instance The Schema service singleton instance.
404
-	 */
405
-	private static $instance;
406
-
407
-	/**
408
-	 * WordLift's schema.
409
-	 *
410
-	 * @since  3.1.0
411
-	 * @access private
412
-	 * @var array $schema WordLift's schema.
413
-	 */
414
-	private $schema;
415
-
416
-	/**
417
-	 * The Log service.
418
-	 *
419
-	 * @since  3.1.0
420
-	 * @access private
421
-	 * @var \Wordlift_Log_Service $log The Log service.
422
-	 */
423
-	private $log;
424
-
425
-	/**
426
-	 * The {@link Wordlift_Post_Property_Storage_Factory} instance.
427
-	 *
428
-	 * @since  3.15.0
429
-	 * @access private
430
-	 * @var \Wordlift_Storage_Factory $storage_factory The {@link Wordlift_Post_Property_Storage_Factory} instance.
431
-	 */
432
-	private $storage_factory;
433
-
434
-	/**
435
-	 * The {@link Wordlift_Sparql_Tuple_Rendition_Factory} instance.
436
-	 *
437
-	 * @since  3.15.0
438
-	 * @access private
439
-	 * @var \Wordlift_Sparql_Tuple_Rendition_Factory $rendition_factory The {@link Wordlift_Sparql_Tuple_Rendition_Factory} instance.
440
-	 */
441
-	private $rendition_factory;
442
-
443
-	/**
444
-	 * The {@link Wordlift_Configuration_Service} instance.
445
-	 *
446
-	 * @since  3.15.0
447
-	 * @access private
448
-	 * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
449
-	 */
450
-	private $configuration_service;
451
-
452
-	/**
453
-	 * The web site configured language code.
454
-	 *
455
-	 * @since  3.15.0
456
-	 * @access private
457
-	 * @var string $language_code The web site configured language code.
458
-	 */
459
-	private $language_code;
460
-
461
-	/**
462
-	 * Wordlift_Schema_Service constructor.
463
-	 *
464
-	 * @since 3.1.0
465
-	 *
466
-	 * @param \Wordlift_Storage_Factory                $storage_factory       The {@link Wordlift_Post_Property_Storage_Factory} instance.
467
-	 * @param \Wordlift_Sparql_Tuple_Rendition_Factory $rendition_factory     The {@link Wordlift_Sparql_Tuple_Rendition_Factory} instance.
468
-	 * @param \Wordlift_Configuration_Service          $configuration_service The {@link Wordlift_Configuration_Service} instance.
469
-	 */
470
-	public function __construct( $storage_factory, $rendition_factory, $configuration_service ) {
471
-
472
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
473
-
474
-		$this->storage_factory       = $storage_factory;
475
-		$this->rendition_factory     = $rendition_factory;
476
-		$this->configuration_service = $configuration_service;
477
-		$this->language_code         = $this->configuration_service->get_language_code();
478
-
479
-		// Set the taxonomy data.
480
-		// Note: parent types must be defined before child types.
481
-		$this->schema = array(
482
-			'article'       => $this->get_article_schema(),
483
-			'thing'         => $this->get_thing_schema(),
484
-			'creative-work' => $this->get_creative_work_schema(),
485
-			'event'         => $this->get_event_schema(),
486
-			'organization'  => $this->get_organization_schema(),
487
-			'person'        => $this->get_person_schema(),
488
-			'place'         => $this->get_place_schema(),
489
-			'localbusiness' => $this->get_local_business_schema(),
490
-			'recipe'        => $this->get_recipe_schema(),
491
-			'web-page'      => $this->get_web_page_schema(),
492
-			'offer'         => $this->get_offer_schema(),
493
-		);
494
-
495
-		// Create a singleton instance of the Schema service, useful to provide static functions to global functions.
496
-		self::$instance = $this;
497
-
498
-	}
499
-
500
-	/**
501
-	 * Get a reference to the Schema service.
502
-	 *
503
-	 * @since 3.1.0
504
-	 *
505
-	 * @return Wordlift_Schema_Service A reference to the Schema service.
506
-	 */
507
-	public static function get_instance() {
508
-
509
-		return self::$instance;
510
-	}
511
-
512
-	/**
513
-	 * Get the properties for a field with the specified key. The key is used as
514
-	 * meta key when the field's value is stored in WordPress meta data table.
515
-	 *
516
-	 * @since 3.6.0
517
-	 *
518
-	 * @param string $key The field's key.
519
-	 *
520
-	 * @return null|array An array of field's properties or null if the field is not found.
521
-	 */
522
-	public function get_field( $key ) {
523
-
524
-		// Parse each schema's fields until we find the one we're looking for, then
525
-		// return its properties.
526
-		foreach ( $this->schema as $_ => $schema ) {
527
-
528
-			if ( ! isset( $schema['custom_fields'] ) ) {
529
-				break;
530
-			}
531
-
532
-			foreach ( $schema['custom_fields'] as $field => $props ) {
533
-				if ( $key === $field ) {
534
-					return $props;
535
-				}
536
-			}
537
-		}
538
-
539
-		return null;
540
-	}
541
-
542
-	/**
543
-	 * Get all renditions for each WordLift's schema.
544
-	 *
545
-	 * @since 3.18.0
546
-	 *
547
-	 * @return array An array with the schema renditions.
548
-	 */
549
-	public function get_renditions() {
550
-		// Get the custom fields.
551
-		$renditions = array_reduce(
552
-			$this->schema,
553
-			function ( $carry, $item ) {
554
-				return array_merge( $carry, $item['linked_data'] );
555
-			},
556
-			array()
557
-		);
558
-
559
-		// Return the schemas.
560
-		return $renditions;
561
-	}
562
-
563
-	/**
564
-	 * Get the WordLift's schema.
565
-	 *
566
-	 * @param string $name The schema name.
567
-	 *
568
-	 * @return array|null An array with the schema configuration or NULL if the schema is not found.
569
-	 *
570
-	 * @since 3.1.0
571
-	 */
572
-	public function get_schema( $name ) {
573
-		// Check if the schema exists and, if not, return NULL.
574
-		if ( ! isset( $this->schema[ $name ] ) ) {
575
-			return null;
576
-		}
577
-
578
-		// Return the requested schema.
579
-		return $this->schema[ $name ];
580
-	}
581
-
582
-	/**
583
-	 * Get the WordLift's schema trough schema type uri.
584
-	 *
585
-	 * @param string $uri The schema uri.
586
-	 *
587
-	 * @return array|null An array with the schema configuration or NULL if the schema is not found.
588
-	 *
589
-	 * @since 3.3.0
590
-	 */
591
-	public function get_schema_by_uri( $uri ) {
592
-
593
-		foreach ( $this->schema as $name => $schema ) {
594
-			if ( $schema['uri'] === $uri ) {
595
-				return $schema;
596
-			}
597
-		}
598
-
599
-		return null;
600
-	}
601
-
602
-	/**
603
-	 * Get the 'thing' schema.
604
-	 *
605
-	 * @return array An array with the schema configuration.
606
-	 *
607
-	 * @since 3.1.0
608
-	 */
609
-	private function get_thing_schema() {
610
-
611
-		return array(
612
-			'css_class'     => 'wl-thing',
613
-			'uri'           => 'http://schema.org/Thing',
614
-			'same_as'       => array( '*' ),
615
-			// set as default.
616
-			'custom_fields' => array(
617
-				self::FIELD_SAME_AS                            => array(
618
-					'predicate'   => 'http://schema.org/sameAs',
619
-					'type'        => self::DATA_TYPE_URI,
620
-					'export_type' => 'http://schema.org/Thing',
621
-					'constraints' => array(
622
-						'cardinality' => INF,
623
-					),
624
-					// We need a custom metabox.
625
-					'input_field' => 'sameas',
626
-				),
627
-				// Add the schema:url property.
628
-				Wordlift_Schema_Url_Property_Service::META_KEY => Wordlift_Schema_Url_Property_Service::get_instance()
629
-																									  ->get_compat_definition(),
630
-			),
631
-			// {{sameAs}} not present in the microdata template,
632
-			// because it is treated separately in *wl_content_embed_item_microdata*
633
-			'templates'     => array(
634
-				'subtitle' => '{{id}}',
635
-			),
636
-			'linked_data'   => array(
637
-				// ### Title to rdfs:label.
638
-				$this->rendition_factory->create(
639
-					$this->storage_factory->post_title(),
640
-					Wordlift_Query_Builder::RDFS_LABEL_URI,
641
-					null,
642
-					$this->language_code
643
-				),
644
-				// ### Title to dct:title.
645
-				$this->rendition_factory->create(
646
-					$this->storage_factory->post_title(),
647
-					'http://purl.org/dc/terms/title',
648
-					null,
649
-					$this->language_code
650
-				),
651
-				// ### Alternative title to rdfs:label.
652
-				$this->rendition_factory->create(
653
-					$this->storage_factory->post_meta( Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY ),
654
-					Wordlift_Query_Builder::RDFS_LABEL_URI,
655
-					null,
656
-					$this->language_code
657
-				),
658
-				// ### Alternative title to dct:title.
659
-				$this->rendition_factory->create(
660
-					$this->storage_factory->post_meta( Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY ),
661
-					'http://purl.org/dc/terms/title',
662
-					null,
663
-					$this->language_code
664
-				),
665
-				// ### Title to schema:name.
666
-				$this->rendition_factory->create(
667
-					$this->storage_factory->post_title(),
668
-					'http://schema.org/name',
669
-					null,
670
-					$this->language_code
671
-				),
672
-				// ### Alternative title to schema:alterName.
673
-				$this->rendition_factory->create(
674
-					$this->storage_factory->post_meta( Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY ),
675
-					'http://schema.org/alternateName',
676
-					null,
677
-					$this->language_code
678
-				),
679
-				// ### schema:url.
680
-				$this->rendition_factory->create(
681
-					$this->storage_factory->url_property(),
682
-					Wordlift_Query_Builder::SCHEMA_URL_URI,
683
-					self::DATA_TYPE_URI
684
-				),
685
-				// ### schema:description.
686
-				$this->rendition_factory->create(
687
-					$this->storage_factory->post_description_no_tags_no_shortcodes(),
688
-					'http://schema.org/description',
689
-					null,
690
-					$this->language_code
691
-				),
692
-				// ### owl:sameAs.
693
-				$this->rendition_factory->create(
694
-					$this->storage_factory->post_meta( self::FIELD_SAME_AS ),
695
-					'http://www.w3.org/2002/07/owl#sameAs',
696
-					self::DATA_TYPE_URI
697
-				),
698
-				// ### rdf:type.
699
-				$this->rendition_factory->create(
700
-					$this->storage_factory->schema_class(),
701
-					Wordlift_Query_Builder::RDFS_TYPE_URI,
702
-					self::DATA_TYPE_URI
703
-				),
704
-				// ### schema:image.
705
-				$this->rendition_factory->create(
706
-					$this->storage_factory->post_images(),
707
-					Wordlift_Query_Builder::SCHEMA_IMAGE_URI,
708
-					self::DATA_TYPE_URI
709
-				),
710
-				// ### dct:relation.
711
-				$this->rendition_factory->create(
712
-					$this->storage_factory->relations(),
713
-					Wordlift_Query_Builder::DCTERMS_RELATION_URI,
714
-					self::DATA_TYPE_URI
715
-				),
716
-			),
717
-		);
718
-
719
-	}
720
-
721
-	/**
722
-	 * Get the 'web-page' schema.
723
-	 *
724
-	 * @return array An array with the schema configuration.
725
-	 *
726
-	 * @since 3.18.0
727
-	 */
728
-	private function get_web_page_schema() {
729
-
730
-		return array(
731
-			'css_class'   => 'wl-webpage',
732
-			'uri'         => 'http://schema.org/WebPage',
733
-			'linked_data' => array(
734
-				// ### schema:headline.
735
-				$this->rendition_factory->create(
736
-					$this->storage_factory->post_title(),
737
-					'http://schema.org/headline',
738
-					null,
739
-					$this->language_code
740
-				),
741
-				// ### schema:url.
742
-				$this->rendition_factory->create(
743
-					$this->storage_factory->url_property(),
744
-					Wordlift_Query_Builder::SCHEMA_URL_URI,
745
-					self::DATA_TYPE_URI
746
-				),
747
-				// ### rdf:type.
748
-				$this->rendition_factory->create(
749
-					$this->storage_factory->schema_class(),
750
-					Wordlift_Query_Builder::RDFS_TYPE_URI,
751
-					self::DATA_TYPE_URI
752
-				),
753
-				// ### dcterms:references.
754
-				$this->rendition_factory->create(
755
-					$this->storage_factory->relations(),
756
-					Wordlift_Query_Builder::DCTERMS_REFERENCES_URI,
757
-					self::DATA_TYPE_URI,
758
-					$this->language_code
759
-				),
760
-			),
761
-		);
762
-
763
-	}
764
-
765
-	/**
766
-	 * Get the 'creative work' schema.
767
-	 *
768
-	 * @return array An array with the schema configuration.
769
-	 *
770
-	 * @since 3.1.0
771
-	 */
772
-	private function get_creative_work_schema() {
773
-
774
-		$schema = array(
775
-			'label'         => 'CreativeWork',
776
-			'description'   => 'A creative work (or a Music Album).',
777
-			'parents'       => array( 'thing' ),
778
-			// Give term slug as parent.
779
-			'css_class'     => 'wl-creative-work',
780
-			'uri'           => 'http://schema.org/CreativeWork',
781
-			'same_as'       => array(
782
-				'http://schema.org/MusicAlbum',
783
-				'http://schema.org/Product',
784
-			),
785
-			'custom_fields' => array(
786
-				self::FIELD_AUTHOR => array(
787
-					'predicate'   => 'http://schema.org/author',
788
-					'type'        => self::DATA_TYPE_URI,
789
-					'export_type' => 'http://schema.org/Person',
790
-					'constraints' => array(
791
-						'uri_type'    => array( 'Person', 'Organization' ),
792
-						'cardinality' => INF,
793
-					),
794
-				),
795
-			),
796
-			'linked_data'   => array(
797
-				// ### schema:author.
798
-				$this->rendition_factory->create(
799
-					$this->storage_factory->author_uri(),
800
-					Wordlift_Query_Builder::SCHEMA_AUTHOR_URI,
801
-					self::DATA_TYPE_URI
802
-				),
803
-			),
804
-			'templates'     => array(
805
-				'subtitle' => '{{id}}',
806
-			),
807
-		);
808
-
809
-		// Merge the custom fields with those provided by the thing schema.
810
-		$parent_schema           = $this->get_thing_schema();
811
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
812
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
813
-
814
-		return $schema;
815
-	}
816
-
817
-	/**
818
-	 * Get the 'event' schema.
819
-	 *
820
-	 * @return array An array with the schema configuration.
821
-	 *
822
-	 * @since 3.1.0
823
-	 */
824
-	private function get_event_schema() {
825
-
826
-		$schema = array(
827
-			'label'         => 'Event',
828
-			'description'   => 'An event . ',
829
-			'parents'       => array( 'thing' ),
830
-			'css_class'     => 'wl-event',
831
-			'uri'           => self::SCHEMA_EVENT_TYPE,
832
-			'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
833
-			'custom_fields' => array(
834
-				self::FIELD_DATE_START => array(
835
-					'predicate'   => 'http://schema.org/startDate',
836
-					'type'        => self::DATA_TYPE_DATE,
837
-					'export_type' => 'xsd:dateTime',
838
-					'constraints' => '',
839
-				),
840
-				self::FIELD_DATE_END   => array(
841
-					'predicate'   => 'http://schema.org/endDate',
842
-					'type'        => self::DATA_TYPE_DATE,
843
-					'export_type' => 'xsd:dateTime',
844
-					'constraints' => '',
845
-				),
846
-				self::FIELD_LOCATION   => array(
847
-					'predicate'   => 'http://schema.org/location',
848
-					'type'        => self::DATA_TYPE_URI,
849
-					'export_type' => 'http://schema.org/PostalAddress',
850
-					'constraints' => array(
851
-						'uri_type'    => array( 'Place', 'LocalBusiness' ),
852
-						'cardinality' => INF,
853
-					),
854
-				),
855
-				self::FIELD_PERFORMER  => array(
856
-					'predicate'   => 'http://schema.org/performer',
857
-					'type'        => self::DATA_TYPE_URI,
858
-					'export_type' => 'http://schema.org/Person',
859
-					'constraints' => array(
860
-						'uri_type'    => array( 'Person', 'Organization' ),
861
-						'cardinality' => INF,
862
-					),
863
-				),
864
-				self::FIELD_OFFERS     => array(
865
-					'predicate'   => 'http://schema.org/offers',
866
-					'type'        => self::DATA_TYPE_URI,
867
-					'export_type' => 'http://schema.org/Offer',
868
-					'constraints' => array(
869
-						'uri_type'    => array( 'Offer' ),
870
-						'cardinality' => INF,
871
-					),
872
-				),
873
-			),
874
-			'linked_data'   => array(
875
-				// ### schema:startDate.
876
-				$this->rendition_factory->create(
877
-					$this->storage_factory->post_meta( self::FIELD_DATE_START ),
878
-					'http://schema.org/startDate',
879
-					self::DATA_TYPE_DATE_TIME
880
-				),
881
-				// ### schema:endDate.
882
-				$this->rendition_factory->create(
883
-					$this->storage_factory->post_meta( self::FIELD_DATE_END ),
884
-					'http://schema.org/endDate',
885
-					self::DATA_TYPE_DATE_TIME
886
-				),
887
-				// ### schema:location.
888
-				$this->rendition_factory->create(
889
-					$this->storage_factory->post_meta_to_uri( self::FIELD_LOCATION ),
890
-					'http://schema.org/location',
891
-					self::DATA_TYPE_URI
892
-				),
893
-				// ### schema:performer.
894
-				$this->rendition_factory->create(
895
-					$this->storage_factory->post_meta_to_uri( self::FIELD_PERFORMER ),
896
-					'http://schema.org/performer',
897
-					self::DATA_TYPE_URI
898
-				),
899
-				// ### schema:offers.
900
-				$this->rendition_factory->create(
901
-					$this->storage_factory->post_meta_to_uri( self::FIELD_OFFERS ),
902
-					'http://schema.org/offers',
903
-					self::DATA_TYPE_URI
904
-				),
905
-			),
906
-			'templates'     => array(
907
-				'subtitle' => '{{id}}',
908
-			),
909
-		);
910
-
911
-		// Merge the custom fields with those provided by the thing schema.
912
-		$parent_schema           = $this->get_thing_schema();
913
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
914
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
915
-
916
-		return $schema;
917
-	}
918
-
919
-	/**
920
-	 * Get the 'organization' schema.
921
-	 *
922
-	 * @return array An array with the schema configuration.
923
-	 *
924
-	 * @since 3.1.0
925
-	 */
926
-	private function get_organization_schema() {
927
-
928
-		$schema = array(
929
-			'label'         => 'Organization',
930
-			'description'   => 'An organization, including a government or a newspaper.',
931
-			'parents'       => array( 'thing' ),
932
-			'css_class'     => 'wl-organization',
933
-			'uri'           => 'http://schema.org/Organization',
934
-			'same_as'       => array(
935
-				'http://rdf.freebase.com/ns/organization.organization',
936
-				'http://rdf.freebase.com/ns/government.government',
937
-				'http://schema.org/Newspaper',
938
-			),
939
-			'custom_fields' => array(
940
-				self::FIELD_LEGAL_NAME          => array(
941
-					'predicate'   => 'http://schema.org/legalName',
942
-					'type'        => self::DATA_TYPE_STRING,
943
-					'export_type' => 'xsd:string',
944
-					'constraints' => '',
945
-				),
946
-				self::FIELD_FOUNDER             => array(
947
-					'predicate'   => 'http://schema.org/founder',
948
-					'type'        => self::DATA_TYPE_URI,
949
-					'export_type' => 'http://schema.org/Person',
950
-					'constraints' => array(
951
-						'uri_type'    => 'Person',
952
-						'cardinality' => INF,
953
-					),
954
-				),
955
-				self::FIELD_ADDRESS             => array(
956
-					'predicate'   => 'http://schema.org/streetAddress',
957
-					'type'        => self::DATA_TYPE_STRING,
958
-					'export_type' => 'xsd:string',
959
-					'constraints' => '',
960
-					// To build custom metabox.
961
-					'input_field' => 'address',
962
-				),
963
-				self::FIELD_ADDRESS_PO_BOX      => array(
964
-					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
965
-					'type'        => self::DATA_TYPE_STRING,
966
-					'export_type' => 'xsd:string',
967
-					'constraints' => '',
968
-					// To build custom metabox.
969
-					'input_field' => 'address',
970
-				),
971
-				self::FIELD_ADDRESS_POSTAL_CODE => array(
972
-					'predicate'   => 'http://schema.org/postalCode',
973
-					'type'        => self::DATA_TYPE_STRING,
974
-					'export_type' => 'xsd:string',
975
-					'constraints' => '',
976
-					// To build custom metabox.
977
-					'input_field' => 'address',
978
-				),
979
-				self::FIELD_ADDRESS_LOCALITY    => array(
980
-					'predicate'   => 'http://schema.org/addressLocality',
981
-					'type'        => self::DATA_TYPE_STRING,
982
-					'export_type' => 'xsd:string',
983
-					'constraints' => '',
984
-					// To build custom metabox.
985
-					'input_field' => 'address',
986
-				),
987
-				self::FIELD_ADDRESS_REGION      => array(
988
-					'predicate'   => 'http://schema.org/addressRegion',
989
-					'type'        => self::DATA_TYPE_STRING,
990
-					'export_type' => 'xsd:string',
991
-					'constraints' => '',
992
-					// To build custom metabox.
993
-					'input_field' => 'address',
994
-				),
995
-				self::FIELD_ADDRESS_COUNTRY     => array(
996
-					'predicate'   => 'http://schema.org/addressCountry',
997
-					'type'        => self::DATA_TYPE_STRING,
998
-					'export_type' => 'xsd:string',
999
-					'constraints' => '',
1000
-					// To build custom metabox.
1001
-					'input_field' => 'address',
1002
-				),
1003
-				self::FIELD_EMAIL               => array(
1004
-					'predicate'   => 'http://schema.org/email',
1005
-					'type'        => self::DATA_TYPE_STRING,
1006
-					'export_type' => 'xsd:string',
1007
-					'constraints' => '',
1008
-				),
1009
-				self::FIELD_TELEPHONE           => array(
1010
-					'predicate'   => 'http://schema.org/telephone',
1011
-					'type'        => self::DATA_TYPE_STRING,
1012
-					'export_type' => 'xsd:string',
1013
-					'constraints' => '',
1014
-				),
1015
-			),
1016
-			'linked_data'   => array(
1017
-				// ### schema:legalName.
1018
-				$this->rendition_factory->create(
1019
-					$this->storage_factory->post_meta( self::FIELD_LEGAL_NAME ),
1020
-					'http://schema.org/legalName'
1021
-				),
1022
-				// ### schema:founder.
1023
-				$this->rendition_factory->create(
1024
-					$this->storage_factory->post_meta_to_uri( self::FIELD_FOUNDER ),
1025
-					'http://schema.org/founder',
1026
-					self::DATA_TYPE_URI
1027
-				),
1028
-				// ### schema:email.
1029
-				$this->rendition_factory->create(
1030
-					$this->storage_factory->post_meta( self::FIELD_EMAIL ),
1031
-					'http://schema.org/email'
1032
-				),
1033
-				// ### schema:telephone.
1034
-				$this->rendition_factory->create(
1035
-					$this->storage_factory->post_meta( self::FIELD_TELEPHONE ),
1036
-					'http://schema.org/telephone'
1037
-				),
1038
-			),
1039
-			'templates'     => array(
1040
-				'subtitle' => '{{id}}',
1041
-			),
1042
-		);
1043
-
1044
-		// Merge the custom fields with those provided by the thing schema.
1045
-		$parent_schema           = $this->get_thing_schema();
1046
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1047
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1048
-
1049
-		return $schema;
1050
-	}
1051
-
1052
-	/**
1053
-	 * Get the 'person' schema.
1054
-	 *
1055
-	 * @return array An array with the schema configuration.
1056
-	 *
1057
-	 * @since 3.1.0
1058
-	 */
1059
-	private function get_person_schema() {
1060
-
1061
-		$schema = array(
1062
-			'label'         => 'Person',
1063
-			'description'   => 'A person (or a music artist).',
1064
-			'parents'       => array( 'thing' ),
1065
-			'css_class'     => 'wl-person',
1066
-			'uri'           => 'http://schema.org/Person',
1067
-			'same_as'       => array(
1068
-				'http://rdf.freebase.com/ns/people.person',
1069
-				'http://rdf.freebase.com/ns/music.artist',
1070
-				'http://dbpedia.org/class/yago/LivingPeople',
1071
-			),
1072
-			'custom_fields' => array(
1073
-				self::FIELD_KNOWS       => array(
1074
-					'predicate'   => 'http://schema.org/knows',
1075
-					'type'        => self::DATA_TYPE_URI,
1076
-					'export_type' => 'http://schema.org/Person',
1077
-					'constraints' => array(
1078
-						'uri_type'    => 'Person',
1079
-						'cardinality' => INF,
1080
-					),
1081
-				),
1082
-				self::FIELD_BIRTH_DATE  => array(
1083
-					'predicate'   => 'http://schema.org/birthDate',
1084
-					'type'        => self::DATA_TYPE_DATE,
1085
-					'export_type' => 'xsd:date',
1086
-					'constraints' => '',
1087
-				),
1088
-				self::FIELD_BIRTH_PLACE => array(
1089
-					'predicate'   => 'http://schema.org/birthPlace',
1090
-					'type'        => self::DATA_TYPE_URI,
1091
-					'export_type' => 'http://schema.org/Place',
1092
-					'constraints' => array(
1093
-						'uri_type' => 'Place',
1094
-					),
1095
-				),
1096
-				self::FIELD_AFFILIATION => array(
1097
-					'predicate'   => 'http://schema.org/affiliation',
1098
-					'type'        => self::DATA_TYPE_URI,
1099
-					'export_type' => 'http://schema.org/Organization',
1100
-					'constraints' => array(
1101
-						'uri_type'    => array(
1102
-							'Organization',
1103
-							'LocalBusiness',
1104
-						),
1105
-						'cardinality' => INF,
1106
-					),
1107
-				),
1108
-				self::FIELD_EMAIL       => array(
1109
-					'predicate'   => 'http://schema.org/email',
1110
-					'type'        => self::DATA_TYPE_STRING,
1111
-					'export_type' => 'xsd:string',
1112
-					'constraints' => array(
1113
-						'cardinality' => INF,
1114
-					),
1115
-				),
1116
-			),
1117
-			'linked_data'   => array(
1118
-				// ### schema:knows.
1119
-				$this->rendition_factory->create(
1120
-					$this->storage_factory->post_meta_to_uri( self::FIELD_KNOWS ),
1121
-					'http://schema.org/knows',
1122
-					self::DATA_TYPE_URI
1123
-				),
1124
-				// ### schema:birthDate.
1125
-				$this->rendition_factory->create(
1126
-					$this->storage_factory->post_meta( self::FIELD_BIRTH_DATE ),
1127
-					'http://schema.org/birthDate',
1128
-					self::DATA_TYPE_DATE
1129
-				),
1130
-				// ### schema:birthPlace.
1131
-				$this->rendition_factory->create(
1132
-					$this->storage_factory->post_meta_to_uri( self::FIELD_BIRTH_PLACE ),
1133
-					'http://schema.org/birthPlace',
1134
-					self::DATA_TYPE_URI
1135
-				),
1136
-				// ### schema:affiliation.
1137
-				$this->rendition_factory->create(
1138
-					$this->storage_factory->post_meta_to_uri( self::FIELD_AFFILIATION ),
1139
-					'http://schema.org/affiliation',
1140
-					self::DATA_TYPE_URI
1141
-				),
1142
-				// ### schema:email.
1143
-				$this->rendition_factory->create(
1144
-					$this->storage_factory->post_meta( self::FIELD_EMAIL ),
1145
-					'http://schema.org/email'
1146
-				),
1147
-			),
1148
-			'templates'     => array(
1149
-				'subtitle' => '{{id}}',
1150
-			),
1151
-		);
1152
-
1153
-		// Merge the custom fields with those provided by the thing schema.
1154
-		$parent_schema           = $this->get_thing_schema();
1155
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1156
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1157
-
1158
-		return $schema;
1159
-
1160
-	}
1161
-
1162
-	/**
1163
-	 * Get the 'place' schema.
1164
-	 *
1165
-	 * @return array An array with the schema configuration.
1166
-	 *
1167
-	 * @since 3.1.0
1168
-	 */
1169
-	private function get_place_schema() {
1170
-
1171
-		$schema = array(
1172
-			'label'         => 'Place',
1173
-			'description'   => 'A place.',
1174
-			'parents'       => array( 'thing' ),
1175
-			'css_class'     => 'wl-place',
1176
-			'uri'           => 'http://schema.org/Place',
1177
-			'same_as'       => array(
1178
-				'http://rdf.freebase.com/ns/location.location',
1179
-				'http://www.opengis.net/gml/_Feature',
1180
-			),
1181
-			'custom_fields' => array(
1182
-				self::FIELD_GEO_LATITUDE        => array(
1183
-					'predicate'   => 'http://schema.org/latitude',
1184
-					'type'        => self::DATA_TYPE_DOUBLE,
1185
-					'export_type' => 'xsd:double',
1186
-					'constraints' => '',
1187
-					// To build custom metabox.
1188
-					'input_field' => 'coordinates',
1189
-				),
1190
-				self::FIELD_GEO_LONGITUDE       => array(
1191
-					'predicate'   => 'http://schema.org/longitude',
1192
-					'type'        => self::DATA_TYPE_DOUBLE,
1193
-					'export_type' => 'xsd:double',
1194
-					'constraints' => '',
1195
-					// To build custom metabox.
1196
-					'input_field' => 'coordinates',
1197
-				),
1198
-				self::FIELD_ADDRESS             => array(
1199
-					'predicate'   => 'http://schema.org/streetAddress',
1200
-					'type'        => self::DATA_TYPE_STRING,
1201
-					'export_type' => 'xsd:string',
1202
-					'constraints' => '',
1203
-					// To build custom metabox.
1204
-					'input_field' => 'address',
1205
-				),
1206
-				self::FIELD_ADDRESS_PO_BOX      => array(
1207
-					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
1208
-					'type'        => self::DATA_TYPE_STRING,
1209
-					'export_type' => 'xsd:string',
1210
-					'constraints' => '',
1211
-					// To build custom metabox.
1212
-					'input_field' => 'address',
1213
-				),
1214
-				self::FIELD_ADDRESS_POSTAL_CODE => array(
1215
-					'predicate'   => 'http://schema.org/postalCode',
1216
-					'type'        => self::DATA_TYPE_STRING,
1217
-					'export_type' => 'xsd:string',
1218
-					'constraints' => '',
1219
-					// To build custom metabox.
1220
-					'input_field' => 'address',
1221
-				),
1222
-				self::FIELD_ADDRESS_LOCALITY    => array(
1223
-					'predicate'   => 'http://schema.org/addressLocality',
1224
-					'type'        => self::DATA_TYPE_STRING,
1225
-					'export_type' => 'xsd:string',
1226
-					'constraints' => '',
1227
-					// To build custom metabox.
1228
-					'input_field' => 'address',
1229
-				),
1230
-				self::FIELD_ADDRESS_REGION      => array(
1231
-					'predicate'   => 'http://schema.org/addressRegion',
1232
-					'type'        => self::DATA_TYPE_STRING,
1233
-					'export_type' => 'xsd:string',
1234
-					'constraints' => '',
1235
-					// To build custom metabox.
1236
-					'input_field' => 'address',
1237
-				),
1238
-				self::FIELD_ADDRESS_COUNTRY     => array(
1239
-					'predicate'   => 'http://schema.org/addressCountry',
1240
-					'type'        => self::DATA_TYPE_STRING,
1241
-					'export_type' => 'xsd:string',
1242
-					'constraints' => '',
1243
-					// To build custom metabox.
1244
-					'input_field' => 'address',
1245
-				),
1246
-			),
1247
-			'linked_data'   => array(
1248
-				$this->rendition_factory->create_address(
1249
-					$this->storage_factory,
1250
-					$this->language_code
1251
-				),
1252
-			),
1253
-			'templates'     => array(
1254
-				'subtitle' => '{{id}}',
1255
-			),
1256
-		);
1257
-
1258
-		// Merge the custom fields with those provided by the thing schema.
1259
-		$parent_schema           = $this->get_thing_schema();
1260
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1261
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1262
-
1263
-		return $schema;
1264
-	}
1265
-
1266
-	/**
1267
-	 * Get the 'local business' schema.
1268
-	 *
1269
-	 * @return array An array with the schema configuration.
1270
-	 *
1271
-	 * @since 3.1.0
1272
-	 */
1273
-	private function get_local_business_schema() {
1274
-
1275
-		$schema = array(
1276
-			'label'         => 'LocalBusiness',
1277
-			'description'   => 'A local business.',
1278
-			'parents'       => array( 'place', 'organization' ),
1279
-			'css_class'     => 'wl-local-business',
1280
-			'uri'           => 'http://schema.org/LocalBusiness',
1281
-			'same_as'       => array(
1282
-				'http://rdf.freebase.com/ns/business/business_location',
1283
-				'https://schema.org/Store',
1284
-			),
1285
-			'custom_fields' => array(),
1286
-			'linked_data'   => array(),
1287
-			'templates'     => array(
1288
-				'subtitle' => '{{id}}',
1289
-			),
1290
-		);
1291
-
1292
-		// Merge the custom fields with those provided by the place and organization schema.
1293
-		$place_schema            = $this->get_place_schema();
1294
-		$organization_schema     = $this->get_organization_schema();
1295
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
1296
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $place_schema['linked_data'], $organization_schema['linked_data'] );
1297
-
1298
-		return $schema;
1299
-	}
1300
-
1301
-	/**
1302
-	 * Get the 'recipe' schema.
1303
-	 *
1304
-	 * @return array An array with the schema configuration.
1305
-	 *
1306
-	 * @since 3.14.0
1307
-	 */
1308
-	private function get_recipe_schema() {
1309
-
1310
-		$schema = array(
1311
-			'label'         => 'Recipe',
1312
-			'description'   => 'A Recipe.',
1313
-			'parents'       => array( 'CreativeWork' ),
1314
-			'css_class'     => 'wl-recipe',
1315
-			'uri'           => 'http://schema.org/Recipe',
1316
-			'same_as'       => array(),
1317
-			'templates'     => array(
1318
-				'subtitle' => '{{id}}',
1319
-			),
1320
-			'custom_fields' => array(
1321
-				self::FIELD_RECIPE_CUISINE          => array(
1322
-					'predicate'   => 'http://schema.org/recipeCuisine',
1323
-					'type'        => self::DATA_TYPE_STRING,
1324
-					'export_type' => 'xsd:string',
1325
-					'constraints' => '',
1326
-					'metabox'     => array(
1327
-						'label' => __( 'Recipe cuisine', 'wordlift' ),
1328
-					),
1329
-				),
1330
-				self::FIELD_RECIPE_INGREDIENT       => array(
1331
-					'predicate'   => 'http://schema.org/recipeIngredient',
1332
-					'type'        => self::DATA_TYPE_STRING,
1333
-					'export_type' => 'xsd:string',
1334
-					'constraints' => array(
1335
-						'cardinality' => INF,
1336
-					),
1337
-					'metabox'     => array(
1338
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
1339
-					),
1340
-				),
1341
-				self::FIELD_RECIPE_INSTRUCTIONS     => array(
1342
-					'predicate'   => 'http://schema.org/recipeInstructions',
1343
-					'type'        => self::DATA_TYPE_MULTILINE,
1344
-					'export_type' => 'xsd:string',
1345
-					'constraints' => '',
1346
-					'metabox'     => array(
1347
-						'class' => 'Wordlift_Metabox_Field_Multiline',
1348
-						'label' => __( 'Recipe instructions', 'wordlift' ),
1349
-					),
1350
-				),
1351
-				self::FIELD_RECIPE_YIELD            => array(
1352
-					'predicate'   => 'http://schema.org/recipeYield',
1353
-					'type'        => self::DATA_TYPE_STRING,
1354
-					'export_type' => 'xsd:string',
1355
-					'constraints' => '',
1356
-					'metabox'     => array(
1357
-						'label' => __( 'Recipe number of servings', 'wordlift' ),
1358
-					),
1359
-				),
1360
-				self::FIELD_RECIPE_INGREDIENT       => array(
1361
-					'predicate'   => 'http://schema.org/recipeIngredient',
1362
-					'type'        => self::DATA_TYPE_STRING,
1363
-					'export_type' => 'xsd:string',
1364
-					'constraints' => array(
1365
-						'cardinality' => INF,
1366
-					),
1367
-					'metabox'     => array(
1368
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
1369
-					),
1370
-				),
1371
-				self::FIELD_NUTRITION_INFO_CALORIES => array(
1372
-					'predicate'   => 'http://schema.org/calories',
1373
-					'type'        => self::DATA_TYPE_STRING,
1374
-					'export_type' => 'xsd:string',
1375
-					'constraints' => '',
1376
-					'metabox'     => array(
1377
-						'label' => __( 'Calories (e.g. 240 calories)', 'wordlift' ),
1378
-					),
1379
-				),
1380
-				self::FIELD_PREP_TIME               => array(
1381
-					'predicate'   => 'http://schema.org/prepTime',
1382
-					'type'        => self::DATA_TYPE_DURATION,
1383
-					'export_type' => 'xsd:time',
1384
-					'constraints' => '',
1385
-					'metabox'     => array(
1386
-						'class' => 'Wordlift_Metabox_Field_Duration',
1387
-						'label' => __( 'Recipe preparation time (e.g. 1:30)', 'wordlift' ),
1388
-					),
1389
-				),
1390
-				self::FIELD_COOK_TIME               => array(
1391
-					'predicate'   => 'http://schema.org/cookTime',
1392
-					'type'        => self::DATA_TYPE_DURATION,
1393
-					'export_type' => 'xsd:time',
1394
-					'constraints' => '',
1395
-					'metabox'     => array(
1396
-						'class' => 'Wordlift_Metabox_Field_Duration',
1397
-						'label' => __( 'Recipe cook time (e.g. 1:30)', 'wordlift' ),
1398
-					),
1399
-				),
1400
-				self::FIELD_TOTAL_TIME              => array(
1401
-					'predicate'   => 'http://schema.org/totalTime',
1402
-					'type'        => self::DATA_TYPE_DURATION,
1403
-					'export_type' => 'xsd:time',
1404
-					'constraints' => '',
1405
-					'metabox'     => array(
1406
-						'class' => 'Wordlift_Metabox_Field_Duration',
1407
-						'label' => __( 'Recipe total time (e.g. 1:30)', 'wordlift' ),
1408
-					),
1409
-				),
1410
-			),
1411
-			'linked_data'   => array(
1412
-				// ### schema:recipeCuisine.
1413
-				$this->rendition_factory->create(
1414
-					$this->storage_factory->post_meta( self::FIELD_RECIPE_CUISINE ),
1415
-					'http://schema.org/recipeCuisine'
1416
-				),
1417
-				// ### schema:recipeIngredient.
1418
-				$this->rendition_factory->create(
1419
-					$this->storage_factory->post_meta( self::FIELD_RECIPE_INGREDIENT ),
1420
-					'http://schema.org/recipeIngredient'
1421
-				),
1422
-				// ### schema:recipeInstructions.
1423
-				$this->rendition_factory->create(
1424
-					$this->storage_factory->post_meta( self::FIELD_RECIPE_INSTRUCTIONS ),
1425
-					'http://schema.org/recipeInstructions'
1426
-				),
1427
-				// ### schema:recipeYield.
1428
-				$this->rendition_factory->create(
1429
-					$this->storage_factory->post_meta( self::FIELD_RECIPE_YIELD ),
1430
-					'http://schema.org/recipeYield'
1431
-				),
1432
-				// ### schema:prepTime.
1433
-				$this->rendition_factory->create(
1434
-					$this->storage_factory->post_meta( self::FIELD_PREP_TIME ),
1435
-					'http://schema.org/prepTime',
1436
-					self::DATA_TYPE_DURATION
1437
-				),
1438
-				// ### schema:cookTime.
1439
-				$this->rendition_factory->create(
1440
-					$this->storage_factory->post_meta( self::FIELD_COOK_TIME ),
1441
-					'http://schema.org/cookTime',
1442
-					self::DATA_TYPE_DURATION
1443
-				),
1444
-				// ### schema:totalTime.
1445
-				$this->rendition_factory->create(
1446
-					$this->storage_factory->post_meta( self::FIELD_TOTAL_TIME ),
1447
-					'http://schema.org/totalTime',
1448
-					self::DATA_TYPE_DURATION
1449
-				),
1450
-			),
1451
-		);
1452
-
1453
-		// Merge the custom fields with those provided by the parent schema.
1454
-		$parent_schema           = $this->get_creative_work_schema();
1455
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1456
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1457
-
1458
-		return $schema;
1459
-	}
1460
-
1461
-	/**
1462
-	 * Get the 'offer' schema.
1463
-	 *
1464
-	 * @return array An array with the schema configuration.
1465
-	 *
1466
-	 * @since 3.18.0
1467
-	 */
1468
-	private function get_offer_schema() {
1469
-
1470
-		$schema = array(
1471
-			'label'         => 'Offer',
1472
-			'description'   => 'An offer. ',
1473
-			'parents'       => array( 'thing' ),
1474
-			'css_class'     => 'wl-offer',
1475
-			'uri'           => self::SCHEMA_OFFER_TYPE,
1476
-			'same_as'       => array(),
1477
-			'templates'     => array(
1478
-				'subtitle' => '{{id}}',
1479
-			),
1480
-			'custom_fields' => array(
1481
-				self::FIELD_AVAILABILITY        => array(
1482
-					'predicate'   => 'http://schema.org/availability',
1483
-					'type'        => self::DATA_TYPE_STRING,
1484
-					'export_type' => 'xsd:string',
1485
-					'metabox'     => array(
1486
-						'class' => 'Wordlift_Metabox_Field_Select',
1487
-					),
1488
-					'options'     => array(
1489
-						'Discontinued'        => esc_html__( 'Discontinued', 'wordlift' ),
1490
-						'InStock'             => esc_html__( 'In Stock', 'wordlift' ),
1491
-						'InStoreOnly'         => esc_html__( 'In Store Only', 'wordlift' ),
1492
-						'LimitedAvailability' => esc_html__( 'Limited Availability', 'wordlift' ),
1493
-						'OnlineOnly'          => esc_html__( 'Online Only', 'wordlift' ),
1494
-						'OutOfStock'          => esc_html__( 'Out of Stock', 'wordlift' ),
1495
-						'PreOrder'            => esc_html__( 'Pre Order', 'wordlift' ),
1496
-						'PreSale'             => esc_html__( 'Pre Sale', 'wordlift' ),
1497
-						'SoldOut'             => esc_html__( 'Sold Out', 'wordlift' ),
1498
-					),
1499
-				),
1500
-				self::FIELD_PRICE               => array(
1501
-					'predicate'   => 'http://schema.org/price',
1502
-					'type'        => self::DATA_TYPE_STRING,
1503
-					'export_type' => 'xsd:integer',
1504
-					'metabox'     => array(
1505
-						'class' => 'Wordlift_Metabox_Field_Integer',
1506
-					),
1507
-				),
1508
-				self::FIELD_PRICE_CURRENCY      => array(
1509
-					'predicate'   => 'http://schema.org/priceCurrency',
1510
-					'type'        => self::DATA_TYPE_STRING,
1511
-					'export_type' => 'xsd:string',
1512
-				),
1513
-				self::FIELD_AVAILABILITY_STARTS => array(
1514
-					'predicate'   => 'http://schema.org/availabilityStarts',
1515
-					'type'        => self::DATA_TYPE_DATE,
1516
-					'export_type' => 'xsd:dateTime',
1517
-				),
1518
-				self::FIELD_AVAILABILITY_ENDS   => array(
1519
-					'predicate'   => 'http://schema.org/availabilityEnds',
1520
-					'type'        => self::DATA_TYPE_DATE,
1521
-					'export_type' => 'xsd:dateTime',
1522
-				),
1523
-				self::FIELD_INVENTORY_LEVEL     => array(
1524
-					'predicate'   => 'http://schema.org/inventoryLevel',
1525
-					'type'        => self::DATA_TYPE_STRING,
1526
-					'export_type' => 'xsd:integer',
1527
-					'metabox'     => array(
1528
-						'class' => 'Wordlift_Metabox_Field_Integer',
1529
-					),
1530
-				),
1531
-				self::FIELD_VALID_FROM          => array(
1532
-					'predicate'   => 'http://schema.org/validFrom',
1533
-					'type'        => self::DATA_TYPE_DATE,
1534
-					'export_type' => 'xsd:dateTime',
1535
-				),
1536
-				self::FIELD_PRICE_VALID_UNTIL   => array(
1537
-					'predicate'   => 'http://schema.org/priceValidUntil',
1538
-					'type'        => self::DATA_TYPE_DATE,
1539
-					'export_type' => 'xsd:dateTime',
1540
-				),
1541
-				self::FIELD_ITEM_OFFERED        => array(
1542
-					'predicate'   => 'http://schema.org/itemOffered',
1543
-					'type'        => self::DATA_TYPE_URI,
1544
-					'export_type' => 'http://schema.org/Thing',
1545
-					'constraints' => array(
1546
-						'uri_type'    => array(
1547
-							'Event',
1548
-							'Thing',
1549
-						),
1550
-						'cardinality' => INF,
1551
-					),
1552
-				),
1553
-			),
1554
-			'linked_data'   => array(
1555
-				// ### schema:availability.
1556
-				$this->rendition_factory->create(
1557
-					$this->storage_factory->post_meta( self::FIELD_AVAILABILITY ),
1558
-					'http://schema.org/availability',
1559
-					null
1560
-				),
1561
-				// ### schema:availabilityStarts.
1562
-				$this->rendition_factory->create(
1563
-					$this->storage_factory->post_meta( self::FIELD_AVAILABILITY_STARTS ),
1564
-					'http://schema.org/availabilityStarts',
1565
-					self::DATA_TYPE_DATE_TIME
1566
-				),
1567
-				// ### schema:availabilityEnds.
1568
-				$this->rendition_factory->create(
1569
-					$this->storage_factory->post_meta( self::FIELD_AVAILABILITY_ENDS ),
1570
-					'http://schema.org/availabilityEnds',
1571
-					self::DATA_TYPE_DATE_TIME
1572
-				),
1573
-				// ### schema:inventoryLevel.
1574
-				$this->rendition_factory->create(
1575
-					$this->storage_factory->post_meta( self::FIELD_INVENTORY_LEVEL ),
1576
-					'http://schema.org/inventoryLevel',
1577
-					self::DATA_TYPE_INTEGER
1578
-				),
1579
-				// ### schema:price.
1580
-				$this->rendition_factory->create(
1581
-					$this->storage_factory->post_meta( self::FIELD_PRICE ),
1582
-					'http://schema.org/price',
1583
-					self::DATA_TYPE_INTEGER
1584
-				),
1585
-				// ### schema:priceCurrency.
1586
-				$this->rendition_factory->create(
1587
-					$this->storage_factory->post_meta( self::FIELD_PRICE_CURRENCY ),
1588
-					'http://schema.org/priceCurrency',
1589
-					null
1590
-				),
1591
-				// ### schema:validFrom.
1592
-				$this->rendition_factory->create(
1593
-					$this->storage_factory->post_meta( self::FIELD_VALID_FROM ),
1594
-					'http://schema.org/validFrom',
1595
-					null
1596
-				),
1597
-				// ### schema:priceValidUntil.
1598
-				$this->rendition_factory->create(
1599
-					$this->storage_factory->post_meta( self::FIELD_PRICE_VALID_UNTIL ),
1600
-					'http://schema.org/priceValidUntil',
1601
-					null
1602
-				),
1603
-				// ### schema:itemOffered.
1604
-				$this->rendition_factory->create(
1605
-					$this->storage_factory->post_meta_to_uri( self::FIELD_ITEM_OFFERED ),
1606
-					'http://schema.org/itemOffered',
1607
-					self::DATA_TYPE_URI
1608
-				),
1609
-			),
1610
-		);
1611
-
1612
-		// Merge the custom fields with those provided by the thing schema.
1613
-		$parent_schema           = $this->get_thing_schema();
1614
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1615
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1616
-
1617
-		return $schema;
1618
-	}
1619
-
1620
-	/**
1621
-	 * Get the 'article' schema.
1622
-	 *
1623
-	 * @return array An array with the schema configuration.
1624
-	 *
1625
-	 * @since 3.15.0
1626
-	 */
1627
-	private function get_article_schema() {
1628
-
1629
-		$schema = array(
1630
-			'label'         => 'Article',
1631
-			'description'   => 'An Article.',
1632
-			'parents'       => array(),
1633
-			'css_class'     => 'wl-article',
1634
-			'uri'           => 'http://schema.org/Article',
1635
-			'same_as'       => array(),
1636
-			'templates'     => array(
1637
-				'subtitle' => '{{id}}',
1638
-			),
1639
-			'custom_fields' => array(),
1640
-			'linked_data'   => array(
1641
-				// ### schema:headline.
1642
-				$this->rendition_factory->create(
1643
-					$this->storage_factory->post_title(),
1644
-					'http://schema.org/headline',
1645
-					null,
1646
-					$this->language_code
1647
-				),
1648
-				// ### schema:url.
1649
-				$this->rendition_factory->create(
1650
-					$this->storage_factory->url_property(),
1651
-					Wordlift_Query_Builder::SCHEMA_URL_URI,
1652
-					self::DATA_TYPE_URI
1653
-				),
1654
-				// ### rdf:type.
1655
-				$this->rendition_factory->create(
1656
-					$this->storage_factory->schema_class(),
1657
-					Wordlift_Query_Builder::RDFS_TYPE_URI,
1658
-					self::DATA_TYPE_URI
1659
-				),
1660
-				// ### dcterms:references.
1661
-				$this->rendition_factory->create(
1662
-					$this->storage_factory->relations(),
1663
-					Wordlift_Query_Builder::DCTERMS_REFERENCES_URI,
1664
-					self::DATA_TYPE_URI,
1665
-					$this->language_code
1666
-				),
1667
-			),
1668
-		);
1669
-
1670
-		return $schema;
1671
-	}
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 'dateTime' data type name.
337
+     *
338
+     * @since 3.15.0
339
+     */
340
+    const DATA_TYPE_DATE_TIME = 'dateTime';
341
+
342
+    /**
343
+     * The 'time' data type name.
344
+     *
345
+     * @since 3.14.0
346
+     */
347
+    const DATA_TYPE_DURATION = 'duration';
348
+
349
+    /**
350
+     * The 'double' data type name.
351
+     *
352
+     * @since 3.1.0
353
+     */
354
+    const DATA_TYPE_DOUBLE = 'double';
355
+
356
+    /**
357
+     * The 'string' data type name.
358
+     *
359
+     * @since 3.1.0
360
+     */
361
+    const DATA_TYPE_STRING = 'string';
362
+
363
+    /**
364
+     * The multiline text data type name.
365
+     *
366
+     * @since 3.14.0
367
+     */
368
+    const DATA_TYPE_MULTILINE = 'multiline';
369
+
370
+    /**
371
+     * The 'integer' data type name.
372
+     *
373
+     * @since 3.1.0
374
+     */
375
+    const DATA_TYPE_INTEGER = 'int';
376
+
377
+    /**
378
+     * The 'boolean' data type name.
379
+     *
380
+     * @since 3.1.0
381
+     */
382
+    const DATA_TYPE_BOOLEAN = 'bool';
383
+
384
+    /**
385
+     * The schema.org Event type URI.
386
+     *
387
+     * @since 3.1.0
388
+     */
389
+    const SCHEMA_EVENT_TYPE = 'http://schema.org/Event';
390
+
391
+    /**
392
+     * The schema.org Offer type URI.
393
+     *
394
+     * @since 3.18.0
395
+     */
396
+    const SCHEMA_OFFER_TYPE = 'http://schema.org/Offer';
397
+
398
+    /**
399
+     * The Schema service singleton instance.
400
+     *
401
+     * @since  3.1.0
402
+     * @access private
403
+     * @var \Wordlift_Schema_Service $instance The Schema service singleton instance.
404
+     */
405
+    private static $instance;
406
+
407
+    /**
408
+     * WordLift's schema.
409
+     *
410
+     * @since  3.1.0
411
+     * @access private
412
+     * @var array $schema WordLift's schema.
413
+     */
414
+    private $schema;
415
+
416
+    /**
417
+     * The Log service.
418
+     *
419
+     * @since  3.1.0
420
+     * @access private
421
+     * @var \Wordlift_Log_Service $log The Log service.
422
+     */
423
+    private $log;
424
+
425
+    /**
426
+     * The {@link Wordlift_Post_Property_Storage_Factory} instance.
427
+     *
428
+     * @since  3.15.0
429
+     * @access private
430
+     * @var \Wordlift_Storage_Factory $storage_factory The {@link Wordlift_Post_Property_Storage_Factory} instance.
431
+     */
432
+    private $storage_factory;
433
+
434
+    /**
435
+     * The {@link Wordlift_Sparql_Tuple_Rendition_Factory} instance.
436
+     *
437
+     * @since  3.15.0
438
+     * @access private
439
+     * @var \Wordlift_Sparql_Tuple_Rendition_Factory $rendition_factory The {@link Wordlift_Sparql_Tuple_Rendition_Factory} instance.
440
+     */
441
+    private $rendition_factory;
442
+
443
+    /**
444
+     * The {@link Wordlift_Configuration_Service} instance.
445
+     *
446
+     * @since  3.15.0
447
+     * @access private
448
+     * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
449
+     */
450
+    private $configuration_service;
451
+
452
+    /**
453
+     * The web site configured language code.
454
+     *
455
+     * @since  3.15.0
456
+     * @access private
457
+     * @var string $language_code The web site configured language code.
458
+     */
459
+    private $language_code;
460
+
461
+    /**
462
+     * Wordlift_Schema_Service constructor.
463
+     *
464
+     * @since 3.1.0
465
+     *
466
+     * @param \Wordlift_Storage_Factory                $storage_factory       The {@link Wordlift_Post_Property_Storage_Factory} instance.
467
+     * @param \Wordlift_Sparql_Tuple_Rendition_Factory $rendition_factory     The {@link Wordlift_Sparql_Tuple_Rendition_Factory} instance.
468
+     * @param \Wordlift_Configuration_Service          $configuration_service The {@link Wordlift_Configuration_Service} instance.
469
+     */
470
+    public function __construct( $storage_factory, $rendition_factory, $configuration_service ) {
471
+
472
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
473
+
474
+        $this->storage_factory       = $storage_factory;
475
+        $this->rendition_factory     = $rendition_factory;
476
+        $this->configuration_service = $configuration_service;
477
+        $this->language_code         = $this->configuration_service->get_language_code();
478
+
479
+        // Set the taxonomy data.
480
+        // Note: parent types must be defined before child types.
481
+        $this->schema = array(
482
+            'article'       => $this->get_article_schema(),
483
+            'thing'         => $this->get_thing_schema(),
484
+            'creative-work' => $this->get_creative_work_schema(),
485
+            'event'         => $this->get_event_schema(),
486
+            'organization'  => $this->get_organization_schema(),
487
+            'person'        => $this->get_person_schema(),
488
+            'place'         => $this->get_place_schema(),
489
+            'localbusiness' => $this->get_local_business_schema(),
490
+            'recipe'        => $this->get_recipe_schema(),
491
+            'web-page'      => $this->get_web_page_schema(),
492
+            'offer'         => $this->get_offer_schema(),
493
+        );
494
+
495
+        // Create a singleton instance of the Schema service, useful to provide static functions to global functions.
496
+        self::$instance = $this;
497
+
498
+    }
499
+
500
+    /**
501
+     * Get a reference to the Schema service.
502
+     *
503
+     * @since 3.1.0
504
+     *
505
+     * @return Wordlift_Schema_Service A reference to the Schema service.
506
+     */
507
+    public static function get_instance() {
508
+
509
+        return self::$instance;
510
+    }
511
+
512
+    /**
513
+     * Get the properties for a field with the specified key. The key is used as
514
+     * meta key when the field's value is stored in WordPress meta data table.
515
+     *
516
+     * @since 3.6.0
517
+     *
518
+     * @param string $key The field's key.
519
+     *
520
+     * @return null|array An array of field's properties or null if the field is not found.
521
+     */
522
+    public function get_field( $key ) {
523
+
524
+        // Parse each schema's fields until we find the one we're looking for, then
525
+        // return its properties.
526
+        foreach ( $this->schema as $_ => $schema ) {
527
+
528
+            if ( ! isset( $schema['custom_fields'] ) ) {
529
+                break;
530
+            }
531
+
532
+            foreach ( $schema['custom_fields'] as $field => $props ) {
533
+                if ( $key === $field ) {
534
+                    return $props;
535
+                }
536
+            }
537
+        }
538
+
539
+        return null;
540
+    }
541
+
542
+    /**
543
+     * Get all renditions for each WordLift's schema.
544
+     *
545
+     * @since 3.18.0
546
+     *
547
+     * @return array An array with the schema renditions.
548
+     */
549
+    public function get_renditions() {
550
+        // Get the custom fields.
551
+        $renditions = array_reduce(
552
+            $this->schema,
553
+            function ( $carry, $item ) {
554
+                return array_merge( $carry, $item['linked_data'] );
555
+            },
556
+            array()
557
+        );
558
+
559
+        // Return the schemas.
560
+        return $renditions;
561
+    }
562
+
563
+    /**
564
+     * Get the WordLift's schema.
565
+     *
566
+     * @param string $name The schema name.
567
+     *
568
+     * @return array|null An array with the schema configuration or NULL if the schema is not found.
569
+     *
570
+     * @since 3.1.0
571
+     */
572
+    public function get_schema( $name ) {
573
+        // Check if the schema exists and, if not, return NULL.
574
+        if ( ! isset( $this->schema[ $name ] ) ) {
575
+            return null;
576
+        }
577
+
578
+        // Return the requested schema.
579
+        return $this->schema[ $name ];
580
+    }
581
+
582
+    /**
583
+     * Get the WordLift's schema trough schema type uri.
584
+     *
585
+     * @param string $uri The schema uri.
586
+     *
587
+     * @return array|null An array with the schema configuration or NULL if the schema is not found.
588
+     *
589
+     * @since 3.3.0
590
+     */
591
+    public function get_schema_by_uri( $uri ) {
592
+
593
+        foreach ( $this->schema as $name => $schema ) {
594
+            if ( $schema['uri'] === $uri ) {
595
+                return $schema;
596
+            }
597
+        }
598
+
599
+        return null;
600
+    }
601
+
602
+    /**
603
+     * Get the 'thing' schema.
604
+     *
605
+     * @return array An array with the schema configuration.
606
+     *
607
+     * @since 3.1.0
608
+     */
609
+    private function get_thing_schema() {
610
+
611
+        return array(
612
+            'css_class'     => 'wl-thing',
613
+            'uri'           => 'http://schema.org/Thing',
614
+            'same_as'       => array( '*' ),
615
+            // set as default.
616
+            'custom_fields' => array(
617
+                self::FIELD_SAME_AS                            => array(
618
+                    'predicate'   => 'http://schema.org/sameAs',
619
+                    'type'        => self::DATA_TYPE_URI,
620
+                    'export_type' => 'http://schema.org/Thing',
621
+                    'constraints' => array(
622
+                        'cardinality' => INF,
623
+                    ),
624
+                    // We need a custom metabox.
625
+                    'input_field' => 'sameas',
626
+                ),
627
+                // Add the schema:url property.
628
+                Wordlift_Schema_Url_Property_Service::META_KEY => Wordlift_Schema_Url_Property_Service::get_instance()
629
+                                                                                                        ->get_compat_definition(),
630
+            ),
631
+            // {{sameAs}} not present in the microdata template,
632
+            // because it is treated separately in *wl_content_embed_item_microdata*
633
+            'templates'     => array(
634
+                'subtitle' => '{{id}}',
635
+            ),
636
+            'linked_data'   => array(
637
+                // ### Title to rdfs:label.
638
+                $this->rendition_factory->create(
639
+                    $this->storage_factory->post_title(),
640
+                    Wordlift_Query_Builder::RDFS_LABEL_URI,
641
+                    null,
642
+                    $this->language_code
643
+                ),
644
+                // ### Title to dct:title.
645
+                $this->rendition_factory->create(
646
+                    $this->storage_factory->post_title(),
647
+                    'http://purl.org/dc/terms/title',
648
+                    null,
649
+                    $this->language_code
650
+                ),
651
+                // ### Alternative title to rdfs:label.
652
+                $this->rendition_factory->create(
653
+                    $this->storage_factory->post_meta( Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY ),
654
+                    Wordlift_Query_Builder::RDFS_LABEL_URI,
655
+                    null,
656
+                    $this->language_code
657
+                ),
658
+                // ### Alternative title to dct:title.
659
+                $this->rendition_factory->create(
660
+                    $this->storage_factory->post_meta( Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY ),
661
+                    'http://purl.org/dc/terms/title',
662
+                    null,
663
+                    $this->language_code
664
+                ),
665
+                // ### Title to schema:name.
666
+                $this->rendition_factory->create(
667
+                    $this->storage_factory->post_title(),
668
+                    'http://schema.org/name',
669
+                    null,
670
+                    $this->language_code
671
+                ),
672
+                // ### Alternative title to schema:alterName.
673
+                $this->rendition_factory->create(
674
+                    $this->storage_factory->post_meta( Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY ),
675
+                    'http://schema.org/alternateName',
676
+                    null,
677
+                    $this->language_code
678
+                ),
679
+                // ### schema:url.
680
+                $this->rendition_factory->create(
681
+                    $this->storage_factory->url_property(),
682
+                    Wordlift_Query_Builder::SCHEMA_URL_URI,
683
+                    self::DATA_TYPE_URI
684
+                ),
685
+                // ### schema:description.
686
+                $this->rendition_factory->create(
687
+                    $this->storage_factory->post_description_no_tags_no_shortcodes(),
688
+                    'http://schema.org/description',
689
+                    null,
690
+                    $this->language_code
691
+                ),
692
+                // ### owl:sameAs.
693
+                $this->rendition_factory->create(
694
+                    $this->storage_factory->post_meta( self::FIELD_SAME_AS ),
695
+                    'http://www.w3.org/2002/07/owl#sameAs',
696
+                    self::DATA_TYPE_URI
697
+                ),
698
+                // ### rdf:type.
699
+                $this->rendition_factory->create(
700
+                    $this->storage_factory->schema_class(),
701
+                    Wordlift_Query_Builder::RDFS_TYPE_URI,
702
+                    self::DATA_TYPE_URI
703
+                ),
704
+                // ### schema:image.
705
+                $this->rendition_factory->create(
706
+                    $this->storage_factory->post_images(),
707
+                    Wordlift_Query_Builder::SCHEMA_IMAGE_URI,
708
+                    self::DATA_TYPE_URI
709
+                ),
710
+                // ### dct:relation.
711
+                $this->rendition_factory->create(
712
+                    $this->storage_factory->relations(),
713
+                    Wordlift_Query_Builder::DCTERMS_RELATION_URI,
714
+                    self::DATA_TYPE_URI
715
+                ),
716
+            ),
717
+        );
718
+
719
+    }
720
+
721
+    /**
722
+     * Get the 'web-page' schema.
723
+     *
724
+     * @return array An array with the schema configuration.
725
+     *
726
+     * @since 3.18.0
727
+     */
728
+    private function get_web_page_schema() {
729
+
730
+        return array(
731
+            'css_class'   => 'wl-webpage',
732
+            'uri'         => 'http://schema.org/WebPage',
733
+            'linked_data' => array(
734
+                // ### schema:headline.
735
+                $this->rendition_factory->create(
736
+                    $this->storage_factory->post_title(),
737
+                    'http://schema.org/headline',
738
+                    null,
739
+                    $this->language_code
740
+                ),
741
+                // ### schema:url.
742
+                $this->rendition_factory->create(
743
+                    $this->storage_factory->url_property(),
744
+                    Wordlift_Query_Builder::SCHEMA_URL_URI,
745
+                    self::DATA_TYPE_URI
746
+                ),
747
+                // ### rdf:type.
748
+                $this->rendition_factory->create(
749
+                    $this->storage_factory->schema_class(),
750
+                    Wordlift_Query_Builder::RDFS_TYPE_URI,
751
+                    self::DATA_TYPE_URI
752
+                ),
753
+                // ### dcterms:references.
754
+                $this->rendition_factory->create(
755
+                    $this->storage_factory->relations(),
756
+                    Wordlift_Query_Builder::DCTERMS_REFERENCES_URI,
757
+                    self::DATA_TYPE_URI,
758
+                    $this->language_code
759
+                ),
760
+            ),
761
+        );
762
+
763
+    }
764
+
765
+    /**
766
+     * Get the 'creative work' schema.
767
+     *
768
+     * @return array An array with the schema configuration.
769
+     *
770
+     * @since 3.1.0
771
+     */
772
+    private function get_creative_work_schema() {
773
+
774
+        $schema = array(
775
+            'label'         => 'CreativeWork',
776
+            'description'   => 'A creative work (or a Music Album).',
777
+            'parents'       => array( 'thing' ),
778
+            // Give term slug as parent.
779
+            'css_class'     => 'wl-creative-work',
780
+            'uri'           => 'http://schema.org/CreativeWork',
781
+            'same_as'       => array(
782
+                'http://schema.org/MusicAlbum',
783
+                'http://schema.org/Product',
784
+            ),
785
+            'custom_fields' => array(
786
+                self::FIELD_AUTHOR => array(
787
+                    'predicate'   => 'http://schema.org/author',
788
+                    'type'        => self::DATA_TYPE_URI,
789
+                    'export_type' => 'http://schema.org/Person',
790
+                    'constraints' => array(
791
+                        'uri_type'    => array( 'Person', 'Organization' ),
792
+                        'cardinality' => INF,
793
+                    ),
794
+                ),
795
+            ),
796
+            'linked_data'   => array(
797
+                // ### schema:author.
798
+                $this->rendition_factory->create(
799
+                    $this->storage_factory->author_uri(),
800
+                    Wordlift_Query_Builder::SCHEMA_AUTHOR_URI,
801
+                    self::DATA_TYPE_URI
802
+                ),
803
+            ),
804
+            'templates'     => array(
805
+                'subtitle' => '{{id}}',
806
+            ),
807
+        );
808
+
809
+        // Merge the custom fields with those provided by the thing schema.
810
+        $parent_schema           = $this->get_thing_schema();
811
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
812
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
813
+
814
+        return $schema;
815
+    }
816
+
817
+    /**
818
+     * Get the 'event' schema.
819
+     *
820
+     * @return array An array with the schema configuration.
821
+     *
822
+     * @since 3.1.0
823
+     */
824
+    private function get_event_schema() {
825
+
826
+        $schema = array(
827
+            'label'         => 'Event',
828
+            'description'   => 'An event . ',
829
+            'parents'       => array( 'thing' ),
830
+            'css_class'     => 'wl-event',
831
+            'uri'           => self::SCHEMA_EVENT_TYPE,
832
+            'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
833
+            'custom_fields' => array(
834
+                self::FIELD_DATE_START => array(
835
+                    'predicate'   => 'http://schema.org/startDate',
836
+                    'type'        => self::DATA_TYPE_DATE,
837
+                    'export_type' => 'xsd:dateTime',
838
+                    'constraints' => '',
839
+                ),
840
+                self::FIELD_DATE_END   => array(
841
+                    'predicate'   => 'http://schema.org/endDate',
842
+                    'type'        => self::DATA_TYPE_DATE,
843
+                    'export_type' => 'xsd:dateTime',
844
+                    'constraints' => '',
845
+                ),
846
+                self::FIELD_LOCATION   => array(
847
+                    'predicate'   => 'http://schema.org/location',
848
+                    'type'        => self::DATA_TYPE_URI,
849
+                    'export_type' => 'http://schema.org/PostalAddress',
850
+                    'constraints' => array(
851
+                        'uri_type'    => array( 'Place', 'LocalBusiness' ),
852
+                        'cardinality' => INF,
853
+                    ),
854
+                ),
855
+                self::FIELD_PERFORMER  => array(
856
+                    'predicate'   => 'http://schema.org/performer',
857
+                    'type'        => self::DATA_TYPE_URI,
858
+                    'export_type' => 'http://schema.org/Person',
859
+                    'constraints' => array(
860
+                        'uri_type'    => array( 'Person', 'Organization' ),
861
+                        'cardinality' => INF,
862
+                    ),
863
+                ),
864
+                self::FIELD_OFFERS     => array(
865
+                    'predicate'   => 'http://schema.org/offers',
866
+                    'type'        => self::DATA_TYPE_URI,
867
+                    'export_type' => 'http://schema.org/Offer',
868
+                    'constraints' => array(
869
+                        'uri_type'    => array( 'Offer' ),
870
+                        'cardinality' => INF,
871
+                    ),
872
+                ),
873
+            ),
874
+            'linked_data'   => array(
875
+                // ### schema:startDate.
876
+                $this->rendition_factory->create(
877
+                    $this->storage_factory->post_meta( self::FIELD_DATE_START ),
878
+                    'http://schema.org/startDate',
879
+                    self::DATA_TYPE_DATE_TIME
880
+                ),
881
+                // ### schema:endDate.
882
+                $this->rendition_factory->create(
883
+                    $this->storage_factory->post_meta( self::FIELD_DATE_END ),
884
+                    'http://schema.org/endDate',
885
+                    self::DATA_TYPE_DATE_TIME
886
+                ),
887
+                // ### schema:location.
888
+                $this->rendition_factory->create(
889
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_LOCATION ),
890
+                    'http://schema.org/location',
891
+                    self::DATA_TYPE_URI
892
+                ),
893
+                // ### schema:performer.
894
+                $this->rendition_factory->create(
895
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_PERFORMER ),
896
+                    'http://schema.org/performer',
897
+                    self::DATA_TYPE_URI
898
+                ),
899
+                // ### schema:offers.
900
+                $this->rendition_factory->create(
901
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_OFFERS ),
902
+                    'http://schema.org/offers',
903
+                    self::DATA_TYPE_URI
904
+                ),
905
+            ),
906
+            'templates'     => array(
907
+                'subtitle' => '{{id}}',
908
+            ),
909
+        );
910
+
911
+        // Merge the custom fields with those provided by the thing schema.
912
+        $parent_schema           = $this->get_thing_schema();
913
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
914
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
915
+
916
+        return $schema;
917
+    }
918
+
919
+    /**
920
+     * Get the 'organization' schema.
921
+     *
922
+     * @return array An array with the schema configuration.
923
+     *
924
+     * @since 3.1.0
925
+     */
926
+    private function get_organization_schema() {
927
+
928
+        $schema = array(
929
+            'label'         => 'Organization',
930
+            'description'   => 'An organization, including a government or a newspaper.',
931
+            'parents'       => array( 'thing' ),
932
+            'css_class'     => 'wl-organization',
933
+            'uri'           => 'http://schema.org/Organization',
934
+            'same_as'       => array(
935
+                'http://rdf.freebase.com/ns/organization.organization',
936
+                'http://rdf.freebase.com/ns/government.government',
937
+                'http://schema.org/Newspaper',
938
+            ),
939
+            'custom_fields' => array(
940
+                self::FIELD_LEGAL_NAME          => array(
941
+                    'predicate'   => 'http://schema.org/legalName',
942
+                    'type'        => self::DATA_TYPE_STRING,
943
+                    'export_type' => 'xsd:string',
944
+                    'constraints' => '',
945
+                ),
946
+                self::FIELD_FOUNDER             => array(
947
+                    'predicate'   => 'http://schema.org/founder',
948
+                    'type'        => self::DATA_TYPE_URI,
949
+                    'export_type' => 'http://schema.org/Person',
950
+                    'constraints' => array(
951
+                        'uri_type'    => 'Person',
952
+                        'cardinality' => INF,
953
+                    ),
954
+                ),
955
+                self::FIELD_ADDRESS             => array(
956
+                    'predicate'   => 'http://schema.org/streetAddress',
957
+                    'type'        => self::DATA_TYPE_STRING,
958
+                    'export_type' => 'xsd:string',
959
+                    'constraints' => '',
960
+                    // To build custom metabox.
961
+                    'input_field' => 'address',
962
+                ),
963
+                self::FIELD_ADDRESS_PO_BOX      => array(
964
+                    'predicate'   => 'http://schema.org/postOfficeBoxNumber',
965
+                    'type'        => self::DATA_TYPE_STRING,
966
+                    'export_type' => 'xsd:string',
967
+                    'constraints' => '',
968
+                    // To build custom metabox.
969
+                    'input_field' => 'address',
970
+                ),
971
+                self::FIELD_ADDRESS_POSTAL_CODE => array(
972
+                    'predicate'   => 'http://schema.org/postalCode',
973
+                    'type'        => self::DATA_TYPE_STRING,
974
+                    'export_type' => 'xsd:string',
975
+                    'constraints' => '',
976
+                    // To build custom metabox.
977
+                    'input_field' => 'address',
978
+                ),
979
+                self::FIELD_ADDRESS_LOCALITY    => array(
980
+                    'predicate'   => 'http://schema.org/addressLocality',
981
+                    'type'        => self::DATA_TYPE_STRING,
982
+                    'export_type' => 'xsd:string',
983
+                    'constraints' => '',
984
+                    // To build custom metabox.
985
+                    'input_field' => 'address',
986
+                ),
987
+                self::FIELD_ADDRESS_REGION      => array(
988
+                    'predicate'   => 'http://schema.org/addressRegion',
989
+                    'type'        => self::DATA_TYPE_STRING,
990
+                    'export_type' => 'xsd:string',
991
+                    'constraints' => '',
992
+                    // To build custom metabox.
993
+                    'input_field' => 'address',
994
+                ),
995
+                self::FIELD_ADDRESS_COUNTRY     => array(
996
+                    'predicate'   => 'http://schema.org/addressCountry',
997
+                    'type'        => self::DATA_TYPE_STRING,
998
+                    'export_type' => 'xsd:string',
999
+                    'constraints' => '',
1000
+                    // To build custom metabox.
1001
+                    'input_field' => 'address',
1002
+                ),
1003
+                self::FIELD_EMAIL               => array(
1004
+                    'predicate'   => 'http://schema.org/email',
1005
+                    'type'        => self::DATA_TYPE_STRING,
1006
+                    'export_type' => 'xsd:string',
1007
+                    'constraints' => '',
1008
+                ),
1009
+                self::FIELD_TELEPHONE           => array(
1010
+                    'predicate'   => 'http://schema.org/telephone',
1011
+                    'type'        => self::DATA_TYPE_STRING,
1012
+                    'export_type' => 'xsd:string',
1013
+                    'constraints' => '',
1014
+                ),
1015
+            ),
1016
+            'linked_data'   => array(
1017
+                // ### schema:legalName.
1018
+                $this->rendition_factory->create(
1019
+                    $this->storage_factory->post_meta( self::FIELD_LEGAL_NAME ),
1020
+                    'http://schema.org/legalName'
1021
+                ),
1022
+                // ### schema:founder.
1023
+                $this->rendition_factory->create(
1024
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_FOUNDER ),
1025
+                    'http://schema.org/founder',
1026
+                    self::DATA_TYPE_URI
1027
+                ),
1028
+                // ### schema:email.
1029
+                $this->rendition_factory->create(
1030
+                    $this->storage_factory->post_meta( self::FIELD_EMAIL ),
1031
+                    'http://schema.org/email'
1032
+                ),
1033
+                // ### schema:telephone.
1034
+                $this->rendition_factory->create(
1035
+                    $this->storage_factory->post_meta( self::FIELD_TELEPHONE ),
1036
+                    'http://schema.org/telephone'
1037
+                ),
1038
+            ),
1039
+            'templates'     => array(
1040
+                'subtitle' => '{{id}}',
1041
+            ),
1042
+        );
1043
+
1044
+        // Merge the custom fields with those provided by the thing schema.
1045
+        $parent_schema           = $this->get_thing_schema();
1046
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1047
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1048
+
1049
+        return $schema;
1050
+    }
1051
+
1052
+    /**
1053
+     * Get the 'person' schema.
1054
+     *
1055
+     * @return array An array with the schema configuration.
1056
+     *
1057
+     * @since 3.1.0
1058
+     */
1059
+    private function get_person_schema() {
1060
+
1061
+        $schema = array(
1062
+            'label'         => 'Person',
1063
+            'description'   => 'A person (or a music artist).',
1064
+            'parents'       => array( 'thing' ),
1065
+            'css_class'     => 'wl-person',
1066
+            'uri'           => 'http://schema.org/Person',
1067
+            'same_as'       => array(
1068
+                'http://rdf.freebase.com/ns/people.person',
1069
+                'http://rdf.freebase.com/ns/music.artist',
1070
+                'http://dbpedia.org/class/yago/LivingPeople',
1071
+            ),
1072
+            'custom_fields' => array(
1073
+                self::FIELD_KNOWS       => array(
1074
+                    'predicate'   => 'http://schema.org/knows',
1075
+                    'type'        => self::DATA_TYPE_URI,
1076
+                    'export_type' => 'http://schema.org/Person',
1077
+                    'constraints' => array(
1078
+                        'uri_type'    => 'Person',
1079
+                        'cardinality' => INF,
1080
+                    ),
1081
+                ),
1082
+                self::FIELD_BIRTH_DATE  => array(
1083
+                    'predicate'   => 'http://schema.org/birthDate',
1084
+                    'type'        => self::DATA_TYPE_DATE,
1085
+                    'export_type' => 'xsd:date',
1086
+                    'constraints' => '',
1087
+                ),
1088
+                self::FIELD_BIRTH_PLACE => array(
1089
+                    'predicate'   => 'http://schema.org/birthPlace',
1090
+                    'type'        => self::DATA_TYPE_URI,
1091
+                    'export_type' => 'http://schema.org/Place',
1092
+                    'constraints' => array(
1093
+                        'uri_type' => 'Place',
1094
+                    ),
1095
+                ),
1096
+                self::FIELD_AFFILIATION => array(
1097
+                    'predicate'   => 'http://schema.org/affiliation',
1098
+                    'type'        => self::DATA_TYPE_URI,
1099
+                    'export_type' => 'http://schema.org/Organization',
1100
+                    'constraints' => array(
1101
+                        'uri_type'    => array(
1102
+                            'Organization',
1103
+                            'LocalBusiness',
1104
+                        ),
1105
+                        'cardinality' => INF,
1106
+                    ),
1107
+                ),
1108
+                self::FIELD_EMAIL       => array(
1109
+                    'predicate'   => 'http://schema.org/email',
1110
+                    'type'        => self::DATA_TYPE_STRING,
1111
+                    'export_type' => 'xsd:string',
1112
+                    'constraints' => array(
1113
+                        'cardinality' => INF,
1114
+                    ),
1115
+                ),
1116
+            ),
1117
+            'linked_data'   => array(
1118
+                // ### schema:knows.
1119
+                $this->rendition_factory->create(
1120
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_KNOWS ),
1121
+                    'http://schema.org/knows',
1122
+                    self::DATA_TYPE_URI
1123
+                ),
1124
+                // ### schema:birthDate.
1125
+                $this->rendition_factory->create(
1126
+                    $this->storage_factory->post_meta( self::FIELD_BIRTH_DATE ),
1127
+                    'http://schema.org/birthDate',
1128
+                    self::DATA_TYPE_DATE
1129
+                ),
1130
+                // ### schema:birthPlace.
1131
+                $this->rendition_factory->create(
1132
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_BIRTH_PLACE ),
1133
+                    'http://schema.org/birthPlace',
1134
+                    self::DATA_TYPE_URI
1135
+                ),
1136
+                // ### schema:affiliation.
1137
+                $this->rendition_factory->create(
1138
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_AFFILIATION ),
1139
+                    'http://schema.org/affiliation',
1140
+                    self::DATA_TYPE_URI
1141
+                ),
1142
+                // ### schema:email.
1143
+                $this->rendition_factory->create(
1144
+                    $this->storage_factory->post_meta( self::FIELD_EMAIL ),
1145
+                    'http://schema.org/email'
1146
+                ),
1147
+            ),
1148
+            'templates'     => array(
1149
+                'subtitle' => '{{id}}',
1150
+            ),
1151
+        );
1152
+
1153
+        // Merge the custom fields with those provided by the thing schema.
1154
+        $parent_schema           = $this->get_thing_schema();
1155
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1156
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1157
+
1158
+        return $schema;
1159
+
1160
+    }
1161
+
1162
+    /**
1163
+     * Get the 'place' schema.
1164
+     *
1165
+     * @return array An array with the schema configuration.
1166
+     *
1167
+     * @since 3.1.0
1168
+     */
1169
+    private function get_place_schema() {
1170
+
1171
+        $schema = array(
1172
+            'label'         => 'Place',
1173
+            'description'   => 'A place.',
1174
+            'parents'       => array( 'thing' ),
1175
+            'css_class'     => 'wl-place',
1176
+            'uri'           => 'http://schema.org/Place',
1177
+            'same_as'       => array(
1178
+                'http://rdf.freebase.com/ns/location.location',
1179
+                'http://www.opengis.net/gml/_Feature',
1180
+            ),
1181
+            'custom_fields' => array(
1182
+                self::FIELD_GEO_LATITUDE        => array(
1183
+                    'predicate'   => 'http://schema.org/latitude',
1184
+                    'type'        => self::DATA_TYPE_DOUBLE,
1185
+                    'export_type' => 'xsd:double',
1186
+                    'constraints' => '',
1187
+                    // To build custom metabox.
1188
+                    'input_field' => 'coordinates',
1189
+                ),
1190
+                self::FIELD_GEO_LONGITUDE       => array(
1191
+                    'predicate'   => 'http://schema.org/longitude',
1192
+                    'type'        => self::DATA_TYPE_DOUBLE,
1193
+                    'export_type' => 'xsd:double',
1194
+                    'constraints' => '',
1195
+                    // To build custom metabox.
1196
+                    'input_field' => 'coordinates',
1197
+                ),
1198
+                self::FIELD_ADDRESS             => array(
1199
+                    'predicate'   => 'http://schema.org/streetAddress',
1200
+                    'type'        => self::DATA_TYPE_STRING,
1201
+                    'export_type' => 'xsd:string',
1202
+                    'constraints' => '',
1203
+                    // To build custom metabox.
1204
+                    'input_field' => 'address',
1205
+                ),
1206
+                self::FIELD_ADDRESS_PO_BOX      => array(
1207
+                    'predicate'   => 'http://schema.org/postOfficeBoxNumber',
1208
+                    'type'        => self::DATA_TYPE_STRING,
1209
+                    'export_type' => 'xsd:string',
1210
+                    'constraints' => '',
1211
+                    // To build custom metabox.
1212
+                    'input_field' => 'address',
1213
+                ),
1214
+                self::FIELD_ADDRESS_POSTAL_CODE => array(
1215
+                    'predicate'   => 'http://schema.org/postalCode',
1216
+                    'type'        => self::DATA_TYPE_STRING,
1217
+                    'export_type' => 'xsd:string',
1218
+                    'constraints' => '',
1219
+                    // To build custom metabox.
1220
+                    'input_field' => 'address',
1221
+                ),
1222
+                self::FIELD_ADDRESS_LOCALITY    => array(
1223
+                    'predicate'   => 'http://schema.org/addressLocality',
1224
+                    'type'        => self::DATA_TYPE_STRING,
1225
+                    'export_type' => 'xsd:string',
1226
+                    'constraints' => '',
1227
+                    // To build custom metabox.
1228
+                    'input_field' => 'address',
1229
+                ),
1230
+                self::FIELD_ADDRESS_REGION      => array(
1231
+                    'predicate'   => 'http://schema.org/addressRegion',
1232
+                    'type'        => self::DATA_TYPE_STRING,
1233
+                    'export_type' => 'xsd:string',
1234
+                    'constraints' => '',
1235
+                    // To build custom metabox.
1236
+                    'input_field' => 'address',
1237
+                ),
1238
+                self::FIELD_ADDRESS_COUNTRY     => array(
1239
+                    'predicate'   => 'http://schema.org/addressCountry',
1240
+                    'type'        => self::DATA_TYPE_STRING,
1241
+                    'export_type' => 'xsd:string',
1242
+                    'constraints' => '',
1243
+                    // To build custom metabox.
1244
+                    'input_field' => 'address',
1245
+                ),
1246
+            ),
1247
+            'linked_data'   => array(
1248
+                $this->rendition_factory->create_address(
1249
+                    $this->storage_factory,
1250
+                    $this->language_code
1251
+                ),
1252
+            ),
1253
+            'templates'     => array(
1254
+                'subtitle' => '{{id}}',
1255
+            ),
1256
+        );
1257
+
1258
+        // Merge the custom fields with those provided by the thing schema.
1259
+        $parent_schema           = $this->get_thing_schema();
1260
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1261
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1262
+
1263
+        return $schema;
1264
+    }
1265
+
1266
+    /**
1267
+     * Get the 'local business' schema.
1268
+     *
1269
+     * @return array An array with the schema configuration.
1270
+     *
1271
+     * @since 3.1.0
1272
+     */
1273
+    private function get_local_business_schema() {
1274
+
1275
+        $schema = array(
1276
+            'label'         => 'LocalBusiness',
1277
+            'description'   => 'A local business.',
1278
+            'parents'       => array( 'place', 'organization' ),
1279
+            'css_class'     => 'wl-local-business',
1280
+            'uri'           => 'http://schema.org/LocalBusiness',
1281
+            'same_as'       => array(
1282
+                'http://rdf.freebase.com/ns/business/business_location',
1283
+                'https://schema.org/Store',
1284
+            ),
1285
+            'custom_fields' => array(),
1286
+            'linked_data'   => array(),
1287
+            'templates'     => array(
1288
+                'subtitle' => '{{id}}',
1289
+            ),
1290
+        );
1291
+
1292
+        // Merge the custom fields with those provided by the place and organization schema.
1293
+        $place_schema            = $this->get_place_schema();
1294
+        $organization_schema     = $this->get_organization_schema();
1295
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
1296
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $place_schema['linked_data'], $organization_schema['linked_data'] );
1297
+
1298
+        return $schema;
1299
+    }
1300
+
1301
+    /**
1302
+     * Get the 'recipe' schema.
1303
+     *
1304
+     * @return array An array with the schema configuration.
1305
+     *
1306
+     * @since 3.14.0
1307
+     */
1308
+    private function get_recipe_schema() {
1309
+
1310
+        $schema = array(
1311
+            'label'         => 'Recipe',
1312
+            'description'   => 'A Recipe.',
1313
+            'parents'       => array( 'CreativeWork' ),
1314
+            'css_class'     => 'wl-recipe',
1315
+            'uri'           => 'http://schema.org/Recipe',
1316
+            'same_as'       => array(),
1317
+            'templates'     => array(
1318
+                'subtitle' => '{{id}}',
1319
+            ),
1320
+            'custom_fields' => array(
1321
+                self::FIELD_RECIPE_CUISINE          => array(
1322
+                    'predicate'   => 'http://schema.org/recipeCuisine',
1323
+                    'type'        => self::DATA_TYPE_STRING,
1324
+                    'export_type' => 'xsd:string',
1325
+                    'constraints' => '',
1326
+                    'metabox'     => array(
1327
+                        'label' => __( 'Recipe cuisine', 'wordlift' ),
1328
+                    ),
1329
+                ),
1330
+                self::FIELD_RECIPE_INGREDIENT       => array(
1331
+                    'predicate'   => 'http://schema.org/recipeIngredient',
1332
+                    'type'        => self::DATA_TYPE_STRING,
1333
+                    'export_type' => 'xsd:string',
1334
+                    'constraints' => array(
1335
+                        'cardinality' => INF,
1336
+                    ),
1337
+                    'metabox'     => array(
1338
+                        'label' => __( 'Recipe ingredient', 'wordlift' ),
1339
+                    ),
1340
+                ),
1341
+                self::FIELD_RECIPE_INSTRUCTIONS     => array(
1342
+                    'predicate'   => 'http://schema.org/recipeInstructions',
1343
+                    'type'        => self::DATA_TYPE_MULTILINE,
1344
+                    'export_type' => 'xsd:string',
1345
+                    'constraints' => '',
1346
+                    'metabox'     => array(
1347
+                        'class' => 'Wordlift_Metabox_Field_Multiline',
1348
+                        'label' => __( 'Recipe instructions', 'wordlift' ),
1349
+                    ),
1350
+                ),
1351
+                self::FIELD_RECIPE_YIELD            => array(
1352
+                    'predicate'   => 'http://schema.org/recipeYield',
1353
+                    'type'        => self::DATA_TYPE_STRING,
1354
+                    'export_type' => 'xsd:string',
1355
+                    'constraints' => '',
1356
+                    'metabox'     => array(
1357
+                        'label' => __( 'Recipe number of servings', 'wordlift' ),
1358
+                    ),
1359
+                ),
1360
+                self::FIELD_RECIPE_INGREDIENT       => array(
1361
+                    'predicate'   => 'http://schema.org/recipeIngredient',
1362
+                    'type'        => self::DATA_TYPE_STRING,
1363
+                    'export_type' => 'xsd:string',
1364
+                    'constraints' => array(
1365
+                        'cardinality' => INF,
1366
+                    ),
1367
+                    'metabox'     => array(
1368
+                        'label' => __( 'Recipe ingredient', 'wordlift' ),
1369
+                    ),
1370
+                ),
1371
+                self::FIELD_NUTRITION_INFO_CALORIES => array(
1372
+                    'predicate'   => 'http://schema.org/calories',
1373
+                    'type'        => self::DATA_TYPE_STRING,
1374
+                    'export_type' => 'xsd:string',
1375
+                    'constraints' => '',
1376
+                    'metabox'     => array(
1377
+                        'label' => __( 'Calories (e.g. 240 calories)', 'wordlift' ),
1378
+                    ),
1379
+                ),
1380
+                self::FIELD_PREP_TIME               => array(
1381
+                    'predicate'   => 'http://schema.org/prepTime',
1382
+                    'type'        => self::DATA_TYPE_DURATION,
1383
+                    'export_type' => 'xsd:time',
1384
+                    'constraints' => '',
1385
+                    'metabox'     => array(
1386
+                        'class' => 'Wordlift_Metabox_Field_Duration',
1387
+                        'label' => __( 'Recipe preparation time (e.g. 1:30)', 'wordlift' ),
1388
+                    ),
1389
+                ),
1390
+                self::FIELD_COOK_TIME               => array(
1391
+                    'predicate'   => 'http://schema.org/cookTime',
1392
+                    'type'        => self::DATA_TYPE_DURATION,
1393
+                    'export_type' => 'xsd:time',
1394
+                    'constraints' => '',
1395
+                    'metabox'     => array(
1396
+                        'class' => 'Wordlift_Metabox_Field_Duration',
1397
+                        'label' => __( 'Recipe cook time (e.g. 1:30)', 'wordlift' ),
1398
+                    ),
1399
+                ),
1400
+                self::FIELD_TOTAL_TIME              => array(
1401
+                    'predicate'   => 'http://schema.org/totalTime',
1402
+                    'type'        => self::DATA_TYPE_DURATION,
1403
+                    'export_type' => 'xsd:time',
1404
+                    'constraints' => '',
1405
+                    'metabox'     => array(
1406
+                        'class' => 'Wordlift_Metabox_Field_Duration',
1407
+                        'label' => __( 'Recipe total time (e.g. 1:30)', 'wordlift' ),
1408
+                    ),
1409
+                ),
1410
+            ),
1411
+            'linked_data'   => array(
1412
+                // ### schema:recipeCuisine.
1413
+                $this->rendition_factory->create(
1414
+                    $this->storage_factory->post_meta( self::FIELD_RECIPE_CUISINE ),
1415
+                    'http://schema.org/recipeCuisine'
1416
+                ),
1417
+                // ### schema:recipeIngredient.
1418
+                $this->rendition_factory->create(
1419
+                    $this->storage_factory->post_meta( self::FIELD_RECIPE_INGREDIENT ),
1420
+                    'http://schema.org/recipeIngredient'
1421
+                ),
1422
+                // ### schema:recipeInstructions.
1423
+                $this->rendition_factory->create(
1424
+                    $this->storage_factory->post_meta( self::FIELD_RECIPE_INSTRUCTIONS ),
1425
+                    'http://schema.org/recipeInstructions'
1426
+                ),
1427
+                // ### schema:recipeYield.
1428
+                $this->rendition_factory->create(
1429
+                    $this->storage_factory->post_meta( self::FIELD_RECIPE_YIELD ),
1430
+                    'http://schema.org/recipeYield'
1431
+                ),
1432
+                // ### schema:prepTime.
1433
+                $this->rendition_factory->create(
1434
+                    $this->storage_factory->post_meta( self::FIELD_PREP_TIME ),
1435
+                    'http://schema.org/prepTime',
1436
+                    self::DATA_TYPE_DURATION
1437
+                ),
1438
+                // ### schema:cookTime.
1439
+                $this->rendition_factory->create(
1440
+                    $this->storage_factory->post_meta( self::FIELD_COOK_TIME ),
1441
+                    'http://schema.org/cookTime',
1442
+                    self::DATA_TYPE_DURATION
1443
+                ),
1444
+                // ### schema:totalTime.
1445
+                $this->rendition_factory->create(
1446
+                    $this->storage_factory->post_meta( self::FIELD_TOTAL_TIME ),
1447
+                    'http://schema.org/totalTime',
1448
+                    self::DATA_TYPE_DURATION
1449
+                ),
1450
+            ),
1451
+        );
1452
+
1453
+        // Merge the custom fields with those provided by the parent schema.
1454
+        $parent_schema           = $this->get_creative_work_schema();
1455
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1456
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1457
+
1458
+        return $schema;
1459
+    }
1460
+
1461
+    /**
1462
+     * Get the 'offer' schema.
1463
+     *
1464
+     * @return array An array with the schema configuration.
1465
+     *
1466
+     * @since 3.18.0
1467
+     */
1468
+    private function get_offer_schema() {
1469
+
1470
+        $schema = array(
1471
+            'label'         => 'Offer',
1472
+            'description'   => 'An offer. ',
1473
+            'parents'       => array( 'thing' ),
1474
+            'css_class'     => 'wl-offer',
1475
+            'uri'           => self::SCHEMA_OFFER_TYPE,
1476
+            'same_as'       => array(),
1477
+            'templates'     => array(
1478
+                'subtitle' => '{{id}}',
1479
+            ),
1480
+            'custom_fields' => array(
1481
+                self::FIELD_AVAILABILITY        => array(
1482
+                    'predicate'   => 'http://schema.org/availability',
1483
+                    'type'        => self::DATA_TYPE_STRING,
1484
+                    'export_type' => 'xsd:string',
1485
+                    'metabox'     => array(
1486
+                        'class' => 'Wordlift_Metabox_Field_Select',
1487
+                    ),
1488
+                    'options'     => array(
1489
+                        'Discontinued'        => esc_html__( 'Discontinued', 'wordlift' ),
1490
+                        'InStock'             => esc_html__( 'In Stock', 'wordlift' ),
1491
+                        'InStoreOnly'         => esc_html__( 'In Store Only', 'wordlift' ),
1492
+                        'LimitedAvailability' => esc_html__( 'Limited Availability', 'wordlift' ),
1493
+                        'OnlineOnly'          => esc_html__( 'Online Only', 'wordlift' ),
1494
+                        'OutOfStock'          => esc_html__( 'Out of Stock', 'wordlift' ),
1495
+                        'PreOrder'            => esc_html__( 'Pre Order', 'wordlift' ),
1496
+                        'PreSale'             => esc_html__( 'Pre Sale', 'wordlift' ),
1497
+                        'SoldOut'             => esc_html__( 'Sold Out', 'wordlift' ),
1498
+                    ),
1499
+                ),
1500
+                self::FIELD_PRICE               => array(
1501
+                    'predicate'   => 'http://schema.org/price',
1502
+                    'type'        => self::DATA_TYPE_STRING,
1503
+                    'export_type' => 'xsd:integer',
1504
+                    'metabox'     => array(
1505
+                        'class' => 'Wordlift_Metabox_Field_Integer',
1506
+                    ),
1507
+                ),
1508
+                self::FIELD_PRICE_CURRENCY      => array(
1509
+                    'predicate'   => 'http://schema.org/priceCurrency',
1510
+                    'type'        => self::DATA_TYPE_STRING,
1511
+                    'export_type' => 'xsd:string',
1512
+                ),
1513
+                self::FIELD_AVAILABILITY_STARTS => array(
1514
+                    'predicate'   => 'http://schema.org/availabilityStarts',
1515
+                    'type'        => self::DATA_TYPE_DATE,
1516
+                    'export_type' => 'xsd:dateTime',
1517
+                ),
1518
+                self::FIELD_AVAILABILITY_ENDS   => array(
1519
+                    'predicate'   => 'http://schema.org/availabilityEnds',
1520
+                    'type'        => self::DATA_TYPE_DATE,
1521
+                    'export_type' => 'xsd:dateTime',
1522
+                ),
1523
+                self::FIELD_INVENTORY_LEVEL     => array(
1524
+                    'predicate'   => 'http://schema.org/inventoryLevel',
1525
+                    'type'        => self::DATA_TYPE_STRING,
1526
+                    'export_type' => 'xsd:integer',
1527
+                    'metabox'     => array(
1528
+                        'class' => 'Wordlift_Metabox_Field_Integer',
1529
+                    ),
1530
+                ),
1531
+                self::FIELD_VALID_FROM          => array(
1532
+                    'predicate'   => 'http://schema.org/validFrom',
1533
+                    'type'        => self::DATA_TYPE_DATE,
1534
+                    'export_type' => 'xsd:dateTime',
1535
+                ),
1536
+                self::FIELD_PRICE_VALID_UNTIL   => array(
1537
+                    'predicate'   => 'http://schema.org/priceValidUntil',
1538
+                    'type'        => self::DATA_TYPE_DATE,
1539
+                    'export_type' => 'xsd:dateTime',
1540
+                ),
1541
+                self::FIELD_ITEM_OFFERED        => array(
1542
+                    'predicate'   => 'http://schema.org/itemOffered',
1543
+                    'type'        => self::DATA_TYPE_URI,
1544
+                    'export_type' => 'http://schema.org/Thing',
1545
+                    'constraints' => array(
1546
+                        'uri_type'    => array(
1547
+                            'Event',
1548
+                            'Thing',
1549
+                        ),
1550
+                        'cardinality' => INF,
1551
+                    ),
1552
+                ),
1553
+            ),
1554
+            'linked_data'   => array(
1555
+                // ### schema:availability.
1556
+                $this->rendition_factory->create(
1557
+                    $this->storage_factory->post_meta( self::FIELD_AVAILABILITY ),
1558
+                    'http://schema.org/availability',
1559
+                    null
1560
+                ),
1561
+                // ### schema:availabilityStarts.
1562
+                $this->rendition_factory->create(
1563
+                    $this->storage_factory->post_meta( self::FIELD_AVAILABILITY_STARTS ),
1564
+                    'http://schema.org/availabilityStarts',
1565
+                    self::DATA_TYPE_DATE_TIME
1566
+                ),
1567
+                // ### schema:availabilityEnds.
1568
+                $this->rendition_factory->create(
1569
+                    $this->storage_factory->post_meta( self::FIELD_AVAILABILITY_ENDS ),
1570
+                    'http://schema.org/availabilityEnds',
1571
+                    self::DATA_TYPE_DATE_TIME
1572
+                ),
1573
+                // ### schema:inventoryLevel.
1574
+                $this->rendition_factory->create(
1575
+                    $this->storage_factory->post_meta( self::FIELD_INVENTORY_LEVEL ),
1576
+                    'http://schema.org/inventoryLevel',
1577
+                    self::DATA_TYPE_INTEGER
1578
+                ),
1579
+                // ### schema:price.
1580
+                $this->rendition_factory->create(
1581
+                    $this->storage_factory->post_meta( self::FIELD_PRICE ),
1582
+                    'http://schema.org/price',
1583
+                    self::DATA_TYPE_INTEGER
1584
+                ),
1585
+                // ### schema:priceCurrency.
1586
+                $this->rendition_factory->create(
1587
+                    $this->storage_factory->post_meta( self::FIELD_PRICE_CURRENCY ),
1588
+                    'http://schema.org/priceCurrency',
1589
+                    null
1590
+                ),
1591
+                // ### schema:validFrom.
1592
+                $this->rendition_factory->create(
1593
+                    $this->storage_factory->post_meta( self::FIELD_VALID_FROM ),
1594
+                    'http://schema.org/validFrom',
1595
+                    null
1596
+                ),
1597
+                // ### schema:priceValidUntil.
1598
+                $this->rendition_factory->create(
1599
+                    $this->storage_factory->post_meta( self::FIELD_PRICE_VALID_UNTIL ),
1600
+                    'http://schema.org/priceValidUntil',
1601
+                    null
1602
+                ),
1603
+                // ### schema:itemOffered.
1604
+                $this->rendition_factory->create(
1605
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_ITEM_OFFERED ),
1606
+                    'http://schema.org/itemOffered',
1607
+                    self::DATA_TYPE_URI
1608
+                ),
1609
+            ),
1610
+        );
1611
+
1612
+        // Merge the custom fields with those provided by the thing schema.
1613
+        $parent_schema           = $this->get_thing_schema();
1614
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1615
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1616
+
1617
+        return $schema;
1618
+    }
1619
+
1620
+    /**
1621
+     * Get the 'article' schema.
1622
+     *
1623
+     * @return array An array with the schema configuration.
1624
+     *
1625
+     * @since 3.15.0
1626
+     */
1627
+    private function get_article_schema() {
1628
+
1629
+        $schema = array(
1630
+            'label'         => 'Article',
1631
+            'description'   => 'An Article.',
1632
+            'parents'       => array(),
1633
+            'css_class'     => 'wl-article',
1634
+            'uri'           => 'http://schema.org/Article',
1635
+            'same_as'       => array(),
1636
+            'templates'     => array(
1637
+                'subtitle' => '{{id}}',
1638
+            ),
1639
+            'custom_fields' => array(),
1640
+            'linked_data'   => array(
1641
+                // ### schema:headline.
1642
+                $this->rendition_factory->create(
1643
+                    $this->storage_factory->post_title(),
1644
+                    'http://schema.org/headline',
1645
+                    null,
1646
+                    $this->language_code
1647
+                ),
1648
+                // ### schema:url.
1649
+                $this->rendition_factory->create(
1650
+                    $this->storage_factory->url_property(),
1651
+                    Wordlift_Query_Builder::SCHEMA_URL_URI,
1652
+                    self::DATA_TYPE_URI
1653
+                ),
1654
+                // ### rdf:type.
1655
+                $this->rendition_factory->create(
1656
+                    $this->storage_factory->schema_class(),
1657
+                    Wordlift_Query_Builder::RDFS_TYPE_URI,
1658
+                    self::DATA_TYPE_URI
1659
+                ),
1660
+                // ### dcterms:references.
1661
+                $this->rendition_factory->create(
1662
+                    $this->storage_factory->relations(),
1663
+                    Wordlift_Query_Builder::DCTERMS_REFERENCES_URI,
1664
+                    self::DATA_TYPE_URI,
1665
+                    $this->language_code
1666
+                ),
1667
+            ),
1668
+        );
1669
+
1670
+        return $schema;
1671
+    }
1672 1672
 
1673 1673
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -467,9 +467,9 @@  discard block
 block discarded – undo
467 467
 	 * @param \Wordlift_Sparql_Tuple_Rendition_Factory $rendition_factory     The {@link Wordlift_Sparql_Tuple_Rendition_Factory} instance.
468 468
 	 * @param \Wordlift_Configuration_Service          $configuration_service The {@link Wordlift_Configuration_Service} instance.
469 469
 	 */
470
-	public function __construct( $storage_factory, $rendition_factory, $configuration_service ) {
470
+	public function __construct($storage_factory, $rendition_factory, $configuration_service) {
471 471
 
472
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
472
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Schema_Service');
473 473
 
474 474
 		$this->storage_factory       = $storage_factory;
475 475
 		$this->rendition_factory     = $rendition_factory;
@@ -519,18 +519,18 @@  discard block
 block discarded – undo
519 519
 	 *
520 520
 	 * @return null|array An array of field's properties or null if the field is not found.
521 521
 	 */
522
-	public function get_field( $key ) {
522
+	public function get_field($key) {
523 523
 
524 524
 		// Parse each schema's fields until we find the one we're looking for, then
525 525
 		// return its properties.
526
-		foreach ( $this->schema as $_ => $schema ) {
526
+		foreach ($this->schema as $_ => $schema) {
527 527
 
528
-			if ( ! isset( $schema['custom_fields'] ) ) {
528
+			if ( ! isset($schema['custom_fields'])) {
529 529
 				break;
530 530
 			}
531 531
 
532
-			foreach ( $schema['custom_fields'] as $field => $props ) {
533
-				if ( $key === $field ) {
532
+			foreach ($schema['custom_fields'] as $field => $props) {
533
+				if ($key === $field) {
534 534
 					return $props;
535 535
 				}
536 536
 			}
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
 		// Get the custom fields.
551 551
 		$renditions = array_reduce(
552 552
 			$this->schema,
553
-			function ( $carry, $item ) {
554
-				return array_merge( $carry, $item['linked_data'] );
553
+			function($carry, $item) {
554
+				return array_merge($carry, $item['linked_data']);
555 555
 			},
556 556
 			array()
557 557
 		);
@@ -569,14 +569,14 @@  discard block
 block discarded – undo
569 569
 	 *
570 570
 	 * @since 3.1.0
571 571
 	 */
572
-	public function get_schema( $name ) {
572
+	public function get_schema($name) {
573 573
 		// Check if the schema exists and, if not, return NULL.
574
-		if ( ! isset( $this->schema[ $name ] ) ) {
574
+		if ( ! isset($this->schema[$name])) {
575 575
 			return null;
576 576
 		}
577 577
 
578 578
 		// Return the requested schema.
579
-		return $this->schema[ $name ];
579
+		return $this->schema[$name];
580 580
 	}
581 581
 
582 582
 	/**
@@ -588,10 +588,10 @@  discard block
 block discarded – undo
588 588
 	 *
589 589
 	 * @since 3.3.0
590 590
 	 */
591
-	public function get_schema_by_uri( $uri ) {
591
+	public function get_schema_by_uri($uri) {
592 592
 
593
-		foreach ( $this->schema as $name => $schema ) {
594
-			if ( $schema['uri'] === $uri ) {
593
+		foreach ($this->schema as $name => $schema) {
594
+			if ($schema['uri'] === $uri) {
595 595
 				return $schema;
596 596
 			}
597 597
 		}
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 		return array(
612 612
 			'css_class'     => 'wl-thing',
613 613
 			'uri'           => 'http://schema.org/Thing',
614
-			'same_as'       => array( '*' ),
614
+			'same_as'       => array('*'),
615 615
 			// set as default.
616 616
 			'custom_fields' => array(
617 617
 				self::FIELD_SAME_AS                            => array(
@@ -650,14 +650,14 @@  discard block
 block discarded – undo
650 650
 				),
651 651
 				// ### Alternative title to rdfs:label.
652 652
 				$this->rendition_factory->create(
653
-					$this->storage_factory->post_meta( Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY ),
653
+					$this->storage_factory->post_meta(Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY),
654 654
 					Wordlift_Query_Builder::RDFS_LABEL_URI,
655 655
 					null,
656 656
 					$this->language_code
657 657
 				),
658 658
 				// ### Alternative title to dct:title.
659 659
 				$this->rendition_factory->create(
660
-					$this->storage_factory->post_meta( Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY ),
660
+					$this->storage_factory->post_meta(Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY),
661 661
 					'http://purl.org/dc/terms/title',
662 662
 					null,
663 663
 					$this->language_code
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
 				),
672 672
 				// ### Alternative title to schema:alterName.
673 673
 				$this->rendition_factory->create(
674
-					$this->storage_factory->post_meta( Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY ),
674
+					$this->storage_factory->post_meta(Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY),
675 675
 					'http://schema.org/alternateName',
676 676
 					null,
677 677
 					$this->language_code
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
 				),
692 692
 				// ### owl:sameAs.
693 693
 				$this->rendition_factory->create(
694
-					$this->storage_factory->post_meta( self::FIELD_SAME_AS ),
694
+					$this->storage_factory->post_meta(self::FIELD_SAME_AS),
695 695
 					'http://www.w3.org/2002/07/owl#sameAs',
696 696
 					self::DATA_TYPE_URI
697 697
 				),
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
 		$schema = array(
775 775
 			'label'         => 'CreativeWork',
776 776
 			'description'   => 'A creative work (or a Music Album).',
777
-			'parents'       => array( 'thing' ),
777
+			'parents'       => array('thing'),
778 778
 			// Give term slug as parent.
779 779
 			'css_class'     => 'wl-creative-work',
780 780
 			'uri'           => 'http://schema.org/CreativeWork',
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 					'type'        => self::DATA_TYPE_URI,
789 789
 					'export_type' => 'http://schema.org/Person',
790 790
 					'constraints' => array(
791
-						'uri_type'    => array( 'Person', 'Organization' ),
791
+						'uri_type'    => array('Person', 'Organization'),
792 792
 						'cardinality' => INF,
793 793
 					),
794 794
 				),
@@ -808,8 +808,8 @@  discard block
 block discarded – undo
808 808
 
809 809
 		// Merge the custom fields with those provided by the thing schema.
810 810
 		$parent_schema           = $this->get_thing_schema();
811
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
812
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
811
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
812
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
813 813
 
814 814
 		return $schema;
815 815
 	}
@@ -826,10 +826,10 @@  discard block
 block discarded – undo
826 826
 		$schema = array(
827 827
 			'label'         => 'Event',
828 828
 			'description'   => 'An event . ',
829
-			'parents'       => array( 'thing' ),
829
+			'parents'       => array('thing'),
830 830
 			'css_class'     => 'wl-event',
831 831
 			'uri'           => self::SCHEMA_EVENT_TYPE,
832
-			'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
832
+			'same_as'       => array('http://dbpedia.org/ontology/Event'),
833 833
 			'custom_fields' => array(
834 834
 				self::FIELD_DATE_START => array(
835 835
 					'predicate'   => 'http://schema.org/startDate',
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 					'type'        => self::DATA_TYPE_URI,
849 849
 					'export_type' => 'http://schema.org/PostalAddress',
850 850
 					'constraints' => array(
851
-						'uri_type'    => array( 'Place', 'LocalBusiness' ),
851
+						'uri_type'    => array('Place', 'LocalBusiness'),
852 852
 						'cardinality' => INF,
853 853
 					),
854 854
 				),
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
 					'type'        => self::DATA_TYPE_URI,
858 858
 					'export_type' => 'http://schema.org/Person',
859 859
 					'constraints' => array(
860
-						'uri_type'    => array( 'Person', 'Organization' ),
860
+						'uri_type'    => array('Person', 'Organization'),
861 861
 						'cardinality' => INF,
862 862
 					),
863 863
 				),
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
 					'type'        => self::DATA_TYPE_URI,
867 867
 					'export_type' => 'http://schema.org/Offer',
868 868
 					'constraints' => array(
869
-						'uri_type'    => array( 'Offer' ),
869
+						'uri_type'    => array('Offer'),
870 870
 						'cardinality' => INF,
871 871
 					),
872 872
 				),
@@ -874,31 +874,31 @@  discard block
 block discarded – undo
874 874
 			'linked_data'   => array(
875 875
 				// ### schema:startDate.
876 876
 				$this->rendition_factory->create(
877
-					$this->storage_factory->post_meta( self::FIELD_DATE_START ),
877
+					$this->storage_factory->post_meta(self::FIELD_DATE_START),
878 878
 					'http://schema.org/startDate',
879 879
 					self::DATA_TYPE_DATE_TIME
880 880
 				),
881 881
 				// ### schema:endDate.
882 882
 				$this->rendition_factory->create(
883
-					$this->storage_factory->post_meta( self::FIELD_DATE_END ),
883
+					$this->storage_factory->post_meta(self::FIELD_DATE_END),
884 884
 					'http://schema.org/endDate',
885 885
 					self::DATA_TYPE_DATE_TIME
886 886
 				),
887 887
 				// ### schema:location.
888 888
 				$this->rendition_factory->create(
889
-					$this->storage_factory->post_meta_to_uri( self::FIELD_LOCATION ),
889
+					$this->storage_factory->post_meta_to_uri(self::FIELD_LOCATION),
890 890
 					'http://schema.org/location',
891 891
 					self::DATA_TYPE_URI
892 892
 				),
893 893
 				// ### schema:performer.
894 894
 				$this->rendition_factory->create(
895
-					$this->storage_factory->post_meta_to_uri( self::FIELD_PERFORMER ),
895
+					$this->storage_factory->post_meta_to_uri(self::FIELD_PERFORMER),
896 896
 					'http://schema.org/performer',
897 897
 					self::DATA_TYPE_URI
898 898
 				),
899 899
 				// ### schema:offers.
900 900
 				$this->rendition_factory->create(
901
-					$this->storage_factory->post_meta_to_uri( self::FIELD_OFFERS ),
901
+					$this->storage_factory->post_meta_to_uri(self::FIELD_OFFERS),
902 902
 					'http://schema.org/offers',
903 903
 					self::DATA_TYPE_URI
904 904
 				),
@@ -910,8 +910,8 @@  discard block
 block discarded – undo
910 910
 
911 911
 		// Merge the custom fields with those provided by the thing schema.
912 912
 		$parent_schema           = $this->get_thing_schema();
913
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
914
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
913
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
914
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
915 915
 
916 916
 		return $schema;
917 917
 	}
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
 		$schema = array(
929 929
 			'label'         => 'Organization',
930 930
 			'description'   => 'An organization, including a government or a newspaper.',
931
-			'parents'       => array( 'thing' ),
931
+			'parents'       => array('thing'),
932 932
 			'css_class'     => 'wl-organization',
933 933
 			'uri'           => 'http://schema.org/Organization',
934 934
 			'same_as'       => array(
@@ -1016,23 +1016,23 @@  discard block
 block discarded – undo
1016 1016
 			'linked_data'   => array(
1017 1017
 				// ### schema:legalName.
1018 1018
 				$this->rendition_factory->create(
1019
-					$this->storage_factory->post_meta( self::FIELD_LEGAL_NAME ),
1019
+					$this->storage_factory->post_meta(self::FIELD_LEGAL_NAME),
1020 1020
 					'http://schema.org/legalName'
1021 1021
 				),
1022 1022
 				// ### schema:founder.
1023 1023
 				$this->rendition_factory->create(
1024
-					$this->storage_factory->post_meta_to_uri( self::FIELD_FOUNDER ),
1024
+					$this->storage_factory->post_meta_to_uri(self::FIELD_FOUNDER),
1025 1025
 					'http://schema.org/founder',
1026 1026
 					self::DATA_TYPE_URI
1027 1027
 				),
1028 1028
 				// ### schema:email.
1029 1029
 				$this->rendition_factory->create(
1030
-					$this->storage_factory->post_meta( self::FIELD_EMAIL ),
1030
+					$this->storage_factory->post_meta(self::FIELD_EMAIL),
1031 1031
 					'http://schema.org/email'
1032 1032
 				),
1033 1033
 				// ### schema:telephone.
1034 1034
 				$this->rendition_factory->create(
1035
-					$this->storage_factory->post_meta( self::FIELD_TELEPHONE ),
1035
+					$this->storage_factory->post_meta(self::FIELD_TELEPHONE),
1036 1036
 					'http://schema.org/telephone'
1037 1037
 				),
1038 1038
 			),
@@ -1043,8 +1043,8 @@  discard block
 block discarded – undo
1043 1043
 
1044 1044
 		// Merge the custom fields with those provided by the thing schema.
1045 1045
 		$parent_schema           = $this->get_thing_schema();
1046
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1047
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1046
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
1047
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
1048 1048
 
1049 1049
 		return $schema;
1050 1050
 	}
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
 		$schema = array(
1062 1062
 			'label'         => 'Person',
1063 1063
 			'description'   => 'A person (or a music artist).',
1064
-			'parents'       => array( 'thing' ),
1064
+			'parents'       => array('thing'),
1065 1065
 			'css_class'     => 'wl-person',
1066 1066
 			'uri'           => 'http://schema.org/Person',
1067 1067
 			'same_as'       => array(
@@ -1117,31 +1117,31 @@  discard block
 block discarded – undo
1117 1117
 			'linked_data'   => array(
1118 1118
 				// ### schema:knows.
1119 1119
 				$this->rendition_factory->create(
1120
-					$this->storage_factory->post_meta_to_uri( self::FIELD_KNOWS ),
1120
+					$this->storage_factory->post_meta_to_uri(self::FIELD_KNOWS),
1121 1121
 					'http://schema.org/knows',
1122 1122
 					self::DATA_TYPE_URI
1123 1123
 				),
1124 1124
 				// ### schema:birthDate.
1125 1125
 				$this->rendition_factory->create(
1126
-					$this->storage_factory->post_meta( self::FIELD_BIRTH_DATE ),
1126
+					$this->storage_factory->post_meta(self::FIELD_BIRTH_DATE),
1127 1127
 					'http://schema.org/birthDate',
1128 1128
 					self::DATA_TYPE_DATE
1129 1129
 				),
1130 1130
 				// ### schema:birthPlace.
1131 1131
 				$this->rendition_factory->create(
1132
-					$this->storage_factory->post_meta_to_uri( self::FIELD_BIRTH_PLACE ),
1132
+					$this->storage_factory->post_meta_to_uri(self::FIELD_BIRTH_PLACE),
1133 1133
 					'http://schema.org/birthPlace',
1134 1134
 					self::DATA_TYPE_URI
1135 1135
 				),
1136 1136
 				// ### schema:affiliation.
1137 1137
 				$this->rendition_factory->create(
1138
-					$this->storage_factory->post_meta_to_uri( self::FIELD_AFFILIATION ),
1138
+					$this->storage_factory->post_meta_to_uri(self::FIELD_AFFILIATION),
1139 1139
 					'http://schema.org/affiliation',
1140 1140
 					self::DATA_TYPE_URI
1141 1141
 				),
1142 1142
 				// ### schema:email.
1143 1143
 				$this->rendition_factory->create(
1144
-					$this->storage_factory->post_meta( self::FIELD_EMAIL ),
1144
+					$this->storage_factory->post_meta(self::FIELD_EMAIL),
1145 1145
 					'http://schema.org/email'
1146 1146
 				),
1147 1147
 			),
@@ -1152,8 +1152,8 @@  discard block
 block discarded – undo
1152 1152
 
1153 1153
 		// Merge the custom fields with those provided by the thing schema.
1154 1154
 		$parent_schema           = $this->get_thing_schema();
1155
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1156
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1155
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
1156
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
1157 1157
 
1158 1158
 		return $schema;
1159 1159
 
@@ -1171,7 +1171,7 @@  discard block
 block discarded – undo
1171 1171
 		$schema = array(
1172 1172
 			'label'         => 'Place',
1173 1173
 			'description'   => 'A place.',
1174
-			'parents'       => array( 'thing' ),
1174
+			'parents'       => array('thing'),
1175 1175
 			'css_class'     => 'wl-place',
1176 1176
 			'uri'           => 'http://schema.org/Place',
1177 1177
 			'same_as'       => array(
@@ -1257,8 +1257,8 @@  discard block
 block discarded – undo
1257 1257
 
1258 1258
 		// Merge the custom fields with those provided by the thing schema.
1259 1259
 		$parent_schema           = $this->get_thing_schema();
1260
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1261
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1260
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
1261
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
1262 1262
 
1263 1263
 		return $schema;
1264 1264
 	}
@@ -1275,7 +1275,7 @@  discard block
 block discarded – undo
1275 1275
 		$schema = array(
1276 1276
 			'label'         => 'LocalBusiness',
1277 1277
 			'description'   => 'A local business.',
1278
-			'parents'       => array( 'place', 'organization' ),
1278
+			'parents'       => array('place', 'organization'),
1279 1279
 			'css_class'     => 'wl-local-business',
1280 1280
 			'uri'           => 'http://schema.org/LocalBusiness',
1281 1281
 			'same_as'       => array(
@@ -1292,8 +1292,8 @@  discard block
 block discarded – undo
1292 1292
 		// Merge the custom fields with those provided by the place and organization schema.
1293 1293
 		$place_schema            = $this->get_place_schema();
1294 1294
 		$organization_schema     = $this->get_organization_schema();
1295
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
1296
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $place_schema['linked_data'], $organization_schema['linked_data'] );
1295
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields']);
1296
+		$schema['linked_data']   = array_merge($schema['linked_data'], $place_schema['linked_data'], $organization_schema['linked_data']);
1297 1297
 
1298 1298
 		return $schema;
1299 1299
 	}
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
 		$schema = array(
1311 1311
 			'label'         => 'Recipe',
1312 1312
 			'description'   => 'A Recipe.',
1313
-			'parents'       => array( 'CreativeWork' ),
1313
+			'parents'       => array('CreativeWork'),
1314 1314
 			'css_class'     => 'wl-recipe',
1315 1315
 			'uri'           => 'http://schema.org/Recipe',
1316 1316
 			'same_as'       => array(),
@@ -1324,7 +1324,7 @@  discard block
 block discarded – undo
1324 1324
 					'export_type' => 'xsd:string',
1325 1325
 					'constraints' => '',
1326 1326
 					'metabox'     => array(
1327
-						'label' => __( 'Recipe cuisine', 'wordlift' ),
1327
+						'label' => __('Recipe cuisine', 'wordlift'),
1328 1328
 					),
1329 1329
 				),
1330 1330
 				self::FIELD_RECIPE_INGREDIENT       => array(
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
 						'cardinality' => INF,
1336 1336
 					),
1337 1337
 					'metabox'     => array(
1338
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
1338
+						'label' => __('Recipe ingredient', 'wordlift'),
1339 1339
 					),
1340 1340
 				),
1341 1341
 				self::FIELD_RECIPE_INSTRUCTIONS     => array(
@@ -1345,7 +1345,7 @@  discard block
 block discarded – undo
1345 1345
 					'constraints' => '',
1346 1346
 					'metabox'     => array(
1347 1347
 						'class' => 'Wordlift_Metabox_Field_Multiline',
1348
-						'label' => __( 'Recipe instructions', 'wordlift' ),
1348
+						'label' => __('Recipe instructions', 'wordlift'),
1349 1349
 					),
1350 1350
 				),
1351 1351
 				self::FIELD_RECIPE_YIELD            => array(
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
 					'export_type' => 'xsd:string',
1355 1355
 					'constraints' => '',
1356 1356
 					'metabox'     => array(
1357
-						'label' => __( 'Recipe number of servings', 'wordlift' ),
1357
+						'label' => __('Recipe number of servings', 'wordlift'),
1358 1358
 					),
1359 1359
 				),
1360 1360
 				self::FIELD_RECIPE_INGREDIENT       => array(
@@ -1365,7 +1365,7 @@  discard block
 block discarded – undo
1365 1365
 						'cardinality' => INF,
1366 1366
 					),
1367 1367
 					'metabox'     => array(
1368
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
1368
+						'label' => __('Recipe ingredient', 'wordlift'),
1369 1369
 					),
1370 1370
 				),
1371 1371
 				self::FIELD_NUTRITION_INFO_CALORIES => array(
@@ -1374,7 +1374,7 @@  discard block
 block discarded – undo
1374 1374
 					'export_type' => 'xsd:string',
1375 1375
 					'constraints' => '',
1376 1376
 					'metabox'     => array(
1377
-						'label' => __( 'Calories (e.g. 240 calories)', 'wordlift' ),
1377
+						'label' => __('Calories (e.g. 240 calories)', 'wordlift'),
1378 1378
 					),
1379 1379
 				),
1380 1380
 				self::FIELD_PREP_TIME               => array(
@@ -1384,7 +1384,7 @@  discard block
 block discarded – undo
1384 1384
 					'constraints' => '',
1385 1385
 					'metabox'     => array(
1386 1386
 						'class' => 'Wordlift_Metabox_Field_Duration',
1387
-						'label' => __( 'Recipe preparation time (e.g. 1:30)', 'wordlift' ),
1387
+						'label' => __('Recipe preparation time (e.g. 1:30)', 'wordlift'),
1388 1388
 					),
1389 1389
 				),
1390 1390
 				self::FIELD_COOK_TIME               => array(
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
 					'constraints' => '',
1395 1395
 					'metabox'     => array(
1396 1396
 						'class' => 'Wordlift_Metabox_Field_Duration',
1397
-						'label' => __( 'Recipe cook time (e.g. 1:30)', 'wordlift' ),
1397
+						'label' => __('Recipe cook time (e.g. 1:30)', 'wordlift'),
1398 1398
 					),
1399 1399
 				),
1400 1400
 				self::FIELD_TOTAL_TIME              => array(
@@ -1404,46 +1404,46 @@  discard block
 block discarded – undo
1404 1404
 					'constraints' => '',
1405 1405
 					'metabox'     => array(
1406 1406
 						'class' => 'Wordlift_Metabox_Field_Duration',
1407
-						'label' => __( 'Recipe total time (e.g. 1:30)', 'wordlift' ),
1407
+						'label' => __('Recipe total time (e.g. 1:30)', 'wordlift'),
1408 1408
 					),
1409 1409
 				),
1410 1410
 			),
1411 1411
 			'linked_data'   => array(
1412 1412
 				// ### schema:recipeCuisine.
1413 1413
 				$this->rendition_factory->create(
1414
-					$this->storage_factory->post_meta( self::FIELD_RECIPE_CUISINE ),
1414
+					$this->storage_factory->post_meta(self::FIELD_RECIPE_CUISINE),
1415 1415
 					'http://schema.org/recipeCuisine'
1416 1416
 				),
1417 1417
 				// ### schema:recipeIngredient.
1418 1418
 				$this->rendition_factory->create(
1419
-					$this->storage_factory->post_meta( self::FIELD_RECIPE_INGREDIENT ),
1419
+					$this->storage_factory->post_meta(self::FIELD_RECIPE_INGREDIENT),
1420 1420
 					'http://schema.org/recipeIngredient'
1421 1421
 				),
1422 1422
 				// ### schema:recipeInstructions.
1423 1423
 				$this->rendition_factory->create(
1424
-					$this->storage_factory->post_meta( self::FIELD_RECIPE_INSTRUCTIONS ),
1424
+					$this->storage_factory->post_meta(self::FIELD_RECIPE_INSTRUCTIONS),
1425 1425
 					'http://schema.org/recipeInstructions'
1426 1426
 				),
1427 1427
 				// ### schema:recipeYield.
1428 1428
 				$this->rendition_factory->create(
1429
-					$this->storage_factory->post_meta( self::FIELD_RECIPE_YIELD ),
1429
+					$this->storage_factory->post_meta(self::FIELD_RECIPE_YIELD),
1430 1430
 					'http://schema.org/recipeYield'
1431 1431
 				),
1432 1432
 				// ### schema:prepTime.
1433 1433
 				$this->rendition_factory->create(
1434
-					$this->storage_factory->post_meta( self::FIELD_PREP_TIME ),
1434
+					$this->storage_factory->post_meta(self::FIELD_PREP_TIME),
1435 1435
 					'http://schema.org/prepTime',
1436 1436
 					self::DATA_TYPE_DURATION
1437 1437
 				),
1438 1438
 				// ### schema:cookTime.
1439 1439
 				$this->rendition_factory->create(
1440
-					$this->storage_factory->post_meta( self::FIELD_COOK_TIME ),
1440
+					$this->storage_factory->post_meta(self::FIELD_COOK_TIME),
1441 1441
 					'http://schema.org/cookTime',
1442 1442
 					self::DATA_TYPE_DURATION
1443 1443
 				),
1444 1444
 				// ### schema:totalTime.
1445 1445
 				$this->rendition_factory->create(
1446
-					$this->storage_factory->post_meta( self::FIELD_TOTAL_TIME ),
1446
+					$this->storage_factory->post_meta(self::FIELD_TOTAL_TIME),
1447 1447
 					'http://schema.org/totalTime',
1448 1448
 					self::DATA_TYPE_DURATION
1449 1449
 				),
@@ -1452,8 +1452,8 @@  discard block
 block discarded – undo
1452 1452
 
1453 1453
 		// Merge the custom fields with those provided by the parent schema.
1454 1454
 		$parent_schema           = $this->get_creative_work_schema();
1455
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1456
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1455
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
1456
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
1457 1457
 
1458 1458
 		return $schema;
1459 1459
 	}
@@ -1470,7 +1470,7 @@  discard block
 block discarded – undo
1470 1470
 		$schema = array(
1471 1471
 			'label'         => 'Offer',
1472 1472
 			'description'   => 'An offer. ',
1473
-			'parents'       => array( 'thing' ),
1473
+			'parents'       => array('thing'),
1474 1474
 			'css_class'     => 'wl-offer',
1475 1475
 			'uri'           => self::SCHEMA_OFFER_TYPE,
1476 1476
 			'same_as'       => array(),
@@ -1486,15 +1486,15 @@  discard block
 block discarded – undo
1486 1486
 						'class' => 'Wordlift_Metabox_Field_Select',
1487 1487
 					),
1488 1488
 					'options'     => array(
1489
-						'Discontinued'        => esc_html__( 'Discontinued', 'wordlift' ),
1490
-						'InStock'             => esc_html__( 'In Stock', 'wordlift' ),
1491
-						'InStoreOnly'         => esc_html__( 'In Store Only', 'wordlift' ),
1492
-						'LimitedAvailability' => esc_html__( 'Limited Availability', 'wordlift' ),
1493
-						'OnlineOnly'          => esc_html__( 'Online Only', 'wordlift' ),
1494
-						'OutOfStock'          => esc_html__( 'Out of Stock', 'wordlift' ),
1495
-						'PreOrder'            => esc_html__( 'Pre Order', 'wordlift' ),
1496
-						'PreSale'             => esc_html__( 'Pre Sale', 'wordlift' ),
1497
-						'SoldOut'             => esc_html__( 'Sold Out', 'wordlift' ),
1489
+						'Discontinued'        => esc_html__('Discontinued', 'wordlift'),
1490
+						'InStock'             => esc_html__('In Stock', 'wordlift'),
1491
+						'InStoreOnly'         => esc_html__('In Store Only', 'wordlift'),
1492
+						'LimitedAvailability' => esc_html__('Limited Availability', 'wordlift'),
1493
+						'OnlineOnly'          => esc_html__('Online Only', 'wordlift'),
1494
+						'OutOfStock'          => esc_html__('Out of Stock', 'wordlift'),
1495
+						'PreOrder'            => esc_html__('Pre Order', 'wordlift'),
1496
+						'PreSale'             => esc_html__('Pre Sale', 'wordlift'),
1497
+						'SoldOut'             => esc_html__('Sold Out', 'wordlift'),
1498 1498
 					),
1499 1499
 				),
1500 1500
 				self::FIELD_PRICE               => array(
@@ -1554,55 +1554,55 @@  discard block
 block discarded – undo
1554 1554
 			'linked_data'   => array(
1555 1555
 				// ### schema:availability.
1556 1556
 				$this->rendition_factory->create(
1557
-					$this->storage_factory->post_meta( self::FIELD_AVAILABILITY ),
1557
+					$this->storage_factory->post_meta(self::FIELD_AVAILABILITY),
1558 1558
 					'http://schema.org/availability',
1559 1559
 					null
1560 1560
 				),
1561 1561
 				// ### schema:availabilityStarts.
1562 1562
 				$this->rendition_factory->create(
1563
-					$this->storage_factory->post_meta( self::FIELD_AVAILABILITY_STARTS ),
1563
+					$this->storage_factory->post_meta(self::FIELD_AVAILABILITY_STARTS),
1564 1564
 					'http://schema.org/availabilityStarts',
1565 1565
 					self::DATA_TYPE_DATE_TIME
1566 1566
 				),
1567 1567
 				// ### schema:availabilityEnds.
1568 1568
 				$this->rendition_factory->create(
1569
-					$this->storage_factory->post_meta( self::FIELD_AVAILABILITY_ENDS ),
1569
+					$this->storage_factory->post_meta(self::FIELD_AVAILABILITY_ENDS),
1570 1570
 					'http://schema.org/availabilityEnds',
1571 1571
 					self::DATA_TYPE_DATE_TIME
1572 1572
 				),
1573 1573
 				// ### schema:inventoryLevel.
1574 1574
 				$this->rendition_factory->create(
1575
-					$this->storage_factory->post_meta( self::FIELD_INVENTORY_LEVEL ),
1575
+					$this->storage_factory->post_meta(self::FIELD_INVENTORY_LEVEL),
1576 1576
 					'http://schema.org/inventoryLevel',
1577 1577
 					self::DATA_TYPE_INTEGER
1578 1578
 				),
1579 1579
 				// ### schema:price.
1580 1580
 				$this->rendition_factory->create(
1581
-					$this->storage_factory->post_meta( self::FIELD_PRICE ),
1581
+					$this->storage_factory->post_meta(self::FIELD_PRICE),
1582 1582
 					'http://schema.org/price',
1583 1583
 					self::DATA_TYPE_INTEGER
1584 1584
 				),
1585 1585
 				// ### schema:priceCurrency.
1586 1586
 				$this->rendition_factory->create(
1587
-					$this->storage_factory->post_meta( self::FIELD_PRICE_CURRENCY ),
1587
+					$this->storage_factory->post_meta(self::FIELD_PRICE_CURRENCY),
1588 1588
 					'http://schema.org/priceCurrency',
1589 1589
 					null
1590 1590
 				),
1591 1591
 				// ### schema:validFrom.
1592 1592
 				$this->rendition_factory->create(
1593
-					$this->storage_factory->post_meta( self::FIELD_VALID_FROM ),
1593
+					$this->storage_factory->post_meta(self::FIELD_VALID_FROM),
1594 1594
 					'http://schema.org/validFrom',
1595 1595
 					null
1596 1596
 				),
1597 1597
 				// ### schema:priceValidUntil.
1598 1598
 				$this->rendition_factory->create(
1599
-					$this->storage_factory->post_meta( self::FIELD_PRICE_VALID_UNTIL ),
1599
+					$this->storage_factory->post_meta(self::FIELD_PRICE_VALID_UNTIL),
1600 1600
 					'http://schema.org/priceValidUntil',
1601 1601
 					null
1602 1602
 				),
1603 1603
 				// ### schema:itemOffered.
1604 1604
 				$this->rendition_factory->create(
1605
-					$this->storage_factory->post_meta_to_uri( self::FIELD_ITEM_OFFERED ),
1605
+					$this->storage_factory->post_meta_to_uri(self::FIELD_ITEM_OFFERED),
1606 1606
 					'http://schema.org/itemOffered',
1607 1607
 					self::DATA_TYPE_URI
1608 1608
 				),
@@ -1611,8 +1611,8 @@  discard block
 block discarded – undo
1611 1611
 
1612 1612
 		// Merge the custom fields with those provided by the thing schema.
1613 1613
 		$parent_schema           = $this->get_thing_schema();
1614
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1615
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1614
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
1615
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
1616 1616
 
1617 1617
 		return $schema;
1618 1618
 	}
Please login to merge, or discard this patch.
src/includes/class-wordlift-publisher-service.php 2 patches
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -18,222 +18,222 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Publisher_Service {
20 20
 
21
-	/**
22
-	 * The {@link Wordlift_Configuration_Service} instance.
23
-	 *
24
-	 * @since  3.19.0
25
-	 * @access private
26
-	 * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
27
-	 */
28
-	private $configuration_service;
29
-
30
-	/**
31
-	 * The {@link Wordlift_Publisher_Service} instance.
32
-	 *
33
-	 * @since 3.19.0
34
-	 *
35
-	 * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
36
-	 */
37
-	public function __construct( $configuration_service ) {
38
-		$this->configuration_service = $configuration_service;
39
-	}
40
-
41
-	/**
42
-	 * Counts the number of potential publishers.
43
-	 *
44
-	 * @since 3.11.0
45
-	 *
46
-	 * @return int The number of potential publishers.
47
-	 */
48
-	public function count() {
49
-
50
-		// Search for entities which are either a Person
51
-		// or Organization.
52
-
53
-		// Get only the ids as all we need is the count.
54
-		$entities = get_posts( array(
55
-			'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
56
-			'post_status'    => 'publish',
57
-			'posts_per_page' => - 1,
58
-			'tax_query'      => array(
59
-				array(
60
-					'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
61
-					'field'    => 'slug',
62
-					'terms'    => array( 'organization', 'person' ),
63
-				),
64
-			),
65
-			'fields'         => 'ids',
66
-		) );
67
-
68
-		// Finally return the count.
69
-		return count( $entities );
70
-	}
71
-
72
-	/**
73
-	 * Search SQL filter for matching against post title only.
74
-	 *
75
-	 * @link    http://wordpress.stackexchange.com/a/11826/1685
76
-	 *
77
-	 * @since   3.15.0
78
-	 *
79
-	 * @param   string   $search   The search string.
80
-	 * @param   WP_Query $wp_query The {@link WP_Query} instance.
81
-	 *
82
-	 * @return array|string An array of results.
83
-	 */
84
-	public function limit_search_to_title( $search, $wp_query ) {
85
-
86
-		// Bail out if the search or the `search_terms` haven't been set.
87
-		if ( empty( $search ) || empty( $wp_query->query_vars['search_terms'] ) ) {
88
-			return $search;
89
-		}
90
-
91
-		global $wpdb;
92
-
93
-		$query_vars = $wp_query->query_vars;
94
-		$percent    = ! empty( $query_vars['exact'] ) ? '' : '%';
95
-		$search     = array();
96
-
97
-		foreach ( (array) $query_vars['search_terms'] as $term ) {
98
-			$search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $percent . $wpdb->esc_like( $term ) . $percent );
99
-		}
100
-
101
-		if ( ! is_user_logged_in() ) {
102
-			$search[] = "$wpdb->posts.post_password = ''";
103
-		}
104
-
105
-		$search = ' AND ' . implode( ' AND ', $search );
106
-
107
-		return $search;
108
-	}
109
-
110
-	/**
111
-	 * Query WP for potential publishers, i.e. {@link WP_Post}s which are associated`
112
-	 * with `wl_entity_type` (taxonomy) terms of `Organization` or `Person`.
113
-	 *
114
-	 * @since 3.11.0
115
-	 *
116
-	 * @param string $filter The title filter.
117
-	 *
118
-	 * @return array An array of results in a select2 friendly format.
119
-	 */
120
-	public function query( $filter = '' ) {
121
-
122
-		// Search for the filter in the titles only.
123
-		add_filter( 'posts_search', array(
124
-			$this,
125
-			'limit_search_to_title',
126
-		), 10, 2 );
127
-
128
-		/*
21
+    /**
22
+     * The {@link Wordlift_Configuration_Service} instance.
23
+     *
24
+     * @since  3.19.0
25
+     * @access private
26
+     * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
27
+     */
28
+    private $configuration_service;
29
+
30
+    /**
31
+     * The {@link Wordlift_Publisher_Service} instance.
32
+     *
33
+     * @since 3.19.0
34
+     *
35
+     * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
36
+     */
37
+    public function __construct( $configuration_service ) {
38
+        $this->configuration_service = $configuration_service;
39
+    }
40
+
41
+    /**
42
+     * Counts the number of potential publishers.
43
+     *
44
+     * @since 3.11.0
45
+     *
46
+     * @return int The number of potential publishers.
47
+     */
48
+    public function count() {
49
+
50
+        // Search for entities which are either a Person
51
+        // or Organization.
52
+
53
+        // Get only the ids as all we need is the count.
54
+        $entities = get_posts( array(
55
+            'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
56
+            'post_status'    => 'publish',
57
+            'posts_per_page' => - 1,
58
+            'tax_query'      => array(
59
+                array(
60
+                    'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
61
+                    'field'    => 'slug',
62
+                    'terms'    => array( 'organization', 'person' ),
63
+                ),
64
+            ),
65
+            'fields'         => 'ids',
66
+        ) );
67
+
68
+        // Finally return the count.
69
+        return count( $entities );
70
+    }
71
+
72
+    /**
73
+     * Search SQL filter for matching against post title only.
74
+     *
75
+     * @link    http://wordpress.stackexchange.com/a/11826/1685
76
+     *
77
+     * @since   3.15.0
78
+     *
79
+     * @param   string   $search   The search string.
80
+     * @param   WP_Query $wp_query The {@link WP_Query} instance.
81
+     *
82
+     * @return array|string An array of results.
83
+     */
84
+    public function limit_search_to_title( $search, $wp_query ) {
85
+
86
+        // Bail out if the search or the `search_terms` haven't been set.
87
+        if ( empty( $search ) || empty( $wp_query->query_vars['search_terms'] ) ) {
88
+            return $search;
89
+        }
90
+
91
+        global $wpdb;
92
+
93
+        $query_vars = $wp_query->query_vars;
94
+        $percent    = ! empty( $query_vars['exact'] ) ? '' : '%';
95
+        $search     = array();
96
+
97
+        foreach ( (array) $query_vars['search_terms'] as $term ) {
98
+            $search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $percent . $wpdb->esc_like( $term ) . $percent );
99
+        }
100
+
101
+        if ( ! is_user_logged_in() ) {
102
+            $search[] = "$wpdb->posts.post_password = ''";
103
+        }
104
+
105
+        $search = ' AND ' . implode( ' AND ', $search );
106
+
107
+        return $search;
108
+    }
109
+
110
+    /**
111
+     * Query WP for potential publishers, i.e. {@link WP_Post}s which are associated`
112
+     * with `wl_entity_type` (taxonomy) terms of `Organization` or `Person`.
113
+     *
114
+     * @since 3.11.0
115
+     *
116
+     * @param string $filter The title filter.
117
+     *
118
+     * @return array An array of results in a select2 friendly format.
119
+     */
120
+    public function query( $filter = '' ) {
121
+
122
+        // Search for the filter in the titles only.
123
+        add_filter( 'posts_search', array(
124
+            $this,
125
+            'limit_search_to_title',
126
+        ), 10, 2 );
127
+
128
+        /*
129 129
 		 * Search for entities which are either a Person
130 130
 		 * or Organization. Sort the results by title in ascending order.
131 131
 		 */
132
-		$entities = get_posts( array(
133
-			'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
134
-			'post_status'    => 'publish',
135
-			'posts_per_page' => - 1,
136
-			'tax_query'      => array(
137
-				array(
138
-					'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
139
-					'field'    => 'slug',
140
-					'terms'    => array( 'organization', 'person' ),
141
-				),
142
-			),
143
-			's'              => $filter,
144
-			'orderby'        => 'title',
145
-			'order'          => 'ASC',
146
-		) );
147
-
148
-		// Remove the search filter added before the query.
149
-		remove_filter( 'posts_search', array(
150
-			$this,
151
-			'limit_search_to_title',
152
-		), 10, 2 );
153
-
154
-		// Set a reference to ourselves to pass to the closure.
155
-		$publisher_service = $this;
156
-
157
-		// Map the results in a `Select2` compatible array.
158
-		return array_map( function ( $entity ) use ( $publisher_service ) {
159
-			$type     = wp_get_post_terms( $entity->ID, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
160
-			$thumb_id = get_post_thumbnail_id( $entity->ID );
161
-
162
-			return array(
163
-				'id'            => $entity->ID,
164
-				'text'          => $entity->post_title,
165
-				'type'          => $type[0]->name,
166
-				'thumbnail_url' => $publisher_service->get_attachment_image_url( $thumb_id ),
167
-			);
168
-		}, $entities );
169
-	}
170
-
171
-	/**
172
-	 * Get the thumbnail's URL.
173
-	 *
174
-	 * @since 3.11.0
175
-	 *
176
-	 * @param int    $attachment_id The attachment id.
177
-	 * @param string $size          The attachment size (default = 'thumbnail').
178
-	 *
179
-	 * @return string|bool The image URL or false if not found.
180
-	 */
181
-	public function get_attachment_image_url( $attachment_id, $size = 'thumbnail' ) {
182
-
183
-		$image = wp_get_attachment_image_src( $attachment_id, $size );
184
-
185
-		return isset( $image['0'] ) ? $image['0'] : false;
186
-	}
187
-
188
-	/**
189
-	 * Add additional instructions to featured image metabox
190
-	 * when the entity type is the publisher.
191
-	 *
192
-	 * @since  3.19.0
193
-	 *
194
-	 * @param  string $content Current metabox content.
195
-	 *
196
-	 * @return string $content metabox content with additional instructions.
197
-	 */
198
-	public function add_featured_image_instruction( $content ) {
199
-		// Get the current post ID.
200
-		$post_id = get_the_ID();
201
-
202
-		// Get the publisher id.
203
-		$publisher_id = $this->configuration_service->get_publisher_id();
204
-
205
-
206
-		// Bail if for some reason the post id is not set.
207
-		if (
208
-			empty( $post_id ) ||
209
-			$post_id !== (int) $publisher_id
210
-		) {
211
-			return $content;
212
-		}
213
-
214
-		$terms = wp_get_post_terms(
215
-			$post_id, // The post id.
216
-			Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, // The taxonomy slug.
217
-			array(
218
-				'fields' => 'slugs',
219
-				// We don't need all fields, but only slugs.
220
-			)
221
-		);
222
-
223
-		// Check that the entity type is "Organization".
224
-		if ( in_array( 'organization', $terms, true ) ) {
225
-			// Add the featured image description when the type is "Organization".
226
-
227
-			$link = sprintf( '<a target="_blank" href="%s">%s</a>',
228
-				esc_attr__( 'https://developers.google.com/search/docs/data-types/article#logo-guidelines', 'wordlift' ),
229
-				esc_html__( 'AMP logo guidelines', 'wordlift' ) );
230
-			$content .= sprintf( '<p>'
231
-								 . esc_html_x( 'According to the %s, the logo should fit in a 60x600px rectangle, and either be exactly 60px high (preferred), or exactly 600px wide. For example, 450x45px would not be acceptable, even though it fits in the 600x60px rectangle. To comply with the guidelines, WordLift will automatically resize the Featured Image for structured data formats.', 'After "According to the" goes the link to the "AMP logo guidelines".', 'wordlift' )
232
-								 . '</p>', $link );
233
-		}
234
-
235
-		// Finally return the content.
236
-		return $content;
237
-	}
132
+        $entities = get_posts( array(
133
+            'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
134
+            'post_status'    => 'publish',
135
+            'posts_per_page' => - 1,
136
+            'tax_query'      => array(
137
+                array(
138
+                    'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
139
+                    'field'    => 'slug',
140
+                    'terms'    => array( 'organization', 'person' ),
141
+                ),
142
+            ),
143
+            's'              => $filter,
144
+            'orderby'        => 'title',
145
+            'order'          => 'ASC',
146
+        ) );
147
+
148
+        // Remove the search filter added before the query.
149
+        remove_filter( 'posts_search', array(
150
+            $this,
151
+            'limit_search_to_title',
152
+        ), 10, 2 );
153
+
154
+        // Set a reference to ourselves to pass to the closure.
155
+        $publisher_service = $this;
156
+
157
+        // Map the results in a `Select2` compatible array.
158
+        return array_map( function ( $entity ) use ( $publisher_service ) {
159
+            $type     = wp_get_post_terms( $entity->ID, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
160
+            $thumb_id = get_post_thumbnail_id( $entity->ID );
161
+
162
+            return array(
163
+                'id'            => $entity->ID,
164
+                'text'          => $entity->post_title,
165
+                'type'          => $type[0]->name,
166
+                'thumbnail_url' => $publisher_service->get_attachment_image_url( $thumb_id ),
167
+            );
168
+        }, $entities );
169
+    }
170
+
171
+    /**
172
+     * Get the thumbnail's URL.
173
+     *
174
+     * @since 3.11.0
175
+     *
176
+     * @param int    $attachment_id The attachment id.
177
+     * @param string $size          The attachment size (default = 'thumbnail').
178
+     *
179
+     * @return string|bool The image URL or false if not found.
180
+     */
181
+    public function get_attachment_image_url( $attachment_id, $size = 'thumbnail' ) {
182
+
183
+        $image = wp_get_attachment_image_src( $attachment_id, $size );
184
+
185
+        return isset( $image['0'] ) ? $image['0'] : false;
186
+    }
187
+
188
+    /**
189
+     * Add additional instructions to featured image metabox
190
+     * when the entity type is the publisher.
191
+     *
192
+     * @since  3.19.0
193
+     *
194
+     * @param  string $content Current metabox content.
195
+     *
196
+     * @return string $content metabox content with additional instructions.
197
+     */
198
+    public function add_featured_image_instruction( $content ) {
199
+        // Get the current post ID.
200
+        $post_id = get_the_ID();
201
+
202
+        // Get the publisher id.
203
+        $publisher_id = $this->configuration_service->get_publisher_id();
204
+
205
+
206
+        // Bail if for some reason the post id is not set.
207
+        if (
208
+            empty( $post_id ) ||
209
+            $post_id !== (int) $publisher_id
210
+        ) {
211
+            return $content;
212
+        }
213
+
214
+        $terms = wp_get_post_terms(
215
+            $post_id, // The post id.
216
+            Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, // The taxonomy slug.
217
+            array(
218
+                'fields' => 'slugs',
219
+                // We don't need all fields, but only slugs.
220
+            )
221
+        );
222
+
223
+        // Check that the entity type is "Organization".
224
+        if ( in_array( 'organization', $terms, true ) ) {
225
+            // Add the featured image description when the type is "Organization".
226
+
227
+            $link = sprintf( '<a target="_blank" href="%s">%s</a>',
228
+                esc_attr__( 'https://developers.google.com/search/docs/data-types/article#logo-guidelines', 'wordlift' ),
229
+                esc_html__( 'AMP logo guidelines', 'wordlift' ) );
230
+            $content .= sprintf( '<p>'
231
+                                    . esc_html_x( 'According to the %s, the logo should fit in a 60x600px rectangle, and either be exactly 60px high (preferred), or exactly 600px wide. For example, 450x45px would not be acceptable, even though it fits in the 600x60px rectangle. To comply with the guidelines, WordLift will automatically resize the Featured Image for structured data formats.', 'After "According to the" goes the link to the "AMP logo guidelines".', 'wordlift' )
232
+                                    . '</p>', $link );
233
+        }
234
+
235
+        // Finally return the content.
236
+        return $content;
237
+    }
238 238
 
239 239
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
36 36
 	 */
37
-	public function __construct( $configuration_service ) {
37
+	public function __construct($configuration_service) {
38 38
 		$this->configuration_service = $configuration_service;
39 39
 	}
40 40
 
@@ -51,22 +51,22 @@  discard block
 block discarded – undo
51 51
 		// or Organization.
52 52
 
53 53
 		// Get only the ids as all we need is the count.
54
-		$entities = get_posts( array(
54
+		$entities = get_posts(array(
55 55
 			'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
56 56
 			'post_status'    => 'publish',
57
-			'posts_per_page' => - 1,
57
+			'posts_per_page' => -1,
58 58
 			'tax_query'      => array(
59 59
 				array(
60 60
 					'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
61 61
 					'field'    => 'slug',
62
-					'terms'    => array( 'organization', 'person' ),
62
+					'terms'    => array('organization', 'person'),
63 63
 				),
64 64
 			),
65 65
 			'fields'         => 'ids',
66
-		) );
66
+		));
67 67
 
68 68
 		// Finally return the count.
69
-		return count( $entities );
69
+		return count($entities);
70 70
 	}
71 71
 
72 72
 	/**
@@ -81,28 +81,28 @@  discard block
 block discarded – undo
81 81
 	 *
82 82
 	 * @return array|string An array of results.
83 83
 	 */
84
-	public function limit_search_to_title( $search, $wp_query ) {
84
+	public function limit_search_to_title($search, $wp_query) {
85 85
 
86 86
 		// Bail out if the search or the `search_terms` haven't been set.
87
-		if ( empty( $search ) || empty( $wp_query->query_vars['search_terms'] ) ) {
87
+		if (empty($search) || empty($wp_query->query_vars['search_terms'])) {
88 88
 			return $search;
89 89
 		}
90 90
 
91 91
 		global $wpdb;
92 92
 
93 93
 		$query_vars = $wp_query->query_vars;
94
-		$percent    = ! empty( $query_vars['exact'] ) ? '' : '%';
94
+		$percent    = ! empty($query_vars['exact']) ? '' : '%';
95 95
 		$search     = array();
96 96
 
97
-		foreach ( (array) $query_vars['search_terms'] as $term ) {
98
-			$search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $percent . $wpdb->esc_like( $term ) . $percent );
97
+		foreach ((array) $query_vars['search_terms'] as $term) {
98
+			$search[] = $wpdb->prepare("$wpdb->posts.post_title LIKE %s", $percent.$wpdb->esc_like($term).$percent);
99 99
 		}
100 100
 
101
-		if ( ! is_user_logged_in() ) {
101
+		if ( ! is_user_logged_in()) {
102 102
 			$search[] = "$wpdb->posts.post_password = ''";
103 103
 		}
104 104
 
105
-		$search = ' AND ' . implode( ' AND ', $search );
105
+		$search = ' AND '.implode(' AND ', $search);
106 106
 
107 107
 		return $search;
108 108
 	}
@@ -117,55 +117,55 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @return array An array of results in a select2 friendly format.
119 119
 	 */
120
-	public function query( $filter = '' ) {
120
+	public function query($filter = '') {
121 121
 
122 122
 		// Search for the filter in the titles only.
123
-		add_filter( 'posts_search', array(
123
+		add_filter('posts_search', array(
124 124
 			$this,
125 125
 			'limit_search_to_title',
126
-		), 10, 2 );
126
+		), 10, 2);
127 127
 
128 128
 		/*
129 129
 		 * Search for entities which are either a Person
130 130
 		 * or Organization. Sort the results by title in ascending order.
131 131
 		 */
132
-		$entities = get_posts( array(
132
+		$entities = get_posts(array(
133 133
 			'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
134 134
 			'post_status'    => 'publish',
135
-			'posts_per_page' => - 1,
135
+			'posts_per_page' => -1,
136 136
 			'tax_query'      => array(
137 137
 				array(
138 138
 					'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
139 139
 					'field'    => 'slug',
140
-					'terms'    => array( 'organization', 'person' ),
140
+					'terms'    => array('organization', 'person'),
141 141
 				),
142 142
 			),
143 143
 			's'              => $filter,
144 144
 			'orderby'        => 'title',
145 145
 			'order'          => 'ASC',
146
-		) );
146
+		));
147 147
 
148 148
 		// Remove the search filter added before the query.
149
-		remove_filter( 'posts_search', array(
149
+		remove_filter('posts_search', array(
150 150
 			$this,
151 151
 			'limit_search_to_title',
152
-		), 10, 2 );
152
+		), 10, 2);
153 153
 
154 154
 		// Set a reference to ourselves to pass to the closure.
155 155
 		$publisher_service = $this;
156 156
 
157 157
 		// Map the results in a `Select2` compatible array.
158
-		return array_map( function ( $entity ) use ( $publisher_service ) {
159
-			$type     = wp_get_post_terms( $entity->ID, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
160
-			$thumb_id = get_post_thumbnail_id( $entity->ID );
158
+		return array_map(function($entity) use ($publisher_service) {
159
+			$type     = wp_get_post_terms($entity->ID, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
160
+			$thumb_id = get_post_thumbnail_id($entity->ID);
161 161
 
162 162
 			return array(
163 163
 				'id'            => $entity->ID,
164 164
 				'text'          => $entity->post_title,
165 165
 				'type'          => $type[0]->name,
166
-				'thumbnail_url' => $publisher_service->get_attachment_image_url( $thumb_id ),
166
+				'thumbnail_url' => $publisher_service->get_attachment_image_url($thumb_id),
167 167
 			);
168
-		}, $entities );
168
+		}, $entities);
169 169
 	}
170 170
 
171 171
 	/**
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
 	 *
179 179
 	 * @return string|bool The image URL or false if not found.
180 180
 	 */
181
-	public function get_attachment_image_url( $attachment_id, $size = 'thumbnail' ) {
181
+	public function get_attachment_image_url($attachment_id, $size = 'thumbnail') {
182 182
 
183
-		$image = wp_get_attachment_image_src( $attachment_id, $size );
183
+		$image = wp_get_attachment_image_src($attachment_id, $size);
184 184
 
185
-		return isset( $image['0'] ) ? $image['0'] : false;
185
+		return isset($image['0']) ? $image['0'] : false;
186 186
 	}
187 187
 
188 188
 	/**
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 *
196 196
 	 * @return string $content metabox content with additional instructions.
197 197
 	 */
198
-	public function add_featured_image_instruction( $content ) {
198
+	public function add_featured_image_instruction($content) {
199 199
 		// Get the current post ID.
200 200
 		$post_id = get_the_ID();
201 201
 
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 
206 206
 		// Bail if for some reason the post id is not set.
207 207
 		if (
208
-			empty( $post_id ) ||
208
+			empty($post_id) ||
209 209
 			$post_id !== (int) $publisher_id
210 210
 		) {
211 211
 			return $content;
@@ -221,15 +221,15 @@  discard block
 block discarded – undo
221 221
 		);
222 222
 
223 223
 		// Check that the entity type is "Organization".
224
-		if ( in_array( 'organization', $terms, true ) ) {
224
+		if (in_array('organization', $terms, true)) {
225 225
 			// Add the featured image description when the type is "Organization".
226 226
 
227
-			$link = sprintf( '<a target="_blank" href="%s">%s</a>',
228
-				esc_attr__( 'https://developers.google.com/search/docs/data-types/article#logo-guidelines', 'wordlift' ),
229
-				esc_html__( 'AMP logo guidelines', 'wordlift' ) );
230
-			$content .= sprintf( '<p>'
231
-								 . esc_html_x( 'According to the %s, the logo should fit in a 60x600px rectangle, and either be exactly 60px high (preferred), or exactly 600px wide. For example, 450x45px would not be acceptable, even though it fits in the 600x60px rectangle. To comply with the guidelines, WordLift will automatically resize the Featured Image for structured data formats.', 'After "According to the" goes the link to the "AMP logo guidelines".', 'wordlift' )
232
-								 . '</p>', $link );
227
+			$link = sprintf('<a target="_blank" href="%s">%s</a>',
228
+				esc_attr__('https://developers.google.com/search/docs/data-types/article#logo-guidelines', 'wordlift'),
229
+				esc_html__('AMP logo guidelines', 'wordlift'));
230
+			$content .= sprintf('<p>'
231
+								 . esc_html_x('According to the %s, the logo should fit in a 60x600px rectangle, and either be exactly 60px high (preferred), or exactly 600px wide. For example, 450x45px would not be acceptable, even though it fits in the 600x60px rectangle. To comply with the guidelines, WordLift will automatically resize the Featured Image for structured data formats.', 'After "According to the" goes the link to the "AMP logo guidelines".', 'wordlift')
232
+								 . '</p>', $link);
233 233
 		}
234 234
 
235 235
 		// Finally return the content.
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin.php 2 patches
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -22,173 +22,173 @@
 block discarded – undo
22 22
  */
23 23
 class Wordlift_Admin {
24 24
 
25
-	/**
26
-	 * The ID of this plugin.
27
-	 *
28
-	 * @since    1.0.0
29
-	 * @access   private
30
-	 * @var      string $plugin_name The ID of this plugin.
31
-	 */
32
-	private $plugin_name;
33
-
34
-	/**
35
-	 * The version of this plugin.
36
-	 *
37
-	 * @since    1.0.0
38
-	 * @access   private
39
-	 * @var      string $version The current version of this plugin.
40
-	 */
41
-	private $version;
42
-
43
-	/**
44
-	 * The {@link Wordlift_Configuration_Service} instance.
45
-	 *
46
-	 * @since  3.14.0
47
-	 * @access private
48
-	 * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
49
-	 */
50
-	private $configuration_service;
51
-
52
-	/**
53
-	 * The {@link Wordlift_User_Service} instance.
54
-	 *
55
-	 * @since  3.14.0
56
-	 * @access private
57
-	 * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
58
-	 */
59
-	private $user_service;
60
-
61
-	/**
62
-	 * Initialize the class and set its properties.
63
-	 *
64
-	 * @since  1.0.0
65
-	 *
66
-	 * @param string $plugin_name The name of this plugin.
67
-	 * @param string $version The version of this plugin.
68
-	 * @param \Wordlift_Configuration_Service $configuration_service The configuration service.
69
-	 * @param \Wordlift_Notice_Service $notice_service The notice service.
70
-	 * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
71
-	 */
72
-	public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
73
-
74
-		$this->plugin_name = $plugin_name;
75
-		$this->version     = $version;
76
-
77
-		$this->configuration_service = $configuration_service;
78
-		$this->user_service          = $user_service;
79
-
80
-		$dataset_uri = $configuration_service->get_dataset_uri();
81
-		$key         = $configuration_service->get_key();
82
-
83
-		if ( empty( $dataset_uri ) ) {
84
-			$settings_page = Wordlift_Admin_Settings_Page::get_instance();
85
-			if ( empty( $key ) ) {
86
-				$error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
87
-			} else {
88
-				$error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
89
-			}
90
-			$notice_service->add_error( $error );
91
-		}
92
-
93
-		// Load additional code if we're in the admin UI.
94
-		if ( is_admin() ) {
95
-			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php';
96
-
97
-			new Wordlift_Dashboard_Latest_News();
98
-		}
99
-
100
-	}
101
-
102
-	/**
103
-	 * Register the stylesheets for the admin area.
104
-	 *
105
-	 * @since    1.0.0
106
-	 */
107
-	public function enqueue_styles() {
108
-
109
-		/**
110
-		 * This function is provided for demonstration purposes only.
111
-		 *
112
-		 * An instance of this class should be passed to the run() function
113
-		 * defined in Wordlift_Loader as all of the hooks are defined
114
-		 * in that particular class.
115
-		 *
116
-		 * The Wordlift_Loader will then create the relationship
117
-		 * between the defined hooks and the functions defined in this
118
-		 * class.
119
-		 */
120
-
121
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
122
-
123
-	}
124
-
125
-	/**
126
-	 * Register the JavaScript for the admin area.
127
-	 *
128
-	 * @since    1.0.0
129
-	 */
130
-	public function enqueue_scripts() {
131
-
132
-		/**
133
-		 * This function is provided for demonstration purposes only.
134
-		 *
135
-		 * An instance of this class should be passed to the run() function
136
-		 * defined in Wordlift_Loader as all of the hooks are defined
137
-		 * in that particular class.
138
-		 *
139
-		 * The Wordlift_Loader will then create the relationship
140
-		 * between the defined hooks and the functions defined in this
141
-		 * class.
142
-		 */
143
-
144
-		// Enqueue the admin scripts.
145
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array(
146
-			'jquery',
147
-			'underscore',
148
-			'backbone',
149
-		), $this->version, false );
150
-
151
-		// Set the basic params.
152
-		$params = array(
153
-			// @todo scripts in admin should use wp.post.
154
-			'ajax_url'              => admin_url( 'admin-ajax.php' ),
155
-			// @todo remove specific actions from settings.
156
-			'action'                => 'entity_by_title',
157
-			'datasetUri'            => $this->configuration_service->get_dataset_uri(),
158
-			'language'              => $this->configuration_service->get_language_code(),
159
-			'link_by_default'       => $this->configuration_service->is_link_by_default(),
160
-			// Whether the current user is allowed to create new entities.
161
-			//
162
-			// @see https://github.com/insideout10/wordlift-plugin/issues/561
163
-			'can_create_entities'   => current_user_can( 'edit_wordlift_entities' ) ? 'yes' : 'no',
164
-			'l10n'                  => array(
165
-				'You already published an entity with the same name'                 => __( 'You already published an entity with the same name: ', 'wordlift' ),
166
-				'logo_selection_title'                                               => __( 'WordLift Choose Logo', 'wordlift' ),
167
-				'logo_selection_button'                                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
168
-				'Type at least 3 characters to search...'                            => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ),
169
-				'No results found for your search.'                                  => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ),
170
-				'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ),
171
-			),
172
-			'wl_autocomplete_nonce' => wp_create_nonce( 'wordlift_autocomplete' ),
173
-		);
174
-
175
-		// Set post-related values if there's a current post.
176
-		if ( null !== $post = $entity_being_edited = get_post() ) {
177
-
178
-			$params['post_id']           = $entity_being_edited->ID;
179
-			$entity_service              = Wordlift_Entity_Service::get_instance();
180
-			$params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() );
181
-			// We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
182
-			// from the results, since we don't want the current entity to be discovered by the analysis.
183
-			//
184
-			// See https://github.com/insideout10/wordlift-plugin/issues/345
185
-			$params['itemId'] = $entity_service->get_uri( $entity_being_edited->ID );
186
-
187
-		}
188
-
189
-		// Finally output the params as `wlSettings` for JavaScript code.
190
-		wp_localize_script( $this->plugin_name, 'wlSettings', $params );
191
-
192
-	}
25
+    /**
26
+     * The ID of this plugin.
27
+     *
28
+     * @since    1.0.0
29
+     * @access   private
30
+     * @var      string $plugin_name The ID of this plugin.
31
+     */
32
+    private $plugin_name;
33
+
34
+    /**
35
+     * The version of this plugin.
36
+     *
37
+     * @since    1.0.0
38
+     * @access   private
39
+     * @var      string $version The current version of this plugin.
40
+     */
41
+    private $version;
42
+
43
+    /**
44
+     * The {@link Wordlift_Configuration_Service} instance.
45
+     *
46
+     * @since  3.14.0
47
+     * @access private
48
+     * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
49
+     */
50
+    private $configuration_service;
51
+
52
+    /**
53
+     * The {@link Wordlift_User_Service} instance.
54
+     *
55
+     * @since  3.14.0
56
+     * @access private
57
+     * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
58
+     */
59
+    private $user_service;
60
+
61
+    /**
62
+     * Initialize the class and set its properties.
63
+     *
64
+     * @since  1.0.0
65
+     *
66
+     * @param string $plugin_name The name of this plugin.
67
+     * @param string $version The version of this plugin.
68
+     * @param \Wordlift_Configuration_Service $configuration_service The configuration service.
69
+     * @param \Wordlift_Notice_Service $notice_service The notice service.
70
+     * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
71
+     */
72
+    public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
73
+
74
+        $this->plugin_name = $plugin_name;
75
+        $this->version     = $version;
76
+
77
+        $this->configuration_service = $configuration_service;
78
+        $this->user_service          = $user_service;
79
+
80
+        $dataset_uri = $configuration_service->get_dataset_uri();
81
+        $key         = $configuration_service->get_key();
82
+
83
+        if ( empty( $dataset_uri ) ) {
84
+            $settings_page = Wordlift_Admin_Settings_Page::get_instance();
85
+            if ( empty( $key ) ) {
86
+                $error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
87
+            } else {
88
+                $error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
89
+            }
90
+            $notice_service->add_error( $error );
91
+        }
92
+
93
+        // Load additional code if we're in the admin UI.
94
+        if ( is_admin() ) {
95
+            require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php';
96
+
97
+            new Wordlift_Dashboard_Latest_News();
98
+        }
99
+
100
+    }
101
+
102
+    /**
103
+     * Register the stylesheets for the admin area.
104
+     *
105
+     * @since    1.0.0
106
+     */
107
+    public function enqueue_styles() {
108
+
109
+        /**
110
+         * This function is provided for demonstration purposes only.
111
+         *
112
+         * An instance of this class should be passed to the run() function
113
+         * defined in Wordlift_Loader as all of the hooks are defined
114
+         * in that particular class.
115
+         *
116
+         * The Wordlift_Loader will then create the relationship
117
+         * between the defined hooks and the functions defined in this
118
+         * class.
119
+         */
120
+
121
+        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
122
+
123
+    }
124
+
125
+    /**
126
+     * Register the JavaScript for the admin area.
127
+     *
128
+     * @since    1.0.0
129
+     */
130
+    public function enqueue_scripts() {
131
+
132
+        /**
133
+         * This function is provided for demonstration purposes only.
134
+         *
135
+         * An instance of this class should be passed to the run() function
136
+         * defined in Wordlift_Loader as all of the hooks are defined
137
+         * in that particular class.
138
+         *
139
+         * The Wordlift_Loader will then create the relationship
140
+         * between the defined hooks and the functions defined in this
141
+         * class.
142
+         */
143
+
144
+        // Enqueue the admin scripts.
145
+        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array(
146
+            'jquery',
147
+            'underscore',
148
+            'backbone',
149
+        ), $this->version, false );
150
+
151
+        // Set the basic params.
152
+        $params = array(
153
+            // @todo scripts in admin should use wp.post.
154
+            'ajax_url'              => admin_url( 'admin-ajax.php' ),
155
+            // @todo remove specific actions from settings.
156
+            'action'                => 'entity_by_title',
157
+            'datasetUri'            => $this->configuration_service->get_dataset_uri(),
158
+            'language'              => $this->configuration_service->get_language_code(),
159
+            'link_by_default'       => $this->configuration_service->is_link_by_default(),
160
+            // Whether the current user is allowed to create new entities.
161
+            //
162
+            // @see https://github.com/insideout10/wordlift-plugin/issues/561
163
+            'can_create_entities'   => current_user_can( 'edit_wordlift_entities' ) ? 'yes' : 'no',
164
+            'l10n'                  => array(
165
+                'You already published an entity with the same name'                 => __( 'You already published an entity with the same name: ', 'wordlift' ),
166
+                'logo_selection_title'                                               => __( 'WordLift Choose Logo', 'wordlift' ),
167
+                'logo_selection_button'                                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
168
+                'Type at least 3 characters to search...'                            => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ),
169
+                'No results found for your search.'                                  => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ),
170
+                'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ),
171
+            ),
172
+            'wl_autocomplete_nonce' => wp_create_nonce( 'wordlift_autocomplete' ),
173
+        );
174
+
175
+        // Set post-related values if there's a current post.
176
+        if ( null !== $post = $entity_being_edited = get_post() ) {
177
+
178
+            $params['post_id']           = $entity_being_edited->ID;
179
+            $entity_service              = Wordlift_Entity_Service::get_instance();
180
+            $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() );
181
+            // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
182
+            // from the results, since we don't want the current entity to be discovered by the analysis.
183
+            //
184
+            // See https://github.com/insideout10/wordlift-plugin/issues/345
185
+            $params['itemId'] = $entity_service->get_uri( $entity_being_edited->ID );
186
+
187
+        }
188
+
189
+        // Finally output the params as `wlSettings` for JavaScript code.
190
+        wp_localize_script( $this->plugin_name, 'wlSettings', $params );
191
+
192
+    }
193 193
 
194 194
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * @param \Wordlift_Notice_Service $notice_service The notice service.
70 70
 	 * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
71 71
 	 */
72
-	public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
72
+	public function __construct($plugin_name, $version, $configuration_service, $notice_service, $user_service) {
73 73
 
74 74
 		$this->plugin_name = $plugin_name;
75 75
 		$this->version     = $version;
@@ -80,19 +80,19 @@  discard block
 block discarded – undo
80 80
 		$dataset_uri = $configuration_service->get_dataset_uri();
81 81
 		$key         = $configuration_service->get_key();
82 82
 
83
-		if ( empty( $dataset_uri ) ) {
83
+		if (empty($dataset_uri)) {
84 84
 			$settings_page = Wordlift_Admin_Settings_Page::get_instance();
85
-			if ( empty( $key ) ) {
86
-				$error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
85
+			if (empty($key)) {
86
+				$error = sprintf(esc_html__("WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift'), '<a href="'.$settings_page->get_url().'">'.esc_html__('settings page', 'wordlift').'</a>');
87 87
 			} else {
88
-				$error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
88
+				$error = sprintf(esc_html__("WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift'), '<a href="'.$settings_page->get_url().'">'.esc_html__('settings page', 'wordlift').'</a>');
89 89
 			}
90
-			$notice_service->add_error( $error );
90
+			$notice_service->add_error($error);
91 91
 		}
92 92
 
93 93
 		// Load additional code if we're in the admin UI.
94
-		if ( is_admin() ) {
95
-			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php';
94
+		if (is_admin()) {
95
+			require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-dashboard-latest-news.php';
96 96
 
97 97
 			new Wordlift_Dashboard_Latest_News();
98 98
 		}
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		 * class.
119 119
 		 */
120 120
 
121
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
121
+		wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/wordlift-admin.css', array(), $this->version, 'all');
122 122
 
123 123
 	}
124 124
 
@@ -142,16 +142,16 @@  discard block
 block discarded – undo
142 142
 		 */
143 143
 
144 144
 		// Enqueue the admin scripts.
145
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array(
145
+		wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/1/admin.js', array(
146 146
 			'jquery',
147 147
 			'underscore',
148 148
 			'backbone',
149
-		), $this->version, false );
149
+		), $this->version, false);
150 150
 
151 151
 		// Set the basic params.
152 152
 		$params = array(
153 153
 			// @todo scripts in admin should use wp.post.
154
-			'ajax_url'              => admin_url( 'admin-ajax.php' ),
154
+			'ajax_url'              => admin_url('admin-ajax.php'),
155 155
 			// @todo remove specific actions from settings.
156 156
 			'action'                => 'entity_by_title',
157 157
 			'datasetUri'            => $this->configuration_service->get_dataset_uri(),
@@ -160,34 +160,34 @@  discard block
 block discarded – undo
160 160
 			// Whether the current user is allowed to create new entities.
161 161
 			//
162 162
 			// @see https://github.com/insideout10/wordlift-plugin/issues/561
163
-			'can_create_entities'   => current_user_can( 'edit_wordlift_entities' ) ? 'yes' : 'no',
163
+			'can_create_entities'   => current_user_can('edit_wordlift_entities') ? 'yes' : 'no',
164 164
 			'l10n'                  => array(
165
-				'You already published an entity with the same name'                 => __( 'You already published an entity with the same name: ', 'wordlift' ),
166
-				'logo_selection_title'                                               => __( 'WordLift Choose Logo', 'wordlift' ),
167
-				'logo_selection_button'                                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
168
-				'Type at least 3 characters to search...'                            => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ),
169
-				'No results found for your search.'                                  => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ),
170
-				'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ),
165
+				'You already published an entity with the same name'                 => __('You already published an entity with the same name: ', 'wordlift'),
166
+				'logo_selection_title'                                               => __('WordLift Choose Logo', 'wordlift'),
167
+				'logo_selection_button'                                              => array('text' => __('Choose Logo', 'wordlift')),
168
+				'Type at least 3 characters to search...'                            => _x('Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift'),
169
+				'No results found for your search.'                                  => _x('No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift'),
170
+				'Please wait while we look for entities in the linked data cloud...' => _x('Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift'),
171 171
 			),
172
-			'wl_autocomplete_nonce' => wp_create_nonce( 'wordlift_autocomplete' ),
172
+			'wl_autocomplete_nonce' => wp_create_nonce('wordlift_autocomplete'),
173 173
 		);
174 174
 
175 175
 		// Set post-related values if there's a current post.
176
-		if ( null !== $post = $entity_being_edited = get_post() ) {
176
+		if (null !== $post = $entity_being_edited = get_post()) {
177 177
 
178 178
 			$params['post_id']           = $entity_being_edited->ID;
179 179
 			$entity_service              = Wordlift_Entity_Service::get_instance();
180
-			$params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() );
180
+			$params['entityBeingEdited'] = isset($entity_being_edited->post_type) && $entity_service->is_entity($post->ID) && is_numeric(get_the_ID());
181 181
 			// We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
182 182
 			// from the results, since we don't want the current entity to be discovered by the analysis.
183 183
 			//
184 184
 			// See https://github.com/insideout10/wordlift-plugin/issues/345
185
-			$params['itemId'] = $entity_service->get_uri( $entity_being_edited->ID );
185
+			$params['itemId'] = $entity_service->get_uri($entity_being_edited->ID);
186 186
 
187 187
 		}
188 188
 
189 189
 		// Finally output the params as `wlSettings` for JavaScript code.
190
-		wp_localize_script( $this->plugin_name, 'wlSettings', $params );
190
+		wp_localize_script($this->plugin_name, 'wlSettings', $params);
191 191
 
192 192
 	}
193 193
 
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-settings-page.php 2 patches
Indentation   +362 added lines, -362 removed lines patch added patch discarded remove patch
@@ -18,367 +18,367 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Admin_Settings_Page extends Wordlift_Admin_Page {
20 20
 
21
-	/**
22
-	 * A singleton instance of the Notice service.
23
-	 *
24
-	 * @since  3.2.0
25
-	 * @access private
26
-	 * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service.
27
-	 */
28
-	private static $instance;
29
-
30
-	/**
31
-	 * A {@link Wordlift_Entity_Service} instance.
32
-	 *
33
-	 * @since  3.11.0
34
-	 * @access private
35
-	 * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
36
-	 */
37
-	private $entity_service;
38
-
39
-	/**
40
-	 * A {@link Wordlift_Configuration_Service} instance.
41
-	 *
42
-	 * @since  3.11.0
43
-	 * @access private
44
-	 * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
45
-	 */
46
-	private $configuration_service;
47
-
48
-	/**
49
-	 * A {@link Wordlift_Admin_Input_Element} element renderer.
50
-	 *
51
-	 * @since  3.11.0
52
-	 * @access private
53
-	 * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer.
54
-	 */
55
-	private $input_element;
56
-
57
-	/**
58
-	 * A {@link Wordlift_Admin_Radio_Input_Element} element renderer.
59
-	 *
60
-	 * @since  3.13.0
61
-	 * @access protected
62
-	 * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer.
63
-	 */
64
-	private $radio_input_element;
65
-
66
-	/**
67
-	 * A {@link Wordlift_Admin_Language_Select_Element} element renderer.
68
-	 *
69
-	 * @since  3.11.0
70
-	 * @access private
71
-	 * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
72
-	 */
73
-	private $language_select_element;
74
-
75
-	/**
76
-	 * A {@link Wordlift_Admin_Publisher_Element} element renderer.
77
-	 *
78
-	 * @since  3.11.0
79
-	 * @access private
80
-	 * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer.
81
-	 */
82
-	private $publisher_element;
83
-
84
-	/**
85
-	 * Create a {@link Wordlift_Admin_Settings_Page} instance.
86
-	 *
87
-	 * @since 3.11.0
88
-	 *
89
-	 * @param \Wordlift_Configuration_Service         $configuration_service
90
-	 * @param \Wordlift_Entity_Service                $entity_service
91
-	 * @param \Wordlift_Admin_Input_Element           $input_element
92
-	 * @param \Wordlift_Admin_Language_Select_Element $language_select_element
93
-	 * @param \Wordlift_Admin_Publisher_Element       $publisher_element
94
-	 * @param \Wordlift_Admin_Radio_Input_Element     $radio_input_element
95
-	 */
96
-	function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element ) {
97
-
98
-		$this->configuration_service = $configuration_service;
99
-		$this->entity_service        = $entity_service;
100
-
101
-		// Set a reference to the UI elements.
102
-		$this->input_element           = $input_element;
103
-		$this->radio_input_element     = $radio_input_element;
104
-		$this->language_select_element = $language_select_element;
105
-		$this->publisher_element       = $publisher_element;
106
-
107
-		self::$instance = $this;
108
-	}
109
-
110
-	/**
111
-	 * Get the singleton instance of the Notice service.
112
-	 *
113
-	 * @since 3.14.0
114
-	 * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service.
115
-	 */
116
-	public static function get_instance() {
117
-
118
-		return self::$instance;
119
-	}
120
-
121
-	/**
122
-	 * @inheritdoc
123
-	 */
124
-	function get_parent_slug() {
125
-
126
-		return 'wl_admin_menu';
127
-	}
128
-
129
-	/**
130
-	 * @inheritdoc
131
-	 */
132
-	function get_capability() {
133
-
134
-		return 'manage_options';
135
-	}
136
-
137
-	/**
138
-	 * @inheritdoc
139
-	 */
140
-	function get_page_title() {
141
-
142
-		return 'WorldLift Settings';
143
-	}
144
-
145
-	/**
146
-	 * @inheritdoc
147
-	 */
148
-	function get_menu_title() {
149
-
150
-		return 'Settings';
151
-	}
152
-
153
-	/**
154
-	 * @inheritdoc
155
-	 */
156
-	function get_menu_slug() {
157
-
158
-		return 'wl_configuration_admin_menu';
159
-	}
160
-
161
-	/**
162
-	 * @inheritdoc
163
-	 */
164
-	function get_partial_name() {
165
-
166
-		return 'wordlift-admin-settings-page.php';
167
-	}
168
-
169
-	/**
170
-	 * @inheritdoc
171
-	 */
172
-	public function enqueue_scripts() {
173
-
174
-		// Enqueue the media scripts to be used for the publisher's logo selection.
175
-		wp_enqueue_media();
176
-
177
-		// JavaScript required for the settings page.
178
-		// @todo: try to move to the `wordlift-admin.bundle.js`.
179
-		wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.js', array( 'wp-util' ) );
180
-		wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' );
181
-
182
-	}
183
-
184
-	/**
185
-	 * Configure all the configuration parameters.
186
-	 *
187
-	 * Called by the *admin_init* hook.
188
-	 *
189
-	 * @since 3.11.0
190
-	 */
191
-	function admin_init() {
192
-
193
-		// Register WordLift's general settings, providing our own sanitize callback
194
-		// which will also check whether the user filled the WL Publisher form.
195
-		register_setting(
196
-			'wl_general_settings',
197
-			'wl_general_settings',
198
-			array( $this, 'sanitize_callback', )
199
-		);
200
-
201
-		// Add the general settings section.
202
-		add_settings_section(
203
-			'wl_general_settings_section', // ID used to identify this section and with which to register options.
204
-			'',                            // Section header.
205
-			'',                            // Callback used to render the description of the section.
206
-			'wl_general_settings'          // Page on which to add this section of options.
207
-		);
208
-
209
-		$key_args = array(
210
-			'id'          => 'wl-key',
211
-			'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']',
212
-			'value'       => $this->configuration_service->get_key(),
213
-			'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ),
214
-		);
215
-
216
-		// Before we were used to validate the key beforehand, but this means
217
-		// an http call whenever a page is opened in the admin area. Therefore
218
-		// we now leave the input `untouched`, leaving to the client to update
219
-		// the `css_class`.
220
-		//
221
-		// See https://github.com/insideout10/wordlift-plugin/issues/669.
222
-		$key_args['css_class'] = 'untouched';
223
-
224
-		// Add the `key` field.
225
-		add_settings_field(
226
-			'wl-key',                                       // Element id used to identify the field throughout the theme.
227
-			__( 'WordLift Key', 'wordlift' ),               // The label to the left of the option interface element.
228
-			// The name of the function responsible for rendering the option interface.
229
-			array( $this->input_element, 'render', ),
230
-			'wl_general_settings',                          // The page on which this option will be displayed.
231
-			'wl_general_settings_section',                  // The name of the section to which this field belongs.
232
-			$key_args                                       // The array of arguments to pass to the callback. In this case, just a description.
233
-		);
234
-
235
-		// Entity Base Path input.
236
-		$entity_base_path_args = array(
237
-			// The array of arguments to pass to the callback. In this case, just a description.
238
-			'id'          => 'wl-entity-base-path',
239
-			'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']',
240
-			'value'       => $this->configuration_service->get_entity_base_path(),
241
-			/* translators: Placeholders: %s - a link to FAQ's page. */
242
-			'description' => sprintf( __( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ),
243
-		);
244
-
245
-		// The following call is very heavy on large web sites and is always run
246
-		// also when not needed:
247
-		//  $entity_base_path_args['readonly'] = 0 < $this->entity_service->count();
248
-		//
249
-		// It is now replaced by a filter to add the `readonly` flag to the
250
-		// input element when this is actually rendered.
251
-		add_filter( 'wl_admin_input_element_params', array(
252
-			$this,
253
-			'entity_path_input_element_params',
254
-		) );
255
-
256
-
257
-		// Add the `wl_entity_base_path` field.
258
-		add_settings_field(
259
-			'wl-entity-base-path',                                // ID used to identify the field throughout the theme
260
-			__( 'Entity Base Path', 'wordlift' ),                 // The label to the left of the option interface element
261
-			// The name of the function responsible for rendering the option interface
262
-			array( $this->input_element, 'render', ),
263
-			'wl_general_settings',                                // The page on which this option will be displayed
264
-			'wl_general_settings_section',                        // The name of the section to which this field belongs
265
-			$entity_base_path_args
266
-		);
267
-
268
-		// Add the `language_name` field.
269
-		add_settings_field(
270
-			'wl-site-language',
271
-			__( 'Site Language', 'wordlift' ),
272
-			array( $this->language_select_element, 'render' ),
273
-			'wl_general_settings',
274
-			'wl_general_settings_section',
275
-			array(
276
-				// The array of arguments to pass to the callback. In this case, just a description.
277
-				'id'          => 'wl-site-language',
278
-				'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']',
279
-				'value'       => $this->configuration_service->get_language_code(),
280
-				'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ),
281
-			)
282
-		);
283
-
284
-		// Add the `publisher` field.
285
-		add_settings_field(
286
-			'wl-publisher-id',
287
-			__( 'Publisher', 'wordlift' ),
288
-			array( $this->publisher_element, 'render' ),
289
-			'wl_general_settings',
290
-			'wl_general_settings_section',
291
-			array(
292
-				'id'   => 'wl-publisher-id',
293
-				'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']',
294
-			)
295
-		);
296
-
297
-		// Add the `link by default` field.
298
-		add_settings_field(
299
-			'wl-link-by-default',
300
-			__( 'Link by Default', 'wordlift' ),
301
-			array( $this->radio_input_element, 'render' ),
302
-			'wl_general_settings',
303
-			'wl_general_settings_section',
304
-			array(
305
-				'id'          => 'wl-link-by-default',
306
-				'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']',
307
-				'value'       => $this->configuration_service->is_link_by_default() ? 'yes' : 'no',
308
-				'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ),
309
-			)
310
-		);
311
-
312
-		// Add the `diagnostic data` field.
313
-		add_settings_field(
314
-			'wl-send-diagnostic',
315
-			__( 'Send Diagnostic Data', 'wordlift' ),
316
-			array( $this->radio_input_element, 'render' ),
317
-			'wl_general_settings',
318
-			'wl_general_settings_section',
319
-			array(
320
-				'id'          => 'wl-send-diagnostic',
321
-				'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']',
322
-				'value'       => 'yes' === $this->configuration_service->get_diagnostic_preferences() ? 'yes' : 'no',
323
-				'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ),
324
-			)
325
-		);
326
-
327
-	}
328
-
329
-	/**
330
-	 * Filter the {@link Wordlift_Admin_Input_Element} in order to add the
331
-	 * `readonly` flag to the `wl-entity-base-path` input.
332
-	 *
333
-	 * @since 3.17.0
334
-	 *
335
-	 * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters.
336
-	 *
337
-	 * @return array The updated array.
338
-	 */
339
-	public function entity_path_input_element_params( $args ) {
340
-
341
-		// Bail out if it's not the `wl-entity-base-path`).
342
-		if ( 'wl-entity-base-path' !== $args['id'] ) {
343
-			return $args;
344
-		}
345
-
346
-		// Set the readonly flag according to the entities count.
347
-		$args['readonly'] = 0 < $this->entity_service->count();
348
-
349
-		// Return the updated args.
350
-		return $args;
351
-	}
352
-
353
-	/**
354
-	 * Sanitize the configuration settings to be stored.
355
-	 *
356
-	 * If a new entity is being created for the publisher, create it and set The
357
-	 * publisher setting.
358
-	 *
359
-	 * @since 3.11.0
360
-	 *
361
-	 * @param array $input The configuration settings array.
362
-	 *
363
-	 * @return array The sanitized input array.
364
-	 */
365
-	function sanitize_callback( $input ) {
366
-
367
-		// Check whether a publisher name has been set.
368
-		if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) {
369
-			$name         = $_POST['wl_publisher']['name'];
370
-			$type         = $_POST['wl_publisher']['type'];
371
-			$thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null;
372
-
373
-			// Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
374
-			$type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' );
375
-
376
-			// Create an entity for the publisher and assign it to the input
377
-			// parameter which WordPress automatically saves into the settings.
378
-			$input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' );
379
-		}
380
-
381
-		return $input;
382
-	}
21
+    /**
22
+     * A singleton instance of the Notice service.
23
+     *
24
+     * @since  3.2.0
25
+     * @access private
26
+     * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service.
27
+     */
28
+    private static $instance;
29
+
30
+    /**
31
+     * A {@link Wordlift_Entity_Service} instance.
32
+     *
33
+     * @since  3.11.0
34
+     * @access private
35
+     * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
36
+     */
37
+    private $entity_service;
38
+
39
+    /**
40
+     * A {@link Wordlift_Configuration_Service} instance.
41
+     *
42
+     * @since  3.11.0
43
+     * @access private
44
+     * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
45
+     */
46
+    private $configuration_service;
47
+
48
+    /**
49
+     * A {@link Wordlift_Admin_Input_Element} element renderer.
50
+     *
51
+     * @since  3.11.0
52
+     * @access private
53
+     * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer.
54
+     */
55
+    private $input_element;
56
+
57
+    /**
58
+     * A {@link Wordlift_Admin_Radio_Input_Element} element renderer.
59
+     *
60
+     * @since  3.13.0
61
+     * @access protected
62
+     * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer.
63
+     */
64
+    private $radio_input_element;
65
+
66
+    /**
67
+     * A {@link Wordlift_Admin_Language_Select_Element} element renderer.
68
+     *
69
+     * @since  3.11.0
70
+     * @access private
71
+     * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
72
+     */
73
+    private $language_select_element;
74
+
75
+    /**
76
+     * A {@link Wordlift_Admin_Publisher_Element} element renderer.
77
+     *
78
+     * @since  3.11.0
79
+     * @access private
80
+     * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer.
81
+     */
82
+    private $publisher_element;
83
+
84
+    /**
85
+     * Create a {@link Wordlift_Admin_Settings_Page} instance.
86
+     *
87
+     * @since 3.11.0
88
+     *
89
+     * @param \Wordlift_Configuration_Service         $configuration_service
90
+     * @param \Wordlift_Entity_Service                $entity_service
91
+     * @param \Wordlift_Admin_Input_Element           $input_element
92
+     * @param \Wordlift_Admin_Language_Select_Element $language_select_element
93
+     * @param \Wordlift_Admin_Publisher_Element       $publisher_element
94
+     * @param \Wordlift_Admin_Radio_Input_Element     $radio_input_element
95
+     */
96
+    function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element ) {
97
+
98
+        $this->configuration_service = $configuration_service;
99
+        $this->entity_service        = $entity_service;
100
+
101
+        // Set a reference to the UI elements.
102
+        $this->input_element           = $input_element;
103
+        $this->radio_input_element     = $radio_input_element;
104
+        $this->language_select_element = $language_select_element;
105
+        $this->publisher_element       = $publisher_element;
106
+
107
+        self::$instance = $this;
108
+    }
109
+
110
+    /**
111
+     * Get the singleton instance of the Notice service.
112
+     *
113
+     * @since 3.14.0
114
+     * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service.
115
+     */
116
+    public static function get_instance() {
117
+
118
+        return self::$instance;
119
+    }
120
+
121
+    /**
122
+     * @inheritdoc
123
+     */
124
+    function get_parent_slug() {
125
+
126
+        return 'wl_admin_menu';
127
+    }
128
+
129
+    /**
130
+     * @inheritdoc
131
+     */
132
+    function get_capability() {
133
+
134
+        return 'manage_options';
135
+    }
136
+
137
+    /**
138
+     * @inheritdoc
139
+     */
140
+    function get_page_title() {
141
+
142
+        return 'WorldLift Settings';
143
+    }
144
+
145
+    /**
146
+     * @inheritdoc
147
+     */
148
+    function get_menu_title() {
149
+
150
+        return 'Settings';
151
+    }
152
+
153
+    /**
154
+     * @inheritdoc
155
+     */
156
+    function get_menu_slug() {
157
+
158
+        return 'wl_configuration_admin_menu';
159
+    }
160
+
161
+    /**
162
+     * @inheritdoc
163
+     */
164
+    function get_partial_name() {
165
+
166
+        return 'wordlift-admin-settings-page.php';
167
+    }
168
+
169
+    /**
170
+     * @inheritdoc
171
+     */
172
+    public function enqueue_scripts() {
173
+
174
+        // Enqueue the media scripts to be used for the publisher's logo selection.
175
+        wp_enqueue_media();
176
+
177
+        // JavaScript required for the settings page.
178
+        // @todo: try to move to the `wordlift-admin.bundle.js`.
179
+        wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.js', array( 'wp-util' ) );
180
+        wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' );
181
+
182
+    }
183
+
184
+    /**
185
+     * Configure all the configuration parameters.
186
+     *
187
+     * Called by the *admin_init* hook.
188
+     *
189
+     * @since 3.11.0
190
+     */
191
+    function admin_init() {
192
+
193
+        // Register WordLift's general settings, providing our own sanitize callback
194
+        // which will also check whether the user filled the WL Publisher form.
195
+        register_setting(
196
+            'wl_general_settings',
197
+            'wl_general_settings',
198
+            array( $this, 'sanitize_callback', )
199
+        );
200
+
201
+        // Add the general settings section.
202
+        add_settings_section(
203
+            'wl_general_settings_section', // ID used to identify this section and with which to register options.
204
+            '',                            // Section header.
205
+            '',                            // Callback used to render the description of the section.
206
+            'wl_general_settings'          // Page on which to add this section of options.
207
+        );
208
+
209
+        $key_args = array(
210
+            'id'          => 'wl-key',
211
+            'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']',
212
+            'value'       => $this->configuration_service->get_key(),
213
+            'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ),
214
+        );
215
+
216
+        // Before we were used to validate the key beforehand, but this means
217
+        // an http call whenever a page is opened in the admin area. Therefore
218
+        // we now leave the input `untouched`, leaving to the client to update
219
+        // the `css_class`.
220
+        //
221
+        // See https://github.com/insideout10/wordlift-plugin/issues/669.
222
+        $key_args['css_class'] = 'untouched';
223
+
224
+        // Add the `key` field.
225
+        add_settings_field(
226
+            'wl-key',                                       // Element id used to identify the field throughout the theme.
227
+            __( 'WordLift Key', 'wordlift' ),               // The label to the left of the option interface element.
228
+            // The name of the function responsible for rendering the option interface.
229
+            array( $this->input_element, 'render', ),
230
+            'wl_general_settings',                          // The page on which this option will be displayed.
231
+            'wl_general_settings_section',                  // The name of the section to which this field belongs.
232
+            $key_args                                       // The array of arguments to pass to the callback. In this case, just a description.
233
+        );
234
+
235
+        // Entity Base Path input.
236
+        $entity_base_path_args = array(
237
+            // The array of arguments to pass to the callback. In this case, just a description.
238
+            'id'          => 'wl-entity-base-path',
239
+            'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']',
240
+            'value'       => $this->configuration_service->get_entity_base_path(),
241
+            /* translators: Placeholders: %s - a link to FAQ's page. */
242
+            'description' => sprintf( __( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ),
243
+        );
244
+
245
+        // The following call is very heavy on large web sites and is always run
246
+        // also when not needed:
247
+        //  $entity_base_path_args['readonly'] = 0 < $this->entity_service->count();
248
+        //
249
+        // It is now replaced by a filter to add the `readonly` flag to the
250
+        // input element when this is actually rendered.
251
+        add_filter( 'wl_admin_input_element_params', array(
252
+            $this,
253
+            'entity_path_input_element_params',
254
+        ) );
255
+
256
+
257
+        // Add the `wl_entity_base_path` field.
258
+        add_settings_field(
259
+            'wl-entity-base-path',                                // ID used to identify the field throughout the theme
260
+            __( 'Entity Base Path', 'wordlift' ),                 // The label to the left of the option interface element
261
+            // The name of the function responsible for rendering the option interface
262
+            array( $this->input_element, 'render', ),
263
+            'wl_general_settings',                                // The page on which this option will be displayed
264
+            'wl_general_settings_section',                        // The name of the section to which this field belongs
265
+            $entity_base_path_args
266
+        );
267
+
268
+        // Add the `language_name` field.
269
+        add_settings_field(
270
+            'wl-site-language',
271
+            __( 'Site Language', 'wordlift' ),
272
+            array( $this->language_select_element, 'render' ),
273
+            'wl_general_settings',
274
+            'wl_general_settings_section',
275
+            array(
276
+                // The array of arguments to pass to the callback. In this case, just a description.
277
+                'id'          => 'wl-site-language',
278
+                'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']',
279
+                'value'       => $this->configuration_service->get_language_code(),
280
+                'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ),
281
+            )
282
+        );
283
+
284
+        // Add the `publisher` field.
285
+        add_settings_field(
286
+            'wl-publisher-id',
287
+            __( 'Publisher', 'wordlift' ),
288
+            array( $this->publisher_element, 'render' ),
289
+            'wl_general_settings',
290
+            'wl_general_settings_section',
291
+            array(
292
+                'id'   => 'wl-publisher-id',
293
+                'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']',
294
+            )
295
+        );
296
+
297
+        // Add the `link by default` field.
298
+        add_settings_field(
299
+            'wl-link-by-default',
300
+            __( 'Link by Default', 'wordlift' ),
301
+            array( $this->radio_input_element, 'render' ),
302
+            'wl_general_settings',
303
+            'wl_general_settings_section',
304
+            array(
305
+                'id'          => 'wl-link-by-default',
306
+                'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']',
307
+                'value'       => $this->configuration_service->is_link_by_default() ? 'yes' : 'no',
308
+                'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ),
309
+            )
310
+        );
311
+
312
+        // Add the `diagnostic data` field.
313
+        add_settings_field(
314
+            'wl-send-diagnostic',
315
+            __( 'Send Diagnostic Data', 'wordlift' ),
316
+            array( $this->radio_input_element, 'render' ),
317
+            'wl_general_settings',
318
+            'wl_general_settings_section',
319
+            array(
320
+                'id'          => 'wl-send-diagnostic',
321
+                'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']',
322
+                'value'       => 'yes' === $this->configuration_service->get_diagnostic_preferences() ? 'yes' : 'no',
323
+                'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ),
324
+            )
325
+        );
326
+
327
+    }
328
+
329
+    /**
330
+     * Filter the {@link Wordlift_Admin_Input_Element} in order to add the
331
+     * `readonly` flag to the `wl-entity-base-path` input.
332
+     *
333
+     * @since 3.17.0
334
+     *
335
+     * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters.
336
+     *
337
+     * @return array The updated array.
338
+     */
339
+    public function entity_path_input_element_params( $args ) {
340
+
341
+        // Bail out if it's not the `wl-entity-base-path`).
342
+        if ( 'wl-entity-base-path' !== $args['id'] ) {
343
+            return $args;
344
+        }
345
+
346
+        // Set the readonly flag according to the entities count.
347
+        $args['readonly'] = 0 < $this->entity_service->count();
348
+
349
+        // Return the updated args.
350
+        return $args;
351
+    }
352
+
353
+    /**
354
+     * Sanitize the configuration settings to be stored.
355
+     *
356
+     * If a new entity is being created for the publisher, create it and set The
357
+     * publisher setting.
358
+     *
359
+     * @since 3.11.0
360
+     *
361
+     * @param array $input The configuration settings array.
362
+     *
363
+     * @return array The sanitized input array.
364
+     */
365
+    function sanitize_callback( $input ) {
366
+
367
+        // Check whether a publisher name has been set.
368
+        if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) {
369
+            $name         = $_POST['wl_publisher']['name'];
370
+            $type         = $_POST['wl_publisher']['type'];
371
+            $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null;
372
+
373
+            // Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
374
+            $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' );
375
+
376
+            // Create an entity for the publisher and assign it to the input
377
+            // parameter which WordPress automatically saves into the settings.
378
+            $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' );
379
+        }
380
+
381
+        return $input;
382
+    }
383 383
 
384 384
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @param \Wordlift_Admin_Publisher_Element       $publisher_element
94 94
 	 * @param \Wordlift_Admin_Radio_Input_Element     $radio_input_element
95 95
 	 */
96
-	function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element ) {
96
+	function __construct($configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element) {
97 97
 
98 98
 		$this->configuration_service = $configuration_service;
99 99
 		$this->entity_service        = $entity_service;
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
 
177 177
 		// JavaScript required for the settings page.
178 178
 		// @todo: try to move to the `wordlift-admin.bundle.js`.
179
-		wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.js', array( 'wp-util' ) );
180
-		wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' );
179
+		wp_enqueue_script('wordlift-admin-settings-page', plugin_dir_url(dirname(__FILE__)).'admin/js/1/settings.js', array('wp-util'));
180
+		wp_enqueue_style('wordlift-admin-settings-page', plugin_dir_url(dirname(__FILE__)).'admin/js/1/settings.css');
181 181
 
182 182
 	}
183 183
 
@@ -195,22 +195,22 @@  discard block
 block discarded – undo
195 195
 		register_setting(
196 196
 			'wl_general_settings',
197 197
 			'wl_general_settings',
198
-			array( $this, 'sanitize_callback', )
198
+			array($this, 'sanitize_callback',)
199 199
 		);
200 200
 
201 201
 		// Add the general settings section.
202 202
 		add_settings_section(
203 203
 			'wl_general_settings_section', // ID used to identify this section and with which to register options.
204
-			'',                            // Section header.
205
-			'',                            // Callback used to render the description of the section.
204
+			'', // Section header.
205
+			'', // Callback used to render the description of the section.
206 206
 			'wl_general_settings'          // Page on which to add this section of options.
207 207
 		);
208 208
 
209 209
 		$key_args = array(
210 210
 			'id'          => 'wl-key',
211
-			'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']',
211
+			'name'        => 'wl_general_settings['.Wordlift_Configuration_Service::KEY.']',
212 212
 			'value'       => $this->configuration_service->get_key(),
213
-			'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ),
213
+			'description' => __('Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift'),
214 214
 		);
215 215
 
216 216
 		// Before we were used to validate the key beforehand, but this means
@@ -223,12 +223,12 @@  discard block
 block discarded – undo
223 223
 
224 224
 		// Add the `key` field.
225 225
 		add_settings_field(
226
-			'wl-key',                                       // Element id used to identify the field throughout the theme.
227
-			__( 'WordLift Key', 'wordlift' ),               // The label to the left of the option interface element.
226
+			'wl-key', // Element id used to identify the field throughout the theme.
227
+			__('WordLift Key', 'wordlift'), // The label to the left of the option interface element.
228 228
 			// The name of the function responsible for rendering the option interface.
229
-			array( $this->input_element, 'render', ),
230
-			'wl_general_settings',                          // The page on which this option will be displayed.
231
-			'wl_general_settings_section',                  // The name of the section to which this field belongs.
229
+			array($this->input_element, 'render',),
230
+			'wl_general_settings', // The page on which this option will be displayed.
231
+			'wl_general_settings_section', // The name of the section to which this field belongs.
232 232
 			$key_args                                       // The array of arguments to pass to the callback. In this case, just a description.
233 233
 		);
234 234
 
@@ -236,10 +236,10 @@  discard block
 block discarded – undo
236 236
 		$entity_base_path_args = array(
237 237
 			// The array of arguments to pass to the callback. In this case, just a description.
238 238
 			'id'          => 'wl-entity-base-path',
239
-			'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']',
239
+			'name'        => 'wl_general_settings['.Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY.']',
240 240
 			'value'       => $this->configuration_service->get_entity_base_path(),
241 241
 			/* translators: Placeholders: %s - a link to FAQ's page. */
242
-			'description' => sprintf( __( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ),
242
+			'description' => sprintf(__('All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift'), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary'),
243 243
 		);
244 244
 
245 245
 		// The following call is very heavy on large web sites and is always run
@@ -248,79 +248,79 @@  discard block
 block discarded – undo
248 248
 		//
249 249
 		// It is now replaced by a filter to add the `readonly` flag to the
250 250
 		// input element when this is actually rendered.
251
-		add_filter( 'wl_admin_input_element_params', array(
251
+		add_filter('wl_admin_input_element_params', array(
252 252
 			$this,
253 253
 			'entity_path_input_element_params',
254
-		) );
254
+		));
255 255
 
256 256
 
257 257
 		// Add the `wl_entity_base_path` field.
258 258
 		add_settings_field(
259
-			'wl-entity-base-path',                                // ID used to identify the field throughout the theme
260
-			__( 'Entity Base Path', 'wordlift' ),                 // The label to the left of the option interface element
259
+			'wl-entity-base-path', // ID used to identify the field throughout the theme
260
+			__('Entity Base Path', 'wordlift'), // The label to the left of the option interface element
261 261
 			// The name of the function responsible for rendering the option interface
262
-			array( $this->input_element, 'render', ),
263
-			'wl_general_settings',                                // The page on which this option will be displayed
264
-			'wl_general_settings_section',                        // The name of the section to which this field belongs
262
+			array($this->input_element, 'render',),
263
+			'wl_general_settings', // The page on which this option will be displayed
264
+			'wl_general_settings_section', // The name of the section to which this field belongs
265 265
 			$entity_base_path_args
266 266
 		);
267 267
 
268 268
 		// Add the `language_name` field.
269 269
 		add_settings_field(
270 270
 			'wl-site-language',
271
-			__( 'Site Language', 'wordlift' ),
272
-			array( $this->language_select_element, 'render' ),
271
+			__('Site Language', 'wordlift'),
272
+			array($this->language_select_element, 'render'),
273 273
 			'wl_general_settings',
274 274
 			'wl_general_settings_section',
275 275
 			array(
276 276
 				// The array of arguments to pass to the callback. In this case, just a description.
277 277
 				'id'          => 'wl-site-language',
278
-				'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']',
278
+				'name'        => 'wl_general_settings['.Wordlift_Configuration_Service::LANGUAGE.']',
279 279
 				'value'       => $this->configuration_service->get_language_code(),
280
-				'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ),
280
+				'description' => __('Each WordLift Key can be used only in one language. Pick yours.', 'wordlift'),
281 281
 			)
282 282
 		);
283 283
 
284 284
 		// Add the `publisher` field.
285 285
 		add_settings_field(
286 286
 			'wl-publisher-id',
287
-			__( 'Publisher', 'wordlift' ),
288
-			array( $this->publisher_element, 'render' ),
287
+			__('Publisher', 'wordlift'),
288
+			array($this->publisher_element, 'render'),
289 289
 			'wl_general_settings',
290 290
 			'wl_general_settings_section',
291 291
 			array(
292 292
 				'id'   => 'wl-publisher-id',
293
-				'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']',
293
+				'name' => 'wl_general_settings['.Wordlift_Configuration_Service::PUBLISHER_ID.']',
294 294
 			)
295 295
 		);
296 296
 
297 297
 		// Add the `link by default` field.
298 298
 		add_settings_field(
299 299
 			'wl-link-by-default',
300
-			__( 'Link by Default', 'wordlift' ),
301
-			array( $this->radio_input_element, 'render' ),
300
+			__('Link by Default', 'wordlift'),
301
+			array($this->radio_input_element, 'render'),
302 302
 			'wl_general_settings',
303 303
 			'wl_general_settings_section',
304 304
 			array(
305 305
 				'id'          => 'wl-link-by-default',
306
-				'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']',
306
+				'name'        => 'wl_general_settings['.Wordlift_Configuration_Service::LINK_BY_DEFAULT.']',
307 307
 				'value'       => $this->configuration_service->is_link_by_default() ? 'yes' : 'no',
308
-				'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ),
308
+				'description' => __('Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift'),
309 309
 			)
310 310
 		);
311 311
 
312 312
 		// Add the `diagnostic data` field.
313 313
 		add_settings_field(
314 314
 			'wl-send-diagnostic',
315
-			__( 'Send Diagnostic Data', 'wordlift' ),
316
-			array( $this->radio_input_element, 'render' ),
315
+			__('Send Diagnostic Data', 'wordlift'),
316
+			array($this->radio_input_element, 'render'),
317 317
 			'wl_general_settings',
318 318
 			'wl_general_settings_section',
319 319
 			array(
320 320
 				'id'          => 'wl-send-diagnostic',
321
-				'name'        => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']',
321
+				'name'        => 'wl_general_settings['.Wordlift_Configuration_Service::SEND_DIAGNOSTIC.']',
322 322
 				'value'       => 'yes' === $this->configuration_service->get_diagnostic_preferences() ? 'yes' : 'no',
323
-				'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ),
323
+				'description' => __('Whether to send diagnostic data or not.', 'wordlift'),
324 324
 			)
325 325
 		);
326 326
 
@@ -336,10 +336,10 @@  discard block
 block discarded – undo
336 336
 	 *
337 337
 	 * @return array The updated array.
338 338
 	 */
339
-	public function entity_path_input_element_params( $args ) {
339
+	public function entity_path_input_element_params($args) {
340 340
 
341 341
 		// Bail out if it's not the `wl-entity-base-path`).
342
-		if ( 'wl-entity-base-path' !== $args['id'] ) {
342
+		if ('wl-entity-base-path' !== $args['id']) {
343 343
 			return $args;
344 344
 		}
345 345
 
@@ -362,20 +362,20 @@  discard block
 block discarded – undo
362 362
 	 *
363 363
 	 * @return array The sanitized input array.
364 364
 	 */
365
-	function sanitize_callback( $input ) {
365
+	function sanitize_callback($input) {
366 366
 
367 367
 		// Check whether a publisher name has been set.
368
-		if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) {
368
+		if (isset($_POST['wl_publisher']) && ! empty($_POST['wl_publisher']['name'])) {
369 369
 			$name         = $_POST['wl_publisher']['name'];
370 370
 			$type         = $_POST['wl_publisher']['type'];
371 371
 			$thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null;
372 372
 
373 373
 			// Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
374
-			$type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' );
374
+			$type_uri = sprintf('http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person');
375 375
 
376 376
 			// Create an entity for the publisher and assign it to the input
377 377
 			// parameter which WordPress automatically saves into the settings.
378
-			$input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' );
378
+			$input['publisher_id'] = $this->entity_service->create($name, $type_uri, $thumbnail_id, 'publish');
379 379
 		}
380 380
 
381 381
 		return $input;
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-dashboard-latest-news.php 2 patches
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -20,145 +20,145 @@
 block discarded – undo
20 20
  */
21 21
 class Wordlift_Dashboard_Latest_News {
22 22
 
23
-	/**
24
-	 * Add needed hooks for the latest news widget.
25
-	 */
26
-	public function __construct() {
27
-		add_action( 'wp_ajax_wordlift_get_latest_news', array(
28
-			$this,
29
-			'ajax_get_latest_news',
30
-		) );
31
-		add_action( 'wp_dashboard_setup', array(
32
-			$this,
33
-			'add_dashboard_latest_news_widget',
34
-		) );
35
-
36
-		add_action( 'admin_enqueue_scripts', function () {
37
-			wp_enqueue_script( 'wl-admin-dashboard', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift-admin-dashboard.js', array( 'jquery' ) );
38
-		} );
39
-	}
40
-
41
-	/**
42
-	 * Return latest news html.
43
-	 *
44
-	 * @return string Articles html markup.
45
-	 */
46
-	public function render() {
47
-		include( plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-news-widget.php' );
48
-	}
49
-
50
-	/**
51
-	 * Returns latest news data filtered by $start_position.
52
-	 *
53
-	 * @param int $start_position (news array key start position).
54
-	 *
55
-	 * @return array Latest posts data.
56
-	 */
57
-	public function get_last_wordlift_articles( $start_position = 0 ) {
58
-		$feed_articles = $this->get_wordlift_articles_data();
59
-
60
-		// Filter articles by $start_position
61
-		if ( ! empty( $feed_articles ) ) {
62
-			return array(
63
-				'posts_data'     => array_slice( $feed_articles, $start_position, 3 ),
64
-				'count'          => count( $feed_articles ),
65
-				'start_position' => $start_position,
66
-			);
67
-		}
68
-
69
-		return false;
70
-	}
71
-
72
-	/**
73
-	 * Returns latest news array data.
74
-	 *
75
-	 * @uses  https://codex.wordpress.org/Function_Reference/fetch_feed
76
-	 * @uses  https://codex.wordpress.org/Function_Reference/get_locale
77
-	 *
78
-	 * @param int $articles_number (articles total number).
79
-	 *
80
-	 * @return array Latest $articles_number feed posts.
81
-	 */
82
-	public function get_wordlift_articles_data( $articles_number = 10 ) {
83
-		// Init cache class
84
-		$cache_sistem_lib = new Wordlift_File_Cache_Service( WL_TEMP_DIR . 'articles/' );
85
-		$locale           = get_locale();
86
-		$cache_id         = 'news_' . date( 'Y_m_d' ) . '_' . $locale;
87
-		$posts_data       = array();
88
-
89
-		// Get latest articles from cache
90
-		$feed_articles = $cache_sistem_lib->get_cache( $cache_id );
91
-		if ( false === $feed_articles ) {
92
-			// Check wordpress installation language to define articles rss url
93
-			$feed_uri = ( 'it_IT' === $locale ) ? 'https://wordlift.io/blog/it/feed/' : 'https://wordlift.io/blog/en/feed/';
94
-
95
-			// Get rss feed data, the response is cached by default for 12 hours
96
-			$feed = fetch_feed( $feed_uri );
97
-			if ( ! is_wp_error( $feed ) ) {
98
-				// Build an array of requested $articles_number, starting with element 0
99
-				$feed_articles = $feed->get_items( 0, $articles_number );
100
-				foreach ( $feed_articles as $key => $item ) {
101
-					$data = array(
102
-						// fetch_feed will return the title html decoded.
103
-						'post_title'       => $item->get_title(),
104
-						'post_date'        => $item->get_date( 'j F Y | g:i a' ),
105
-						'post_url'         => self::add_utm_parameter( $item->get_permalink() ),
106
-						// fetch_feed will return the description html (not decoded).
107
-						'post_description' => $item->get_description(),
108
-					);
109
-					array_push( $posts_data, $data );
110
-				}
111
-				// Set articles in cache.
112
-				$cache_sistem_lib->set_cache( $cache_id, $posts_data );
113
-				$feed_articles = $posts_data;
114
-			}
115
-		}
116
-
117
-		return $feed_articles;
118
-	}
119
-
120
-	/**
121
-	 * Add the `utm` parameter for GA.
122
-	 *
123
-	 * @since 3.19.0
124
-	 *
125
-	 * @param string $url The URL.
126
-	 *
127
-	 * @return string The URL with the `utm` parameter prepended by `&` or by `?`.
128
-	 */
129
-	private static function add_utm_parameter( $url ) {
130
-
131
-		if ( false === strpos( $url, '?' ) ) {
132
-			return $url . '?utm=wl_dash';
133
-		}
134
-
135
-		return $url . '&utm=wl_dash';
136
-	}
137
-
138
-	/**
139
-	 * Ajax call for more latest news.
140
-	 *
141
-	 * @uses  https://codex.wordpress.org/Function_Reference/wp_send_json_success
142
-	 *
143
-	 * @return string JSON obj with articles data.
144
-	 */
145
-	public function ajax_get_latest_news() {
146
-		// Get wordlift articles
147
-		$start_position = explode( '_', $_POST['more_posts_link_id'] );
148
-		$data           = $this->get_last_wordlift_articles( $start_position[ count( $start_position ) - 1 ] );
149
-
150
-		// Return response as json object
151
-		wp_send_json_success( $data );
152
-	}
153
-
154
-	/**
155
-	 * Add latest news widget to the administration dashboard.
156
-	 */
157
-	public function add_dashboard_latest_news_widget() {
158
-		wp_add_dashboard_widget( 'wordlift-dashboard-latest-news-widget', 'Latest WordLift News', array(
159
-			$this,
160
-			'render',
161
-		) );
162
-	}
23
+    /**
24
+     * Add needed hooks for the latest news widget.
25
+     */
26
+    public function __construct() {
27
+        add_action( 'wp_ajax_wordlift_get_latest_news', array(
28
+            $this,
29
+            'ajax_get_latest_news',
30
+        ) );
31
+        add_action( 'wp_dashboard_setup', array(
32
+            $this,
33
+            'add_dashboard_latest_news_widget',
34
+        ) );
35
+
36
+        add_action( 'admin_enqueue_scripts', function () {
37
+            wp_enqueue_script( 'wl-admin-dashboard', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift-admin-dashboard.js', array( 'jquery' ) );
38
+        } );
39
+    }
40
+
41
+    /**
42
+     * Return latest news html.
43
+     *
44
+     * @return string Articles html markup.
45
+     */
46
+    public function render() {
47
+        include( plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-news-widget.php' );
48
+    }
49
+
50
+    /**
51
+     * Returns latest news data filtered by $start_position.
52
+     *
53
+     * @param int $start_position (news array key start position).
54
+     *
55
+     * @return array Latest posts data.
56
+     */
57
+    public function get_last_wordlift_articles( $start_position = 0 ) {
58
+        $feed_articles = $this->get_wordlift_articles_data();
59
+
60
+        // Filter articles by $start_position
61
+        if ( ! empty( $feed_articles ) ) {
62
+            return array(
63
+                'posts_data'     => array_slice( $feed_articles, $start_position, 3 ),
64
+                'count'          => count( $feed_articles ),
65
+                'start_position' => $start_position,
66
+            );
67
+        }
68
+
69
+        return false;
70
+    }
71
+
72
+    /**
73
+     * Returns latest news array data.
74
+     *
75
+     * @uses  https://codex.wordpress.org/Function_Reference/fetch_feed
76
+     * @uses  https://codex.wordpress.org/Function_Reference/get_locale
77
+     *
78
+     * @param int $articles_number (articles total number).
79
+     *
80
+     * @return array Latest $articles_number feed posts.
81
+     */
82
+    public function get_wordlift_articles_data( $articles_number = 10 ) {
83
+        // Init cache class
84
+        $cache_sistem_lib = new Wordlift_File_Cache_Service( WL_TEMP_DIR . 'articles/' );
85
+        $locale           = get_locale();
86
+        $cache_id         = 'news_' . date( 'Y_m_d' ) . '_' . $locale;
87
+        $posts_data       = array();
88
+
89
+        // Get latest articles from cache
90
+        $feed_articles = $cache_sistem_lib->get_cache( $cache_id );
91
+        if ( false === $feed_articles ) {
92
+            // Check wordpress installation language to define articles rss url
93
+            $feed_uri = ( 'it_IT' === $locale ) ? 'https://wordlift.io/blog/it/feed/' : 'https://wordlift.io/blog/en/feed/';
94
+
95
+            // Get rss feed data, the response is cached by default for 12 hours
96
+            $feed = fetch_feed( $feed_uri );
97
+            if ( ! is_wp_error( $feed ) ) {
98
+                // Build an array of requested $articles_number, starting with element 0
99
+                $feed_articles = $feed->get_items( 0, $articles_number );
100
+                foreach ( $feed_articles as $key => $item ) {
101
+                    $data = array(
102
+                        // fetch_feed will return the title html decoded.
103
+                        'post_title'       => $item->get_title(),
104
+                        'post_date'        => $item->get_date( 'j F Y | g:i a' ),
105
+                        'post_url'         => self::add_utm_parameter( $item->get_permalink() ),
106
+                        // fetch_feed will return the description html (not decoded).
107
+                        'post_description' => $item->get_description(),
108
+                    );
109
+                    array_push( $posts_data, $data );
110
+                }
111
+                // Set articles in cache.
112
+                $cache_sistem_lib->set_cache( $cache_id, $posts_data );
113
+                $feed_articles = $posts_data;
114
+            }
115
+        }
116
+
117
+        return $feed_articles;
118
+    }
119
+
120
+    /**
121
+     * Add the `utm` parameter for GA.
122
+     *
123
+     * @since 3.19.0
124
+     *
125
+     * @param string $url The URL.
126
+     *
127
+     * @return string The URL with the `utm` parameter prepended by `&` or by `?`.
128
+     */
129
+    private static function add_utm_parameter( $url ) {
130
+
131
+        if ( false === strpos( $url, '?' ) ) {
132
+            return $url . '?utm=wl_dash';
133
+        }
134
+
135
+        return $url . '&utm=wl_dash';
136
+    }
137
+
138
+    /**
139
+     * Ajax call for more latest news.
140
+     *
141
+     * @uses  https://codex.wordpress.org/Function_Reference/wp_send_json_success
142
+     *
143
+     * @return string JSON obj with articles data.
144
+     */
145
+    public function ajax_get_latest_news() {
146
+        // Get wordlift articles
147
+        $start_position = explode( '_', $_POST['more_posts_link_id'] );
148
+        $data           = $this->get_last_wordlift_articles( $start_position[ count( $start_position ) - 1 ] );
149
+
150
+        // Return response as json object
151
+        wp_send_json_success( $data );
152
+    }
153
+
154
+    /**
155
+     * Add latest news widget to the administration dashboard.
156
+     */
157
+    public function add_dashboard_latest_news_widget() {
158
+        wp_add_dashboard_widget( 'wordlift-dashboard-latest-news-widget', 'Latest WordLift News', array(
159
+            $this,
160
+            'render',
161
+        ) );
162
+    }
163 163
 
164 164
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -24,17 +24,17 @@  discard block
 block discarded – undo
24 24
 	 * Add needed hooks for the latest news widget.
25 25
 	 */
26 26
 	public function __construct() {
27
-		add_action( 'wp_ajax_wordlift_get_latest_news', array(
27
+		add_action('wp_ajax_wordlift_get_latest_news', array(
28 28
 			$this,
29 29
 			'ajax_get_latest_news',
30
-		) );
31
-		add_action( 'wp_dashboard_setup', array(
30
+		));
31
+		add_action('wp_dashboard_setup', array(
32 32
 			$this,
33 33
 			'add_dashboard_latest_news_widget',
34
-		) );
34
+		));
35 35
 
36
-		add_action( 'admin_enqueue_scripts', function () {
37
-			wp_enqueue_script( 'wl-admin-dashboard', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift-admin-dashboard.js', array( 'jquery' ) );
36
+		add_action('admin_enqueue_scripts', function() {
37
+			wp_enqueue_script('wl-admin-dashboard', plugin_dir_url(dirname(__FILE__)).'admin/js/wordlift-admin-dashboard.js', array('jquery'));
38 38
 		} );
39 39
 	}
40 40
 
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 * @return string Articles html markup.
45 45
 	 */
46 46
 	public function render() {
47
-		include( plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-news-widget.php' );
47
+		include(plugin_dir_path(__FILE__).'partials/wordlift-admin-news-widget.php');
48 48
 	}
49 49
 
50 50
 	/**
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 * @return array Latest posts data.
56 56
 	 */
57
-	public function get_last_wordlift_articles( $start_position = 0 ) {
57
+	public function get_last_wordlift_articles($start_position = 0) {
58 58
 		$feed_articles = $this->get_wordlift_articles_data();
59 59
 
60 60
 		// Filter articles by $start_position
61
-		if ( ! empty( $feed_articles ) ) {
61
+		if ( ! empty($feed_articles)) {
62 62
 			return array(
63
-				'posts_data'     => array_slice( $feed_articles, $start_position, 3 ),
64
-				'count'          => count( $feed_articles ),
63
+				'posts_data'     => array_slice($feed_articles, $start_position, 3),
64
+				'count'          => count($feed_articles),
65 65
 				'start_position' => $start_position,
66 66
 			);
67 67
 		}
@@ -79,37 +79,37 @@  discard block
 block discarded – undo
79 79
 	 *
80 80
 	 * @return array Latest $articles_number feed posts.
81 81
 	 */
82
-	public function get_wordlift_articles_data( $articles_number = 10 ) {
82
+	public function get_wordlift_articles_data($articles_number = 10) {
83 83
 		// Init cache class
84
-		$cache_sistem_lib = new Wordlift_File_Cache_Service( WL_TEMP_DIR . 'articles/' );
84
+		$cache_sistem_lib = new Wordlift_File_Cache_Service(WL_TEMP_DIR.'articles/');
85 85
 		$locale           = get_locale();
86
-		$cache_id         = 'news_' . date( 'Y_m_d' ) . '_' . $locale;
86
+		$cache_id         = 'news_'.date('Y_m_d').'_'.$locale;
87 87
 		$posts_data       = array();
88 88
 
89 89
 		// Get latest articles from cache
90
-		$feed_articles = $cache_sistem_lib->get_cache( $cache_id );
91
-		if ( false === $feed_articles ) {
90
+		$feed_articles = $cache_sistem_lib->get_cache($cache_id);
91
+		if (false === $feed_articles) {
92 92
 			// Check wordpress installation language to define articles rss url
93
-			$feed_uri = ( 'it_IT' === $locale ) ? 'https://wordlift.io/blog/it/feed/' : 'https://wordlift.io/blog/en/feed/';
93
+			$feed_uri = ('it_IT' === $locale) ? 'https://wordlift.io/blog/it/feed/' : 'https://wordlift.io/blog/en/feed/';
94 94
 
95 95
 			// Get rss feed data, the response is cached by default for 12 hours
96
-			$feed = fetch_feed( $feed_uri );
97
-			if ( ! is_wp_error( $feed ) ) {
96
+			$feed = fetch_feed($feed_uri);
97
+			if ( ! is_wp_error($feed)) {
98 98
 				// Build an array of requested $articles_number, starting with element 0
99
-				$feed_articles = $feed->get_items( 0, $articles_number );
100
-				foreach ( $feed_articles as $key => $item ) {
99
+				$feed_articles = $feed->get_items(0, $articles_number);
100
+				foreach ($feed_articles as $key => $item) {
101 101
 					$data = array(
102 102
 						// fetch_feed will return the title html decoded.
103 103
 						'post_title'       => $item->get_title(),
104
-						'post_date'        => $item->get_date( 'j F Y | g:i a' ),
105
-						'post_url'         => self::add_utm_parameter( $item->get_permalink() ),
104
+						'post_date'        => $item->get_date('j F Y | g:i a'),
105
+						'post_url'         => self::add_utm_parameter($item->get_permalink()),
106 106
 						// fetch_feed will return the description html (not decoded).
107 107
 						'post_description' => $item->get_description(),
108 108
 					);
109
-					array_push( $posts_data, $data );
109
+					array_push($posts_data, $data);
110 110
 				}
111 111
 				// Set articles in cache.
112
-				$cache_sistem_lib->set_cache( $cache_id, $posts_data );
112
+				$cache_sistem_lib->set_cache($cache_id, $posts_data);
113 113
 				$feed_articles = $posts_data;
114 114
 			}
115 115
 		}
@@ -126,13 +126,13 @@  discard block
 block discarded – undo
126 126
 	 *
127 127
 	 * @return string The URL with the `utm` parameter prepended by `&` or by `?`.
128 128
 	 */
129
-	private static function add_utm_parameter( $url ) {
129
+	private static function add_utm_parameter($url) {
130 130
 
131
-		if ( false === strpos( $url, '?' ) ) {
132
-			return $url . '?utm=wl_dash';
131
+		if (false === strpos($url, '?')) {
132
+			return $url.'?utm=wl_dash';
133 133
 		}
134 134
 
135
-		return $url . '&utm=wl_dash';
135
+		return $url.'&utm=wl_dash';
136 136
 	}
137 137
 
138 138
 	/**
@@ -144,21 +144,21 @@  discard block
 block discarded – undo
144 144
 	 */
145 145
 	public function ajax_get_latest_news() {
146 146
 		// Get wordlift articles
147
-		$start_position = explode( '_', $_POST['more_posts_link_id'] );
148
-		$data           = $this->get_last_wordlift_articles( $start_position[ count( $start_position ) - 1 ] );
147
+		$start_position = explode('_', $_POST['more_posts_link_id']);
148
+		$data           = $this->get_last_wordlift_articles($start_position[count($start_position) - 1]);
149 149
 
150 150
 		// Return response as json object
151
-		wp_send_json_success( $data );
151
+		wp_send_json_success($data);
152 152
 	}
153 153
 
154 154
 	/**
155 155
 	 * Add latest news widget to the administration dashboard.
156 156
 	 */
157 157
 	public function add_dashboard_latest_news_widget() {
158
-		wp_add_dashboard_widget( 'wordlift-dashboard-latest-news-widget', 'Latest WordLift News', array(
158
+		wp_add_dashboard_widget('wordlift-dashboard-latest-news-widget', 'Latest WordLift News', array(
159 159
 			$this,
160 160
 			'render',
161
-		) );
161
+		));
162 162
 	}
163 163
 
164 164
 }
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-setup.php 2 patches
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  */
14 14
 
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -28,106 +28,106 @@  discard block
 block discarded – undo
28 28
  */
29 29
 class Wordlift_Admin_Setup {
30 30
 
31
-	/**
32
-	 * A {@link Wordlift_Configuration_Service} instance.
33
-	 *
34
-	 * @since  3.9.0
35
-	 * @access private
36
-	 * @var Wordlift_Configuration_Service A {@link Wordlift_Configuration_Service} instance.
37
-	 */
38
-	private $configuration_service;
39
-
40
-	/**
41
-	 * A {@link Wordlift_Key_Validation_Service} instance.
42
-	 *
43
-	 * @since  3.9.0
44
-	 * @access private
45
-	 * @var Wordlift_Key_Validation_Service A {@link Wordlift_Key_Validation_Service} instance.
46
-	 */
47
-	private $key_validation_service;
48
-
49
-	/**
50
-	 * A {@link Wordlift_Entity_Service} instance.
51
-	 *
52
-	 * @since  3.9.0
53
-	 * @access private
54
-	 * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
55
-	 */
56
-	private $entity_service;
57
-
58
-	/**
59
-	 * Initialize the class and set its properties.
60
-	 *
61
-	 * @since    3.9.0
62
-	 *
63
-	 * @param Wordlift_Configuration_Service  $configuration_service  A {@link Wordlift_Configuration_Service} instance.
64
-	 * @param Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance.
65
-	 * @param Wordlift_Entity_Service         $entity_service         A {@link Wordlift_Entity_Service} instance.
66
-	 */
67
-	public function __construct( $configuration_service, $key_validation_service, $entity_service ) {
68
-
69
-		// Set a reference to the configuration service.
70
-		$this->configuration_service = $configuration_service;
71
-
72
-		// Set a reference to the key validation service.
73
-		$this->key_validation_service = $key_validation_service;
74
-
75
-		// Set a reference to the entity service.
76
-		$this->entity_service = $entity_service;
77
-
78
-		// Hook to some WP's events:
79
-		// When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up.
80
-		add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
81
-
82
-		// Hook to `admin_menu` in order to add our own setup wizard page.
83
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
84
-
85
-		// Triggered when the user accesses the admin area, we decide whether to show our own wizard.
86
-		add_action( 'admin_init', array( $this, 'show_page' ) );
87
-
88
-		// Hook to `admin_notices` to display our notices.
89
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
90
-
91
-	}
92
-
93
-	/**
94
-	 * Hook to `admin_init` and redirect to WordLift's setup page if the `_wl_activation_redirect` transient flag is set.
95
-	 *
96
-	 * @since 3.9.0
97
-	 */
98
-	public function admin_init() {
99
-
100
-		// If the `_wl_activation_redirect` is set, the redirect to the setup page.
101
-		if ( get_transient( '_wl_activation_redirect' ) ) {
102
-			delete_transient( '_wl_activation_redirect' );
103
-
104
-			// If the user asked to skip the wizard then comply.
105
-			if ( $this->configuration_service->is_skip_wizard() ) {
106
-				return;
107
-			}
108
-
109
-			// If we're already on the page or the user doesn't have permissions, return.
110
-			if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) {
111
-				return;
112
-			}
113
-
114
-			// Finally redirect to the setup page.
115
-			wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) );
116
-
117
-			exit;
118
-		}
119
-
120
-	}
121
-
122
-	/**
123
-	 * Generate an admin notice suggesting to start the wizard if there is no configuration.
124
-	 *
125
-	 * @since    3.9.0
126
-	 */
127
-	public function admin_notices() {
128
-
129
-		// Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard.
130
-		if ( '' === $this->configuration_service->get_key() && ! $this->configuration_service->is_skip_wizard() ) { ?>
31
+    /**
32
+     * A {@link Wordlift_Configuration_Service} instance.
33
+     *
34
+     * @since  3.9.0
35
+     * @access private
36
+     * @var Wordlift_Configuration_Service A {@link Wordlift_Configuration_Service} instance.
37
+     */
38
+    private $configuration_service;
39
+
40
+    /**
41
+     * A {@link Wordlift_Key_Validation_Service} instance.
42
+     *
43
+     * @since  3.9.0
44
+     * @access private
45
+     * @var Wordlift_Key_Validation_Service A {@link Wordlift_Key_Validation_Service} instance.
46
+     */
47
+    private $key_validation_service;
48
+
49
+    /**
50
+     * A {@link Wordlift_Entity_Service} instance.
51
+     *
52
+     * @since  3.9.0
53
+     * @access private
54
+     * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
55
+     */
56
+    private $entity_service;
57
+
58
+    /**
59
+     * Initialize the class and set its properties.
60
+     *
61
+     * @since    3.9.0
62
+     *
63
+     * @param Wordlift_Configuration_Service  $configuration_service  A {@link Wordlift_Configuration_Service} instance.
64
+     * @param Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance.
65
+     * @param Wordlift_Entity_Service         $entity_service         A {@link Wordlift_Entity_Service} instance.
66
+     */
67
+    public function __construct( $configuration_service, $key_validation_service, $entity_service ) {
68
+
69
+        // Set a reference to the configuration service.
70
+        $this->configuration_service = $configuration_service;
71
+
72
+        // Set a reference to the key validation service.
73
+        $this->key_validation_service = $key_validation_service;
74
+
75
+        // Set a reference to the entity service.
76
+        $this->entity_service = $entity_service;
77
+
78
+        // Hook to some WP's events:
79
+        // When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up.
80
+        add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
81
+
82
+        // Hook to `admin_menu` in order to add our own setup wizard page.
83
+        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
84
+
85
+        // Triggered when the user accesses the admin area, we decide whether to show our own wizard.
86
+        add_action( 'admin_init', array( $this, 'show_page' ) );
87
+
88
+        // Hook to `admin_notices` to display our notices.
89
+        add_action( 'admin_notices', array( $this, 'admin_notices' ) );
90
+
91
+    }
92
+
93
+    /**
94
+     * Hook to `admin_init` and redirect to WordLift's setup page if the `_wl_activation_redirect` transient flag is set.
95
+     *
96
+     * @since 3.9.0
97
+     */
98
+    public function admin_init() {
99
+
100
+        // If the `_wl_activation_redirect` is set, the redirect to the setup page.
101
+        if ( get_transient( '_wl_activation_redirect' ) ) {
102
+            delete_transient( '_wl_activation_redirect' );
103
+
104
+            // If the user asked to skip the wizard then comply.
105
+            if ( $this->configuration_service->is_skip_wizard() ) {
106
+                return;
107
+            }
108
+
109
+            // If we're already on the page or the user doesn't have permissions, return.
110
+            if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) {
111
+                return;
112
+            }
113
+
114
+            // Finally redirect to the setup page.
115
+            wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) );
116
+
117
+            exit;
118
+        }
119
+
120
+    }
121
+
122
+    /**
123
+     * Generate an admin notice suggesting to start the wizard if there is no configuration.
124
+     *
125
+     * @since    3.9.0
126
+     */
127
+    public function admin_notices() {
128
+
129
+        // Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard.
130
+        if ( '' === $this->configuration_service->get_key() && ! $this->configuration_service->is_skip_wizard() ) { ?>
131 131
 			<div id="wl-message" class="updated">
132 132
 				<p><?php esc_html_e( 'Welcome to WordLift &#8211; You&lsquo;re almost ready to start', 'wordlift' ); ?></p>
133 133
 				<p class="submit"><a href="<?php echo esc_url( admin_url( 'admin.php?page=wl-setup' ) ); ?>"
@@ -138,129 +138,129 @@  discard block
 block discarded – undo
138 138
 			</div>
139 139
 		<?php }
140 140
 
141
-	}
141
+    }
142 142
 
143
-	/**
144
-	 * Handle hiding the wizard notices by user request
145
-	 *
146
-	 * @since    3.9.0
147
-	 */
148
-	public function hide_notices() {
143
+    /**
144
+     * Handle hiding the wizard notices by user request
145
+     *
146
+     * @since    3.9.0
147
+     */
148
+    public function hide_notices() {
149 149
 
150
-		// If it's not a `wl-hide-notice` or the nonce is not set, return.
151
-		if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) {
152
-			return;
153
-		}
150
+        // If it's not a `wl-hide-notice` or the nonce is not set, return.
151
+        if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) {
152
+            return;
153
+        }
154 154
 
155
-		// If the nonce is invalid, return an error.
156
-		if ( ! wp_verify_nonce( $_GET['_wl_notice_nonce'], 'wordlift_hide_notices_nonce' ) ) {
157
-			wp_die( __( 'Action failed. Please refresh the page and retry.', 'wordlift' ) );
158
-		}
155
+        // If the nonce is invalid, return an error.
156
+        if ( ! wp_verify_nonce( $_GET['_wl_notice_nonce'], 'wordlift_hide_notices_nonce' ) ) {
157
+            wp_die( __( 'Action failed. Please refresh the page and retry.', 'wordlift' ) );
158
+        }
159 159
 
160
-		// If the user doesn't have the right privileges, return an error.
161
-		if ( ! current_user_can( 'manage_options' ) ) {
162
-			wp_die( __( 'Cheatin&#8217; huh?', 'wordlift' ) );
163
-		}
160
+        // If the user doesn't have the right privileges, return an error.
161
+        if ( ! current_user_can( 'manage_options' ) ) {
162
+            wp_die( __( 'Cheatin&#8217; huh?', 'wordlift' ) );
163
+        }
164 164
 
165
-		// Store a flag telling to skip the wizard.
166
-		$this->configuration_service->set_skip_wizard( TRUE );
165
+        // Store a flag telling to skip the wizard.
166
+        $this->configuration_service->set_skip_wizard( TRUE );
167 167
 
168
-	}
168
+    }
169 169
 
170
-	/**
171
-	 * Register the wizard page to be able to access it
172
-	 *
173
-	 * @since    3.9.0
174
-	 */
175
-	public function admin_menu() {
170
+    /**
171
+     * Register the wizard page to be able to access it
172
+     *
173
+     * @since    3.9.0
174
+     */
175
+    public function admin_menu() {
176 176
 
177
-		// @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu.
178
-		add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' );
177
+        // @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu.
178
+        add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' );
179 179
 
180
-	}
180
+    }
181 181
 
182
-	/**
183
-	 * Displays the wizard page
184
-	 *
185
-	 * @since    3.9.0
186
-	 */
187
-	public function show_page() {
182
+    /**
183
+     * Displays the wizard page
184
+     *
185
+     * @since    3.9.0
186
+     */
187
+    public function show_page() {
188 188
 
189
-		// First check if we are in the wizard page at all, if not do nothing.
190
-		if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) {
191
-			return;
192
-		}
189
+        // First check if we are in the wizard page at all, if not do nothing.
190
+        if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) {
191
+            return;
192
+        }
193 193
 
194
-		// If it's a POST and the `wl-save-configuration` action is set, save the configuration.
195
-		if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) {
194
+        // If it's a POST and the `wl-save-configuration` action is set, save the configuration.
195
+        if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) {
196 196
 
197
-			// Check the nonce and the user capabilities.
198
-			check_admin_referer( 'wl-save-configuration' );
197
+            // Check the nonce and the user capabilities.
198
+            check_admin_referer( 'wl-save-configuration' );
199 199
 
200
-			// Check if the user has the right privileges.
201
-			if ( ! current_user_can( 'manage_options' ) ) {
202
-				wp_die( __( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) );
203
-			}
200
+            // Check if the user has the right privileges.
201
+            if ( ! current_user_can( 'manage_options' ) ) {
202
+                wp_die( __( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) );
203
+            }
204 204
 
205
-			// Save the configuration.
206
-			$this->save_configuration( $_POST );
205
+            // Save the configuration.
206
+            $this->save_configuration( $_POST );
207 207
 
208
-			// Redirect to the admin's page.
209
-			wp_redirect( admin_url() );
208
+            // Redirect to the admin's page.
209
+            wp_redirect( admin_url() );
210 210
 
211
-			exit;
212
-		}
211
+            exit;
212
+        }
213 213
 
214
-		include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-setup.php';
214
+        include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-setup.php';
215 215
 
216
-		exit;
217
-	}
216
+        exit;
217
+    }
218 218
 
219
-	/**
220
-	 * Save WordLift's configuration using the provided parameters.
221
-	 *
222
-	 * @since 3.9.0
223
-	 *
224
-	 * @param array $params An array of configuration parameters.
225
-	 */
226
-	private function save_configuration( $params ) {
219
+    /**
220
+     * Save WordLift's configuration using the provided parameters.
221
+     *
222
+     * @since 3.9.0
223
+     *
224
+     * @param array $params An array of configuration parameters.
225
+     */
226
+    private function save_configuration( $params ) {
227 227
 
228
-		// We have the following parameters:
229
-		// `key`, holding WL's key,
230
-		// `vocabulary`, holding the vocabulary path,
231
-		// `language`, with the language code (e.g. `en`),
232
-		// `send_diagnostic`, the user preferences about sharing data with us.
233
-		// `user_type`, the user type either `personal` or `company`,
234
-		// `name`, with the `personal` or `company`'s name,
235
-		// `logo`, the attachment id for the `personal` or `company` entity.
228
+        // We have the following parameters:
229
+        // `key`, holding WL's key,
230
+        // `vocabulary`, holding the vocabulary path,
231
+        // `language`, with the language code (e.g. `en`),
232
+        // `send_diagnostic`, the user preferences about sharing data with us.
233
+        // `user_type`, the user type either `personal` or `company`,
234
+        // `name`, with the `personal` or `company`'s name,
235
+        // `logo`, the attachment id for the `personal` or `company` entity.
236 236
 
237
-		// Store the key:
238
-		$this->configuration_service->set_key( $params['key'] );
237
+        // Store the key:
238
+        $this->configuration_service->set_key( $params['key'] );
239 239
 
240
-		// Store the vocabulary path:
241
-		$this->configuration_service->set_entity_base_path( $params['vocabulary'] );
240
+        // Store the vocabulary path:
241
+        $this->configuration_service->set_entity_base_path( $params['vocabulary'] );
242 242
 
243
-		// Store the site's language:
244
-		$this->configuration_service->set_language_code( $params['language'] );
243
+        // Store the site's language:
244
+        $this->configuration_service->set_language_code( $params['language'] );
245 245
 
246
-		// Store the preferences in variable, because if the checkbox is not checked
247
-		// the `share-diagnostic` will not exists in `$params` array.
248
-		$share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes' ;
246
+        // Store the preferences in variable, because if the checkbox is not checked
247
+        // the `share-diagnostic` will not exists in `$params` array.
248
+        $share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes' ;
249 249
 
250
-		// Store the diagnostic preferences:
251
-		$this->configuration_service->set_diagnostic_preferences( $share_diagnostic_preferences );
250
+        // Store the diagnostic preferences:
251
+        $this->configuration_service->set_diagnostic_preferences( $share_diagnostic_preferences );
252 252
 
253
-		// Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
254
-		$type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' );
253
+        // Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
254
+        $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' );
255 255
 
256
-		// Create an entity for the publisher.
257
-		$publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' );
256
+        // Create an entity for the publisher.
257
+        $publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' );
258 258
 
259
-		// Store the publisher entity post id in the configuration.
260
-		$this->configuration_service->set_publisher_id( $publisher_post_id );
259
+        // Store the publisher entity post id in the configuration.
260
+        $this->configuration_service->set_publisher_id( $publisher_post_id );
261 261
 
262
-		flush_rewrite_rules(); // Needed because of possible change to the entity base path.
262
+        flush_rewrite_rules(); // Needed because of possible change to the entity base path.
263 263
 
264
-	}
264
+    }
265 265
 
266 266
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @since      3.9.0
13 13
  */
14 14
 
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @param Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance.
65 65
 	 * @param Wordlift_Entity_Service         $entity_service         A {@link Wordlift_Entity_Service} instance.
66 66
 	 */
67
-	public function __construct( $configuration_service, $key_validation_service, $entity_service ) {
67
+	public function __construct($configuration_service, $key_validation_service, $entity_service) {
68 68
 
69 69
 		// Set a reference to the configuration service.
70 70
 		$this->configuration_service = $configuration_service;
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
 
78 78
 		// Hook to some WP's events:
79 79
 		// When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up.
80
-		add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
80
+		add_action('wp_loaded', array($this, 'hide_notices'));
81 81
 
82 82
 		// Hook to `admin_menu` in order to add our own setup wizard page.
83
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
83
+		add_action('admin_menu', array($this, 'admin_menu'));
84 84
 
85 85
 		// Triggered when the user accesses the admin area, we decide whether to show our own wizard.
86
-		add_action( 'admin_init', array( $this, 'show_page' ) );
86
+		add_action('admin_init', array($this, 'show_page'));
87 87
 
88 88
 		// Hook to `admin_notices` to display our notices.
89
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
89
+		add_action('admin_notices', array($this, 'admin_notices'));
90 90
 
91 91
 	}
92 92
 
@@ -98,21 +98,21 @@  discard block
 block discarded – undo
98 98
 	public function admin_init() {
99 99
 
100 100
 		// If the `_wl_activation_redirect` is set, the redirect to the setup page.
101
-		if ( get_transient( '_wl_activation_redirect' ) ) {
102
-			delete_transient( '_wl_activation_redirect' );
101
+		if (get_transient('_wl_activation_redirect')) {
102
+			delete_transient('_wl_activation_redirect');
103 103
 
104 104
 			// If the user asked to skip the wizard then comply.
105
-			if ( $this->configuration_service->is_skip_wizard() ) {
105
+			if ($this->configuration_service->is_skip_wizard()) {
106 106
 				return;
107 107
 			}
108 108
 
109 109
 			// If we're already on the page or the user doesn't have permissions, return.
110
-			if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) {
110
+			if (( ! empty($_GET['page']) && 'wl-setup' === $_GET['page']) || is_network_admin() || isset($_GET['activate-multi']) || ! current_user_can('manage_options')) {
111 111
 				return;
112 112
 			}
113 113
 
114 114
 			// Finally redirect to the setup page.
115
-			wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) );
115
+			wp_safe_redirect(admin_url('index.php?page=wl-setup'));
116 116
 
117 117
 			exit;
118 118
 		}
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
 	public function admin_notices() {
128 128
 
129 129
 		// Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard.
130
-		if ( '' === $this->configuration_service->get_key() && ! $this->configuration_service->is_skip_wizard() ) { ?>
130
+		if ('' === $this->configuration_service->get_key() && ! $this->configuration_service->is_skip_wizard()) { ?>
131 131
 			<div id="wl-message" class="updated">
132
-				<p><?php esc_html_e( 'Welcome to WordLift &#8211; You&lsquo;re almost ready to start', 'wordlift' ); ?></p>
133
-				<p class="submit"><a href="<?php echo esc_url( admin_url( 'admin.php?page=wl-setup' ) ); ?>"
134
-				                     class="button-primary"><?php esc_html_e( 'Run the Setup Wizard', 'wordlift' ); ?></a>
132
+				<p><?php esc_html_e('Welcome to WordLift &#8211; You&lsquo;re almost ready to start', 'wordlift'); ?></p>
133
+				<p class="submit"><a href="<?php echo esc_url(admin_url('admin.php?page=wl-setup')); ?>"
134
+				                     class="button-primary"><?php esc_html_e('Run the Setup Wizard', 'wordlift'); ?></a>
135 135
 					<a class="button-secondary skip"
136
-					   href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wl-hide-notice', 'install' ), 'wordlift_hide_notices_nonce', '_wl_notice_nonce' ) ); ?>"><?php esc_html_e( 'Skip Setup', 'wordlift' ); ?></a>
136
+					   href="<?php echo esc_url(wp_nonce_url(add_query_arg('wl-hide-notice', 'install'), 'wordlift_hide_notices_nonce', '_wl_notice_nonce')); ?>"><?php esc_html_e('Skip Setup', 'wordlift'); ?></a>
137 137
 				</p>
138 138
 			</div>
139 139
 		<?php }
@@ -148,22 +148,22 @@  discard block
 block discarded – undo
148 148
 	public function hide_notices() {
149 149
 
150 150
 		// If it's not a `wl-hide-notice` or the nonce is not set, return.
151
-		if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) {
151
+		if ( ! isset($_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'])) {
152 152
 			return;
153 153
 		}
154 154
 
155 155
 		// If the nonce is invalid, return an error.
156
-		if ( ! wp_verify_nonce( $_GET['_wl_notice_nonce'], 'wordlift_hide_notices_nonce' ) ) {
157
-			wp_die( __( 'Action failed. Please refresh the page and retry.', 'wordlift' ) );
156
+		if ( ! wp_verify_nonce($_GET['_wl_notice_nonce'], 'wordlift_hide_notices_nonce')) {
157
+			wp_die(__('Action failed. Please refresh the page and retry.', 'wordlift'));
158 158
 		}
159 159
 
160 160
 		// If the user doesn't have the right privileges, return an error.
161
-		if ( ! current_user_can( 'manage_options' ) ) {
162
-			wp_die( __( 'Cheatin&#8217; huh?', 'wordlift' ) );
161
+		if ( ! current_user_can('manage_options')) {
162
+			wp_die(__('Cheatin&#8217; huh?', 'wordlift'));
163 163
 		}
164 164
 
165 165
 		// Store a flag telling to skip the wizard.
166
-		$this->configuration_service->set_skip_wizard( TRUE );
166
+		$this->configuration_service->set_skip_wizard(TRUE);
167 167
 
168 168
 	}
169 169
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	public function admin_menu() {
176 176
 
177 177
 		// @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu.
178
-		add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' );
178
+		add_dashboard_page('', '', 'manage_options', 'wl-setup', '');
179 179
 
180 180
 	}
181 181
 
@@ -187,31 +187,31 @@  discard block
 block discarded – undo
187 187
 	public function show_page() {
188 188
 
189 189
 		// First check if we are in the wizard page at all, if not do nothing.
190
-		if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) {
190
+		if (empty($_GET['page']) || 'wl-setup' !== $_GET['page']) {
191 191
 			return;
192 192
 		}
193 193
 
194 194
 		// If it's a POST and the `wl-save-configuration` action is set, save the configuration.
195
-		if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) {
195
+		if (isset($_POST['action']) && 'wl-save-configuration' === $_POST['action']) {
196 196
 
197 197
 			// Check the nonce and the user capabilities.
198
-			check_admin_referer( 'wl-save-configuration' );
198
+			check_admin_referer('wl-save-configuration');
199 199
 
200 200
 			// Check if the user has the right privileges.
201
-			if ( ! current_user_can( 'manage_options' ) ) {
202
-				wp_die( __( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) );
201
+			if ( ! current_user_can('manage_options')) {
202
+				wp_die(__('Sorry, you do not have a permission to save the settings', 'wordlift'));
203 203
 			}
204 204
 
205 205
 			// Save the configuration.
206
-			$this->save_configuration( $_POST );
206
+			$this->save_configuration($_POST);
207 207
 
208 208
 			// Redirect to the admin's page.
209
-			wp_redirect( admin_url() );
209
+			wp_redirect(admin_url());
210 210
 
211 211
 			exit;
212 212
 		}
213 213
 
214
-		include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-setup.php';
214
+		include plugin_dir_path(dirname(__FILE__)).'admin/partials/wordlift-admin-setup.php';
215 215
 
216 216
 		exit;
217 217
 	}
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 	 *
224 224
 	 * @param array $params An array of configuration parameters.
225 225
 	 */
226
-	private function save_configuration( $params ) {
226
+	private function save_configuration($params) {
227 227
 
228 228
 		// We have the following parameters:
229 229
 		// `key`, holding WL's key,
@@ -235,29 +235,29 @@  discard block
 block discarded – undo
235 235
 		// `logo`, the attachment id for the `personal` or `company` entity.
236 236
 
237 237
 		// Store the key:
238
-		$this->configuration_service->set_key( $params['key'] );
238
+		$this->configuration_service->set_key($params['key']);
239 239
 
240 240
 		// Store the vocabulary path:
241
-		$this->configuration_service->set_entity_base_path( $params['vocabulary'] );
241
+		$this->configuration_service->set_entity_base_path($params['vocabulary']);
242 242
 
243 243
 		// Store the site's language:
244
-		$this->configuration_service->set_language_code( $params['language'] );
244
+		$this->configuration_service->set_language_code($params['language']);
245 245
 
246 246
 		// Store the preferences in variable, because if the checkbox is not checked
247 247
 		// the `share-diagnostic` will not exists in `$params` array.
248
-		$share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes' ;
248
+		$share_diagnostic_preferences = empty($params['share-diagnostic']) ? 'no' : 'yes';
249 249
 
250 250
 		// Store the diagnostic preferences:
251
-		$this->configuration_service->set_diagnostic_preferences( $share_diagnostic_preferences );
251
+		$this->configuration_service->set_diagnostic_preferences($share_diagnostic_preferences);
252 252
 
253 253
 		// Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
254
-		$type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' );
254
+		$type_uri = sprintf('http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person');
255 255
 
256 256
 		// Create an entity for the publisher.
257
-		$publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' );
257
+		$publisher_post_id = $this->entity_service->create($params['name'], $type_uri, $params['logo'], 'publish');
258 258
 
259 259
 		// Store the publisher entity post id in the configuration.
260
-		$this->configuration_service->set_publisher_id( $publisher_post_id );
260
+		$this->configuration_service->set_publisher_id($publisher_post_id);
261 261
 
262 262
 		flush_rewrite_rules(); // Needed because of possible change to the entity base path.
263 263
 
Please login to merge, or discard this patch.
src/admin/partials/wordlift-admin-news-widget.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php $articles = $this->get_last_wordlift_articles(); ?>
2 2
 <div id='news_container'>
3
-	<?php if ( ! empty( $articles['posts_data'] ) ) { ?>
4
-		<?php foreach ( $articles['posts_data'] as $key => $item ) { ?>
3
+	<?php if ( ! empty($articles['posts_data'])) { ?>
4
+		<?php foreach ($articles['posts_data'] as $key => $item) { ?>
5 5
             <div>
6 6
                 <a target="_blank"
7
-                   href="<?php echo esc_url( $item['post_url'] ); ?>"><?php echo esc_html( $item['post_title'] ); ?></a>
7
+                   href="<?php echo esc_url($item['post_url']); ?>"><?php echo esc_html($item['post_title']); ?></a>
8 8
                 <p><?php echo $item['post_description']; ?></p>
9 9
             </div>
10 10
 		<?php } ?>
11 11
 	<?php } ?>
12 12
     <div>
13 13
         <a href="#" id="max_posts_count_3"
14
-           class="wl_more_posts"><?php echo esc_html__( 'More posts', 'wordlift' ); ?></a>
14
+           class="wl_more_posts"><?php echo esc_html__('More posts', 'wordlift'); ?></a>
15 15
     </div>
16 16
 </div>
Please login to merge, or discard this patch.
src/admin/partials/admin-setup/step-1.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,42 +1,42 @@  discard block
 block discarded – undo
1 1
 <!-- Pane 1 content -->
2 2
 <script type="text/html" id="page-0">
3 3
 	<h2 class="page-title">
4
-		<?php esc_html_e( 'Welcome', 'wordlift' ); ?>
4
+		<?php esc_html_e('Welcome', 'wordlift'); ?>
5 5
 	</h2>
6 6
 
7 7
 	<p class="page-txt">
8
-		   <?php esc_html_e( 'Thank you for downloading WordLift. Now you can boost your website with a double-digit growth. WordLift helps you with:', 'wordlift' ); ?>
8
+		   <?php esc_html_e('Thank you for downloading WordLift. Now you can boost your website with a double-digit growth. WordLift helps you with:', 'wordlift'); ?>
9 9
 	</p>
10 10
 
11 11
 	<ul class="page-list">
12 12
 		<li>
13 13
 			<span class="fa fa-university"></span>
14
-			<?php esc_html_e( 'Trustworthiness', 'wordlift' ); ?>
14
+			<?php esc_html_e('Trustworthiness', 'wordlift'); ?>
15 15
 		</li>
16 16
 
17 17
 		<li>
18 18
 			<span class="fa fa-map-marker"></span>
19
-			<?php esc_html_e( 'Enrichment', 'wordlift' ); ?>
19
+			<?php esc_html_e('Enrichment', 'wordlift'); ?>
20 20
 		</li>
21 21
 
22 22
 		<li>
23 23
 			<span class="fa fa-heart"></span>
24
-			<?php esc_html_e( 'Engagement', 'wordlift' ); ?>
24
+			<?php esc_html_e('Engagement', 'wordlift'); ?>
25 25
 		</li>
26 26
 
27 27
 		<li>
28 28
 			<span class="fa fa-hand-o-right"></span>
29
-			<?php esc_html_e( 'Smart Navigation', 'wordlift' ); ?>
29
+			<?php esc_html_e('Smart Navigation', 'wordlift'); ?>
30 30
 		</li>
31 31
 
32 32
 		<li>
33 33
 			<span class="fa fa-google"></span>
34
-			<?php esc_html_e( 'SEO Optimization', 'wordlift' ); ?>
34
+			<?php esc_html_e('SEO Optimization', 'wordlift'); ?>
35 35
 		</li>
36 36
 
37 37
 		<li>
38 38
 			<span class="fa fa-group"></span>
39
-			<?php esc_html_e( 'Content Marketing', 'wordlift' ); ?>
39
+			<?php esc_html_e('Content Marketing', 'wordlift'); ?>
40 40
 		</li>
41 41
 	</ul>
42 42
 
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
 				target="_tab"
47 47
 				class="button"
48 48
 			>
49
-				<?php esc_html_e( 'Learn More', 'wordlift' ); ?>
49
+				<?php esc_html_e('Learn More', 'wordlift'); ?>
50 50
 			</a>
51 51
 			<input
52 52
 				type="button"
53 53
 				data-wl-next="wl-next"
54 54
 				class="wl-default-action"
55
-				value="<?php esc_attr_e( 'Next', 'wordlift' ); ?>"
55
+				value="<?php esc_attr_e('Next', 'wordlift'); ?>"
56 56
 			>
57 57
 	</div>
58 58
 </script>
59 59
\ No newline at end of file
Please login to merge, or discard this patch.
src/admin/partials/admin-setup/step-4.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  discard block
 block discarded – undo
1 1
 <!-- Pane 4 content -->
2 2
 <script type="text/html" id="page-3">
3 3
 	<h2 class="page-title">
4
-		<?php esc_html_e( 'Vocabulary', 'wordlift' ); ?>	
4
+		<?php esc_html_e('Vocabulary', 'wordlift'); ?>	
5 5
 	</h2>
6 6
 
7 7
 	<p class="page-txt">
8
-		<?php esc_html_e( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field below. Check our FAQs if you need more info.', 'wordlift' ); ?>
8
+		<?php esc_html_e('All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field below. Check our FAQs if you need more info.', 'wordlift'); ?>
9 9
 	</p>
10 10
 
11 11
 	<input
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	>
20 20
 	
21 21
 	<p class="page-det">
22
-		<?php esc_html_e( 'Leave it empty to place your entities in the root folder of your website', 'wordlift' ); ?>
22
+		<?php esc_html_e('Leave it empty to place your entities in the root folder of your website', 'wordlift'); ?>
23 23
 	</p>
24 24
 	
25 25
 	<div class="btn-wrapper">
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 			type="button"
28 28
 			data-wl-next="wl-next"
29 29
 			class="wl-default-action"
30
-			value="<?php esc_attr_e( 'Next', 'wordlift' ); ?>"
30
+			value="<?php esc_attr_e('Next', 'wordlift'); ?>"
31 31
 		>
32 32
 	</div>
33 33
 </script>
Please login to merge, or discard this patch.