Completed
Push — develop ( 4910e3...56d9e6 )
by
unknown
04:13
created
src/admin/WL_Metabox/class-wl-metabox-field-sameas.php 3 patches
Doc Comments   +2 added lines patch added patch discarded remove patch
@@ -81,6 +81,7 @@  discard block
 block discarded – undo
81 81
 
82 82
 	/**
83 83
 	 * @inheritdoc
84
+	 * @param integer $count
84 85
 	 */
85 86
 	protected function get_add_button_html( $count ) {
86 87
 
@@ -99,6 +100,7 @@  discard block
 block discarded – undo
99 100
 
100 101
 	/**
101 102
 	 * @inheritdoc
103
+	 * @param integer $count
102 104
 	 */
103 105
 	protected function get_stored_values_html( &$count ) {
104 106
 
Please login to merge, or discard this patch.
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -16,131 +16,131 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class WL_Metabox_Field_sameas extends WL_Metabox_Field {
18 18
 
19
-	/**
20
-	 * @inheritdoc
21
-	 */
22
-	public function __construct( $args ) {
23
-		parent::__construct( $args['sameas'] );
24
-	}
25
-
26
-	/**
27
-	 * @inheritdoc
28
-	 */
29
-	public function save_data( $values ) {
30
-		// The autocomplete select may send JSON arrays in input values.
31
-
32
-		// Only use mb_* functions when mbstring is available.
33
-		//
34
-		// See https://github.com/insideout10/wordlift-plugin/issues/693.
35
-		if ( extension_loaded( 'mbstring' ) ) {
36
-			mb_regex_encoding( 'UTF-8' );
37
-
38
-			$merged = array_reduce( (array) $values, function ( $carry, $item ) {
39
-				return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) );
40
-			}, array() );
41
-		} else {
42
-			$merged = array_reduce( (array) $values, function ( $carry, $item ) {
43
-				return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) );
44
-			}, array() );
45
-		}
46
-
47
-		parent::save_data( $merged );
48
-	}
49
-
50
-	/**
51
-	 * @inheritdoc
52
-	 */
53
-	public function sanitize_data_filter( $value ) {
54
-
55
-		// Call our sanitizer helper.
56
-		return Wordlift_Sanitizer::sanitize_url( $value );
57
-	}
58
-
59
-	/**
60
-	 * @inheritdoc
61
-	 */
62
-	protected function get_heading_html() {
63
-
64
-		// Add the select html fragment after the heading.
65
-		return parent::get_heading_html()
66
-			   . $this->get_select_html();
67
-	}
68
-
69
-	/**
70
-	 * Get the select html fragment.
71
-	 *
72
-	 * @since 3.15.0
73
-	 * @return string The html fragment.
74
-	 */
75
-	private function get_select_html() {
76
-		// Return an element where the new Autocomplete Select will attach to.
77
-		return '<p>'
78
-			   . esc_html__( 'Use the search below to link this entity with equivalent entities in the linked data cloud.', 'wordlift' )
79
-			   . '<div id="wl-metabox-field-sameas"></div></p>';
80
-	}
81
-
82
-	/**
83
-	 * @inheritdoc
84
-	 */
85
-	protected function get_add_button_html( $count ) {
86
-
87
-		$placeholder = esc_attr_x( 'Type here the URL of an equivalent entity from another dataset.', 'sameAs metabox input', 'wordlift' );
88
-
89
-		return
90
-			"<label for='$this->meta_name'>"
91
-			. esc_html__( 'If you already know the URL of the entity that you would like to link, add it in the field below.', 'wordlift' )
92
-			. '</label>'
93
-			. '<div class="wl-input-wrapper">'
94
-			. "<input type='text' id='$this->meta_name' name='wl_metaboxes[$this->meta_name][]' placeholder='$placeholder' style='width:88%' />"
95
-			. '<button class="button wl-remove-input wl-button" type="button">Remove</button>'
96
-			. '</div>'
97
-			. parent::get_add_button_html( $count );
98
-	}
99
-
100
-	/**
101
-	 * @inheritdoc
102
-	 */
103
-	protected function get_stored_values_html( &$count ) {
104
-
105
-		return '<p>'
106
-			   . parent::get_stored_values_html( $count )
107
-			   . '</p>';
108
-	}
109
-
110
-	/**
111
-	 * @inheritdoc
112
-	 */
113
-	public function html() {
114
-
115
-		// Open main <div> for the Field.
116
-		$html = $this->html_wrapper_open();
117
-
118
-		// Label.
119
-		$html .= $this->get_heading_html();
120
-
121
-		// print nonce.
122
-		$html .= $this->html_nonce();
123
-
124
-		// print data loaded from DB.
125
-		$count = 0;
126
-
127
-		// If cardinality allows it, print button to add new values.
128
-		$html .= $this->get_add_button_html( $count );
129
-
130
-		$html .= $this->get_stored_values_html( $count );
131
-
132
-		// Close the HTML wrapper.
133
-		$html .= $this->html_wrapper_close();
134
-
135
-		return $html;
136
-	}
137
-
138
-	/**
139
-	 * @inheritdoc
140
-	 */
141
-	public function html_input( $value ) {
142
-		@ob_start();
143
-		?>
19
+    /**
20
+     * @inheritdoc
21
+     */
22
+    public function __construct( $args ) {
23
+        parent::__construct( $args['sameas'] );
24
+    }
25
+
26
+    /**
27
+     * @inheritdoc
28
+     */
29
+    public function save_data( $values ) {
30
+        // The autocomplete select may send JSON arrays in input values.
31
+
32
+        // Only use mb_* functions when mbstring is available.
33
+        //
34
+        // See https://github.com/insideout10/wordlift-plugin/issues/693.
35
+        if ( extension_loaded( 'mbstring' ) ) {
36
+            mb_regex_encoding( 'UTF-8' );
37
+
38
+            $merged = array_reduce( (array) $values, function ( $carry, $item ) {
39
+                return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) );
40
+            }, array() );
41
+        } else {
42
+            $merged = array_reduce( (array) $values, function ( $carry, $item ) {
43
+                return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) );
44
+            }, array() );
45
+        }
46
+
47
+        parent::save_data( $merged );
48
+    }
49
+
50
+    /**
51
+     * @inheritdoc
52
+     */
53
+    public function sanitize_data_filter( $value ) {
54
+
55
+        // Call our sanitizer helper.
56
+        return Wordlift_Sanitizer::sanitize_url( $value );
57
+    }
58
+
59
+    /**
60
+     * @inheritdoc
61
+     */
62
+    protected function get_heading_html() {
63
+
64
+        // Add the select html fragment after the heading.
65
+        return parent::get_heading_html()
66
+                . $this->get_select_html();
67
+    }
68
+
69
+    /**
70
+     * Get the select html fragment.
71
+     *
72
+     * @since 3.15.0
73
+     * @return string The html fragment.
74
+     */
75
+    private function get_select_html() {
76
+        // Return an element where the new Autocomplete Select will attach to.
77
+        return '<p>'
78
+                . esc_html__( 'Use the search below to link this entity with equivalent entities in the linked data cloud.', 'wordlift' )
79
+                . '<div id="wl-metabox-field-sameas"></div></p>';
80
+    }
81
+
82
+    /**
83
+     * @inheritdoc
84
+     */
85
+    protected function get_add_button_html( $count ) {
86
+
87
+        $placeholder = esc_attr_x( 'Type here the URL of an equivalent entity from another dataset.', 'sameAs metabox input', 'wordlift' );
88
+
89
+        return
90
+            "<label for='$this->meta_name'>"
91
+            . esc_html__( 'If you already know the URL of the entity that you would like to link, add it in the field below.', 'wordlift' )
92
+            . '</label>'
93
+            . '<div class="wl-input-wrapper">'
94
+            . "<input type='text' id='$this->meta_name' name='wl_metaboxes[$this->meta_name][]' placeholder='$placeholder' style='width:88%' />"
95
+            . '<button class="button wl-remove-input wl-button" type="button">Remove</button>'
96
+            . '</div>'
97
+            . parent::get_add_button_html( $count );
98
+    }
99
+
100
+    /**
101
+     * @inheritdoc
102
+     */
103
+    protected function get_stored_values_html( &$count ) {
104
+
105
+        return '<p>'
106
+                . parent::get_stored_values_html( $count )
107
+                . '</p>';
108
+    }
109
+
110
+    /**
111
+     * @inheritdoc
112
+     */
113
+    public function html() {
114
+
115
+        // Open main <div> for the Field.
116
+        $html = $this->html_wrapper_open();
117
+
118
+        // Label.
119
+        $html .= $this->get_heading_html();
120
+
121
+        // print nonce.
122
+        $html .= $this->html_nonce();
123
+
124
+        // print data loaded from DB.
125
+        $count = 0;
126
+
127
+        // If cardinality allows it, print button to add new values.
128
+        $html .= $this->get_add_button_html( $count );
129
+
130
+        $html .= $this->get_stored_values_html( $count );
131
+
132
+        // Close the HTML wrapper.
133
+        $html .= $this->html_wrapper_close();
134
+
135
+        return $html;
136
+    }
137
+
138
+    /**
139
+     * @inheritdoc
140
+     */
141
+    public function html_input( $value ) {
142
+        @ob_start();
143
+        ?>
144 144
 			<div class="wl-input-wrapper">
145 145
 				<input
146 146
 					type="text"
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 			</div>
158 158
 		<?php
159 159
 
160
-		$html = ob_get_clean();
160
+        $html = ob_get_clean();
161 161
 
162
-		return $html;
163
-	}
162
+        return $html;
163
+    }
164 164
 
165 165
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -19,41 +19,41 @@  discard block
 block discarded – undo
19 19
 	/**
20 20
 	 * @inheritdoc
21 21
 	 */
22
-	public function __construct( $args ) {
23
-		parent::__construct( $args['sameas'] );
22
+	public function __construct($args) {
23
+		parent::__construct($args['sameas']);
24 24
 	}
25 25
 
26 26
 	/**
27 27
 	 * @inheritdoc
28 28
 	 */
29
-	public function save_data( $values ) {
29
+	public function save_data($values) {
30 30
 		// The autocomplete select may send JSON arrays in input values.
31 31
 
32 32
 		// Only use mb_* functions when mbstring is available.
33 33
 		//
34 34
 		// See https://github.com/insideout10/wordlift-plugin/issues/693.
35
-		if ( extension_loaded( 'mbstring' ) ) {
36
-			mb_regex_encoding( 'UTF-8' );
35
+		if (extension_loaded('mbstring')) {
36
+			mb_regex_encoding('UTF-8');
37 37
 
38
-			$merged = array_reduce( (array) $values, function ( $carry, $item ) {
39
-				return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) );
40
-			}, array() );
38
+			$merged = array_reduce((array) $values, function($carry, $item) {
39
+				return array_merge($carry, mb_split("\x{2063}", wp_unslash($item)));
40
+			}, array());
41 41
 		} else {
42
-			$merged = array_reduce( (array) $values, function ( $carry, $item ) {
43
-				return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) );
44
-			}, array() );
42
+			$merged = array_reduce((array) $values, function($carry, $item) {
43
+				return array_merge($carry, preg_split("/\x{2063}/u", wp_unslash($item)));
44
+			}, array());
45 45
 		}
46 46
 
47
-		parent::save_data( $merged );
47
+		parent::save_data($merged);
48 48
 	}
49 49
 
50 50
 	/**
51 51
 	 * @inheritdoc
52 52
 	 */
