Completed
Push — develop ( aa8228...88124f )
by David
02:48
created
src/admin/WL_Metabox/class-wordlift-metabox-field-multiline.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,20 +18,20 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Metabox_Field_Multiline extends WL_Metabox_Field {
20 20
 
21
-	/**
22
-	 * @inheritdoc
23
-	 */
24
-	public function html_input( $text ) {
21
+    /**
22
+     * @inheritdoc
23
+     */
24
+    public function html_input( $text ) {
25 25
 
26
-		$esc_text      = esc_textarea( $text );
27
-		$esc_meta_name = esc_attr( $this->meta_name );
28
-		$html          = <<<EOF
26
+        $esc_text      = esc_textarea( $text );
27
+        $esc_meta_name = esc_attr( $this->meta_name );
28
+        $html          = <<<EOF
29 29
 			<div class="wl-input-wrapper">
30 30
 				<textarea id="$esc_meta_name" class="$esc_meta_name" name="wl_metaboxes[$esc_meta_name][]" style="width:88%">$esc_text</textarea>
31 31
 				<button class="button wl-remove-input wl-button" type="button" style="width:10 % ">Remove</button>
32 32
 			</div>
33 33
 EOF;
34 34
 
35
-		return $html;
36
-	}
35
+        return $html;
36
+    }
37 37
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -21,10 +21,10 @@
 block discarded – undo
21 21
 	/**
22 22
 	 * @inheritdoc
23 23
 	 */
24
-	public function html_input( $text ) {
24
+	public function html_input($text) {
25 25
 
26
-		$esc_text      = esc_textarea( $text );
27
-		$esc_meta_name = esc_attr( $this->meta_name );
26
+		$esc_text      = esc_textarea($text);
27
+		$esc_meta_name = esc_attr($this->meta_name);
28 28
 		$html          = <<<EOF
29 29
 			<div class="wl-input-wrapper">
30 30
 				<textarea id="$esc_meta_name" class="$esc_meta_name" name="wl_metaboxes[$esc_meta_name][]" style="width:88%">$esc_text</textarea>
Please login to merge, or discard this patch.
src/admin/WL_Metabox/class-wordlift-metabox-field-duration.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -18,29 +18,29 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Metabox_Field_Duration extends WL_Metabox_Field {
20 20
 
21
-	/**
22
-	 * @param mixed $duration
23
-	 *
24
-	 * @return string HTML for the duration input element
25
-	 */
26
-	public function html_input( $duration ) {
21
+    /**
22
+     * @param mixed $duration
23
+     *
24
+     * @return string HTML for the duration input element
25
+     */
26
+    public function html_input( $duration ) {
27 27
 
28
-		$esc_duration  = esc_attr( $duration );
29
-		$esc_meta_name = esc_attr( $this->meta_name );
30
-		$html          = <<<EOF
28
+        $esc_duration  = esc_attr( $duration );
29
+        $esc_meta_name = esc_attr( $this->meta_name );
30
+        $html          = <<<EOF
31 31
 			<div class="wl-input-wrapper">
32 32
 				<input type="text" pattern="\s*((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}\s*" id="$esc_meta_name" class="$esc_meta_name" name="wl_metaboxes[$esc_meta_name][]" value="$esc_duration" style="width:88%" />
33 33
 				<button class="button wl-remove-input wl-button" type="button" style="width:10 % ">Remove</button>
34 34
 			</div>
35 35
 EOF;
36 36
 
37
-		return $html;
38
-	}
37
+        return $html;
38
+    }
39 39
 
40
-	public function html_wrapper_close() {
40
+    public function html_wrapper_close() {
41 41
 
42
-		$invalid_message = esc_html__( 'Invalid format, should be time in HH:MM format or just MM', 'wordlift' );
43
-		$html            = <<<EOF
42
+        $invalid_message = esc_html__( 'Invalid format, should be time in HH:MM format or just MM', 'wordlift' );
43
+        $html            = <<<EOF
44 44
 			<script type='text/javascript'>
45 45
 				( function( $ ) {
46 46
 
@@ -63,33 +63,33 @@  discard block
 block discarded – undo
63 63
 			</script>
64 64
 EOF;
65 65
 
66
-		$html .= parent::html_wrapper_close();
66
+        $html .= parent::html_wrapper_close();
67 67
 
68
-		return $html;
69
-	}
68
+        return $html;
69
+    }
70 70
 
71
-	/**
72
-	 * Sanitize a single value. Called from $this->sanitize_data. Default sanitization excludes empty values.
73
-	 * make sure the value is either empty, an integer representing valid number of minutes
74
-	 * or an HH:MM time format.
75
-	 *
76
-	 * @param mixed $value The value being sanitized.
77
-	 *
78
-	 * @return mixed Returns sanitized value, or null.
79
-	 */
80
-	public function sanitize_data_filter( $value ) {
71
+    /**
72
+     * Sanitize a single value. Called from $this->sanitize_data. Default sanitization excludes empty values.
73
+     * make sure the value is either empty, an integer representing valid number of minutes
74
+     * or an HH:MM time format.
75
+     *
76
+     * @param mixed $value The value being sanitized.
77
+     *
78
+     * @return mixed Returns sanitized value, or null.
79
+     */
80
+    public function sanitize_data_filter( $value ) {
81 81
 
82
-		if ( ! is_null( $value ) && '' !== $value ) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ .
83
-			preg_match( '#((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}#',
84
-				trim( $value ),
85
-				$matches
86
-			);
82
+        if ( ! is_null( $value ) && '' !== $value ) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ .
83
+            preg_match( '#((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}#',
84
+                trim( $value ),
85
+                $matches
86
+            );
87 87
 
88
-			if ( count( $matches ) > 0 ) {
89
-				return $matches[0];
90
-			}
91
-		}
88
+            if ( count( $matches ) > 0 ) {
89
+                return $matches[0];
90
+            }
91
+        }
92 92
 
93
-		return null;
94
-	}
93
+        return null;
94
+    }
95 95
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @return string HTML for the duration input element
25 25
 	 */
26
-	public function html_input( $duration ) {
26
+	public function html_input($duration) {
27 27
 
28
-		$esc_duration  = esc_attr( $duration );
29
-		$esc_meta_name = esc_attr( $this->meta_name );
28
+		$esc_duration  = esc_attr($duration);
29
+		$esc_meta_name = esc_attr($this->meta_name);
30 30
 		$html          = <<<EOF
31 31
 			<div class="wl-input-wrapper">
32 32
 				<input type="text" pattern="\s*((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}\s*" id="$esc_meta_name" class="$esc_meta_name" name="wl_metaboxes[$esc_meta_name][]" value="$esc_duration" style="width:88%" />
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 
40 40
 	public function html_wrapper_close() {
41 41
 
42
-		$invalid_message = esc_html__( 'Invalid format, should be time in HH:MM format or just MM', 'wordlift' );
42
+		$invalid_message = esc_html__('Invalid format, should be time in HH:MM format or just MM', 'wordlift');
43 43
 		$html            = <<<EOF
44 44
 			<script type='text/javascript'>
45 45
 				( function( $ ) {
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
 	 *
78 78
 	 * @return mixed Returns sanitized value, or null.
79 79
 	 */
80
-	public function sanitize_data_filter( $value ) {
80
+	public function sanitize_data_filter($value) {
81 81
 
82
-		if ( ! is_null( $value ) && '' !== $value ) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ .
83
-			preg_match( '#((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}#',
84
-				trim( $value ),
82
+		if ( ! is_null($value) && '' !== $value) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ .
83
+			preg_match('#((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}#',
84
+				trim($value),
85 85
 				$matches
86 86
 			);
87 87
 
88
-			if ( count( $matches ) > 0 ) {
88
+			if (count($matches) > 0) {
89 89
 				return $matches[0];
90 90
 			}
91 91
 		}
Please login to merge, or discard this patch.
src/admin/WL_Metabox/WL_Metabox.php 2 patches
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -25,277 +25,277 @@
 block discarded – undo
25 25
  */
26 26
 class WL_Metabox {
27 27
 
28
-	public $fields;
29
-
30
-	/**
31
-	 * WL_Metabox constructor.
32
-	 *
33
-	 * @since 3.1.0
34
-	 */
35
-	public function __construct() {
36
-
37
-		// Add hooks to print metaboxes and save submitted data.
38
-		add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
39
-		add_action( 'wl_linked_data_save_post', array(
40
-			&$this,
41
-			'save_form_data',
42
-		) );
43
-
44
-		// Enqueue js and css.
45
-		$this->enqueue_scripts_and_styles();
46
-
47
-	}
48
-
49
-	/**
50
-	 * Add a callback to print the metabox in page.
51
-	 * Wordpress will fire the $this->html() callback at the right time.
52
-	 */
53
-	public function add_main_metabox() {
54
-
55
-		// Add main metabox (will print also the inner fields).
56
-		$id    = uniqid( 'wl-metabox-' );
57
-		$title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
58
-		add_meta_box( $id, $title, array(
59
-			$this,
60
-			'html',
61
-		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
62
-
63
-		// Add filter to change the metabox CSS class.
64
-		add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
65
-	}
66
-
67
-	/**
68
-	 * Called from WP to print the metabox content in page.
69
-	 *
70
-	 * @since 3.1.0
71
-	 *
72
-	 * @param WP_Post $post The post.
73
-	 */
74
-	public function html( $post ) {
75
-
76
-		// Build the fields we need to print.
77
-		$this->instantiate_fields( $post->ID );
78
-
79
-		// Loop over the fields.
80
-		foreach ( $this->fields as $field ) {
81
-
82
-			// load data from DB (values will be available in $field->data).
83
-			$field->get_data();
84
-
85
-			// print field HTML (nonce included).
86
-			echo $field->html();
87
-		}
88
-
89
-	}
90
-
91
-	/**
92
-	 * Read the WL <-> Schema mapping and build the Fields for the entity being edited.
93
-	 *
94
-	 * Note: the first function that calls this method will instantiate the fields.
95
-	 * Why it isn't called from the constructor? Because we need to hook this process as late as possible.
96
-	 *
97
-	 * @since 3.1.0
98
-	 *
99
-	 * @param int $post_id The post id.
100
-	 */
101
-	public function instantiate_fields( $post_id ) {
102
-
103
-		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
104
-		if ( isset( $this->fields ) ) {
105
-			return;
106
-		}
107
-
108
-		$entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
109
-
110
-		if ( isset( $entity_type ) ) {
111
-
112
-			/**
113
-			 * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
114
-			 * We must divide fields in two groups:
115
-			 * - simple: accept values for one property
116
-			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
117
-			 */
118
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
119
-			$simple_metaboxes  = $metaboxes[0];
120
-			$grouped_metaboxes = $metaboxes[1];
28
+    public $fields;
29
+
30
+    /**
31
+     * WL_Metabox constructor.
32
+     *
33
+     * @since 3.1.0
34
+     */
35
+    public function __construct() {
36
+
37
+        // Add hooks to print metaboxes and save submitted data.
38
+        add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
39
+        add_action( 'wl_linked_data_save_post', array(
40
+            &$this,
41
+            'save_form_data',
42
+        ) );
43
+
44
+        // Enqueue js and css.
45
+        $this->enqueue_scripts_and_styles();
46
+
47
+    }
48
+
49
+    /**
50
+     * Add a callback to print the metabox in page.
51
+     * Wordpress will fire the $this->html() callback at the right time.
52
+     */
53
+    public function add_main_metabox() {
54
+
55
+        // Add main metabox (will print also the inner fields).
56
+        $id    = uniqid( 'wl-metabox-' );
57
+        $title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
58
+        add_meta_box( $id, $title, array(
59
+            $this,
60
+            'html',
61
+        ), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
62
+
63
+        // Add filter to change the metabox CSS class.
64
+        add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
65
+    }
66
+
67
+    /**
68
+     * Called from WP to print the metabox content in page.
69
+     *
70
+     * @since 3.1.0
71
+     *
72
+     * @param WP_Post $post The post.
73
+     */
74
+    public function html( $post ) {
75
+
76
+        // Build the fields we need to print.
77
+        $this->instantiate_fields( $post->ID );
78
+
79
+        // Loop over the fields.
80
+        foreach ( $this->fields as $field ) {
81
+
82
+            // load data from DB (values will be available in $field->data).
83
+            $field->get_data();
84
+
85
+            // print field HTML (nonce included).
86
+            echo $field->html();
87
+        }
88
+
89
+    }
90
+
91
+    /**
92
+     * Read the WL <-> Schema mapping and build the Fields for the entity being edited.
93
+     *
94
+     * Note: the first function that calls this method will instantiate the fields.
95
+     * Why it isn't called from the constructor? Because we need to hook this process as late as possible.
96
+     *
97
+     * @since 3.1.0
98
+     *
99
+     * @param int $post_id The post id.
100
+     */
101
+    public function instantiate_fields( $post_id ) {
102
+
103
+        // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
104
+        if ( isset( $this->fields ) ) {
105
+            return;
106
+        }
107
+
108
+        $entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
109
+
110
+        if ( isset( $entity_type ) ) {
111
+
112
+            /**
113
+             * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
114
+             * We must divide fields in two groups:
115
+             * - simple: accept values for one property
116
+             * - grouped: accept values for more properties, or for one property that needs a specific metabox.
117
+             */
118
+            $metaboxes         = $this->group_properties_by_input_field( $entity_type );
119
+            $simple_metaboxes  = $metaboxes[0];
120
+            $grouped_metaboxes = $metaboxes[1];
121 121
 
122
-			// Loop over simple entity properties.
123
-			foreach ( $simple_metaboxes as $key => $property ) {
122
+            // Loop over simple entity properties.
123
+            foreach ( $simple_metaboxes as $key => $property ) {
124 124
 
125
-				// Info passed to the metabox.
126
-				$info         = array();
127
-				$info[ $key ] = $property;
125
+                // Info passed to the metabox.
126
+                $info         = array();
127
+                $info[ $key ] = $property;
128 128
 
129
-				// Build the requested field as WL_Metabox_Field_ object.
130
-				$this->add_field( $info );
131
-			}
129
+                // Build the requested field as WL_Metabox_Field_ object.
130
+                $this->add_field( $info );
131
+            }
132 132
 
133
-			// Loop over grouped properties.
134
-			foreach ( $grouped_metaboxes as $key => $property ) {
133
+            // Loop over grouped properties.
134
+            foreach ( $grouped_metaboxes as $key => $property ) {
135 135
 
136
-				// Info passed to the metabox.
137
-				$info         = array();
138
-				$info[ $key ] = $property;
136
+                // Info passed to the metabox.
137
+                $info         = array();
138
+                $info[ $key ] = $property;
139 139
 
140
-				// Build the requested field group as WL_Metabox_Field_ object.
141
-				$this->add_field( $info, true );
142
-			}
140
+                // Build the requested field group as WL_Metabox_Field_ object.
141
+                $this->add_field( $info, true );
142
+            }
143 143
 
144
-		}
144
+        }
145 145
 
146
-	}
146
+    }
147 147
 
148
-	/**
149
-	 * Separates metaboxes in simple and grouped.
150
-	 *
151
-	 * @param array $custom_fields Information on the entity type.
152
-	 *
153
-	 * @return array
154
-	 */
155
-	public function group_properties_by_input_field( $custom_fields ) {
148
+    /**
149
+     * Separates metaboxes in simple and grouped.
150
+     *
151
+     * @param array $custom_fields Information on the entity type.
152
+     *
153
+     * @return array
154
+     */
155
+    public function group_properties_by_input_field( $custom_fields ) {
156 156
 
157
-		$simple_properties  = array();
158
-		$grouped_properties = array();
157
+        $simple_properties  = array();
158
+        $grouped_properties = array();
159 159
 
160
-		// Loop over possible entity properties.
161
-		foreach ( $custom_fields as $key => $property ) {
160
+        // Loop over possible entity properties.
161
+        foreach ( $custom_fields as $key => $property ) {
162 162
 
163
-			// Check presence of predicate and type.
164
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
163
+            // Check presence of predicate and type.
164
+            if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
165 165
 
166
-				// Check if input_field is defined.
167
-				if ( isset( $property['input_field'] ) && $property['input_field'] !== '' ) {
166
+                // Check if input_field is defined.
167
+                if ( isset( $property['input_field'] ) && $property['input_field'] !== '' ) {
168 168
 
169
-					$grouped_key = $property['input_field'];
169
+                    $grouped_key = $property['input_field'];
170 170
 
171
-					// Update list of grouped properties.
172
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
171
+                    // Update list of grouped properties.
172
+                    $grouped_properties[ $grouped_key ][ $key ] = $property;
173 173
 
174
-				} else {
174
+                } else {
175 175
 
176
-					// input_field not defined, add simple metabox.
177
-					$simple_properties[ $key ] = $property;
178
-				}
179
-			}
180
-		}
176
+                    // input_field not defined, add simple metabox.
177
+                    $simple_properties[ $key ] = $property;
178
+                }
179
+            }
180
+        }
181 181
 
182
-		return array( $simple_properties, $grouped_properties );
183
-	}
182
+        return array( $simple_properties, $grouped_properties );
183
+    }
184 184
 
185
-	/**
186
-	 * Add a Field to the current Metabox, based on the description of the Field.
187
-	 * This method is a rude factory for Field objects.
188
-	 *
189
-	 * @param array $args
190
-	 * @param bool  $grouped Flag to distinguish between simple and grouped Fields
191
-	 */
192
-	public function add_field( $args, $grouped = false ) {
185
+    /**
186
+     * Add a Field to the current Metabox, based on the description of the Field.
187
+     * This method is a rude factory for Field objects.
188
+     *
189
+     * @param array $args
190
+     * @param bool  $grouped Flag to distinguish between simple and grouped Fields
191
+     */
192
+    public function add_field( $args, $grouped = false ) {
193 193
 
194
-		if ( $grouped ) {
195
-			// Special fields (sameas, coordinates, etc.).
194
+        if ( $grouped ) {
195
+            // Special fields (sameas, coordinates, etc.).
196 196
 
197
-			// Build Field with a custom class (e.g. WL_Metabox_Field_date).
198
-			$field_class = 'WL_Metabox_Field_' . key( $args );
197
+            // Build Field with a custom class (e.g. WL_Metabox_Field_date).
198
+            $field_class = 'WL_Metabox_Field_' . key( $args );
199 199
 
200
-		} else {
201
-			// Simple fields (string, uri, boolean, etc.).
200
+        } else {
201
+            // Simple fields (string, uri, boolean, etc.).
202 202
 
203
-			// Which field? We want to use the class that is specific for the field.
204
-			$meta      = key( $args );
205
-			$this_meta = $args[ $meta ];
203
+            // Which field? We want to use the class that is specific for the field.
204
+            $meta      = key( $args );
205
+            $this_meta = $args[ $meta ];
206 206
 
207
-			// If the field declares what metabox it wants, use that one.
208
-			if ( isset( $this_meta['metabox']['class'] ) ) {
207
+            // If the field declares what metabox it wants, use that one.
208
+            if ( isset( $this_meta['metabox']['class'] ) ) {
209 209
 
210
-				$field_class = $this_meta['metabox']['class'];
210
+                $field_class = $this_meta['metabox']['class'];
211 211
 
212
-			} elseif ( ! isset( $this_meta['type'] ) || ( $this_meta['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING ) ) {
212
+            } elseif ( ! isset( $this_meta['type'] ) || ( $this_meta['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING ) ) {
213 213
 
214
-				// TODO: all fields should explicitly declare the required WL_Metabox.
215
-				// When they will remove this.
214
+                // TODO: all fields should explicitly declare the required WL_Metabox.
215
+                // When they will remove this.
216 216
 
217
-				// Use default WL_Metabox_Field (manages strings).
218
-				$field_class = 'WL_Metabox_Field';
217
+                // Use default WL_Metabox_Field (manages strings).
218
+                $field_class = 'WL_Metabox_Field';
219 219
 
220
-			} else {
220
+            } else {
221 221
 
222
-				// TODO: all fields should explicitly declare the required WL_Metabox.
223
-				// When they will remove this.
222
+                // TODO: all fields should explicitly declare the required WL_Metabox.
223
+                // When they will remove this.
224 224
 
225
-				// Build Field with a custom class (e.g. WL_Metabox_Field_date).
226
-				$field_class = 'WL_Metabox_Field_' . $this_meta['type'];
225
+                // Build Field with a custom class (e.g. WL_Metabox_Field_date).
226
+                $field_class = 'WL_Metabox_Field_' . $this_meta['type'];
227 227
 
228
-			}
229
-		}
228
+            }
229
+        }
230 230
 
231
-		// Call apropriate constructor (e.g. WL_Metabox_Field_... ).
232
-		$this->fields[] = new $field_class( $args );
233
-	}
231
+        // Call apropriate constructor (e.g. WL_Metabox_Field_... ).
232
+        $this->fields[] = new $field_class( $args );
233
+    }
234 234
 
235
-	public function save_form_data( $entity_id ) {
235
+    public function save_form_data( $entity_id ) {
236 236
 
237
-		// Build Field objects.
238
-		$this->instantiate_fields( $entity_id );
237
+        // Build Field objects.
238
+        $this->instantiate_fields( $entity_id );
239 239
 
240
-		// Check if WL metabox form was posted.
241
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
242
-			return;
243
-		}
240
+        // Check if WL metabox form was posted.
241
+        if ( ! isset( $_POST['wl_metaboxes'] ) ) {
242
+            return;
243
+        }
244 244
 
245
-		foreach ( $this->fields as $field ) {
245
+        foreach ( $this->fields as $field ) {
246 246
 
247
-			// Verify nonce.
248
-			$valid_nonce = $field->verify_nonce();
249
-			if ( $valid_nonce ) {
247
+            // Verify nonce.
248
+            $valid_nonce = $field->verify_nonce();
249
+            if ( $valid_nonce ) {
250 250
 
251
-				$posted_data = $_POST['wl_metaboxes'];
252
-				$field_name  = $field->meta_name;
251
+                $posted_data = $_POST['wl_metaboxes'];
252
+                $field_name  = $field->meta_name;
253 253
 
254
-				// Each Filed only deals with its values.
255
-				if ( isset( $posted_data[ $field_name ] ) ) {
254
+                // Each Filed only deals with its values.
255
+                if ( isset( $posted_data[ $field_name ] ) ) {
256 256
 
257
-					$values = $posted_data[ $field_name ];
258
-					if ( ! is_array( $values ) ) {
259
-						$values = array( $values );
260
-					}
257
+                    $values = $posted_data[ $field_name ];
258
+                    if ( ! is_array( $values ) ) {
259
+                        $values = array( $values );
260
+                    }
261 261
 
262
-					// Save data permanently
263
-					$field->save_data( $values );
264
-				}
265
-			}
266
-		}
262
+                    // Save data permanently
263
+                    $field->save_data( $values );
264
+                }
265
+            }
266
+        }
267 267
 
268
-		wl_linked_data_push_to_redlink( $entity_id );
269
-	}
268
+        wl_linked_data_push_to_redlink( $entity_id );
269
+    }
270 270
 
271
-	/**
272
-	 * Enqueue scripts and styles.
273
-	 *
274
-	 * @since 3.0.0
275
-	 */
276
-	public function enqueue_scripts_and_styles() {
271
+    /**
272
+     * Enqueue scripts and styles.
273
+     *
274
+     * @since 3.0.0
275
+     */
276
+    public function enqueue_scripts_and_styles() {
277 277
 
278
-		// Load the jquery-ui-timepicker-addon library.
279
-		wp_enqueue_style( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css' );
280
-		wp_enqueue_script( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js', array( 'jquery-ui-datepicker' ), '1.6.3', true );
278
+        // Load the jquery-ui-timepicker-addon library.
279
+        wp_enqueue_style( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css' );
280
+        wp_enqueue_script( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js', array( 'jquery-ui-datepicker' ), '1.6.3', true );
281 281
 
282
-		wp_enqueue_script( 'jquery-ui-timepicker-no-conflict', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.no-conflict.js', array(
283
-			'jquery-ui-datepicker',
284
-			'jquery-ui-timepicker-addon',
285
-		) );
282
+        wp_enqueue_script( 'jquery-ui-timepicker-no-conflict', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.no-conflict.js', array(
283
+            'jquery-ui-datepicker',
284
+            'jquery-ui-timepicker-addon',
285
+        ) );
286 286
 
287
-		// Leaflet.
288
-		wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
289
-		wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
287
+        // Leaflet.
288
+        wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
289
+        wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
290 290
 
291
-		// Add AJAX autocomplete to facilitate metabox editing.
292
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
293
-		wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
294
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
295
-				'action'   => 'entity_by_title',
296
-			)
297
-		);
291
+        // Add AJAX autocomplete to facilitate metabox editing.
292
+        wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
293
+        wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
294
+                'ajax_url' => admin_url( 'admin-ajax.php' ),
295
+                'action'   => 'entity_by_title',
296
+            )
297
+        );
298 298
 
299
-	}
299
+    }
300 300
 
301 301
 }
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@  discard block
 block discarded – undo
7 7
  * @subpackage Wordlift/admin/WL_Metabox
8 8
  */
9 9
 
10
-require_once( 'WL_Metabox_Field.php' );
11
-require_once( 'WL_Metabox_Field_date.php' );
12
-require_once( 'WL_Metabox_Field_uri.php' );
13
-require_once( 'WL_Metabox_Field_coordinates.php' );
14
-require_once( 'WL_Metabox_Field_sameas.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' );
10
+require_once('WL_Metabox_Field.php');
11
+require_once('WL_Metabox_Field_date.php');
12
+require_once('WL_Metabox_Field_uri.php');
13
+require_once('WL_Metabox_Field_coordinates.php');
14
+require_once('WL_Metabox_Field_sameas.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 18
 
19 19
 /**
20 20
  * Define the {@link WL_Metabox} class.
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 	public function __construct() {
36 36
 
37 37
 		// Add hooks to print metaboxes and save submitted data.
38
-		add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
39
-		add_action( 'wl_linked_data_save_post', array(
38
+		add_action('add_meta_boxes', array(&$this, 'add_main_metabox'));
39
+		add_action('wl_linked_data_save_post', array(
40 40
 			&$this,
41 41
 			'save_form_data',
42
-		) );
42
+		));
43 43
 
44 44
 		// Enqueue js and css.
45 45
 		$this->enqueue_scripts_and_styles();
@@ -53,15 +53,15 @@  discard block
 block discarded – undo
53 53
 	public function add_main_metabox() {
54 54
 
55 55
 		// Add main metabox (will print also the inner fields).
56
-		$id    = uniqid( 'wl-metabox-' );
57
-		$title = get_the_title() . ' ' . __( 'properties', 'wordlift' );
58
-		add_meta_box( $id, $title, array(
56
+		$id    = uniqid('wl-metabox-');
57
+		$title = get_the_title().' '.__('properties', 'wordlift');
58
+		add_meta_box($id, $title, array(
59 59
 			$this,
60 60
 			'html',
61
-		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
61
+		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high');
62 62
 
63 63
 		// Add filter to change the metabox CSS class.
64
-		add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
64
+		add_filter("postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class');
65 65
 	}
66 66
 
67 67
 	/**
@@ -71,13 +71,13 @@  discard block
 block discarded – undo
71 71
 	 *
72 72
 	 * @param WP_Post $post The post.
73 73
 	 */
74
-	public function html( $post ) {
74
+	public function html($post) {
75 75
 
76 76
 		// Build the fields we need to print.
77
-		$this->instantiate_fields( $post->ID );
77
+		$this->instantiate_fields($post->ID);
78 78
 
79 79
 		// Loop over the fields.
80
-		foreach ( $this->fields as $field ) {
80
+		foreach ($this->fields as $field) {
81 81
 
82 82
 			// load data from DB (values will be available in $field->data).
83 83
 			$field->get_data();
@@ -98,16 +98,16 @@  discard block
 block discarded – undo
98 98
 	 *
99 99
 	 * @param int $post_id The post id.
100 100
 	 */
101
-	public function instantiate_fields( $post_id ) {
101
+	public function instantiate_fields($post_id) {
102 102
 
103 103
 		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering.
104
-		if ( isset( $this->fields ) ) {
104
+		if (isset($this->fields)) {
105 105
 			return;
106 106
 		}
107 107
 
108
-		$entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
108
+		$entity_type = wl_entity_taxonomy_get_custom_fields($post_id);
109 109
 
110
-		if ( isset( $entity_type ) ) {
110
+		if (isset($entity_type)) {
111 111
 
112 112
 			/**
113 113
 			 * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
@@ -115,30 +115,30 @@  discard block
 block discarded – undo
115 115
 			 * - simple: accept values for one property
116 116
 			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
117 117
 			 */
118
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
118
+			$metaboxes         = $this->group_properties_by_input_field($entity_type);
119 119
 			$simple_metaboxes  = $metaboxes[0];
120 120
 			$grouped_metaboxes = $metaboxes[1];
121 121
 
122 122
 			// Loop over simple entity properties.
123
-			foreach ( $simple_metaboxes as $key => $property ) {
123
+			foreach ($simple_metaboxes as $key => $property) {
124 124
 
125 125
 				// Info passed to the metabox.
126 126
 				$info         = array();
127
-				$info[ $key ] = $property;
127
+				$info[$key] = $property;
128 128
 
129 129
 				// Build the requested field as WL_Metabox_Field_ object.
130
-				$this->add_field( $info );
130
+				$this->add_field($info);
131 131
 			}
132 132
 
133 133
 			// Loop over grouped properties.
134
-			foreach ( $grouped_metaboxes as $key => $property ) {
134
+			foreach ($grouped_metaboxes as $key => $property) {
135 135
 
136 136
 				// Info passed to the metabox.
137 137
 				$info         = array();
138
-				$info[ $key ] = $property;
138
+				$info[$key] = $property;
139 139
 
140 140
 				// Build the requested field group as WL_Metabox_Field_ object.
141
-				$this->add_field( $info, true );
141
+				$this->add_field($info, true);
142 142
 			}
143 143
 
144 144
 		}
@@ -152,34 +152,34 @@  discard block
 block discarded – undo
152 152
 	 *
153 153
 	 * @return array
154 154
 	 */
155
-	public function group_properties_by_input_field( $custom_fields ) {
155
+	public function group_properties_by_input_field($custom_fields) {
156 156
 
157 157
 		$simple_properties  = array();
158 158
 		$grouped_properties = array();
159 159
 
160 160
 		// Loop over possible entity properties.
161
-		foreach ( $custom_fields as $key => $property ) {
161
+		foreach ($custom_fields as $key => $property) {
162 162
 
163 163
 			// Check presence of predicate and type.
164
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
164
+			if (isset($property['predicate']) && isset($property['type'])) {
165 165
 
166 166
 				// Check if input_field is defined.
167
-				if ( isset( $property['input_field'] ) && $property['input_field'] !== '' ) {
167
+				if (isset($property['input_field']) && $property['input_field'] !== '') {
168 168
 
169 169
 					$grouped_key = $property['input_field'];
170 170
 
171 171
 					// Update list of grouped properties.
172
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
172
+					$grouped_properties[$grouped_key][$key] = $property;
173 173
 
174 174
 				} else {
175 175
 
176 176
 					// input_field not defined, add simple metabox.
177
-					$simple_properties[ $key ] = $property;
177
+					$simple_properties[$key] = $property;
178 178
 				}
179 179
 			}
180 180
 		}
181 181
 
182
-		return array( $simple_properties, $grouped_properties );
182
+		return array($simple_properties, $grouped_properties);
183 183
 	}
184 184
 
185 185
 	/**
@@ -189,27 +189,27 @@  discard block
 block discarded – undo
189 189
 	 * @param array $args
190 190
 	 * @param bool  $grouped Flag to distinguish between simple and grouped Fields
191 191
 	 */
192
-	public function add_field( $args, $grouped = false ) {
192
+	public function add_field($args, $grouped = false) {
193 193
 
194
-		if ( $grouped ) {
194
+		if ($grouped) {
195 195
 			// Special fields (sameas, coordinates, etc.).
196 196
 
197 197
 			// Build Field with a custom class (e.g. WL_Metabox_Field_date).
198
-			$field_class = 'WL_Metabox_Field_' . key( $args );
198
+			$field_class = 'WL_Metabox_Field_'.key($args);
199 199
 
200 200
 		} else {
201 201
 			// Simple fields (string, uri, boolean, etc.).
202 202
 
203 203
 			// Which field? We want to use the class that is specific for the field.
204
-			$meta      = key( $args );
205
-			$this_meta = $args[ $meta ];
204
+			$meta      = key($args);
205
+			$this_meta = $args[$meta];
206 206
 
207 207
 			// If the field declares what metabox it wants, use that one.
208
-			if ( isset( $this_meta['metabox']['class'] ) ) {
208
+			if (isset($this_meta['metabox']['class'])) {
209 209
 
210 210
 				$field_class = $this_meta['metabox']['class'];
211 211
 
212
-			} elseif ( ! isset( $this_meta['type'] ) || ( $this_meta['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING ) ) {
212
+			} elseif ( ! isset($this_meta['type']) || ($this_meta['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING)) {
213 213
 
214 214
 				// TODO: all fields should explicitly declare the required WL_Metabox.
215 215
 				// When they will remove this.
@@ -223,49 +223,49 @@  discard block
 block discarded – undo
223 223
 				// When they will remove this.
224 224
 
225 225
 				// Build Field with a custom class (e.g. WL_Metabox_Field_date).
226
-				$field_class = 'WL_Metabox_Field_' . $this_meta['type'];
226
+				$field_class = 'WL_Metabox_Field_'.$this_meta['type'];
227 227
 
228 228
 			}
229 229
 		}
230 230
 
231 231
 		// Call apropriate constructor (e.g. WL_Metabox_Field_... ).
232
-		$this->fields[] = new $field_class( $args );
232
+		$this->fields[] = new $field_class($args);
233 233
 	}
234 234
 
235
-	public function save_form_data( $entity_id ) {
235
+	public function save_form_data($entity_id) {
236 236
 
237 237
 		// Build Field objects.
238
-		$this->instantiate_fields( $entity_id );
238
+		$this->instantiate_fields($entity_id);
239 239
 
240 240
 		// Check if WL metabox form was posted.
241
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
241
+		if ( ! isset($_POST['wl_metaboxes'])) {
242 242
 			return;
243 243
 		}
244 244
 
245
-		foreach ( $this->fields as $field ) {
245
+		foreach ($this->fields as $field) {
246 246
 
247 247
 			// Verify nonce.
248 248
 			$valid_nonce = $field->verify_nonce();
249
-			if ( $valid_nonce ) {
249
+			if ($valid_nonce) {
250 250
 
251 251
 				$posted_data = $_POST['wl_metaboxes'];
252 252
 				$field_name  = $field->meta_name;
253 253
 
254 254
 				// Each Filed only deals with its values.
255
-				if ( isset( $posted_data[ $field_name ] ) ) {
255
+				if (isset($posted_data[$field_name])) {
256 256
 
257
-					$values = $posted_data[ $field_name ];
258
-					if ( ! is_array( $values ) ) {
259
-						$values = array( $values );
257
+					$values = $posted_data[$field_name];
258
+					if ( ! is_array($values)) {
259
+						$values = array($values);
260 260
 					}
261 261
 
262 262
 					// Save data permanently
263
-					$field->save_data( $values );
263
+					$field->save_data($values);
264 264
 				}
265 265
 			}
266 266
 		}
267 267
 
268
-		wl_linked_data_push_to_redlink( $entity_id );
268
+		wl_linked_data_push_to_redlink($entity_id);
269 269
 	}
270 270
 
271 271
 	/**
@@ -276,22 +276,22 @@  discard block
 block discarded – undo
276 276
 	public function enqueue_scripts_and_styles() {
277 277
 
278 278
 		// Load the jquery-ui-timepicker-addon library.
279
-		wp_enqueue_style( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css' );
280
-		wp_enqueue_script( 'jquery-ui-timepicker-addon', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js', array( 'jquery-ui-datepicker' ), '1.6.3', true );
279
+		wp_enqueue_style('jquery-ui-timepicker-addon', dirname(plugin_dir_url(__FILE__)).'/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css');
280
+		wp_enqueue_script('jquery-ui-timepicker-addon', dirname(plugin_dir_url(__FILE__)).'/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js', array('jquery-ui-datepicker'), '1.6.3', true);
281 281
 
282
-		wp_enqueue_script( 'jquery-ui-timepicker-no-conflict', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.no-conflict.js', array(
282
+		wp_enqueue_script('jquery-ui-timepicker-no-conflict', dirname(plugin_dir_url(__FILE__)).'/js/jquery.datetimepicker.no-conflict.js', array(
283 283
 			'jquery-ui-datepicker',
284 284
 			'jquery-ui-timepicker-addon',
285
-		) );
285
+		));
286 286
 
287 287
 		// Leaflet.
288
-		wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
289
-		wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
288
+		wp_enqueue_style('leaflet', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.css');
289
+		wp_enqueue_script('leaflet', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.js', __FILE__);
290 290
 
291 291
 		// Add AJAX autocomplete to facilitate metabox editing.
292
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
293
-		wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
294
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
292
+		wp_enqueue_script('wl-entity-metabox-utility', dirname(plugin_dir_url(__FILE__)).'/js/wl_entity_metabox_utilities.js');
293
+		wp_localize_script('wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
294
+				'ajax_url' => admin_url('admin-ajax.php'),
295 295
 				'action'   => 'entity_by_title',
296 296
 			)
297 297
 		);
Please login to merge, or discard this patch.
src/modules/core/wordlift_core_install.php 2 patches
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -11,95 +11,95 @@  discard block
 block discarded – undo
11 11
  */
12 12
 function wl_core_install_entity_type_data() {
13 13
 
14
-	// Ensure the custom type and the taxonomy are registered.
15
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
16
-
17
-	wl_entity_type_taxonomy_register();
18
-
19
-	// Ensure the custom taxonomy for dbpedia topics is registered
20
-	Wordlift_Topic_Taxonomy_Service::get_instance()->init();
21
-
22
-	// Set the taxonomy data.
23
-	// Note: parent types must be defined before child types.
24
-	$terms = array(
25
-		'thing'         => array(
26
-			'label'       => 'Thing',
27
-			'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.',
28
-		),
29
-		'creative-work' => array(
30
-			'label'       => 'CreativeWork',
31
-			'description' => 'A creative work (or a Music Album).',
32
-		),
33
-		'event'         => array(
34
-			'label'       => 'Event',
35
-			'description' => 'An event.',
36
-		),
37
-		'organization'  => array(
38
-			'label'       => 'Organization',
39
-			'description' => 'An organization, including a government or a newspaper.',
40
-		),
41
-		'person'        => array(
42
-			'label'       => 'Person',
43
-			'description' => 'A person (or a music artist).',
44
-		),
45
-		'place'         => array(
46
-			'label'       => 'Place',
47
-			'description' => 'A place.',
48
-		),
49
-		'localbusiness' => array(
50
-			'label'       => 'LocalBusiness',
51
-			'description' => 'A local business.',
52
-		),
53
-	);
54
-
55
-	foreach ( $terms as $slug => $term ) {
56
-
57
-		// Create the term if it does not exist, then get its ID
58
-		$term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
59
-
60
-		if ( 0 == $term_id || is_null( $term_id ) ) {
61
-			$result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
62
-		} else {
63
-			$term_id = $term_id['term_id'];
64
-			$result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
65
-		}
66
-
67
-		// Check for errors.
68
-		if ( is_wp_error( $result ) ) {
69
-			wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
70
-			continue;
71
-		}
72
-
73
-		// Check if 'parent' corresponds to an actual term and get its ID.
74
-		if ( ! isset( $term['parents'] ) ) {
75
-			$term['parents'] = array();
76
-		}
77
-
78
-		$parent_ids = array();
79
-		foreach ( $term['parents'] as $parent_slug ) {
80
-			$parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
81
-			$parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
82
-		}
83
-
84
-		// Define a parent in the WP taxonomy style (not important for WL)
85
-		if ( empty( $parent_ids ) ) {
86
-			// No parent
87
-			$parent_id = 0;
88
-		} else {
89
-			// Get first parent
90
-			$parent_id = $parent_ids[0];
91
-		}
92
-
93
-		// Update term with description, slug and parent
94
-		wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
95
-			'name'        => $term['label'],
96
-			'slug'        => $slug,
97
-			'description' => $term['description'],
98
-			// We give to WP taxonomy just one parent. TODO: see if can give more than one
99
-			'parent'      => $parent_id,
100
-		) );
101
-
102
-	}
14
+    // Ensure the custom type and the taxonomy are registered.
15
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
16
+
17
+    wl_entity_type_taxonomy_register();
18
+
19
+    // Ensure the custom taxonomy for dbpedia topics is registered
20
+    Wordlift_Topic_Taxonomy_Service::get_instance()->init();
21
+
22
+    // Set the taxonomy data.
23
+    // Note: parent types must be defined before child types.
24
+    $terms = array(
25
+        'thing'         => array(
26
+            'label'       => 'Thing',
27
+            'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.',
28
+        ),
29
+        'creative-work' => array(
30
+            'label'       => 'CreativeWork',
31
+            'description' => 'A creative work (or a Music Album).',
32
+        ),
33
+        'event'         => array(
34
+            'label'       => 'Event',
35
+            'description' => 'An event.',
36
+        ),
37
+        'organization'  => array(
38
+            'label'       => 'Organization',
39
+            'description' => 'An organization, including a government or a newspaper.',
40
+        ),
41
+        'person'        => array(
42
+            'label'       => 'Person',
43
+            'description' => 'A person (or a music artist).',
44
+        ),
45
+        'place'         => array(
46
+            'label'       => 'Place',
47
+            'description' => 'A place.',
48
+        ),
49
+        'localbusiness' => array(
50
+            'label'       => 'LocalBusiness',
51
+            'description' => 'A local business.',
52
+        ),
53
+    );
54
+
55
+    foreach ( $terms as $slug => $term ) {
56
+
57
+        // Create the term if it does not exist, then get its ID
58
+        $term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
59
+
60
+        if ( 0 == $term_id || is_null( $term_id ) ) {
61
+            $result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
62
+        } else {
63
+            $term_id = $term_id['term_id'];
64
+            $result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
65
+        }
66
+
67
+        // Check for errors.
68
+        if ( is_wp_error( $result ) ) {
69
+            wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
70
+            continue;
71
+        }
72
+
73
+        // Check if 'parent' corresponds to an actual term and get its ID.
74
+        if ( ! isset( $term['parents'] ) ) {
75
+            $term['parents'] = array();
76
+        }
77
+
78
+        $parent_ids = array();
79
+        foreach ( $term['parents'] as $parent_slug ) {
80
+            $parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
81
+            $parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
82
+        }
83
+
84
+        // Define a parent in the WP taxonomy style (not important for WL)
85
+        if ( empty( $parent_ids ) ) {
86
+            // No parent
87
+            $parent_id = 0;
88
+        } else {
89
+            // Get first parent
90
+            $parent_id = $parent_ids[0];
91
+        }
92
+
93
+        // Update term with description, slug and parent
94
+        wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
95
+            'name'        => $term['label'],
96
+            'slug'        => $slug,
97
+            'description' => $term['description'],
98
+            // We give to WP taxonomy just one parent. TODO: see if can give more than one
99
+            'parent'      => $parent_id,
100
+        ) );
101
+
102
+    }
103 103
 
104 104
 }
105 105
 
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
  */
109 109
 function wl_core_install_create_relation_instance_table() {
110 110
 
111
-	global $wpdb;
112
-	// global $wl_db_version;
113
-	$installed_version = get_option( 'wl_db_version' );
111
+    global $wpdb;
112
+    // global $wl_db_version;
113
+    $installed_version = get_option( 'wl_db_version' );
114 114
 
115
-	if ( WL_DB_VERSION != $installed_version ) {
116
-		$table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
117
-		$charset_collate = $wpdb->get_charset_collate();
115
+    if ( WL_DB_VERSION != $installed_version ) {
116
+        $table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
117
+        $charset_collate = $wpdb->get_charset_collate();
118 118
 
119
-		// Sql statement for the relation instances custom table
120
-		$sql = <<<EOF
119
+        // Sql statement for the relation instances custom table
120
+        $sql = <<<EOF
121 121
 			CREATE TABLE $table_name (
122 122
   				id int(11) NOT NULL AUTO_INCREMENT,
123 123
   				subject_id int(11) NOT NULL,
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 			) $charset_collate;
130 130
 EOF;
131 131
 
132
-		// @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
133
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
134
-		$results = dbDelta( $sql );
132
+        // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
133
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
134
+        $results = dbDelta( $sql );
135 135
 
136
-		wl_write_log( $results );
136
+        wl_write_log( $results );
137 137
 
138
-		update_option( 'wl_db_version', WL_DB_VERSION );
139
-	}
138
+        update_option( 'wl_db_version', WL_DB_VERSION );
139
+    }
140 140
 }
141 141
 
142 142
 /**
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
  */
148 148
 function wl_core_upgrade_db_to_1_0() {
149 149
 
150
-	if ( ! get_option( 'wl_db_version' ) ) {
151
-		wl_core_install_entity_type_data();
152
-		wl_core_install_create_relation_instance_table();
153
-	}
150
+    if ( ! get_option( 'wl_db_version' ) ) {
151
+        wl_core_install_entity_type_data();
152
+        wl_core_install_create_relation_instance_table();
153
+    }
154 154
 
155 155
 }
156 156
 
@@ -163,31 +163,31 @@  discard block
 block discarded – undo
163 163
  */
164 164
 function wl_core_upgrade_db_1_0_to_3_10() {
165 165
 
166
-	// If the DB version is less than 3.10, than flatten the txonomy.
167
-	if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
166
+    // If the DB version is less than 3.10, than flatten the txonomy.
167
+    if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
168 168
 
169
-		$term_slugs = array(
170
-			'thing',
171
-			'creative-work',
172
-			'event',
173
-			'organization',
174
-			'person',
175
-			'place',
176
-			'localbusiness',
177
-		);
169
+        $term_slugs = array(
170
+            'thing',
171
+            'creative-work',
172
+            'event',
173
+            'organization',
174
+            'person',
175
+            'place',
176
+            'localbusiness',
177
+        );
178 178
 
179
-		foreach ( $term_slugs as $slug ) {
179
+        foreach ( $term_slugs as $slug ) {
180 180
 
181
-			$term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
181
+            $term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
182 182
 
183
-			// Set the term's parent to 0.
184
-			if ( $term ) {
185
-				wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
186
-					'parent' => 0,
187
-				) );
188
-			}
189
-		}
190
-	}
183
+            // Set the term's parent to 0.
184
+            if ( $term ) {
185
+                wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
186
+                    'parent' => 0,
187
+                ) );
188
+            }
189
+        }
190
+    }
191 191
 
192 192
 }
193 193
 
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
  * @since 3.12.0
201 201
  */
202 202
 function wl_core_upgrade_db_3_10_3_12() {
203
-	/*
203
+    /*
204 204
 	 * As this upgrade functionality runs on the init hook, and the AMP plugin
205 205
 	 * initialization does the same, avoid possible race conditions by
206 206
 	 * deferring the actual flush to a later hook.
207 207
 	 */
208
-	add_action( 'wp_loaded', function () {
209
-		flush_rewrite_rules();
210
-	} );
208
+    add_action( 'wp_loaded', function () {
209
+        flush_rewrite_rules();
210
+    } );
211 211
 }
212 212
 
213 213
 /**
@@ -218,49 +218,49 @@  discard block
 block discarded – undo
218 218
  * @since 3.14.0
219 219
  */
220 220
 function wl_core_upgrade_db_3_12_3_14() {
221
-	$result = wp_insert_term(
222
-		'Recipe',
223
-		Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
224
-		array(
225
-			'slug'        => 'recipe',
226
-			'description' => 'A Recipe.',
227
-		)
228
-	);
229
-
230
-	// Assign capabilities to manipulate entities to admins.
231
-	$admins = get_role( 'administrator' );
232
-
233
-	$admins->add_cap( 'edit_wordlift_entity' );
234
-	$admins->add_cap( 'edit_wordlift_entities' );
235
-	$admins->add_cap( 'edit_others_wordlift_entities' );
236
-	$admins->add_cap( 'publish_wordlift_entities' );
237
-	$admins->add_cap( 'read_private_wordlift_entities' );
238
-	$admins->add_cap( 'delete_wordlift_entity' );
239
-
240
-	// Assign capabilities to manipulate entities to editors.
241
-	$editors = get_role( 'editor' );
242
-
243
-	$editors->add_cap( 'edit_wordlift_entity' );
244
-	$editors->add_cap( 'edit_wordlift_entities' );
245
-	$editors->add_cap( 'edit_others_wordlift_entities' );
246
-	$editors->add_cap( 'publish_wordlift_entities' );
247
-	$editors->add_cap( 'read_private_wordlift_entities' );
248
-	$editors->add_cap( 'delete_wordlift_entity' );
221
+    $result = wp_insert_term(
222
+        'Recipe',
223
+        Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
224
+        array(
225
+            'slug'        => 'recipe',
226
+            'description' => 'A Recipe.',
227
+        )
228
+    );
229
+
230
+    // Assign capabilities to manipulate entities to admins.
231
+    $admins = get_role( 'administrator' );
232
+
233
+    $admins->add_cap( 'edit_wordlift_entity' );
234
+    $admins->add_cap( 'edit_wordlift_entities' );
235
+    $admins->add_cap( 'edit_others_wordlift_entities' );
236
+    $admins->add_cap( 'publish_wordlift_entities' );
237
+    $admins->add_cap( 'read_private_wordlift_entities' );
238
+    $admins->add_cap( 'delete_wordlift_entity' );
239
+
240
+    // Assign capabilities to manipulate entities to editors.
241
+    $editors = get_role( 'editor' );
242
+
243
+    $editors->add_cap( 'edit_wordlift_entity' );
244
+    $editors->add_cap( 'edit_wordlift_entities' );
245
+    $editors->add_cap( 'edit_others_wordlift_entities' );
246
+    $editors->add_cap( 'publish_wordlift_entities' );
247
+    $editors->add_cap( 'read_private_wordlift_entities' );
248
+    $editors->add_cap( 'delete_wordlift_entity' );
249 249
 
250 250
 }
251 251
 
252 252
 // Check db status on automated plugins updates
253 253
 function wl_core_update_db_check() {
254 254
 
255
-	if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) {
255
+    if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) {
256 256
 
257
-		wl_core_upgrade_db_to_1_0();
258
-		wl_core_upgrade_db_1_0_to_3_10();
259
-		wl_core_upgrade_db_3_10_3_12();
260
-		wl_core_upgrade_db_3_12_3_14();
261
-		update_option( 'wl_db_version', WL_DB_VERSION );
257
+        wl_core_upgrade_db_to_1_0();
258
+        wl_core_upgrade_db_1_0_to_3_10();
259
+        wl_core_upgrade_db_3_10_3_12();
260
+        wl_core_upgrade_db_3_12_3_14();
261
+        update_option( 'wl_db_version', WL_DB_VERSION );
262 262
 
263
-	}
263
+    }
264 264
 
265 265
 }
266 266
 
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -52,37 +52,37 @@  discard block
 block discarded – undo
52 52
 		),
53 53
 	);
54 54
 
55
-	foreach ( $terms as $slug => $term ) {
55
+	foreach ($terms as $slug => $term) {
56 56
 
57 57
 		// Create the term if it does not exist, then get its ID
58
-		$term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
58
+		$term_id = term_exists($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
59 59
 
60
-		if ( 0 == $term_id || is_null( $term_id ) ) {
61
-			$result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
60
+		if (0 == $term_id || is_null($term_id)) {
61
+			$result = wp_insert_term($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
62 62
 		} else {
63 63
 			$term_id = $term_id['term_id'];
64
-			$result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
64
+			$result  = get_term($term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A);
65 65
 		}
66 66
 
67 67
 		// Check for errors.
68
-		if ( is_wp_error( $result ) ) {
69
-			wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
68
+		if (is_wp_error($result)) {
69
+			wl_write_log('wl_install_entity_type_data [ '.$result->get_error_message().' ]');
70 70
 			continue;
71 71
 		}
72 72
 
73 73
 		// Check if 'parent' corresponds to an actual term and get its ID.
74
-		if ( ! isset( $term['parents'] ) ) {
74
+		if ( ! isset($term['parents'])) {
75 75
 			$term['parents'] = array();
76 76
 		}
77 77
 
78 78
 		$parent_ids = array();
79
-		foreach ( $term['parents'] as $parent_slug ) {
80
-			$parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
81
-			$parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
79
+		foreach ($term['parents'] as $parent_slug) {
80
+			$parent_id    = get_term_by('slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
81
+			$parent_ids[] = intval($parent_id->term_id); // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
82 82
 		}
83 83
 
84 84
 		// Define a parent in the WP taxonomy style (not important for WL)
85
-		if ( empty( $parent_ids ) ) {
85
+		if (empty($parent_ids)) {
86 86
 			// No parent
87 87
 			$parent_id = 0;
88 88
 		} else {
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
 		}
92 92
 
93 93
 		// Update term with description, slug and parent
94
-		wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
94
+		wp_update_term($result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
95 95
 			'name'        => $term['label'],
96 96
 			'slug'        => $slug,
97 97
 			'description' => $term['description'],
98 98
 			// We give to WP taxonomy just one parent. TODO: see if can give more than one
99 99
 			'parent'      => $parent_id,
100
-		) );
100
+		));
101 101
 
102 102
 	}
103 103
 
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
 
111 111
 	global $wpdb;
112 112
 	// global $wl_db_version;
113
-	$installed_version = get_option( 'wl_db_version' );
113
+	$installed_version = get_option('wl_db_version');
114 114
 
115
-	if ( WL_DB_VERSION != $installed_version ) {
116
-		$table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
115
+	if (WL_DB_VERSION != $installed_version) {
116
+		$table_name      = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME;
117 117
 		$charset_collate = $wpdb->get_charset_collate();
118 118
 
119 119
 		// Sql statement for the relation instances custom table
@@ -130,12 +130,12 @@  discard block
 block discarded – undo
130 130
 EOF;
131 131
 
132 132
 		// @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
133
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
134
-		$results = dbDelta( $sql );
133
+		require_once(ABSPATH.'wp-admin/includes/upgrade.php');
134
+		$results = dbDelta($sql);
135 135
 
136
-		wl_write_log( $results );
136
+		wl_write_log($results);
137 137
 
138
-		update_option( 'wl_db_version', WL_DB_VERSION );
138
+		update_option('wl_db_version', WL_DB_VERSION);
139 139
 	}
140 140
 }
141 141
 
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
  */
148 148
 function wl_core_upgrade_db_to_1_0() {
149 149
 
150
-	if ( ! get_option( 'wl_db_version' ) ) {
150
+	if ( ! get_option('wl_db_version')) {
151 151
 		wl_core_install_entity_type_data();
152 152
 		wl_core_install_create_relation_instance_table();
153 153
 	}
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 function wl_core_upgrade_db_1_0_to_3_10() {
165 165
 
166 166
 	// If the DB version is less than 3.10, than flatten the txonomy.
167
-	if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
167
+	if (version_compare(get_option('wl_db_version'), '3.9', '<=')) {
168 168
 
169 169
 		$term_slugs = array(
170 170
 			'thing',
@@ -176,15 +176,15 @@  discard block
 block discarded – undo
176 176
 			'localbusiness',
177 177
 		);
178 178
 
179
-		foreach ( $term_slugs as $slug ) {
179
+		foreach ($term_slugs as $slug) {
180 180
 
181
-			$term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
181
+			$term = get_term_by('slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
182 182
 
183 183
 			// Set the term's parent to 0.
184
-			if ( $term ) {
185
-				wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
184
+			if ($term) {
185
+				wp_update_term($term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
186 186
 					'parent' => 0,
187
-				) );
187
+				));
188 188
 			}
189 189
 		}
190 190
 	}
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	 * initialization does the same, avoid possible race conditions by
206 206
 	 * deferring the actual flush to a later hook.
207 207
 	 */
208
-	add_action( 'wp_loaded', function () {
208
+	add_action('wp_loaded', function() {
209 209
 		flush_rewrite_rules();
210 210
 	} );
211 211
 }
@@ -228,40 +228,40 @@  discard block
 block discarded – undo
228 228
 	);
229 229
 
230 230
 	// Assign capabilities to manipulate entities to admins.
231
-	$admins = get_role( 'administrator' );
231
+	$admins = get_role('administrator');
232 232
 
233
-	$admins->add_cap( 'edit_wordlift_entity' );
234
-	$admins->add_cap( 'edit_wordlift_entities' );
235
-	$admins->add_cap( 'edit_others_wordlift_entities' );
236
-	$admins->add_cap( 'publish_wordlift_entities' );
237
-	$admins->add_cap( 'read_private_wordlift_entities' );
238
-	$admins->add_cap( 'delete_wordlift_entity' );
233
+	$admins->add_cap('edit_wordlift_entity');
234
+	$admins->add_cap('edit_wordlift_entities');
235
+	$admins->add_cap('edit_others_wordlift_entities');
236
+	$admins->add_cap('publish_wordlift_entities');
237
+	$admins->add_cap('read_private_wordlift_entities');
238
+	$admins->add_cap('delete_wordlift_entity');
239 239
 
240 240
 	// Assign capabilities to manipulate entities to editors.
241
-	$editors = get_role( 'editor' );
241
+	$editors = get_role('editor');
242 242
 
243
-	$editors->add_cap( 'edit_wordlift_entity' );
244
-	$editors->add_cap( 'edit_wordlift_entities' );
245
-	$editors->add_cap( 'edit_others_wordlift_entities' );
246
-	$editors->add_cap( 'publish_wordlift_entities' );
247
-	$editors->add_cap( 'read_private_wordlift_entities' );
248
-	$editors->add_cap( 'delete_wordlift_entity' );
243
+	$editors->add_cap('edit_wordlift_entity');
244
+	$editors->add_cap('edit_wordlift_entities');
245
+	$editors->add_cap('edit_others_wordlift_entities');
246
+	$editors->add_cap('publish_wordlift_entities');
247
+	$editors->add_cap('read_private_wordlift_entities');
248
+	$editors->add_cap('delete_wordlift_entity');
249 249
 
250 250
 }
251 251
 
252 252
 // Check db status on automated plugins updates
253 253
 function wl_core_update_db_check() {
254 254
 
255
-	if ( get_option( 'wl_db_version' ) != WL_DB_VERSION ) {
255
+	if (get_option('wl_db_version') != WL_DB_VERSION) {
256 256
 
257 257
 		wl_core_upgrade_db_to_1_0();
258 258
 		wl_core_upgrade_db_1_0_to_3_10();
259 259
 		wl_core_upgrade_db_3_10_3_12();
260 260
 		wl_core_upgrade_db_3_12_3_14();
261
-		update_option( 'wl_db_version', WL_DB_VERSION );
261
+		update_option('wl_db_version', WL_DB_VERSION);
262 262
 
263 263
 	}
264 264
 
265 265
 }
266 266
 
267
-add_action( 'init', 'wl_core_update_db_check', 11 ); // need taxonomies and post type to be defined first
267
+add_action('init', 'wl_core_update_db_check', 11); // need taxonomies and post type to be defined first
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-double-property-service.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,15 +16,15 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Double_Property_Service extends Wordlift_Simple_Property_Service {
18 18
 
19
-	/**
20
-	 * @inheritdoc
21
-	 */
22
-	function get( $post_id, $meta_key ) {
19
+    /**
20
+     * @inheritdoc
21
+     */
22
+    function get( $post_id, $meta_key ) {
23 23
 
24
-		// Map the result to a numeric value when possible.
25
-		return array_map( function ( $value ) {
26
-			return is_numeric( $value ) ? (double) $value : $value;
27
-		}, parent::get( $post_id, $meta_key ) );
28
-	}
24
+        // Map the result to a numeric value when possible.
25
+        return array_map( function ( $value ) {
26
+            return is_numeric( $value ) ? (double) $value : $value;
27
+        }, parent::get( $post_id, $meta_key ) );
28
+    }
29 29
 
30 30
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,12 +19,12 @@
 block discarded – undo
19 19
 	/**
20 20
 	 * @inheritdoc
21 21
 	 */
22
-	function get( $post_id, $meta_key ) {
22
+	function get($post_id, $meta_key) {
23 23
 
24 24
 		// Map the result to a numeric value when possible.
25
-		return array_map( function ( $value ) {
26
-			return is_numeric( $value ) ? (double) $value : $value;
27
-		}, parent::get( $post_id, $meta_key ) );
25
+		return array_map(function($value) {
26
+			return is_numeric($value) ? (double) $value : $value;
27
+		}, parent::get($post_id, $meta_key));
28 28
 	}
29 29
 
30 30
 }
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-property-getter-factory.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -25,40 +25,40 @@
 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
-		) );
47
-		$property_getter->register( new Wordlift_Location_Property_Service( $entity_service ), array(
48
-			Wordlift_Schema_Service::FIELD_LOCATION,
49
-		) );
50
-		$property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) );
51
-		$property_getter->register( new Wordlift_Double_Property_Service(), array(
52
-			Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
53
-			Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
54
-		) );
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
+        ) );
47
+        $property_getter->register( new Wordlift_Location_Property_Service( $entity_service ), array(
48
+            Wordlift_Schema_Service::FIELD_LOCATION,
49
+        ) );
50
+        $property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) );
51
+        $property_getter->register( new Wordlift_Double_Property_Service(), array(
52
+            Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
53
+            Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
54
+        ) );
55 55
 
56
-		$property_getter->register( new Wordlift_Duration_Property_Service( $entity_service ), array(
57
-			Wordlift_Schema_Service::FIELD_PREP_TIME,
58
-			Wordlift_Schema_Service::FIELD_TOTAL_TIME,
59
-		) );
56
+        $property_getter->register( new Wordlift_Duration_Property_Service( $entity_service ), array(
57
+            Wordlift_Schema_Service::FIELD_PREP_TIME,
58
+            Wordlift_Schema_Service::FIELD_TOTAL_TIME,
59
+        ) );
60 60
 
61
-		return $property_getter;
62
-	}
61
+        return $property_getter;
62
+    }
63 63
 
64 64
 }
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,29 +34,29 @@  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,
44 44
 			Wordlift_Schema_Service::FIELD_BIRTH_PLACE,
45 45
 			Wordlift_Schema_Service::FIELD_AFFILIATION,
46
-		) );
47
-		$property_getter->register( new Wordlift_Location_Property_Service( $entity_service ), array(
46
+		));
47
+		$property_getter->register(new Wordlift_Location_Property_Service($entity_service), array(
48 48
 			Wordlift_Schema_Service::FIELD_LOCATION,
49
-		) );
50
-		$property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) );
51
-		$property_getter->register( new Wordlift_Double_Property_Service(), array(
49
+		));
50
+		$property_getter->register(new Wordlift_Url_Property_Service(), array(Wordlift_Url_Property_Service::META_KEY));
51
+		$property_getter->register(new Wordlift_Double_Property_Service(), array(
52 52
 			Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
53 53
 			Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
54
-		) );
54
+		));
55 55
 
56
-		$property_getter->register( new Wordlift_Duration_Property_Service( $entity_service ), array(
56
+		$property_getter->register(new Wordlift_Duration_Property_Service($entity_service), array(
57 57
 			Wordlift_Schema_Service::FIELD_PREP_TIME,
58 58
 			Wordlift_Schema_Service::FIELD_TOTAL_TIME,
59
-		) );
59
+		));
60 60
 
61 61
 		return $property_getter;
62 62
 	}
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-duration-property-service.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -19,20 +19,20 @@
 block discarded – undo
19 19
  */
20 20
 class Wordlift_Duration_Property_Service extends Wordlift_Simple_Property_Service {
21 21
 
22
-	/**
23
-	 * {@inheritdoc}
24
-	 */
25
-	function get( $post_id, $meta_key ) {
22
+    /**
23
+     * {@inheritdoc}
24
+     */
25
+    function get( $post_id, $meta_key ) {
26 26
 
27
-		/*
27
+        /*
28 28
 		 * Map the value in the meta
29 29
 		 * The UI for the meta date enable two forms, a number of minutes
30 30
 		 * or an h:mm format.
31 31
 		 * Both needs to be adjusted to the iso format.
32 32
 		 */
33
-		return array_map( function ( $value ) {
34
-			return 'PT' . str_replace( ':', 'H', $value ) . 'M';
35
-		}, parent::get( $post_id, $meta_key ) );
36
-	}
33
+        return array_map( function ( $value ) {
34
+            return 'PT' . str_replace( ':', 'H', $value ) . 'M';
35
+        }, parent::get( $post_id, $meta_key ) );
36
+    }
37 37
 
38 38
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * {@inheritdoc}
24 24
 	 */
25
-	function get( $post_id, $meta_key ) {
25
+	function get($post_id, $meta_key) {
26 26
 
27 27
 		/*
28 28
 		 * Map the value in the meta
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 		 * or an h:mm format.
31 31
 		 * Both needs to be adjusted to the iso format.
32 32
 		 */
33
-		return array_map( function ( $value ) {
34
-			return 'PT' . str_replace( ':', 'H', $value ) . 'M';
35
-		}, parent::get( $post_id, $meta_key ) );
33
+		return array_map(function($value) {
34
+			return 'PT'.str_replace(':', 'H', $value).'M';
35
+		}, parent::get($post_id, $meta_key));
36 36
 	}
37 37
 
38 38
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-schema-url-property-service.php 2 patches
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -13,209 +13,209 @@
 block discarded – undo
13 13
  */
14 14
 class Wordlift_Schema_Url_Property_Service extends Wordlift_Property_Service {
15 15
 
16
-	/**
17
-	 * The meta key used to store data for this property. We don't use wl_url to
18
-	 * avoid potential confusion about other URLs.
19
-	 *
20
-	 * @since 3.6.0
21
-	 */
22
-	const META_KEY = 'wl_schema_url';
23
-
24
-	/**
25
-	 * {@inheritdoc}
26
-	 */
27
-	public function get_rdf_predicate() {
28
-
29
-		return 'http://schema.org/url';
30
-	}
31
-
32
-	/**
33
-	 * {@inheritdoc}
34
-	 */
35
-	public function get_rdf_data_type() {
36
-
37
-		return 'xsd:anyURI';
38
-	}
39
-
40
-	/**
41
-	 * {@inheritdoc}
42
-	 */
43
-	public function get_data_type() {
44
-
45
-		return Wordlift_Schema_Service::DATA_TYPE_URI;
46
-	}
47
-
48
-	/**
49
-	 * {@inheritdoc}
50
-	 */
51
-	public function get_cardinality() {
52
-
53
-		return INF;
54
-	}
55
-
56
-	/**
57
-	 * {@inheritdoc}
58
-	 */
59
-	public function get_metabox_class() {
60
-
61
-		return 'WL_Metabox_Field';
62
-	}
63
-
64
-	/**
65
-	 * {@inheritdoc}
66
-	 */
67
-	public function get_metabox_label() {
68
-
69
-		return __( 'Web Site(s)', 'wordlift' );
70
-	}
71
-
72
-	/**
73
-	 * @var
74
-	 */
75
-	private $sparql_service;
76
-
77
-	/**
78
-	 * Create a Wordlift_Schema_Url_Property_Service instance.
79
-	 * @since 3.6.0
80
-	 *
81
-	 * @param Wordlift_Sparql_Service $sparql_service
82
-	 */
83
-	public function __construct( $sparql_service ) {
84
-		parent::__construct();
85
-
86
-		// Finally listen for metadata requests for this field.
87
-		$this->add_filter_get_post_metadata();
88
-
89
-		$this->sparql_service = $sparql_service;
90
-	}
91
-
92
-	/**
93
-	 * Get the schema:url value for the specified post/entity.
94
-	 *
95
-	 * @since 3.6.0
96
-	 *
97
-	 * @param int $post_id The post id.
98
-	 *
99
-	 * @return array|NULL The schema:url value or NULL if not set.
100
-	 */
101
-	public function get( $post_id ) {
102
-
103
-		// Get the schema:url values set in WP.
104
-		$values = get_post_meta( $post_id, self::META_KEY, false );
105
-
106
-		// If the property has never been set, we set its default value the first
107
-		// time to <permalink>.
108
-		if ( 0 === count( $values ) ) {
109
-			return array( '<permalink>' );
110
-		}
111
-
112
-		// If there's only one value and that value is empty, we return NULL, i.e.
113
-		// variable not set.
114
-		if ( 1 === count( $values ) && empty( $values[0] ) ) {
115
-			return null;
116
-		}
117
-
118
-		// Finally return whatever values the editor set.
119
-		return $values;
120
-	}
121
-
122
-	/**
123
-	 * {@inheritdoc}
124
-	 */
125
-	public function sanitize( $value ) {
126
-
127
-		// TODO: check that it's an URL or that is <permalink>
128
-
129
-		return $value;
130
-	}
131
-
132
-	/**
133
-	 * Generate an insert query that inserts the schema:url values for the specified
134
-	 * post.
135
-	 *
136
-	 * @since 3.6.0
137
-	 *
138
-	 * @param string $s       The subject URI.
139
-	 * @param int    $post_id The post id.
140
-	 *
141
-	 * @return string The insert query or an empty string.
142
-	 */
143
-	public function get_insert_query( $s, $post_id ) {
144
-
145
-		// If we have no value, return an empty string (no query).
146
-		if ( null === ( $values = $this->get( $post_id ) ) ) {
147
-			return '';
148
-		}
149
-
150
-		// Create the insert query.
151
-		$q = Wordlift_Query_Builder::new_instance()->insert();
152
-
153
-		// Add each schema:url, replacing <permalink> with the actual post permalink.
154
-		foreach ( $values as $value ) {
155
-			$q = $q->statement( $s, $this->get_rdf_predicate(), '<permalink>' === $value ? get_permalink( $post_id ) : $value, Wordlift_Query_Builder::OBJECT_URI );
156
-		}
157
-
158
-		// Build and return the query.
159
-		return $q->build();
160
-	}
161
-
162
-	/**
163
-	 * Get direct calls to read this meta and alter the response according to our
164
-	 * own strategy, i.e. if a value has never been set for this meta, then return
165
-	 * <permalink>.
166
-	 *
167
-	 * @since 3.6.0
168
-	 *
169
-	 * @param mixed  $value     The original value.
170
-	 * @param int    $object_id The post id.
171
-	 * @param string $meta_key  The meta key. We expect wl_schema_url or we return straight the value.
172
-	 * @param bool   $single    Whether to return a single value.
173
-	 *
174
-	 * @return array|mixed|NULL|string
175
-	 */
176
-	public function get_post_metadata( $value, $object_id, $meta_key, $single ) {
177
-
178
-		// It's not us, return the value.
179
-		if ( self::META_KEY !== $meta_key ) {
180
-			return $value;
181
-		}
182
-
183
-		$this->remove_filter_get_post_metadata();
184
-
185
-		$new_value = $this->get( $object_id );
186
-
187
-		$this->add_filter_get_post_metadata();
188
-
189
-		// If we must return a single value, but we don't have a value, then return an empty string.
190
-		if ( $single && ( is_null( $new_value ) || 0 === count( $new_value ) ) ) {
191
-			return '';
192
-		}
193
-
194
-		// If we have a value and we need to return it as single, return the first value.
195
-		if ( $single ) {
196
-			return $new_value[0];
197
-		}
198
-
199
-		// Otherwise return the array.
200
-		return $new_value;
201
-	}
202
-
203
-	private function add_filter_get_post_metadata() {
204
-
205
-		add_filter( 'get_post_metadata', array(
206
-			$this,
207
-			'get_post_metadata',
208
-		), 10, 4 );
209
-
210
-	}
211
-
212
-	private function remove_filter_get_post_metadata() {
213
-
214
-		remove_filter( 'get_post_metadata', array(
215
-			$this,
216
-			'get_post_metadata',
217
-		), 10 );
218
-
219
-	}
16
+    /**
17
+     * The meta key used to store data for this property. We don't use wl_url to
18
+     * avoid potential confusion about other URLs.
19
+     *
20
+     * @since 3.6.0
21
+     */
22
+    const META_KEY = 'wl_schema_url';
23
+
24
+    /**
25
+     * {@inheritdoc}
26
+     */
27
+    public function get_rdf_predicate() {
28
+
29
+        return 'http://schema.org/url';
30
+    }
31
+
32
+    /**
33
+     * {@inheritdoc}
34
+     */
35
+    public function get_rdf_data_type() {
36
+
37
+        return 'xsd:anyURI';
38
+    }
39
+
40
+    /**
41
+     * {@inheritdoc}
42
+     */
43
+    public function get_data_type() {
44
+
45
+        return Wordlift_Schema_Service::DATA_TYPE_URI;
46
+    }
47
+
48
+    /**
49
+     * {@inheritdoc}
50
+     */
51
+    public function get_cardinality() {
52
+
53
+        return INF;
54
+    }
55
+
56
+    /**
57
+     * {@inheritdoc}
58
+     */
59
+    public function get_metabox_class() {
60
+
61
+        return 'WL_Metabox_Field';
62
+    }
63
+
64
+    /**
65
+     * {@inheritdoc}
66
+     */
67
+    public function get_metabox_label() {
68
+
69
+        return __( 'Web Site(s)', 'wordlift' );
70
+    }
71
+
72
+    /**
73
+     * @var
74
+     */
75
+    private $sparql_service;
76
+
77
+    /**
78
+     * Create a Wordlift_Schema_Url_Property_Service instance.
79
+     * @since 3.6.0
80
+     *
81
+     * @param Wordlift_Sparql_Service $sparql_service
82
+     */
83
+    public function __construct( $sparql_service ) {
84
+        parent::__construct();
85
+
86
+        // Finally listen for metadata requests for this field.
87
+        $this->add_filter_get_post_metadata();
88
+
89
+        $this->sparql_service = $sparql_service;
90
+    }
91
+
92
+    /**
93
+     * Get the schema:url value for the specified post/entity.
94
+     *
95
+     * @since 3.6.0
96
+     *
97
+     * @param int $post_id The post id.
98
+     *
99
+     * @return array|NULL The schema:url value or NULL if not set.
100
+     */
101
+    public function get( $post_id ) {
102
+
103
+        // Get the schema:url values set in WP.
104
+        $values = get_post_meta( $post_id, self::META_KEY, false );
105
+
106
+        // If the property has never been set, we set its default value the first
107
+        // time to <permalink>.
108
+        if ( 0 === count( $values ) ) {
109
+            return array( '<permalink>' );
110
+        }
111
+
112
+        // If there's only one value and that value is empty, we return NULL, i.e.
113
+        // variable not set.
114
+        if ( 1 === count( $values ) && empty( $values[0] ) ) {
115
+            return null;
116
+        }
117
+
118
+        // Finally return whatever values the editor set.
119
+        return $values;
120
+    }
121
+
122
+    /**
123
+     * {@inheritdoc}
124
+     */
125
+    public function sanitize( $value ) {
126
+
127
+        // TODO: check that it's an URL or that is <permalink>
128
+
129
+        return $value;
130
+    }
131
+
132
+    /**
133
+     * Generate an insert query that inserts the schema:url values for the specified
134
+     * post.
135
+     *
136
+     * @since 3.6.0
137
+     *
138
+     * @param string $s       The subject URI.
139
+     * @param int    $post_id The post id.
140
+     *
141
+     * @return string The insert query or an empty string.
142
+     */
143
+    public function get_insert_query( $s, $post_id ) {
144
+
145
+        // If we have no value, return an empty string (no query).
146
+        if ( null === ( $values = $this->get( $post_id ) ) ) {
147
+            return '';
148
+        }
149
+
150
+        // Create the insert query.
151
+        $q = Wordlift_Query_Builder::new_instance()->insert();
152
+
153
+        // Add each schema:url, replacing <permalink> with the actual post permalink.
154
+        foreach ( $values as $value ) {
155
+            $q = $q->statement( $s, $this->get_rdf_predicate(), '<permalink>' === $value ? get_permalink( $post_id ) : $value, Wordlift_Query_Builder::OBJECT_URI );
156
+        }
157
+
158
+        // Build and return the query.
159
+        return $q->build();
160
+    }
161
+
162
+    /**
163
+     * Get direct calls to read this meta and alter the response according to our
164
+     * own strategy, i.e. if a value has never been set for this meta, then return
165
+     * <permalink>.
166
+     *
167
+     * @since 3.6.0
168
+     *
169
+     * @param mixed  $value     The original value.
170
+     * @param int    $object_id The post id.
171
+     * @param string $meta_key  The meta key. We expect wl_schema_url or we return straight the value.
172
+     * @param bool   $single    Whether to return a single value.
173
+     *
174
+     * @return array|mixed|NULL|string
175
+     */
176
+    public function get_post_metadata( $value, $object_id, $meta_key, $single ) {
177
+
178
+        // It's not us, return the value.
179
+        if ( self::META_KEY !== $meta_key ) {
180
+            return $value;
181
+        }
182
+
183
+        $this->remove_filter_get_post_metadata();
184
+
185
+        $new_value = $this->get( $object_id );
186
+
187
+        $this->add_filter_get_post_metadata();
188
+
189
+        // If we must return a single value, but we don't have a value, then return an empty string.
190
+        if ( $single && ( is_null( $new_value ) || 0 === count( $new_value ) ) ) {
191
+            return '';
192
+        }
193
+
194
+        // If we have a value and we need to return it as single, return the first value.
195
+        if ( $single ) {
196
+            return $new_value[0];
197
+        }
198
+
199
+        // Otherwise return the array.
200
+        return $new_value;
201
+    }
202
+
203
+    private function add_filter_get_post_metadata() {
204
+
205
+        add_filter( 'get_post_metadata', array(
206
+            $this,
207
+            'get_post_metadata',
208
+        ), 10, 4 );
209
+
210
+    }
211
+
212
+    private function remove_filter_get_post_metadata() {
213
+
214
+        remove_filter( 'get_post_metadata', array(
215
+            $this,
216
+            'get_post_metadata',
217
+        ), 10 );
218
+
219
+    }
220 220
 
221 221
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function get_metabox_label() {
68 68
 
69
-		return __( 'Web Site(s)', 'wordlift' );
69
+		return __('Web Site(s)', 'wordlift');
70 70
 	}
71 71
 
72 72
 	/**
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @param Wordlift_Sparql_Service $sparql_service
82 82
 	 */
83
-	public function __construct( $sparql_service ) {
83
+	public function __construct($sparql_service) {
84 84
 		parent::__construct();
85 85
 
86 86
 		// Finally listen for metadata requests for this field.
@@ -98,20 +98,20 @@  discard block
 block discarded – undo
98 98
 	 *
99 99
 	 * @return array|NULL The schema:url value or NULL if not set.
100 100
 	 */
101
-	public function get( $post_id ) {
101
+	public function get($post_id) {
102 102
 
103 103
 		// Get the schema:url values set in WP.
104
-		$values = get_post_meta( $post_id, self::META_KEY, false );
104
+		$values = get_post_meta($post_id, self::META_KEY, false);
105 105
 
106 106
 		// If the property has never been set, we set its default value the first
107 107
 		// time to <permalink>.
108
-		if ( 0 === count( $values ) ) {
109
-			return array( '<permalink>' );
108
+		if (0 === count($values)) {
109
+			return array('<permalink>');
110 110
 		}
111 111
 
112 112
 		// If there's only one value and that value is empty, we return NULL, i.e.
113 113
 		// variable not set.
114
-		if ( 1 === count( $values ) && empty( $values[0] ) ) {
114
+		if (1 === count($values) && empty($values[0])) {
115 115
 			return null;
116 116
 		}
117 117
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	/**
123 123
 	 * {@inheritdoc}
124 124
 	 */
125
-	public function sanitize( $value ) {
125
+	public function sanitize($value) {
126 126
 
127 127
 		// TODO: check that it's an URL or that is <permalink>
128 128
 
@@ -140,10 +140,10 @@  discard block
 block discarded – undo
140 140
 	 *
141 141
 	 * @return string The insert query or an empty string.
142 142
 	 */
143
-	public function get_insert_query( $s, $post_id ) {
143
+	public function get_insert_query($s, $post_id) {
144 144
 
145 145
 		// If we have no value, return an empty string (no query).
146
-		if ( null === ( $values = $this->get( $post_id ) ) ) {
146
+		if (null === ($values = $this->get($post_id))) {
147 147
 			return '';
148 148
 		}
149 149
 
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
 		$q = Wordlift_Query_Builder::new_instance()->insert();
152 152
 
153 153
 		// Add each schema:url, replacing <permalink> with the actual post permalink.
154
-		foreach ( $values as $value ) {
155
-			$q = $q->statement( $s, $this->get_rdf_predicate(), '<permalink>' === $value ? get_permalink( $post_id ) : $value, Wordlift_Query_Builder::OBJECT_URI );
154
+		foreach ($values as $value) {
155
+			$q = $q->statement($s, $this->get_rdf_predicate(), '<permalink>' === $value ? get_permalink($post_id) : $value, Wordlift_Query_Builder::OBJECT_URI);
156 156
 		}
157 157
 
158 158
 		// Build and return the query.
@@ -173,26 +173,26 @@  discard block
 block discarded – undo
173 173
 	 *
174 174
 	 * @return array|mixed|NULL|string
175 175
 	 */
176
-	public function get_post_metadata( $value, $object_id, $meta_key, $single ) {
176
+	public function get_post_metadata($value, $object_id, $meta_key, $single) {
177 177
 
178 178
 		// It's not us, return the value.
179
-		if ( self::META_KEY !== $meta_key ) {
179
+		if (self::META_KEY !== $meta_key) {
180 180
 			return $value;
181 181
 		}
182 182
 
183 183
 		$this->remove_filter_get_post_metadata();
184 184
 
185
-		$new_value = $this->get( $object_id );
185
+		$new_value = $this->get($object_id);
186 186
 
187 187
 		$this->add_filter_get_post_metadata();
188 188
 
189 189
 		// If we must return a single value, but we don't have a value, then return an empty string.
190
-		if ( $single && ( is_null( $new_value ) || 0 === count( $new_value ) ) ) {
190
+		if ($single && (is_null($new_value) || 0 === count($new_value))) {
191 191
 			return '';
192 192
 		}
193 193
 
194 194
 		// If we have a value and we need to return it as single, return the first value.
195
-		if ( $single ) {
195
+		if ($single) {
196 196
 			return $new_value[0];
197 197
 		}
198 198
 
@@ -202,19 +202,19 @@  discard block
 block discarded – undo
202 202
 
203 203
 	private function add_filter_get_post_metadata() {
204 204
 
205
-		add_filter( 'get_post_metadata', array(
205
+		add_filter('get_post_metadata', array(
206 206
 			$this,
207 207
 			'get_post_metadata',
208
-		), 10, 4 );
208
+		), 10, 4);
209 209
 
210 210
 	}
211 211
 
212 212
 	private function remove_filter_get_post_metadata() {
213 213
 
214
-		remove_filter( 'get_post_metadata', array(
214
+		remove_filter('get_post_metadata', array(
215 215
 			$this,
216 216
 			'get_post_metadata',
217
-		), 10 );
217
+		), 10);
218 218
 
219 219
 	}
220 220
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-schema-service.php 2 patches
Indentation   +945 added lines, -945 removed lines patch added patch discarded remove patch
@@ -15,950 +15,950 @@
 block discarded – undo
15 15
  */
16 16
 class Wordlift_Schema_Service {
17 17
 
18
-	/**
19
-	 * The 'location created' field name.
20
-	 *
21
-	 * @since 3.5.0
22
-	 */
23
-	const FIELD_LOCATION_CREATED = 'wl_location_created';
24
-
25
-	/**
26
-	 * The 'topic' field name.
27
-	 *
28
-	 * @since 3.5.0
29
-	 */
30
-	const FIELD_TOPIC = 'wl_topic';
31
-
32
-	/**
33
-	 * The 'author' field name.
34
-	 *
35
-	 * @since 3.1.0
36
-	 */
37
-	const FIELD_AUTHOR = 'wl_author';
38
-
39
-	/**
40
-	 * The 'same as' field name.
41
-	 *
42
-	 * @since 3.1.0
43
-	 */
44
-	const FIELD_SAME_AS = 'entity_same_as';
45
-
46
-	/**
47
-	 * The 'date start' field name.
48
-	 *
49
-	 * @since 3.1.0
50
-	 */
51
-	const FIELD_DATE_START = 'wl_cal_date_start';
52
-
53
-	/**
54
-	 * The 'date end' field name.
55
-	 *
56
-	 * @since 3.1.0
57
-	 */
58
-	const FIELD_DATE_END = 'wl_cal_date_end';
59
-
60
-	/**
61
-	 * The 'location' field name.
62
-	 *
63
-	 * @since 3.1.0
64
-	 */
65
-	const FIELD_LOCATION = 'wl_location';
66
-
67
-	/**
68
-	 * The 'founder' field name.
69
-	 *
70
-	 * @since 3.1.0
71
-	 */
72
-	const FIELD_FOUNDER = 'wl_founder';
73
-
74
-	/**
75
-	 * The 'knows' field name.
76
-	 *
77
-	 * @since 3.1.0
78
-	 */
79
-	const FIELD_KNOWS = 'wl_knows';
80
-
81
-	/**
82
-	 * The 'birth date' field name.
83
-	 *
84
-	 * @since 3.1.0
85
-	 */
86
-	const FIELD_BIRTH_DATE = 'wl_birth_date';
87
-
88
-	/**
89
-	 * The 'birth place' field name.
90
-	 *
91
-	 * @since 3.1.0
92
-	 */
93
-	const FIELD_BIRTH_PLACE = 'wl_birth_place';
94
-
95
-	/**
96
-	 * The 'latitude' field name.
97
-	 *
98
-	 * @since 3.1.0
99
-	 */
100
-	const FIELD_GEO_LATITUDE = 'wl_geo_latitude';
101
-
102
-	/**
103
-	 * The 'longitude' field name.
104
-	 *
105
-	 * @since 3.1.0
106
-	 */
107
-	const FIELD_GEO_LONGITUDE = 'wl_geo_longitude';
108
-
109
-	/**
110
-	 * The 'streetAddress' field name.
111
-	 *
112
-	 * @since 3.1.0
113
-	 */
114
-	const FIELD_ADDRESS = 'wl_address';
115
-
116
-	/**
117
-	 * The 'postOfficeBoxNumber' field name.
118
-	 *
119
-	 * @since 3.3.0
120
-	 */
121
-	const FIELD_ADDRESS_PO_BOX = 'wl_address_post_office_box';
122
-
123
-	/**
124
-	 * The 'postalCode' field name.
125
-	 *
126
-	 * @since 3.3.0
127
-	 */
128
-	const FIELD_ADDRESS_POSTAL_CODE = 'wl_address_postal_code';
129
-
130
-	/**
131
-	 * The 'addressLocality' field name.
132
-	 *
133
-	 * @since 3.3.0
134
-	 */
135
-	const FIELD_ADDRESS_LOCALITY = 'wl_address_locality';
136
-	/**
137
-	 * The 'addressRegion' field name.
138
-	 *
139
-	 * @since 3.3.0
140
-	 */
141
-	const FIELD_ADDRESS_REGION = 'wl_address_region';
142
-
143
-	/**
144
-	 * The 'addressCountry' field name.
145
-	 *
146
-	 * @since 3.3.0
147
-	 */
148
-	const FIELD_ADDRESS_COUNTRY = 'wl_address_country';
149
-
150
-	/**
151
-	 * The 'entity type' field name.
152
-	 *
153
-	 * @since 3.1.0
154
-	 */
155
-	const FIELD_ENTITY_TYPE = 'wl_entity_type_uri';
156
-
157
-	/**
158
-	 * The 'email' field name.
159
-	 *
160
-	 * @since 3.2.0
161
-	 */
162
-	const FIELD_EMAIL = 'wl_email';
163
-
164
-	/**
165
-	 * The 'affiliation' field name.
166
-	 *
167
-	 * @since 3.2.0
168
-	 */
169
-	const FIELD_AFFILIATION = 'wl_affiliation';
170
-
171
-	/**
172
-	 * The 'telephone' field name.
173
-	 *
174
-	 * @since 3.8.0
175
-	 */
176
-	const FIELD_TELEPHONE = 'wl_schema_telephone';
177
-
178
-	/**
179
-	 * The 'legalName' field name.
180
-	 *
181
-	 * @since 3.12.0
182
-	 */
183
-	const FIELD_LEGAL_NAME = 'wl_schema_legal_name';
184
-
185
-	/**
186
-	 * The 'recipeCuisine' field name.
187
-	 *
188
-	 * @since 3.14.0
189
-	 */
190
-	const FIELD_RECIPE_CUISINE = 'wl_schema_recipe_cuisine';
191
-
192
-	/**
193
-	 * The 'recipeIngredient' field name.
194
-	 *
195
-	 * @since 3.14.0
196
-	 */
197
-	const FIELD_RECIPE_INGREDIENT = 'wl_schema_recipe_ingredient';
198
-
199
-	/**
200
-	 * The 'recipeInstructions' field name.
201
-	 *
202
-	 * @since 3.14.0
203
-	 */
204
-	const FIELD_RECIPE_INSTRUCTIONS = 'wl_schema_recipe_instructions';
205
-
206
-	/**
207
-	 * The 'recipeYield' field name.
208
-	 *
209
-	 * @since 3.14.0
210
-	 */
211
-	const FIELD_RECIPE_YIELD = 'wl_schema_recipe_yield';
212
-
213
-	/**
214
-	 * The 'prepTime' field name.
215
-	 *
216
-	 * @since 3.14.0
217
-	 */
218
-	const FIELD_PREP_TIME = 'wl_schema_prep_time';
219
-
220
-	/**
221
-	 * The 'totalTime' field name.
222
-	 *
223
-	 * @since 3.14.0
224
-	 */
225
-	const FIELD_TOTAL_TIME = 'wl_schema_total_time';
226
-
227
-	/**
228
-	 * The 'URI' data type name.
229
-	 *
230
-	 * @since 3.1.0
231
-	 */
232
-	const DATA_TYPE_URI = 'uri';
233
-
234
-	/**
235
-	 * The 'date' data type name.
236
-	 *
237
-	 * @since 3.1.0
238
-	 */
239
-	const DATA_TYPE_DATE = 'date';
240
-
241
-	/**
242
-	 * The 'time' data type name.
243
-	 *
244
-	 * @since 3.14.0
245
-	 */
246
-	const DATA_TYPE_DURATION = 'duration';
247
-
248
-	/**
249
-	 * The 'double' data type name.
250
-	 *
251
-	 * @since 3.1.0
252
-	 */
253
-	const DATA_TYPE_DOUBLE = 'double';
254
-
255
-	/**
256
-	 * The 'string' data type name.
257
-	 *
258
-	 * @since 3.1.0
259
-	 */
260
-	const DATA_TYPE_STRING = 'string';
261
-
262
-	/**
263
-	 * The multiline text data type name.
264
-	 *
265
-	 * @since 3.14.0
266
-	 */
267
-	const DATA_TYPE_MULTILINE = 'multiline';
268
-
269
-	/**
270
-	 * The 'integer' data type name.
271
-	 *
272
-	 * @since 3.1.0
273
-	 */
274
-	const DATA_TYPE_INTEGER = 'int';
275
-
276
-	/**
277
-	 * The 'boolean' data type name.
278
-	 *
279
-	 * @since 3.1.0
280
-	 */
281
-	const DATA_TYPE_BOOLEAN = 'bool';
282
-
283
-	/**
284
-	 * The schema.org Event type URI.
285
-	 *
286
-	 * @since 3.1.0
287
-	 */
288
-	const SCHEMA_EVENT_TYPE = 'http://schema.org/Event';
289
-
290
-	/**
291
-	 * The Schema service singleton instance.
292
-	 *
293
-	 * @since  3.1.0
294
-	 * @access private
295
-	 * @var \Wordlift_Schema_Service $instance The Schema service singleton instance.
296
-	 */
297
-	private static $instance;
298
-
299
-	/**
300
-	 * WordLift's schema.
301
-	 *
302
-	 * @since  3.1.0
303
-	 * @access private
304
-	 * @var array $schema WordLift's schema.
305
-	 */
306
-	private $schema;
307
-
308
-	/**
309
-	 * The Log service.
310
-	 *
311
-	 * @since  3.1.0
312
-	 * @access private
313
-	 * @var \Wordlift_Log_Service $log_service The Log service.
314
-	 */
315
-	private $log_service;
316
-
317
-	/**
318
-	 * Wordlift_Schema_Service constructor.
319
-	 *
320
-	 * @since 3.1.0
321
-	 */
322
-	public function __construct() {
323
-
324
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
325
-
326
-		// Create a singleton instance of the Schema service, useful to provide static functions to global functions.
327
-		self::$instance = $this;
328
-
329
-		// Set the taxonomy data.
330
-		// Note: parent types must be defined before child types.
331
-		$this->schema = array(
332
-			'thing'         => $this->get_thing_schema(),
333
-			'creative-work' => $this->get_creative_work_schema(),
334
-			'event'         => $this->get_event_schema(),
335
-			'organization'  => $this->get_organization_schema(),
336
-			'person'        => $this->get_person_schema(),
337
-			'place'         => $this->get_place_schema(),
338
-			'localbusiness' => $this->get_local_business_schema(),
339
-			'recipe'        => $this->get_recipe_schema(),
340
-		);
341
-
342
-	}
343
-
344
-	/**
345
-	 * Get a reference to the Schema service.
346
-	 *
347
-	 * @since 3.1.0
348
-	 *
349
-	 * @return Wordlift_Schema_Service A reference to the Schema service.
350
-	 */
351
-	public static function get_instance() {
352
-
353
-		return self::$instance;
354
-	}
355
-
356
-	/**
357
-	 * Get the properties for a field with the specified key. The key is used as
358
-	 * meta key when the field's value is stored in WordPress meta data table.
359
-	 *
360
-	 * @since 3.6.0
361
-	 *
362
-	 * @param string $key The field's key.
363
-	 *
364
-	 * @return null|array An array of field's properties or null if the field is not found.
365
-	 */
366
-	public function get_field( $key ) {
367
-
368
-		// Parse each schema's fields until we find the one we're looking for, then
369
-		// return its properties.
370
-		foreach ( $this->schema as $_ => $schema ) {
371
-
372
-			if ( ! isset( $schema['custom_fields'] ) ) {
373
-				break;
374
-			}
375
-
376
-			foreach ( $schema['custom_fields'] as $field => $props ) {
377
-				if ( $key === $field ) {
378
-					return $props;
379
-				}
380
-			}
381
-		}
382
-
383
-		return null;
384
-	}
385
-
386
-	/**
387
-	 * Get the WordLift's schema.
388
-	 *
389
-	 * @param string $name The schema name.
390
-	 *
391
-	 * @return array|null An array with the schema configuration or NULL if the schema is not found.
392
-	 *
393
-	 * @since 3.1.0
394
-	 */
395
-	public function get_schema( $name ) {
396
-
397
-		// Check if the schema exists and, if not, return NULL.
398
-		if ( ! isset( $this->schema[ $name ] ) ) {
399
-			return null;
400
-		}
401
-
402
-		// Return the requested schema.
403
-		return $this->schema[ $name ];
404
-	}
405
-
406
-	/**
407
-	 * Get the WordLift's schema trough schema type uri.
408
-	 *
409
-	 * @param string $uri The schema uri.
410
-	 *
411
-	 * @return array|null An array with the schema configuration or NULL if the schema is not found.
412
-	 *
413
-	 * @since 3.3.0
414
-	 */
415
-	public function get_schema_by_uri( $uri ) {
416
-
417
-		foreach ( $this->schema as $name => $schema ) {
418
-			if ( $schema['uri'] === $uri ) {
419
-				return $schema;
420
-			}
421
-		}
422
-
423
-		return null;
424
-	}
425
-
426
-	/**
427
-	 * Get the 'thing' schema.
428
-	 *
429
-	 * @return array An array with the schema configuration.
430
-	 *
431
-	 * @since 3.1.0
432
-	 */
433
-	private function get_thing_schema() {
434
-
435
-		return array(
436
-			'css_class'     => 'wl-thing',
437
-			'uri'           => 'http://schema.org/Thing',
438
-			'same_as'       => array( '*' ),
439
-			// set as default.
440
-			'custom_fields' => array(
441
-				self::FIELD_SAME_AS                            => array(
442
-					'predicate'   => 'http://schema.org/sameAs',
443
-					'type'        => self::DATA_TYPE_URI,
444
-					'export_type' => 'http://schema.org/Thing',
445
-					'constraints' => array(
446
-						'cardinality' => INF,
447
-					),
448
-					// We need a custom metabox.
449
-					'input_field' => 'sameas',
450
-				),
451
-				// Add the schema:url property.
452
-				Wordlift_Schema_Url_Property_Service::META_KEY => Wordlift_Schema_Url_Property_Service::get_instance()
453
-				                                                                                      ->get_compat_definition(),
454
-			),
455
-			// {{sameAs}} not present in the microdata template,
456
-			// because it is treated separately in *wl_content_embed_item_microdata*
457
-			'templates'     => array(
458
-				'subtitle' => '{{id}}',
459
-			),
460
-		);
461
-
462
-	}
463
-
464
-	/**
465
-	 * Get the 'creative work' schema.
466
-	 *
467
-	 * @return array An array with the schema configuration.
468
-	 *
469
-	 * @since 3.1.0
470
-	 */
471
-	private function get_creative_work_schema() {
472
-
473
-		$schema = array(
474
-			'label'         => 'CreativeWork',
475
-			'description'   => 'A creative work (or a Music Album).',
476
-			'parents'       => array( 'thing' ),
477
-			// Give term slug as parent.
478
-			'css_class'     => 'wl-creative-work',
479
-			'uri'           => 'http://schema.org/CreativeWork',
480
-			'same_as'       => array(
481
-				'http://schema.org/MusicAlbum',
482
-				'http://schema.org/Product',
483
-			),
484
-			'custom_fields' => array(
485
-				self::FIELD_AUTHOR => array(
486
-					'predicate'   => 'http://schema.org/author',
487
-					'type'        => self::DATA_TYPE_URI,
488
-					'export_type' => 'http://schema.org/Person',
489
-					'constraints' => array(
490
-						'uri_type'    => array( 'Person', 'Organization' ),
491
-						'cardinality' => INF,
492
-					),
493
-				),
494
-			),
495
-			'templates'     => array(
496
-				'subtitle' => '{{id}}',
497
-			),
498
-		);
499
-
500
-		// Merge the custom fields with those provided by the thing schema.
501
-		$thing_schema            = $this->get_thing_schema();
502
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
503
-
504
-		return $schema;
505
-	}
506
-
507
-	/**
508
-	 * Get the 'event' schema.
509
-	 *
510
-	 * @return array An array with the schema configuration.
511
-	 *
512
-	 * @since 3.1.0
513
-	 */
514
-	private function get_event_schema() {
515
-
516
-		$schema = array(
517
-			'label'         => 'Event',
518
-			'description'   => 'An event . ',
519
-			'parents'       => array( 'thing' ),
520
-			'css_class'     => 'wl-event',
521
-			'uri'           => self::SCHEMA_EVENT_TYPE,
522
-			'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
523
-			'custom_fields' => array(
524
-				self::FIELD_DATE_START => array(
525
-					'predicate'   => 'http://schema.org/startDate',
526
-					'type'        => self::DATA_TYPE_DATE,
527
-					'export_type' => 'xsd:datetime',
528
-					'constraints' => '',
529
-				),
530
-				self::FIELD_DATE_END   => array(
531
-					'predicate'   => 'http://schema.org/endDate',
532
-					'type'        => self::DATA_TYPE_DATE,
533
-					'export_type' => 'xsd:datetime',
534
-					'constraints' => '',
535
-				),
536
-				self::FIELD_LOCATION   => array(
537
-					'predicate'   => 'http://schema.org/location',
538
-					'type'        => self::DATA_TYPE_URI,
539
-					'export_type' => 'http://schema.org/PostalAddress',
540
-					'constraints' => array(
541
-						'uri_type'    => array( 'Place', 'LocalBusiness' ),
542
-						'cardinality' => INF,
543
-					),
544
-				),
545
-			),
546
-			'templates'     => array(
547
-				'subtitle' => '{{id}}',
548
-			),
549
-		);
550
-
551
-		// Merge the custom fields with those provided by the thing schema.
552
-		$thing_schema            = $this->get_thing_schema();
553
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
554
-
555
-		return $schema;
556
-	}
557
-
558
-	/**
559
-	 * Get the 'organization' schema.
560
-	 *
561
-	 * @return array An array with the schema configuration.
562
-	 *
563
-	 * @since 3.1.0
564
-	 */
565
-	private function get_organization_schema() {
566
-
567
-		$schema = array(
568
-			'label'         => 'Organization',
569
-			'description'   => 'An organization, including a government or a newspaper.',
570
-			'parents'       => array( 'thing' ),
571
-			'css_class'     => 'wl-organization',
572
-			'uri'           => 'http://schema.org/Organization',
573
-			'same_as'       => array(
574
-				'http://rdf.freebase.com/ns/organization.organization',
575
-				'http://rdf.freebase.com/ns/government.government',
576
-				'http://schema.org/Newspaper',
577
-			),
578
-			'custom_fields' => array(
579
-				self::FIELD_LEGAL_NAME          => array(
580
-					'predicate'   => 'http://schema.org/legalName',
581
-					'type'        => self::DATA_TYPE_STRING,
582
-					'export_type' => 'xsd:string',
583
-					'constraints' => '',
584
-				),
585
-				self::FIELD_FOUNDER             => array(
586
-					'predicate'   => 'http://schema.org/founder',
587
-					'type'        => self::DATA_TYPE_URI,
588
-					'export_type' => 'http://schema.org/Person',
589
-					'constraints' => array(
590
-						'uri_type'    => 'Person',
591
-						'cardinality' => INF,
592
-					),
593
-				),
594
-				self::FIELD_ADDRESS             => array(
595
-					'predicate'   => 'http://schema.org/streetAddress',
596
-					'type'        => self::DATA_TYPE_STRING,
597
-					'export_type' => 'xsd:string',
598
-					'constraints' => '',
599
-					// To build custom metabox.
600
-					'input_field' => 'address',
601
-				),
602
-				self::FIELD_ADDRESS_PO_BOX      => array(
603
-					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
604
-					'type'        => self::DATA_TYPE_STRING,
605
-					'export_type' => 'xsd:string',
606
-					'constraints' => '',
607
-					// To build custom metabox.
608
-					'input_field' => 'address',
609
-				),
610
-				self::FIELD_ADDRESS_POSTAL_CODE => array(
611
-					'predicate'   => 'http://schema.org/postalCode',
612
-					'type'        => self::DATA_TYPE_STRING,
613
-					'export_type' => 'xsd:string',
614
-					'constraints' => '',
615
-					// To build custom metabox.
616
-					'input_field' => 'address',
617
-				),
618
-				self::FIELD_ADDRESS_LOCALITY    => array(
619
-					'predicate'   => 'http://schema.org/addressLocality',
620
-					'type'        => self::DATA_TYPE_STRING,
621
-					'export_type' => 'xsd:string',
622
-					'constraints' => '',
623
-					// To build custom metabox.
624
-					'input_field' => 'address',
625
-				),
626
-				self::FIELD_ADDRESS_REGION      => array(
627
-					'predicate'   => 'http://schema.org/addressRegion',
628
-					'type'        => self::DATA_TYPE_STRING,
629
-					'export_type' => 'xsd:string',
630
-					'constraints' => '',
631
-					// To build custom metabox.
632
-					'input_field' => 'address',
633
-				),
634
-				self::FIELD_ADDRESS_COUNTRY     => array(
635
-					'predicate'   => 'http://schema.org/addressCountry',
636
-					'type'        => self::DATA_TYPE_STRING,
637
-					'export_type' => 'xsd:string',
638
-					'constraints' => '',
639
-					// To build custom metabox.
640
-					'input_field' => 'address',
641
-				),
642
-				self::FIELD_EMAIL               => array(
643
-					'predicate'   => 'http://schema.org/email',
644
-					'type'        => self::DATA_TYPE_STRING,
645
-					'export_type' => 'xsd:string',
646
-					'constraints' => '',
647
-				),
648
-				self::FIELD_TELEPHONE           => array(
649
-					'predicate'   => 'http://schema.org/telephone',
650
-					'type'        => self::DATA_TYPE_STRING,
651
-					'export_type' => 'xsd:string',
652
-					'constraints' => '',
653
-				),
654
-			),
655
-			'templates'     => array(
656
-				'subtitle' => '{{id}}',
657
-			),
658
-		);
659
-
660
-		// Merge the custom fields with those provided by the thing schema.
661
-		$thing_schema            = $this->get_thing_schema();
662
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
663
-
664
-		return $schema;
665
-	}
666
-
667
-	/**
668
-	 * Get the 'person' schema.
669
-	 *
670
-	 * @return array An array with the schema configuration.
671
-	 *
672
-	 * @since 3.1.0
673
-	 */
674
-	private function get_person_schema() {
675
-
676
-		$schema = array(
677
-			'label'         => 'Person',
678
-			'description'   => 'A person (or a music artist).',
679
-			'parents'       => array( 'thing' ),
680
-			'css_class'     => 'wl-person',
681
-			'uri'           => 'http://schema.org/Person',
682
-			'same_as'       => array(
683
-				'http://rdf.freebase.com/ns/people.person',
684
-				'http://rdf.freebase.com/ns/music.artist',
685
-				'http://dbpedia.org/class/yago/LivingPeople',
686
-			),
687
-			'custom_fields' => array(
688
-				self::FIELD_KNOWS       => array(
689
-					'predicate'   => 'http://schema.org/knows',
690
-					'type'        => self::DATA_TYPE_URI,
691
-					'export_type' => 'http://schema.org/Person',
692
-					'constraints' => array(
693
-						'uri_type'    => 'Person',
694
-						'cardinality' => INF,
695
-					),
696
-				),
697
-				self::FIELD_BIRTH_DATE  => array(
698
-					'predicate'   => 'http://schema.org/birthDate',
699
-					'type'        => self::DATA_TYPE_DATE,
700
-					'export_type' => 'xsd:date',
701
-					'constraints' => '',
702
-				),
703
-				self::FIELD_BIRTH_PLACE => array(
704
-					'predicate'   => 'http://schema.org/birthPlace',
705
-					'type'        => self::DATA_TYPE_URI,
706
-					'export_type' => 'http://schema.org/Place',
707
-					'constraints' => array(
708
-						'uri_type' => 'Place',
709
-					),
710
-				),
711
-				self::FIELD_AFFILIATION => array(
712
-					'predicate'   => 'http://schema.org/affiliation',
713
-					'type'        => self::DATA_TYPE_URI,
714
-					'export_type' => 'http://schema.org/Organization',
715
-					'constraints' => array(
716
-						'uri_type'    => array(
717
-							'Organization',
718
-							'LocalBusiness',
719
-						),
720
-						'cardinality' => INF,
721
-					),
722
-				),
723
-				self::FIELD_EMAIL       => array(
724
-					'predicate'   => 'http://schema.org/email',
725
-					'type'        => self::DATA_TYPE_STRING,
726
-					'export_type' => 'xsd:string',
727
-					'constraints' => array(
728
-						'cardinality' => INF,
729
-					),
730
-				),
731
-			),
732
-			'templates'     => array(
733
-				'subtitle' => '{{id}}',
734
-			),
735
-		);
736
-
737
-		// Merge the custom fields with those provided by the thing schema.
738
-		$thing_schema            = $this->get_thing_schema();
739
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
740
-
741
-		return $schema;
742
-
743
-	}
744
-
745
-	/**
746
-	 * Get the 'place' schema.
747
-	 *
748
-	 * @return array An array with the schema configuration.
749
-	 *
750
-	 * @since 3.1.0
751
-	 */
752
-	private function get_place_schema() {
753
-
754
-		$schema = array(
755
-			'label'         => 'Place',
756
-			'description'   => 'A place.',
757
-			'parents'       => array( 'thing' ),
758
-			'css_class'     => 'wl-place',
759
-			'uri'           => 'http://schema.org/Place',
760
-			'same_as'       => array(
761
-				'http://rdf.freebase.com/ns/location.location',
762
-				'http://www.opengis.net/gml/_Feature',
763
-			),
764
-			'custom_fields' => array(
765
-				self::FIELD_GEO_LATITUDE        => array(
766
-					'predicate'   => 'http://schema.org/latitude',
767
-					'type'        => self::DATA_TYPE_DOUBLE,
768
-					'export_type' => 'xsd:double',
769
-					'constraints' => '',
770
-					// To build custom metabox.
771
-					'input_field' => 'coordinates',
772
-				),
773
-				self::FIELD_GEO_LONGITUDE       => array(
774
-					'predicate'   => 'http://schema.org/longitude',
775
-					'type'        => self::DATA_TYPE_DOUBLE,
776
-					'export_type' => 'xsd:double',
777
-					'constraints' => '',
778
-					// To build custom metabox.
779
-					'input_field' => 'coordinates',
780
-				),
781
-				self::FIELD_ADDRESS             => array(
782
-					'predicate'   => 'http://schema.org/streetAddress',
783
-					'type'        => self::DATA_TYPE_STRING,
784
-					'export_type' => 'xsd:string',
785
-					'constraints' => '',
786
-					// To build custom metabox.
787
-					'input_field' => 'address',
788
-				),
789
-				self::FIELD_ADDRESS_PO_BOX      => array(
790
-					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
791
-					'type'        => self::DATA_TYPE_STRING,
792
-					'export_type' => 'xsd:string',
793
-					'constraints' => '',
794
-					// To build custom metabox.
795
-					'input_field' => 'address',
796
-				),
797
-				self::FIELD_ADDRESS_POSTAL_CODE => array(
798
-					'predicate'   => 'http://schema.org/postalCode',
799
-					'type'        => self::DATA_TYPE_STRING,
800
-					'export_type' => 'xsd:string',
801
-					'constraints' => '',
802
-					// To build custom metabox.
803
-					'input_field' => 'address',
804
-				),
805
-				self::FIELD_ADDRESS_LOCALITY    => array(
806
-					'predicate'   => 'http://schema.org/addressLocality',
807
-					'type'        => self::DATA_TYPE_STRING,
808
-					'export_type' => 'xsd:string',
809
-					'constraints' => '',
810
-					// To build custom metabox.
811
-					'input_field' => 'address',
812
-				),
813
-				self::FIELD_ADDRESS_REGION      => array(
814
-					'predicate'   => 'http://schema.org/addressRegion',
815
-					'type'        => self::DATA_TYPE_STRING,
816
-					'export_type' => 'xsd:string',
817
-					'constraints' => '',
818
-					// To build custom metabox.
819
-					'input_field' => 'address',
820
-				),
821
-				self::FIELD_ADDRESS_COUNTRY     => array(
822
-					'predicate'   => 'http://schema.org/addressCountry',
823
-					'type'        => self::DATA_TYPE_STRING,
824
-					'export_type' => 'xsd:string',
825
-					'constraints' => '',
826
-					// To build custom metabox.
827
-					'input_field' => 'address',
828
-				),
829
-			),
830
-			'templates'     => array(
831
-				'subtitle' => '{{id}}',
832
-			),
833
-		);
834
-
835
-		// Merge the custom fields with those provided by the thing schema.
836
-		$thing_schema            = $this->get_thing_schema();
837
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
838
-
839
-		return $schema;
840
-	}
841
-
842
-	/**
843
-	 * Get the 'local business' schema.
844
-	 *
845
-	 * @return array An array with the schema configuration.
846
-	 *
847
-	 * @since 3.1.0
848
-	 */
849
-	private function get_local_business_schema() {
850
-
851
-		$schema = array(
852
-			'label'         => 'LocalBusiness',
853
-			'description'   => 'A local business.',
854
-			'parents'       => array( 'place', 'organization' ),
855
-			'css_class'     => 'wl-local-business',
856
-			'uri'           => 'http://schema.org/LocalBusiness',
857
-			'same_as'       => array(
858
-				'http://rdf.freebase.com/ns/business/business_location',
859
-				'https://schema.org/Store',
860
-			),
861
-			'custom_fields' => array(),
862
-			'templates'     => array(
863
-				'subtitle' => '{{id}}',
864
-			),
865
-		);
866
-
867
-		// Merge the custom fields with those provided by the place and organization schema.
868
-		$place_schema            = $this->get_place_schema();
869
-		$organization_schema     = $this->get_organization_schema();
870
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
871
-
872
-		return $schema;
873
-	}
874
-
875
-	/**
876
-	 * Get the 'recipe' schema.
877
-	 *
878
-	 * @return array An array with the schema configuration.
879
-	 *
880
-	 * @since 3.14.0
881
-	 */
882
-	private function get_recipe_schema() {
883
-
884
-		$schema = array(
885
-			'label'         => 'Recipe',
886
-			'description'   => 'A Recipe.',
887
-			'parents'       => array( 'CreativeWork' ),
888
-			'css_class'     => 'wl-recipe',
889
-			'uri'           => 'http://schema.org/Recipe',
890
-			'same_as'       => array(),
891
-			'templates'     => array(
892
-				'subtitle' => '{{id}}',
893
-			),
894
-			'custom_fields' => array(
895
-				self::FIELD_RECIPE_CUISINE      => array(
896
-					'predicate'   => 'http://schema.org/recipeCuisine',
897
-					'type'        => self::DATA_TYPE_STRING,
898
-					'export_type' => 'xsd:string',
899
-					'constraints' => '',
900
-					'metabox'     => array(
901
-						'label' => __( 'Recipe cuisine', 'wordlift' ),
902
-					),
903
-				),
904
-				self::FIELD_RECIPE_INGREDIENT   => array(
905
-					'predicate'   => 'http://schema.org/recipeIngredient',
906
-					'type'        => self::DATA_TYPE_STRING,
907
-					'export_type' => 'xsd:string',
908
-					'constraints' => array(
909
-						'cardinality' => INF,
910
-					),
911
-					'metabox'     => array(
912
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
913
-					),
914
-				),
915
-				self::FIELD_RECIPE_INSTRUCTIONS => array(
916
-					'predicate'   => 'http://schema.org/recipeInstructions',
917
-					'type'        => self::DATA_TYPE_MULTILINE,
918
-					'export_type' => 'xsd:string',
919
-					'constraints' => '',
920
-					'metabox'     => array(
921
-						'class' => 'Wordlift_Metabox_Field_Multiline',
922
-						'label' => __( 'Recipe instructions', 'wordlift' ),
923
-					),
924
-				),
925
-				self::FIELD_RECIPE_YIELD        => array(
926
-					'predicate'   => 'http://schema.org/recipeYield',
927
-					'type'        => self::DATA_TYPE_STRING,
928
-					'export_type' => 'xsd:string',
929
-					'constraints' => '',
930
-					'metabox'     => array(
931
-						'label' => __( 'Recipe number of servings', 'wordlift' ),
932
-					),
933
-				),
934
-				self::FIELD_PREP_TIME           => array(
935
-					'predicate'   => 'http://schema.org/prepTime',
936
-					'type'        => self::DATA_TYPE_DURATION,
937
-					'export_type' => 'xsd:time',
938
-					'constraints' => '',
939
-					'metabox'     => array(
940
-						'class' => 'Wordlift_Metabox_Field_Duration',
941
-						'label' => __( 'Recipe preparation time', 'wordlift' ),
942
-					),
943
-				),
944
-				self::FIELD_TOTAL_TIME          => array(
945
-					'predicate'   => 'http://schema.org/totalTime',
946
-					'type'        => self::DATA_TYPE_DURATION,
947
-					'export_type' => 'xsd:time',
948
-					'constraints' => '',
949
-					'metabox'     => array(
950
-						'class' => 'Wordlift_Metabox_Field_Duration',
951
-						'label' => __( 'Recipe total time', 'wordlift' ),
952
-					),
953
-				),
954
-			),
955
-		);
956
-
957
-		// Merge the custom fields with those provided by the parent schema.
958
-		$parent_schema           = $this->get_creative_work_schema();
959
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
960
-
961
-		return $schema;
962
-	}
18
+    /**
19
+     * The 'location created' field name.
20
+     *
21
+     * @since 3.5.0
22
+     */
23
+    const FIELD_LOCATION_CREATED = 'wl_location_created';
24
+
25
+    /**
26
+     * The 'topic' field name.
27
+     *
28
+     * @since 3.5.0
29
+     */
30
+    const FIELD_TOPIC = 'wl_topic';
31
+
32
+    /**
33
+     * The 'author' field name.
34
+     *
35
+     * @since 3.1.0
36
+     */
37
+    const FIELD_AUTHOR = 'wl_author';
38
+
39
+    /**
40
+     * The 'same as' field name.
41
+     *
42
+     * @since 3.1.0
43
+     */
44
+    const FIELD_SAME_AS = 'entity_same_as';
45
+
46
+    /**
47
+     * The 'date start' field name.
48
+     *
49
+     * @since 3.1.0
50
+     */
51
+    const FIELD_DATE_START = 'wl_cal_date_start';
52
+
53
+    /**
54
+     * The 'date end' field name.
55
+     *
56
+     * @since 3.1.0
57
+     */
58
+    const FIELD_DATE_END = 'wl_cal_date_end';
59
+
60
+    /**
61
+     * The 'location' field name.
62
+     *
63
+     * @since 3.1.0
64
+     */
65
+    const FIELD_LOCATION = 'wl_location';
66
+
67
+    /**
68
+     * The 'founder' field name.
69
+     *
70
+     * @since 3.1.0
71
+     */
72
+    const FIELD_FOUNDER = 'wl_founder';
73
+
74
+    /**
75
+     * The 'knows' field name.
76
+     *
77
+     * @since 3.1.0
78
+     */
79
+    const FIELD_KNOWS = 'wl_knows';
80
+
81
+    /**
82
+     * The 'birth date' field name.
83
+     *
84
+     * @since 3.1.0
85
+     */
86
+    const FIELD_BIRTH_DATE = 'wl_birth_date';
87
+
88
+    /**
89
+     * The 'birth place' field name.
90
+     *
91
+     * @since 3.1.0
92
+     */
93
+    const FIELD_BIRTH_PLACE = 'wl_birth_place';
94
+
95
+    /**
96
+     * The 'latitude' field name.
97
+     *
98
+     * @since 3.1.0
99
+     */
100
+    const FIELD_GEO_LATITUDE = 'wl_geo_latitude';
101
+
102
+    /**
103
+     * The 'longitude' field name.
104
+     *
105
+     * @since 3.1.0
106
+     */
107
+    const FIELD_GEO_LONGITUDE = 'wl_geo_longitude';
108
+
109
+    /**
110
+     * The 'streetAddress' field name.
111
+     *
112
+     * @since 3.1.0
113
+     */
114
+    const FIELD_ADDRESS = 'wl_address';
115
+
116
+    /**
117
+     * The 'postOfficeBoxNumber' field name.
118
+     *
119
+     * @since 3.3.0
120
+     */
121
+    const FIELD_ADDRESS_PO_BOX = 'wl_address_post_office_box';
122
+
123
+    /**
124
+     * The 'postalCode' field name.
125
+     *
126
+     * @since 3.3.0
127
+     */
128
+    const FIELD_ADDRESS_POSTAL_CODE = 'wl_address_postal_code';
129
+
130
+    /**
131
+     * The 'addressLocality' field name.
132
+     *
133
+     * @since 3.3.0
134
+     */
135
+    const FIELD_ADDRESS_LOCALITY = 'wl_address_locality';
136
+    /**
137
+     * The 'addressRegion' field name.
138
+     *
139
+     * @since 3.3.0
140
+     */
141
+    const FIELD_ADDRESS_REGION = 'wl_address_region';
142
+
143
+    /**
144
+     * The 'addressCountry' field name.
145
+     *
146
+     * @since 3.3.0
147
+     */
148
+    const FIELD_ADDRESS_COUNTRY = 'wl_address_country';
149
+
150
+    /**
151
+     * The 'entity type' field name.
152
+     *
153
+     * @since 3.1.0
154
+     */
155
+    const FIELD_ENTITY_TYPE = 'wl_entity_type_uri';
156
+
157
+    /**
158
+     * The 'email' field name.
159
+     *
160
+     * @since 3.2.0
161
+     */
162
+    const FIELD_EMAIL = 'wl_email';
163
+
164
+    /**
165
+     * The 'affiliation' field name.
166
+     *
167
+     * @since 3.2.0
168
+     */
169
+    const FIELD_AFFILIATION = 'wl_affiliation';
170
+
171
+    /**
172
+     * The 'telephone' field name.
173
+     *
174
+     * @since 3.8.0
175
+     */
176
+    const FIELD_TELEPHONE = 'wl_schema_telephone';
177
+
178
+    /**
179
+     * The 'legalName' field name.
180
+     *
181
+     * @since 3.12.0
182
+     */
183
+    const FIELD_LEGAL_NAME = 'wl_schema_legal_name';
184
+
185
+    /**
186
+     * The 'recipeCuisine' field name.
187
+     *
188
+     * @since 3.14.0
189
+     */
190
+    const FIELD_RECIPE_CUISINE = 'wl_schema_recipe_cuisine';
191
+
192
+    /**
193
+     * The 'recipeIngredient' field name.
194
+     *
195
+     * @since 3.14.0
196
+     */
197
+    const FIELD_RECIPE_INGREDIENT = 'wl_schema_recipe_ingredient';
198
+
199
+    /**
200
+     * The 'recipeInstructions' field name.
201
+     *
202
+     * @since 3.14.0
203
+     */
204
+    const FIELD_RECIPE_INSTRUCTIONS = 'wl_schema_recipe_instructions';
205
+
206
+    /**
207
+     * The 'recipeYield' field name.
208
+     *
209
+     * @since 3.14.0
210
+     */
211
+    const FIELD_RECIPE_YIELD = 'wl_schema_recipe_yield';
212
+
213
+    /**
214
+     * The 'prepTime' field name.
215
+     *
216
+     * @since 3.14.0
217
+     */
218
+    const FIELD_PREP_TIME = 'wl_schema_prep_time';
219
+
220
+    /**
221
+     * The 'totalTime' field name.
222
+     *
223
+     * @since 3.14.0
224
+     */
225
+    const FIELD_TOTAL_TIME = 'wl_schema_total_time';
226
+
227
+    /**
228
+     * The 'URI' data type name.
229
+     *
230
+     * @since 3.1.0
231
+     */
232
+    const DATA_TYPE_URI = 'uri';
233
+
234
+    /**
235
+     * The 'date' data type name.
236
+     *
237
+     * @since 3.1.0
238
+     */
239
+    const DATA_TYPE_DATE = 'date';
240
+
241
+    /**
242
+     * The 'time' data type name.
243
+     *
244
+     * @since 3.14.0
245
+     */
246
+    const DATA_TYPE_DURATION = 'duration';
247
+
248
+    /**
249
+     * The 'double' data type name.
250
+     *
251
+     * @since 3.1.0
252
+     */
253
+    const DATA_TYPE_DOUBLE = 'double';
254
+
255
+    /**
256
+     * The 'string' data type name.
257
+     *
258
+     * @since 3.1.0
259
+     */
260
+    const DATA_TYPE_STRING = 'string';
261
+
262
+    /**
263
+     * The multiline text data type name.
264
+     *
265
+     * @since 3.14.0
266
+     */
267
+    const DATA_TYPE_MULTILINE = 'multiline';
268
+
269
+    /**
270
+     * The 'integer' data type name.
271
+     *
272
+     * @since 3.1.0
273
+     */
274
+    const DATA_TYPE_INTEGER = 'int';
275
+
276
+    /**
277
+     * The 'boolean' data type name.
278
+     *
279
+     * @since 3.1.0
280
+     */
281
+    const DATA_TYPE_BOOLEAN = 'bool';
282
+
283
+    /**
284
+     * The schema.org Event type URI.
285
+     *
286
+     * @since 3.1.0
287
+     */
288
+    const SCHEMA_EVENT_TYPE = 'http://schema.org/Event';
289
+
290
+    /**
291
+     * The Schema service singleton instance.
292
+     *
293
+     * @since  3.1.0
294
+     * @access private
295
+     * @var \Wordlift_Schema_Service $instance The Schema service singleton instance.
296
+     */
297
+    private static $instance;
298
+
299
+    /**
300
+     * WordLift's schema.
301
+     *
302
+     * @since  3.1.0
303
+     * @access private
304
+     * @var array $schema WordLift's schema.
305
+     */
306
+    private $schema;
307
+
308
+    /**
309
+     * The Log service.
310
+     *
311
+     * @since  3.1.0
312
+     * @access private
313
+     * @var \Wordlift_Log_Service $log_service The Log service.
314
+     */
315
+    private $log_service;
316
+
317
+    /**
318
+     * Wordlift_Schema_Service constructor.
319
+     *
320
+     * @since 3.1.0
321
+     */
322
+    public function __construct() {
323
+
324
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
325
+
326
+        // Create a singleton instance of the Schema service, useful to provide static functions to global functions.
327
+        self::$instance = $this;
328
+
329
+        // Set the taxonomy data.
330
+        // Note: parent types must be defined before child types.
331
+        $this->schema = array(
332
+            'thing'         => $this->get_thing_schema(),
333
+            'creative-work' => $this->get_creative_work_schema(),
334
+            'event'         => $this->get_event_schema(),
335
+            'organization'  => $this->get_organization_schema(),
336
+            'person'        => $this->get_person_schema(),
337
+            'place'         => $this->get_place_schema(),
338
+            'localbusiness' => $this->get_local_business_schema(),
339
+            'recipe'        => $this->get_recipe_schema(),
340
+        );
341
+
342
+    }
343
+
344
+    /**
345
+     * Get a reference to the Schema service.
346
+     *
347
+     * @since 3.1.0
348
+     *
349
+     * @return Wordlift_Schema_Service A reference to the Schema service.
350
+     */
351
+    public static function get_instance() {
352
+
353
+        return self::$instance;
354
+    }
355
+
356
+    /**
357
+     * Get the properties for a field with the specified key. The key is used as
358
+     * meta key when the field's value is stored in WordPress meta data table.
359
+     *
360
+     * @since 3.6.0
361
+     *
362
+     * @param string $key The field's key.
363
+     *
364
+     * @return null|array An array of field's properties or null if the field is not found.
365
+     */
366
+    public function get_field( $key ) {
367
+
368
+        // Parse each schema's fields until we find the one we're looking for, then
369
+        // return its properties.
370
+        foreach ( $this->schema as $_ => $schema ) {
371
+
372
+            if ( ! isset( $schema['custom_fields'] ) ) {
373
+                break;
374
+            }
375
+
376
+            foreach ( $schema['custom_fields'] as $field => $props ) {
377
+                if ( $key === $field ) {
378
+                    return $props;
379
+                }
380
+            }
381
+        }
382
+
383
+        return null;
384
+    }
385
+
386
+    /**
387
+     * Get the WordLift's schema.
388
+     *
389
+     * @param string $name The schema name.
390
+     *
391
+     * @return array|null An array with the schema configuration or NULL if the schema is not found.
392
+     *
393
+     * @since 3.1.0
394
+     */
395
+    public function get_schema( $name ) {
396
+
397
+        // Check if the schema exists and, if not, return NULL.
398
+        if ( ! isset( $this->schema[ $name ] ) ) {
399
+            return null;
400
+        }
401
+
402
+        // Return the requested schema.
403
+        return $this->schema[ $name ];
404
+    }
405
+
406
+    /**
407
+     * Get the WordLift's schema trough schema type uri.
408
+     *
409
+     * @param string $uri The schema uri.
410
+     *
411
+     * @return array|null An array with the schema configuration or NULL if the schema is not found.
412
+     *
413
+     * @since 3.3.0
414
+     */
415
+    public function get_schema_by_uri( $uri ) {
416
+
417
+        foreach ( $this->schema as $name => $schema ) {
418
+            if ( $schema['uri'] === $uri ) {
419
+                return $schema;
420
+            }
421
+        }
422
+
423
+        return null;
424
+    }
425
+
426
+    /**
427
+     * Get the 'thing' schema.
428
+     *
429
+     * @return array An array with the schema configuration.
430
+     *
431
+     * @since 3.1.0
432
+     */
433
+    private function get_thing_schema() {
434
+
435
+        return array(
436
+            'css_class'     => 'wl-thing',
437
+            'uri'           => 'http://schema.org/Thing',
438
+            'same_as'       => array( '*' ),
439
+            // set as default.
440
+            'custom_fields' => array(
441
+                self::FIELD_SAME_AS                            => array(
442
+                    'predicate'   => 'http://schema.org/sameAs',
443
+                    'type'        => self::DATA_TYPE_URI,
444
+                    'export_type' => 'http://schema.org/Thing',
445
+                    'constraints' => array(
446
+                        'cardinality' => INF,
447
+                    ),
448
+                    // We need a custom metabox.
449
+                    'input_field' => 'sameas',
450
+                ),
451
+                // Add the schema:url property.
452
+                Wordlift_Schema_Url_Property_Service::META_KEY => Wordlift_Schema_Url_Property_Service::get_instance()
453
+                                                                                                        ->get_compat_definition(),
454
+            ),
455
+            // {{sameAs}} not present in the microdata template,
456
+            // because it is treated separately in *wl_content_embed_item_microdata*
457
+            'templates'     => array(
458
+                'subtitle' => '{{id}}',
459
+            ),
460
+        );
461
+
462
+    }
463
+
464
+    /**
465
+     * Get the 'creative work' schema.
466
+     *
467
+     * @return array An array with the schema configuration.
468
+     *
469
+     * @since 3.1.0
470
+     */
471
+    private function get_creative_work_schema() {
472
+
473
+        $schema = array(
474
+            'label'         => 'CreativeWork',
475
+            'description'   => 'A creative work (or a Music Album).',
476
+            'parents'       => array( 'thing' ),
477
+            // Give term slug as parent.
478
+            'css_class'     => 'wl-creative-work',
479
+            'uri'           => 'http://schema.org/CreativeWork',
480
+            'same_as'       => array(
481
+                'http://schema.org/MusicAlbum',
482
+                'http://schema.org/Product',
483
+            ),
484
+            'custom_fields' => array(
485
+                self::FIELD_AUTHOR => array(
486
+                    'predicate'   => 'http://schema.org/author',
487
+                    'type'        => self::DATA_TYPE_URI,
488
+                    'export_type' => 'http://schema.org/Person',
489
+                    'constraints' => array(
490
+                        'uri_type'    => array( 'Person', 'Organization' ),
491
+                        'cardinality' => INF,
492
+                    ),
493
+                ),
494
+            ),
495
+            'templates'     => array(
496
+                'subtitle' => '{{id}}',
497
+            ),
498
+        );
499
+
500
+        // Merge the custom fields with those provided by the thing schema.
501
+        $thing_schema            = $this->get_thing_schema();
502
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
503
+
504
+        return $schema;
505
+    }
506
+
507
+    /**
508
+     * Get the 'event' schema.
509
+     *
510
+     * @return array An array with the schema configuration.
511
+     *
512
+     * @since 3.1.0
513
+     */
514
+    private function get_event_schema() {
515
+
516
+        $schema = array(
517
+            'label'         => 'Event',
518
+            'description'   => 'An event . ',
519
+            'parents'       => array( 'thing' ),
520
+            'css_class'     => 'wl-event',
521
+            'uri'           => self::SCHEMA_EVENT_TYPE,
522
+            'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
523
+            'custom_fields' => array(
524
+                self::FIELD_DATE_START => array(
525
+                    'predicate'   => 'http://schema.org/startDate',
526
+                    'type'        => self::DATA_TYPE_DATE,
527
+                    'export_type' => 'xsd:datetime',
528
+                    'constraints' => '',
529
+                ),
530
+                self::FIELD_DATE_END   => array(
531
+                    'predicate'   => 'http://schema.org/endDate',
532
+                    'type'        => self::DATA_TYPE_DATE,
533
+                    'export_type' => 'xsd:datetime',
534
+                    'constraints' => '',
535
+                ),
536
+                self::FIELD_LOCATION   => array(
537
+                    'predicate'   => 'http://schema.org/location',
538
+                    'type'        => self::DATA_TYPE_URI,
539
+                    'export_type' => 'http://schema.org/PostalAddress',
540
+                    'constraints' => array(
541
+                        'uri_type'    => array( 'Place', 'LocalBusiness' ),
542
+                        'cardinality' => INF,
543
+                    ),
544
+                ),
545
+            ),
546
+            'templates'     => array(
547
+                'subtitle' => '{{id}}',
548
+            ),
549
+        );
550
+
551
+        // Merge the custom fields with those provided by the thing schema.
552
+        $thing_schema            = $this->get_thing_schema();
553
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
554
+
555
+        return $schema;
556
+    }
557
+
558
+    /**
559
+     * Get the 'organization' schema.
560
+     *
561
+     * @return array An array with the schema configuration.
562
+     *
563
+     * @since 3.1.0
564
+     */
565
+    private function get_organization_schema() {
566
+
567
+        $schema = array(
568
+            'label'         => 'Organization',
569
+            'description'   => 'An organization, including a government or a newspaper.',
570
+            'parents'       => array( 'thing' ),
571
+            'css_class'     => 'wl-organization',
572
+            'uri'           => 'http://schema.org/Organization',
573
+            'same_as'       => array(
574
+                'http://rdf.freebase.com/ns/organization.organization',
575
+                'http://rdf.freebase.com/ns/government.government',
576
+                'http://schema.org/Newspaper',
577
+            ),
578
+            'custom_fields' => array(
579
+                self::FIELD_LEGAL_NAME          => array(
580
+                    'predicate'   => 'http://schema.org/legalName',
581
+                    'type'        => self::DATA_TYPE_STRING,
582
+                    'export_type' => 'xsd:string',
583
+                    'constraints' => '',
584
+                ),
585
+                self::FIELD_FOUNDER             => array(
586
+                    'predicate'   => 'http://schema.org/founder',
587
+                    'type'        => self::DATA_TYPE_URI,
588
+                    'export_type' => 'http://schema.org/Person',
589
+                    'constraints' => array(
590
+                        'uri_type'    => 'Person',
591
+                        'cardinality' => INF,
592
+                    ),
593
+                ),
594
+                self::FIELD_ADDRESS             => array(
595
+                    'predicate'   => 'http://schema.org/streetAddress',
596
+                    'type'        => self::DATA_TYPE_STRING,
597
+                    'export_type' => 'xsd:string',
598
+                    'constraints' => '',
599
+                    // To build custom metabox.
600
+                    'input_field' => 'address',
601
+                ),
602
+                self::FIELD_ADDRESS_PO_BOX      => array(
603
+                    'predicate'   => 'http://schema.org/postOfficeBoxNumber',
604
+                    'type'        => self::DATA_TYPE_STRING,
605
+                    'export_type' => 'xsd:string',
606
+                    'constraints' => '',
607
+                    // To build custom metabox.
608
+                    'input_field' => 'address',
609
+                ),
610
+                self::FIELD_ADDRESS_POSTAL_CODE => array(
611
+                    'predicate'   => 'http://schema.org/postalCode',
612
+                    'type'        => self::DATA_TYPE_STRING,
613
+                    'export_type' => 'xsd:string',
614
+                    'constraints' => '',
615
+                    // To build custom metabox.
616
+                    'input_field' => 'address',
617
+                ),
618
+                self::FIELD_ADDRESS_LOCALITY    => array(
619
+                    'predicate'   => 'http://schema.org/addressLocality',
620
+                    'type'        => self::DATA_TYPE_STRING,
621
+                    'export_type' => 'xsd:string',
622
+                    'constraints' => '',
623
+                    // To build custom metabox.
624
+                    'input_field' => 'address',
625
+                ),
626
+                self::FIELD_ADDRESS_REGION      => array(
627
+                    'predicate'   => 'http://schema.org/addressRegion',
628
+                    'type'        => self::DATA_TYPE_STRING,
629
+                    'export_type' => 'xsd:string',
630
+                    'constraints' => '',
631
+                    // To build custom metabox.
632
+                    'input_field' => 'address',
633
+                ),
634
+                self::FIELD_ADDRESS_COUNTRY     => array(
635
+                    'predicate'   => 'http://schema.org/addressCountry',
636
+                    'type'        => self::DATA_TYPE_STRING,
637
+                    'export_type' => 'xsd:string',
638
+                    'constraints' => '',
639
+                    // To build custom metabox.
640
+                    'input_field' => 'address',
641
+                ),
642
+                self::FIELD_EMAIL               => array(
643
+                    'predicate'   => 'http://schema.org/email',
644
+                    'type'        => self::DATA_TYPE_STRING,
645
+                    'export_type' => 'xsd:string',
646
+                    'constraints' => '',
647
+                ),
648
+                self::FIELD_TELEPHONE           => array(
649
+                    'predicate'   => 'http://schema.org/telephone',
650
+                    'type'        => self::DATA_TYPE_STRING,
651
+                    'export_type' => 'xsd:string',
652
+                    'constraints' => '',
653
+                ),
654
+            ),
655
+            'templates'     => array(
656
+                'subtitle' => '{{id}}',
657
+            ),
658
+        );
659
+
660
+        // Merge the custom fields with those provided by the thing schema.
661
+        $thing_schema            = $this->get_thing_schema();
662
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
663
+
664
+        return $schema;
665
+    }
666
+
667
+    /**
668
+     * Get the 'person' schema.
669
+     *
670
+     * @return array An array with the schema configuration.
671
+     *
672
+     * @since 3.1.0
673
+     */
674
+    private function get_person_schema() {
675
+
676
+        $schema = array(
677
+            'label'         => 'Person',
678
+            'description'   => 'A person (or a music artist).',
679
+            'parents'       => array( 'thing' ),
680
+            'css_class'     => 'wl-person',
681
+            'uri'           => 'http://schema.org/Person',
682
+            'same_as'       => array(
683
+                'http://rdf.freebase.com/ns/people.person',
684
+                'http://rdf.freebase.com/ns/music.artist',
685
+                'http://dbpedia.org/class/yago/LivingPeople',
686
+            ),
687
+            'custom_fields' => array(
688
+                self::FIELD_KNOWS       => array(
689
+                    'predicate'   => 'http://schema.org/knows',
690
+                    'type'        => self::DATA_TYPE_URI,
691
+                    'export_type' => 'http://schema.org/Person',
692
+                    'constraints' => array(
693
+                        'uri_type'    => 'Person',
694
+                        'cardinality' => INF,
695
+                    ),
696
+                ),
697
+                self::FIELD_BIRTH_DATE  => array(
698
+                    'predicate'   => 'http://schema.org/birthDate',
699
+                    'type'        => self::DATA_TYPE_DATE,
700
+                    'export_type' => 'xsd:date',
701
+                    'constraints' => '',
702
+                ),
703
+                self::FIELD_BIRTH_PLACE => array(
704
+                    'predicate'   => 'http://schema.org/birthPlace',
705
+                    'type'        => self::DATA_TYPE_URI,
706
+                    'export_type' => 'http://schema.org/Place',
707
+                    'constraints' => array(
708
+                        'uri_type' => 'Place',
709
+                    ),
710
+                ),
711
+                self::FIELD_AFFILIATION => array(
712
+                    'predicate'   => 'http://schema.org/affiliation',
713
+                    'type'        => self::DATA_TYPE_URI,
714
+                    'export_type' => 'http://schema.org/Organization',
715
+                    'constraints' => array(
716
+                        'uri_type'    => array(
717
+                            'Organization',
718
+                            'LocalBusiness',
719
+                        ),
720
+                        'cardinality' => INF,
721
+                    ),
722
+                ),
723
+                self::FIELD_EMAIL       => array(
724
+                    'predicate'   => 'http://schema.org/email',
725
+                    'type'        => self::DATA_TYPE_STRING,
726
+                    'export_type' => 'xsd:string',
727
+                    'constraints' => array(
728
+                        'cardinality' => INF,
729
+                    ),
730
+                ),
731
+            ),
732
+            'templates'     => array(
733
+                'subtitle' => '{{id}}',
734
+            ),
735
+        );
736
+
737
+        // Merge the custom fields with those provided by the thing schema.
738
+        $thing_schema            = $this->get_thing_schema();
739
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
740
+
741
+        return $schema;
742
+
743
+    }
744
+
745
+    /**
746
+     * Get the 'place' schema.
747
+     *
748
+     * @return array An array with the schema configuration.
749
+     *
750
+     * @since 3.1.0
751
+     */
752
+    private function get_place_schema() {
753
+
754
+        $schema = array(
755
+            'label'         => 'Place',
756
+            'description'   => 'A place.',
757
+            'parents'       => array( 'thing' ),
758
+            'css_class'     => 'wl-place',
759
+            'uri'           => 'http://schema.org/Place',
760
+            'same_as'       => array(
761
+                'http://rdf.freebase.com/ns/location.location',
762
+                'http://www.opengis.net/gml/_Feature',
763
+            ),
764
+            'custom_fields' => array(
765
+                self::FIELD_GEO_LATITUDE        => array(
766
+                    'predicate'   => 'http://schema.org/latitude',
767
+                    'type'        => self::DATA_TYPE_DOUBLE,
768
+                    'export_type' => 'xsd:double',
769
+                    'constraints' => '',
770
+                    // To build custom metabox.
771
+                    'input_field' => 'coordinates',
772
+                ),
773
+                self::FIELD_GEO_LONGITUDE       => array(
774
+                    'predicate'   => 'http://schema.org/longitude',
775
+                    'type'        => self::DATA_TYPE_DOUBLE,
776
+                    'export_type' => 'xsd:double',
777
+                    'constraints' => '',
778
+                    // To build custom metabox.
779
+                    'input_field' => 'coordinates',
780
+                ),
781
+                self::FIELD_ADDRESS             => array(
782
+                    'predicate'   => 'http://schema.org/streetAddress',
783
+                    'type'        => self::DATA_TYPE_STRING,
784
+                    'export_type' => 'xsd:string',
785
+                    'constraints' => '',
786
+                    // To build custom metabox.
787
+                    'input_field' => 'address',
788
+                ),
789
+                self::FIELD_ADDRESS_PO_BOX      => array(
790
+                    'predicate'   => 'http://schema.org/postOfficeBoxNumber',
791
+                    'type'        => self::DATA_TYPE_STRING,
792
+                    'export_type' => 'xsd:string',
793
+                    'constraints' => '',
794
+                    // To build custom metabox.
795
+                    'input_field' => 'address',
796
+                ),
797
+                self::FIELD_ADDRESS_POSTAL_CODE => array(
798
+                    'predicate'   => 'http://schema.org/postalCode',
799
+                    'type'        => self::DATA_TYPE_STRING,
800
+                    'export_type' => 'xsd:string',
801
+                    'constraints' => '',
802
+                    // To build custom metabox.
803
+                    'input_field' => 'address',
804
+                ),
805
+                self::FIELD_ADDRESS_LOCALITY    => array(
806
+                    'predicate'   => 'http://schema.org/addressLocality',
807
+                    'type'        => self::DATA_TYPE_STRING,
808
+                    'export_type' => 'xsd:string',
809
+                    'constraints' => '',
810
+                    // To build custom metabox.
811
+                    'input_field' => 'address',
812
+                ),
813
+                self::FIELD_ADDRESS_REGION      => array(
814
+                    'predicate'   => 'http://schema.org/addressRegion',
815
+                    'type'        => self::DATA_TYPE_STRING,
816
+                    'export_type' => 'xsd:string',
817
+                    'constraints' => '',
818
+                    // To build custom metabox.
819
+                    'input_field' => 'address',
820
+                ),
821
+                self::FIELD_ADDRESS_COUNTRY     => array(
822
+                    'predicate'   => 'http://schema.org/addressCountry',
823
+                    'type'        => self::DATA_TYPE_STRING,
824
+                    'export_type' => 'xsd:string',
825
+                    'constraints' => '',
826
+                    // To build custom metabox.
827
+                    'input_field' => 'address',
828
+                ),
829
+            ),
830
+            'templates'     => array(
831
+                'subtitle' => '{{id}}',
832
+            ),
833
+        );
834
+
835
+        // Merge the custom fields with those provided by the thing schema.
836
+        $thing_schema            = $this->get_thing_schema();
837
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
838
+
839
+        return $schema;
840
+    }
841
+
842
+    /**
843
+     * Get the 'local business' schema.
844
+     *
845
+     * @return array An array with the schema configuration.
846
+     *
847
+     * @since 3.1.0
848
+     */
849
+    private function get_local_business_schema() {
850
+
851
+        $schema = array(
852
+            'label'         => 'LocalBusiness',
853
+            'description'   => 'A local business.',
854
+            'parents'       => array( 'place', 'organization' ),
855
+            'css_class'     => 'wl-local-business',
856
+            'uri'           => 'http://schema.org/LocalBusiness',
857
+            'same_as'       => array(
858
+                'http://rdf.freebase.com/ns/business/business_location',
859
+                'https://schema.org/Store',
860
+            ),
861
+            'custom_fields' => array(),
862
+            'templates'     => array(
863
+                'subtitle' => '{{id}}',
864
+            ),
865
+        );
866
+
867
+        // Merge the custom fields with those provided by the place and organization schema.
868
+        $place_schema            = $this->get_place_schema();
869
+        $organization_schema     = $this->get_organization_schema();
870
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
871
+
872
+        return $schema;
873
+    }
874
+
875
+    /**
876
+     * Get the 'recipe' schema.
877
+     *
878
+     * @return array An array with the schema configuration.
879
+     *
880
+     * @since 3.14.0
881
+     */
882
+    private function get_recipe_schema() {
883
+
884
+        $schema = array(
885
+            'label'         => 'Recipe',
886
+            'description'   => 'A Recipe.',
887
+            'parents'       => array( 'CreativeWork' ),
888
+            'css_class'     => 'wl-recipe',
889
+            'uri'           => 'http://schema.org/Recipe',
890
+            'same_as'       => array(),
891
+            'templates'     => array(
892
+                'subtitle' => '{{id}}',
893
+            ),
894
+            'custom_fields' => array(
895
+                self::FIELD_RECIPE_CUISINE      => array(
896
+                    'predicate'   => 'http://schema.org/recipeCuisine',
897
+                    'type'        => self::DATA_TYPE_STRING,
898
+                    'export_type' => 'xsd:string',
899
+                    'constraints' => '',
900
+                    'metabox'     => array(
901
+                        'label' => __( 'Recipe cuisine', 'wordlift' ),
902
+                    ),
903
+                ),
904
+                self::FIELD_RECIPE_INGREDIENT   => array(
905
+                    'predicate'   => 'http://schema.org/recipeIngredient',
906
+                    'type'        => self::DATA_TYPE_STRING,
907
+                    'export_type' => 'xsd:string',
908
+                    'constraints' => array(
909
+                        'cardinality' => INF,
910
+                    ),
911
+                    'metabox'     => array(
912
+                        'label' => __( 'Recipe ingredient', 'wordlift' ),
913
+                    ),
914
+                ),
915
+                self::FIELD_RECIPE_INSTRUCTIONS => array(
916
+                    'predicate'   => 'http://schema.org/recipeInstructions',
917
+                    'type'        => self::DATA_TYPE_MULTILINE,
918
+                    'export_type' => 'xsd:string',
919
+                    'constraints' => '',
920
+                    'metabox'     => array(
921
+                        'class' => 'Wordlift_Metabox_Field_Multiline',
922
+                        'label' => __( 'Recipe instructions', 'wordlift' ),
923
+                    ),
924
+                ),
925
+                self::FIELD_RECIPE_YIELD        => array(
926
+                    'predicate'   => 'http://schema.org/recipeYield',
927
+                    'type'        => self::DATA_TYPE_STRING,
928
+                    'export_type' => 'xsd:string',
929
+                    'constraints' => '',
930
+                    'metabox'     => array(
931
+                        'label' => __( 'Recipe number of servings', 'wordlift' ),
932
+                    ),
933
+                ),
934
+                self::FIELD_PREP_TIME           => array(
935
+                    'predicate'   => 'http://schema.org/prepTime',
936
+                    'type'        => self::DATA_TYPE_DURATION,
937
+                    'export_type' => 'xsd:time',
938
+                    'constraints' => '',
939
+                    'metabox'     => array(
940
+                        'class' => 'Wordlift_Metabox_Field_Duration',
941
+                        'label' => __( 'Recipe preparation time', 'wordlift' ),
942
+                    ),
943
+                ),
944
+                self::FIELD_TOTAL_TIME          => array(
945
+                    'predicate'   => 'http://schema.org/totalTime',
946
+                    'type'        => self::DATA_TYPE_DURATION,
947
+                    'export_type' => 'xsd:time',
948
+                    'constraints' => '',
949
+                    'metabox'     => array(
950
+                        'class' => 'Wordlift_Metabox_Field_Duration',
951
+                        'label' => __( 'Recipe total time', 'wordlift' ),
952
+                    ),
953
+                ),
954
+            ),
955
+        );
956
+
957
+        // Merge the custom fields with those provided by the parent schema.
958
+        $parent_schema           = $this->get_creative_work_schema();
959
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
960
+
961
+        return $schema;
962
+    }
963 963
 
964 964
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 	 */
322 322
 	public function __construct() {
323 323
 
324
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
324
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Schema_Service');
325 325
 
326 326
 		// Create a singleton instance of the Schema service, useful to provide static functions to global functions.
327 327
 		self::$instance = $this;
@@ -363,18 +363,18 @@  discard block
 block discarded – undo
363 363
 	 *
364 364
 	 * @return null|array An array of field's properties or null if the field is not found.
365 365
 	 */
366
-	public function get_field( $key ) {
366
+	public function get_field($key) {
367 367
 
368 368
 		// Parse each schema's fields until we find the one we're looking for, then
369 369
 		// return its properties.
370
-		foreach ( $this->schema as $_ => $schema ) {
370
+		foreach ($this->schema as $_ => $schema) {
371 371
 
372
-			if ( ! isset( $schema['custom_fields'] ) ) {
372
+			if ( ! isset($schema['custom_fields'])) {
373 373
 				break;
374 374
 			}
375 375
 
376
-			foreach ( $schema['custom_fields'] as $field => $props ) {
377
-				if ( $key === $field ) {
376
+			foreach ($schema['custom_fields'] as $field => $props) {
377
+				if ($key === $field) {
378 378
 					return $props;
379 379
 				}
380 380
 			}
@@ -392,15 +392,15 @@  discard block
 block discarded – undo
392 392
 	 *
393 393
 	 * @since 3.1.0
394 394
 	 */
395
-	public function get_schema( $name ) {
395
+	public function get_schema($name) {
396 396
 
397 397
 		// Check if the schema exists and, if not, return NULL.
398
-		if ( ! isset( $this->schema[ $name ] ) ) {
398
+		if ( ! isset($this->schema[$name])) {
399 399
 			return null;
400 400
 		}
401 401
 
402 402
 		// Return the requested schema.
403
-		return $this->schema[ $name ];
403
+		return $this->schema[$name];
404 404
 	}
405 405
 
406 406
 	/**
@@ -412,10 +412,10 @@  discard block
 block discarded – undo
412 412
 	 *
413 413
 	 * @since 3.3.0
414 414
 	 */
415
-	public function get_schema_by_uri( $uri ) {
415
+	public function get_schema_by_uri($uri) {
416 416
 
417
-		foreach ( $this->schema as $name => $schema ) {
418
-			if ( $schema['uri'] === $uri ) {
417
+		foreach ($this->schema as $name => $schema) {
418
+			if ($schema['uri'] === $uri) {
419 419
 				return $schema;
420 420
 			}
421 421
 		}
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 		return array(
436 436
 			'css_class'     => 'wl-thing',
437 437
 			'uri'           => 'http://schema.org/Thing',
438
-			'same_as'       => array( '*' ),
438
+			'same_as'       => array('*'),
439 439
 			// set as default.
440 440
 			'custom_fields' => array(
441 441
 				self::FIELD_SAME_AS                            => array(
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 		$schema = array(
474 474
 			'label'         => 'CreativeWork',
475 475
 			'description'   => 'A creative work (or a Music Album).',
476
-			'parents'       => array( 'thing' ),
476
+			'parents'       => array('thing'),
477 477
 			// Give term slug as parent.
478 478
 			'css_class'     => 'wl-creative-work',
479 479
 			'uri'           => 'http://schema.org/CreativeWork',
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 					'type'        => self::DATA_TYPE_URI,
488 488
 					'export_type' => 'http://schema.org/Person',
489 489
 					'constraints' => array(
490
-						'uri_type'    => array( 'Person', 'Organization' ),
490
+						'uri_type'    => array('Person', 'Organization'),
491 491
 						'cardinality' => INF,
492 492
 					),
493 493
 				),
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 
500 500
 		// Merge the custom fields with those provided by the thing schema.
501 501
 		$thing_schema            = $this->get_thing_schema();
502
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
502
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $thing_schema['custom_fields']);
503 503
 
504 504
 		return $schema;
505 505
 	}
@@ -516,10 +516,10 @@  discard block
 block discarded – undo
516 516
 		$schema = array(
517 517
 			'label'         => 'Event',
518 518
 			'description'   => 'An event . ',
519
-			'parents'       => array( 'thing' ),
519
+			'parents'       => array('thing'),
520 520
 			'css_class'     => 'wl-event',
521 521
 			'uri'           => self::SCHEMA_EVENT_TYPE,
522
-			'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
522
+			'same_as'       => array('http://dbpedia.org/ontology/Event'),
523 523
 			'custom_fields' => array(
524 524
 				self::FIELD_DATE_START => array(
525 525
 					'predicate'   => 'http://schema.org/startDate',
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 					'type'        => self::DATA_TYPE_URI,
539 539
 					'export_type' => 'http://schema.org/PostalAddress',
540 540
 					'constraints' => array(
541
-						'uri_type'    => array( 'Place', 'LocalBusiness' ),
541
+						'uri_type'    => array('Place', 'LocalBusiness'),
542 542
 						'cardinality' => INF,
543 543
 					),
544 544
 				),
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 
551 551
 		// Merge the custom fields with those provided by the thing schema.
552 552
 		$thing_schema            = $this->get_thing_schema();
553
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
553
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $thing_schema['custom_fields']);
554 554
 
555 555
 		return $schema;
556 556
 	}
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
 		$schema = array(
568 568
 			'label'         => 'Organization',
569 569
 			'description'   => 'An organization, including a government or a newspaper.',
570
-			'parents'       => array( 'thing' ),
570
+			'parents'       => array('thing'),
571 571
 			'css_class'     => 'wl-organization',
572 572
 			'uri'           => 'http://schema.org/Organization',
573 573
 			'same_as'       => array(
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
 
660 660
 		// Merge the custom fields with those provided by the thing schema.
661 661
 		$thing_schema            = $this->get_thing_schema();
662
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
662
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $thing_schema['custom_fields']);
663 663
 
664 664
 		return $schema;
665 665
 	}
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 		$schema = array(
677 677
 			'label'         => 'Person',
678 678
 			'description'   => 'A person (or a music artist).',
679
-			'parents'       => array( 'thing' ),
679
+			'parents'       => array('thing'),
680 680
 			'css_class'     => 'wl-person',
681 681
 			'uri'           => 'http://schema.org/Person',
682 682
 			'same_as'       => array(
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
 
737 737
 		// Merge the custom fields with those provided by the thing schema.
738 738
 		$thing_schema            = $this->get_thing_schema();
739
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
739
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $thing_schema['custom_fields']);
740 740
 
741 741
 		return $schema;
742 742
 
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 		$schema = array(
755 755
 			'label'         => 'Place',
756 756
 			'description'   => 'A place.',
757
-			'parents'       => array( 'thing' ),
757
+			'parents'       => array('thing'),
758 758
 			'css_class'     => 'wl-place',
759 759
 			'uri'           => 'http://schema.org/Place',
760 760
 			'same_as'       => array(
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
 
835 835
 		// Merge the custom fields with those provided by the thing schema.
836 836
 		$thing_schema            = $this->get_thing_schema();
837
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
837
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $thing_schema['custom_fields']);
838 838
 
839 839
 		return $schema;
840 840
 	}
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 		$schema = array(
852 852
 			'label'         => 'LocalBusiness',
853 853
 			'description'   => 'A local business.',
854
-			'parents'       => array( 'place', 'organization' ),
854
+			'parents'       => array('place', 'organization'),
855 855
 			'css_class'     => 'wl-local-business',
856 856
 			'uri'           => 'http://schema.org/LocalBusiness',
857 857
 			'same_as'       => array(
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
 		// Merge the custom fields with those provided by the place and organization schema.
868 868
 		$place_schema            = $this->get_place_schema();
869 869
 		$organization_schema     = $this->get_organization_schema();
870
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
870
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields']);
871 871
 
872 872
 		return $schema;
873 873
 	}
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 		$schema = array(
885 885
 			'label'         => 'Recipe',
886 886
 			'description'   => 'A Recipe.',
887
-			'parents'       => array( 'CreativeWork' ),
887
+			'parents'       => array('CreativeWork'),
888 888
 			'css_class'     => 'wl-recipe',
889 889
 			'uri'           => 'http://schema.org/Recipe',
890 890
 			'same_as'       => array(),
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
 					'export_type' => 'xsd:string',
899 899
 					'constraints' => '',
900 900
 					'metabox'     => array(
901
-						'label' => __( 'Recipe cuisine', 'wordlift' ),
901
+						'label' => __('Recipe cuisine', 'wordlift'),
902 902
 					),
903 903
 				),
904 904
 				self::FIELD_RECIPE_INGREDIENT   => array(
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
 						'cardinality' => INF,
910 910
 					),
911 911
 					'metabox'     => array(
912
-						'label' => __( 'Recipe ingredient', 'wordlift' ),
912
+						'label' => __('Recipe ingredient', 'wordlift'),
913 913
 					),
914 914
 				),
915 915
 				self::FIELD_RECIPE_INSTRUCTIONS => array(
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
 					'constraints' => '',
920 920
 					'metabox'     => array(
921 921
 						'class' => 'Wordlift_Metabox_Field_Multiline',
922
-						'label' => __( 'Recipe instructions', 'wordlift' ),
922
+						'label' => __('Recipe instructions', 'wordlift'),
923 923
 					),
924 924
 				),
925 925
 				self::FIELD_RECIPE_YIELD        => array(
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
 					'export_type' => 'xsd:string',
929 929
 					'constraints' => '',
930 930
 					'metabox'     => array(
931
-						'label' => __( 'Recipe number of servings', 'wordlift' ),
931
+						'label' => __('Recipe number of servings', 'wordlift'),
932 932
 					),
933 933
 				),
934 934
 				self::FIELD_PREP_TIME           => array(
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
 					'constraints' => '',
939 939
 					'metabox'     => array(
940 940
 						'class' => 'Wordlift_Metabox_Field_Duration',
941
-						'label' => __( 'Recipe preparation time', 'wordlift' ),
941
+						'label' => __('Recipe preparation time', 'wordlift'),
942 942
 					),
943 943
 				),
944 944
 				self::FIELD_TOTAL_TIME          => array(
@@ -948,7 +948,7 @@  discard block
 block discarded – undo
948 948
 					'constraints' => '',
949 949
 					'metabox'     => array(
950 950
 						'class' => 'Wordlift_Metabox_Field_Duration',
951
-						'label' => __( 'Recipe total time', 'wordlift' ),
951
+						'label' => __('Recipe total time', 'wordlift'),
952 952
 					),
953 953
 				),
954 954
 			),
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
 
957 957
 		// Merge the custom fields with those provided by the parent schema.
958 958
 		$parent_schema           = $this->get_creative_work_schema();
959
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
959
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $parent_schema['custom_fields']);
960 960
 
961 961
 		return $schema;
962 962
 	}
Please login to merge, or discard this patch.