Completed
Pull Request — develop (#1626)
by
unknown
01:05
created
src/includes/class-wordlift-abstract-post-to-jsonld-converter.php 2 patches
Indentation   +397 added lines, -397 removed lines patch added patch discarded remove patch
@@ -24,423 +24,423 @@
 block discarded – undo
24 24
  */
25 25
 abstract class Wordlift_Abstract_Post_To_Jsonld_Converter implements Wordlift_Post_Converter {
26 26
 
27
-	/**
28
-	 * The JSON-LD context.
29
-	 *
30
-	 * @since 3.10.0
31
-	 */
32
-	const CONTEXT = 'http://schema.org';
33
-
34
-	/**
35
-	 * A {@link Wordlift_Entity_Type_Service} instance.
36
-	 *
37
-	 * @since  3.10.0
38
-	 * @access protected
39
-	 * @var \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
40
-	 */
41
-	protected $entity_type_service;
42
-
43
-	/**
44
-	 * A {@link Wordlift_User_Service} instance.
45
-	 *
46
-	 * @since  3.10.0
47
-	 * @access private
48
-	 * @var \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance.
49
-	 */
50
-	protected $user_service;
51
-
52
-	/**
53
-	 * A {@link Wordlift_Attachment_Service} instance.
54
-	 *
55
-	 * @since  3.10.0
56
-	 * @access private
57
-	 * @var \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance.
58
-	 */
59
-	protected $attachment_service;
60
-
61
-	/**
62
-	 * @var Wordlift_Property_Getter
63
-	 */
64
-	private $property_getter;
65
-
66
-	/**
67
-	 * Wordlift_Post_To_Jsonld_Converter constructor.
68
-	 *
69
-	 * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
70
-	 * @param \Wordlift_User_Service        $user_service A {@link Wordlift_User_Service} instance.
71
-	 * @param \Wordlift_Attachment_Service  $attachment_service A {@link Wordlift_Attachment_Service} instance.
72
-	 * @param \Wordlift_Property_Getter     $property_getter
73
-	 *
74
-	 * @since 3.10.0
75
-	 */
76
-	public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter ) {
77
-		$this->entity_type_service = $entity_type_service;
78
-		$this->user_service        = $user_service;
79
-		$this->attachment_service  = $attachment_service;
80
-		$this->property_getter     = $property_getter;
81
-	}
82
-
83
-	/**
84
-	 * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference
85
-	 * found while processing the post is set in the $references array.
86
-	 *
87
-	 * @param int   $post_id The post id.
88
-	 * @param array $references An array of entity references.
89
-	 * @param array $references_infos
90
-	 *
91
-	 * @return array A JSON-LD array.
92
-	 * @since 3.10.0
93
-	 */
94
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
95
-	public function convert( $post_id, &$references = array(), &$references_infos = array() ) {
96
-
97
-		// Get the post instance.
98
-		$post = get_post( $post_id );
99
-		if ( null === $post ) {
100
-			// Post not found.
101
-			return null;
102
-		}
103
-
104
-		// Get the post URI @id.
105
-		$id = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID );
106
-		if ( $id === null ) {
107
-			$id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri();
108
-		}
109
-
110
-		/*
27
+    /**
28
+     * The JSON-LD context.
29
+     *
30
+     * @since 3.10.0
31
+     */
32
+    const CONTEXT = 'http://schema.org';
33
+
34
+    /**
35
+     * A {@link Wordlift_Entity_Type_Service} instance.
36
+     *
37
+     * @since  3.10.0
38
+     * @access protected
39
+     * @var \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
40
+     */
41
+    protected $entity_type_service;
42
+
43
+    /**
44
+     * A {@link Wordlift_User_Service} instance.
45
+     *
46
+     * @since  3.10.0
47
+     * @access private
48
+     * @var \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance.
49
+     */
50
+    protected $user_service;
51
+
52
+    /**
53
+     * A {@link Wordlift_Attachment_Service} instance.
54
+     *
55
+     * @since  3.10.0
56
+     * @access private
57
+     * @var \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance.
58
+     */
59
+    protected $attachment_service;
60
+
61
+    /**
62
+     * @var Wordlift_Property_Getter
63
+     */
64
+    private $property_getter;
65
+
66
+    /**
67
+     * Wordlift_Post_To_Jsonld_Converter constructor.
68
+     *
69
+     * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
70
+     * @param \Wordlift_User_Service        $user_service A {@link Wordlift_User_Service} instance.
71
+     * @param \Wordlift_Attachment_Service  $attachment_service A {@link Wordlift_Attachment_Service} instance.
72
+     * @param \Wordlift_Property_Getter     $property_getter
73
+     *
74
+     * @since 3.10.0
75
+     */
76
+    public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter ) {
77
+        $this->entity_type_service = $entity_type_service;
78
+        $this->user_service        = $user_service;
79
+        $this->attachment_service  = $attachment_service;
80
+        $this->property_getter     = $property_getter;
81
+    }
82
+
83
+    /**
84
+     * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference
85
+     * found while processing the post is set in the $references array.
86
+     *
87
+     * @param int   $post_id The post id.
88
+     * @param array $references An array of entity references.
89
+     * @param array $references_infos
90
+     *
91
+     * @return array A JSON-LD array.
92
+     * @since 3.10.0
93
+     */
94
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
95
+    public function convert( $post_id, &$references = array(), &$references_infos = array() ) {
96
+
97
+        // Get the post instance.
98
+        $post = get_post( $post_id );
99
+        if ( null === $post ) {
100
+            // Post not found.
101
+            return null;
102
+        }
103
+
104
+        // Get the post URI @id.
105
+        $id = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID );
106
+        if ( $id === null ) {
107
+            $id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri();
108
+        }
109
+
110
+        /*
111 111
 		 * The `types` variable holds one or more entity types. The `type` variable isn't used anymore.
112 112
 		 *
113 113
 		 * @since 3.20.0 We support more than one entity type.
114 114
 		 *
115 115
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/835
116 116
 		 */
117
-		// Get the entity @type. We consider `post` BlogPostings.
118
-		// $type = $this->entity_type_service->get( $post_id );
119
-		$types = $this->entity_type_service->get_names( $post_id );
120
-		$type  = self::make_one( $types );
121
-
122
-		// Prepare the response.
123
-		$jsonld = array(
124
-			'@context' => self::CONTEXT,
125
-			'@id'      => $id,
126
-			'@type'    => $type,
127
-		);
128
-
129
-		if ( post_type_supports( $post->post_type, 'excerpt' ) ) {
130
-			$jsonld['description'] = Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post );
131
-		}
132
-
133
-		// Set the `mainEntityOfPage` property if the post has some contents.
134
-		/*
117
+        // Get the entity @type. We consider `post` BlogPostings.
118
+        // $type = $this->entity_type_service->get( $post_id );
119
+        $types = $this->entity_type_service->get_names( $post_id );
120
+        $type  = self::make_one( $types );
121
+
122
+        // Prepare the response.
123
+        $jsonld = array(
124
+            '@context' => self::CONTEXT,
125
+            '@id'      => $id,
126
+            '@type'    => $type,
127
+        );
128
+
129
+        if ( post_type_supports( $post->post_type, 'excerpt' ) ) {
130
+            $jsonld['description'] = Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post );
131
+        }
132
+
133
+        // Set the `mainEntityOfPage` property if the post has some contents.
134
+        /*
135 135
 		 * Apply the `wl_post_content` filter, in case 3rd parties want to change the post content, e.g.
136 136
 		 * because the content is written elsewhere.
137 137
 		 *
138 138
 		 * @since 3.20.0
139 139
 		 */