53
-	public function sanitize_data_filter( $value ) {
53
+	public function sanitize_data_filter($value) {
54 54
 
55 55
 		// Call our sanitizer helper.
56
-		return Wordlift_Sanitizer::sanitize_url( $value );
56
+		return Wordlift_Sanitizer::sanitize_url($value);
57 57
 	}
58 58
 
59 59
 	/**
@@ -75,35 +75,35 @@  discard block
 block discarded – undo
75 75
 	private function get_select_html() {
76 76
 		// Return an element where the new Autocomplete Select will attach to.
77 77
 		return '<p>'
78
-			   . esc_html__( 'Use the search below to link this entity with equivalent entities in the linked data cloud.', 'wordlift' )
78
+			   . esc_html__('Use the search below to link this entity with equivalent entities in the linked data cloud.', 'wordlift')
79 79
 			   . '<div id="wl-metabox-field-sameas"></div></p>';
80 80
 	}
81 81
 
82 82
 	/**
83 83
 	 * @inheritdoc
84 84
 	 */
85
-	protected function get_add_button_html( $count ) {
85
+	protected function get_add_button_html($count) {
86 86
 
87
-		$placeholder = esc_attr_x( 'Type here the URL of an equivalent entity from another dataset.', 'sameAs metabox input', 'wordlift' );
87
+		$placeholder = esc_attr_x('Type here the URL of an equivalent entity from another dataset.', 'sameAs metabox input', 'wordlift');
88 88
 
89 89
 		return
90 90
 			"<label for='$this->meta_name'>"
91
-			. esc_html__( 'If you already know the URL of the entity that you would like to link, add it in the field below.', 'wordlift' )
91
+			. esc_html__('If you already know the URL of the entity that you would like to link, add it in the field below.', 'wordlift')
92 92
 			. '</label>'
93 93
 			. '<div class="wl-input-wrapper">'
94 94
 			. "<input type='text' id='$this->meta_name' name='wl_metaboxes[$this->meta_name][]' placeholder='$placeholder' style='width:88%' />"
95 95
 			. '<button class="button wl-remove-input wl-button" type="button">Remove</button>'
96 96
 			. '</div>'
97
-			. parent::get_add_button_html( $count );
97
+			. parent::get_add_button_html($count);
98 98
 	}
99 99
 
100 100
 	/**
101 101
 	 * @inheritdoc
102 102
 	 */
103
-	protected function get_stored_values_html( &$count ) {
103
+	protected function get_stored_values_html(&$count) {
104 104
 
105 105
 		return '<p>'
106
-			   . parent::get_stored_values_html( $count )
106
+			   . parent::get_stored_values_html($count)
107 107
 			   . '</p>';
108 108
 	}
109 109
 
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 		$count = 0;
126 126
 
127 127
 		// If cardinality allows it, print button to add new values.
128
-		$html .= $this->get_add_button_html( $count );
128
+		$html .= $this->get_add_button_html($count);
129 129
 
130
-		$html .= $this->get_stored_values_html( $count );
130
+		$html .= $this->get_stored_values_html($count);
131 131
 
132 132
 		// Close the HTML wrapper.
133 133
 		$html .= $this->html_wrapper_close();
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	/**
139 139
 	 * @inheritdoc
140 140
 	 */
141
-	public function html_input( $value ) {
141
+	public function html_input($value) {
142 142
 		@ob_start();
143 143
 		?>
144 144
 			<div class="wl-input-wrapper">
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 				/>
153 153
 
154 154
 				<button class="button wl-remove-input wl-button" type="button">
155
-					<?php esc_html_e( 'Remove', 'wordlift' ); ?>
155
+					<?php esc_html_e('Remove', 'wordlift'); ?>
156 156
 				</button>
157 157
 			</div>
158 158
 		<?php
Please login to merge, or discard this patch.
src/includes/class-wordlift-schema-service.php 2 patches
Indentation   +1600 added lines, -1600 removed lines patch added patch discarded remove patch
@@ -18,1605 +18,1605 @@
 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
-				// ### schema:url.
666
-				$this->rendition_factory->create(
667
-					$this->storage_factory->url_property(),
668
-					Wordlift_Query_Builder::SCHEMA_URL_URI,
669
-					self::DATA_TYPE_URI
670
-				),
671
-				// ### schema:description.
672
-				$this->rendition_factory->create(
673
-					$this->storage_factory->post_description_no_tags_no_shortcodes(),
674
-					'http://schema.org/description',
675
-					null,
676
-					$this->language_code
677
-				),
678
-				// ### owl:sameAs.
679
-				$this->rendition_factory->create(
680
-					$this->storage_factory->post_meta( self::FIELD_SAME_AS ),
681
-					'http://www.w3.org/2002/07/owl#sameAs',
682
-					self::DATA_TYPE_URI
683
-				),
684
-				// ### rdf:type.
685
-				$this->rendition_factory->create(
686
-					$this->storage_factory->schema_class(),
687
-					Wordlift_Query_Builder::RDFS_TYPE_URI,
688
-					self::DATA_TYPE_URI
689
-				),
690
-				// ### schema:image.
691
-				$this->rendition_factory->create(
692
-					$this->storage_factory->post_images(),
693
-					Wordlift_Query_Builder::SCHEMA_IMAGE_URI,
694
-					self::DATA_TYPE_URI
695
-				),
696
-				// ### dct:relation.
697
-				$this->rendition_factory->create(
698
-					$this->storage_factory->relations(),
699
-					Wordlift_Query_Builder::DCTERMS_RELATION_URI,
700
-					self::DATA_TYPE_URI
701
-				),
702
-			),
703
-		);
704
-
705
-	}
706
-
707
-	/**
708
-	 * Get the 'web-page' schema.
709
-	 *
710
-	 * @return array An array with the schema configuration.
711
-	 *
712
-	 * @since 3.18.0
713
-	 */
714
-	private function get_web_page_schema() {
715
-
716
-		return array(
717
-			'css_class'     => 'wl-webpage',
718
-			'uri'           => 'http://schema.org/WebPage',
719
-			'linked_data'   => array(
720
-				// ### schema:headline.
721
-				$this->rendition_factory->create(
722
-					$this->storage_factory->post_title(),
723
-					'http://schema.org/headline',
724
-					null,
725
-					$this->language_code
726
-				),
727
-				// ### schema:url.
728
-				$this->rendition_factory->create(
729
-					$this->storage_factory->url_property(),
730
-					Wordlift_Query_Builder::SCHEMA_URL_URI,
731
-					self::DATA_TYPE_URI
732
-				),
733
-				// ### rdf:type.
734
-				$this->rendition_factory->create(
735
-					$this->storage_factory->schema_class(),
736
-					Wordlift_Query_Builder::RDFS_TYPE_URI,
737
-					self::DATA_TYPE_URI
738
-				),
739
-				// ### dcterms:references.
740
-				$this->rendition_factory->create(
741
-					$this->storage_factory->relations(),
742
-					Wordlift_Query_Builder::DCTERMS_REFERENCES_URI,
743
-					self::DATA_TYPE_URI,
744
-					$this->language_code
745
-				),
746
-			),
747
-		);
748
-
749
-	}
750
-
751
-	/**
752
-	 * Get the 'creative work' schema.
753
-	 *
754
-	 * @return array An array with the schema configuration.
755
-	 *
756
-	 * @since 3.1.0
757
-	 */
758
-	private function get_creative_work_schema() {
759
-
760
-		$schema = array(
761
-			'label'         => 'CreativeWork',
762
-			'description'   => 'A creative work (or a Music Album).',
763
-			'parents'       => array( 'thing' ),
764
-			// Give term slug as parent.
765
-			'css_class'     => 'wl-creative-work',
766
-			'uri'           => 'http://schema.org/CreativeWork',
767
-			'same_as'       => array(
768
-				'http://schema.org/MusicAlbum',
769
-				'http://schema.org/Product',
770
-			),
771
-			'custom_fields' => array(
772
-				self::FIELD_AUTHOR => array(
773
-					'predicate'   => 'http://schema.org/author',
774
-					'type'        => self::DATA_TYPE_URI,
775
-					'export_type' => 'http://schema.org/Person',
776
-					'constraints' => array(
777
-						'uri_type'    => array( 'Person', 'Organization' ),
778
-						'cardinality' => INF,
779
-					),
780
-				),
781
-			),
782
-			'linked_data'   => array(
783
-				// ### schema:author.
784
-				$this->rendition_factory->create(
785
-					$this->storage_factory->author_uri(),
786
-					Wordlift_Query_Builder::SCHEMA_AUTHOR_URI,
787
-					self::DATA_TYPE_URI
788
-				),
789
-			),
790
-			'templates'     => array(
791
-				'subtitle' => '{{id}}',
792
-			),
793
-		);
794
-
795
-		// Merge the custom fields with those provided by the thing schema.
796
-		$parent_schema           = $this->get_thing_schema();
797
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
798
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
799
-
800
-		return $schema;
801
-	}
802
-
803
-	/**
804
-	 * Get the 'event' schema.
805
-	 *
806
-	 * @return array An array with the schema configuration.
807
-	 *
808
-	 * @since 3.1.0
809
-	 */
810
-	private function get_event_schema() {
811
-
812
-		$schema = array(
813
-			'label'         => 'Event',
814
-			'description'   => 'An event . ',
815
-			'parents'       => array( 'thing' ),
816
-			'css_class'     => 'wl-event',
817
-			'uri'           => self::SCHEMA_EVENT_TYPE,
818
-			'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
819
-			'custom_fields' => array(
820
-				self::FIELD_DATE_START => array(
821
-					'predicate'   => 'http://schema.org/startDate',
822
-					'type'        => self::DATA_TYPE_DATE,
823
-					'export_type' => 'xsd:dateTime',
824
-					'constraints' => '',
825
-				),
826
-				self::FIELD_DATE_END   => array(
827
-					'predicate'   => 'http://schema.org/endDate',
828
-					'type'        => self::DATA_TYPE_DATE,
829
-					'export_type' => 'xsd:dateTime',
830
-					'constraints' => '',
831
-				),
832
-				self::FIELD_LOCATION   => array(
833
-					'predicate'   => 'http://schema.org/location',
834
-					'type'        => self::DATA_TYPE_URI,
835
-					'export_type' => 'http://schema.org/PostalAddress',
836
-					'constraints' => array(
837
-						'uri_type'    => array( 'Place', 'LocalBusiness' ),
838
-						'cardinality' => INF,
839
-					),
840
-				),
841
-				self::FIELD_PERFORMER => array(
842
-					'predicate'   => 'http://schema.org/performer',
843
-					'type'        => self::DATA_TYPE_URI,
844
-					'export_type' => 'http://schema.org/Person',
845
-					'constraints' => array(
846
-						'uri_type'    => array( 'Person', 'Organization' ),
847
-						'cardinality' => INF,
848
-					),
849
-				),
850
-				self::FIELD_OFFERS => array(
851
-					'predicate'   => 'http://schema.org/offers',
852
-					'type'        => self::DATA_TYPE_URI,
853
-					'export_type' => 'http://schema.org/Offer',
854
-					'constraints' => array(
855
-						'uri_type'    => array( 'Offer' ),
856
-						'cardinality' => INF,
857
-					),
858
-				),
859
-			),
860
-			'linked_data'   => array(
861
-				// ### schema:startDate.
862
-				$this->rendition_factory->create(
863
-					$this->storage_factory->post_meta( self::FIELD_DATE_START ),
864
-					'http://schema.org/startDate',
865
-					self::DATA_TYPE_DATE_TIME
866
-				),
867
-				// ### schema:endDate.
868
-				$this->rendition_factory->create(
869
-					$this->storage_factory->post_meta( self::FIELD_DATE_END ),
870
-					'http://schema.org/endDate',
871
-					self::DATA_TYPE_DATE_TIME
872
-				),
873
-				// ### schema:location.
874
-				$this->rendition_factory->create(
875
-					$this->storage_factory->post_meta_to_uri( self::FIELD_LOCATION ),
876
-					'http://schema.org/location',
877
-					self::DATA_TYPE_URI
878
-				),
879
-				// ### schema:performer.
880
-				$this->rendition_factory->create(
881
-					$this->storage_factory->post_meta_to_uri( self::FIELD_PERFORMER ),
882
-					'http://schema.org/performer',
883
-					self::DATA_TYPE_URI
884
-				),
885
-				// ### schema:offers.
886
-				$this->rendition_factory->create(
887
-					$this->storage_factory->post_meta_to_uri( self::FIELD_OFFERS ),
888
-					'http://schema.org/offers',
889
-					self::DATA_TYPE_URI
890
-				),
891
-			),
892
-			'templates'     => array(
893
-				'subtitle' => '{{id}}',
894
-			),
895
-		);
896
-
897
-		// Merge the custom fields with those provided by the thing schema.
898
-		$parent_schema           = $this->get_thing_schema();
899
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
900
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
901
-
902
-		return $schema;
903
-	}
904
-
905
-	/**
906
-	 * Get the 'organization' schema.
907
-	 *
908
-	 * @return array An array with the schema configuration.
909
-	 *
910
-	 * @since 3.1.0
911
-	 */
912
-	private function get_organization_schema() {
913
-
914
-		$schema = array(
915
-			'label'         => 'Organization',
916
-			'description'   => 'An organization, including a government or a newspaper.',
917
-			'parents'       => array( 'thing' ),
918
-			'css_class'     => 'wl-organization',
919
-			'uri'           => 'http://schema.org/Organization',
920
-			'same_as'       => array(
921
-				'http://rdf.freebase.com/ns/organization.organization',
922
-				'http://rdf.freebase.com/ns/government.government',
923
-				'http://schema.org/Newspaper',
924
-			),
925
-			'custom_fields' => array(
926
-				self::FIELD_LEGAL_NAME          => array(
927
-					'predicate'   => 'http://schema.org/legalName',
928
-					'type'        => self::DATA_TYPE_STRING,
929
-					'export_type' => 'xsd:string',
930
-					'constraints' => '',
931
-				),
932
-				self::FIELD_FOUNDER             => array(
933
-					'predicate'   => 'http://schema.org/founder',
934
-					'type'        => self::DATA_TYPE_URI,
935
-					'export_type' => 'http://schema.org/Person',
936
-					'constraints' => array(
937
-						'uri_type'    => 'Person',
938
-						'cardinality' => INF,
939
-					),
940
-				),
941
-				self::FIELD_ADDRESS             => array(
942
-					'predicate'   => 'http://schema.org/streetAddress',
943
-					'type'        => self::DATA_TYPE_STRING,
944
-					'export_type' => 'xsd:string',
945
-					'constraints' => '',
946
-					// To build custom metabox.
947
-					'input_field' => 'address',
948
-				),
949
-				self::FIELD_ADDRESS_PO_BOX      => array(
950
-					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
951
-					'type'        => self::DATA_TYPE_STRING,
952
-					'export_type' => 'xsd:string',
953
-					'constraints' => '',
954
-					// To build custom metabox.
955
-					'input_field' => 'address',
956
-				),
957
-				self::FIELD_ADDRESS_POSTAL_CODE => array(
958
-					'predicate'   => 'http://schema.org/postalCode',
959
-					'type'        => self::DATA_TYPE_STRING,
960
-					'export_type' => 'xsd:string',
961
-					'constraints' => '',
962
-					// To build custom metabox.
963
-					'input_field' => 'address',
964
-				),
965
-				self::FIELD_ADDRESS_LOCALITY    => array(
966
-					'predicate'   => 'http://schema.org/addressLocality',
967
-					'type'        => self::DATA_TYPE_STRING,
968
-					'export_type' => 'xsd:string',
969
-					'constraints' => '',
970
-					// To build custom metabox.
971
-					'input_field' => 'address',
972
-				),
973
-				self::FIELD_ADDRESS_REGION      => array(
974
-					'predicate'   => 'http://schema.org/addressRegion',
975
-					'type'        => self::DATA_TYPE_STRING,
976
-					'export_type' => 'xsd:string',
977
-					'constraints' => '',
978
-					// To build custom metabox.
979
-					'input_field' => 'address',
980
-				),
981
-				self::FIELD_ADDRESS_COUNTRY     => array(
982
-					'predicate'   => 'http://schema.org/addressCountry',
983
-					'type'        => self::DATA_TYPE_STRING,
984
-					'export_type' => 'xsd:string',
985
-					'constraints' => '',
986
-					// To build custom metabox.
987
-					'input_field' => 'address',
988
-				),
989
-				self::FIELD_EMAIL               => array(
990
-					'predicate'   => 'http://schema.org/email',
991
-					'type'        => self::DATA_TYPE_STRING,
992
-					'export_type' => 'xsd:string',
993
-					'constraints' => '',
994
-				),
995
-				self::FIELD_TELEPHONE           => array(
996
-					'predicate'   => 'http://schema.org/telephone',
997
-					'type'        => self::DATA_TYPE_STRING,
998
-					'export_type' => 'xsd:string',
999
-					'constraints' => '',
1000
-				),
1001
-			),
1002
-			'linked_data'   => array(
1003
-				// ### schema:legalName.
1004
-				$this->rendition_factory->create(
1005
-					$this->storage_factory->post_meta( self::FIELD_LEGAL_NAME ),
1006
-					'http://schema.org/legalName'
1007
-				),
1008
-				// ### schema:founder.
1009
-				$this->rendition_factory->create(
1010
-					$this->storage_factory->post_meta_to_uri( self::FIELD_FOUNDER ),
1011
-					'http://schema.org/founder',
1012
-					self::DATA_TYPE_URI
1013
-				),
1014
-				// ### schema:email.
1015
-				$this->rendition_factory->create(
1016
-					$this->storage_factory->post_meta( self::FIELD_EMAIL ),
1017
-					'http://schema.org/email'
1018
-				),
1019
-				// ### schema:telephone.
1020
-				$this->rendition_factory->create(
1021
-					$this->storage_factory->post_meta( self::FIELD_TELEPHONE ),
1022
-					'http://schema.org/telephone'
1023
-				),
1024
-			),
1025
-			'templates'     => array(
1026
-				'subtitle' => '{{id}}',
1027
-			),
1028
-		);
1029
-
1030
-		// Merge the custom fields with those provided by the thing schema.
1031
-		$parent_schema           = $this->get_thing_schema();
1032
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1033
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1034
-
1035
-		return $schema;
1036
-	}
1037
-
1038
-	/**
1039
-	 * Get the 'person' schema.
1040
-	 *
1041
-	 * @return array An array with the schema configuration.
1042
-	 *
1043
-	 * @since 3.1.0
1044
-	 */
1045
-	private function get_person_schema() {
1046
-
1047
-		$schema = array(
1048
-			'label'         => 'Person',
1049
-			'description'   => 'A person (or a music artist).',
1050
-			'parents'       => array( 'thing' ),
1051
-			'css_class'     => 'wl-person',
1052
-			'uri'           => 'http://schema.org/Person',
1053
-			'same_as'       => array(
1054
-				'http://rdf.freebase.com/ns/people.person',
1055
-				'http://rdf.freebase.com/ns/music.artist',
1056
-				'http://dbpedia.org/class/yago/LivingPeople',
1057
-			),
1058
-			'custom_fields' => array(
1059
-				self::FIELD_KNOWS       => array(
1060
-					'predicate'   => 'http://schema.org/knows',
1061
-					'type'        => self::DATA_TYPE_URI,
1062
-					'export_type' => 'http://schema.org/Person',
1063
-					'constraints' => array(
1064
-						'uri_type'    => 'Person',
1065
-						'cardinality' => INF,
1066
-					),
1067
-				),
1068
-				self::FIELD_BIRTH_DATE  => array(
1069
-					'predicate'   => 'http://schema.org/birthDate',
1070
-					'type'        => self::DATA_TYPE_DATE,
1071
-					'export_type' => 'xsd:date',
1072
-					'constraints' => '',
1073
-				),
1074
-				self::FIELD_BIRTH_PLACE => array(
1075
-					'predicate'   => 'http://schema.org/birthPlace',
1076
-					'type'        => self::DATA_TYPE_URI,
1077
-					'export_type' => 'http://schema.org/Place',
1078
-					'constraints' => array(
1079
-						'uri_type' => 'Place',
1080
-					),
1081
-				),
1082
-				self::FIELD_AFFILIATION => array(
1083
-					'predicate'   => 'http://schema.org/affiliation',
1084
-					'type'        => self::DATA_TYPE_URI,
1085
-					'export_type' => 'http://schema.org/Organization',
1086
-					'constraints' => array(
1087
-						'uri_type'    => array(
1088
-							'Organization',
1089
-							'LocalBusiness',
1090
-						),
1091
-						'cardinality' => INF,
1092
-					),
1093
-				),
1094
-				self::FIELD_EMAIL       => array(
1095
-					'predicate'   => 'http://schema.org/email',
1096
-					'type'        => self::DATA_TYPE_STRING,
1097
-					'export_type' => 'xsd:string',
1098
-					'constraints' => array(
1099
-						'cardinality' => INF,
1100
-					),
1101
-				),
1102
-			),
1103
-			'linked_data'   => array(
1104
-				// ### schema:knows.
1105
-				$this->rendition_factory->create(
1106
-					$this->storage_factory->post_meta_to_uri( self::FIELD_KNOWS ),
1107
-					'http://schema.org/knows',
1108
-					self::DATA_TYPE_URI
1109
-				),
1110
-				// ### schema:birthDate.
1111
-				$this->rendition_factory->create(
1112
-					$this->storage_factory->post_meta( self::FIELD_BIRTH_DATE ),
1113
-					'http://schema.org/birthDate',
1114
-					self::DATA_TYPE_DATE
1115
-				),
1116
-				// ### schema:birthPlace.
1117
-				$this->rendition_factory->create(
1118
-					$this->storage_factory->post_meta_to_uri( self::FIELD_BIRTH_PLACE ),
1119
-					'http://schema.org/birthPlace',
1120
-					self::DATA_TYPE_URI
1121
-				),
1122
-				// ### schema:affiliation.
1123
-				$this->rendition_factory->create(
1124
-					$this->storage_factory->post_meta_to_uri( self::FIELD_AFFILIATION ),
1125
-					'http://schema.org/affiliation',
1126
-					self::DATA_TYPE_URI
1127
-				),
1128
-				// ### schema:email.
1129
-				$this->rendition_factory->create(
1130
-					$this->storage_factory->post_meta( self::FIELD_EMAIL ),
1131
-					'http://schema.org/email'
1132
-				),
1133
-			),
1134
-			'templates'     => array(
1135
-				'subtitle' => '{{id}}',
1136
-			),
1137
-		);
1138
-
1139
-		// Merge the custom fields with those provided by the thing schema.
1140
-		$parent_schema           = $this->get_thing_schema();
1141
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1142
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1143
-
1144
-		return $schema;
1145
-
1146
-	}
1147
-
1148
-	/**
1149
-	 * Get the 'place' schema.
1150
-	 *
1151
-	 * @return array An array with the schema configuration.
1152
-	 *
1153
-	 * @since 3.1.0
1154
-	 */
1155
-	private function get_place_schema() {
1156
-
1157
-		$schema = array(
1158
-			'label'         => 'Place',
1159
-			'description'   => 'A place.',
1160
-			'parents'       => array( 'thing' ),
1161
-			'css_class'     => 'wl-place',
1162
-			'uri'           => 'http://schema.org/Place',
1163
-			'same_as'       => array(
1164
-				'http://rdf.freebase.com/ns/location.location',
1165
-				'http://www.opengis.net/gml/_Feature',
1166
-			),
1167
-			'custom_fields' => array(
1168
-				self::FIELD_GEO_LATITUDE        => array(
1169
-					'predicate'   => 'http://schema.org/latitude',
1170
-					'type'        => self::DATA_TYPE_DOUBLE,
1171
-					'export_type' => 'xsd:double',
1172
-					'constraints' => '',
1173
-					// To build custom metabox.
1174
-					'input_field' => 'coordinates',
1175
-				),
1176
-				self::FIELD_GEO_LONGITUDE       => array(
1177
-					'predicate'   => 'http://schema.org/longitude',
1178
-					'type'        => self::DATA_TYPE_DOUBLE,
1179
-					'export_type' => 'xsd:double',
1180
-					'constraints' => '',
1181
-					// To build custom metabox.
1182
-					'input_field' => 'coordinates',
1183
-				),
1184
-				self::FIELD_ADDRESS             => array(
1185
-					'predicate'   => 'http://schema.org/streetAddress',
1186
-					'type'        => self::DATA_TYPE_STRING,
1187
-					'export_type' => 'xsd:string',
1188
-					'constraints' => '',
1189
-					// To build custom metabox.
1190
-					'input_field' => 'address',
1191
-				),
1192
-				self::FIELD_ADDRESS_PO_BOX      => array(
1193
-					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
1194
-					'type'        => self::DATA_TYPE_STRING,
1195
-					'export_type' => 'xsd:string',
1196
-					'constraints' => '',
1197
-					// To build custom metabox.
1198
-					'input_field' => 'address',
1199
-				),
1200
-				self::FIELD_ADDRESS_POSTAL_CODE => array(
1201
-					'predicate'   => 'http://schema.org/postalCode',
1202
-					'type'        => self::DATA_TYPE_STRING,
1203
-					'export_type' => 'xsd:string',
1204
-					'constraints' => '',
1205
-					// To build custom metabox.
1206
-					'input_field' => 'address',
1207
-				),
1208
-				self::FIELD_ADDRESS_LOCALITY    => array(
1209
-					'predicate'   => 'http://schema.org/addressLocality',
1210
-					'type'        => self::DATA_TYPE_STRING,
1211
-					'export_type' => 'xsd:string',
1212
-					'constraints' => '',
1213
-					// To build custom metabox.
1214
-					'input_field' => 'address',
1215
-				),
1216
-				self::FIELD_ADDRESS_REGION      => array(
1217
-					'predicate'   => 'http://schema.org/addressRegion',
1218
-					'type'        => self::DATA_TYPE_STRING,
1219
-					'export_type' => 'xsd:string',
1220
-					'constraints' => '',
1221
-					// To build custom metabox.
1222
-					'input_field' => 'address',
1223
-				),
1224
-				self::FIELD_ADDRESS_COUNTRY     => array(
1225
-					'predicate'   => 'http://schema.org/addressCountry',
1226
-					'type'        => self::DATA_TYPE_STRING,
1227
-					'export_type' => 'xsd:string',
1228
-					'constraints' => '',
1229
-					// To build custom metabox.
1230
-					'input_field' => 'address',
1231
-				),
1232
-			),
1233
-			'linked_data'   => array(
1234
-				$this->rendition_factory->create_address(
1235
-					$this->storage_factory,
1236
-					$this->language_code
1237
-				),
1238
-			),
1239
-			'templates'     => array(
1240
-				'subtitle' => '{{id}}',
1241
-			),
1242
-		);
1243
-
1244
-		// Merge the custom fields with those provided by the thing schema.
1245
-		$parent_schema           = $this->get_thing_schema();
1246
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1247
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1248
-
1249
-		return $schema;
1250
-	}
1251
-
1252
-	/**
1253
-	 * Get the 'local business' schema.
1254
-	 *
1255
-	 * @return array An array with the schema configuration.
1256
-	 *
1257
-	 * @since 3.1.0
1258
-	 */
1259
-	private function get_local_business_schema() {
1260
-
1261
-		$schema = array(
1262
-			'label'         => 'LocalBusiness',
1263
-			'description'   => 'A local business.',
1264
-			'parents'       => array( 'place', 'organization' ),
1265
-			'css_class'     => 'wl-local-business',
1266
-			'uri'           => 'http://schema.org/LocalBusiness',
1267
-			'same_as'       => array(
1268
-				'http://rdf.freebase.com/ns/business/business_location',
1269
-				'https://schema.org/Store',
1270
-			),
1271
-			'custom_fields' => array(),
1272
-			'linked_data'   => array(),
1273
-			'templates'     => array(
1274
-				'subtitle' => '{{id}}',
1275
-			),
1276
-		);
1277
-
1278
-		// Merge the custom fields with those provided by the place and organization schema.
1279
-		$place_schema            = $this->get_place_schema();
1280
-		$organization_schema     = $this->get_organization_schema();
1281
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
1282
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $place_schema['linked_data'], $organization_schema['linked_data'] );
1283
-
1284
-		return $schema;
1285
-	}
1286
-
1287
-	/**
1288
-	 * Get the 'recipe' schema.
1289
-	 *
1290
-	 * @return array An array with the schema configuration.
1291
-	 *
1292
-	 * @since 3.14.0
1293
-	 */
1294
-	private function get_recipe_schema() {
1295
-
1296
-		$schema = array(
1297
-			'label'         => 'Recipe',
1298
-			'description'   => 'A Recipe.',
1299
-			'parents'       => array( 'CreativeWork' ),
1300
-			'css_class'     => 'wl-recipe',
1301
-			'uri'           => 'http://schema.org/Recipe',
1302
-			'same_as'       => array(),
1303
-			'templates'     => array(
1304
-				'subtitle' => '{{id}}',
1305
-			),
1306
-			'custom_fields' => array(
1307
-				self::FIELD_RECIPE_CUISINE          => array(
1308
-					'predicate'   => 'http://schema.org/recipeCuisine',
1309
-					'type'        => self::DATA_TYPE_STRING,
1310
-					'export_type' => 'xsd:string',
1311
-					'constraints' => '',
1312
-					'metabox'     => array(
1313
-						'label' => __( 'Recipe cuisine', 'wordlift' ),
1314
-					),
1315
-				),
1316
-				self::FIELD_RECIPE_INGREDIENT       => array(
1317
-					'predicate'   => 'http://schema.org/recipeIngredient',
1318
-					'type'        => self::DATA_TYPE_STRING,
1319
-					'export_type' => 'xsd:string',
1320
-					'constraints' => array(
1321
-						'cardinality' => INF,
1322
-					),
1323
-					'metabox'     => array(
1324
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
1325
-					),
1326
-				),
1327
-				self::FIELD_RECIPE_INSTRUCTIONS     => array(
1328
-					'predicate'   => 'http://schema.org/recipeInstructions',
1329
-					'type'        => self::DATA_TYPE_MULTILINE,
1330
-					'export_type' => 'xsd:string',
1331
-					'constraints' => '',
1332
-					'metabox'     => array(
1333
-						'class' => 'Wordlift_Metabox_Field_Multiline',
1334
-						'label' => __( 'Recipe instructions', 'wordlift' ),
1335
-					),
1336
-				),
1337
-				self::FIELD_RECIPE_YIELD            => array(
1338
-					'predicate'   => 'http://schema.org/recipeYield',
1339
-					'type'        => self::DATA_TYPE_STRING,
1340
-					'export_type' => 'xsd:string',
1341
-					'constraints' => '',
1342
-					'metabox'     => array(
1343
-						'label' => __( 'Recipe number of servings', 'wordlift' ),
1344
-					),
1345
-				),
1346
-				self::FIELD_RECIPE_INGREDIENT       => array(
1347
-					'predicate'   => 'http://schema.org/recipeIngredient',
1348
-					'type'        => self::DATA_TYPE_STRING,
1349
-					'export_type' => 'xsd:string',
1350
-					'constraints' => array(
1351
-						'cardinality' => INF,
1352
-					),
1353
-					'metabox'     => array(
1354
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
1355
-					),
1356
-				),
1357
-				self::FIELD_NUTRITION_INFO_CALORIES => array(
1358
-					'predicate'   => 'http://schema.org/calories',
1359
-					'type'        => self::DATA_TYPE_STRING,
1360
-					'export_type' => 'xsd:string',
1361
-					'constraints' => '',
1362
-					'metabox'     => array(
1363
-						'label' => __( 'Calories (e.g. 240 calories)', 'wordlift' ),
1364
-					),
1365
-				),
1366
-				self::FIELD_PREP_TIME               => array(
1367
-					'predicate'   => 'http://schema.org/prepTime',
1368
-					'type'        => self::DATA_TYPE_DURATION,
1369
-					'export_type' => 'xsd:time',
1370
-					'constraints' => '',
1371
-					'metabox'     => array(
1372
-						'class' => 'Wordlift_Metabox_Field_Duration',
1373
-						'label' => __( 'Recipe preparation time (e.g. 1:30)', 'wordlift' ),
1374
-					),
1375
-				),
1376
-				self::FIELD_COOK_TIME               => array(
1377
-					'predicate'   => 'http://schema.org/cookTime',
1378
-					'type'        => self::DATA_TYPE_DURATION,
1379
-					'export_type' => 'xsd:time',
1380
-					'constraints' => '',
1381
-					'metabox'     => array(
1382
-						'class' => 'Wordlift_Metabox_Field_Duration',
1383
-						'label' => __( 'Recipe cook time (e.g. 1:30)', 'wordlift' ),
1384
-					),
1385
-				),
1386
-				self::FIELD_TOTAL_TIME              => array(
1387
-					'predicate'   => 'http://schema.org/totalTime',
1388
-					'type'        => self::DATA_TYPE_DURATION,
1389
-					'export_type' => 'xsd:time',
1390
-					'constraints' => '',
1391
-					'metabox'     => array(
1392
-						'class' => 'Wordlift_Metabox_Field_Duration',
1393
-						'label' => __( 'Recipe total time (e.g. 1:30)', 'wordlift' ),
1394
-					),
1395
-				),
1396
-			),
1397
-			'linked_data'   => array(
1398
-				// ### schema:recipeCuisine.
1399
-				$this->rendition_factory->create(
1400
-					$this->storage_factory->post_meta( self::FIELD_RECIPE_CUISINE ),
1401
-					'http://schema.org/recipeCuisine'
1402
-				),
1403
-				// ### schema:recipeIngredient.
1404
-				$this->rendition_factory->create(
1405
-					$this->storage_factory->post_meta( self::FIELD_RECIPE_INGREDIENT ),
1406
-					'http://schema.org/recipeIngredient'
1407
-				),
1408
-				// ### schema:prepTime.
1409
-				$this->rendition_factory->create(
1410
-					$this->storage_factory->post_meta( self::FIELD_PREP_TIME ),
1411
-					'http://schema.org/prepTime',
1412
-					self::DATA_TYPE_DURATION
1413
-				),
1414
-				// ### schema:cookTime.
1415
-				$this->rendition_factory->create(
1416
-					$this->storage_factory->post_meta( self::FIELD_COOK_TIME ),
1417
-					'http://schema.org/cookTime',
1418
-					self::DATA_TYPE_DURATION
1419
-				),
1420
-				// ### schema:totalTime.
1421
-				$this->rendition_factory->create(
1422
-					$this->storage_factory->post_meta( self::FIELD_TOTAL_TIME ),
1423
-					'http://schema.org/totalTime',
1424
-					self::DATA_TYPE_DURATION
1425
-				),
1426
-			),
1427
-		);
1428
-
1429
-		// Merge the custom fields with those provided by the parent schema.
1430
-		$parent_schema           = $this->get_creative_work_schema();
1431
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1432
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1433
-
1434
-		return $schema;
1435
-	}
1436
-
1437
-	/**
1438
-	 * Get the 'offer' schema.
1439
-	 *
1440
-	 * @return array An array with the schema configuration.
1441
-	 *
1442
-	 * @since 3.18.0
1443
-	 */
1444
-	private function get_offer_schema() {
1445
-
1446
-		$schema = array(
1447
-			'label'         => 'Offer',
1448
-			'description'   => 'An offer. ',
1449
-			'parents'       => array( 'thing' ),
1450
-			'css_class'     => 'wl-offer',
1451
-			'uri'           => self::SCHEMA_OFFER_TYPE,
1452
-			'same_as'       => array(),
1453
-			'templates'     => array(
1454
-				'subtitle' => '{{id}}',
1455
-			),
1456
-			'custom_fields' => array(
1457
-				self::FIELD_AVAILABILITY => array(
1458
-					'predicate'   => 'http://schema.org/availability',
1459
-					'type'        => self::DATA_TYPE_STRING,
1460
-					'export_type' => 'xsd:string',
1461
-					'metabox'     => array(
1462
-						'class' => 'Wordlift_Metabox_Field_Select',
1463
-					),
1464
-					'options' => array(
1465
-						'Discontinued'        => esc_html__( 'Discontinued', 'wordlift' ),
1466
-						'InStock'             => esc_html__( 'In Stock', 'wordlift' ),
1467
-						'InStoreOnly'         => esc_html__( 'In Store Only', 'wordlift' ),
1468
-						'LimitedAvailability' => esc_html__( 'Limited Availability', 'wordlift' ),
1469
-						'OnlineOnly'          => esc_html__( 'Online Only', 'wordlift' ),
1470
-						'OutOfStock'          => esc_html__( 'Out of Stock', 'wordlift' ),
1471
-						'PreOrder'            => esc_html__( 'Pre Order', 'wordlift' ),
1472
-						'PreSale'             => esc_html__( 'Pre Sale', 'wordlift' ),
1473
-						'SoldOut'             => esc_html__( 'Sold Out', 'wordlift' ),
1474
-					),
1475
-				),
1476
-				self::FIELD_PRICE => array(
1477
-					'predicate'   => 'http://schema.org/price',
1478
-					'type'        => self::DATA_TYPE_STRING,
1479
-					'export_type' => 'xsd:integer',
1480
-					'metabox'     => array(
1481
-						'class' => 'Wordlift_Metabox_Field_Integer',
1482
-					),
1483
-				),
1484
-				self::FIELD_PRICE_CURRENCY => array(
1485
-					'predicate'   => 'http://schema.org/priceCurrency',
1486
-					'type'        => self::DATA_TYPE_STRING,
1487
-					'export_type' => 'xsd:string',
1488
-				),
1489
-				self::FIELD_AVAILABILITY_STARTS => array(
1490
-					'predicate'   => 'http://schema.org/availabilityStarts',
1491
-					'type'        => self::DATA_TYPE_DATE,
1492
-					'export_type' => 'xsd:dateTime',
1493
-				),
1494
-				self::FIELD_AVAILABILITY_ENDS => array(
1495
-					'predicate'   => 'http://schema.org/availabilityEnds',
1496
-					'type'        => self::DATA_TYPE_DATE,
1497
-					'export_type' => 'xsd:dateTime',
1498
-				),
1499
-				self::FIELD_INVENTORY_LEVEL => array(
1500
-					'predicate'   => 'http://schema.org/inventoryLevel',
1501
-					'type'        => self::DATA_TYPE_STRING,
1502
-					'export_type' => 'xsd:integer',
1503
-					'metabox'     => array(
1504
-						'class' => 'Wordlift_Metabox_Field_Integer',
1505
-					),
1506
-				),
1507
-				self::FIELD_VALID_FROM => array(
1508
-					'predicate'   => 'http://schema.org/validFrom',
1509
-					'type'        => self::DATA_TYPE_DATE,
1510
-					'export_type' => 'xsd:dateTime',
1511
-				),
1512
-				self::FIELD_PRICE_VALID_UNTIL => array(
1513
-					'predicate'   => 'http://schema.org/priceValidUntil',
1514
-					'type'        => self::DATA_TYPE_DATE,
1515
-					'export_type' => 'xsd:dateTime',
1516
-				),
1517
-				self::FIELD_ITEM_OFFERED => array(
1518
-					'predicate'   => 'http://schema.org/itemOffered',
1519
-					'type'        => self::DATA_TYPE_URI,
1520
-					'export_type' => 'http://schema.org/Thing',
1521
-					'constraints' => array(
1522
-						'uri_type'    => array(
1523
-							'Event',
1524
-							'Thing',
1525
-						),
1526
-						'cardinality' => INF,
1527
-					),
1528
-				),
1529
-			),
1530
-			'linked_data' => array(
1531
-				// ### schema:availability.
1532
-				$this->rendition_factory->create(
1533
-					$this->storage_factory->post_meta( self::FIELD_AVAILABILITY ),
1534
-					'http://schema.org/availability',
1535
-					null
1536
-				),
1537
-				// ### schema:availabilityStarts.
1538
-				$this->rendition_factory->create(
1539
-					$this->storage_factory->post_meta( self::FIELD_AVAILABILITY_STARTS ),
1540
-					'http://schema.org/availabilityStarts',
1541
-					self::DATA_TYPE_DATE_TIME
1542
-				),
1543
-				// ### schema:availabilityEnds.
1544
-				$this->rendition_factory->create(
1545
-					$this->storage_factory->post_meta( self::FIELD_AVAILABILITY_ENDS ),
1546
-					'http://schema.org/availabilityEnds',
1547
-					self::DATA_TYPE_DATE_TIME
1548
-				),
1549
-				// ### schema:inventoryLevel.
1550
-				$this->rendition_factory->create(
1551
-					$this->storage_factory->post_meta( self::FIELD_INVENTORY_LEVEL ),
1552
-					'http://schema.org/inventoryLevel',
1553
-					self::DATA_TYPE_INTEGER
1554
-				),
1555
-				// ### schema:price.
1556
-				$this->rendition_factory->create(
1557
-					$this->storage_factory->post_meta( self::FIELD_PRICE ),
1558
-					'http://schema.org/price',
1559
-					self::DATA_TYPE_INTEGER
1560
-				),
1561
-				// ### schema:priceCurrency.
1562
-				$this->rendition_factory->create(
1563
-					$this->storage_factory->post_meta( self::FIELD_PRICE_CURRENCY ),
1564
-					'http://schema.org/priceCurrency',
1565
-					null
1566
-				),
1567
-				// ### schema:validFrom.
1568
-				$this->rendition_factory->create(
1569
-					$this->storage_factory->post_meta( self::FIELD_VALID_FROM ),
1570
-					'http://schema.org/validFrom',
1571
-					null
1572
-				),
1573
-				// ### schema:priceValidUntil.
1574
-				$this->rendition_factory->create(
1575
-					$this->storage_factory->post_meta( self::FIELD_PRICE_VALID_UNTIL ),
1576
-					'http://schema.org/priceValidUntil',
1577
-					null
1578
-				),
1579
-				// ### schema:itemOffered.
1580
-				$this->rendition_factory->create(
1581
-					$this->storage_factory->post_meta_to_uri( self::FIELD_ITEM_OFFERED ),
1582
-					'http://schema.org/itemOffered',
1583
-					self::DATA_TYPE_URI
1584
-				),
1585
-			),
1586
-		);
1587
-
1588
-		// Merge the custom fields with those provided by the thing schema.
1589
-		$parent_schema           = $this->get_thing_schema();
1590
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1591
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1592
-
1593
-		return $schema;
1594
-	}
1595
-
1596
-	/**
1597
-	 * Get the 'article' schema.
1598
-	 *
1599
-	 * @return array An array with the schema configuration.
1600
-	 *
1601
-	 * @since 3.15.0
1602
-	 */
1603
-	private function get_article_schema() {
1604
-
1605
-		$schema = array(
1606
-			'label'         => 'Article',
1607
-			'description'   => 'An Article.',
1608
-			'parents'       => array(),
1609
-			'css_class'     => 'wl-article',
1610
-			'uri'           => 'http://schema.org/Article',
1611
-			'same_as'       => array(),
1612
-			'templates'     => array(
1613
-				'subtitle' => '{{id}}',
1614
-			),
1615
-			'custom_fields' => array(),
1616
-			'linked_data'   => array(),
1617
-		);
1618
-
1619
-		return $schema;
1620
-	}
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
+                // ### schema:url.
666
+                $this->rendition_factory->create(
667
+                    $this->storage_factory->url_property(),
668
+                    Wordlift_Query_Builder::SCHEMA_URL_URI,
669
+                    self::DATA_TYPE_URI
670
+                ),
671
+                // ### schema:description.
672
+                $this->rendition_factory->create(
673
+                    $this->storage_factory->post_description_no_tags_no_shortcodes(),
674
+                    'http://schema.org/description',
675
+                    null,
676
+                    $this->language_code
677
+                ),
678
+                // ### owl:sameAs.
679
+                $this->rendition_factory->create(
680
+                    $this->storage_factory->post_meta( self::FIELD_SAME_AS ),
681
+                    'http://www.w3.org/2002/07/owl#sameAs',
682
+                    self::DATA_TYPE_URI
683
+                ),
684
+                // ### rdf:type.
685
+                $this->rendition_factory->create(
686
+                    $this->storage_factory->schema_class(),
687
+                    Wordlift_Query_Builder::RDFS_TYPE_URI,
688
+                    self::DATA_TYPE_URI
689
+                ),
690
+                // ### schema:image.
691
+                $this->rendition_factory->create(
692
+                    $this->storage_factory->post_images(),
693
+                    Wordlift_Query_Builder::SCHEMA_IMAGE_URI,
694
+                    self::DATA_TYPE_URI
695
+                ),
696
+                // ### dct:relation.
697
+                $this->rendition_factory->create(
698
+                    $this->storage_factory->relations(),
699
+                    Wordlift_Query_Builder::DCTERMS_RELATION_URI,
700
+                    self::DATA_TYPE_URI
701
+                ),
702
+            ),
703
+        );
704
+
705
+    }
706
+
707
+    /**
708
+     * Get the 'web-page' schema.
709
+     *
710
+     * @return array An array with the schema configuration.
711
+     *
712
+     * @since 3.18.0
713
+     */
714
+    private function get_web_page_schema() {
715
+
716
+        return array(
717
+            'css_class'     => 'wl-webpage',
718
+            'uri'           => 'http://schema.org/WebPage',
719
+            'linked_data'   => array(
720
+                // ### schema:headline.
721
+                $this->rendition_factory->create(
722
+                    $this->storage_factory->post_title(),
723
+                    'http://schema.org/headline',
724
+                    null,
725
+                    $this->language_code
726
+                ),
727
+                // ### schema:url.
728
+                $this->rendition_factory->create(
729
+                    $this->storage_factory->url_property(),
730
+                    Wordlift_Query_Builder::SCHEMA_URL_URI,
731
+                    self::DATA_TYPE_URI
732
+                ),
733
+                // ### rdf:type.
734
+                $this->rendition_factory->create(
735
+                    $this->storage_factory->schema_class(),
736
+                    Wordlift_Query_Builder::RDFS_TYPE_URI,
737
+                    self::DATA_TYPE_URI
738
+                ),
739
+                // ### dcterms:references.
740
+                $this->rendition_factory->create(
741
+                    $this->storage_factory->relations(),
742
+                    Wordlift_Query_Builder::DCTERMS_REFERENCES_URI,
743
+                    self::DATA_TYPE_URI,
744
+                    $this->language_code
745
+                ),
746
+            ),
747
+        );
748
+
749
+    }
750
+
751
+    /**
752
+     * Get the 'creative work' schema.
753
+     *
754
+     * @return array An array with the schema configuration.
755
+     *
756
+     * @since 3.1.0
757
+     */
758
+    private function get_creative_work_schema() {
759
+
760
+        $schema = array(
761
+            'label'         => 'CreativeWork',
762
+            'description'   => 'A creative work (or a Music Album).',
763
+            'parents'       => array( 'thing' ),
764
+            // Give term slug as parent.
765
+            'css_class'     => 'wl-creative-work',
766
+            'uri'           => 'http://schema.org/CreativeWork',
767
+            'same_as'       => array(
768
+                'http://schema.org/MusicAlbum',
769
+                'http://schema.org/Product',
770
+            ),
771
+            'custom_fields' => array(
772
+                self::FIELD_AUTHOR => array(
773
+                    'predicate'   => 'http://schema.org/author',
774
+                    'type'        => self::DATA_TYPE_URI,
775
+                    'export_type' => 'http://schema.org/Person',
776
+                    'constraints' => array(
777
+                        'uri_type'    => array( 'Person', 'Organization' ),
778
+                        'cardinality' => INF,
779
+                    ),
780
+                ),
781
+            ),
782
+            'linked_data'   => array(
783
+                // ### schema:author.
784
+                $this->rendition_factory->create(
785
+                    $this->storage_factory->author_uri(),
786
+                    Wordlift_Query_Builder::SCHEMA_AUTHOR_URI,
787
+                    self::DATA_TYPE_URI
788
+                ),
789
+            ),
790
+            'templates'     => array(
791
+                'subtitle' => '{{id}}',
792
+            ),
793
+        );
794
+
795
+        // Merge the custom fields with those provided by the thing schema.
796
+        $parent_schema           = $this->get_thing_schema();
797
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
798
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
799
+
800
+        return $schema;
801
+    }
802
+
803
+    /**
804
+     * Get the 'event' schema.
805
+     *
806
+     * @return array An array with the schema configuration.
807
+     *
808
+     * @since 3.1.0
809
+     */
810
+    private function get_event_schema() {
811
+
812
+        $schema = array(
813
+            'label'         => 'Event',
814
+            'description'   => 'An event . ',
815
+            'parents'       => array( 'thing' ),
816
+            'css_class'     => 'wl-event',
817
+            'uri'           => self::SCHEMA_EVENT_TYPE,
818
+            'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
819
+            'custom_fields' => array(
820
+                self::FIELD_DATE_START => array(
821
+                    'predicate'   => 'http://schema.org/startDate',
822
+                    'type'        => self::DATA_TYPE_DATE,
823
+                    'export_type' => 'xsd:dateTime',
824
+                    'constraints' => '',
825
+                ),
826
+                self::FIELD_DATE_END   => array(
827
+                    'predicate'   => 'http://schema.org/endDate',
828
+                    'type'        => self::DATA_TYPE_DATE,
829
+                    'export_type' => 'xsd:dateTime',
830
+                    'constraints' => '',
831
+                ),
832
+                self::FIELD_LOCATION   => array(
833
+                    'predicate'   => 'http://schema.org/location',
834
+                    'type'        => self::DATA_TYPE_URI,
835
+                    'export_type' => 'http://schema.org/PostalAddress',
836
+                    'constraints' => array(
837
+                        'uri_type'    => array( 'Place', 'LocalBusiness' ),
838
+                        'cardinality' => INF,
839
+                    ),
840
+                ),
841
+                self::FIELD_PERFORMER => array(
842
+                    'predicate'   => 'http://schema.org/performer',
843
+                    'type'        => self::DATA_TYPE_URI,
844
+                    'export_type' => 'http://schema.org/Person',
845
+                    'constraints' => array(
846
+                        'uri_type'    => array( 'Person', 'Organization' ),
847
+                        'cardinality' => INF,
848
+                    ),
849
+                ),
850
+                self::FIELD_OFFERS => array(
851
+                    'predicate'   => 'http://schema.org/offers',
852
+                    'type'        => self::DATA_TYPE_URI,
853
+                    'export_type' => 'http://schema.org/Offer',
854
+                    'constraints' => array(
855
+                        'uri_type'    => array( 'Offer' ),
856
+                        'cardinality' => INF,
857
+                    ),
858
+                ),
859
+            ),
860
+            'linked_data'   => array(
861
+                // ### schema:startDate.
862
+                $this->rendition_factory->create(
863
+                    $this->storage_factory->post_meta( self::FIELD_DATE_START ),
864
+                    'http://schema.org/startDate',
865
+                    self::DATA_TYPE_DATE_TIME
866
+                ),
867
+                // ### schema:endDate.
868
+                $this->rendition_factory->create(
869
+                    $this->storage_factory->post_meta( self::FIELD_DATE_END ),
870
+                    'http://schema.org/endDate',
871
+                    self::DATA_TYPE_DATE_TIME
872
+                ),
873
+                // ### schema:location.
874
+                $this->rendition_factory->create(
875
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_LOCATION ),
876
+                    'http://schema.org/location',
877
+                    self::DATA_TYPE_URI
878
+                ),
879
+                // ### schema:performer.
880
+                $this->rendition_factory->create(
881
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_PERFORMER ),
882
+                    'http://schema.org/performer',
883
+                    self::DATA_TYPE_URI
884
+                ),
885
+                // ### schema:offers.
886
+                $this->rendition_factory->create(
887
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_OFFERS ),
888
+                    'http://schema.org/offers',
889
+                    self::DATA_TYPE_URI
890
+                ),
891
+            ),
892
+            'templates'     => array(
893
+                'subtitle' => '{{id}}',
894
+            ),
895
+        );
896
+
897
+        // Merge the custom fields with those provided by the thing schema.
898
+        $parent_schema           = $this->get_thing_schema();
899
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
900
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
901
+
902
+        return $schema;
903
+    }
904
+
905
+    /**
906
+     * Get the 'organization' schema.
907
+     *
908
+     * @return array An array with the schema configuration.
909
+     *
910
+     * @since 3.1.0
911
+     */
912
+    private function get_organization_schema() {
913
+
914
+        $schema = array(
915
+            'label'         => 'Organization',
916
+            'description'   => 'An organization, including a government or a newspaper.',
917
+            'parents'       => array( 'thing' ),
918
+            'css_class'     => 'wl-organization',
919
+            'uri'           => 'http://schema.org/Organization',
920
+            'same_as'       => array(
921
+                'http://rdf.freebase.com/ns/organization.organization',
922
+                'http://rdf.freebase.com/ns/government.government',
923
+                'http://schema.org/Newspaper',
924
+            ),
925
+            'custom_fields' => array(
926
+                self::FIELD_LEGAL_NAME          => array(
927
+                    'predicate'   => 'http://schema.org/legalName',
928
+                    'type'        => self::DATA_TYPE_STRING,
929
+                    'export_type' => 'xsd:string',
930
+                    'constraints' => '',
931
+                ),
932
+                self::FIELD_FOUNDER             => array(
933
+                    'predicate'   => 'http://schema.org/founder',
934
+                    'type'        => self::DATA_TYPE_URI,
935
+                    'export_type' => 'http://schema.org/Person',
936
+                    'constraints' => array(
937
+                        'uri_type'    => 'Person',
938
+                        'cardinality' => INF,
939
+                    ),
940
+                ),
941
+                self::FIELD_ADDRESS             => array(
942
+                    'predicate'   => 'http://schema.org/streetAddress',
943
+                    'type'        => self::DATA_TYPE_STRING,
944
+                    'export_type' => 'xsd:string',
945
+                    'constraints' => '',
946
+                    // To build custom metabox.
947
+                    'input_field' => 'address',
948
+                ),
949
+                self::FIELD_ADDRESS_PO_BOX      => array(
950
+                    'predicate'   => 'http://schema.org/postOfficeBoxNumber',
951
+                    'type'        => self::DATA_TYPE_STRING,
952
+                    'export_type' => 'xsd:string',
953
+                    'constraints' => '',
954
+                    // To build custom metabox.
955
+                    'input_field' => 'address',
956
+                ),
957
+                self::FIELD_ADDRESS_POSTAL_CODE => array(
958
+                    'predicate'   => 'http://schema.org/postalCode',
959
+                    'type'        => self::DATA_TYPE_STRING,
960
+                    'export_type' => 'xsd:string',
961
+                    'constraints' => '',
962
+                    // To build custom metabox.
963
+                    'input_field' => 'address',
964
+                ),
965
+                self::FIELD_ADDRESS_LOCALITY    => array(
966
+                    'predicate'   => 'http://schema.org/addressLocality',
967
+                    'type'        => self::DATA_TYPE_STRING,
968
+                    'export_type' => 'xsd:string',
969
+                    'constraints' => '',
970
+                    // To build custom metabox.
971
+                    'input_field' => 'address',
972
+                ),
973
+                self::FIELD_ADDRESS_REGION      => array(
974
+                    'predicate'   => 'http://schema.org/addressRegion',
975
+                    'type'        => self::DATA_TYPE_STRING,
976
+                    'export_type' => 'xsd:string',
977
+                    'constraints' => '',
978
+                    // To build custom metabox.
979
+                    'input_field' => 'address',
980
+                ),
981
+                self::FIELD_ADDRESS_COUNTRY     => array(
982
+                    'predicate'   => 'http://schema.org/addressCountry',
983
+                    'type'        => self::DATA_TYPE_STRING,
984
+                    'export_type' => 'xsd:string',
985
+                    'constraints' => '',
986
+                    // To build custom metabox.
987
+                    'input_field' => 'address',
988
+                ),
989
+                self::FIELD_EMAIL               => array(
990
+                    'predicate'   => 'http://schema.org/email',
991
+                    'type'        => self::DATA_TYPE_STRING,
992
+                    'export_type' => 'xsd:string',
993
+                    'constraints' => '',
994
+                ),
995
+                self::FIELD_TELEPHONE           => array(
996
+                    'predicate'   => 'http://schema.org/telephone',
997
+                    'type'        => self::DATA_TYPE_STRING,
998
+                    'export_type' => 'xsd:string',
999
+                    'constraints' => '',
1000
+                ),
1001
+            ),
1002
+            'linked_data'   => array(
1003
+                // ### schema:legalName.
1004
+                $this->rendition_factory->create(
1005
+                    $this->storage_factory->post_meta( self::FIELD_LEGAL_NAME ),
1006
+                    'http://schema.org/legalName'
1007
+                ),
1008
+                // ### schema:founder.
1009
+                $this->rendition_factory->create(
1010
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_FOUNDER ),
1011
+                    'http://schema.org/founder',
1012
+                    self::DATA_TYPE_URI
1013
+                ),
1014
+                // ### schema:email.
1015
+                $this->rendition_factory->create(
1016
+                    $this->storage_factory->post_meta( self::FIELD_EMAIL ),
1017
+                    'http://schema.org/email'
1018
+                ),
1019
+                // ### schema:telephone.
1020
+                $this->rendition_factory->create(
1021
+                    $this->storage_factory->post_meta( self::FIELD_TELEPHONE ),
1022
+                    'http://schema.org/telephone'
1023
+                ),
1024
+            ),
1025
+            'templates'     => array(
1026
+                'subtitle' => '{{id}}',
1027
+            ),
1028
+        );
1029
+
1030
+        // Merge the custom fields with those provided by the thing schema.
1031
+        $parent_schema           = $this->get_thing_schema();
1032
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1033
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1034
+
1035
+        return $schema;
1036
+    }
1037
+
1038
+    /**
1039
+     * Get the 'person' schema.
1040
+     *
1041
+     * @return array An array with the schema configuration.
1042
+     *
1043
+     * @since 3.1.0
1044
+     */
1045
+    private function get_person_schema() {
1046
+
1047
+        $schema = array(
1048
+            'label'         => 'Person',
1049
+            'description'   => 'A person (or a music artist).',
1050
+            'parents'       => array( 'thing' ),
1051
+            'css_class'     => 'wl-person',
1052
+            'uri'           => 'http://schema.org/Person',
1053
+            'same_as'       => array(
1054
+                'http://rdf.freebase.com/ns/people.person',
1055
+                'http://rdf.freebase.com/ns/music.artist',
1056
+                'http://dbpedia.org/class/yago/LivingPeople',
1057
+            ),
1058
+            'custom_fields' => array(
1059
+                self::FIELD_KNOWS       => array(
1060
+                    'predicate'   => 'http://schema.org/knows',
1061
+                    'type'        => self::DATA_TYPE_URI,
1062
+                    'export_type' => 'http://schema.org/Person',
1063
+                    'constraints' => array(
1064
+                        'uri_type'    => 'Person',
1065
+                        'cardinality' => INF,
1066
+                    ),
1067
+                ),
1068
+                self::FIELD_BIRTH_DATE  => array(
1069
+                    'predicate'   => 'http://schema.org/birthDate',
1070
+                    'type'        => self::DATA_TYPE_DATE,
1071
+                    'export_type' => 'xsd:date',
1072
+                    'constraints' => '',
1073
+                ),
1074
+                self::FIELD_BIRTH_PLACE => array(
1075
+                    'predicate'   => 'http://schema.org/birthPlace',
1076
+                    'type'        => self::DATA_TYPE_URI,
1077
+                    'export_type' => 'http://schema.org/Place',
1078
+                    'constraints' => array(
1079
+                        'uri_type' => 'Place',
1080
+                    ),
1081
+                ),
1082
+                self::FIELD_AFFILIATION => array(
1083
+                    'predicate'   => 'http://schema.org/affiliation',
1084
+                    'type'        => self::DATA_TYPE_URI,
1085
+                    'export_type' => 'http://schema.org/Organization',
1086
+                    'constraints' => array(
1087
+                        'uri_type'    => array(
1088
+                            'Organization',
1089
+                            'LocalBusiness',
1090
+                        ),
1091
+                        'cardinality' => INF,
1092
+                    ),
1093
+                ),
1094
+                self::FIELD_EMAIL       => array(
1095
+                    'predicate'   => 'http://schema.org/email',
1096
+                    'type'        => self::DATA_TYPE_STRING,
1097
+                    'export_type' => 'xsd:string',
1098
+                    'constraints' => array(
1099
+                        'cardinality' => INF,
1100
+                    ),
1101
+                ),
1102
+            ),
1103
+            'linked_data'   => array(
1104
+                // ### schema:knows.
1105
+                $this->rendition_factory->create(
1106
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_KNOWS ),
1107
+                    'http://schema.org/knows',
1108
+                    self::DATA_TYPE_URI
1109
+                ),
1110
+                // ### schema:birthDate.
1111
+                $this->rendition_factory->create(
1112
+                    $this->storage_factory->post_meta( self::FIELD_BIRTH_DATE ),
1113
+                    'http://schema.org/birthDate',
1114
+                    self::DATA_TYPE_DATE
1115
+                ),
1116
+                // ### schema:birthPlace.
1117
+                $this->rendition_factory->create(
1118
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_BIRTH_PLACE ),
1119
+                    'http://schema.org/birthPlace',
1120
+                    self::DATA_TYPE_URI
1121
+                ),
1122
+                // ### schema:affiliation.
1123
+                $this->rendition_factory->create(
1124
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_AFFILIATION ),
1125
+                    'http://schema.org/affiliation',
1126
+                    self::DATA_TYPE_URI
1127
+                ),
1128
+                // ### schema:email.
1129
+                $this->rendition_factory->create(
1130
+                    $this->storage_factory->post_meta( self::FIELD_EMAIL ),
1131
+                    'http://schema.org/email'
1132
+                ),
1133
+            ),
1134
+            'templates'     => array(
1135
+                'subtitle' => '{{id}}',
1136
+            ),
1137
+        );
1138
+
1139
+        // Merge the custom fields with those provided by the thing schema.
1140
+        $parent_schema           = $this->get_thing_schema();
1141
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1142
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1143
+
1144
+        return $schema;
1145
+
1146
+    }
1147
+
1148
+    /**
1149
+     * Get the 'place' schema.
1150
+     *
1151
+     * @return array An array with the schema configuration.
1152
+     *
1153
+     * @since 3.1.0
1154
+     */
1155
+    private function get_place_schema() {
1156
+
1157
+        $schema = array(
1158
+            'label'         => 'Place',
1159
+            'description'   => 'A place.',
1160
+            'parents'       => array( 'thing' ),
1161
+            'css_class'     => 'wl-place',
1162
+            'uri'           => 'http://schema.org/Place',
1163
+            'same_as'       => array(
1164
+                'http://rdf.freebase.com/ns/location.location',
1165
+                'http://www.opengis.net/gml/_Feature',
1166
+            ),
1167
+            'custom_fields' => array(
1168
+                self::FIELD_GEO_LATITUDE        => array(
1169
+                    'predicate'   => 'http://schema.org/latitude',
1170
+                    'type'        => self::DATA_TYPE_DOUBLE,
1171
+                    'export_type' => 'xsd:double',
1172
+                    'constraints' => '',
1173
+                    // To build custom metabox.
1174
+                    'input_field' => 'coordinates',
1175
+                ),
1176
+                self::FIELD_GEO_LONGITUDE       => array(
1177
+                    'predicate'   => 'http://schema.org/longitude',
1178
+                    'type'        => self::DATA_TYPE_DOUBLE,
1179
+                    'export_type' => 'xsd:double',
1180
+                    'constraints' => '',
1181
+                    // To build custom metabox.
1182
+                    'input_field' => 'coordinates',
1183
+                ),
1184
+                self::FIELD_ADDRESS             => array(
1185
+                    'predicate'   => 'http://schema.org/streetAddress',
1186
+                    'type'        => self::DATA_TYPE_STRING,
1187
+                    'export_type' => 'xsd:string',
1188
+                    'constraints' => '',
1189
+                    // To build custom metabox.
1190
+                    'input_field' => 'address',
1191
+                ),
1192
+                self::FIELD_ADDRESS_PO_BOX      => array(
1193
+                    'predicate'   => 'http://schema.org/postOfficeBoxNumber',
1194
+                    'type'        => self::DATA_TYPE_STRING,
1195
+                    'export_type' => 'xsd:string',
1196
+                    'constraints' => '',
1197
+                    // To build custom metabox.
1198
+                    'input_field' => 'address',
1199
+                ),
1200
+                self::FIELD_ADDRESS_POSTAL_CODE => array(
1201
+                    'predicate'   => 'http://schema.org/postalCode',
1202
+                    'type'        => self::DATA_TYPE_STRING,
1203
+                    'export_type' => 'xsd:string',
1204
+                    'constraints' => '',
1205
+                    // To build custom metabox.
1206
+                    'input_field' => 'address',
1207
+                ),
1208
+                self::FIELD_ADDRESS_LOCALITY    => array(
1209
+                    'predicate'   => 'http://schema.org/addressLocality',
1210
+                    'type'        => self::DATA_TYPE_STRING,
1211
+                    'export_type' => 'xsd:string',
1212
+                    'constraints' => '',
1213
+                    // To build custom metabox.
1214
+                    'input_field' => 'address',
1215
+                ),
1216
+                self::FIELD_ADDRESS_REGION      => array(
1217
+                    'predicate'   => 'http://schema.org/addressRegion',
1218
+                    'type'        => self::DATA_TYPE_STRING,
1219
+                    'export_type' => 'xsd:string',
1220
+                    'constraints' => '',
1221
+                    // To build custom metabox.
1222
+                    'input_field' => 'address',
1223
+                ),
1224
+                self::FIELD_ADDRESS_COUNTRY     => array(
1225
+                    'predicate'   => 'http://schema.org/addressCountry',
1226
+                    'type'        => self::DATA_TYPE_STRING,
1227
+                    'export_type' => 'xsd:string',
1228
+                    'constraints' => '',
1229
+                    // To build custom metabox.
1230
+                    'input_field' => 'address',
1231
+                ),
1232
+            ),
1233
+            'linked_data'   => array(
1234
+                $this->rendition_factory->create_address(
1235
+                    $this->storage_factory,
1236
+                    $this->language_code
1237
+                ),
1238
+            ),
1239
+            'templates'     => array(
1240
+                'subtitle' => '{{id}}',
1241
+            ),
1242
+        );
1243
+
1244
+        // Merge the custom fields with those provided by the thing schema.
1245
+        $parent_schema           = $this->get_thing_schema();
1246
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1247
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1248
+
1249
+        return $schema;
1250
+    }
1251
+
1252
+    /**
1253
+     * Get the 'local business' schema.
1254
+     *
1255
+     * @return array An array with the schema configuration.
1256
+     *
1257
+     * @since 3.1.0
1258
+     */
1259
+    private function get_local_business_schema() {
1260
+
1261
+        $schema = array(
1262
+            'label'         => 'LocalBusiness',
1263
+            'description'   => 'A local business.',
1264
+            'parents'       => array( 'place', 'organization' ),
1265
+            'css_class'     => 'wl-local-business',
1266
+            'uri'           => 'http://schema.org/LocalBusiness',
1267
+            'same_as'       => array(
1268
+                'http://rdf.freebase.com/ns/business/business_location',
1269
+                'https://schema.org/Store',
1270
+            ),
1271
+            'custom_fields' => array(),
1272
+            'linked_data'   => array(),
1273
+            'templates'     => array(
1274
+                'subtitle' => '{{id}}',
1275
+            ),
1276
+        );
1277
+
1278
+        // Merge the custom fields with those provided by the place and organization schema.
1279
+        $place_schema            = $this->get_place_schema();
1280
+        $organization_schema     = $this->get_organization_schema();
1281
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
1282
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $place_schema['linked_data'], $organization_schema['linked_data'] );
1283
+
1284
+        return $schema;
1285
+    }
1286
+
1287
+    /**
1288
+     * Get the 'recipe' schema.
1289
+     *
1290
+     * @return array An array with the schema configuration.
1291
+     *
1292
+     * @since 3.14.0
1293
+     */
1294
+    private function get_recipe_schema() {
1295
+
1296
+        $schema = array(
1297
+            'label'         => 'Recipe',
1298
+            'description'   => 'A Recipe.',
1299
+            'parents'       => array( 'CreativeWork' ),
1300
+            'css_class'     => 'wl-recipe',
1301
+            'uri'           => 'http://schema.org/Recipe',
1302
+            'same_as'       => array(),
1303
+            'templates'     => array(
1304
+                'subtitle' => '{{id}}',
1305
+            ),
1306
+            'custom_fields' => array(
1307
+                self::FIELD_RECIPE_CUISINE          => array(
1308
+                    'predicate'   => 'http://schema.org/recipeCuisine',
1309
+                    'type'        => self::DATA_TYPE_STRING,
1310
+                    'export_type' => 'xsd:string',
1311
+                    'constraints' => '',
1312
+                    'metabox'     => array(
1313
+                        'label' => __( 'Recipe cuisine', 'wordlift' ),
1314
+                    ),
1315
+                ),
1316
+                self::FIELD_RECIPE_INGREDIENT       => array(
1317
+                    'predicate'   => 'http://schema.org/recipeIngredient',
1318
+                    'type'        => self::DATA_TYPE_STRING,
1319
+                    'export_type' => 'xsd:string',
1320
+                    'constraints' => array(
1321
+                        'cardinality' => INF,
1322
+                    ),
1323
+                    'metabox'     => array(
1324
+                        'label' => __( 'Recipe ingredient', 'wordlift' ),
1325
+                    ),
1326
+                ),
1327
+                self::FIELD_RECIPE_INSTRUCTIONS     => array(
1328
+                    'predicate'   => 'http://schema.org/recipeInstructions',
1329
+                    'type'        => self::DATA_TYPE_MULTILINE,
1330
+                    'export_type' => 'xsd:string',
1331
+                    'constraints' => '',
1332
+                    'metabox'     => array(
1333
+                        'class' => 'Wordlift_Metabox_Field_Multiline',
1334
+                        'label' => __( 'Recipe instructions', 'wordlift' ),
1335
+                    ),
1336
+                ),
1337
+                self::FIELD_RECIPE_YIELD            => array(
1338
+                    'predicate'   => 'http://schema.org/recipeYield',
1339
+                    'type'        => self::DATA_TYPE_STRING,
1340
+                    'export_type' => 'xsd:string',
1341
+                    'constraints' => '',
1342
+                    'metabox'     => array(
1343
+                        'label' => __( 'Recipe number of servings', 'wordlift' ),
1344
+                    ),
1345
+                ),
1346
+                self::FIELD_RECIPE_INGREDIENT       => array(
1347
+                    'predicate'   => 'http://schema.org/recipeIngredient',
1348
+                    'type'        => self::DATA_TYPE_STRING,
1349
+                    'export_type' => 'xsd:string',
1350
+                    'constraints' => array(
1351
+                        'cardinality' => INF,
1352
+                    ),
1353
+                    'metabox'     => array(
1354
+                        'label' => __( 'Recipe ingredient', 'wordlift' ),
1355
+                    ),
1356
+                ),
1357
+                self::FIELD_NUTRITION_INFO_CALORIES => array(
1358
+                    'predicate'   => 'http://schema.org/calories',
1359
+                    'type'        => self::DATA_TYPE_STRING,
1360
+                    'export_type' => 'xsd:string',
1361
+                    'constraints' => '',
1362
+                    'metabox'     => array(
1363
+                        'label' => __( 'Calories (e.g. 240 calories)', 'wordlift' ),
1364
+                    ),
1365
+                ),
1366
+                self::FIELD_PREP_TIME               => array(
1367
+                    'predicate'   => 'http://schema.org/prepTime',
1368
+                    'type'        => self::DATA_TYPE_DURATION,
1369
+                    'export_type' => 'xsd:time',
1370
+                    'constraints' => '',
1371
+                    'metabox'     => array(
1372
+                        'class' => 'Wordlift_Metabox_Field_Duration',
1373
+                        'label' => __( 'Recipe preparation time (e.g. 1:30)', 'wordlift' ),
1374
+                    ),
1375
+                ),
1376
+                self::FIELD_COOK_TIME               => array(
1377
+                    'predicate'   => 'http://schema.org/cookTime',
1378
+                    'type'        => self::DATA_TYPE_DURATION,
1379
+                    'export_type' => 'xsd:time',
1380
+                    'constraints' => '',
1381
+                    'metabox'     => array(
1382
+                        'class' => 'Wordlift_Metabox_Field_Duration',
1383
+                        'label' => __( 'Recipe cook time (e.g. 1:30)', 'wordlift' ),
1384
+                    ),
1385
+                ),
1386
+                self::FIELD_TOTAL_TIME              => array(
1387
+                    'predicate'   => 'http://schema.org/totalTime',
1388
+                    'type'        => self::DATA_TYPE_DURATION,
1389
+                    'export_type' => 'xsd:time',
1390
+                    'constraints' => '',
1391
+                    'metabox'     => array(
1392
+                        'class' => 'Wordlift_Metabox_Field_Duration',
1393
+                        'label' => __( 'Recipe total time (e.g. 1:30)', 'wordlift' ),
1394
+                    ),
1395
+                ),
1396
+            ),
1397
+            'linked_data'   => array(
1398
+                // ### schema:recipeCuisine.
1399
+                $this->rendition_factory->create(
1400
+                    $this->storage_factory->post_meta( self::FIELD_RECIPE_CUISINE ),
1401
+                    'http://schema.org/recipeCuisine'
1402
+                ),
1403
+                // ### schema:recipeIngredient.
1404
+                $this->rendition_factory->create(
1405
+                    $this->storage_factory->post_meta( self::FIELD_RECIPE_INGREDIENT ),
1406
+                    'http://schema.org/recipeIngredient'
1407
+                ),
1408
+                // ### schema:prepTime.
1409
+                $this->rendition_factory->create(
1410
+                    $this->storage_factory->post_meta( self::FIELD_PREP_TIME ),
1411
+                    'http://schema.org/prepTime',
1412
+                    self::DATA_TYPE_DURATION
1413
+                ),
1414
+                // ### schema:cookTime.
1415
+                $this->rendition_factory->create(
1416
+                    $this->storage_factory->post_meta( self::FIELD_COOK_TIME ),
1417
+                    'http://schema.org/cookTime',
1418
+                    self::DATA_TYPE_DURATION
1419
+                ),
1420
+                // ### schema:totalTime.
1421
+                $this->rendition_factory->create(
1422
+                    $this->storage_factory->post_meta( self::FIELD_TOTAL_TIME ),
1423
+                    'http://schema.org/totalTime',
1424
+                    self::DATA_TYPE_DURATION
1425
+                ),
1426
+            ),
1427
+        );
1428
+
1429
+        // Merge the custom fields with those provided by the parent schema.
1430
+        $parent_schema           = $this->get_creative_work_schema();
1431
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1432
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1433
+
1434
+        return $schema;
1435
+    }
1436
+
1437
+    /**
1438
+     * Get the 'offer' schema.
1439
+     *
1440
+     * @return array An array with the schema configuration.
1441
+     *
1442
+     * @since 3.18.0
1443
+     */
1444
+    private function get_offer_schema() {
1445
+
1446
+        $schema = array(
1447
+            'label'         => 'Offer',
1448
+            'description'   => 'An offer. ',
1449
+            'parents'       => array( 'thing' ),
1450
+            'css_class'     => 'wl-offer',
1451
+            'uri'           => self::SCHEMA_OFFER_TYPE,
1452
+            'same_as'       => array(),
1453
+            'templates'     => array(
1454
+                'subtitle' => '{{id}}',
1455
+            ),
1456
+            'custom_fields' => array(
1457
+                self::FIELD_AVAILABILITY => array(
1458
+                    'predicate'   => 'http://schema.org/availability',
1459
+                    'type'        => self::DATA_TYPE_STRING,
1460
+                    'export_type' => 'xsd:string',
1461
+                    'metabox'     => array(
1462
+                        'class' => 'Wordlift_Metabox_Field_Select',
1463
+                    ),
1464
+                    'options' => array(
1465
+                        'Discontinued'        => esc_html__( 'Discontinued', 'wordlift' ),
1466
+                        'InStock'             => esc_html__( 'In Stock', 'wordlift' ),
1467
+                        'InStoreOnly'         => esc_html__( 'In Store Only', 'wordlift' ),
1468
+                        'LimitedAvailability' => esc_html__( 'Limited Availability', 'wordlift' ),
1469
+                        'OnlineOnly'          => esc_html__( 'Online Only', 'wordlift' ),
1470
+                        'OutOfStock'          => esc_html__( 'Out of Stock', 'wordlift' ),
1471
+                        'PreOrder'            => esc_html__( 'Pre Order', 'wordlift' ),
1472
+                        'PreSale'             => esc_html__( 'Pre Sale', 'wordlift' ),
1473
+                        'SoldOut'             => esc_html__( 'Sold Out', 'wordlift' ),
1474
+                    ),
1475
+                ),
1476
+                self::FIELD_PRICE => array(
1477
+                    'predicate'   => 'http://schema.org/price',
1478
+                    'type'        => self::DATA_TYPE_STRING,
1479
+                    'export_type' => 'xsd:integer',
1480
+                    'metabox'     => array(
1481
+                        'class' => 'Wordlift_Metabox_Field_Integer',
1482
+                    ),
1483
+                ),
1484
+                self::FIELD_PRICE_CURRENCY => array(
1485
+                    'predicate'   => 'http://schema.org/priceCurrency',
1486
+                    'type'        => self::DATA_TYPE_STRING,
1487
+                    'export_type' => 'xsd:string',
1488
+                ),
1489
+                self::FIELD_AVAILABILITY_STARTS => array(
1490
+                    'predicate'   => 'http://schema.org/availabilityStarts',
1491
+                    'type'        => self::DATA_TYPE_DATE,
1492
+                    'export_type' => 'xsd:dateTime',
1493
+                ),
1494
+                self::FIELD_AVAILABILITY_ENDS => array(
1495
+                    'predicate'   => 'http://schema.org/availabilityEnds',
1496
+                    'type'        => self::DATA_TYPE_DATE,
1497
+                    'export_type' => 'xsd:dateTime',
1498
+                ),
1499
+                self::FIELD_INVENTORY_LEVEL => array(
1500
+                    'predicate'   => 'http://schema.org/inventoryLevel',
1501
+                    'type'        => self::DATA_TYPE_STRING,
1502
+                    'export_type' => 'xsd:integer',
1503
+                    'metabox'     => array(
1504
+                        'class' => 'Wordlift_Metabox_Field_Integer',
1505
+                    ),
1506
+                ),
1507
+                self::FIELD_VALID_FROM => array(
1508
+                    'predicate'   => 'http://schema.org/validFrom',
1509
+                    'type'        => self::DATA_TYPE_DATE,
1510
+                    'export_type' => 'xsd:dateTime',
1511
+                ),
1512
+                self::FIELD_PRICE_VALID_UNTIL => array(
1513
+                    'predicate'   => 'http://schema.org/priceValidUntil',
1514
+                    'type'        => self::DATA_TYPE_DATE,
1515
+                    'export_type' => 'xsd:dateTime',
1516
+                ),
1517
+                self::FIELD_ITEM_OFFERED => array(
1518
+                    'predicate'   => 'http://schema.org/itemOffered',
1519
+                    'type'        => self::DATA_TYPE_URI,
1520
+                    'export_type' => 'http://schema.org/Thing',
1521
+                    'constraints' => array(
1522
+                        'uri_type'    => array(
1523
+                            'Event',
1524
+                            'Thing',
1525
+                        ),
1526
+                        'cardinality' => INF,
1527
+                    ),
1528
+                ),
1529
+            ),
1530
+            'linked_data' => array(
1531
+                // ### schema:availability.
1532
+                $this->rendition_factory->create(
1533
+                    $this->storage_factory->post_meta( self::FIELD_AVAILABILITY ),
1534
+                    'http://schema.org/availability',
1535
+                    null
1536
+                ),
1537
+                // ### schema:availabilityStarts.
1538
+                $this->rendition_factory->create(
1539
+                    $this->storage_factory->post_meta( self::FIELD_AVAILABILITY_STARTS ),
1540
+                    'http://schema.org/availabilityStarts',
1541
+                    self::DATA_TYPE_DATE_TIME
1542
+                ),
1543
+                // ### schema:availabilityEnds.
1544
+                $this->rendition_factory->create(
1545
+                    $this->storage_factory->post_meta( self::FIELD_AVAILABILITY_ENDS ),
1546
+                    'http://schema.org/availabilityEnds',
1547
+                    self::DATA_TYPE_DATE_TIME
1548
+                ),
1549
+                // ### schema:inventoryLevel.
1550
+                $this->rendition_factory->create(
1551
+                    $this->storage_factory->post_meta( self::FIELD_INVENTORY_LEVEL ),
1552
+                    'http://schema.org/inventoryLevel',
1553
+                    self::DATA_TYPE_INTEGER
1554
+                ),
1555
+                // ### schema:price.
1556
+                $this->rendition_factory->create(
1557
+                    $this->storage_factory->post_meta( self::FIELD_PRICE ),
1558
+                    'http://schema.org/price',
1559
+                    self::DATA_TYPE_INTEGER
1560
+                ),
1561
+                // ### schema:priceCurrency.
1562
+                $this->rendition_factory->create(
1563
+                    $this->storage_factory->post_meta( self::FIELD_PRICE_CURRENCY ),
1564
+                    'http://schema.org/priceCurrency',
1565
+                    null
1566
+                ),
1567
+                // ### schema:validFrom.
1568
+                $this->rendition_factory->create(
1569
+                    $this->storage_factory->post_meta( self::FIELD_VALID_FROM ),
1570
+                    'http://schema.org/validFrom',
1571
+                    null
1572
+                ),
1573
+                // ### schema:priceValidUntil.
1574
+                $this->rendition_factory->create(
1575
+                    $this->storage_factory->post_meta( self::FIELD_PRICE_VALID_UNTIL ),
1576
+                    'http://schema.org/priceValidUntil',
1577
+                    null
1578
+                ),
1579
+                // ### schema:itemOffered.
1580
+                $this->rendition_factory->create(
1581
+                    $this->storage_factory->post_meta_to_uri( self::FIELD_ITEM_OFFERED ),
1582
+                    'http://schema.org/itemOffered',
1583
+                    self::DATA_TYPE_URI
1584
+                ),
1585
+            ),
1586
+        );
1587
+
1588
+        // Merge the custom fields with those provided by the thing schema.
1589
+        $parent_schema           = $this->get_thing_schema();
1590
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1591
+        $schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1592
+
1593
+        return $schema;
1594
+    }
1595
+
1596
+    /**
1597
+     * Get the 'article' schema.
1598
+     *
1599
+     * @return array An array with the schema configuration.
1600
+     *
1601
+     * @since 3.15.0
1602
+     */
1603
+    private function get_article_schema() {
1604
+
1605
+        $schema = array(
1606
+            'label'         => 'Article',
1607
+            'description'   => 'An Article.',
1608
+            'parents'       => array(),
1609
+            'css_class'     => 'wl-article',
1610
+            'uri'           => 'http://schema.org/Article',
1611
+            'same_as'       => array(),
1612
+            'templates'     => array(
1613
+                'subtitle' => '{{id}}',
1614
+            ),
1615
+            'custom_fields' => array(),
1616
+            'linked_data'   => array(),
1617
+        );
1618
+
1619
+        return $schema;
1620
+    }
1621 1621
 
1622 1622
 }
Please login to merge, or discard this patch.
Spacing   +94 added lines, -94 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
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
 				),
678 678
 				// ### owl:sameAs.
679 679
 				$this->rendition_factory->create(
680
-					$this->storage_factory->post_meta( self::FIELD_SAME_AS ),
680
+					$this->storage_factory->post_meta(self::FIELD_SAME_AS),
681 681
 					'http://www.w3.org/2002/07/owl#sameAs',
682 682
 					self::DATA_TYPE_URI
683 683
 				),
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
 		$schema = array(
761 761
 			'label'         => 'CreativeWork',
762 762
 			'description'   => 'A creative work (or a Music Album).',
763
-			'parents'       => array( 'thing' ),
763
+			'parents'       => array('thing'),
764 764
 			// Give term slug as parent.
765 765
 			'css_class'     => 'wl-creative-work',
766 766
 			'uri'           => 'http://schema.org/CreativeWork',
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
 					'type'        => self::DATA_TYPE_URI,
775 775
 					'export_type' => 'http://schema.org/Person',
776 776
 					'constraints' => array(
777
-						'uri_type'    => array( 'Person', 'Organization' ),
777
+						'uri_type'    => array('Person', 'Organization'),
778 778
 						'cardinality' => INF,
779 779
 					),
780 780
 				),