140
-		$post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
141
-		if ( ! empty( $post_content ) ) {
142
-			// We're setting the `mainEntityOfPage` to signal which one is the
143
-			// main entity for the specified URL. It might be however that the
144
-			// post/page is actually about another specific entity. How WL deals
145
-			// with that hasn't been defined yet (see https://github.com/insideout10/wordlift-plugin/issues/451).
146
-			//
147
-			// See http://schema.org/mainEntityOfPage
148
-			//
149
-			// No need to specify `'@type' => 'WebPage'.
150
-			//
151
-			// See https://github.com/insideout10/wordlift-plugin/issues/451.
152
-			$jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID );
153
-
154
-			/**
155
-			 * @see https://github.com/insideout10/wordlift-plugin/issues/1207
156
-			 *
157
-			 * @since 3.27.7
158
-			 */
159
-			if ( in_array( $type, array( 'Occupation', 'OccupationAggregationByEmployer' ), true ) ) {
160
-				$jsonld['mainEntityOfPage'] = array(
161
-					'@type'        => 'WebPage',
162
-					'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ),
163
-				);
164
-			}
165
-		};
166
-
167
-		$this->set_images( $this->attachment_service, $post, $jsonld );
168
-
169
-		// Get the entities referenced by this post and set it to the `references`
170
-		// array so that the caller can do further processing, such as printing out
171
-		// more of those references.
172
-		$references_without_locations = Object_Relation_Service::get_instance()
173
-															   ->get_references( $post_id, Object_Type_Enum::POST );
174
-
175
-		/*
140
+        $post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
141
+        if ( ! empty( $post_content ) ) {
142
+            // We're setting the `mainEntityOfPage` to signal which one is the
143
+            // main entity for the specified URL. It might be however that the
144
+            // post/page is actually about another specific entity. How WL deals
145
+            // with that hasn't been defined yet (see https://github.com/insideout10/wordlift-plugin/issues/451).
146
+            //
147
+            // See http://schema.org/mainEntityOfPage
148
+            //
149
+            // No need to specify `'@type' => 'WebPage'.
150
+            //
151
+            // See https://github.com/insideout10/wordlift-plugin/issues/451.
152
+            $jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID );
153
+
154
+            /**
155
+             * @see https://github.com/insideout10/wordlift-plugin/issues/1207
156
+             *
157
+             * @since 3.27.7
158
+             */
159
+            if ( in_array( $type, array( 'Occupation', 'OccupationAggregationByEmployer' ), true ) ) {
160
+                $jsonld['mainEntityOfPage'] = array(
161
+                    '@type'        => 'WebPage',
162
+                    'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ),
163
+                );
164
+            }
165
+        };
166
+
167
+        $this->set_images( $this->attachment_service, $post, $jsonld );
168
+
169
+        // Get the entities referenced by this post and set it to the `references`
170
+        // array so that the caller can do further processing, such as printing out
171
+        // more of those references.
172
+        $references_without_locations = Object_Relation_Service::get_instance()
173
+                                                                ->get_references( $post_id, Object_Type_Enum::POST );
174
+
175
+        /*
176 176
 		 * Add the locations to the references.
177 177
 		 *
178 178
 		 * @since 3.19.5
179 179
 		 *
180 180
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/858.
181 181
 		 */