@@ -794,8 +794,8 @@  discard block
 block discarded – undo
794 794
 
795 795
 		// Merge the custom fields with those provided by the thing schema.
796 796
 		$parent_schema           = $this->get_thing_schema();
797
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
798
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
797
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
798
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
799 799
 
800 800
 		return $schema;
801 801
 	}
@@ -812,10 +812,10 @@  discard block
 block discarded – undo
812 812
 		$schema = array(
813 813
 			'label'         => 'Event',
814 814
 			'description'   => 'An event . ',
815
-			'parents'       => array( 'thing' ),
815
+			'parents'       => array('thing'),
816 816
 			'css_class'     => 'wl-event',
817 817
 			'uri'           => self::SCHEMA_EVENT_TYPE,
818
-			'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
818
+			'same_as'       => array('http://dbpedia.org/ontology/Event'),
819 819
 			'custom_fields' => array(
820 820
 				self::FIELD_DATE_START => array(
821 821
 					'predicate'   => 'http://schema.org/startDate',
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
 					'type'        => self::DATA_TYPE_URI,
835 835
 					'export_type' => 'http://schema.org/PostalAddress',
836 836
 					'constraints' => array(
837
-						'uri_type'    => array( 'Place', 'LocalBusiness' ),
837
+						'uri_type'    => array('Place', 'LocalBusiness'),
838 838
 						'cardinality' => INF,
839 839
 					),
840 840
 				),
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
 					'type'        => self::DATA_TYPE_URI,
844 844
 					'export_type' => 'http://schema.org/Person',
845 845
 					'constraints' => array(
846
-						'uri_type'    => array( 'Person', 'Organization' ),
846
+						'uri_type'    => array('Person', 'Organization'),
847 847
 						'cardinality' => INF,
848 848
 					),
849 849
 				),
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
 					'type'        => self::DATA_TYPE_URI,
853 853
 					'export_type' => 'http://schema.org/Offer',
854 854
 					'constraints' => array(
855
-						'uri_type'    => array( 'Offer' ),
855
+						'uri_type'    => array('Offer'),
856 856
 						'cardinality' => INF,
857 857
 					),
858 858
 				),
@@ -860,31 +860,31 @@  discard block
 block discarded – undo
860 860
 			'linked_data'   => array(
861 861
 				// ### schema:startDate.
862 862
 				$this->rendition_factory->create(
863
-					$this->storage_factory->post_meta( self::FIELD_DATE_START ),
863
+					$this->storage_factory->post_meta(self::FIELD_DATE_START),
864 864
 					'http://schema.org/startDate',
865 865
 					self::DATA_TYPE_DATE_TIME
866 866
 				),
867 867
 				// ### schema:endDate.
868 868
 				$this->rendition_factory->create(
869
-					$this->storage_factory->post_meta( self::FIELD_DATE_END ),
869
+					$this->storage_factory->post_meta(self::FIELD_DATE_END),
870 870
 					'http://schema.org/endDate',
871 871
 					self::DATA_TYPE_DATE_TIME
872 872
 				),
873 873
 				// ### schema:location.
874 874
 				$this->rendition_factory->create(
875
-					$this->storage_factory->post_meta_to_uri( self::FIELD_LOCATION ),
875
+					$this->storage_factory->post_meta_to_uri(self::FIELD_LOCATION),
876 876
 					'http://schema.org/location',
877 877
 					self::DATA_TYPE_URI
878 878
 				),
879 879
 				// ### schema:performer.
880 880
 				$this->rendition_factory->create(
881
-					$this->storage_factory->post_meta_to_uri( self::FIELD_PERFORMER ),
881
+					$this->storage_factory->post_meta_to_uri(self::FIELD_PERFORMER),
882 882
 					'http://schema.org/performer',
883 883
 					self::DATA_TYPE_URI
884 884
 				),
885 885
 				// ### schema:offers.
886 886
 				$this->rendition_factory->create(
887
-					$this->storage_factory->post_meta_to_uri( self::FIELD_OFFERS ),
887
+					$this->storage_factory->post_meta_to_uri(self::FIELD_OFFERS),
888 888
 					'http://schema.org/offers',
889 889
 					self::DATA_TYPE_URI
890 890
 				),
@@ -896,8 +896,8 @@  discard block
 block discarded – undo
896 896
 
897 897
 		// Merge the custom fields with those provided by the thing schema.
898 898
 		$parent_schema           = $this->get_thing_schema();
899
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
900
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
899
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
900
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
901 901
 
902 902
 		return $schema;
903 903
 	}
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
 		$schema = array(
915 915
 			'label'         => 'Organization',
916 916
 			'description'   => 'An organization, including a government or a newspaper.',
917
-			'parents'       => array( 'thing' ),
917
+			'parents'       => array('thing'),
918 918
 			'css_class'     => 'wl-organization',
919 919
 			'uri'           => 'http://schema.org/Organization',
920 920
 			'same_as'       => array(
@@ -1002,23 +1002,23 @@  discard block
 block discarded – undo
1002 1002
 			'linked_data'   => array(
1003 1003
 				// ### schema:legalName.
1004 1004
 				$this->rendition_factory->create(
1005
-					$this->storage_factory->post_meta( self::FIELD_LEGAL_NAME ),
1005
+					$this->storage_factory->post_meta(self::FIELD_LEGAL_NAME),
1006 1006
 					'http://schema.org/legalName'
1007 1007
 				),
1008 1008
 				// ### schema:founder.
1009 1009
 				$this->rendition_factory->create(
1010
-					$this->storage_factory->post_meta_to_uri( self::FIELD_FOUNDER ),
1010
+					$this->storage_factory->post_meta_to_uri(self::FIELD_FOUNDER),
1011 1011
 					'http://schema.org/founder',
1012 1012
 					self::DATA_TYPE_URI
1013 1013
 				),
1014 1014
 				// ### schema:email.
1015 1015
 				$this->rendition_factory->create(
1016
-					$this->storage_factory->post_meta( self::FIELD_EMAIL ),
1016
+					$this->storage_factory->post_meta(self::FIELD_EMAIL),
1017 1017
 					'http://schema.org/email'
1018 1018
 				),
1019 1019
 				// ### schema:telephone.
1020 1020
 				$this->rendition_factory->create(
1021
-					$this->storage_factory->post_meta( self::FIELD_TELEPHONE ),
1021
+					$this->storage_factory->post_meta(self::FIELD_TELEPHONE),
1022 1022
 					'http://schema.org/telephone'
1023 1023
 				),
1024 1024
 			),
@@ -1029,8 +1029,8 @@  discard block
 block discarded – undo
1029 1029
 
1030 1030
 		// Merge the custom fields with those provided by the thing schema.
1031 1031
 		$parent_schema           = $this->get_thing_schema();
1032
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1033
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1032
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
1033
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
1034 1034
 
1035 1035
 		return $schema;
1036 1036
 	}
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 		$schema = array(
1048 1048
 			'label'         => 'Person',
1049 1049
 			'description'   => 'A person (or a music artist).',
1050
-			'parents'       => array( 'thing' ),
1050
+			'parents'       => array('thing'),
1051 1051
 			'css_class'     => 'wl-person',
1052 1052
 			'uri'           => 'http://schema.org/Person',
1053 1053
 			'same_as'       => array(
@@ -1103,31 +1103,31 @@  discard block
 block discarded – undo
1103 1103
 			'linked_data'   => array(
1104 1104
 				// ### schema:knows.
1105 1105
 				$this->rendition_factory->create(
1106
-					$this->storage_factory->post_meta_to_uri( self::FIELD_KNOWS ),
1106
+					$this->storage_factory->post_meta_to_uri(self::FIELD_KNOWS),
1107 1107
 					'http://schema.org/knows',
1108 1108
 					self::DATA_TYPE_URI
1109 1109
 				),
1110 1110
 				// ### schema:birthDate.
1111 1111
 				$this->rendition_factory->create(
1112
-					$this->storage_factory->post_meta( self::FIELD_BIRTH_DATE ),
1112
+					$this->storage_factory->post_meta(self::FIELD_BIRTH_DATE),
1113 1113
 					'http://schema.org/birthDate',
1114 1114
 					self::DATA_TYPE_DATE
1115 1115
 				),
1116 1116
 				// ### schema:birthPlace.
1117 1117
 				$this->rendition_factory->create(
1118
-					$this->storage_factory->post_meta_to_uri( self::FIELD_BIRTH_PLACE ),
1118
+					$this->storage_factory->post_meta_to_uri(self::FIELD_BIRTH_PLACE),
1119 1119
 					'http://schema.org/birthPlace',
1120 1120
 					self::DATA_TYPE_URI
1121 1121
 				),
1122 1122
 				// ### schema:affiliation.
1123 1123
 				$this->rendition_factory->create(
1124
-					$this->storage_factory->post_meta_to_uri( self::FIELD_AFFILIATION ),
1124
+					$this->storage_factory->post_meta_to_uri(self::FIELD_AFFILIATION),
1125 1125
 					'http://schema.org/affiliation',
1126 1126
 					self::DATA_TYPE_URI
1127 1127
 				),
1128 1128
 				// ### schema:email.
1129 1129
 				$this->rendition_factory->create(
1130
-					$this->storage_factory->post_meta( self::FIELD_EMAIL ),
1130
+					$this->storage_factory->post_meta(self::FIELD_EMAIL),
1131 1131
 					'http://schema.org/email'
1132 1132
 				),
1133 1133
 			),
@@ -1138,8 +1138,8 @@  discard block
 block discarded – undo
1138 1138
 
1139 1139
 		// Merge the custom fields with those provided by the thing schema.
1140 1140
 		$parent_schema           = $this->get_thing_schema();
1141
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1142
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1141
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
1142
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
1143 1143
 
1144 1144
 		return $schema;
1145 1145
 
@@ -1157,7 +1157,7 @@  discard block
 block discarded – undo
1157 1157
 		$schema = array(
1158 1158
 			'label'         => 'Place',
1159 1159
 			'description'   => 'A place.',
1160
-			'parents'       => array( 'thing' ),
1160
+			'parents'       => array('thing'),
1161 1161
 			'css_class'     => 'wl-place',
1162 1162
 			'uri'           => 'http://schema.org/Place',
1163 1163
 			'same_as'       => array(
@@ -1243,8 +1243,8 @@  discard block
 block discarded – undo
1243 1243
 
1244 1244
 		// Merge the custom fields with those provided by the thing schema.
1245 1245
 		$parent_schema           = $this->get_thing_schema();
1246
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1247
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1246
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
1247
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
1248 1248
 
1249 1249
 		return $schema;
1250 1250
 	}
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
 		$schema = array(
1262 1262
 			'label'         => 'LocalBusiness',
1263 1263
 			'description'   => 'A local business.',
1264
-			'parents'       => array( 'place', 'organization' ),
1264
+			'parents'       => array('place', 'organization'),
1265 1265
 			'css_class'     => 'wl-local-business',
1266 1266
 			'uri'           => 'http://schema.org/LocalBusiness',
1267 1267
 			'same_as'       => array(
@@ -1278,8 +1278,8 @@  discard block
 block discarded – undo
1278 1278
 		// Merge the custom fields with those provided by the place and organization schema.
1279 1279
 		$place_schema            = $this->get_place_schema();
1280 1280
 		$organization_schema     = $this->get_organization_schema();
1281
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
1282
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $place_schema['linked_data'], $organization_schema['linked_data'] );
1281
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields']);
1282
+		$schema['linked_data']   = array_merge($schema['linked_data'], $place_schema['linked_data'], $organization_schema['linked_data']);
1283 1283
 
1284 1284
 		return $schema;
1285 1285
 	}
@@ -1296,7 +1296,7 @@  discard block
 block discarded – undo
1296 1296
 		$schema = array(
1297 1297
 			'label'         => 'Recipe',
1298 1298
 			'description'   => 'A Recipe.',
1299
-			'parents'       => array( 'CreativeWork' ),
1299
+			'parents'       => array('CreativeWork'),
1300 1300
 			'css_class'     => 'wl-recipe',
1301 1301
 			'uri'           => 'http://schema.org/Recipe',
1302 1302
 			'same_as'       => array(),
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
 					'export_type' => 'xsd:string',
1311 1311
 					'constraints' => '',
1312 1312
 					'metabox'     => array(
1313
-						'label' => __( 'Recipe cuisine', 'wordlift' ),
1313
+						'label' => __('Recipe cuisine', 'wordlift'),
1314 1314
 					),
1315 1315
 				),
1316 1316
 				self::FIELD_RECIPE_INGREDIENT       => array(
@@ -1321,7 +1321,7 @@  discard block
 block discarded – undo
1321 1321
 						'cardinality' => INF,
1322 1322
 					),
1323 1323
 					'metabox'     => array(
1324
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
1324
+						'label' => __('Recipe ingredient', 'wordlift'),
1325 1325
 					),
1326 1326
 				),
1327 1327
 				self::FIELD_RECIPE_INSTRUCTIONS     => array(
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
 					'constraints' => '',
1332 1332
 					'metabox'     => array(
1333 1333
 						'class' => 'Wordlift_Metabox_Field_Multiline',
1334
-						'label' => __( 'Recipe instructions', 'wordlift' ),
1334
+						'label' => __('Recipe instructions', 'wordlift'),
1335 1335
 					),
1336 1336
 				),
1337 1337
 				self::FIELD_RECIPE_YIELD            => array(
@@ -1340,7 +1340,7 @@  discard block
 block discarded – undo
1340 1340
 					'export_type' => 'xsd:string',
1341 1341
 					'constraints' => '',
1342 1342
 					'metabox'     => array(
1343
-						'label' => __( 'Recipe number of servings', 'wordlift' ),
1343
+						'label' => __('Recipe number of servings', 'wordlift'),
1344 1344
 					),
1345 1345
 				),
1346 1346
 				self::FIELD_RECIPE_INGREDIENT       => array(
@@ -1351,7 +1351,7 @@  discard block
 block discarded – undo
1351 1351
 						'cardinality' => INF,
1352 1352
 					),
1353 1353
 					'metabox'     => array(
1354
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
1354
+						'label' => __('Recipe ingredient', 'wordlift'),
1355 1355
 					),
1356 1356
 				),
1357 1357
 				self::FIELD_NUTRITION_INFO_CALORIES => array(
@@ -1360,7 +1360,7 @@  discard block
 block discarded – undo
1360 1360
 					'export_type' => 'xsd:string',
1361 1361
 					'constraints' => '',
1362 1362
 					'metabox'     => array(
1363
-						'label' => __( 'Calories (e.g. 240 calories)', 'wordlift' ),
1363
+						'label' => __('Calories (e.g. 240 calories)', 'wordlift'),
1364 1364
 					),
1365 1365
 				),
1366 1366
 				self::FIELD_PREP_TIME               => array(
@@ -1370,7 +1370,7 @@  discard block
 block discarded – undo
1370 1370
 					'constraints' => '',
1371 1371
 					'metabox'     => array(
1372 1372
 						'class' => 'Wordlift_Metabox_Field_Duration',
1373
-						'label' => __( 'Recipe preparation time (e.g. 1:30)', 'wordlift' ),
1373
+						'label' => __('Recipe preparation time (e.g. 1:30)', 'wordlift'),
1374 1374
 					),
1375 1375
 				),
1376 1376
 				self::FIELD_COOK_TIME               => array(
@@ -1380,7 +1380,7 @@  discard block
 block discarded – undo
1380 1380
 					'constraints' => '',
1381 1381
 					'metabox'     => array(
1382 1382
 						'class' => 'Wordlift_Metabox_Field_Duration',
1383
-						'label' => __( 'Recipe cook time (e.g. 1:30)', 'wordlift' ),
1383
+						'label' => __('Recipe cook time (e.g. 1:30)', 'wordlift'),
1384 1384
 					),
1385 1385
 				),
1386 1386
 				self::FIELD_TOTAL_TIME              => array(
@@ -1390,36 +1390,36 @@  discard block
 block discarded – undo
1390 1390
 					'constraints' => '',
1391 1391
 					'metabox'     => array(
1392 1392
 						'class' => 'Wordlift_Metabox_Field_Duration',
1393
-						'label' => __( 'Recipe total time (e.g. 1:30)', 'wordlift' ),
1393
+						'label' => __('Recipe total time (e.g. 1:30)', 'wordlift'),
1394 1394
 					),
1395 1395
 				),
1396 1396
 			),
1397 1397
 			'linked_data'   => array(
1398 1398
 				// ### schema:recipeCuisine.
1399 1399
 				$this->rendition_factory->create(
1400
-					$this->storage_factory->post_meta( self::FIELD_RECIPE_CUISINE ),
1400
+					$this->storage_factory->post_meta(self::FIELD_RECIPE_CUISINE),
1401 1401
 					'http://schema.org/recipeCuisine'
1402 1402
 				),
1403 1403
 				// ### schema:recipeIngredient.
1404 1404
 				$this->rendition_factory->create(
1405
-					$this->storage_factory->post_meta( self::FIELD_RECIPE_INGREDIENT ),
1405
+					$this->storage_factory->post_meta(self::FIELD_RECIPE_INGREDIENT),
1406 1406
 					'http://schema.org/recipeIngredient'
1407 1407
 				),
1408 1408
 				// ### schema:prepTime.
1409 1409
 				$this->rendition_factory->create(
1410
-					$this->storage_factory->post_meta( self::FIELD_PREP_TIME ),
1410
+					$this->storage_factory->post_meta(self::FIELD_PREP_TIME),
1411 1411
 					'http://schema.org/prepTime',
1412 1412
 					self::DATA_TYPE_DURATION
1413 1413
 				),
1414 1414
 				// ### schema:cookTime.
1415 1415
 				$this->rendition_factory->create(
1416
-					$this->storage_factory->post_meta( self::FIELD_COOK_TIME ),
1416
+					$this->storage_factory->post_meta(self::FIELD_COOK_TIME),
1417 1417
 					'http://schema.org/cookTime',
1418 1418
 					self::DATA_TYPE_DURATION
1419 1419
 				),
1420 1420
 				// ### schema:totalTime.
1421 1421
 				$this->rendition_factory->create(
1422
-					$this->storage_factory->post_meta( self::FIELD_TOTAL_TIME ),
1422
+					$this->storage_factory->post_meta(self::FIELD_TOTAL_TIME),
1423 1423
 					'http://schema.org/totalTime',
1424 1424
 					self::DATA_TYPE_DURATION
1425 1425
 				),
@@ -1428,8 +1428,8 @@  discard block
 block discarded – undo
1428 1428
 
1429 1429
 		// Merge the custom fields with those provided by the parent schema.
1430 1430
 		$parent_schema           = $this->get_creative_work_schema();
1431
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1432
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1431
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
1432
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
1433 1433
 
1434 1434
 		return $schema;
1435 1435
 	}
@@ -1446,7 +1446,7 @@  discard block
 block discarded – undo
1446 1446
 		$schema = array(
1447 1447
 			'label'         => 'Offer',
1448 1448
 			'description'   => 'An offer. ',
1449
-			'parents'       => array( 'thing' ),
1449
+			'parents'       => array('thing'),
1450 1450
 			'css_class'     => 'wl-offer',
1451 1451
 			'uri'           => self::SCHEMA_OFFER_TYPE,
1452 1452
 			'same_as'       => array(),
@@ -1462,15 +1462,15 @@  discard block
 block discarded – undo
1462 1462
 						'class' => 'Wordlift_Metabox_Field_Select',
1463 1463
 					),
1464 1464
 					'options' => array(
1465
-						'Discontinued'        => esc_html__( 'Discontinued', 'wordlift' ),
1466
-						'InStock'             => esc_html__( 'In Stock', 'wordlift' ),
1467
-						'InStoreOnly'         => esc_html__( 'In Store Only', 'wordlift' ),
1468
-						'LimitedAvailability' => esc_html__( 'Limited Availability', 'wordlift' ),
1469
-						'OnlineOnly'          => esc_html__( 'Online Only', 'wordlift' ),
1470
-						'OutOfStock'          => esc_html__( 'Out of Stock', 'wordlift' ),
1471
-						'PreOrder'            => esc_html__( 'Pre Order', 'wordlift' ),
1472
-						'PreSale'             => esc_html__( 'Pre Sale', 'wordlift' ),
1473
-						'SoldOut'             => esc_html__( 'Sold Out', 'wordlift' ),
1465
+						'Discontinued'        => esc_html__('Discontinued', 'wordlift'),
1466
+						'InStock'             => esc_html__('In Stock', 'wordlift'),
1467
+						'InStoreOnly'         => esc_html__('In Store Only', 'wordlift'),
1468
+						'LimitedAvailability' => esc_html__('Limited Availability', 'wordlift'),
1469
+						'OnlineOnly'          => esc_html__('Online Only', 'wordlift'),
1470
+						'OutOfStock'          => esc_html__('Out of Stock', 'wordlift'),
1471
+						'PreOrder'            => esc_html__('Pre Order', 'wordlift'),
1472
+						'PreSale'             => esc_html__('Pre Sale', 'wordlift'),
1473
+						'SoldOut'             => esc_html__('Sold Out', 'wordlift'),
1474 1474
 					),
1475 1475
 				),
1476 1476
 				self::FIELD_PRICE => array(
@@ -1530,55 +1530,55 @@  discard block
 block discarded – undo
1530 1530
 			'linked_data' => array(
1531 1531
 				// ### schema:availability.
1532 1532
 				$this->rendition_factory->create(
1533
-					$this->storage_factory->post_meta( self::FIELD_AVAILABILITY ),
1533
+					$this->storage_factory->post_meta(self::FIELD_AVAILABILITY),
1534 1534
 					'http://schema.org/availability',
1535 1535
 					null
1536 1536
 				),
1537 1537
 				// ### schema:availabilityStarts.
1538 1538
 				$this->rendition_factory->create(
1539
-					$this->storage_factory->post_meta( self::FIELD_AVAILABILITY_STARTS ),
1539
+					$this->storage_factory->post_meta(self::FIELD_AVAILABILITY_STARTS),
1540 1540
 					'http://schema.org/availabilityStarts',
1541 1541
 					self::DATA_TYPE_DATE_TIME
1542 1542
 				),
1543 1543
 				// ### schema:availabilityEnds.
1544 1544
 				$this->rendition_factory->create(
1545
-					$this->storage_factory->post_meta( self::FIELD_AVAILABILITY_ENDS ),
1545
+					$this->storage_factory->post_meta(self::FIELD_AVAILABILITY_ENDS),
1546 1546
 					'http://schema.org/availabilityEnds',
1547 1547
 					self::DATA_TYPE_DATE_TIME
1548 1548
 				),
1549 1549
 				// ### schema:inventoryLevel.
1550 1550
 				$this->rendition_factory->create(
1551
-					$this->storage_factory->post_meta( self::FIELD_INVENTORY_LEVEL ),
1551
+					$this->storage_factory->post_meta(self::FIELD_INVENTORY_LEVEL),
1552 1552
 					'http://schema.org/inventoryLevel',
1553 1553
 					self::DATA_TYPE_INTEGER
1554 1554
 				),
1555 1555
 				// ### schema:price.
1556 1556
 				$this->rendition_factory->create(
1557
-					$this->storage_factory->post_meta( self::FIELD_PRICE ),
1557
+					$this->storage_factory->post_meta(self::FIELD_PRICE),
1558 1558
 					'http://schema.org/price',
1559 1559
 					self::DATA_TYPE_INTEGER
1560 1560
 				),
1561 1561
 				// ### schema:priceCurrency.
1562 1562
 				$this->rendition_factory->create(
1563
-					$this->storage_factory->post_meta( self::FIELD_PRICE_CURRENCY ),
1563
+					$this->storage_factory->post_meta(self::FIELD_PRICE_CURRENCY),
1564 1564
 					'http://schema.org/priceCurrency',
1565 1565
 					null
1566 1566
 				),
1567 1567
 				// ### schema:validFrom.
1568 1568
 				$this->rendition_factory->create(
1569
-					$this->storage_factory->post_meta( self::FIELD_VALID_FROM ),
1569
+					$this->storage_factory->post_meta(self::FIELD_VALID_FROM),
1570 1570
 					'http://schema.org/validFrom',
1571 1571
 					null
1572 1572
 				),
1573 1573
 				// ### schema:priceValidUntil.
1574 1574
 				$this->rendition_factory->create(
1575
-					$this->storage_factory->post_meta( self::FIELD_PRICE_VALID_UNTIL ),
1575
+					$this->storage_factory->post_meta(self::FIELD_PRICE_VALID_UNTIL),
1576 1576
 					'http://schema.org/priceValidUntil',
1577 1577
 					null
1578 1578
 				),
1579 1579
 				// ### schema:itemOffered.
1580 1580
 				$this->rendition_factory->create(
1581
-					$this->storage_factory->post_meta_to_uri( self::FIELD_ITEM_OFFERED ),
1581
+					$this->storage_factory->post_meta_to_uri(self::FIELD_ITEM_OFFERED),
1582 1582
 					'http://schema.org/itemOffered',
1583 1583
 					self::DATA_TYPE_URI
1584 1584
 				),
@@ -1587,8 +1587,8 @@  discard block
 block discarded – undo
1587 1587
 
1588 1588
 		// Merge the custom fields with those provided by the thing schema.
1589 1589
 		$parent_schema           = $this->get_thing_schema();
1590
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
1591
-		$schema['linked_data']   = array_merge( $schema['linked_data'], $parent_schema['linked_data'] );
1590
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
1591
+		$schema['linked_data']   = array_merge($schema['linked_data'], $parent_schema['linked_data']);
1592 1592
 
1593 1593
 		return $schema;
1594 1594
 	}
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-property-getter-factory.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -25,44 +25,44 @@
 block discarded – undo
25 25
  */
26 26
 class Wordlift_Property_Getter_Factory {
27 27
 
28
-	/**
29
-	 * Create a {@link Wordlift_Property_Getter} instance.
30
-	 *
31
-	 * @since 3.8.0
32
-	 *
33
-	 * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
34
-	 *
35
-	 * @return \Wordlift_Property_Getter A {@link Wordlift_Property_Getter} instance.
36
-	 */
37
-	public static function create( $entity_service ) {
28
+    /**
29
+     * Create a {@link Wordlift_Property_Getter} instance.
30
+     *
31
+     * @since 3.8.0
32
+     *
33
+     * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
34
+     *
35
+     * @return \Wordlift_Property_Getter A {@link Wordlift_Property_Getter} instance.
36
+     */
37
+    public static function create( $entity_service ) {
38 38
 
39
-		$property_getter = new Wordlift_Property_Getter( new Wordlift_Simple_Property_Service() );
40
-		$property_getter->register( new Wordlift_Entity_Property_Service( $entity_service ), array(
41
-			Wordlift_Schema_Service::FIELD_FOUNDER,
42
-			Wordlift_Schema_Service::FIELD_AUTHOR,
43
-			Wordlift_Schema_Service::FIELD_KNOWS,
44
-			Wordlift_Schema_Service::FIELD_BIRTH_PLACE,
45
-			Wordlift_Schema_Service::FIELD_AFFILIATION,
46
-			Wordlift_Schema_Service::FIELD_PERFORMER,
47
-			Wordlift_Schema_Service::FIELD_OFFERS,
48
-			Wordlift_Schema_Service::FIELD_ITEM_OFFERED,
49
-		) );
50
-		$property_getter->register( new Wordlift_Location_Property_Service( $entity_service ), array(
51
-			Wordlift_Schema_Service::FIELD_LOCATION,
52
-		) );
53
-		$property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) );
54
-		$property_getter->register( new Wordlift_Double_Property_Service(), array(
55
-			Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
56
-			Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
57
-		) );
39
+        $property_getter = new Wordlift_Property_Getter( new Wordlift_Simple_Property_Service() );
40
+        $property_getter->register( new Wordlift_Entity_Property_Service( $entity_service ), array(
41
+            Wordlift_Schema_Service::FIELD_FOUNDER,
42
+            Wordlift_Schema_Service::FIELD_AUTHOR,
43
+            Wordlift_Schema_Service::FIELD_KNOWS,
44
+            Wordlift_Schema_Service::FIELD_BIRTH_PLACE,
45
+            Wordlift_Schema_Service::FIELD_AFFILIATION,
46
+            Wordlift_Schema_Service::FIELD_PERFORMER,
47
+            Wordlift_Schema_Service::FIELD_OFFERS,
48
+            Wordlift_Schema_Service::FIELD_ITEM_OFFERED,
49
+        ) );
50
+        $property_getter->register( new Wordlift_Location_Property_Service( $entity_service ), array(
51
+            Wordlift_Schema_Service::FIELD_LOCATION,
52
+        ) );
53
+        $property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) );
54
+        $property_getter->register( new Wordlift_Double_Property_Service(), array(
55
+            Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
56
+            Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
57
+        ) );
58 58
 
59
-		$property_getter->register( new Wordlift_Duration_Property_Service(), array(
60
-			Wordlift_Schema_Service::FIELD_PREP_TIME,
61
-			Wordlift_Schema_Service::FIELD_COOK_TIME,
62
-			Wordlift_Schema_Service::FIELD_TOTAL_TIME,
63
-		) );
59
+        $property_getter->register( new Wordlift_Duration_Property_Service(), array(
60
+            Wordlift_Schema_Service::FIELD_PREP_TIME,
61
+            Wordlift_Schema_Service::FIELD_COOK_TIME,
62
+            Wordlift_Schema_Service::FIELD_TOTAL_TIME,
63
+        ) );
64 64
 
65
-		return $property_getter;
66
-	}
65
+        return $property_getter;
66
+    }
67 67
 
68 68
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
  * @subpackage Wordlift/includes/properties
8 8
  */
9 9
 
10
-require_once( 'class-wordlift-property-getter.php' );
11
-require_once( 'class-wordlift-simple-property-service.php' );
12
-require_once( 'class-wordlift-entity-property-service.php' );
13
-require_once( 'class-wordlift-location-property-service.php' );
14
-require_once( 'class-wordlift-url-property-service.php' );
15
-require_once( 'class-wordlift-double-property-service.php' );
16
-require_once( 'class-wordlift-duration-property-service.php' );
10
+require_once('class-wordlift-property-getter.php');
11
+require_once('class-wordlift-simple-property-service.php');
12
+require_once('class-wordlift-entity-property-service.php');
13
+require_once('class-wordlift-location-property-service.php');
14
+require_once('class-wordlift-url-property-service.php');
15
+require_once('class-wordlift-double-property-service.php');
16
+require_once('class-wordlift-duration-property-service.php');
17 17
 
18 18
 /**
19 19
  * A Wordlift_Property_Getter_Factory, which instantiate a configured
@@ -34,10 +34,10 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @return \Wordlift_Property_Getter A {@link Wordlift_Property_Getter} instance.
36 36
 	 */
37
-	public static function create( $entity_service ) {
37
+	public static function create($entity_service) {
38 38
 
39
-		$property_getter = new Wordlift_Property_Getter( new Wordlift_Simple_Property_Service() );
40
-		$property_getter->register( new Wordlift_Entity_Property_Service( $entity_service ), array(
39
+		$property_getter = new Wordlift_Property_Getter(new Wordlift_Simple_Property_Service());
40
+		$property_getter->register(new Wordlift_Entity_Property_Service($entity_service), array(
41 41
 			Wordlift_Schema_Service::FIELD_FOUNDER,
42 42
 			Wordlift_Schema_Service::FIELD_AUTHOR,
43 43
 			Wordlift_Schema_Service::FIELD_KNOWS,
@@ -46,21 +46,21 @@  discard block
 block discarded – undo
46 46
 			Wordlift_Schema_Service::FIELD_PERFORMER,
47 47
 			Wordlift_Schema_Service::FIELD_OFFERS,
48 48
 			Wordlift_Schema_Service::FIELD_ITEM_OFFERED,
49
-		) );
50
-		$property_getter->register( new Wordlift_Location_Property_Service( $entity_service ), array(
49
+		));
50
+		$property_getter->register(new Wordlift_Location_Property_Service($entity_service), array(
51 51
 			Wordlift_Schema_Service::FIELD_LOCATION,
52
-		) );
53
-		$property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) );
54
-		$property_getter->register( new Wordlift_Double_Property_Service(), array(
52
+		));
53
+		$property_getter->register(new Wordlift_Url_Property_Service(), array(Wordlift_Url_Property_Service::META_KEY));
54
+		$property_getter->register(new Wordlift_Double_Property_Service(), array(
55 55
 			Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
56 56
 			Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
57
-		) );
57
+		));
58 58
 
59
-		$property_getter->register( new Wordlift_Duration_Property_Service(), array(
59
+		$property_getter->register(new Wordlift_Duration_Property_Service(), array(
60 60
 			Wordlift_Schema_Service::FIELD_PREP_TIME,
61 61
 			Wordlift_Schema_Service::FIELD_COOK_TIME,
62 62
 			Wordlift_Schema_Service::FIELD_TOTAL_TIME,
63
-		) );
63
+		));
64 64
 
65 65
 		return $property_getter;
66 66
 	}