182
-		// A reference to use in closure.
183
-		$entity_type_service = $this->entity_type_service;
184
-		$locations           = array_reduce(
185
-			$references_without_locations,
186
-			function ( $carry, $reference ) use ( $entity_type_service ) {
187
-				/**
188
-				 * @var $reference Reference
189
-				 */
190
-				// @see https://schema.org/location for the schema.org types using the `location` property.
191
-				if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' )
192
-				 && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' )
193
-				 && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) {
194
-
195
-					return $carry;
196
-				}
197
-				$post_location_ids        = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION );
198
-				$post_location_references = array_map(
199
-					function ( $post_id ) {
200
-						return new Post_Reference( $post_id );
201
-					},
202
-					$post_location_ids
203
-				);
204
-
205
-				return array_merge( $carry, $post_location_references );
206
-			},
207
-			array()
208
-		);
209
-
210
-		// Merge the references with the referenced locations if any.
211
-		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
212
-		$references = array_merge( $references_without_locations, $locations );
213
-
214
-		return $jsonld;
215
-	}
216
-
217
-	/**
218
-	 * If the provided value starts with the schema.org context, we remove the schema.org
219
-	 * part since it is set with the '@context'.
220
-	 *
221
-	 * @param string $value The property value.
222
-	 *
223
-	 * @return string The property value without the context.
224
-	 * @since 3.10.0
225
-	 */
226
-	public function relative_to_context( $value ) {
227
-		Assertions::is_string( $value, '$value is not a string: ' . var_export( $value, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
228
-
229
-		return 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value;
230
-	}
231
-
232
-	/**
233
-	 * Set the images, by looking for embedded images, for images loaded via the
234
-	 * gallery and for the featured image.
235
-	 *
236
-	 * Uses the cache service to store the results of this function for a day.
237
-	 *
238
-	 * @param $attachment_service Wordlift_Attachment_Service
239
-	 * @param WP_Post                                        $post The target {@link WP_Post}.
240
-	 * @param array                                          $jsonld The JSON-LD array.
241
-	 *
242
-	 * @since 3.10.0
243
-	 */
244
-	public static function set_images( $attachment_service, $post, &$jsonld ) {
245
-
246
-		// Prepare the attachment ids array.
247
-		$ids = array();
248
-
249
-		// Set the thumbnail id as first attachment id, if any.
250
-		$thumbnail_id = get_post_thumbnail_id( $post->ID );
251
-		if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) {
252
-			$ids[] = $thumbnail_id;
253
-		}
254
-
255
-		// For the time being the following is being removed since the query
256
-		// initiated by `get_image_embeds` is consuming lots of CPU.
257
-		//
258
-		// See https://github.com/insideout10/wordlift-plugin/issues/689.
259
-		//
260
-		// Get the embeds, removing existing ids.
261
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
262
-		if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) {
263
-			$embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids );
264
-		} else {
265
-			$embeds = array();
266
-		}
267
-
268
-		// Get the gallery, removing existing ids.
269
-		$gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds );
270
-
271
-		// Map the attachment ids to images' data structured for schema.org use.
272
-		$images_with_sizes = array_filter(
273
-			array_reduce(
274
-				array_merge( $ids, $embeds, $gallery ),
275
-				function ( $carry, $item ) {
276
-					/*
182
+        // A reference to use in closure.
183
+        $entity_type_service = $this->entity_type_service;
184
+        $locations           = array_reduce(
185
+            $references_without_locations,
186
+            function ( $carry, $reference ) use ( $entity_type_service ) {
187
+                /**
188
+                 * @var $reference Reference
189
+                 */
190
+                // @see https://schema.org/location for the schema.org types using the `location` property.
191
+                if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' )
192
+                 && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' )
193
+                 && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) {
194
+
195
+                    return $carry;
196
+                }
197
+                $post_location_ids        = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION );
198
+                $post_location_references = array_map(
199
+                    function ( $post_id ) {
200
+                        return new Post_Reference( $post_id );
201
+                    },
202
+                    $post_location_ids
203
+                );
204
+
205
+                return array_merge( $carry, $post_location_references );
206
+            },
207
+            array()
208
+        );
209
+
210
+        // Merge the references with the referenced locations if any.
211
+        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
212
+        $references = array_merge( $references_without_locations, $locations );
213
+
214
+        return $jsonld;
215
+    }
216
+
217
+    /**
218
+     * If the provided value starts with the schema.org context, we remove the schema.org
219
+     * part since it is set with the '@context'.
220
+     *
221
+     * @param string $value The property value.
222
+     *
223
+     * @return string The property value without the context.
224
+     * @since 3.10.0
225
+     */
226
+    public function relative_to_context( $value ) {
227
+        Assertions::is_string( $value, '$value is not a string: ' . var_export( $value, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
228
+
229
+        return 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value;
230
+    }
231
+
232
+    /**
233
+     * Set the images, by looking for embedded images, for images loaded via the
234
+     * gallery and for the featured image.
235
+     *
236
+     * Uses the cache service to store the results of this function for a day.
237
+     *
238
+     * @param $attachment_service Wordlift_Attachment_Service
239
+     * @param WP_Post                                        $post The target {@link WP_Post}.
240
+     * @param array                                          $jsonld The JSON-LD array.
241
+     *
242
+     * @since 3.10.0
243
+     */
244
+    public static function set_images( $attachment_service, $post, &$jsonld ) {
245
+
246
+        // Prepare the attachment ids array.
247
+        $ids = array();
248
+
249
+        // Set the thumbnail id as first attachment id, if any.
250
+        $thumbnail_id = get_post_thumbnail_id( $post->ID );
251
+        if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) {
252
+            $ids[] = $thumbnail_id;
253
+        }
254
+
255
+        // For the time being the following is being removed since the query
256
+        // initiated by `get_image_embeds` is consuming lots of CPU.
257
+        //
258
+        // See https://github.com/insideout10/wordlift-plugin/issues/689.
259
+        //
260
+        // Get the embeds, removing existing ids.
261
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
262
+        if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) {
263
+            $embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids );
264
+        } else {
265
+            $embeds = array();
266
+        }
267
+
268
+        // Get the gallery, removing existing ids.
269
+        $gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds );
270
+
271
+        // Map the attachment ids to images' data structured for schema.org use.
272
+        $images_with_sizes = array_filter(
273
+            array_reduce(
274
+                array_merge( $ids, $embeds, $gallery ),
275
+                function ( $carry, $item ) {
276
+                    /*
277 277
 					* @todo: we're not sure that we're getting attachment data here, we
278 278
 					* should filter `false`s.
279 279
 					*/
280 280
 
281
-					$sources = array_merge(
282
-						Wordlift_Image_Service::get_sources( $item ),
283
-						array( wp_get_attachment_image_src( $item, 'full' ) )
284
-					);
285
-
286
-					$sources_with_image = array_filter(
287
-						$sources,
288
-						function ( $source ) {
289
-							return ! empty( $source[0] );
290
-						}
291
-					);
292
-
293
-					// Get the attachment data.
294
-					// $attachment = wp_get_attachment_image_src( $item, 'full' );
295
-
296
-					// var_dump( array( "sources-$item" => Wordlift_Image_Service::get_sources( $item ) ) );
297
-
298
-					// Bail if image is not found.
299
-					// In some cases, you can delete the image from the database
300
-					// or from uploads dir, but the image id still exists as featured image
301
-					// or in [gallery] shortcode.
302
-					// if ( empty( $attachment[0] ) ) {
303
-					if ( empty( $sources_with_image ) ) {
304
-						return $carry;
305
-					}
306
-
307
-					// Merge the arrays.
308
-					return array_merge(
309
-						$carry,
310
-						$sources_with_image
311
-					);
312
-				},
313
-				// Initial array.
314
-
315
-				array()
316
-			)
317
-		);
318
-
319
-		// Refactor data as per schema.org specifications.
320
-		$images = array_map(
321
-			function ( $attachment ) {
322
-				return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size(
323
-					array(
324
-						'@type' => 'ImageObject',
325
-						'url'   => $attachment[0],
326
-					),
327
-					$attachment
328
-				);
329
-			},
330
-			$images_with_sizes
331
-		);
332
-
333
-		// Add images if present.
334
-		if ( 0 < count( $images ) ) {
335
-			$jsonld['image'] = $images;
336
-		}
337
-
338
-	}
339
-
340
-	/**
341
-	 * If the provided array of values contains only one value, then one single
342
-	 * value is returned, otherwise the original array is returned.
343
-	 *
344
-	 * @param array $value An array of values.
345
-	 *
346
-	 * @return mixed|array A single value or the original array.
347
-	 * @since 3.20.0 The function has been moved from {@link Wordlift_Entity_Post_To_Jsonld_Converter} to
348
-	 *  {@link Wordlift_Abstract_Post_To_Jsonld_Converter}.
349
-	 * @since  3.8.0
350
-	 * @access private
351
-	 */
352
-	protected static function make_one( $value ) {
353
-
354
-		return 1 === count( $value ) ? $value[0] : $value;
355
-	}
356
-
357
-	/**
358
-	 * Process the provided array by adding the width / height if the values
359
-	 * are available and are greater than 0.
360
-	 *
361
-	 * @param array $image The `ImageObject` array.
362
-	 * @param array $attachment The attachment array.
363
-	 *
364
-	 * @return array The enriched `ImageObject` array.
365
-	 * @since 3.14.0
366
-	 */
367
-	public static function set_image_size( $image, $attachment ) {
368
-
369
-		// If you specify a "width" or "height" value you should leave out
370
-		// 'px'. For example: "width":"4608px" should be "width":"4608".
371
-		//
372
-		// See https://github.com/insideout10/wordlift-plugin/issues/451.
373
-		if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) {
374
-			$image['width'] = $attachment[1];
375
-		}
376
-
377
-		if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) {
378
-			$image['height'] = $attachment[2];
379
-		}
380
-
381
-		return $image;
382
-	}
383
-
384
-	/**
385
-	 * Add data to the JSON-LD using the `custom_fields` array which contains the definitions of property
386
-	 * for the post entity type.
387
-	 *
388
-	 * @param array   $jsonld The JSON-LD array.
389
-	 * @param array   $fields The entity types field array.
390
-	 * @param WP_Post $post The target {@link WP_Post} instance.
391
-	 * @param array   $references The references array.
392
-	 *
393
-	 * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in
394
-	 *  the {@link Wordlift_Schema_Service} class.
395
-	 */
396
-	protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) {
397
-
398
-		// Set a reference to use in closures.
399
-		$converter = $this;
400
-
401
-		// Try each field on the entity.
402
-		foreach ( $fields as $key => $value ) {
403
-
404
-			// Get the predicate.
405
-			$name = $this->relative_to_context( $value['predicate'] );
406
-
407
-			// Get the value, the property service will get the right extractor
408
-			// for that property.
409
-			$value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST );
410
-
411
-			if ( empty( $value ) ) {
412
-				continue;
413
-			}
414
-
415
-			// Map the value to the property name.
416
-			// If we got an array with just one value, we return that one value.
417
-			// If we got a Wordlift_Property_Entity_Reference we get the URL.
418
-			$jsonld[ $name ] = self::make_one(
419
-				array_map(
420
-					function ( $item ) use ( $converter, &$references, &$references_infos ) {
421
-
422
-						if ( $item instanceof Wordlift_Property_Entity_Reference ) {
423
-
424
-							  $url = $item->get_url();
425
-
426
-							  // The refactored converters require the entity id.
427
-							// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
428
-							  $references[] = $item->to_reference();
429
-
430
-							// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
431
-							  $references_infos[] = array( 'reference' => $item );
432
-
433
-							  return array( '@id' => $url );
434
-						}
435
-
436
-						return $converter->relative_to_context( $item );
437
-					},
438
-					$value
439
-				)
440
-			);
441
-
442
-		}
443
-
444
-	}
281
+                    $sources = array_merge(
282
+                        Wordlift_Image_Service::get_sources( $item ),
283
+                        array( wp_get_attachment_image_src( $item, 'full' ) )
284
+                    );
285
+
286
+                    $sources_with_image = array_filter(
287
+                        $sources,
288
+                        function ( $source ) {
289
+                            return ! empty( $source[0] );
290
+                        }
291
+                    );
292
+
293
+                    // Get the attachment data.
294
+                    // $attachment = wp_get_attachment_image_src( $item, 'full' );
295
+
296
+                    // var_dump( array( "sources-$item" => Wordlift_Image_Service::get_sources( $item ) ) );
297
+
298
+                    // Bail if image is not found.
299
+                    // In some cases, you can delete the image from the database
300
+                    // or from uploads dir, but the image id still exists as featured image
301
+                    // or in [gallery] shortcode.
302
+                    // if ( empty( $attachment[0] ) ) {
303
+                    if ( empty( $sources_with_image ) ) {
304
+                        return $carry;
305
+                    }
306
+
307
+                    // Merge the arrays.
308
+                    return array_merge(
309
+                        $carry,
310
+                        $sources_with_image
311
+                    );
312
+                },
313
+                // Initial array.
314
+
315
+                array()
316
+            )
317
+        );
318
+
319
+        // Refactor data as per schema.org specifications.
320
+        $images = array_map(
321
+            function ( $attachment ) {
322
+                return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size(
323
+                    array(
324
+                        '@type' => 'ImageObject',
325
+                        'url'   => $attachment[0],
326
+                    ),
327
+                    $attachment
328
+                );
329
+            },
330
+            $images_with_sizes
331
+        );
332
+
333
+        // Add images if present.
334
+        if ( 0 < count( $images ) ) {
335
+            $jsonld['image'] = $images;
336
+        }
337
+
338
+    }
339
+
340
+    /**
341
+     * If the provided array of values contains only one value, then one single
342
+     * value is returned, otherwise the original array is returned.
343
+     *
344
+     * @param array $value An array of values.
345
+     *
346
+     * @return mixed|array A single value or the original array.
347
+     * @since 3.20.0 The function has been moved from {@link Wordlift_Entity_Post_To_Jsonld_Converter} to
348
+     *  {@link Wordlift_Abstract_Post_To_Jsonld_Converter}.
349
+     * @since  3.8.0
350
+     * @access private
351
+     */
352
+    protected static function make_one( $value ) {
353
+
354
+        return 1 === count( $value ) ? $value[0] : $value;
355
+    }
356
+
357
+    /**
358
+     * Process the provided array by adding the width / height if the values
359
+     * are available and are greater than 0.
360
+     *
361
+     * @param array $image The `ImageObject` array.
362
+     * @param array $attachment The attachment array.
363
+     *
364
+     * @return array The enriched `ImageObject` array.
365
+     * @since 3.14.0
366
+     */
367
+    public static function set_image_size( $image, $attachment ) {
368
+
369
+        // If you specify a "width" or "height" value you should leave out
370
+        // 'px'. For example: "width":"4608px" should be "width":"4608".
371
+        //
372
+        // See https://github.com/insideout10/wordlift-plugin/issues/451.
373
+        if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) {
374
+            $image['width'] = $attachment[1];
375
+        }
376
+
377
+        if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) {
378
+            $image['height'] = $attachment[2];
379
+        }
380
+
381
+        return $image;
382
+    }
383
+
384
+    /**
385
+     * Add data to the JSON-LD using the `custom_fields` array which contains the definitions of property
386
+     * for the post entity type.
387
+     *
388
+     * @param array   $jsonld The JSON-LD array.
389
+     * @param array   $fields The entity types field array.
390
+     * @param WP_Post $post The target {@link WP_Post} instance.
391
+     * @param array   $references The references array.
392
+     *
393
+     * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in
394
+     *  the {@link Wordlift_Schema_Service} class.
395
+     */
396
+    protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) {
397
+
398
+        // Set a reference to use in closures.
399
+        $converter = $this;
400
+
401
+        // Try each field on the entity.
402
+        foreach ( $fields as $key => $value ) {
403
+
404
+            // Get the predicate.
405
+            $name = $this->relative_to_context( $value['predicate'] );
406
+
407
+            // Get the value, the property service will get the right extractor
408
+            // for that property.
409
+            $value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST );
410
+
411
+            if ( empty( $value ) ) {
412
+                continue;
413
+            }
414
+
415
+            // Map the value to the property name.
416
+            // If we got an array with just one value, we return that one value.
417
+            // If we got a Wordlift_Property_Entity_Reference we get the URL.
418
+            $jsonld[ $name ] = self::make_one(
419
+                array_map(
420
+                    function ( $item ) use ( $converter, &$references, &$references_infos ) {
421
+
422
+                        if ( $item instanceof Wordlift_Property_Entity_Reference ) {
423
+
424
+                                $url = $item->get_url();
425
+
426
+                                // The refactored converters require the entity id.
427
+                            // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
428
+                                $references[] = $item->to_reference();
429
+
430
+                            // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
431
+                                $references_infos[] = array( 'reference' => $item );
432
+
433
+                                return array( '@id' => $url );
434
+                        }
435
+
436
+                        return $converter->relative_to_context( $item );
437
+                    },
438
+                    $value
439
+                )
440
+            );
441
+
442
+        }
443
+
444
+    }
445 445
 
446 446
 }
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 *
74 74
 	 * @since 3.10.0
75 75
 	 */
76
-	public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter ) {
76
+	public function __construct($entity_type_service, $user_service, $attachment_service, $property_getter) {
77 77
 		$this->entity_type_service = $entity_type_service;
78 78
 		$this->user_service        = $user_service;
79 79
 		$this->attachment_service  = $attachment_service;
@@ -92,19 +92,19 @@  discard block
 block discarded – undo
92 92
 	 * @since 3.10.0
93 93
 	 */
94 94
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
95
-	public function convert( $post_id, &$references = array(), &$references_infos = array() ) {
95
+	public function convert($post_id, &$references = array(), &$references_infos = array()) {
96 96
 
97 97
 		// Get the post instance.
98
-		$post = get_post( $post_id );
99
-		if ( null === $post ) {
98
+		$post = get_post($post_id);
99
+		if (null === $post) {
100 100
 			// Post not found.
101 101
 			return null;
102 102
 		}
103 103
 
104 104
 		// Get the post URI @id.
105
-		$id = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID );
106
-		if ( $id === null ) {
107
-			$id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri();
105
+		$id = Wordlift_Entity_Service::get_instance()->get_uri($post->ID);
106
+		if ($id === null) {
107
+			$id = 'get_uri returned null, dataset is '.wl_configuration_get_redlink_dataset_uri();
108 108
 		}
109 109
 
110 110
 		/*
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
 		 */
117 117
 		// Get the entity @type. We consider `post` BlogPostings.
118 118
 		// $type = $this->entity_type_service->get( $post_id );
119
-		$types = $this->entity_type_service->get_names( $post_id );
120
-		$type  = self::make_one( $types );
119
+		$types = $this->entity_type_service->get_names($post_id);
120
+		$type  = self::make_one($types);
121 121
 
122 122
 		// Prepare the response.
123 123
 		$jsonld = array(
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
 			'@type'    => $type,
127 127
 		);
128 128
 
129
-		if ( post_type_supports( $post->post_type, 'excerpt' ) ) {
130
-			$jsonld['description'] = Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post );
129
+		if (post_type_supports($post->post_type, 'excerpt')) {
130
+			$jsonld['description'] = Wordlift_Post_Excerpt_Helper::get_text_excerpt($post);
131 131
 		}
132 132
 
133 133
 		// Set the `mainEntityOfPage` property if the post has some contents.
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 		 *
138 138
 		 * @since 3.20.0
139 139
 		 */
140
-		$post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
141
-		if ( ! empty( $post_content ) ) {
140
+		$post_content = apply_filters('wl_post_content', $post->post_content, $post);
141
+		if ( ! empty($post_content)) {
142 142
 			// We're setting the `mainEntityOfPage` to signal which one is the
143 143
 			// main entity for the specified URL. It might be however that the
144 144
 			// post/page is actually about another specific entity. How WL deals
@@ -149,28 +149,28 @@  discard block
 block discarded – undo
149 149
 			// No need to specify `'@type' => 'WebPage'.
150 150
 			//
151 151
 			// See https://github.com/insideout10/wordlift-plugin/issues/451.
152
-			$jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID );
152
+			$jsonld['mainEntityOfPage'] = get_the_permalink($post->ID);
153 153
 
154 154
 			/**
155 155
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/1207
156 156
 			 *
157 157
 			 * @since 3.27.7
158 158
 			 */
159
-			if ( in_array( $type, array( 'Occupation', 'OccupationAggregationByEmployer' ), true ) ) {
159
+			if (in_array($type, array('Occupation', 'OccupationAggregationByEmployer'), true)) {
160 160
 				$jsonld['mainEntityOfPage'] = array(
161 161
 					'@type'        => 'WebPage',
162
-					'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ),
162
+					'lastReviewed' => get_post_time('Y-m-d\TH:i:sP', true, $post, false),
163 163
 				);
164 164
 			}
165 165
 		};
166 166
 
167
-		$this->set_images( $this->attachment_service, $post, $jsonld );
167
+		$this->set_images($this->attachment_service, $post, $jsonld);
168 168
 
169 169
 		// Get the entities referenced by this post and set it to the `references`
170 170
 		// array so that the caller can do further processing, such as printing out
171 171
 		// more of those references.
172 172
 		$references_without_locations = Object_Relation_Service::get_instance()
173
-															   ->get_references( $post_id, Object_Type_Enum::POST );
173
+															   ->get_references($post_id, Object_Type_Enum::POST);
174 174
 
175 175
 		/*
176 176
 		 * Add the locations to the references.
@@ -183,33 +183,33 @@  discard block
 block discarded – undo
183 183
 		$entity_type_service = $this->entity_type_service;
184 184
 		$locations           = array_reduce(
185 185
 			$references_without_locations,
186
-			function ( $carry, $reference ) use ( $entity_type_service ) {
186
+			function($carry, $reference) use ($entity_type_service) {
187 187
 				/**
188 188
 				 * @var $reference Reference
189 189
 				 */
190 190
 				// @see https://schema.org/location for the schema.org types using the `location` property.
191
-				if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' )
192
-				 && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' )
193
-				 && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) {
191
+				if ( ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Action')
192
+				 && ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Event')
193
+				 && ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Organization')) {
194 194
 
195 195
 					return $carry;
196 196
 				}
197
-				$post_location_ids        = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION );
197
+				$post_location_ids        = get_post_meta($reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION);
198 198
 				$post_location_references = array_map(
199
-					function ( $post_id ) {
200
-						return new Post_Reference( $post_id );
199
+					function($post_id) {
200
+						return new Post_Reference($post_id);
201 201
 					},
202 202
 					$post_location_ids
203 203
 				);
204 204
 
205
-				return array_merge( $carry, $post_location_references );
205
+				return array_merge($carry, $post_location_references);
206 206
 			},
207 207
 			array()
208 208
 		);
209 209
 
210 210
 		// Merge the references with the referenced locations if any.
211 211
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
212
-		$references = array_merge( $references_without_locations, $locations );
212
+		$references = array_merge($references_without_locations, $locations);
213 213
 
214 214
 		return $jsonld;
215 215
 	}
@@ -223,10 +223,10 @@  discard block
 block discarded – undo
223 223
 	 * @return string The property value without the context.
224 224
 	 * @since 3.10.0
225 225
 	 */
226
-	public function relative_to_context( $value ) {
227
-		Assertions::is_string( $value, '$value is not a string: ' . var_export( $value, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
226
+	public function relative_to_context($value) {
227
+		Assertions::is_string($value, '$value is not a string: '.var_export($value, true)); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
228 228
 
229
-		return 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value;
229
+		return 0 === strpos($value, self::CONTEXT.'/') ? substr($value, strlen(self::CONTEXT) + 1) : $value;
230 230
 	}
231 231
 
232 232
 	/**
@@ -241,14 +241,14 @@  discard block
 block discarded – undo
241 241
 	 *
242 242
 	 * @since 3.10.0
243 243
 	 */
244
-	public static function set_images( $attachment_service, $post, &$jsonld ) {
244
+	public static function set_images($attachment_service, $post, &$jsonld) {
245 245
 
246 246
 		// Prepare the attachment ids array.
247 247
 		$ids = array();
248 248
 
249 249
 		// Set the thumbnail id as first attachment id, if any.
250
-		$thumbnail_id = get_post_thumbnail_id( $post->ID );
251
-		if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) {
250
+		$thumbnail_id = get_post_thumbnail_id($post->ID);
251
+		if ('' !== $thumbnail_id && 0 !== $thumbnail_id) {
252 252
 			$ids[] = $thumbnail_id;
253 253
 		}
254 254
 
@@ -259,34 +259,34 @@  discard block
 block discarded – undo
259 259
 		//
260 260
 		// Get the embeds, removing existing ids.
261 261
 		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
262
-		if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) {
263
-			$embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids );
262
+		if (apply_filters('wl_feature__enable__image-embeds', false)) {
263
+			$embeds = array_diff($attachment_service->get_image_embeds($post->post_content), $ids);
264 264
 		} else {
265 265
 			$embeds = array();
266 266
 		}
267 267
 
268 268
 		// Get the gallery, removing existing ids.
269
-		$gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds );
269
+		$gallery = array_diff($attachment_service->get_gallery($post), $ids, $embeds);
270 270
 
271 271
 		// Map the attachment ids to images' data structured for schema.org use.
272 272
 		$images_with_sizes = array_filter(
273 273
 			array_reduce(
274
-				array_merge( $ids, $embeds, $gallery ),
275
-				function ( $carry, $item ) {
274
+				array_merge($ids, $embeds, $gallery),
275
+				function($carry, $item) {
276 276
 					/*
277 277
 					* @todo: we're not sure that we're getting attachment data here, we
278 278
 					* should filter `false`s.
279 279
 					*/
280 280
 
281 281
 					$sources = array_merge(
282
-						Wordlift_Image_Service::get_sources( $item ),
283
-						array( wp_get_attachment_image_src( $item, 'full' ) )
282
+						Wordlift_Image_Service::get_sources($item),
283
+						array(wp_get_attachment_image_src($item, 'full'))
284 284
 					);
285 285
 
286 286
 					$sources_with_image = array_filter(
287 287
 						$sources,
288
-						function ( $source ) {
289
-							return ! empty( $source[0] );
288
+						function($source) {
289
+							return ! empty($source[0]);
290 290
 						}
291 291
 					);
292 292
 
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 					// or from uploads dir, but the image id still exists as featured image
301 301
 					// or in [gallery] shortcode.
302 302
 					// if ( empty( $attachment[0] ) ) {
303
-					if ( empty( $sources_with_image ) ) {
303
+					if (empty($sources_with_image)) {
304 304
 						return $carry;
305 305
 					}
306 306
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 
319 319
 		// Refactor data as per schema.org specifications.
320 320
 		$images = array_map(
321
-			function ( $attachment ) {
321
+			function($attachment) {
322 322
 				return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size(
323 323
 					array(
324 324
 						'@type' => 'ImageObject',
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 		);
332 332
 
333 333
 		// Add images if present.
334
-		if ( 0 < count( $images ) ) {
334
+		if (0 < count($images)) {
335 335
 			$jsonld['image'] = $images;
336 336
 		}
337 337
 
@@ -349,9 +349,9 @@  discard block
 block discarded – undo
349 349
 	 * @since  3.8.0
350 350
 	 * @access private
351 351
 	 */
352
-	protected static function make_one( $value ) {
352
+	protected static function make_one($value) {
353 353
 
354
-		return 1 === count( $value ) ? $value[0] : $value;
354
+		return 1 === count($value) ? $value[0] : $value;
355 355
 	}
356 356
 
357 357
 	/**
@@ -364,17 +364,17 @@  discard block
 block discarded – undo
364 364
 	 * @return array The enriched `ImageObject` array.
365 365
 	 * @since 3.14.0
366 366
 	 */
367
-	public static function set_image_size( $image, $attachment ) {
367
+	public static function set_image_size($image, $attachment) {
368 368
 
369 369
 		// If you specify a "width" or "height" value you should leave out
370 370
 		// 'px'. For example: "width":"4608px" should be "width":"4608".
371 371
 		//
372 372
 		// See https://github.com/insideout10/wordlift-plugin/issues/451.
373
-		if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) {
373
+		if (isset($attachment[1]) && is_numeric($attachment[1]) && 0 < $attachment[1]) {
374 374
 			$image['width'] = $attachment[1];
375 375
 		}
376 376
 
377
-		if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) {
377
+		if (isset($attachment[2]) && is_numeric($attachment[2]) && 0 < $attachment[2]) {
378 378
 			$image['height'] = $attachment[2];
379 379
 		}
380 380
 
@@ -393,33 +393,33 @@  discard block
 block discarded – undo
393 393
 	 * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in
394 394
 	 *  the {@link Wordlift_Schema_Service} class.
395 395
 	 */
396
-	protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) {
396
+	protected function process_type_custom_fields(&$jsonld, $fields, $post, &$references, &$references_infos) {
397 397
 
398 398
 		// Set a reference to use in closures.
399 399
 		$converter = $this;
400 400
 
401 401
 		// Try each field on the entity.
402
-		foreach ( $fields as $key => $value ) {
402
+		foreach ($fields as $key => $value) {
403 403
 
404 404
 			// Get the predicate.
405
-			$name = $this->relative_to_context( $value['predicate'] );
405
+			$name = $this->relative_to_context($value['predicate']);
406 406
 
407 407
 			// Get the value, the property service will get the right extractor
408 408
 			// for that property.
409
-			$value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST );
409
+			$value = $this->property_getter->get($post->ID, $key, Object_Type_Enum::POST);
410 410
 
411
-			if ( empty( $value ) ) {
411
+			if (empty($value)) {
412 412
 				continue;
413 413
 			}
414 414
 
415 415
 			// Map the value to the property name.
416 416
 			// If we got an array with just one value, we return that one value.
417 417
 			// If we got a Wordlift_Property_Entity_Reference we get the URL.
418
-			$jsonld[ $name ] = self::make_one(
418
+			$jsonld[$name] = self::make_one(
419 419
 				array_map(
420
-					function ( $item ) use ( $converter, &$references, &$references_infos ) {
420
+					function($item) use ($converter, &$references, &$references_infos) {
421 421
 
422
-						if ( $item instanceof Wordlift_Property_Entity_Reference ) {
422
+						if ($item instanceof Wordlift_Property_Entity_Reference) {
423 423
 
424 424
 							  $url = $item->get_url();
425 425
 
@@ -428,12 +428,12 @@  discard block
 block discarded – undo
428 428
 							  $references[] = $item->to_reference();
429 429
 
430 430
 							// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
431
-							  $references_infos[] = array( 'reference' => $item );
431
+							  $references_infos[] = array('reference' => $item);
432 432
 
433
-							  return array( '@id' => $url );
433
+							  return array('@id' => $url);
434 434
 						}
435 435
 
436
-						return $converter->relative_to_context( $item );
436
+						return $converter->relative_to_context($item);
437 437
 					},
438 438
 					$value
439 439
 				)
Please login to merge, or discard this patch.
src/includes/class-wordlift-post-excerpt-helper.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -23,55 +23,55 @@
 block discarded – undo
23 23
  */
24 24
 class Wordlift_Post_Excerpt_Helper {
25 25
 
26
-	/**
27
-	 * Get the text excerpt for the provided {@link WP_Post}.
28
-	 *
29
-	 * Since anyone can hook on the excerpt generation filters, and
30
-	 * amend it with non textual content, we play it self and generate
31
-	 * the excerpt ourselves, mimicking the way WordPress core does it.
32
-	 *
33
-	 * @since 3.10.0
34
-	 *
35
-	 * @param WP_Post $post The {@link WP_Post}.
36
-	 * @param int     $length The desired excerpt length.
37
-	 * @param string  $more The desired more string.
38
-	 *
39
-	 * @return string The excerpt.
40
-	 */
41
-	public static function get_text_excerpt( $post, $length = 55, $more = '...' ) {
26
+    /**
27
+     * Get the text excerpt for the provided {@link WP_Post}.
28
+     *
29
+     * Since anyone can hook on the excerpt generation filters, and
30
+     * amend it with non textual content, we play it self and generate
31
+     * the excerpt ourselves, mimicking the way WordPress core does it.
32
+     *
33
+     * @since 3.10.0
34
+     *
35
+     * @param WP_Post $post The {@link WP_Post}.
36
+     * @param int     $length The desired excerpt length.
37
+     * @param string  $more The desired more string.
38
+     *
39
+     * @return string The excerpt.
40
+     */
41
+    public static function get_text_excerpt( $post, $length = 55, $more = '...' ) {
42 42
 
43
-		/*
43
+        /*
44 44
 		 * Apply the `wl_post_content` filter, in case 3rd parties want to change the post content, e.g.
45 45
 		 * because the content is written elsewhere.
46 46
 		 *
47 47
 		 * @since 3.20.0
48 48
 		 */
49
-		$post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
49
+        $post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
50 50
 
51
-		// Filter shortcode content in post_content, before using it for trimming
52
-		$post_content = do_shortcode( $post_content );
51
+        // Filter shortcode content in post_content, before using it for trimming
52
+        $post_content = do_shortcode( $post_content );
53 53
 
54
-		// Get the excerpt and trim it. Use the `post_excerpt` if available.
55
-		$excerpt = wp_trim_words( ! empty( $post->post_excerpt ) ? $post->post_excerpt : $post_content, $length, $more );
54
+        // Get the excerpt and trim it. Use the `post_excerpt` if available.
55
+        $excerpt = wp_trim_words( ! empty( $post->post_excerpt ) ? $post->post_excerpt : $post_content, $length, $more );
56 56
 
57
-		// Remove shortcodes and decode html entities.
58
-		return wp_strip_all_tags( html_entity_decode( self::strip_all_shortcodes( $excerpt ) ) );
59
-	}
57
+        // Remove shortcodes and decode html entities.
58
+        return wp_strip_all_tags( html_entity_decode( self::strip_all_shortcodes( $excerpt ) ) );
59
+    }
60 60
 
61
-	/**
62
-	 * Remove all the shortcodes from the content. We're using our own function
63
-	 * because WordPress' own `strip_shortcodes` only takes into consideration
64
-	 * shortcodes for installed plugins/themes.
65
-	 *
66
-	 * @since 3.12.0
67
-	 *
68
-	 * @param string $content The content with shortcodes.
69
-	 *
70
-	 * @return string The content without shortcodes.
71
-	 */
72
-	private static function strip_all_shortcodes( $content ) {
61
+    /**
62
+     * Remove all the shortcodes from the content. We're using our own function
63
+     * because WordPress' own `strip_shortcodes` only takes into consideration
64
+     * shortcodes for installed plugins/themes.
65
+     *
66
+     * @since 3.12.0
67
+     *
68
+     * @param string $content The content with shortcodes.
69
+     *
70
+     * @return string The content without shortcodes.
71
+     */
72
+    private static function strip_all_shortcodes( $content ) {
73 73
 
74
-		return preg_replace( '/\[[^]]+\]/', '', $content );
75
-	}
74
+        return preg_replace( '/\[[^]]+\]/', '', $content );
75
+    }
76 76
 
77 77
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return string The excerpt.
40 40
 	 */
41
-	public static function get_text_excerpt( $post, $length = 55, $more = '...' ) {
41
+	public static function get_text_excerpt($post, $length = 55, $more = '...') {
42 42
 
43 43
 		/*
44 44
 		 * Apply the `wl_post_content` filter, in case 3rd parties want to change the post content, e.g.
@@ -46,16 +46,16 @@  discard block
 block discarded – undo
46 46
 		 *
47 47
 		 * @since 3.20.0
48 48
 		 */
49
-		$post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
49
+		$post_content = apply_filters('wl_post_content', $post->post_content, $post);
50 50
 
51 51
 		// Filter shortcode content in post_content, before using it for trimming
52
-		$post_content = do_shortcode( $post_content );
52
+		$post_content = do_shortcode($post_content);
53 53
 
54 54
 		// Get the excerpt and trim it. Use the `post_excerpt` if available.
55
-		$excerpt = wp_trim_words( ! empty( $post->post_excerpt ) ? $post->post_excerpt : $post_content, $length, $more );
55
+		$excerpt = wp_trim_words( ! empty($post->post_excerpt) ? $post->post_excerpt : $post_content, $length, $more);
56 56
 
57 57
 		// Remove shortcodes and decode html entities.
58
-		return wp_strip_all_tags( html_entity_decode( self::strip_all_shortcodes( $excerpt ) ) );
58
+		return wp_strip_all_tags(html_entity_decode(self::strip_all_shortcodes($excerpt)));
59 59
 	}
60 60
 
61 61
 	/**
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return string The content without shortcodes.
71 71
 	 */
72
-	private static function strip_all_shortcodes( $content ) {
72
+	private static function strip_all_shortcodes($content) {
73 73
 
74
-		return preg_replace( '/\[[^]]+\]/', '', $content );
74
+		return preg_replace('/\[[^]]+\]/', '', $content);
75 75
 	}
76 76
 
77 77
 }
Please login to merge, or discard this patch.
src/wordlift/vocabulary-terms/jsonld/class-jsonld-generator.php 2 patches
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -11,167 +11,167 @@
 block discarded – undo
11 11
 
12 12
 class Jsonld_Generator {
13 13
 
14
-	/**
15
-	 * @var \Wordlift_Entity_Type_Service
16
-	 */
17
-	private $entity_type_service;
18
-	/**
19
-	 * @var \Wordlift_Property_Getter
20
-	 */
21
-	private $property_getter;
22
-	/**
23
-	 * @var Type_Service
24
-	 */
25
-	private $term_entity_type_service;
26
-	/**
27
-	 * @var \Wordlift_Entity_Service
28
-	 */
29
-	private $entity_service;
30
-
31
-	public function __construct( $entity_type_service, $property_getter ) {
32
-		$this->entity_type_service      = $entity_type_service;
33
-		$this->property_getter          = $property_getter;
34
-		$this->term_entity_type_service = Type_Service::get_instance();
35
-		$this->entity_service           = \Wordlift_Entity_Service::get_instance();
36
-	}
37
-
38
-	public function init() {
39
-		add_filter( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 );
40
-	}
41
-
42
-	public function wl_term_jsonld_array( $data, $term_id ) {
43
-		$jsonld     = $data['jsonld'];
44
-		$references = $data['references'];
45
-
46
-		$term_jsonld_data = $this->get_jsonld_data_for_term( $term_id );
47
-
48
-		// Return early if we dont have the entity data
49
-		// for the term.
50
-		if ( ! $term_jsonld_data ) {
51
-			return $data;
52
-		}
53
-
54
-		$term_jsonld = $term_jsonld_data['jsonld'];
55
-
56
-		$references = array_merge( $references, $term_jsonld_data['references'] );
57
-
58
-		array_unshift( $jsonld, $term_jsonld );
59
-
60
-		return array(
61
-			'jsonld'     => $jsonld,
62
-			'references' => $references,
63
-		);
64
-	}
65
-
66
-	private function get_jsonld_data_for_term( $term_id ) {
67
-
68
-		$id = $this->entity_service->get_uri( $term_id, Object_Type_Enum::TERM );
69
-
70
-		// If we don't have a dataset  URI, then don't publish the term data
71
-		// on this page.
72
-		if ( ! $id ) {
73
-			return false;
74
-		}
75
-
76
-		$references = array();
77
-		$term       = get_term( $term_id );
78
-		$permalink  = get_term_link( $term );
79
-
80
-		$custom_fields = $this->entity_type_service->get_custom_fields_for_term( $term_id );
81
-		$term          = get_term( $term_id );
82
-		$jsonld        = array(
83
-			'@context'    => 'http://schema.org',
84
-			'name'        => $term->name,
85
-			'@type'       => $this->term_entity_type_service->get_entity_types_labels( $term_id ),
86
-			'@id'         => $id,
87
-			'description' => wp_strip_all_tags( self::strip_all_shortcodes( $term->description ) ),
88
-		);
89
-
90
-		if ( ! $custom_fields || ! is_array( $custom_fields ) ) {
91
-			return $jsonld;
92
-		}
93
-
94
-		foreach ( $custom_fields as $key => $value ) {
95
-			$name  = $this->relative_to_schema_context( $value['predicate'] );
96
-			$value = $this->property_getter->get( $term_id, $key, Object_Type_Enum::TERM );
97
-			$value = $this->process_value( $value, $references );
98
-			if ( ! isset( $value ) ||
99
-				 is_array( $value ) && empty( $value ) ||
100
-				 is_string( $value ) && empty( $value ) ) {
101
-				continue;
102
-			}
103
-			$jsonld[ $name ] = $value;
104
-
105
-		}
106
-
107
-		$jsonld = \Wordlift_Entity_Post_To_Jsonld_Converter::post_process( $jsonld );
108
-
109
-		if ( $permalink ) {
110
-			$jsonld['mainEntityOfPage'] = $permalink;
111
-		}
112
-
113
-		return apply_filters(
114
-			'wl_no_vocabulary_term_jsonld_array',
115
-			array(
116
-				'jsonld'     => $jsonld,
117
-				'references' => $references,
118
-			),
119
-			$term_id
120
-		);
121
-
122
-	}
123
-
124
-	private function relative_to_schema_context( $predicate ) {
125
-		return str_replace( 'http://schema.org/', '', $predicate );
126
-	}
127
-
128
-	private function process_value( $value, &$references ) {
129
-
130
-		if ( is_array( $value )
131
-			 && count( $value ) > 0
132
-			 && $value[0] instanceof \Wordlift_Property_Entity_Reference ) {
133
-
134
-			// All of the references from the custom fields are post references.
135
-			$references = array_merge(
136
-				$references,
137
-				array_map(
138
-					function ( $property_entity_reference ) {
139
-						/**
140
-						 * @var $property_entity_reference \Wordlift_Property_Entity_Reference
141
-						 */
142
-						return $property_entity_reference->to_reference();
143
-					},
144
-					$value
145
-				)
146
-			);
147
-
148
-			return array_map(
149
-				function ( $reference ) {
150
-					/**
151
-					 * @var $reference \Wordlift_Property_Entity_Reference
152
-					 */
153
-					return array( '@id' => $reference->get_url() );
154
-				},
155
-				$value
156
-			);
157
-
158
-		}
159
-
160
-		return $value;
161
-	}
162
-
163
-	/**
164
-	 * Remove all the shortcodes from the content. We're using our own function
165
-	 * because WordPress' own `strip_shortcodes` only takes into consideration
166
-	 * shortcodes for installed plugins/themes.
167
-	 *
168
-	 * @since 3.12.0
169
-	 *
170
-	 * @param string $content The content with shortcodes.
171
-	 *
172
-	 * @return string The content without shortcodes.
173
-	 */
174
-	private static function strip_all_shortcodes( $content ) {
175
-		return preg_replace( '/\[[^]]+\]/', '', $content );
176
-	}
14
+    /**
15
+     * @var \Wordlift_Entity_Type_Service
16
+     */
17
+    private $entity_type_service;
18
+    /**
19
+     * @var \Wordlift_Property_Getter
20
+     */
21
+    private $property_getter;
22
+    /**
23
+     * @var Type_Service
24
+     */
25
+    private $term_entity_type_service;
26
+    /**
27
+     * @var \Wordlift_Entity_Service
28
+     */
29
+    private $entity_service;
30
+
31
+    public function __construct( $entity_type_service, $property_getter ) {
32
+        $this->entity_type_service      = $entity_type_service;
33
+        $this->property_getter          = $property_getter;
34
+        $this->term_entity_type_service = Type_Service::get_instance();
35
+        $this->entity_service           = \Wordlift_Entity_Service::get_instance();
36
+    }
37
+
38
+    public function init() {
39
+        add_filter( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 );
40
+    }
41
+
42
+    public function wl_term_jsonld_array( $data, $term_id ) {
43
+        $jsonld     = $data['jsonld'];
44
+        $references = $data['references'];
45
+
46
+        $term_jsonld_data = $this->get_jsonld_data_for_term( $term_id );
47
+
48
+        // Return early if we dont have the entity data
49
+        // for the term.
50
+        if ( ! $term_jsonld_data ) {
51
+            return $data;
52
+        }
53
+
54
+        $term_jsonld = $term_jsonld_data['jsonld'];
55
+
56
+        $references = array_merge( $references, $term_jsonld_data['references'] );
57
+
58
+        array_unshift( $jsonld, $term_jsonld );
59
+
60
+        return array(
61
+            'jsonld'     => $jsonld,
62
+            'references' => $references,
63
+        );
64
+    }
65
+
66
+    private function get_jsonld_data_for_term( $term_id ) {
67
+
68
+        $id = $this->entity_service->get_uri( $term_id, Object_Type_Enum::TERM );
69
+
70
+        // If we don't have a dataset  URI, then don't publish the term data
71
+        // on this page.
72
+        if ( ! $id ) {
73
+            return false;
74
+        }
75
+
76
+        $references = array();
77
+        $term       = get_term( $term_id );
78
+        $permalink  = get_term_link( $term );
79
+
80
+        $custom_fields = $this->entity_type_service->get_custom_fields_for_term( $term_id );
81
+        $term          = get_term( $term_id );
82
+        $jsonld        = array(
83
+            '@context'    => 'http://schema.org',
84
+            'name'        => $term->name,
85
+            '@type'       => $this->term_entity_type_service->get_entity_types_labels( $term_id ),
86
+            '@id'         => $id,
87
+            'description' => wp_strip_all_tags( self::strip_all_shortcodes( $term->description ) ),
88
+        );
89
+
90
+        if ( ! $custom_fields || ! is_array( $custom_fields ) ) {
91
+            return $jsonld;
92
+        }
93
+
94
+        foreach ( $custom_fields as $key => $value ) {
95
+            $name  = $this->relative_to_schema_context( $value['predicate'] );
96
+            $value = $this->property_getter->get( $term_id, $key, Object_Type_Enum::TERM );
97
+            $value = $this->process_value( $value, $references );
98
+            if ( ! isset( $value ) ||
99
+                 is_array( $value ) && empty( $value ) ||
100
+                 is_string( $value ) && empty( $value ) ) {
101
+                continue;
102
+            }
103
+            $jsonld[ $name ] = $value;
104
+
105
+        }
106
+
107
+        $jsonld = \Wordlift_Entity_Post_To_Jsonld_Converter::post_process( $jsonld );
108
+
109
+        if ( $permalink ) {
110
+            $jsonld['mainEntityOfPage'] = $permalink;
111
+        }
112
+
113
+        return apply_filters(
114
+            'wl_no_vocabulary_term_jsonld_array',
115
+            array(
116
+                'jsonld'     => $jsonld,
117
+                'references' => $references,
118
+            ),
119
+            $term_id
120
+        );
121
+
122
+    }
123
+
124
+    private function relative_to_schema_context( $predicate ) {
125
+        return str_replace( 'http://schema.org/', '', $predicate );
126
+    }
127
+
128
+    private function process_value( $value, &$references ) {
129
+
130
+        if ( is_array( $value )
131
+             && count( $value ) > 0
132
+             && $value[0] instanceof \Wordlift_Property_Entity_Reference ) {
133
+
134
+            // All of the references from the custom fields are post references.
135
+            $references = array_merge(
136
+                $references,
137
+                array_map(
138
+                    function ( $property_entity_reference ) {
139
+                        /**
140
+                         * @var $property_entity_reference \Wordlift_Property_Entity_Reference
141
+                         */
142
+                        return $property_entity_reference->to_reference();
143
+                    },
144
+                    $value
145
+                )
146
+            );
147
+
148
+            return array_map(
149
+                function ( $reference ) {
150
+                    /**
151
+                     * @var $reference \Wordlift_Property_Entity_Reference
152
+                     */
153
+                    return array( '@id' => $reference->get_url() );
154
+                },
155
+                $value
156
+            );
157
+
158
+        }
159
+
160
+        return $value;
161
+    }
162
+
163
+    /**
164
+     * Remove all the shortcodes from the content. We're using our own function
165
+     * because WordPress' own `strip_shortcodes` only takes into consideration
166
+     * shortcodes for installed plugins/themes.
167
+     *
168
+     * @since 3.12.0
169
+     *
170
+     * @param string $content The content with shortcodes.
171
+     *
172
+     * @return string The content without shortcodes.
173
+     */
174
+    private static function strip_all_shortcodes( $content ) {
175
+        return preg_replace( '/\[[^]]+\]/', '', $content );
176
+    }
177 177
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	 */
29 29
 	private $entity_service;
30 30
 
31
-	public function __construct( $entity_type_service, $property_getter ) {
31
+	public function __construct($entity_type_service, $property_getter) {
32 32
 		$this->entity_type_service      = $entity_type_service;
33 33
 		$this->property_getter          = $property_getter;
34 34
 		$this->term_entity_type_service = Type_Service::get_instance();
@@ -36,26 +36,26 @@  discard block
 block discarded – undo
36 36
 	}
37 37
 
38 38
 	public function init() {
39
-		add_filter( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 );
39
+		add_filter('wl_term_jsonld_array', array($this, 'wl_term_jsonld_array'), 10, 2);
40 40
 	}
41 41
 
42
-	public function wl_term_jsonld_array( $data, $term_id ) {
42
+	public function wl_term_jsonld_array($data, $term_id) {
43 43
 		$jsonld     = $data['jsonld'];
44 44
 		$references = $data['references'];
45 45
 
46
-		$term_jsonld_data = $this->get_jsonld_data_for_term( $term_id );
46
+		$term_jsonld_data = $this->get_jsonld_data_for_term($term_id);
47 47
 
48 48
 		// Return early if we dont have the entity data
49 49
 		// for the term.
50
-		if ( ! $term_jsonld_data ) {
50
+		if ( ! $term_jsonld_data) {
51 51
 			return $data;
52 52
 		}
53 53
 
54 54
 		$term_jsonld = $term_jsonld_data['jsonld'];
55 55
 
56
-		$references = array_merge( $references, $term_jsonld_data['references'] );
56
+		$references = array_merge($references, $term_jsonld_data['references']);
57 57
 
58
-		array_unshift( $jsonld, $term_jsonld );
58
+		array_unshift($jsonld, $term_jsonld);
59 59
 
60 60
 		return array(
61 61
 			'jsonld'     => $jsonld,
@@ -63,50 +63,50 @@  discard block
 block discarded – undo
63 63
 		);
64 64
 	}
65 65
 
66
-	private function get_jsonld_data_for_term( $term_id ) {
66
+	private function get_jsonld_data_for_term($term_id) {
67 67
 
68
-		$id = $this->entity_service->get_uri( $term_id, Object_Type_Enum::TERM );
68
+		$id = $this->entity_service->get_uri($term_id, Object_Type_Enum::TERM);
69 69
 
70 70
 		// If we don't have a dataset  URI, then don't publish the term data
71 71
 		// on this page.
72
-		if ( ! $id ) {
72
+		if ( ! $id) {
73 73
 			return false;
74 74
 		}
75 75
 
76 76
 		$references = array();
77
-		$term       = get_term( $term_id );
78
-		$permalink  = get_term_link( $term );
77
+		$term       = get_term($term_id);
78
+		$permalink  = get_term_link($term);
79 79
 
80
-		$custom_fields = $this->entity_type_service->get_custom_fields_for_term( $term_id );
81
-		$term          = get_term( $term_id );
80
+		$custom_fields = $this->entity_type_service->get_custom_fields_for_term($term_id);
81
+		$term          = get_term($term_id);
82 82
 		$jsonld        = array(
83 83
 			'@context'    => 'http://schema.org',
84 84
 			'name'        => $term->name,
85
-			'@type'       => $this->term_entity_type_service->get_entity_types_labels( $term_id ),
85
+			'@type'       => $this->term_entity_type_service->get_entity_types_labels($term_id),
86 86
 			'@id'         => $id,
87
-			'description' => wp_strip_all_tags( self::strip_all_shortcodes( $term->description ) ),
87
+			'description' => wp_strip_all_tags(self::strip_all_shortcodes($term->description)),
88 88
 		);
89 89
 
90
-		if ( ! $custom_fields || ! is_array( $custom_fields ) ) {
90
+		if ( ! $custom_fields || ! is_array($custom_fields)) {
91 91
 			return $jsonld;
92 92
 		}
93 93
 
94
-		foreach ( $custom_fields as $key => $value ) {
95
-			$name  = $this->relative_to_schema_context( $value['predicate'] );
96
-			$value = $this->property_getter->get( $term_id, $key, Object_Type_Enum::TERM );
97
-			$value = $this->process_value( $value, $references );
98
-			if ( ! isset( $value ) ||
99
-				 is_array( $value ) && empty( $value ) ||
100
-				 is_string( $value ) && empty( $value ) ) {
94
+		foreach ($custom_fields as $key => $value) {
95
+			$name  = $this->relative_to_schema_context($value['predicate']);
96
+			$value = $this->property_getter->get($term_id, $key, Object_Type_Enum::TERM);
97
+			$value = $this->process_value($value, $references);
98
+			if ( ! isset($value) ||
99
+				 is_array($value) && empty($value) ||
100
+				 is_string($value) && empty($value)) {
101 101
 				continue;
102 102
 			}
103
-			$jsonld[ $name ] = $value;
103
+			$jsonld[$name] = $value;
104 104
 
105 105
 		}
106 106
 
107
-		$jsonld = \Wordlift_Entity_Post_To_Jsonld_Converter::post_process( $jsonld );
107
+		$jsonld = \Wordlift_Entity_Post_To_Jsonld_Converter::post_process($jsonld);
108 108
 
109
-		if ( $permalink ) {
109
+		if ($permalink) {
110 110
 			$jsonld['mainEntityOfPage'] = $permalink;
111 111
 		}
112 112
 
@@ -121,21 +121,21 @@  discard block
 block discarded – undo
121 121
 
122 122
 	}
123 123
 
124
-	private function relative_to_schema_context( $predicate ) {
125
-		return str_replace( 'http://schema.org/', '', $predicate );
124
+	private function relative_to_schema_context($predicate) {
125
+		return str_replace('http://schema.org/', '', $predicate);
126 126
 	}
127 127
 
128
-	private function process_value( $value, &$references ) {
128
+	private function process_value($value, &$references) {
129 129
 
130
-		if ( is_array( $value )
131
-			 && count( $value ) > 0
132
-			 && $value[0] instanceof \Wordlift_Property_Entity_Reference ) {
130
+		if (is_array($value)
131
+			 && count($value) > 0
132
+			 && $value[0] instanceof \Wordlift_Property_Entity_Reference) {
133 133
 
134 134
 			// All of the references from the custom fields are post references.
135 135
 			$references = array_merge(
136 136
 				$references,
137 137
 				array_map(
138
-					function ( $property_entity_reference ) {
138
+					function($property_entity_reference) {
139 139
 						/**
140 140
 						 * @var $property_entity_reference \Wordlift_Property_Entity_Reference
141 141
 						 */
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
 			);
147 147
 
148 148
 			return array_map(
149
-				function ( $reference ) {
149
+				function($reference) {
150 150
 					/**
151 151
 					 * @var $reference \Wordlift_Property_Entity_Reference
152 152
 					 */
153
-					return array( '@id' => $reference->get_url() );
153
+					return array('@id' => $reference->get_url());
154 154
 				},
155 155
 				$value
156 156
 			);
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 	 *
172 172
 	 * @return string The content without shortcodes.
173 173
 	 */
174
-	private static function strip_all_shortcodes( $content ) {
175
-		return preg_replace( '/\[[^]]+\]/', '', $content );
174
+	private static function strip_all_shortcodes($content) {
175
+		return preg_replace('/\[[^]]+\]/', '', $content);
176 176
 	}
177 177
 }
Please login to merge, or discard this patch.