Please login to merge, or discard this patch.
src/admin/WL_Metabox/class-wordlift-metabox-field-select.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,12 +18,12 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Metabox_Field_Select extends WL_Metabox_Field {
20 20
 
21
-	/**
22
-	 * @inheritdoc
23
-	 */
24
-	public function html_input( $text ) {
25
-		@ob_start();
26
-		?>
21
+    /**
22
+     * @inheritdoc
23
+     */
24
+    public function html_input( $text ) {
25
+        @ob_start();
26
+        ?>
27 27
 		<div class="wl-input-wrapper">
28 28
 
29 29
 			<select name="wl_metaboxes[<?php echo $this->meta_name ?>]" id="<?php echo esc_attr( $this->meta_name ); ?>" style="width:88%;">
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 		</div>
41 41
 		<?php
42 42
 
43
-		$html = ob_get_clean();
44
-		return $html;
45
-	}
43
+        $html = ob_get_clean();
44
+        return $html;
45
+    }
46 46
 
47 47
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,15 +21,15 @@
 block discarded – undo
21 21
 	/**
22 22
 	 * @inheritdoc
23 23
 	 */
24
-	public function html_input( $text ) {
24
+	public function html_input($text) {
25 25
 		@ob_start();
26 26
 		?>
27 27
 		<div class="wl-input-wrapper">
28 28
 
29
-			<select name="wl_metaboxes[<?php echo $this->meta_name ?>]" id="<?php echo esc_attr( $this->meta_name ); ?>" style="width:88%;">
30
-				<?php foreach ( $this->raw_custom_field['options'] as $option => $label ): ?>
29
+			<select name="wl_metaboxes[<?php echo $this->meta_name ?>]" id="<?php echo esc_attr($this->meta_name); ?>" style="width:88%;">
30
+				<?php foreach ($this->raw_custom_field['options'] as $option => $label): ?>
31 31
 
32
-					<option value="<?php echo esc_attr( $option ); ?>" <?php selected( $text, $option ); ?>>
32
+					<option value="<?php echo esc_attr($option); ?>" <?php selected($text, $option); ?>>
33 33
 						<?php echo $label; ?>
34 34
 					</option>
35 35
 
Please login to merge, or discard this patch.
src/admin/WL_Metabox/class-wl-metabox.php 1 patch
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -7,16 +7,16 @@  discard block
 block discarded – undo
7 7
  * @subpackage Wordlift/admin/WL_Metabox
8 8
  */
9 9
 
10
-require_once( 'class-wl-metabox-field.php' );
11
-require_once( 'class-wl-metabox-field-uri.php' );
12
-require_once( 'class-wl-metabox-field-sameas.php' );
13
-require_once( 'WL_Metabox_Field_date.php' );
14
-require_once( 'WL_Metabox_Field_coordinates.php' );
15
-require_once( 'WL_Metabox_Field_address.php' );
16
-require_once( 'class-wordlift-metabox-field-duration.php' );
17
-require_once( 'class-wordlift-metabox-field-multiline.php' );
18
-require_once( 'class-wordlift-metabox-field-integer.php' );
19
-require_once( 'class-wordlift-metabox-field-select.php' );
10
+require_once('class-wl-metabox-field.php');
11
+require_once('class-wl-metabox-field-uri.php');
12
+require_once('class-wl-metabox-field-sameas.php');
13
+require_once('WL_Metabox_Field_date.php');
14
+require_once('WL_Metabox_Field_coordinates.php');
15
+require_once('WL_Metabox_Field_address.php');
16
+require_once('class-wordlift-metabox-field-duration.php');
17
+require_once('class-wordlift-metabox-field-multiline.php');
18
+require_once('class-wordlift-metabox-field-integer.php');
19
+require_once('class-wordlift-metabox-field-select.php');
20 20
 
21 21
 /**
22 22
  * Define the {@link WL_Metabox} class.
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
 	 */
53 53
 	public function __construct() {
54 54
 
55
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
55
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
56 56
 
57 57
 		// Add hooks to print metaboxes and save submitted data.
58
-		add_action( 'add_meta_boxes', array( $this, 'add_main_metabox' ) );
59
-		add_action( 'wl_linked_data_save_post', array(
58
+		add_action('add_meta_boxes', array($this, 'add_main_metabox'));
59
+		add_action('wl_linked_data_save_post', array(
60 60
 			$this,
61 61
 			'save_form_data',
62
-		) );
62
+		));
63 63
 
64 64
 		// Enqueue js and css.
65 65
 		$this->enqueue_scripts_and_styles();
@@ -73,27 +73,27 @@  discard block
 block discarded – undo
73 73
 	public function add_main_metabox() {
74 74
 
75 75
 		// Build the fields we need to print.
76
-		$this->instantiate_fields( get_the_ID() );
76
+		$this->instantiate_fields(get_the_ID());
77 77
 
78 78
 		// Bailout if there are no actual fields, we do not need a metabox in that case.
79
-		if ( empty( $this->fields ) ) {
79
+		if (empty($this->fields)) {
80 80
 			return;
81 81
 		}
82 82
 
83 83
 		// Add main metabox (will print also the inner fields).
84
-		$id    = uniqid( 'wl-metabox-' );
85
-		$title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
84
+		$id    = uniqid('wl-metabox-');
85
+		$title = get_the_title().' '.__('properties', 'wordlift');
86 86
 
87 87
 		// WordPress 4.2 do not accept an array of screens as parameter, have to do be explicit.
88
-		foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $screen ) {
89
-			add_meta_box( $id, $title, array(
88
+		foreach (Wordlift_Entity_Service::valid_entity_post_types() as $screen) {
89
+			add_meta_box($id, $title, array(
90 90
 				$this,
91 91
 				'html',
92
-			), $screen, 'normal', 'high' );
92
+			), $screen, 'normal', 'high');
93 93
 		}
94 94
 
95 95
 		// Add filter to change the metabox CSS class.
96
-		add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
96
+		add_filter("postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class');
97 97
 	}
98 98
 
99 99
 	/**
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
 	 *
104 104
 	 * @param WP_Post $post The post.
105 105
 	 */
106
-	public function html( $post ) {
106
+	public function html($post) {
107 107
 
108 108
 		// Loop over the fields.
109
-		foreach ( $this->fields as $field ) {
109
+		foreach ($this->fields as $field) {
110 110
 
111 111
 			// load data from DB (values will be available in $field->data).
112 112
 			$field->get_data();
@@ -127,18 +127,18 @@  discard block
 block discarded – undo
127 127
 	 *
128 128
 	 * @param int $post_id The post id.
129 129
 	 */
130
-	public function instantiate_fields( $post_id ) {
130
+	public function instantiate_fields($post_id) {
131 131
 
132
-		$this->log->trace( "Instantiating fields for entity post $post_id..." );
132
+		$this->log->trace("Instantiating fields for entity post $post_id...");
133 133
 
134 134
 		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
135
-		if ( isset( $this->fields ) ) {
135
+		if (isset($this->fields)) {
136 136
 			return;
137 137
 		}
138 138
 
139
-		$entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
139
+		$entity_type = wl_entity_taxonomy_get_custom_fields($post_id);
140 140
 
141
-		if ( isset( $entity_type ) ) {
141
+		if (isset($entity_type)) {
142 142
 
143 143
 			/*
144 144
 			 * Might not have any relevant meta box field, for example for articles,
@@ -153,31 +153,31 @@  discard block
 block discarded – undo
153 153
 			 * - simple: accept values for one property
154 154
 			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
155 155
 			 */
156
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
156
+			$metaboxes         = $this->group_properties_by_input_field($entity_type);
157 157
 			$simple_metaboxes  = $metaboxes[0];
158 158
 			$grouped_metaboxes = $metaboxes[1];
159 159
 
160 160
 			// Loop over simple entity properties.
161
-			foreach ( $simple_metaboxes as $key => $property ) {
161
+			foreach ($simple_metaboxes as $key => $property) {
162 162
 
163 163
 				// Info passed to the metabox.
164 164
 				$info         = array();
165
-				$info[ $key ] = $property;
165
+				$info[$key] = $property;
166 166
 
167 167
 				// Build the requested field as WL_Metabox_Field_ object.
168
-				$this->add_field( $info );
168
+				$this->add_field($info);
169 169
 
170 170
 			}
171 171
 
172 172
 			// Loop over grouped properties.
173
-			foreach ( $grouped_metaboxes as $key => $property ) {
173
+			foreach ($grouped_metaboxes as $key => $property) {
174 174
 
175 175
 				// Info passed to the metabox.
176 176
 				$info         = array();
177
-				$info[ $key ] = $property;
177
+				$info[$key] = $property;
178 178
 
179 179
 				// Build the requested field group as WL_Metabox_Field_ object.
180
-				$this->add_field( $info, true );
180
+				$this->add_field($info, true);
181 181
 
182 182
 			}
183 183
 		}
@@ -191,34 +191,34 @@  discard block
 block discarded – undo
191 191
 	 *
192 192
 	 * @return array
193 193
 	 */
194
-	public function group_properties_by_input_field( $custom_fields ) {
194
+	public function group_properties_by_input_field($custom_fields) {
195 195
 
196 196
 		$simple_properties  = array();
197 197
 		$grouped_properties = array();
198 198
 
199 199
 		// Loop over possible entity properties.
200
-		foreach ( $custom_fields as $key => $property ) {
200
+		foreach ($custom_fields as $key => $property) {
201 201
 
202 202
 			// Check presence of predicate and type.
203
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
203
+			if (isset($property['predicate']) && isset($property['type'])) {
204 204
 
205 205
 				// Check if input_field is defined.
206
-				if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) {
206
+				if (isset($property['input_field']) && '' !== $property['input_field']) {
207 207
 
208 208
 					$grouped_key = $property['input_field'];
209 209
 
210 210
 					// Update list of grouped properties.
211
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
211
+					$grouped_properties[$grouped_key][$key] = $property;
212 212
 
213 213
 				} else {
214 214
 
215 215
 					// input_field not defined, add simple metabox.
216
-					$simple_properties[ $key ] = $property;
216
+					$simple_properties[$key] = $property;
217 217
 				}
218 218
 			}
219 219
 		}
220 220
 
221
-		return array( $simple_properties, $grouped_properties );
221
+		return array($simple_properties, $grouped_properties);
222 222
 	}
223 223
 
224 224
 	/**
@@ -228,29 +228,29 @@  discard block
 block discarded – undo
228 228
 	 * @param array $args    The field's information.
229 229
 	 * @param bool  $grouped Flag to distinguish between simple and grouped fields.
230 230
 	 */
231
-	public function add_field( $args, $grouped = false ) {
231
+	public function add_field($args, $grouped = false) {
232 232
 
233
-		if ( $grouped ) {
233
+		if ($grouped) {
234 234
 
235 235
 			// Special fields (sameas, coordinates, etc.).
236 236
 			//
237 237
 			// Build Field with a custom class (e.g. WL_Metabox_Field_date).
238
-			$field_class = 'WL_Metabox_Field_' . key( $args );
238
+			$field_class = 'WL_Metabox_Field_'.key($args);
239 239
 
240 240
 		} else {
241 241
 
242 242
 			// Simple fields (string, uri, boolean, etc.).
243 243
 			//
244 244
 			// Which field? We want to use the class that is specific for the field.
245
-			$meta      = key( $args );
246
-			$this_meta = $args[ $meta ];
245
+			$meta      = key($args);
246
+			$this_meta = $args[$meta];
247 247
 
248 248
 			// If the field declares what metabox it wants, use that one.
249
-			if ( isset( $this_meta['metabox']['class'] ) ) {
249
+			if (isset($this_meta['metabox']['class'])) {
250 250
 
251 251
 				$field_class = $this_meta['metabox']['class'];
252 252
 
253
-			} elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) {
253
+			} elseif ( ! isset($this_meta['type']) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type']) {
254 254
 
255 255
 				// TODO: all fields should explicitly declare the required WL_Metabox.
256 256
 				// When they will remove this.
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 				// When they will remove this.
265 265
 				//
266 266
 				// Build Field with a custom class (e.g. WL_Metabox_Field_date).
267
-				$field_class = 'WL_Metabox_Field_' . $this_meta['type'];
267
+				$field_class = 'WL_Metabox_Field_'.$this_meta['type'];
268 268
 
269 269
 			}
270 270
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 		// End if().
273 273
 
274 274
 		// Call apropriate constructor (e.g. WL_Metabox_Field_... ).
275
-		$this->fields[] = new $field_class( $args );
275
+		$this->fields[] = new $field_class($args);
276 276
 	}
277 277
 
278 278
 	/**
@@ -282,44 +282,44 @@  discard block
 block discarded – undo
282 282
 	 *
283 283
 	 * @param int $entity_id The entity's {@link WP_Post}'s id.
284 284
 	 */
285
-	public function save_form_data( $entity_id ) {
285
+	public function save_form_data($entity_id) {
286 286
 
287
-		$this->log->trace( "Saving form data for entity post $entity_id..." );
287
+		$this->log->trace("Saving form data for entity post $entity_id...");
288 288
 
289 289
 		// Build Field objects.
290
-		$this->instantiate_fields( $entity_id );
290
+		$this->instantiate_fields($entity_id);
291 291
 
292 292
 		// Check if WL metabox form was posted.
293
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
294
-			$this->log->debug( "`wl_metaboxes`, skipping..." );
293
+		if ( ! isset($_POST['wl_metaboxes'])) {
294
+			$this->log->debug("`wl_metaboxes`, skipping...");
295 295
 
296 296
 			return;
297 297
 		}
298 298
 
299
-		foreach ( $this->fields as $field ) {
299
+		foreach ($this->fields as $field) {
300 300
 
301 301
 			// Verify nonce.
302 302
 			$valid_nonce = $field->verify_nonce();
303
-			if ( $valid_nonce ) {
303
+			if ($valid_nonce) {
304 304
 
305 305
 				$posted_data = $_POST['wl_metaboxes'];
306 306
 				$field_name  = $field->meta_name;
307 307
 
308 308
 				// Each Filed only deals with its values.
309
-				if ( isset( $posted_data[ $field_name ] ) ) {
309
+				if (isset($posted_data[$field_name])) {
310 310
 
311
-					$values = $posted_data[ $field_name ];
312
-					if ( ! is_array( $values ) ) {
313
-						$values = array( $values );
311
+					$values = $posted_data[$field_name];
312
+					if ( ! is_array($values)) {
313
+						$values = array($values);
314 314
 					}
315 315
 
316 316
 					// Save data permanently
317
-					$field->save_data( $values );
317
+					$field->save_data($values);
318 318
 				}
319 319
 			}
320 320
 		}
321 321
 
322
-		Wordlift_Linked_Data_Service::get_instance()->push( $entity_id );
322
+		Wordlift_Linked_Data_Service::get_instance()->push($entity_id);
323 323
 
324 324
 	}
325 325
 
@@ -331,20 +331,20 @@  discard block
 block discarded – undo
331 331
 	public function enqueue_scripts_and_styles() {
332 332
 
333 333
 		// Use the minified version if PW_DEBUG isn't set.
334
-		$min = ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ? '.min' : '';
334
+		$min = ! defined('WP_DEBUG') || ! WP_DEBUG ? '.min' : '';
335 335
 
336 336
 		// Load the jquery-ui-timepicker-addon library.
337
-		wp_enqueue_style( 'wl-flatpickr', dirname( plugin_dir_url( __FILE__ ) ) . "/js/flatpickr/flatpickr$min.css", array(), '3.0.6' );
338
-		wp_enqueue_script( 'wl-flatpickr', dirname( plugin_dir_url( __FILE__ ) ) . "/js/flatpickr/flatpickr$min.js", array( 'jquery' ), '3.0.6', true );
337
+		wp_enqueue_style('wl-flatpickr', dirname(plugin_dir_url(__FILE__))."/js/flatpickr/flatpickr$min.css", array(), '3.0.6');
338
+		wp_enqueue_script('wl-flatpickr', dirname(plugin_dir_url(__FILE__))."/js/flatpickr/flatpickr$min.js", array('jquery'), '3.0.6', true);
339 339
 
340 340
 		// Leaflet.
341
-		wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
342
-		wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
341
+		wp_enqueue_style('leaflet', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.css');
342
+		wp_enqueue_script('leaflet', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.js', __FILE__);
343 343
 
344 344
 		// Add AJAX autocomplete to facilitate metabox editing.
345
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
346
-		wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
347
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
345
+		wp_enqueue_script('wl-entity-metabox-utility', dirname(plugin_dir_url(__FILE__)).'/js/wl_entity_metabox_utilities.js');
346
+		wp_localize_script('wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
347
+				'ajax_url' => admin_url('admin-ajax.php'),
348 348
 				'action'   => 'entity_by_title',
349 349
 			)
350 350
 		);
Please login to merge, or discard this patch.
src/admin/WL_Metabox/class-wl-metabox-field-uri.php 2 patches
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -16,145 +16,145 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class WL_Metabox_Field_uri extends WL_Metabox_Field {
18 18
 
19
-	/**
20
-	 * Only accept URIs or local entity IDs.
21
-	 * Build new entity if the user inputted a name that is not present in DB.
22
-	 *
23
-	 * @param mixed $value The value to sanitize.
24
-	 *
25
-	 * @return int|mixed|WP_Error
26
-	 */
27
-	public function sanitize_data_filter( $value ) {
28
-
29
-		if ( empty( $value ) ) {
30
-			return null;
31
-		}
32
-
33
-		// Check that the inserted URI, ID or name does not point to a saved
34
-		// entity or when the editor types a string in the input box, we try to
35
-		// find an entity with that title and, if not found, we create that entity.
36
-		$absent_from_db = is_numeric( $value )
37
-			? is_null( get_post( $value ) )
38
-			: ! $this->exists( $value );
39
-
40
-		// Is it an URI?
41
-		$name_is_uri = strpos( $value, 'http' ) === 0;
42
-
43
-		// We create a new entity only if the entity is not present in the DB.
44
-		// In the case of an external uri, we just save the uri.
45
-		if ( $absent_from_db && ! $name_is_uri ) {
46
-
47
-			// ...we create a new entity!
48
-			$new_entity_id = wp_insert_post( array(
49
-				'post_status' => 'publish',
50
-				'post_type'   => Wordlift_Entity_Service::TYPE_NAME,
51
-				'post_title'  => $value,
52
-			) );
53
-
54
-			$type = 'http://schema.org/' . ( isset( $this->expected_uri_type ) ? $this->expected_uri_type[0] : 'Thing' );
55
-
56
-			wl_set_entity_main_type( $new_entity_id, $type );
57
-
58
-			// Build uri for this entity.
59
-			$new_uri = wl_build_entity_uri( $new_entity_id );
60
-			wl_set_entity_uri( $new_entity_id, $new_uri );
61
-
62
-			Wordlift_Linked_Data_Service::get_instance()->push( $new_entity_id );
63
-
64
-			// Update the value that will be saved as meta.
65
-			$value = $new_entity_id;
66
-		}
67
-
68
-		return $value;
69
-	}
70
-
71
-	/**
72
-	 * Check whether an entity exists given a value.
73
-	 *
74
-	 * @since 3.15.0
75
-	 *
76
-	 * @param string $value An entity URI or a title string..
77
-	 *
78
-	 * @return bool True if the entity exists otherwise false.
79
-	 */
80
-	private function exists( $value ) {
81
-
82
-		// When the editor types a string in the input box, we try to find
83
-		// an entity with that title and, if not found, we create that entity.
84
-		$entity_service = Wordlift_Entity_Service::get_instance();
85
-
86
-		// Try looking for an entity by URI.
87
-		$found_by_uri = null !== $entity_service->get_entity_post_by_uri( $value );
88
-
89
-		// Return true if found.
90
-		if ( $found_by_uri ) {
91
-			$this->log->debug( "Found entity for $value." );
92
-
93
-			return true;
94
-		}
95
-
96
-		// Try looking for an entity by title, get any potential candidate.
97
-		$candidate = get_page_by_title( $value, OBJECT, Wordlift_Entity_Service::valid_entity_post_types() );
98
-
99
-		// If a candidate has been found and it's an entity.
100
-		return null !== $candidate && $entity_service->is_entity( $candidate->ID );
101
-	}
102
-
103
-	/**
104
-	 * @inheritdoc
105
-	 */
106
-	public function html_wrapper_open() {
107
-
108
-		// The containing <div> contains info on cardinality and expected types.
109
-		$html = "<div class='wl-field' data-cardinality='$this->cardinality'";
110
-
111
-		if ( isset( $this->expected_uri_type ) && ! is_null( $this->expected_uri_type ) ) {
112
-
113
-			if ( is_array( $this->expected_uri_type ) ) {
114
-				$html .= " data-expected-types='" . implode( ',', $this->expected_uri_type ) . "'";
115
-			} else {
116
-				$html .= " data-expected-types='$this->expected_uri_type'";
117
-			}
118
-		}
119
-
120
-		$html .= '>';
121
-
122
-		return $html;
123
-	}
124
-
125
-	/**
126
-	 * @inheritdoc
127
-	 */
128
-	public function html_input( $default_entity_identifier ) {
129
-
130
-		if ( empty( $default_entity_identifier ) ) {
131
-			$entity = null;
132
-		} elseif ( is_numeric( $default_entity_identifier ) ) {
133
-			$entity = get_post( $default_entity_identifier );
134
-		} else {
135
-			// @todo: we cannot be so sure this is a URI.
136
-			// It is an URI
137
-			$entity = Wordlift_Entity_Service
138
-				::get_instance()
139
-				->get_entity_post_by_uri( $default_entity_identifier );
140
-		}
141
-
142
-		if ( ! is_null( $entity ) ) {
143
-			$label = $entity->post_title;
144
-			$value = $entity->ID;
145
-		} else {
146
-			// No ID and no internal uri. Just leave as is.
147
-			$label = $default_entity_identifier;
148
-			$value = $default_entity_identifier;
149
-		}
150
-
151
-		// Write saved value in page
152
-		// The <input> tags host the meta value.
153
-		// The visible <input> has the human readable value (i.e. entity name or uri)
154
-		// and is accompained by an hidden <input> tag, passed to the server,
155
-		// that contains the raw value (i.e. the uri or entity id).
156
-		@ob_start();
157
-		?>
19
+    /**
20
+     * Only accept URIs or local entity IDs.
21
+     * Build new entity if the user inputted a name that is not present in DB.
22
+     *
23
+     * @param mixed $value The value to sanitize.
24
+     *
25
+     * @return int|mixed|WP_Error
26
+     */
27
+    public function sanitize_data_filter( $value ) {
28
+
29
+        if ( empty( $value ) ) {
30
+            return null;
31
+        }
32
+
33
+        // Check that the inserted URI, ID or name does not point to a saved
34
+        // entity or when the editor types a string in the input box, we try to
35
+        // find an entity with that title and, if not found, we create that entity.
36
+        $absent_from_db = is_numeric( $value )
37
+            ? is_null( get_post( $value ) )
38
+            : ! $this->exists( $value );
39
+
40
+        // Is it an URI?
41
+        $name_is_uri = strpos( $value, 'http' ) === 0;
42
+
43
+        // We create a new entity only if the entity is not present in the DB.
44
+        // In the case of an external uri, we just save the uri.
45
+        if ( $absent_from_db && ! $name_is_uri ) {
46
+
47
+            // ...we create a new entity!
48
+            $new_entity_id = wp_insert_post( array(
49
+                'post_status' => 'publish',
50
+                'post_type'   => Wordlift_Entity_Service::TYPE_NAME,
51
+                'post_title'  => $value,
52
+            ) );
53
+
54
+            $type = 'http://schema.org/' . ( isset( $this->expected_uri_type ) ? $this->expected_uri_type[0] : 'Thing' );
55
+
56
+            wl_set_entity_main_type( $new_entity_id, $type );
57
+
58
+            // Build uri for this entity.
59
+            $new_uri = wl_build_entity_uri( $new_entity_id );
60
+            wl_set_entity_uri( $new_entity_id, $new_uri );
61
+
62
+            Wordlift_Linked_Data_Service::get_instance()->push( $new_entity_id );
63
+
64
+            // Update the value that will be saved as meta.
65
+            $value = $new_entity_id;
66
+        }
67
+
68
+        return $value;
69
+    }
70
+
71
+    /**
72
+     * Check whether an entity exists given a value.
73
+     *
74
+     * @since 3.15.0
75
+     *
76
+     * @param string $value An entity URI or a title string..
77
+     *
78
+     * @return bool True if the entity exists otherwise false.
79
+     */
80
+    private function exists( $value ) {
81
+
82
+        // When the editor types a string in the input box, we try to find
83
+        // an entity with that title and, if not found, we create that entity.
84
+        $entity_service = Wordlift_Entity_Service::get_instance();
85
+
86
+        // Try looking for an entity by URI.
87
+        $found_by_uri = null !== $entity_service->get_entity_post_by_uri( $value );
88
+
89
+        // Return true if found.
90
+        if ( $found_by_uri ) {
91
+            $this->log->debug( "Found entity for $value." );
92
+
93
+            return true;
94
+        }
95
+
96
+        // Try looking for an entity by title, get any potential candidate.
97
+        $candidate = get_page_by_title( $value, OBJECT, Wordlift_Entity_Service::valid_entity_post_types() );
98
+
99
+        // If a candidate has been found and it's an entity.
100
+        return null !== $candidate && $entity_service->is_entity( $candidate->ID );
101
+    }
102
+
103
+    /**
104
+     * @inheritdoc
105
+     */
106
+    public function html_wrapper_open() {
107
+
108
+        // The containing <div> contains info on cardinality and expected types.
109
+        $html = "<div class='wl-field' data-cardinality='$this->cardinality'";
110
+
111
+        if ( isset( $this->expected_uri_type ) && ! is_null( $this->expected_uri_type ) ) {
112
+
113
+            if ( is_array( $this->expected_uri_type ) ) {
114
+                $html .= " data-expected-types='" . implode( ',', $this->expected_uri_type ) . "'";
115
+            } else {
116
+                $html .= " data-expected-types='$this->expected_uri_type'";
117
+            }
118
+        }
119
+
120
+        $html .= '>';
121
+
122
+        return $html;
123
+    }
124
+
125
+    /**
126
+     * @inheritdoc
127
+     */
128
+    public function html_input( $default_entity_identifier ) {
129
+
130
+        if ( empty( $default_entity_identifier ) ) {
131
+            $entity = null;
132
+        } elseif ( is_numeric( $default_entity_identifier ) ) {
133
+            $entity = get_post( $default_entity_identifier );
134
+        } else {
135
+            // @todo: we cannot be so sure this is a URI.
136
+            // It is an URI
137
+            $entity = Wordlift_Entity_Service
138
+                ::get_instance()
139
+                ->get_entity_post_by_uri( $default_entity_identifier );
140
+        }
141
+
142
+        if ( ! is_null( $entity ) ) {
143
+            $label = $entity->post_title;
144
+            $value = $entity->ID;
145
+        } else {
146
+            // No ID and no internal uri. Just leave as is.
147
+            $label = $default_entity_identifier;
148
+            $value = $default_entity_identifier;
149
+        }
150
+
151
+        // Write saved value in page
152
+        // The <input> tags host the meta value.
153
+        // The visible <input> has the human readable value (i.e. entity name or uri)
154
+        // and is accompained by an hidden <input> tag, passed to the server,
155
+        // that contains the raw value (i.e. the uri or entity id).
156
+        @ob_start();
157
+        ?>
158 158
 			<div class="wl-input-wrapper wl-autocomplete-wrapper">
159 159
 				<input
160 160
 					type="text"
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
 				<div class="wl-input-notice"></div>
177 177
 			</div>
178 178
 		<?php
179
-		$html = ob_get_clean();
179
+        $html = ob_get_clean();
180 180
 
181
-		return $html;
182
-	}
181
+        return $html;
182
+    }
183 183
 
184 184
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -24,42 +24,42 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @return int|mixed|WP_Error
26 26
 	 */
27
-	public function sanitize_data_filter( $value ) {
27
+	public function sanitize_data_filter($value) {
28 28
 
29
-		if ( empty( $value ) ) {
29
+		if (empty($value)) {
30 30
 			return null;
31 31
 		}
32 32
 
33 33
 		// Check that the inserted URI, ID or name does not point to a saved
34 34
 		// entity or when the editor types a string in the input box, we try to
35 35
 		// find an entity with that title and, if not found, we create that entity.
36
-		$absent_from_db = is_numeric( $value )
37
-			? is_null( get_post( $value ) )
38
-			: ! $this->exists( $value );
36
+		$absent_from_db = is_numeric($value)
37
+			? is_null(get_post($value))
38
+			: ! $this->exists($value);
39 39
 
40 40
 		// Is it an URI?
41
-		$name_is_uri = strpos( $value, 'http' ) === 0;
41
+		$name_is_uri = strpos($value, 'http') === 0;
42 42
 
43 43
 		// We create a new entity only if the entity is not present in the DB.
44 44
 		// In the case of an external uri, we just save the uri.
45
-		if ( $absent_from_db && ! $name_is_uri ) {
45
+		if ($absent_from_db && ! $name_is_uri) {
46 46
 
47 47
 			// ...we create a new entity!
48
-			$new_entity_id = wp_insert_post( array(
48
+			$new_entity_id = wp_insert_post(array(
49 49
 				'post_status' => 'publish',
50 50
 				'post_type'   => Wordlift_Entity_Service::TYPE_NAME,
51 51
 				'post_title'  => $value,
52
-			) );
52
+			));
53 53
 
54
-			$type = 'http://schema.org/' . ( isset( $this->expected_uri_type ) ? $this->expected_uri_type[0] : 'Thing' );
54
+			$type = 'http://schema.org/'.(isset($this->expected_uri_type) ? $this->expected_uri_type[0] : 'Thing');
55 55
 
56
-			wl_set_entity_main_type( $new_entity_id, $type );
56
+			wl_set_entity_main_type($new_entity_id, $type);
57 57
 
58 58
 			// Build uri for this entity.
59
-			$new_uri = wl_build_entity_uri( $new_entity_id );
60
-			wl_set_entity_uri( $new_entity_id, $new_uri );
59
+			$new_uri = wl_build_entity_uri($new_entity_id);
60
+			wl_set_entity_uri($new_entity_id, $new_uri);
61 61
 
62
-			Wordlift_Linked_Data_Service::get_instance()->push( $new_entity_id );
62
+			Wordlift_Linked_Data_Service::get_instance()->push($new_entity_id);
63 63
 
64 64
 			// Update the value that will be saved as meta.
65 65
 			$value = $new_entity_id;
@@ -77,27 +77,27 @@  discard block
 block discarded – undo
77 77
 	 *
78 78
 	 * @return bool True if the entity exists otherwise false.
79 79
 	 */
80
-	private function exists( $value ) {
80
+	private function exists($value) {
81 81
 
82 82
 		// When the editor types a string in the input box, we try to find
83 83
 		// an entity with that title and, if not found, we create that entity.
84 84
 		$entity_service = Wordlift_Entity_Service::get_instance();
85 85
 
86 86
 		// Try looking for an entity by URI.
87
-		$found_by_uri = null !== $entity_service->get_entity_post_by_uri( $value );
87
+		$found_by_uri = null !== $entity_service->get_entity_post_by_uri($value);
88 88
 
89 89
 		// Return true if found.
90
-		if ( $found_by_uri ) {
91
-			$this->log->debug( "Found entity for $value." );
90
+		if ($found_by_uri) {
91
+			$this->log->debug("Found entity for $value.");
92 92
 
93 93
 			return true;
94 94
 		}
95 95
 
96 96
 		// Try looking for an entity by title, get any potential candidate.
97
-		$candidate = get_page_by_title( $value, OBJECT, Wordlift_Entity_Service::valid_entity_post_types() );
97
+		$candidate = get_page_by_title($value, OBJECT, Wordlift_Entity_Service::valid_entity_post_types());
98 98
 
99 99
 		// If a candidate has been found and it's an entity.
100
-		return null !== $candidate && $entity_service->is_entity( $candidate->ID );
100
+		return null !== $candidate && $entity_service->is_entity($candidate->ID);
101 101
 	}
102 102
 
103 103
 	/**
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
 		// The containing <div> contains info on cardinality and expected types.
109 109
 		$html = "<div class='wl-field' data-cardinality='$this->cardinality'";
110 110
 
111
-		if ( isset( $this->expected_uri_type ) && ! is_null( $this->expected_uri_type ) ) {
111
+		if (isset($this->expected_uri_type) && ! is_null($this->expected_uri_type)) {
112 112
 
113
-			if ( is_array( $this->expected_uri_type ) ) {
114
-				$html .= " data-expected-types='" . implode( ',', $this->expected_uri_type ) . "'";
113
+			if (is_array($this->expected_uri_type)) {
114
+				$html .= " data-expected-types='".implode(',', $this->expected_uri_type)."'";
115 115
 			} else {
116 116
 				$html .= " data-expected-types='$this->expected_uri_type'";
117 117
 			}
@@ -125,21 +125,21 @@  discard block
 block discarded – undo
125 125
 	/**
126 126
 	 * @inheritdoc
127 127
 	 */
128
-	public function html_input( $default_entity_identifier ) {
128
+	public function html_input($default_entity_identifier) {
129 129
 
130
-		if ( empty( $default_entity_identifier ) ) {
130
+		if (empty($default_entity_identifier)) {
131 131
 			$entity = null;
132
-		} elseif ( is_numeric( $default_entity_identifier ) ) {
133
-			$entity = get_post( $default_entity_identifier );
132
+		} elseif (is_numeric($default_entity_identifier)) {
133
+			$entity = get_post($default_entity_identifier);
134 134
 		} else {
135 135
 			// @todo: we cannot be so sure this is a URI.
136 136
 			// It is an URI
137 137
 			$entity = Wordlift_Entity_Service
138 138
 				::get_instance()
139
-				->get_entity_post_by_uri( $default_entity_identifier );
139
+				->get_entity_post_by_uri($default_entity_identifier);
140 140
 		}
141 141
 
142
-		if ( ! is_null( $entity ) ) {
142
+		if ( ! is_null($entity)) {
143 143
 			$label = $entity->post_title;
144 144
 			$value = $entity->ID;
145 145
 		} else {
@@ -158,19 +158,19 @@  discard block
 block discarded – undo
158 158
 			<div class="wl-input-wrapper wl-autocomplete-wrapper">
159 159
 				<input
160 160
 					type="text"
161
-					class="<?php echo esc_attr( $this->meta_name ); ?> wl-autocomplete"
162
-					value="<?php echo esc_attr( $label ); ?>"
161
+					class="<?php echo esc_attr($this->meta_name); ?> wl-autocomplete"
162
+					value="<?php echo esc_attr($label); ?>"
163 163
 					style="width:88%"
164 164
 				/>
165 165
 				<input
166 166
 					type="hidden"
167
-					class="<?php echo esc_attr( $this->meta_name ); ?>"
167
+					class="<?php echo esc_attr($this->meta_name); ?>"
168 168
 					name="wl_metaboxes[<?php echo $this->meta_name ?>][]"
169
-					value="<?php echo esc_attr( $value ); ?>"
169
+					value="<?php echo esc_attr($value); ?>"
170 170
 				/>
171 171
 
172 172
 				<button class="button wl-remove-input wl-button" type="button">
173
-					<?php esc_html_e( 'Remove', 'wordlift' ); ?>
173
+					<?php esc_html_e('Remove', 'wordlift'); ?>
174 174
 				</button>
175 175
 
176 176
 				<div class="wl-input-notice"></div>
Please login to merge, or discard this patch.
src/admin/WL_Metabox/class-wl-metabox-field.php 2 patches
Indentation   +412 added lines, -412 removed lines patch added patch discarded remove patch
@@ -19,409 +19,409 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class WL_Metabox_Field {
21 21
 
22
-	/**
23
-	 * A {@link Wordlift_Log_Service} instance.
24
-	 *
25
-	 * @since  3.15.0
26
-	 * @access protected
27
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
28
-	 */
29
-	protected $log;
30
-
31
-	/**
32
-	 * The meta name for this field's value.
33
-	 *
34
-	 * @var string $meta_name The meta name for this field's value.
35
-	 */
36
-	public $meta_name;
37
-
38
-	/**
39
-	 * The custom field settings.
40
-	 *
41
-	 * @var null|array $raw_custom_field The custom field settings.
42
-	 */
43
-	public $raw_custom_field;
44
-
45
-	/**
46
-	 * The schema.org predicate.
47
-	 *
48
-	 * @var string $predicate The schema.org predicate.
49
-	 */
50
-	public $predicate;
51
-
52
-	/**
53
-	 * The field's label.
54
-	 *
55
-	 * @var string $label The field's label.
56
-	 */
57
-	public $label;
58
-
59
-	/**
60
-	 * The WordLift data type.
61
-	 *
62
-	 * @var string $expected_wl_type The WordLift data type.
63
-	 */
64
-	public $expected_wl_type;
65
-
66
-	/**
67
-	 * The RDF data type.
68
-	 *
69
-	 * @var string $expected_uri_type The RDF data type.
70
-	 */
71
-	public $expected_uri_type;
72
-
73
-	/**
74
-	 * The cardinality.
75
-	 *
76
-	 * @var int $cardinality The cardinality.
77
-	 */
78
-	public $cardinality;
79
-
80
-	/**
81
-	 * The current value.
82
-	 *
83
-	 * @var array $data The current value.
84
-	 */
85
-	public $data;
86
-
87
-	/**
88
-	 * The current {@link WP_Post} id.
89
-	 *
90
-	 * @since 3.15.3
91
-	 *
92
-	 * @var int The current {@link WP_Post} id.
93
-	 */
94
-	private $post_id;
95
-
96
-	/**
97
-	 * Create a {@link WL_Metabox_Field} instance.
98
-	 *
99
-	 * @param array $args An array of parameters.
100
-	 */
101
-	public function __construct( $args ) {
102
-
103
-		$this->log = Wordlift_Log_Service::get_logger( 'WL_Metabox_Field' );
104
-
105
-		if ( empty( $args ) ) {
106
-			return;
107
-		}
108
-
109
-		// Save a copy of the custom field's params.
110
-		$this->raw_custom_field = reset( $args );
111
-
112
-		// Extract meta name (post_meta key for the DB).
113
-		$this->meta_name = key( $args );
114
-
115
-		// Extract linked data predicate.
116
-		if ( isset( $this->raw_custom_field['predicate'] ) ) {
117
-			$this->predicate = $this->raw_custom_field['predicate'];
118
-		} else {
119
-			return;
120
-		}
121
-
122
-		// Extract human readable label.
123
-		$exploded_predicate = explode( '/', $this->predicate );
124
-
125
-		// Use the label defined for the property if set, otherwise the last part of the schema.org/xyz predicate.
126
-		$this->label = isset( $this->raw_custom_field['metabox']['label'] ) ? $this->raw_custom_field['metabox']['label'] : end( $exploded_predicate );
127
-
128
-		// Extract field constraints (numerosity, expected type).
129
-		// Default constaints: accept one string..
130
-		if ( isset( $this->raw_custom_field['type'] ) ) {
131
-			$this->expected_wl_type = $this->raw_custom_field['type'];
132
-		} else {
133
-			$this->expected_wl_type = Wordlift_Schema_Service::DATA_TYPE_STRING;
134
-		}
135
-
136
-		$this->cardinality = 1;
137
-		if ( isset( $this->raw_custom_field['constraints'] ) ) {
138
-
139
-			$constraints = $this->raw_custom_field['constraints'];
140
-
141
-			// Extract cardinality.
142
-			if ( isset( $constraints['cardinality'] ) ) {
143
-				$this->cardinality = $constraints['cardinality'];
144
-			}
145
-
146
-			// Which type of entity can we accept (e.g. Place, Event, ecc.)? .
147
-			if ( Wordlift_Schema_Service::DATA_TYPE_URI === $this->expected_wl_type && isset( $constraints['uri_type'] ) ) {
148
-				$this->expected_uri_type = is_array( $constraints['uri_type'] )
149
-					? $constraints['uri_type']
150
-					: array( $constraints['uri_type'] );
151
-			}
152
-		}
153
-
154
-		// Save early the post id to avoid other plugins messing up with it.
155
-		//
156
-		// See https://github.com/insideout10/wordlift-plugin/issues/665.
157
-		$this->post_id = get_the_ID();
158
-
159
-	}
160
-
161
-	/**
162
-	 * Return nonce HTML.
163
-	 *
164
-	 * Overwrite this method in a child class to obtain custom behaviour.
165
-	 */
166
-	public function html_nonce() {
167
-
168
-		return wp_nonce_field( 'wordlift_' . $this->meta_name . '_entity_box', 'wordlift_' . $this->meta_name . '_entity_box_nonce', true, false );
169
-	}
170
-
171
-	/**
172
-	 * Verify nonce.
173
-	 *
174
-	 * Overwrite this method in a child class to obtain custom behaviour.
175
-	 *
176
-	 * @return boolean Nonce verification.
177
-	 */
178
-	public function verify_nonce() {
179
-
180
-		$nonce_name   = 'wordlift_' . $this->meta_name . '_entity_box_nonce';
181
-		$nonce_verify = 'wordlift_' . $this->meta_name . '_entity_box';
182
-
183
-		if ( ! isset( $_POST[ $nonce_name ] ) ) {
184
-			return false;
185
-		}
186
-
187
-		// Verify that the nonce is valid.
188
-		return wp_verify_nonce( $_POST[ $nonce_name ], $nonce_verify );
189
-	}
190
-
191
-	/**
192
-	 * Load data from DB and store the resulting array in $this->data.
193
-	 *
194
-	 * Overwrite this method in a child class to obtain custom behaviour.
195
-	 */
196
-	public function get_data() {
197
-
198
-		// Get the post id and load the data.
199
-		$post_id    = $this->post_id;
200
-		$this->data = get_post_meta( $post_id, $this->meta_name );
201
-
202
-		$this->log->debug( 'Found ' . count( $this->data ) . " value(s) for meta $this->meta_name, post $post_id." );
203
-
204
-	}
205
-
206
-	/**
207
-	 * Sanitizes data before saving to DB. Default sanitization trashes empty
208
-	 * values.
209
-	 *
210
-	 * Stores the sanitized values into $this->data so they can be later processed.
211
-	 * Overwrite this method in a child class to obtain custom behaviour.
212
-	 *
213
-	 * @param array $values Array of values to be sanitized and then stored into
214
-	 *                      $this->data.
215
-	 */
216
-	public function sanitize_data( $values ) {
217
-
218
-		$sanitized_data = array();
219
-
220
-		if ( ! is_array( $values ) ) {
221
-			$values = array( $values );
222
-		}
223
-
224
-		foreach ( $values as $value ) {
225
-			$sanitized_value = $this->sanitize_data_filter( $value );
226
-			if ( ! is_null( $sanitized_value ) ) {
227
-				$sanitized_data[] = $sanitized_value;
228
-			}
229
-		}
230
-
231
-		$this->data = $sanitized_data;
232
-	}
233
-
234
-	/**
235
-	 * Sanitize a single value. Called from $this->sanitize_data. Default
236
-	 * sanitization excludes empty values.
237
-	 *
238
-	 * Overwrite this method in a child class to obtain custom behaviour.
239
-	 *
240
-	 * @param string $value The value to sanitize.
241
-	 *
242
-	 * @return mixed Returns sanitized value, or null.
243
-	 */
244
-	public function sanitize_data_filter( $value ) {
245
-
246
-		// TODO: all fields should provide their own sanitize which shouldn't
247
-		// be part of a UI class.
248
-
249
-		// If the field provides its own validation, use it.
250
-		if ( isset( $this->raw_custom_field['sanitize'] ) ) {
251
-			return call_user_func( $this->raw_custom_field['sanitize'], $value );
252
-		}
253
-
254
-		if ( ! is_null( $value ) && '' !== $value ) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ .
255
-			return $value;
256
-		}
257
-
258
-		return null;
259
-	}
260
-
261
-	/**
262
-	 * Save data to DB.
263
-	 *
264
-	 * Overwrite this method in a child class to obtain custom behaviour.
265
-	 *
266
-	 * @param array $values Array of values to be sanitized and then stored into $this->data.
267
-	 */
268
-	public function save_data( $values ) {
269
-
270
-		// Will sanitize data and store them in $field->data.
271
-		$this->sanitize_data( $values );
272
-
273
-		// Bail out, if the post id isn't set in the request or isn't numeric.
274
-		//
275
-		// See https://github.com/insideout10/wordlift-plugin/issues/665.
276
-		if ( ! isset( $_POST['post_ID'] ) || ! is_numeric( $_POST['post_ID'] ) ) {
277
-			return;
278
-		}
279
-
280
-		$entity_id = intval( $_POST['post_ID'] );
281
-
282
-		// Take away old values.
283
-		delete_post_meta( $entity_id, $this->meta_name );
284
-
285
-		// insert new values, respecting cardinality.
286
-		$single = ( 1 === $this->cardinality );
287
-		foreach ( $this->data as $value ) {
288
-			$this->log->trace( "Saving $value to $this->meta_name for entity $entity_id..." );
289
-			$meta_id = add_post_meta( $entity_id, $this->meta_name, $value, $single );
290
-			$this->log->debug( "$value to $this->meta_name for entity $entity_id saved with id $meta_id." );
291
-		}
292
-	}
293
-
294
-	/**
295
-	 * Returns the HTML tag that will contain the Field. By default the we
296
-	 * return a <div> with data- attributes on cardinality and expected types.
297
-	 *
298
-	 * It is useful to provide data- attributes for the JS scripts.
299
-	 *
300
-	 * Overwrite this method in a child class to obtain custom behaviour.
301
-	 */
302
-	public function html_wrapper_open() {
303
-
304
-		return "<div class='wl-field' data-cardinality='$this->cardinality'>";
305
-	}
306
-
307
-	/**
308
-	 * Returns Field HTML (nonce included).
309
-	 *
310
-	 * Overwrite this method (or methods called from this method) in a child
311
-	 * class to obtain custom behaviour.
312
-	 *
313
-	 * The HTML fragment includes the following parts:
314
-	 * * html wrapper open.
315
-	 * * heading.
316
-	 * * nonce.
317
-	 * * stored values.
318
-	 * * an empty input when there are no stored values.
319
-	 * * an add button to add more values.
320
-	 * * html wrapper close.
321
-	 */
322
-	public function html() {
323
-
324
-		// Open main <div> for the Field.
325
-		$html = $this->html_wrapper_open();
326
-
327
-		// Label.
328
-		$html .= $this->get_heading_html();
329
-
330
-		// print nonce.
331
-		$html .= $this->html_nonce();
332
-
333
-		// print data loaded from DB.
334
-		$count = 0;
335
-		$html  .= $this->get_stored_values_html( $count );
336
-
337
-		// Print the empty <input> to add new values.
338
-		if ( 0 === $count ) { // } || $count < $this->cardinality ) { DO NOT print empty inputs unless requested by the editor since fields might support empty strings.
339
-			$this->log->debug( 'Going to print an empty HTML input...' );
340
-			$html .= $this->html_input( '' );    // Will print an empty <input>.
341
-			$count ++;
342
-		}
343
-
344
-		// If cardinality allows it, print button to add new values.
345
-		$html .= $this->get_add_button_html( $count );
346
-
347
-		// Close the HTML wrapper.
348
-		$html .= $this->html_wrapper_close();
349
-
350
-		return $html;
351
-	}
352
-
353
-	/**
354
-	 * Print the heading with the label for the metabox.
355
-	 *
356
-	 * @since 3.15.0
357
-	 * @return string The heading html fragment.
358
-	 */
359
-	protected function get_heading_html() {
360
-
361
-		return "<h3>$this->label</h3>";
362
-	}
363
-
364
-	/**
365
-	 * Print the stored values.
366
-	 *
367
-	 * @since 3.15.0
368
-	 *
369
-	 * @param int $count An output value: the number of printed values.
370
-	 *
371
-	 * @return string The html fragment.
372
-	 */
373
-	protected function get_stored_values_html( &$count ) {
374
-
375
-		$html = '';
376
-
377
-		// print data loaded from DB.
378
-		$count = 0;
379
-		if ( $this->data ) {
380
-			foreach ( $this->data as $value ) {
381
-				if ( $count < $this->cardinality ) {
382
-					$this->log->debug( "Going to print an HTML input #$count with $value..." );
383
-					$html .= $this->html_input( $value );
384
-				}
385
-				$count ++;
386
-			}
387
-		}
388
-
389
-		return $html;
390
-	}
391
-
392
-	/**
393
-	 * Get the add button html.
394
-	 *
395
-	 * This function is protected, allowing extending class to further customize
396
-	 * the add button html code.
397
-	 *
398
-	 * @since 3.15.0
399
-	 *
400
-	 * @param int $count The current number of values.
401
-	 *
402
-	 * @return string The add button html code.
403
-	 */
404
-	protected function get_add_button_html( $count ) {
405
-
406
-		// If cardinality allows it, print button to add new values.
407
-		if ( $count < $this->cardinality ) {
408
-			return '<button class="button wl-add-input wl-button" type="button">' . esc_html__( 'Add' ) . '</button>';
409
-		}
410
-
411
-		// Return an empty string.
412
-		return '';
413
-	}
414
-
415
-	/**
416
-	 * Return a single <input> tag for the Field.
417
-	 *
418
-	 * @param mixed $value Input value.
419
-	 *
420
-	 * @return string The html code fragment.
421
-	 */
422
-	public function html_input( $value ) {
423
-		@ob_start();
424
-		?>
22
+    /**
23
+     * A {@link Wordlift_Log_Service} instance.
24
+     *
25
+     * @since  3.15.0
26
+     * @access protected
27
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
28
+     */
29
+    protected $log;
30
+
31
+    /**
32
+     * The meta name for this field's value.
33
+     *
34
+     * @var string $meta_name The meta name for this field's value.
35
+     */
36
+    public $meta_name;
37
+
38
+    /**
39
+     * The custom field settings.
40
+     *
41
+     * @var null|array $raw_custom_field The custom field settings.
42
+     */
43
+    public $raw_custom_field;
44
+
45
+    /**
46
+     * The schema.org predicate.
47
+     *
48
+     * @var string $predicate The schema.org predicate.
49
+     */
50
+    public $predicate;
51
+
52
+    /**
53
+     * The field's label.
54
+     *
55
+     * @var string $label The field's label.
56
+     */
57
+    public $label;
58
+
59
+    /**
60
+     * The WordLift data type.
61
+     *
62
+     * @var string $expected_wl_type The WordLift data type.
63
+     */
64
+    public $expected_wl_type;
65
+
66
+    /**
67
+     * The RDF data type.
68
+     *
69
+     * @var string $expected_uri_type The RDF data type.
70
+     */
71
+    public $expected_uri_type;
72
+
73
+    /**
74
+     * The cardinality.
75
+     *
76
+     * @var int $cardinality The cardinality.
77
+     */
78
+    public $cardinality;
79
+
80
+    /**
81
+     * The current value.
82
+     *
83
+     * @var array $data The current value.
84
+     */
85
+    public $data;
86
+
87
+    /**
88
+     * The current {@link WP_Post} id.
89
+     *
90
+     * @since 3.15.3
91
+     *
92
+     * @var int The current {@link WP_Post} id.
93
+     */
94
+    private $post_id;
95
+
96
+    /**
97
+     * Create a {@link WL_Metabox_Field} instance.
98
+     *
99
+     * @param array $args An array of parameters.
100
+     */
101
+    public function __construct( $args ) {
102
+
103
+        $this->log = Wordlift_Log_Service::get_logger( 'WL_Metabox_Field' );
104
+
105
+        if ( empty( $args ) ) {
106
+            return;
107
+        }
108
+
109
+        // Save a copy of the custom field's params.
110
+        $this->raw_custom_field = reset( $args );
111
+
112
+        // Extract meta name (post_meta key for the DB).
113
+        $this->meta_name = key( $args );
114
+
115
+        // Extract linked data predicate.
116
+        if ( isset( $this->raw_custom_field['predicate'] ) ) {
117
+            $this->predicate = $this->raw_custom_field['predicate'];
118
+        } else {
119
+            return;
120
+        }
121
+
122
+        // Extract human readable label.
123
+        $exploded_predicate = explode( '/', $this->predicate );
124
+
125
+        // Use the label defined for the property if set, otherwise the last part of the schema.org/xyz predicate.
126
+        $this->label = isset( $this->raw_custom_field['metabox']['label'] ) ? $this->raw_custom_field['metabox']['label'] : end( $exploded_predicate );
127
+
128
+        // Extract field constraints (numerosity, expected type).
129
+        // Default constaints: accept one string..
130
+        if ( isset( $this->raw_custom_field['type'] ) ) {
131
+            $this->expected_wl_type = $this->raw_custom_field['type'];
132
+        } else {
133
+            $this->expected_wl_type = Wordlift_Schema_Service::DATA_TYPE_STRING;
134
+        }
135
+
136
+        $this->cardinality = 1;
137
+        if ( isset( $this->raw_custom_field['constraints'] ) ) {
138
+
139
+            $constraints = $this->raw_custom_field['constraints'];
140
+
141
+            // Extract cardinality.
142
+            if ( isset( $constraints['cardinality'] ) ) {
143
+                $this->cardinality = $constraints['cardinality'];
144
+            }
145
+
146
+            // Which type of entity can we accept (e.g. Place, Event, ecc.)? .
147
+            if ( Wordlift_Schema_Service::DATA_TYPE_URI === $this->expected_wl_type && isset( $constraints['uri_type'] ) ) {
148
+                $this->expected_uri_type = is_array( $constraints['uri_type'] )
149
+                    ? $constraints['uri_type']
150
+                    : array( $constraints['uri_type'] );
151
+            }
152
+        }
153
+
154
+        // Save early the post id to avoid other plugins messing up with it.
155
+        //
156
+        // See https://github.com/insideout10/wordlift-plugin/issues/665.
157
+        $this->post_id = get_the_ID();
158
+
159
+    }
160
+
161
+    /**
162
+     * Return nonce HTML.
163
+     *
164
+     * Overwrite this method in a child class to obtain custom behaviour.
165
+     */
166
+    public function html_nonce() {
167
+
168
+        return wp_nonce_field( 'wordlift_' . $this->meta_name . '_entity_box', 'wordlift_' . $this->meta_name . '_entity_box_nonce', true, false );
169
+    }
170
+
171
+    /**
172
+     * Verify nonce.
173
+     *
174
+     * Overwrite this method in a child class to obtain custom behaviour.
175
+     *
176
+     * @return boolean Nonce verification.
177
+     */
178
+    public function verify_nonce() {
179
+
180
+        $nonce_name   = 'wordlift_' . $this->meta_name . '_entity_box_nonce';
181
+        $nonce_verify = 'wordlift_' . $this->meta_name . '_entity_box';
182
+
183
+        if ( ! isset( $_POST[ $nonce_name ] ) ) {
184
+            return false;
185
+        }
186
+
187
+        // Verify that the nonce is valid.
188
+        return wp_verify_nonce( $_POST[ $nonce_name ], $nonce_verify );
189
+    }
190
+
191
+    /**
192
+     * Load data from DB and store the resulting array in $this->data.
193
+     *
194
+     * Overwrite this method in a child class to obtain custom behaviour.
195
+     */
196
+    public function get_data() {
197
+
198
+        // Get the post id and load the data.
199
+        $post_id    = $this->post_id;
200
+        $this->data = get_post_meta( $post_id, $this->meta_name );
201
+
202
+        $this->log->debug( 'Found ' . count( $this->data ) . " value(s) for meta $this->meta_name, post $post_id." );
203
+
204
+    }
205
+
206
+    /**
207
+     * Sanitizes data before saving to DB. Default sanitization trashes empty
208
+     * values.
209
+     *
210
+     * Stores the sanitized values into $this->data so they can be later processed.
211
+     * Overwrite this method in a child class to obtain custom behaviour.
212
+     *
213
+     * @param array $values Array of values to be sanitized and then stored into
214
+     *                      $this->data.
215
+     */
216
+    public function sanitize_data( $values ) {
217
+
218
+        $sanitized_data = array();
219
+
220
+        if ( ! is_array( $values ) ) {
221
+            $values = array( $values );
222
+        }
223
+
224
+        foreach ( $values as $value ) {
225
+            $sanitized_value = $this->sanitize_data_filter( $value );
226
+            if ( ! is_null( $sanitized_value ) ) {
227
+                $sanitized_data[] = $sanitized_value;
228
+            }
229
+        }
230
+
231
+        $this->data = $sanitized_data;
232
+    }
233
+
234
+    /**
235
+     * Sanitize a single value. Called from $this->sanitize_data. Default
236
+     * sanitization excludes empty values.
237
+     *
238
+     * Overwrite this method in a child class to obtain custom behaviour.
239
+     *
240
+     * @param string $value The value to sanitize.
241
+     *
242
+     * @return mixed Returns sanitized value, or null.
243
+     */
244
+    public function sanitize_data_filter( $value ) {
245
+
246
+        // TODO: all fields should provide their own sanitize which shouldn't
247
+        // be part of a UI class.
248
+
249
+        // If the field provides its own validation, use it.
250
+        if ( isset( $this->raw_custom_field['sanitize'] ) ) {
251
+            return call_user_func( $this->raw_custom_field['sanitize'], $value );
252
+        }
253
+
254
+        if ( ! is_null( $value ) && '' !== $value ) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ .
255
+            return $value;
256
+        }
257
+
258
+        return null;
259
+    }
260
+
261
+    /**
262
+     * Save data to DB.
263
+     *
264
+     * Overwrite this method in a child class to obtain custom behaviour.
265
+     *
266
+     * @param array $values Array of values to be sanitized and then stored into $this->data.
267
+     */
268
+    public function save_data( $values ) {
269
+
270
+        // Will sanitize data and store them in $field->data.
271
+        $this->sanitize_data( $values );
272
+
273
+        // Bail out, if the post id isn't set in the request or isn't numeric.
274
+        //
275
+        // See https://github.com/insideout10/wordlift-plugin/issues/665.
276
+        if ( ! isset( $_POST['post_ID'] ) || ! is_numeric( $_POST['post_ID'] ) ) {
277
+            return;
278
+        }
279
+
280
+        $entity_id = intval( $_POST['post_ID'] );
281
+
282
+        // Take away old values.
283
+        delete_post_meta( $entity_id, $this->meta_name );
284
+
285
+        // insert new values, respecting cardinality.
286
+        $single = ( 1 === $this->cardinality );
287
+        foreach ( $this->data as $value ) {
288
+            $this->log->trace( "Saving $value to $this->meta_name for entity $entity_id..." );
289
+            $meta_id = add_post_meta( $entity_id, $this->meta_name, $value, $single );
290
+            $this->log->debug( "$value to $this->meta_name for entity $entity_id saved with id $meta_id." );
291
+        }
292
+    }
293
+
294
+    /**
295
+     * Returns the HTML tag that will contain the Field. By default the we
296
+     * return a <div> with data- attributes on cardinality and expected types.
297
+     *
298
+     * It is useful to provide data- attributes for the JS scripts.
299
+     *
300
+     * Overwrite this method in a child class to obtain custom behaviour.
301
+     */
302
+    public function html_wrapper_open() {
303
+
304
+        return "<div class='wl-field' data-cardinality='$this->cardinality'>";
305
+    }
306
+
307
+    /**
308
+     * Returns Field HTML (nonce included).
309
+     *
310
+     * Overwrite this method (or methods called from this method) in a child
311
+     * class to obtain custom behaviour.
312
+     *
313
+     * The HTML fragment includes the following parts:
314
+     * * html wrapper open.
315
+     * * heading.
316
+     * * nonce.
317
+     * * stored values.
318
+     * * an empty input when there are no stored values.
319
+     * * an add button to add more values.
320
+     * * html wrapper close.
321
+     */
322
+    public function html() {
323
+
324
+        // Open main <div> for the Field.
325
+        $html = $this->html_wrapper_open();
326
+
327
+        // Label.
328
+        $html .= $this->get_heading_html();
329
+
330
+        // print nonce.
331
+        $html .= $this->html_nonce();
332
+
333
+        // print data loaded from DB.
334
+        $count = 0;
335
+        $html  .= $this->get_stored_values_html( $count );
336
+
337
+        // Print the empty <input> to add new values.
338
+        if ( 0 === $count ) { // } || $count < $this->cardinality ) { DO NOT print empty inputs unless requested by the editor since fields might support empty strings.
339
+            $this->log->debug( 'Going to print an empty HTML input...' );
340
+            $html .= $this->html_input( '' );    // Will print an empty <input>.
341
+            $count ++;
342
+        }
343
+
344
+        // If cardinality allows it, print button to add new values.
345
+        $html .= $this->get_add_button_html( $count );
346
+
347
+        // Close the HTML wrapper.
348
+        $html .= $this->html_wrapper_close();
349
+
350
+        return $html;
351
+    }
352
+
353
+    /**
354
+     * Print the heading with the label for the metabox.
355
+     *
356
+     * @since 3.15.0
357
+     * @return string The heading html fragment.
358
+     */
359
+    protected function get_heading_html() {
360
+
361
+        return "<h3>$this->label</h3>";
362
+    }
363
+
364
+    /**
365
+     * Print the stored values.
366
+     *
367
+     * @since 3.15.0
368
+     *
369
+     * @param int $count An output value: the number of printed values.
370
+     *
371
+     * @return string The html fragment.
372
+     */
373
+    protected function get_stored_values_html( &$count ) {
374
+
375
+        $html = '';
376
+
377
+        // print data loaded from DB.
378
+        $count = 0;
379
+        if ( $this->data ) {
380
+            foreach ( $this->data as $value ) {
381
+                if ( $count < $this->cardinality ) {
382
+                    $this->log->debug( "Going to print an HTML input #$count with $value..." );
383
+                    $html .= $this->html_input( $value );
384
+                }
385
+                $count ++;
386
+            }
387
+        }
388
+
389
+        return $html;
390
+    }
391
+
392
+    /**
393
+     * Get the add button html.
394
+     *
395
+     * This function is protected, allowing extending class to further customize
396
+     * the add button html code.
397
+     *
398
+     * @since 3.15.0
399
+     *
400
+     * @param int $count The current number of values.
401
+     *
402
+     * @return string The add button html code.
403
+     */
404
+    protected function get_add_button_html( $count ) {
405
+
406
+        // If cardinality allows it, print button to add new values.
407
+        if ( $count < $this->cardinality ) {
408
+            return '<button class="button wl-add-input wl-button" type="button">' . esc_html__( 'Add' ) . '</button>';
409
+        }
410
+
411
+        // Return an empty string.
412
+        return '';
413
+    }
414
+
415
+    /**
416
+     * Return a single <input> tag for the Field.
417
+     *
418
+     * @param mixed $value Input value.
419
+     *
420
+     * @return string The html code fragment.
421
+     */
422
+    public function html_input( $value ) {
423
+        @ob_start();
424
+        ?>
425 425
 			<div class="wl-input-wrapper">
426 426
 				<input
427 427
 					type="text"
@@ -436,17 +436,17 @@  discard block
 block discarded – undo
436 436
 				</button>
437 437
 			</div>
438 438
 		<?php
439
-		$html = ob_get_clean();
439
+        $html = ob_get_clean();
440 440
 
441
-		return $html;
442
-	}
441
+        return $html;
442
+    }
443 443
 
444
-	/**
445
-	 * Returns closing for the wrapper HTML tag.
446
-	 */
447
-	public function html_wrapper_close() {
444
+    /**
445
+     * Returns closing for the wrapper HTML tag.
446
+     */
447
+    public function html_wrapper_close() {
448 448
 
449
-		return '</div><hr>';
450
-	}
449
+        return '</div><hr>';
450
+    }
451 451
 
452 452
 }
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -98,56 +98,56 @@  discard block
 block discarded – undo
98 98
 	 *
99 99
 	 * @param array $args An array of parameters.
100 100
 	 */
101
-	public function __construct( $args ) {
101
+	public function __construct($args) {
102 102
 
103
-		$this->log = Wordlift_Log_Service::get_logger( 'WL_Metabox_Field' );
103
+		$this->log = Wordlift_Log_Service::get_logger('WL_Metabox_Field');
104 104
 
105
-		if ( empty( $args ) ) {
105
+		if (empty($args)) {
106 106
 			return;
107 107
 		}
108 108
 
109 109
 		// Save a copy of the custom field's params.
110
-		$this->raw_custom_field = reset( $args );
110
+		$this->raw_custom_field = reset($args);
111 111
 
112 112
 		// Extract meta name (post_meta key for the DB).
113
-		$this->meta_name = key( $args );
113
+		$this->meta_name = key($args);
114 114
 
115 115
 		// Extract linked data predicate.
116
-		if ( isset( $this->raw_custom_field['predicate'] ) ) {
116
+		if (isset($this->raw_custom_field['predicate'])) {
117 117
 			$this->predicate = $this->raw_custom_field['predicate'];
118 118
 		} else {
119 119
 			return;
120 120
 		}
121 121
 
122 122
 		// Extract human readable label.
123
-		$exploded_predicate = explode( '/', $this->predicate );
123
+		$exploded_predicate = explode('/', $this->predicate);
124 124
 
125 125
 		// Use the label defined for the property if set, otherwise the last part of the schema.org/xyz predicate.
126
-		$this->label = isset( $this->raw_custom_field['metabox']['label'] ) ? $this->raw_custom_field['metabox']['label'] : end( $exploded_predicate );
126
+		$this->label = isset($this->raw_custom_field['metabox']['label']) ? $this->raw_custom_field['metabox']['label'] : end($exploded_predicate);
127 127
 
128 128
 		// Extract field constraints (numerosity, expected type).
129 129
 		// Default constaints: accept one string..
130
-		if ( isset( $this->raw_custom_field['type'] ) ) {
130
+		if (isset($this->raw_custom_field['type'])) {
131 131
 			$this->expected_wl_type = $this->raw_custom_field['type'];
132 132
 		} else {
133 133
 			$this->expected_wl_type = Wordlift_Schema_Service::DATA_TYPE_STRING;
134 134
 		}
135 135
 
136 136
 		$this->cardinality = 1;
137
-		if ( isset( $this->raw_custom_field['constraints'] ) ) {
137
+		if (isset($this->raw_custom_field['constraints'])) {
138 138
 
139 139
 			$constraints = $this->raw_custom_field['constraints'];
140 140
 
141 141
 			// Extract cardinality.
142
-			if ( isset( $constraints['cardinality'] ) ) {
142
+			if (isset($constraints['cardinality'])) {
143 143
 				$this->cardinality = $constraints['cardinality'];
144 144
 			}
145 145
 
146 146
 			// Which type of entity can we accept (e.g. Place, Event, ecc.)? .
147
-			if ( Wordlift_Schema_Service::DATA_TYPE_URI === $this->expected_wl_type && isset( $constraints['uri_type'] ) ) {
148
-				$this->expected_uri_type = is_array( $constraints['uri_type'] )
147
+			if (Wordlift_Schema_Service::DATA_TYPE_URI === $this->expected_wl_type && isset($constraints['uri_type'])) {
148
+				$this->expected_uri_type = is_array($constraints['uri_type'])
149 149
 					? $constraints['uri_type']
150
-					: array( $constraints['uri_type'] );
150
+					: array($constraints['uri_type']);
151 151
 			}
152 152
 		}
153 153
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 */
166 166
 	public function html_nonce() {
167 167
 
168
-		return wp_nonce_field( 'wordlift_' . $this->meta_name . '_entity_box', 'wordlift_' . $this->meta_name . '_entity_box_nonce', true, false );
168
+		return wp_nonce_field('wordlift_'.$this->meta_name.'_entity_box', 'wordlift_'.$this->meta_name.'_entity_box_nonce', true, false);
169 169
 	}
170 170
 
171 171
 	/**
@@ -177,15 +177,15 @@  discard block
 block discarded – undo
177 177
 	 */
178 178
 	public function verify_nonce() {
179 179
 
180
-		$nonce_name   = 'wordlift_' . $this->meta_name . '_entity_box_nonce';
181
-		$nonce_verify = 'wordlift_' . $this->meta_name . '_entity_box';
180
+		$nonce_name   = 'wordlift_'.$this->meta_name.'_entity_box_nonce';
181
+		$nonce_verify = 'wordlift_'.$this->meta_name.'_entity_box';
182 182
 
183
-		if ( ! isset( $_POST[ $nonce_name ] ) ) {
183
+		if ( ! isset($_POST[$nonce_name])) {
184 184
 			return false;
185 185
 		}
186 186
 
187 187
 		// Verify that the nonce is valid.
188
-		return wp_verify_nonce( $_POST[ $nonce_name ], $nonce_verify );
188
+		return wp_verify_nonce($_POST[$nonce_name], $nonce_verify);
189 189
 	}
190 190
 
191 191
 	/**
@@ -197,9 +197,9 @@  discard block
 block discarded – undo
197 197
 
198 198
 		// Get the post id and load the data.
199 199
 		$post_id    = $this->post_id;
200
-		$this->data = get_post_meta( $post_id, $this->meta_name );
200
+		$this->data = get_post_meta($post_id, $this->meta_name);
201 201
 
202
-		$this->log->debug( 'Found ' . count( $this->data ) . " value(s) for meta $this->meta_name, post $post_id." );
202
+		$this->log->debug('Found '.count($this->data)." value(s) for meta $this->meta_name, post $post_id.");
203 203
 
204 204
 	}
205 205
 
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
 	 * @param array $values Array of values to be sanitized and then stored into
214 214
 	 *                      $this->data.
215 215
 	 */
216
-	public function sanitize_data( $values ) {
216
+	public function sanitize_data($values) {
217 217
 
218 218
 		$sanitized_data = array();
219 219
 
220
-		if ( ! is_array( $values ) ) {
221
-			$values = array( $values );
220
+		if ( ! is_array($values)) {
221
+			$values = array($values);
222 222
 		}
223 223
 
224
-		foreach ( $values as $value ) {
225
-			$sanitized_value = $this->sanitize_data_filter( $value );
226
-			if ( ! is_null( $sanitized_value ) ) {
224
+		foreach ($values as $value) {
225
+			$sanitized_value = $this->sanitize_data_filter($value);
226
+			if ( ! is_null($sanitized_value)) {
227 227
 				$sanitized_data[] = $sanitized_value;
228 228
 			}
229 229
 		}
@@ -241,17 +241,17 @@  discard block
 block discarded – undo
241 241
 	 *
242 242
 	 * @return mixed Returns sanitized value, or null.
243 243
 	 */
244
-	public function sanitize_data_filter( $value ) {
244
+	public function sanitize_data_filter($value) {
245 245
 
246 246
 		// TODO: all fields should provide their own sanitize which shouldn't
247 247
 		// be part of a UI class.
248 248
 
249 249
 		// If the field provides its own validation, use it.
250
-		if ( isset( $this->raw_custom_field['sanitize'] ) ) {
251
-			return call_user_func( $this->raw_custom_field['sanitize'], $value );
250
+		if (isset($this->raw_custom_field['sanitize'])) {
251
+			return call_user_func($this->raw_custom_field['sanitize'], $value);
252 252
 		}
253 253
 
254
-		if ( ! is_null( $value ) && '' !== $value ) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ .
254
+		if ( ! is_null($value) && '' !== $value) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ .
255 255
 			return $value;
256 256
 		}
257 257
 
@@ -265,29 +265,29 @@  discard block
 block discarded – undo
265 265
 	 *
266 266
 	 * @param array $values Array of values to be sanitized and then stored into $this->data.
267 267
 	 */
268
-	public function save_data( $values ) {
268
+	public function save_data($values) {
269 269
 
270 270
 		// Will sanitize data and store them in $field->data.
271
-		$this->sanitize_data( $values );
271
+		$this->sanitize_data($values);
272 272
 
273 273
 		// Bail out, if the post id isn't set in the request or isn't numeric.
274 274
 		//
275 275
 		// See https://github.com/insideout10/wordlift-plugin/issues/665.
276
-		if ( ! isset( $_POST['post_ID'] ) || ! is_numeric( $_POST['post_ID'] ) ) {
276
+		if ( ! isset($_POST['post_ID']) || ! is_numeric($_POST['post_ID'])) {
277 277
 			return;
278 278
 		}
279 279
 
280
-		$entity_id = intval( $_POST['post_ID'] );
280
+		$entity_id = intval($_POST['post_ID']);
281 281
 
282 282
 		// Take away old values.
283
-		delete_post_meta( $entity_id, $this->meta_name );
283
+		delete_post_meta($entity_id, $this->meta_name);
284 284
 
285 285
 		// insert new values, respecting cardinality.
286
-		$single = ( 1 === $this->cardinality );
287
-		foreach ( $this->data as $value ) {
288
-			$this->log->trace( "Saving $value to $this->meta_name for entity $entity_id..." );
289
-			$meta_id = add_post_meta( $entity_id, $this->meta_name, $value, $single );
290
-			$this->log->debug( "$value to $this->meta_name for entity $entity_id saved with id $meta_id." );
286
+		$single = (1 === $this->cardinality);
287
+		foreach ($this->data as $value) {
288
+			$this->log->trace("Saving $value to $this->meta_name for entity $entity_id...");
289
+			$meta_id = add_post_meta($entity_id, $this->meta_name, $value, $single);
290
+			$this->log->debug("$value to $this->meta_name for entity $entity_id saved with id $meta_id.");
291 291
 		}
292 292
 	}
293 293
 
@@ -332,17 +332,17 @@  discard block
 block discarded – undo
332 332
 
333 333
 		// print data loaded from DB.
334 334
 		$count = 0;
335
-		$html  .= $this->get_stored_values_html( $count );
335
+		$html .= $this->get_stored_values_html($count);
336 336
 
337 337
 		// Print the empty <input> to add new values.
338
-		if ( 0 === $count ) { // } || $count < $this->cardinality ) { DO NOT print empty inputs unless requested by the editor since fields might support empty strings.
339
-			$this->log->debug( 'Going to print an empty HTML input...' );
340
-			$html .= $this->html_input( '' );    // Will print an empty <input>.
341
-			$count ++;
338
+		if (0 === $count) { // } || $count < $this->cardinality ) { DO NOT print empty inputs unless requested by the editor since fields might support empty strings.
339
+			$this->log->debug('Going to print an empty HTML input...');
340
+			$html .= $this->html_input(''); // Will print an empty <input>.
341
+			$count++;
342 342
 		}
343 343
 
344 344
 		// If cardinality allows it, print button to add new values.
345
-		$html .= $this->get_add_button_html( $count );
345
+		$html .= $this->get_add_button_html($count);
346 346
 
347 347
 		// Close the HTML wrapper.
348 348
 		$html .= $this->html_wrapper_close();
@@ -370,19 +370,19 @@  discard block
 block discarded – undo
370 370
 	 *
371 371
 	 * @return string The html fragment.
372 372
 	 */
373
-	protected function get_stored_values_html( &$count ) {
373
+	protected function get_stored_values_html(&$count) {
374 374
 
375 375
 		$html = '';
376 376
 
377 377
 		// print data loaded from DB.
378 378
 		$count = 0;
379
-		if ( $this->data ) {
380
-			foreach ( $this->data as $value ) {
381
-				if ( $count < $this->cardinality ) {
382
-					$this->log->debug( "Going to print an HTML input #$count with $value..." );
383
-					$html .= $this->html_input( $value );
379
+		if ($this->data) {
380
+			foreach ($this->data as $value) {
381
+				if ($count < $this->cardinality) {
382
+					$this->log->debug("Going to print an HTML input #$count with $value...");
383
+					$html .= $this->html_input($value);
384 384
 				}
385
-				$count ++;
385
+				$count++;
386 386
 			}
387 387
 		}
388 388
 
@@ -401,11 +401,11 @@  discard block
 block discarded – undo
401 401
 	 *
402 402
 	 * @return string The add button html code.
403 403
 	 */
404
-	protected function get_add_button_html( $count ) {
404
+	protected function get_add_button_html($count) {
405 405
 
406 406
 		// If cardinality allows it, print button to add new values.
407
-		if ( $count < $this->cardinality ) {
408
-			return '<button class="button wl-add-input wl-button" type="button">' . esc_html__( 'Add' ) . '</button>';
407
+		if ($count < $this->cardinality) {
408
+			return '<button class="button wl-add-input wl-button" type="button">'.esc_html__('Add').'</button>';
409 409
 		}
410 410
 
411 411
 		// Return an empty string.
@@ -419,20 +419,20 @@  discard block
 block discarded – undo
419 419
 	 *
420 420
 	 * @return string The html code fragment.
421 421
 	 */
422
-	public function html_input( $value ) {
422
+	public function html_input($value) {
423 423
 		@ob_start();
424 424
 		?>
425 425
 			<div class="wl-input-wrapper">
426 426
 				<input
427 427
 					type="text"
428
-					id="<?php echo esc_attr( $this->meta_name ); ?>"
428
+					id="<?php echo esc_attr($this->meta_name); ?>"
429 429
 					name="wl_metaboxes[<?php echo $this->meta_name ?>][]"
430
-					value="<?php echo esc_attr( $value ); ?>"
430
+					value="<?php echo esc_attr($value); ?>"
431 431
 					style="width:88%"
432 432
 				/>
433 433
 
434 434
 				<button class="button wl-remove-input wl-button" type="button">
435
-					<?php esc_html_e( 'Remove', 'wordlift' ); ?>
435
+					<?php esc_html_e('Remove', 'wordlift'); ?>
436 436
 				</button>
437 437
 			</div>
438 438
 		<?php
Please login to merge, or discard this patch.
src/admin/WL_Metabox/WL_Metabox_Field_date.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -18,63 +18,63 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class WL_Metabox_Field_date extends WL_Metabox_Field {
20 20
 
21
-	/**
22
-	 * Attribute to distinguish between date formats, inferred from the schema property export type
23
-	 *
24
-	 * @since  3.2.0
25
-	 * @access protected
26
-	 * @var string $date_format The date format.
27
-	 */
28
-	protected $date_format;
29
-
30
-	/**
31
-	 * Boolean flag to decide if the calendar should include time or not
32
-	 *
33
-	 * @since  3.2.0
34
-	 * @access protected
35
-	 * @var boolean $timepicker A boolean flag.
36
-	 */
37
-	protected $timepicker;
38
-
39
-	/**
40
-	 * Whether the calendar should be displayed or not.
41
-	 *
42
-	 * @since  3.14.0
43
-	 * @access protected
44
-	 * @var boolean $no_calendar Whether the calendar should be displayed or not.
45
-	 */
46
-	protected $no_calendar;
47
-
48
-	/**
49
-	 * {@inheritdoc}
50
-	 */
51
-	public function __construct( $args ) {
52
-		parent::__construct( $args );
53
-
54
-		$this->no_calendar = false;
55
-
56
-		// Distinguish between date and datetime
57
-		if ( isset( $this->raw_custom_field['export_type'] ) && 'xsd:dateTime' === $this->raw_custom_field['export_type'] ) {
58
-			$this->date_format = 'Y/m/d H:i';
59
-			$this->timepicker  = true;
60
-		} else {
61
-			$this->date_format = 'Y/m/d';
62
-			$this->timepicker  = false;
63
-		}
64
-
65
-	}
66
-
67
-	/**
68
-	 * @param mixed $date
69
-	 *
70
-	 * @return string
71
-	 */
72
-	public function html_input( $date ) {
73
-
74
-		$this->log->debug("Creating date input with date value $date...");
75
-
76
-		ob_start();
77
-		?>
21
+    /**
22
+     * Attribute to distinguish between date formats, inferred from the schema property export type
23
+     *
24
+     * @since  3.2.0
25
+     * @access protected
26
+     * @var string $date_format The date format.
27
+     */
28
+    protected $date_format;
29
+
30
+    /**
31
+     * Boolean flag to decide if the calendar should include time or not
32
+     *
33
+     * @since  3.2.0
34
+     * @access protected
35
+     * @var boolean $timepicker A boolean flag.
36
+     */
37
+    protected $timepicker;
38
+
39
+    /**
40
+     * Whether the calendar should be displayed or not.
41
+     *
42
+     * @since  3.14.0
43
+     * @access protected
44
+     * @var boolean $no_calendar Whether the calendar should be displayed or not.
45
+     */
46
+    protected $no_calendar;
47
+
48
+    /**
49
+     * {@inheritdoc}
50
+     */
51
+    public function __construct( $args ) {
52
+        parent::__construct( $args );
53
+
54
+        $this->no_calendar = false;
55
+
56
+        // Distinguish between date and datetime
57
+        if ( isset( $this->raw_custom_field['export_type'] ) && 'xsd:dateTime' === $this->raw_custom_field['export_type'] ) {
58
+            $this->date_format = 'Y/m/d H:i';
59
+            $this->timepicker  = true;
60
+        } else {
61
+            $this->date_format = 'Y/m/d';
62
+            $this->timepicker  = false;
63
+        }
64
+
65
+    }
66
+
67
+    /**
68
+     * @param mixed $date
69
+     *
70
+     * @return string
71
+     */
72
+    public function html_input( $date ) {
73
+
74
+        $this->log->debug("Creating date input with date value $date...");
75
+
76
+        ob_start();
77
+        ?>
78 78
 			<div class="wl-input-wrapper">
79 79
 				<input
80 80
 					type="text"
@@ -89,24 +89,24 @@  discard block
 block discarded – undo
89 89
 				</button>
90 90
 			</div>
91 91
 		<?php
92
-		$html = ob_get_clean();
92
+        $html = ob_get_clean();
93 93
 
94
-		return $html;
95
-	}
94
+        return $html;
95
+    }
96 96
 
97
-	public function html_wrapper_close() {
97
+    public function html_wrapper_close() {
98 98
 
99
-		// Should the widget include time picker?
100
-		$timepicker  = json_encode( $this->timepicker );
101
-		$date_format = json_encode( $this->date_format );
102
-		$no_calendar = json_encode( $this->no_calendar );
99
+        // Should the widget include time picker?
100
+        $timepicker  = json_encode( $this->timepicker );
101
+        $date_format = json_encode( $this->date_format );
102
+        $no_calendar = json_encode( $this->no_calendar );
103 103
 
104
-		// Set up the datetimepicker.
105
-		//
106
-		// See https://github.com/trentrichardson/jQuery-Timepicker-Addon
107
-		// See in http://trentrichardson.com/examples/timepicker.
108
-		@ob_start();
109
-		?>
104
+        // Set up the datetimepicker.
105
+        //
106
+        // See https://github.com/trentrichardson/jQuery-Timepicker-Addon
107
+        // See in http://trentrichardson.com/examples/timepicker.
108
+        @ob_start();
109
+        ?>
110 110
 			<script type='text/javascript'>
111 111
 				( function( $ ) {
112 112
 
@@ -122,11 +122,11 @@  discard block
 block discarded – undo
122 122
 				} ) ( jQuery );
123 123
 			</script>
124 124
 		<?php
125
-		$html = ob_get_clean();
125
+        $html = ob_get_clean();
126 126
 
127
-		$html .= parent::html_wrapper_close();
127
+        $html .= parent::html_wrapper_close();
128 128
 
129
-		return $html;
130
-	}
129
+        return $html;
130
+    }
131 131
 
132 132
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -48,13 +48,13 @@  discard block
 block discarded – undo
48 48
 	/**
49 49
 	 * {@inheritdoc}
50 50
 	 */
51
-	public function __construct( $args ) {
52
-		parent::__construct( $args );
51
+	public function __construct($args) {
52
+		parent::__construct($args);
53 53
 
54 54
 		$this->no_calendar = false;
55 55
 
56 56
 		// Distinguish between date and datetime
57
-		if ( isset( $this->raw_custom_field['export_type'] ) && 'xsd:dateTime' === $this->raw_custom_field['export_type'] ) {
57
+		if (isset($this->raw_custom_field['export_type']) && 'xsd:dateTime' === $this->raw_custom_field['export_type']) {
58 58
 			$this->date_format = 'Y/m/d H:i';
59 59
 			$this->timepicker  = true;
60 60
 		} else {
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return string
71 71
 	 */
72
-	public function html_input( $date ) {
72
+	public function html_input($date) {
73 73
 
74 74
 		$this->log->debug("Creating date input with date value $date...");
75 75
 
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
 			<div class="wl-input-wrapper">
79 79
 				<input
80 80
 					type="text"
81
-					class="<?php echo esc_attr( $this->meta_name ); ?>"
81
+					class="<?php echo esc_attr($this->meta_name); ?>"
82 82
 					name="wl_metaboxes[<?php echo $this->meta_name ?>][]"
83 83
 					value="<?php echo $date ?>"
84 84
 					style="width:88%"
85 85
 				/>
86 86
 
87 87
 				<button class="button wl-remove-input wl-button" type="button">
88
-					<?php esc_html_e( 'Remove', 'wordlift' ); ?>
88
+					<?php esc_html_e('Remove', 'wordlift'); ?>
89 89
 				</button>
90 90
 			</div>
91 91
 		<?php
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
 	public function html_wrapper_close() {
98 98
 
99 99
 		// Should the widget include time picker?
100
-		$timepicker  = json_encode( $this->timepicker );
101
-		$date_format = json_encode( $this->date_format );
102
-		$no_calendar = json_encode( $this->no_calendar );
100
+		$timepicker  = json_encode($this->timepicker);
101
+		$date_format = json_encode($this->date_format);
102
+		$no_calendar = json_encode($this->no_calendar);
103 103
 
104 104
 		// Set up the datetimepicker.
105 105
 		//
Please login to merge, or discard this patch.
src/admin/WL_Metabox/WL_Metabox_Field_address.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -8,78 +8,78 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class WL_Metabox_Field_address extends WL_Metabox_Field {
10 10
 
11
-	/**
12
-	 * Sub-fields contained in the Field.
13
-	 *
14
-	 * @since 3.2.0
15
-	 * @access private
16
-	 * @var $subfields Array of WL_Metabox_Field objects, each dealing with a part of the http://schema.org/PostalAddress structure.
17
-	 */
18
-	private $subfields;
11
+    /**
12
+     * Sub-fields contained in the Field.
13
+     *
14
+     * @since 3.2.0
15
+     * @access private
16
+     * @var $subfields Array of WL_Metabox_Field objects, each dealing with a part of the http://schema.org/PostalAddress structure.
17
+     */
18
+    private $subfields;
19 19
 	
20
-	/**
21
-	 * Constructor.
22
-	 * 
23
-	 * @param array $args Set of fields containing info to build the subfields.
24
-	 * The structure of $args is:
25
-	 * array( 'address' => array( ... array of subfields ... ) )
26
-	 */
27
-	public function __construct( $args ) {
20
+    /**
21
+     * Constructor.
22
+     * 
23
+     * @param array $args Set of fields containing info to build the subfields.
24
+     * The structure of $args is:
25
+     * array( 'address' => array( ... array of subfields ... ) )
26
+     */
27
+    public function __construct( $args ) {
28 28
 		
29
-		$this->label = key( $args );
29
+        $this->label = key( $args );
30 30
 		
31
-		// leverage the WL_Metabox_Field class to build the subfields
32
-		$this->subfields = array();
33
-		// Loop over subfields. Using 'reset' to take the data contained in the first element of $args
34
-		foreach ( reset( $args ) as $key => $subfield ) {
35
-			$this->subfields[] = new WL_Metabox_Field( array( $key => $subfield ) );
36
-		}
31
+        // leverage the WL_Metabox_Field class to build the subfields
32
+        $this->subfields = array();
33
+        // Loop over subfields. Using 'reset' to take the data contained in the first element of $args
34
+        foreach ( reset( $args ) as $key => $subfield ) {
35
+            $this->subfields[] = new WL_Metabox_Field( array( $key => $subfield ) );
36
+        }
37 37
 		
38
-		// $_POST array key in which we will pass the values
39
-		$this->meta_name = 'wl_grouped_field_address';
40
-	}
38
+        // $_POST array key in which we will pass the values
39
+        $this->meta_name = 'wl_grouped_field_address';
40
+    }
41 41
 
42
-	/**
43
-	 * Load data from DB and store the resulting array in $this->data.
44
-	 */
45
-	public function get_data() {
42
+    /**
43
+     * Load data from DB and store the resulting array in $this->data.
44
+     */
45
+    public function get_data() {
46 46
 		
47
-		foreach ( $this->subfields as $subfield ) {
48
-			$subfield->get_data();
49
-		}
50
-	}
47
+        foreach ( $this->subfields as $subfield ) {
48
+            $subfield->get_data();
49
+        }
50
+    }
51 51
 
52
-	/**
53
-	 * Save data to DB.
54
-	 * 
55
-	 * @param array $values Values coming from $_POST and passed from WL_Metabox. We just send to each subfield its own value.
56
-	 */
57
-	public function save_data( $values ) {
52
+    /**
53
+     * Save data to DB.
54
+     * 
55
+     * @param array $values Values coming from $_POST and passed from WL_Metabox. We just send to each subfield its own value.
56
+     */
57
+    public function save_data( $values ) {
58 58
 		
59
-		foreach ( $this->subfields as $subfield ) {
60
-			$subfield_value = isset( $values[ $subfield->meta_name ] )? $values[ $subfield->meta_name ] : null;
61
-			$subfield->save_data( $subfield_value );
62
-		}
63
-	}
59
+        foreach ( $this->subfields as $subfield ) {
60
+            $subfield_value = isset( $values[ $subfield->meta_name ] )? $values[ $subfield->meta_name ] : null;
61
+            $subfield->save_data( $subfield_value );
62
+        }
63
+    }
64 64
 
65
-	/**
66
-	 * Returns Field HTML (nonce included).
67
-	 * 
68
-	 * @return string Field HTML
69
-	 */
70
-	public function html() {
71
-		@ob_start();
72
-		// Open main <div> for the Field, then insert label and nonce
73
-		?>
65
+    /**
66
+     * Returns Field HTML (nonce included).
67
+     * 
68
+     * @return string Field HTML
69
+     */
70
+    public function html() {
71
+        @ob_start();
72
+        // Open main <div> for the Field, then insert label and nonce
73
+        ?>
74 74
 			<div class='wl-field'>
75 75
 			<h3><?php echo $this->label ?></h3>
76 76
 			<?php echo $this->html_nonce() ?>
77 77
 
78 78
 		<?php
79
-		// print data loaded from DB
80
-		foreach ( $this->subfields as $subfield ) :
81
-			$value = isset( $subfield->data[0] )? $subfield->data[0] : '';
82
-		?>
79
+        // print data loaded from DB
80
+        foreach ( $this->subfields as $subfield ) :
81
+            $value = isset( $subfield->data[0] )? $subfield->data[0] : '';
82
+        ?>
83 83
 			<div class="wl-input-wrapper">
84 84
 				<label
85 85
 					for="wl_metaboxes[<?php echo $this->meta_name ?>][<?php echo $subfield->meta_name ?>]"
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
 				/>
97 97
 			</div>
98 98
 		<?php
99
-		endforeach;
100
-		$html = ob_get_clean();
99
+        endforeach;
100
+        $html = ob_get_clean();
101 101
 
102
-		// Close the HTML wrapper
103
-		$html .= $this->html_wrapper_close();
102
+        // Close the HTML wrapper
103
+        $html .= $this->html_wrapper_close();
104 104
 
105
-		return $html;
106
-	}
105
+        return $html;
106
+    }
107 107
 }
108 108
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,15 +24,15 @@  discard block
 block discarded – undo
24 24
 	 * The structure of $args is:
25 25
 	 * array( 'address' => array( ... array of subfields ... ) )
26 26
 	 */
27
-	public function __construct( $args ) {
27
+	public function __construct($args) {
28 28
 		
29
-		$this->label = key( $args );
29
+		$this->label = key($args);
30 30
 		
31 31
 		// leverage the WL_Metabox_Field class to build the subfields
32 32
 		$this->subfields = array();
33 33
 		// Loop over subfields. Using 'reset' to take the data contained in the first element of $args
34
-		foreach ( reset( $args ) as $key => $subfield ) {
35
-			$this->subfields[] = new WL_Metabox_Field( array( $key => $subfield ) );
34
+		foreach (reset($args) as $key => $subfield) {
35
+			$this->subfields[] = new WL_Metabox_Field(array($key => $subfield));
36 36
 		}
37 37
 		
38 38
 		// $_POST array key in which we will pass the values
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	public function get_data() {
46 46
 		
47
-		foreach ( $this->subfields as $subfield ) {
47
+		foreach ($this->subfields as $subfield) {
48 48
 			$subfield->get_data();
49 49
 		}
50 50
 	}
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 	 * 
55 55
 	 * @param array $values Values coming from $_POST and passed from WL_Metabox. We just send to each subfield its own value.
56 56
 	 */
57
-	public function save_data( $values ) {
57
+	public function save_data($values) {
58 58
 		
59
-		foreach ( $this->subfields as $subfield ) {
60
-			$subfield_value = isset( $values[ $subfield->meta_name ] )? $values[ $subfield->meta_name ] : null;
61
-			$subfield->save_data( $subfield_value );
59
+		foreach ($this->subfields as $subfield) {
60
+			$subfield_value = isset($values[$subfield->meta_name]) ? $values[$subfield->meta_name] : null;
61
+			$subfield->save_data($subfield_value);
62 62
 		}
63 63
 	}
64 64
 
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
 
78 78
 		<?php
79 79
 		// print data loaded from DB
80
-		foreach ( $this->subfields as $subfield ) :
81
-			$value = isset( $subfield->data[0] )? $subfield->data[0] : '';
80
+		foreach ($this->subfields as $subfield) :
81
+			$value = isset($subfield->data[0]) ? $subfield->data[0] : '';
82 82
 		?>
83 83
 			<div class="wl-input-wrapper">
84 84
 				<label
Please login to merge, or discard this patch.