Completed
Pull Request — master (#1622)
by
unknown
02:48 queued 40s
created
src/includes/class-wordlift-abstract-post-to-jsonld-converter.php 2 patches
Indentation   +395 added lines, -395 removed lines patch added patch discarded remove patch
@@ -23,421 +23,421 @@
 block discarded – undo
23 23
  */
24 24
 abstract class Wordlift_Abstract_Post_To_Jsonld_Converter implements Wordlift_Post_Converter {
25 25
 
26
-	/**
27
-	 * The JSON-LD context.
28
-	 *
29
-	 * @since 3.10.0
30
-	 */
31
-	const CONTEXT = 'http://schema.org';
32
-
33
-	/**
34
-	 * A {@link Wordlift_Entity_Type_Service} instance.
35
-	 *
36
-	 * @since  3.10.0
37
-	 * @access protected
38
-	 * @var \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
39
-	 */
40
-	protected $entity_type_service;
41
-
42
-	/**
43
-	 * A {@link Wordlift_User_Service} instance.
44
-	 *
45
-	 * @since  3.10.0
46
-	 * @access private
47
-	 * @var \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance.
48
-	 */
49
-	protected $user_service;
50
-
51
-	/**
52
-	 * A {@link Wordlift_Attachment_Service} instance.
53
-	 *
54
-	 * @since  3.10.0
55
-	 * @access private
56
-	 * @var \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance.
57
-	 */
58
-	protected $attachment_service;
59
-
60
-	/**
61
-	 * @var Wordlift_Property_Getter
62
-	 */
63
-	private $property_getter;
64
-
65
-	/**
66
-	 * Wordlift_Post_To_Jsonld_Converter constructor.
67
-	 *
68
-	 * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
69
-	 * @param \Wordlift_User_Service        $user_service A {@link Wordlift_User_Service} instance.
70
-	 * @param \Wordlift_Attachment_Service  $attachment_service A {@link Wordlift_Attachment_Service} instance.
71
-	 * @param \Wordlift_Property_Getter     $property_getter
72
-	 *
73
-	 * @since 3.10.0
74
-	 */
75
-	public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter ) {
76
-		$this->entity_type_service = $entity_type_service;
77
-		$this->user_service        = $user_service;
78
-		$this->attachment_service  = $attachment_service;
79
-		$this->property_getter     = $property_getter;
80
-	}
81
-
82
-	/**
83
-	 * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference
84
-	 * found while processing the post is set in the $references array.
85
-	 *
86
-	 * @param int $post_id The post id.
87
-	 * @param array $references An array of entity references.
88
-	 * @param array $references_infos
89
-	 *
90
-	 * @return array A JSON-LD array.
91
-	 * @since 3.10.0
92
-	 */
93
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
94
-	public function convert( $post_id, &$references = array(), &$references_infos = array() ) {
95
-
96
-		// Get the post instance.
97
-		$post = get_post( $post_id );
98
-		if ( null === $post ) {
99
-			// Post not found.
100
-			return null;
101
-		}
102
-
103
-		// Get the post URI @id.
104
-		$id = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID );
105
-		if ( $id === null ) {
106
-			$id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri();
107
-		}
108
-
109
-		/*
26
+    /**
27
+     * The JSON-LD context.
28
+     *
29
+     * @since 3.10.0
30
+     */
31
+    const CONTEXT = 'http://schema.org';
32
+
33
+    /**
34
+     * A {@link Wordlift_Entity_Type_Service} instance.
35
+     *
36
+     * @since  3.10.0
37
+     * @access protected
38
+     * @var \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
39
+     */
40
+    protected $entity_type_service;
41
+
42
+    /**
43
+     * A {@link Wordlift_User_Service} instance.
44
+     *
45
+     * @since  3.10.0
46
+     * @access private
47
+     * @var \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance.
48
+     */
49
+    protected $user_service;
50
+
51
+    /**
52
+     * A {@link Wordlift_Attachment_Service} instance.
53
+     *
54
+     * @since  3.10.0
55
+     * @access private
56
+     * @var \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance.
57
+     */
58
+    protected $attachment_service;
59
+
60
+    /**
61
+     * @var Wordlift_Property_Getter
62
+     */
63
+    private $property_getter;
64
+
65
+    /**
66
+     * Wordlift_Post_To_Jsonld_Converter constructor.
67
+     *
68
+     * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
69
+     * @param \Wordlift_User_Service        $user_service A {@link Wordlift_User_Service} instance.
70
+     * @param \Wordlift_Attachment_Service  $attachment_service A {@link Wordlift_Attachment_Service} instance.
71
+     * @param \Wordlift_Property_Getter     $property_getter
72
+     *
73
+     * @since 3.10.0
74
+     */
75
+    public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter ) {
76
+        $this->entity_type_service = $entity_type_service;
77
+        $this->user_service        = $user_service;
78
+        $this->attachment_service  = $attachment_service;
79
+        $this->property_getter     = $property_getter;
80
+    }
81
+
82
+    /**
83
+     * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference
84
+     * found while processing the post is set in the $references array.
85
+     *
86
+     * @param int $post_id The post id.
87
+     * @param array $references An array of entity references.
88
+     * @param array $references_infos
89
+     *
90
+     * @return array A JSON-LD array.
91
+     * @since 3.10.0
92
+     */
93
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
94
+    public function convert( $post_id, &$references = array(), &$references_infos = array() ) {
95
+
96
+        // Get the post instance.
97
+        $post = get_post( $post_id );
98
+        if ( null === $post ) {
99
+            // Post not found.
100
+            return null;
101
+        }
102
+
103
+        // Get the post URI @id.
104
+        $id = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID );
105
+        if ( $id === null ) {
106
+            $id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri();
107
+        }
108
+
109
+        /*
110 110
 		 * The `types` variable holds one or more entity types. The `type` variable isn't used anymore.
111 111
 		 *
112 112
 		 * @since 3.20.0 We support more than one entity type.
113 113
 		 *
114 114
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/835
115 115
 		 */
116
-		// Get the entity @type. We consider `post` BlogPostings.
117
-		// $type = $this->entity_type_service->get( $post_id );
118
-		$types = $this->entity_type_service->get_names( $post_id );
119
-		$type  = self::make_one( $types );
120
-
121
-		// Prepare the response.
122
-		$jsonld = array(
123
-			'@context' => self::CONTEXT,
124
-			'@id'      => $id,
125
-			'@type'    => $type,
126
-		);
127
-
128
-		if ( post_type_supports( $post->post_type, 'excerpt' ) ) {
129
-			$jsonld['description'] = Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post );
130
-		}
131
-
132
-		// Set the `mainEntityOfPage` property if the post has some contents.
133
-		/*
116
+        // Get the entity @type. We consider `post` BlogPostings.
117
+        // $type = $this->entity_type_service->get( $post_id );
118
+        $types = $this->entity_type_service->get_names( $post_id );
119
+        $type  = self::make_one( $types );
120
+
121
+        // Prepare the response.
122
+        $jsonld = array(
123
+            '@context' => self::CONTEXT,
124
+            '@id'      => $id,
125
+            '@type'    => $type,
126
+        );
127
+
128
+        if ( post_type_supports( $post->post_type, 'excerpt' ) ) {
129
+            $jsonld['description'] = Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post );
130
+        }
131
+
132
+        // Set the `mainEntityOfPage` property if the post has some contents.
133
+        /*
134 134
 		 * Apply the `wl_post_content` filter, in case 3rd parties want to change the post content, e.g.
135 135
 		 * because the content is written elsewhere.
136 136
 		 *
137 137
 		 * @since 3.20.0
138 138
 		 */
139
-		$post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
140
-		if ( ! empty( $post_content ) ) {
141
-			// We're setting the `mainEntityOfPage` to signal which one is the
142
-			// main entity for the specified URL. It might be however that the
143
-			// post/page is actually about another specific entity. How WL deals
144
-			// with that hasn't been defined yet (see https://github.com/insideout10/wordlift-plugin/issues/451).
145
-			//
146
-			// See http://schema.org/mainEntityOfPage
147
-			//
148
-			// No need to specify `'@type' => 'WebPage'.
149
-			//
150
-			// See https://github.com/insideout10/wordlift-plugin/issues/451.
151
-			$jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID );
152
-
153
-			/**
154
-			 * @see https://github.com/insideout10/wordlift-plugin/issues/1207
155
-			 *
156
-			 * @since 3.27.7
157
-			 */
158
-			if ( in_array( $type, array( 'Occupation', 'OccupationAggregationByEmployer' ), true ) ) {
159
-				$jsonld['mainEntityOfPage'] = array(
160
-					'@type'        => 'WebPage',
161
-					'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ),
162
-				);
163
-			}
164
-		};
165
-
166
-		$this->set_images( $this->attachment_service, $post, $jsonld );
167
-
168
-		// Get the entities referenced by this post and set it to the `references`
169
-		// array so that the caller can do further processing, such as printing out
170
-		// more of those references.
171
-		$references_without_locations = Object_Relation_Service::get_instance()
172
-															   ->get_references( $post_id, Object_Type_Enum::POST );
173
-
174
-		/*
139
+        $post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
140
+        if ( ! empty( $post_content ) ) {
141
+            // We're setting the `mainEntityOfPage` to signal which one is the
142
+            // main entity for the specified URL. It might be however that the
143
+            // post/page is actually about another specific entity. How WL deals
144
+            // with that hasn't been defined yet (see https://github.com/insideout10/wordlift-plugin/issues/451).
145
+            //
146
+            // See http://schema.org/mainEntityOfPage
147
+            //
148
+            // No need to specify `'@type' => 'WebPage'.
149
+            //
150
+            // See https://github.com/insideout10/wordlift-plugin/issues/451.
151
+            $jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID );
152
+
153
+            /**
154
+             * @see https://github.com/insideout10/wordlift-plugin/issues/1207
155
+             *
156
+             * @since 3.27.7
157
+             */
158
+            if ( in_array( $type, array( 'Occupation', 'OccupationAggregationByEmployer' ), true ) ) {
159
+                $jsonld['mainEntityOfPage'] = array(
160
+                    '@type'        => 'WebPage',
161
+                    'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ),
162
+                );
163
+            }
164
+        };
165
+
166
+        $this->set_images( $this->attachment_service, $post, $jsonld );
167
+
168
+        // Get the entities referenced by this post and set it to the `references`
169
+        // array so that the caller can do further processing, such as printing out
170
+        // more of those references.
171
+        $references_without_locations = Object_Relation_Service::get_instance()
172
+                                                                ->get_references( $post_id, Object_Type_Enum::POST );
173
+
174
+        /*
175 175
 		 * Add the locations to the references.
176 176
 		 *
177 177
 		 * @since 3.19.5
178 178
 		 *
179 179
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/858.
180 180
 		 */
181
-		// A reference to use in closure.
182
-		$entity_type_service = $this->entity_type_service;
183
-		$locations           = array_reduce(
184
-			$references_without_locations,
185
-			function ( $carry, $reference ) use ( $entity_type_service ) {
186
-				/**
187
-				 * @var $reference Reference
188
-				 */
189
-				// @see https://schema.org/location for the schema.org types using the `location` property.
190
-				if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' )
191
-					 && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' )
192
-					 && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) {
193
-
194
-					return $carry;
195
-				}
196
-				$post_location_ids        = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION );
197
-				$post_location_references = array_map(
198
-					function ( $post_id ) {
199
-						return new Post_Reference( $post_id );
200
-					},
201
-					$post_location_ids
202
-				);
203
-
204
-				return array_merge( $carry, $post_location_references );
205
-			},
206
-			array()
207
-		);
208
-
209
-		// Merge the references with the referenced locations if any.
210
-		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
211
-		$references = array_merge( $references_without_locations, $locations );
212
-
213
-		return $jsonld;
214
-	}
215
-
216
-	/**
217
-	 * If the provided value starts with the schema.org context, we remove the schema.org
218
-	 * part since it is set with the '@context'.
219
-	 *
220
-	 * @param string $value The property value.
221
-	 *
222
-	 * @return string The property value without the context.
223
-	 * @since 3.10.0
224
-	 */
225
-	public function relative_to_context( $value ) {
226
-		return ! is_array( $value ) && 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value;
227
-	}
228
-
229
-	/**
230
-	 * Set the images, by looking for embedded images, for images loaded via the
231
-	 * gallery and for the featured image.
232
-	 *
233
-	 * Uses the cache service to store the results of this function for a day.
234
-	 *
235
-	 * @param $attachment_service Wordlift_Attachment_Service
236
-	 * @param WP_Post                                        $post The target {@link WP_Post}.
237
-	 * @param array                                          $jsonld The JSON-LD array.
238
-	 *
239
-	 * @since 3.10.0
240
-	 */
241
-	public static function set_images( $attachment_service, $post, &$jsonld ) {
242
-
243
-		// Prepare the attachment ids array.
244
-		$ids = array();
245
-
246
-		// Set the thumbnail id as first attachment id, if any.
247
-		$thumbnail_id = get_post_thumbnail_id( $post->ID );
248
-		if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) {
249
-			$ids[] = $thumbnail_id;
250
-		}
251
-
252
-		// For the time being the following is being removed since the query
253
-		// initiated by `get_image_embeds` is consuming lots of CPU.
254
-		//
255
-		// See https://github.com/insideout10/wordlift-plugin/issues/689.
256
-		//
257
-		// Get the embeds, removing existing ids.
258
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
259
-		if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) {
260
-			$embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids );
261
-		} else {
262
-			$embeds = array();
263
-		}
264
-
265
-		// Get the gallery, removing existing ids.
266
-		$gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds );
267
-
268
-		// Map the attachment ids to images' data structured for schema.org use.
269
-		$images_with_sizes = array_filter(
270
-			array_reduce(
271
-				array_merge( $ids, $embeds, $gallery ),
272
-				function ( $carry, $item ) {
273
-					/*
181
+        // A reference to use in closure.
182
+        $entity_type_service = $this->entity_type_service;
183
+        $locations           = array_reduce(
184
+            $references_without_locations,
185
+            function ( $carry, $reference ) use ( $entity_type_service ) {
186
+                /**
187
+                 * @var $reference Reference
188
+                 */
189
+                // @see https://schema.org/location for the schema.org types using the `location` property.
190
+                if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' )
191
+                     && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' )
192
+                     && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) {
193
+
194
+                    return $carry;
195
+                }
196
+                $post_location_ids        = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION );
197
+                $post_location_references = array_map(
198
+                    function ( $post_id ) {
199
+                        return new Post_Reference( $post_id );
200
+                    },
201
+                    $post_location_ids
202
+                );
203
+
204
+                return array_merge( $carry, $post_location_references );
205
+            },
206
+            array()
207
+        );
208
+
209
+        // Merge the references with the referenced locations if any.
210
+        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
211
+        $references = array_merge( $references_without_locations, $locations );
212
+
213
+        return $jsonld;
214
+    }
215
+
216
+    /**
217
+     * If the provided value starts with the schema.org context, we remove the schema.org
218
+     * part since it is set with the '@context'.
219
+     *
220
+     * @param string $value The property value.
221
+     *
222
+     * @return string The property value without the context.
223
+     * @since 3.10.0
224
+     */
225
+    public function relative_to_context( $value ) {
226
+        return ! is_array( $value ) && 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value;
227
+    }
228
+
229
+    /**
230
+     * Set the images, by looking for embedded images, for images loaded via the
231
+     * gallery and for the featured image.
232
+     *
233
+     * Uses the cache service to store the results of this function for a day.
234
+     *
235
+     * @param $attachment_service Wordlift_Attachment_Service
236
+     * @param WP_Post                                        $post The target {@link WP_Post}.
237
+     * @param array                                          $jsonld The JSON-LD array.
238
+     *
239
+     * @since 3.10.0
240
+     */
241
+    public static function set_images( $attachment_service, $post, &$jsonld ) {
242
+
243
+        // Prepare the attachment ids array.
244
+        $ids = array();
245
+
246
+        // Set the thumbnail id as first attachment id, if any.
247
+        $thumbnail_id = get_post_thumbnail_id( $post->ID );
248
+        if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) {
249
+            $ids[] = $thumbnail_id;
250
+        }
251
+
252
+        // For the time being the following is being removed since the query
253
+        // initiated by `get_image_embeds` is consuming lots of CPU.
254
+        //
255
+        // See https://github.com/insideout10/wordlift-plugin/issues/689.
256
+        //
257
+        // Get the embeds, removing existing ids.
258
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
259
+        if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) {
260
+            $embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids );
261
+        } else {
262
+            $embeds = array();
263
+        }
264
+
265
+        // Get the gallery, removing existing ids.
266
+        $gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds );
267
+
268
+        // Map the attachment ids to images' data structured for schema.org use.
269
+        $images_with_sizes = array_filter(
270
+            array_reduce(
271
+                array_merge( $ids, $embeds, $gallery ),
272
+                function ( $carry, $item ) {
273
+                    /*
274 274
 					* @todo: we're not sure that we're getting attachment data here, we
275 275
 					* should filter `false`s.
276 276
 					*/
277 277
 
278
-					$sources = array_merge(
279
-						Wordlift_Image_Service::get_sources( $item ),
280
-						array( wp_get_attachment_image_src( $item, 'full' ) )
281
-					);
282
-
283
-					$sources_with_image = array_filter(
284
-						$sources,
285
-						function ( $source ) {
286
-							return ! empty( $source[0] );
287
-						}
288
-					);
289
-
290
-					// Get the attachment data.
291
-					// $attachment = wp_get_attachment_image_src( $item, 'full' );
292
-
293
-					// var_dump( array( "sources-$item" => Wordlift_Image_Service::get_sources( $item ) ) );
294
-
295
-					// Bail if image is not found.
296
-					// In some cases, you can delete the image from the database
297
-					// or from uploads dir, but the image id still exists as featured image
298
-					// or in [gallery] shortcode.
299
-					// if ( empty( $attachment[0] ) ) {
300
-					if ( empty( $sources_with_image ) ) {
301
-						return $carry;
302
-					}
303
-
304
-					// Merge the arrays.
305
-					return array_merge(
306
-						$carry,
307
-						$sources_with_image
308
-					);
309
-				},
310
-				// Initial array.
311
-
312
-				array()
313
-			)
314
-		);
315
-
316
-		// Refactor data as per schema.org specifications.
317
-		$images = array_map(
318
-			function ( $attachment ) {
319
-				return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size(
320
-					array(
321
-						'@type' => 'ImageObject',
322
-						'url'   => $attachment[0],
323
-					),
324
-					$attachment
325
-				);
326
-			},
327
-			$images_with_sizes
328
-		);
329
-
330
-		// Add images if present.
331
-		if ( 0 < count( $images ) ) {
332
-			$jsonld['image'] = $images;
333
-		}
334
-
335
-	}
336
-
337
-	/**
338
-	 * If the provided array of values contains only one value, then one single
339
-	 * value is returned, otherwise the original array is returned.
340
-	 *
341
-	 * @param array $value An array of values.
342
-	 *
343
-	 * @return mixed|array A single value or the original array.
344
-	 * @since 3.20.0 The function has been moved from {@link Wordlift_Entity_Post_To_Jsonld_Converter} to
345
-	 *  {@link Wordlift_Abstract_Post_To_Jsonld_Converter}.
346
-	 * @since  3.8.0
347
-	 * @access private
348
-	 */
349
-	protected static function make_one( $value ) {
350
-
351
-		return 1 === count( $value ) ? $value[0] : $value;
352
-	}
353
-
354
-	/**
355
-	 * Process the provided array by adding the width / height if the values
356
-	 * are available and are greater than 0.
357
-	 *
358
-	 * @param array $image The `ImageObject` array.
359
-	 * @param array $attachment The attachment array.
360
-	 *
361
-	 * @return array The enriched `ImageObject` array.
362
-	 * @since 3.14.0
363
-	 */
364
-	public static function set_image_size( $image, $attachment ) {
365
-
366
-		// If you specify a "width" or "height" value you should leave out
367
-		// 'px'. For example: "width":"4608px" should be "width":"4608".
368
-		//
369
-		// See https://github.com/insideout10/wordlift-plugin/issues/451.
370
-		if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) {
371
-			$image['width'] = $attachment[1];
372
-		}
373
-
374
-		if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) {
375
-			$image['height'] = $attachment[2];
376
-		}
377
-
378
-		return $image;
379
-	}
380
-
381
-	/**
382
-	 * Add data to the JSON-LD using the `custom_fields` array which contains the definitions of property
383
-	 * for the post entity type.
384
-	 *
385
-	 * @param array   $jsonld The JSON-LD array.
386
-	 * @param array   $fields The entity types field array.
387
-	 * @param WP_Post $post The target {@link WP_Post} instance.
388
-	 * @param array   $references The references array.
389
-	 *
390
-	 * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in
391
-	 *  the {@link Wordlift_Schema_Service} class.
392
-	 */
393
-	protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) {
394
-
395
-		// Set a reference to use in closures.
396
-		$converter = $this;
397
-
398
-		// Try each field on the entity.
399
-		foreach ( $fields as $key => $value ) {
400
-
401
-			// Get the predicate.
402
-			$name = $this->relative_to_context( $value['predicate'] );
403
-
404
-			// Get the value, the property service will get the right extractor
405
-			// for that property.
406
-			$value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST );
407
-
408
-			if ( empty( $value ) ) {
409
-				continue;
410
-			}
411
-
412
-			// Map the value to the property name.
413
-			// If we got an array with just one value, we return that one value.
414
-			// If we got a Wordlift_Property_Entity_Reference we get the URL.
415
-			$jsonld[ $name ] = self::make_one(
416
-				array_map(
417
-					function ( $item ) use ( $converter, &$references, &$references_infos ) {
418
-
419
-						if ( $item instanceof Wordlift_Property_Entity_Reference ) {
420
-
421
-							$url = $item->get_url();
422
-
423
-							// The refactored converters require the entity id.
424
-							// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
425
-							$references[] = $item->to_reference();
426
-
427
-							// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
428
-							$references_infos[] = array( 'reference' => $item );
429
-
430
-							return array( '@id' => $url );
431
-						}
432
-
433
-						return $converter->relative_to_context( $item );
434
-					},
435
-					$value
436
-				)
437
-			);
438
-
439
-		}
440
-
441
-	}
278
+                    $sources = array_merge(
279
+                        Wordlift_Image_Service::get_sources( $item ),
280
+                        array( wp_get_attachment_image_src( $item, 'full' ) )
281
+                    );
282
+
283
+                    $sources_with_image = array_filter(
284
+                        $sources,
285
+                        function ( $source ) {
286
+                            return ! empty( $source[0] );
287
+                        }
288
+                    );
289
+
290
+                    // Get the attachment data.
291
+                    // $attachment = wp_get_attachment_image_src( $item, 'full' );
292
+
293
+                    // var_dump( array( "sources-$item" => Wordlift_Image_Service::get_sources( $item ) ) );
294
+
295
+                    // Bail if image is not found.
296
+                    // In some cases, you can delete the image from the database
297
+                    // or from uploads dir, but the image id still exists as featured image
298
+                    // or in [gallery] shortcode.
299
+                    // if ( empty( $attachment[0] ) ) {
300
+                    if ( empty( $sources_with_image ) ) {
301
+                        return $carry;
302
+                    }
303
+
304
+                    // Merge the arrays.
305
+                    return array_merge(
306
+                        $carry,
307
+                        $sources_with_image
308
+                    );
309
+                },
310
+                // Initial array.
311
+
312
+                array()
313
+            )
314
+        );
315
+
316
+        // Refactor data as per schema.org specifications.
317
+        $images = array_map(
318
+            function ( $attachment ) {
319
+                return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size(
320
+                    array(
321
+                        '@type' => 'ImageObject',
322
+                        'url'   => $attachment[0],
323
+                    ),
324
+                    $attachment
325
+                );
326
+            },
327
+            $images_with_sizes
328
+        );
329
+
330
+        // Add images if present.
331
+        if ( 0 < count( $images ) ) {
332
+            $jsonld['image'] = $images;
333
+        }
334
+
335
+    }
336
+
337
+    /**
338
+     * If the provided array of values contains only one value, then one single
339
+     * value is returned, otherwise the original array is returned.
340
+     *
341
+     * @param array $value An array of values.
342
+     *
343
+     * @return mixed|array A single value or the original array.
344
+     * @since 3.20.0 The function has been moved from {@link Wordlift_Entity_Post_To_Jsonld_Converter} to
345
+     *  {@link Wordlift_Abstract_Post_To_Jsonld_Converter}.
346
+     * @since  3.8.0
347
+     * @access private
348
+     */
349
+    protected static function make_one( $value ) {
350
+
351
+        return 1 === count( $value ) ? $value[0] : $value;
352
+    }
353
+
354
+    /**
355
+     * Process the provided array by adding the width / height if the values
356
+     * are available and are greater than 0.
357
+     *
358
+     * @param array $image The `ImageObject` array.
359
+     * @param array $attachment The attachment array.
360
+     *
361
+     * @return array The enriched `ImageObject` array.
362
+     * @since 3.14.0
363
+     */
364
+    public static function set_image_size( $image, $attachment ) {
365
+
366
+        // If you specify a "width" or "height" value you should leave out
367
+        // 'px'. For example: "width":"4608px" should be "width":"4608".
368
+        //
369
+        // See https://github.com/insideout10/wordlift-plugin/issues/451.
370
+        if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) {
371
+            $image['width'] = $attachment[1];
372
+        }
373
+
374
+        if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) {
375
+            $image['height'] = $attachment[2];
376
+        }
377
+
378
+        return $image;
379
+    }
380
+
381
+    /**
382
+     * Add data to the JSON-LD using the `custom_fields` array which contains the definitions of property
383
+     * for the post entity type.
384
+     *
385
+     * @param array   $jsonld The JSON-LD array.
386
+     * @param array   $fields The entity types field array.
387
+     * @param WP_Post $post The target {@link WP_Post} instance.
388
+     * @param array   $references The references array.
389
+     *
390
+     * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in
391
+     *  the {@link Wordlift_Schema_Service} class.
392
+     */
393
+    protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) {
394
+
395
+        // Set a reference to use in closures.
396
+        $converter = $this;
397
+
398
+        // Try each field on the entity.
399
+        foreach ( $fields as $key => $value ) {
400
+
401
+            // Get the predicate.
402
+            $name = $this->relative_to_context( $value['predicate'] );
403
+
404
+            // Get the value, the property service will get the right extractor
405
+            // for that property.
406
+            $value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST );
407
+
408
+            if ( empty( $value ) ) {
409
+                continue;
410
+            }
411
+
412
+            // Map the value to the property name.
413
+            // If we got an array with just one value, we return that one value.
414
+            // If we got a Wordlift_Property_Entity_Reference we get the URL.
415
+            $jsonld[ $name ] = self::make_one(
416
+                array_map(
417
+                    function ( $item ) use ( $converter, &$references, &$references_infos ) {
418
+
419
+                        if ( $item instanceof Wordlift_Property_Entity_Reference ) {
420
+
421
+                            $url = $item->get_url();
422
+
423
+                            // The refactored converters require the entity id.
424
+                            // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
425
+                            $references[] = $item->to_reference();
426
+
427
+                            // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
428
+                            $references_infos[] = array( 'reference' => $item );
429
+
430
+                            return array( '@id' => $url );
431
+                        }
432
+
433
+                        return $converter->relative_to_context( $item );
434
+                    },
435
+                    $value
436
+                )
437
+            );
438
+
439
+        }
440
+
441
+    }
442 442
 
443 443
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @since 3.10.0
74 74
 	 */
75
-	public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter ) {
75
+	public function __construct($entity_type_service, $user_service, $attachment_service, $property_getter) {
76 76
 		$this->entity_type_service = $entity_type_service;
77 77
 		$this->user_service        = $user_service;
78 78
 		$this->attachment_service  = $attachment_service;
@@ -91,19 +91,19 @@  discard block
 block discarded – undo
91 91
 	 * @since 3.10.0
92 92
 	 */
93 93
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
94
-	public function convert( $post_id, &$references = array(), &$references_infos = array() ) {
94
+	public function convert($post_id, &$references = array(), &$references_infos = array()) {
95 95
 
96 96
 		// Get the post instance.
97
-		$post = get_post( $post_id );
98
-		if ( null === $post ) {
97
+		$post = get_post($post_id);
98
+		if (null === $post) {
99 99
 			// Post not found.
100 100
 			return null;
101 101
 		}
102 102
 
103 103
 		// Get the post URI @id.
104
-		$id = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID );
105
-		if ( $id === null ) {
106
-			$id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri();
104
+		$id = Wordlift_Entity_Service::get_instance()->get_uri($post->ID);
105
+		if ($id === null) {
106
+			$id = 'get_uri returned null, dataset is '.wl_configuration_get_redlink_dataset_uri();
107 107
 		}
108 108
 
109 109
 		/*
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 		 */
116 116
 		// Get the entity @type. We consider `post` BlogPostings.
117 117
 		// $type = $this->entity_type_service->get( $post_id );
118
-		$types = $this->entity_type_service->get_names( $post_id );
119
-		$type  = self::make_one( $types );
118
+		$types = $this->entity_type_service->get_names($post_id);
119
+		$type  = self::make_one($types);
120 120
 
121 121
 		// Prepare the response.
122 122
 		$jsonld = array(
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
 			'@type'    => $type,
126 126
 		);
127 127
 
128
-		if ( post_type_supports( $post->post_type, 'excerpt' ) ) {
129
-			$jsonld['description'] = Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post );
128
+		if (post_type_supports($post->post_type, 'excerpt')) {
129
+			$jsonld['description'] = Wordlift_Post_Excerpt_Helper::get_text_excerpt($post);
130 130
 		}
131 131
 
132 132
 		// Set the `mainEntityOfPage` property if the post has some contents.
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 		 *
137 137
 		 * @since 3.20.0
138 138
 		 */
139
-		$post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
140
-		if ( ! empty( $post_content ) ) {
139
+		$post_content = apply_filters('wl_post_content', $post->post_content, $post);
140
+		if ( ! empty($post_content)) {
141 141
 			// We're setting the `mainEntityOfPage` to signal which one is the
142 142
 			// main entity for the specified URL. It might be however that the
143 143
 			// post/page is actually about another specific entity. How WL deals
@@ -148,28 +148,28 @@  discard block
 block discarded – undo
148 148
 			// No need to specify `'@type' => 'WebPage'.
149 149
 			//
150 150
 			// See https://github.com/insideout10/wordlift-plugin/issues/451.
151
-			$jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID );
151
+			$jsonld['mainEntityOfPage'] = get_the_permalink($post->ID);
152 152
 
153 153
 			/**
154 154
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/1207
155 155
 			 *
156 156
 			 * @since 3.27.7
157 157
 			 */
158
-			if ( in_array( $type, array( 'Occupation', 'OccupationAggregationByEmployer' ), true ) ) {
158
+			if (in_array($type, array('Occupation', 'OccupationAggregationByEmployer'), true)) {
159 159
 				$jsonld['mainEntityOfPage'] = array(
160 160
 					'@type'        => 'WebPage',
161
-					'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ),
161
+					'lastReviewed' => get_post_time('Y-m-d\TH:i:sP', true, $post, false),
162 162
 				);
163 163
 			}
164 164
 		};
165 165
 
166
-		$this->set_images( $this->attachment_service, $post, $jsonld );
166
+		$this->set_images($this->attachment_service, $post, $jsonld);
167 167
 
168 168
 		// Get the entities referenced by this post and set it to the `references`
169 169
 		// array so that the caller can do further processing, such as printing out
170 170
 		// more of those references.
171 171
 		$references_without_locations = Object_Relation_Service::get_instance()
172
-															   ->get_references( $post_id, Object_Type_Enum::POST );
172
+															   ->get_references($post_id, Object_Type_Enum::POST);
173 173
 
174 174
 		/*
175 175
 		 * Add the locations to the references.
@@ -182,33 +182,33 @@  discard block
 block discarded – undo
182 182
 		$entity_type_service = $this->entity_type_service;
183 183
 		$locations           = array_reduce(
184 184
 			$references_without_locations,
185
-			function ( $carry, $reference ) use ( $entity_type_service ) {
185
+			function($carry, $reference) use ($entity_type_service) {
186 186
 				/**
187 187
 				 * @var $reference Reference
188 188
 				 */
189 189
 				// @see https://schema.org/location for the schema.org types using the `location` property.
190
-				if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' )
191
-					 && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' )
192
-					 && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) {
190
+				if ( ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Action')
191
+					 && ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Event')
192
+					 && ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Organization')) {
193 193
 
194 194
 					return $carry;
195 195
 				}
196
-				$post_location_ids        = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION );
196
+				$post_location_ids        = get_post_meta($reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION);
197 197
 				$post_location_references = array_map(
198
-					function ( $post_id ) {
199
-						return new Post_Reference( $post_id );
198
+					function($post_id) {
199
+						return new Post_Reference($post_id);
200 200
 					},
201 201
 					$post_location_ids
202 202
 				);
203 203
 
204
-				return array_merge( $carry, $post_location_references );
204
+				return array_merge($carry, $post_location_references);
205 205
 			},
206 206
 			array()
207 207
 		);
208 208
 
209 209
 		// Merge the references with the referenced locations if any.
210 210
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
211
-		$references = array_merge( $references_without_locations, $locations );
211
+		$references = array_merge($references_without_locations, $locations);
212 212
 
213 213
 		return $jsonld;
214 214
 	}
@@ -222,8 +222,8 @@  discard block
 block discarded – undo
222 222
 	 * @return string The property value without the context.
223 223
 	 * @since 3.10.0
224 224
 	 */
225
-	public function relative_to_context( $value ) {
226
-		return ! is_array( $value ) && 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value;
225
+	public function relative_to_context($value) {
226
+		return ! is_array($value) && 0 === strpos($value, self::CONTEXT.'/') ? substr($value, strlen(self::CONTEXT) + 1) : $value;
227 227
 	}
228 228
 
229 229
 	/**
@@ -238,14 +238,14 @@  discard block
 block discarded – undo
238 238
 	 *
239 239
 	 * @since 3.10.0
240 240
 	 */
241
-	public static function set_images( $attachment_service, $post, &$jsonld ) {
241
+	public static function set_images($attachment_service, $post, &$jsonld) {
242 242
 
243 243
 		// Prepare the attachment ids array.
244 244
 		$ids = array();
245 245
 
246 246
 		// Set the thumbnail id as first attachment id, if any.
247
-		$thumbnail_id = get_post_thumbnail_id( $post->ID );
248
-		if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) {
247
+		$thumbnail_id = get_post_thumbnail_id($post->ID);
248
+		if ('' !== $thumbnail_id && 0 !== $thumbnail_id) {
249 249
 			$ids[] = $thumbnail_id;
250 250
 		}
251 251
 
@@ -256,34 +256,34 @@  discard block
 block discarded – undo
256 256
 		//
257 257
 		// Get the embeds, removing existing ids.
258 258
 		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
259
-		if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) {
260
-			$embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids );
259
+		if (apply_filters('wl_feature__enable__image-embeds', false)) {
260
+			$embeds = array_diff($attachment_service->get_image_embeds($post->post_content), $ids);
261 261
 		} else {
262 262
 			$embeds = array();
263 263
 		}
264 264
 
265 265
 		// Get the gallery, removing existing ids.
266
-		$gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds );
266
+		$gallery = array_diff($attachment_service->get_gallery($post), $ids, $embeds);
267 267
 
268 268
 		// Map the attachment ids to images' data structured for schema.org use.
269 269
 		$images_with_sizes = array_filter(
270 270
 			array_reduce(
271
-				array_merge( $ids, $embeds, $gallery ),
272
-				function ( $carry, $item ) {
271
+				array_merge($ids, $embeds, $gallery),
272
+				function($carry, $item) {
273 273
 					/*
274 274
 					* @todo: we're not sure that we're getting attachment data here, we
275 275
 					* should filter `false`s.
276 276
 					*/
277 277
 
278 278
 					$sources = array_merge(
279
-						Wordlift_Image_Service::get_sources( $item ),
280
-						array( wp_get_attachment_image_src( $item, 'full' ) )
279
+						Wordlift_Image_Service::get_sources($item),
280
+						array(wp_get_attachment_image_src($item, 'full'))
281 281
 					);
282 282
 
283 283
 					$sources_with_image = array_filter(
284 284
 						$sources,
285
-						function ( $source ) {
286
-							return ! empty( $source[0] );
285
+						function($source) {
286
+							return ! empty($source[0]);
287 287
 						}
288 288
 					);
289 289
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 					// or from uploads dir, but the image id still exists as featured image
298 298
 					// or in [gallery] shortcode.
299 299
 					// if ( empty( $attachment[0] ) ) {
300
-					if ( empty( $sources_with_image ) ) {
300
+					if (empty($sources_with_image)) {
301 301
 						return $carry;
302 302
 					}
303 303
 
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 
316 316
 		// Refactor data as per schema.org specifications.
317 317
 		$images = array_map(
318
-			function ( $attachment ) {
318
+			function($attachment) {
319 319
 				return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size(
320 320
 					array(
321 321
 						'@type' => 'ImageObject',
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 		);
329 329
 
330 330
 		// Add images if present.
331
-		if ( 0 < count( $images ) ) {
331
+		if (0 < count($images)) {
332 332
 			$jsonld['image'] = $images;
333 333
 		}
334 334
 
@@ -346,9 +346,9 @@  discard block
 block discarded – undo
346 346
 	 * @since  3.8.0
347 347
 	 * @access private
348 348
 	 */
349
-	protected static function make_one( $value ) {
349
+	protected static function make_one($value) {
350 350
 
351
-		return 1 === count( $value ) ? $value[0] : $value;
351
+		return 1 === count($value) ? $value[0] : $value;
352 352
 	}
353 353
 
354 354
 	/**
@@ -361,17 +361,17 @@  discard block
 block discarded – undo
361 361
 	 * @return array The enriched `ImageObject` array.
362 362
 	 * @since 3.14.0
363 363
 	 */
364
-	public static function set_image_size( $image, $attachment ) {
364
+	public static function set_image_size($image, $attachment) {
365 365
 
366 366
 		// If you specify a "width" or "height" value you should leave out
367 367
 		// 'px'. For example: "width":"4608px" should be "width":"4608".
368 368
 		//
369 369
 		// See https://github.com/insideout10/wordlift-plugin/issues/451.
370
-		if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) {
370
+		if (isset($attachment[1]) && is_numeric($attachment[1]) && 0 < $attachment[1]) {
371 371
 			$image['width'] = $attachment[1];
372 372
 		}
373 373
 
374
-		if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) {
374
+		if (isset($attachment[2]) && is_numeric($attachment[2]) && 0 < $attachment[2]) {
375 375
 			$image['height'] = $attachment[2];
376 376
 		}
377 377
 
@@ -390,33 +390,33 @@  discard block
 block discarded – undo
390 390
 	 * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in
391 391
 	 *  the {@link Wordlift_Schema_Service} class.
392 392
 	 */
393
-	protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) {
393
+	protected function process_type_custom_fields(&$jsonld, $fields, $post, &$references, &$references_infos) {
394 394
 
395 395
 		// Set a reference to use in closures.
396 396
 		$converter = $this;
397 397
 
398 398
 		// Try each field on the entity.
399
-		foreach ( $fields as $key => $value ) {
399
+		foreach ($fields as $key => $value) {
400 400
 
401 401
 			// Get the predicate.
402
-			$name = $this->relative_to_context( $value['predicate'] );
402
+			$name = $this->relative_to_context($value['predicate']);
403 403
 
404 404
 			// Get the value, the property service will get the right extractor
405 405
 			// for that property.
406
-			$value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST );
406
+			$value = $this->property_getter->get($post->ID, $key, Object_Type_Enum::POST);
407 407
 
408
-			if ( empty( $value ) ) {
408
+			if (empty($value)) {
409 409
 				continue;
410 410
 			}
411 411
 
412 412
 			// Map the value to the property name.
413 413
 			// If we got an array with just one value, we return that one value.
414 414
 			// If we got a Wordlift_Property_Entity_Reference we get the URL.
415
-			$jsonld[ $name ] = self::make_one(
415
+			$jsonld[$name] = self::make_one(
416 416
 				array_map(
417
-					function ( $item ) use ( $converter, &$references, &$references_infos ) {
417
+					function($item) use ($converter, &$references, &$references_infos) {
418 418
 
419
-						if ( $item instanceof Wordlift_Property_Entity_Reference ) {
419
+						if ($item instanceof Wordlift_Property_Entity_Reference) {
420 420
 
421 421
 							$url = $item->get_url();
422 422
 
@@ -425,12 +425,12 @@  discard block
 block discarded – undo
425 425
 							$references[] = $item->to_reference();
426 426
 
427 427
 							// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
428
-							$references_infos[] = array( 'reference' => $item );
428
+							$references_infos[] = array('reference' => $item);
429 429
 
430
-							return array( '@id' => $url );
430
+							return array('@id' => $url);
431 431
 						}
432 432
 
433
-						return $converter->relative_to_context( $item );
433
+						return $converter->relative_to_context($item);
434 434
 					},
435 435
 					$value
436 436
 				)
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-post-type-service.php 2 patches
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -16,175 +16,175 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Entity_Post_Type_Service {
18 18
 
19
-	/**
20
-	 * The entity post type.
21
-	 *
22
-	 * @since  3.6.0
23
-	 * @access private
24
-	 * @var string $post_type The entity post type.
25
-	 */
26
-	private $post_type;
27
-
28
-	/**
29
-	 * The entity type slug.
30
-	 *
31
-	 * @since  3.6.0
32
-	 * @access private
33
-	 * @var string $slug The entity type slug.
34
-	 */
35
-	private $slug;
36
-
37
-	/**
38
-	 * A {@link Wordlift_Log_Service} instance.
39
-	 *
40
-	 * @since  3.16.3
41
-	 * @access private
42
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
43
-	 */
44
-	private $log;
45
-
46
-	/**
47
-	 * A singleton instance of the entity type service.
48
-	 *
49
-	 * @since  3.6.0
50
-	 * @access private
51
-	 * @var Wordlift_Entity_Post_Type_Service
52
-	 */
53
-	private static $instance;
54
-
55
-	/**
56
-	 * Create an entity type service instance.
57
-	 *
58
-	 * @param string $post_type The post type, e.g. entity.
59
-	 * @param string $slug The entity type slug, if the slug is empty, the default slug will be used.
60
-	 *
61
-	 * @since 3.6.0
62
-	 */
63
-	public function __construct( $post_type, $slug ) {
64
-
65
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
66
-
67
-		$this->post_type = $post_type;
68
-
69
-		// We cannot assign an empty slug to the register_post_type function, therefore if the slug is empty we default
70
-		// to the type name.
71
-		$this->slug = $slug ? $slug : $post_type;
72
-
73
-		self::$instance = $this;
74
-
75
-	}
76
-
77
-	/**
78
-	 * Get the entity type service singleton instance.
79
-	 *
80
-	 * @return Wordlift_Entity_Post_Type_Service The entity type service singleton instance.
81
-	 * @since 3.6.0
82
-	 */
83
-	public static function get_instance() {
84
-
85
-		return self::$instance;
86
-	}
87
-
88
-	/**
89
-	 * Get the entity type slug.
90
-	 *
91
-	 * @return string The entity type slug.
92
-	 * @since 3.6.0
93
-	 */
94
-	public function get_slug() {
95
-
96
-		return $this->slug;
97
-	}
98
-
99
-	/**
100
-	 * Get the entity post type name.
101
-	 *
102
-	 * @return string The entity post type.
103
-	 * @since 3.6.0
104
-	 */
105
-	public function get_post_type() {
106
-
107
-		return $this->post_type;
108
-	}
109
-
110
-	/**
111
-	 * Register the WordLift entity post type. This method is hooked to WordPress' init action.
112
-	 *
113
-	 * @since 3.6.0
114
-	 */
115
-	public function register() {
116
-
117
-		$this->log->debug( "Registering post type $this->post_type..." );
118
-
119
-		$labels = array(
120
-			'name'               => _x( 'Vocabulary', 'post type general name', 'wordlift' ),
121
-			'singular_name'      => _x( 'Entity', 'post type singular name', 'wordlift' ),
122
-			'add_new'            => _x( 'Add New Entity', 'entity', 'wordlift' ),
123
-			'add_new_item'       => __( 'Add New Entity', 'wordlift' ),
124
-			'edit_item'          => __( 'Edit Entity', 'wordlift' ),
125
-			'new_item'           => __( 'New Entity', 'wordlift' ),
126
-			'all_items'          => __( 'All Entities', 'wordlift' ),
127
-			'view_item'          => __( 'View Entity', 'wordlift' ),
128
-			'search_items'       => __( 'Search in Vocabulary', 'wordlift' ),
129
-			'not_found'          => __( 'No entities found', 'wordlift' ),
130
-			'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ),
131
-			'parent_item_colon'  => '',
132
-			'menu_name'          => __( 'Vocabulary', 'wordlift' ),
133
-		);
134
-
135
-		$args = array(
136
-			'labels'          => $labels,
137
-			'description'     => 'Holds our vocabulary (set of entities) and entity specific data',
138
-			'public'          => true,
139
-			'menu_position'   => 20,
140
-			// after the pages menu.
141
-			// Add support for 'authors' and 'revisions':
142
-			// * see https://github.com/insideout10/wordlift-plugin/issues/395
143
-			// * see https://github.com/insideout10/wordlift-plugin/issues/376
144
-			'supports'        => array(
145
-				'title',
146
-				'editor',
147
-				'thumbnail',
148
-				'excerpt',
149
-				'comments',
150
-				'author',
151
-				'revisions',
152
-				'custom-fields',
153
-			),
154
-			'menu_icon'       => WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-vocabulary-icon.svg',
155
-			// Although we define our slug here, we further manage linking to entities using the Wordlift_Entity_Link_Service.
156
-			'rewrite'         => array( 'slug' => $this->slug ),
157
-			'capability_type' => array(
158
-				'wordlift_entity',
159
-				'wordlift_entities',
160
-			),
161
-			'capabilities'    => array(
162
-				'delete_posts' => 'delete_wordlift_entities',
163
-			),
164
-			'rest_base'       => 'entities',
165
-			'show_in_rest'    => true,
166
-			/**
167
-			 * Filter: wl_feature__enable__vocabulary.
168
-			 *
169
-			 * @param bool whether the vocabulary needs to be shown in menu.
170
-			 *
171
-			 * @return bool
172
-			 * @since 3.27.6
173
-			 */
174
-			'show_in_menu'    => apply_filters( 'wl_feature__enable__vocabulary', true ),
175
-		);
176
-
177
-		register_post_type( $this->post_type, $args );
178
-
179
-		// Enable WP's standard `category` taxonomy for entities.
180
-		//
181
-		// While this enables editors to bind entities to the WP posts' category
182
-		// taxonomy, in Wordlift_Category_Taxonomy_Service we also need to alter
183
-		// WP's main category query to include the `entity` post type.
184
-		//
185
-		// See https://github.com/insideout10/wordlift-plugin/issues/442
186
-		register_taxonomy_for_object_type( 'category', $this->post_type );
187
-
188
-	}
19
+    /**
20
+     * The entity post type.
21
+     *
22
+     * @since  3.6.0
23
+     * @access private
24
+     * @var string $post_type The entity post type.
25
+     */
26
+    private $post_type;
27
+
28
+    /**
29
+     * The entity type slug.
30
+     *
31
+     * @since  3.6.0
32
+     * @access private
33
+     * @var string $slug The entity type slug.
34
+     */
35
+    private $slug;
36
+
37
+    /**
38
+     * A {@link Wordlift_Log_Service} instance.
39
+     *
40
+     * @since  3.16.3
41
+     * @access private
42
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
43
+     */
44
+    private $log;
45
+
46
+    /**
47
+     * A singleton instance of the entity type service.
48
+     *
49
+     * @since  3.6.0
50
+     * @access private
51
+     * @var Wordlift_Entity_Post_Type_Service
52
+     */
53
+    private static $instance;
54
+
55
+    /**
56
+     * Create an entity type service instance.
57
+     *
58
+     * @param string $post_type The post type, e.g. entity.
59
+     * @param string $slug The entity type slug, if the slug is empty, the default slug will be used.
60
+     *
61
+     * @since 3.6.0
62
+     */
63
+    public function __construct( $post_type, $slug ) {
64
+
65
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
66
+
67
+        $this->post_type = $post_type;
68
+
69
+        // We cannot assign an empty slug to the register_post_type function, therefore if the slug is empty we default
70
+        // to the type name.
71
+        $this->slug = $slug ? $slug : $post_type;
72
+
73
+        self::$instance = $this;
74
+
75
+    }
76
+
77
+    /**
78
+     * Get the entity type service singleton instance.
79
+     *
80
+     * @return Wordlift_Entity_Post_Type_Service The entity type service singleton instance.
81
+     * @since 3.6.0
82
+     */
83
+    public static function get_instance() {
84
+
85
+        return self::$instance;
86
+    }
87
+
88
+    /**
89
+     * Get the entity type slug.
90
+     *
91
+     * @return string The entity type slug.
92
+     * @since 3.6.0
93
+     */
94
+    public function get_slug() {
95
+
96
+        return $this->slug;
97
+    }
98
+
99
+    /**
100
+     * Get the entity post type name.
101
+     *
102
+     * @return string The entity post type.
103
+     * @since 3.6.0
104
+     */
105
+    public function get_post_type() {
106
+
107
+        return $this->post_type;
108
+    }
109
+
110
+    /**
111
+     * Register the WordLift entity post type. This method is hooked to WordPress' init action.
112
+     *
113
+     * @since 3.6.0
114
+     */
115
+    public function register() {
116
+
117
+        $this->log->debug( "Registering post type $this->post_type..." );
118
+
119
+        $labels = array(
120
+            'name'               => _x( 'Vocabulary', 'post type general name', 'wordlift' ),
121
+            'singular_name'      => _x( 'Entity', 'post type singular name', 'wordlift' ),
122
+            'add_new'            => _x( 'Add New Entity', 'entity', 'wordlift' ),
123
+            'add_new_item'       => __( 'Add New Entity', 'wordlift' ),
124
+            'edit_item'          => __( 'Edit Entity', 'wordlift' ),
125
+            'new_item'           => __( 'New Entity', 'wordlift' ),
126
+            'all_items'          => __( 'All Entities', 'wordlift' ),
127
+            'view_item'          => __( 'View Entity', 'wordlift' ),
128
+            'search_items'       => __( 'Search in Vocabulary', 'wordlift' ),
129
+            'not_found'          => __( 'No entities found', 'wordlift' ),
130
+            'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ),
131
+            'parent_item_colon'  => '',
132
+            'menu_name'          => __( 'Vocabulary', 'wordlift' ),
133
+        );
134
+
135
+        $args = array(
136
+            'labels'          => $labels,
137
+            'description'     => 'Holds our vocabulary (set of entities) and entity specific data',
138
+            'public'          => true,
139
+            'menu_position'   => 20,
140
+            // after the pages menu.
141
+            // Add support for 'authors' and 'revisions':
142
+            // * see https://github.com/insideout10/wordlift-plugin/issues/395
143
+            // * see https://github.com/insideout10/wordlift-plugin/issues/376
144
+            'supports'        => array(
145
+                'title',
146
+                'editor',
147
+                'thumbnail',
148
+                'excerpt',
149
+                'comments',
150
+                'author',
151
+                'revisions',
152
+                'custom-fields',
153
+            ),
154
+            'menu_icon'       => WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-vocabulary-icon.svg',
155
+            // Although we define our slug here, we further manage linking to entities using the Wordlift_Entity_Link_Service.
156
+            'rewrite'         => array( 'slug' => $this->slug ),
157
+            'capability_type' => array(
158
+                'wordlift_entity',
159
+                'wordlift_entities',
160
+            ),
161
+            'capabilities'    => array(
162
+                'delete_posts' => 'delete_wordlift_entities',
163
+            ),
164
+            'rest_base'       => 'entities',
165
+            'show_in_rest'    => true,
166
+            /**
167
+             * Filter: wl_feature__enable__vocabulary.
168
+             *
169
+             * @param bool whether the vocabulary needs to be shown in menu.
170
+             *
171
+             * @return bool
172
+             * @since 3.27.6
173
+             */
174
+            'show_in_menu'    => apply_filters( 'wl_feature__enable__vocabulary', true ),
175
+        );
176
+
177
+        register_post_type( $this->post_type, $args );
178
+
179
+        // Enable WP's standard `category` taxonomy for entities.
180
+        //
181
+        // While this enables editors to bind entities to the WP posts' category
182
+        // taxonomy, in Wordlift_Category_Taxonomy_Service we also need to alter
183
+        // WP's main category query to include the `entity` post type.
184
+        //
185
+        // See https://github.com/insideout10/wordlift-plugin/issues/442
186
+        register_taxonomy_for_object_type( 'category', $this->post_type );
187
+
188
+    }
189 189
 
190 190
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
 	 *
61 61
 	 * @since 3.6.0
62 62
 	 */
63
-	public function __construct( $post_type, $slug ) {
63
+	public function __construct($post_type, $slug) {
64 64
 
65
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
65
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
66 66
 
67 67
 		$this->post_type = $post_type;
68 68
 
@@ -114,22 +114,22 @@  discard block
 block discarded – undo
114 114
 	 */
115 115
 	public function register() {
116 116
 
117
-		$this->log->debug( "Registering post type $this->post_type..." );
117
+		$this->log->debug("Registering post type $this->post_type...");
118 118
 
119 119
 		$labels = array(
120
-			'name'               => _x( 'Vocabulary', 'post type general name', 'wordlift' ),
121
-			'singular_name'      => _x( 'Entity', 'post type singular name', 'wordlift' ),
122
-			'add_new'            => _x( 'Add New Entity', 'entity', 'wordlift' ),
123
-			'add_new_item'       => __( 'Add New Entity', 'wordlift' ),
124
-			'edit_item'          => __( 'Edit Entity', 'wordlift' ),
125
-			'new_item'           => __( 'New Entity', 'wordlift' ),
126
-			'all_items'          => __( 'All Entities', 'wordlift' ),
127
-			'view_item'          => __( 'View Entity', 'wordlift' ),
128
-			'search_items'       => __( 'Search in Vocabulary', 'wordlift' ),
129
-			'not_found'          => __( 'No entities found', 'wordlift' ),
130
-			'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ),
120
+			'name'               => _x('Vocabulary', 'post type general name', 'wordlift'),
121
+			'singular_name'      => _x('Entity', 'post type singular name', 'wordlift'),
122
+			'add_new'            => _x('Add New Entity', 'entity', 'wordlift'),
123
+			'add_new_item'       => __('Add New Entity', 'wordlift'),
124
+			'edit_item'          => __('Edit Entity', 'wordlift'),
125
+			'new_item'           => __('New Entity', 'wordlift'),
126
+			'all_items'          => __('All Entities', 'wordlift'),
127
+			'view_item'          => __('View Entity', 'wordlift'),
128
+			'search_items'       => __('Search in Vocabulary', 'wordlift'),
129
+			'not_found'          => __('No entities found', 'wordlift'),
130
+			'not_found_in_trash' => __('No entities found in the Trash', 'wordlift'),
131 131
 			'parent_item_colon'  => '',
132
-			'menu_name'          => __( 'Vocabulary', 'wordlift' ),
132
+			'menu_name'          => __('Vocabulary', 'wordlift'),
133 133
 		);
134 134
 
135 135
 		$args = array(
@@ -151,9 +151,9 @@  discard block
 block discarded – undo
151 151
 				'revisions',
152 152
 				'custom-fields',
153 153
 			),
154
-			'menu_icon'       => WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-vocabulary-icon.svg',
154
+			'menu_icon'       => WP_CONTENT_URL.'/plugins/wordlift/images/svg/wl-vocabulary-icon.svg',
155 155
 			// Although we define our slug here, we further manage linking to entities using the Wordlift_Entity_Link_Service.
156
-			'rewrite'         => array( 'slug' => $this->slug ),
156
+			'rewrite'         => array('slug' => $this->slug),
157 157
 			'capability_type' => array(
158 158
 				'wordlift_entity',
159 159
 				'wordlift_entities',
@@ -171,10 +171,10 @@  discard block
 block discarded – undo
171 171
 			 * @return bool
172 172
 			 * @since 3.27.6
173 173
 			 */
174
-			'show_in_menu'    => apply_filters( 'wl_feature__enable__vocabulary', true ),
174
+			'show_in_menu'    => apply_filters('wl_feature__enable__vocabulary', true),
175 175
 		);
176 176
 
177
-		register_post_type( $this->post_type, $args );
177
+		register_post_type($this->post_type, $args);
178 178
 
179 179
 		// Enable WP's standard `category` taxonomy for entities.
180 180
 		//
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 		// WP's main category query to include the `entity` post type.
184 184
 		//
185 185
 		// See https://github.com/insideout10/wordlift-plugin/issues/442
186
-		register_taxonomy_for_object_type( 'category', $this->post_type );
186
+		register_taxonomy_for_object_type('category', $this->post_type);
187 187
 
188 188
 	}
189 189
 
Please login to merge, or discard this patch.
src/install/class-wordlift-install-service.php 2 patches
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -18,179 +18,179 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Install_Service {
20 20
 
21
-	/**
22
-	 * A {@link Wordlift_Log_Service} instance.
23
-	 *
24
-	 * @since  3.18.0
25
-	 * @access private
26
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
27
-	 */
28
-	private $log;
29
-
30
-	/**
31
-	 * The singleton instance.
32
-	 *
33
-	 * @since  3.18.0
34
-	 * @access private
35
-	 * @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance.
36
-	 */
37
-	private static $instance;
38
-
39
-	/**
40
-	 * @var array
41
-	 */
42
-	private $installs;
43
-
44
-	/**
45
-	 * Wordlift_Install_Service constructor.
46
-	 *
47
-	 * @since 3.18.0
48
-	 */
49
-	public function __construct() {
50
-
51
-		/** Installs. */
52
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install.php';
53
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-1-0-0.php';
54
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-10-0.php';
55
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-12-0.php';
56
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-14-0.php';
57
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-15-0.php';
58
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-0.php';
59
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-3.php';
60
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-19-5.php';
61
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-20-0.php';
62
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-23-4.php';
63
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-24-2.php';
64
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-all-entity-types.php';
65
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-package-type.php';
66
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-25-0.php';
67
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-0.php';
68
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-1.php';
69
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-28-0.php';
70
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-32-0.php';
71
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-33-9.php';
72
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-36-0.php';
73
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-38-5.php';
74
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-39-1.php';
75
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-40-1.php';
76
-
77
-		// Get the install services.
78
-		$this->installs = array(
79
-			new Wordlift_Install_1_0_0(),
80
-			new Wordlift_Install_3_10_0(),
81
-			new Wordlift_Install_3_12_0(),
82
-			new Wordlift_Install_3_14_0(),
83
-			new Wordlift_Install_3_15_0(),
84
-			new Wordlift_Install_3_18_0(),
85
-			new Wordlift_Install_3_18_3(),
86
-			new Wordlift_Install_3_19_5(),
87
-			new Wordlift_Install_3_20_0(),
88
-
89
-			/*
21
+    /**
22
+     * A {@link Wordlift_Log_Service} instance.
23
+     *
24
+     * @since  3.18.0
25
+     * @access private
26
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
27
+     */
28
+    private $log;
29
+
30
+    /**
31
+     * The singleton instance.
32
+     *
33
+     * @since  3.18.0
34
+     * @access private
35
+     * @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance.
36
+     */
37
+    private static $instance;
38
+
39
+    /**
40
+     * @var array
41
+     */
42
+    private $installs;
43
+
44
+    /**
45
+     * Wordlift_Install_Service constructor.
46
+     *
47
+     * @since 3.18.0
48
+     */
49
+    public function __construct() {
50
+
51
+        /** Installs. */
52
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install.php';
53
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-1-0-0.php';
54
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-10-0.php';
55
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-12-0.php';
56
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-14-0.php';
57
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-15-0.php';
58
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-0.php';
59
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-3.php';
60
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-19-5.php';
61
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-20-0.php';
62
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-23-4.php';
63
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-24-2.php';
64
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-all-entity-types.php';
65
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-package-type.php';
66
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-25-0.php';
67
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-0.php';
68
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-1.php';
69
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-28-0.php';
70
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-32-0.php';
71
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-33-9.php';
72
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-36-0.php';
73
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-38-5.php';
74
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-39-1.php';
75
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-40-1.php';
76
+
77
+        // Get the install services.
78
+        $this->installs = array(
79
+            new Wordlift_Install_1_0_0(),
80
+            new Wordlift_Install_3_10_0(),
81
+            new Wordlift_Install_3_12_0(),
82
+            new Wordlift_Install_3_14_0(),
83
+            new Wordlift_Install_3_15_0(),
84
+            new Wordlift_Install_3_18_0(),
85
+            new Wordlift_Install_3_18_3(),
86
+            new Wordlift_Install_3_19_5(),
87
+            new Wordlift_Install_3_20_0(),
88
+
89
+            /*
90 90
 			 * This should be enabled with #852.
91 91
 			 */
92
-			new Wordlift_Install_Package_Type(),
93
-			new Wordlift_Install_3_23_4(),
94
-			new Wordlift_Install_3_24_2(),
95
-			new Wordlift_Install_3_25_0(),
96
-			new Wordlift_Install_3_27_0(),
97
-			new Wordlift_Install_3_27_1(),
98
-			new Wordlift_Install_3_28_0(),
99
-			// Add column to represent term
100
-			new Wordlift_Install_3_32_0(),
101
-			// Add the entities table.
102
-			new Wordlift_Install_3_33_9(),
103
-			// When woocommerce extension installed, acf4so should be installed automatically.
104
-			new Wordlift_Install_3_36_0(),
105
-
106
-			new Wordlift_Install_3_38_5(),
107
-			new Wordlift_Install_3_39_1(),
108
-
109
-			// See #1621.
110
-			new Wordlift_Install_3_40_1(),
111
-		);
112
-		self::$instance = $this;
113
-
114
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
115
-
116
-		add_action( 'init', array( $this, 'install' ) );
117
-
118
-	}
119
-
120
-	/**
121
-	 * Get the singleton instance.
122
-	 *
123
-	 * @since 3.18.0
124
-	 */
125
-	public static function get_instance() {
126
-
127
-		return self::$instance;
128
-	}
129
-
130
-	/**
131
-	 * Loop thought all versions and install the updates.
132
-	 *
133
-	 * @return void
134
-	 * @since 3.18.0
135
-	 *
136
-	 * @since 3.20.0 use a transient to avoid concurrent installation calls.
137
-	 */
138
-	public function install() {
139
-
140
-		$version = null;
141
-
142
-		if ( $this->install_required() && false === get_transient( '_wl_installing' ) ) {
143
-			set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS );
144
-			/** @var Wordlift_Install $install */
145
-			foreach ( $this->installs as $install ) {
146
-				// Get the install version.
147
-				$version = $install->get_version();
148
-
149
-				if ( version_compare( $version, $this->get_current_version(), '>' )
150
-					 || $install->must_install() ) {
151
-					$class_name = get_class( $install );
152
-
153
-					$this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." );
154
-					// Install version.
155
-					$install->install();
156
-
157
-					$this->log->info( "$class_name installed." );
158
-
159
-					// Bump the version.
160
-					update_option( 'wl_db_version', $version );
161
-				}
162
-			}
163
-
164
-			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
165
-			@delete_transient( '_wl_installing' );
166
-
167
-		}
168
-
169
-	}
170
-
171
-	private function install_required() {
172
-
173
-		/** @var Wordlift_Install $install */
174
-		foreach ( $this->installs as $install ) {
175
-			// Get the install version.
176
-			$version = $install->get_version();
177
-
178
-			if ( version_compare( $version, $this->get_current_version(), '>' )
179
-				 || $install->must_install() ) {
180
-				return true;
181
-			}
182
-		}
183
-
184
-		return false;
185
-	}
186
-
187
-	/**
188
-	 * Retrieve the current db version.
189
-	 *
190
-	 * @return type
191
-	 */
192
-	private function get_current_version() {
193
-		return get_option( 'wl_db_version', '0.0.0' );
194
-	}
92
+            new Wordlift_Install_Package_Type(),
93
+            new Wordlift_Install_3_23_4(),
94
+            new Wordlift_Install_3_24_2(),
95
+            new Wordlift_Install_3_25_0(),
96
+            new Wordlift_Install_3_27_0(),
97
+            new Wordlift_Install_3_27_1(),
98
+            new Wordlift_Install_3_28_0(),
99
+            // Add column to represent term
100
+            new Wordlift_Install_3_32_0(),
101
+            // Add the entities table.
102
+            new Wordlift_Install_3_33_9(),
103
+            // When woocommerce extension installed, acf4so should be installed automatically.
104
+            new Wordlift_Install_3_36_0(),
105
+
106
+            new Wordlift_Install_3_38_5(),
107
+            new Wordlift_Install_3_39_1(),
108
+
109
+            // See #1621.
110
+            new Wordlift_Install_3_40_1(),
111
+        );
112
+        self::$instance = $this;
113
+
114
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
115
+
116
+        add_action( 'init', array( $this, 'install' ) );
117
+
118
+    }
119
+
120
+    /**
121
+     * Get the singleton instance.
122
+     *
123
+     * @since 3.18.0
124
+     */
125
+    public static function get_instance() {
126
+
127
+        return self::$instance;
128
+    }
129
+
130
+    /**
131
+     * Loop thought all versions and install the updates.
132
+     *
133
+     * @return void
134
+     * @since 3.18.0
135
+     *
136
+     * @since 3.20.0 use a transient to avoid concurrent installation calls.
137
+     */
138
+    public function install() {
139
+
140
+        $version = null;
141
+
142
+        if ( $this->install_required() && false === get_transient( '_wl_installing' ) ) {
143
+            set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS );
144
+            /** @var Wordlift_Install $install */
145
+            foreach ( $this->installs as $install ) {
146
+                // Get the install version.
147
+                $version = $install->get_version();
148
+
149
+                if ( version_compare( $version, $this->get_current_version(), '>' )
150
+                     || $install->must_install() ) {
151
+                    $class_name = get_class( $install );
152
+
153
+                    $this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." );
154
+                    // Install version.
155
+                    $install->install();
156
+
157
+                    $this->log->info( "$class_name installed." );
158
+
159
+                    // Bump the version.
160
+                    update_option( 'wl_db_version', $version );
161
+                }
162
+            }
163
+
164
+            // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
165
+            @delete_transient( '_wl_installing' );
166
+
167
+        }
168
+
169
+    }
170
+
171
+    private function install_required() {
172
+
173
+        /** @var Wordlift_Install $install */
174
+        foreach ( $this->installs as $install ) {
175
+            // Get the install version.
176
+            $version = $install->get_version();
177
+
178
+            if ( version_compare( $version, $this->get_current_version(), '>' )
179
+                 || $install->must_install() ) {
180
+                return true;
181
+            }
182
+        }
183
+
184
+        return false;
185
+    }
186
+
187
+    /**
188
+     * Retrieve the current db version.
189
+     *
190
+     * @return type
191
+     */
192
+    private function get_current_version() {
193
+        return get_option( 'wl_db_version', '0.0.0' );
194
+    }
195 195
 
196 196
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -49,30 +49,30 @@  discard block
 block discarded – undo
49 49
 	public function __construct() {
50 50
 
51 51
 		/** Installs. */
52
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install.php';
53
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-1-0-0.php';
54
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-10-0.php';
55
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-12-0.php';
56
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-14-0.php';
57
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-15-0.php';
58
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-0.php';
59
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-3.php';
60
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-19-5.php';
61
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-20-0.php';
62
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-23-4.php';
63
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-24-2.php';
64
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-all-entity-types.php';
65
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-package-type.php';
66
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-25-0.php';
67
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-0.php';
68
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-1.php';
69
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-28-0.php';
70
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-32-0.php';
71
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-33-9.php';
72
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-36-0.php';
73
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-38-5.php';
74
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-39-1.php';
75
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-40-1.php';
52
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install.php';
53
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-1-0-0.php';
54
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-10-0.php';
55
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-12-0.php';
56
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-14-0.php';
57
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-15-0.php';
58
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-18-0.php';
59
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-18-3.php';
60
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-19-5.php';
61
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-20-0.php';
62
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-23-4.php';
63
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-24-2.php';
64
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-all-entity-types.php';
65
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-package-type.php';
66
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-25-0.php';
67
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-27-0.php';
68
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-27-1.php';
69
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-28-0.php';
70
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-32-0.php';
71
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-33-9.php';
72
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-36-0.php';
73
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-38-5.php';
74
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-39-1.php';
75
+		require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-3-40-1.php';
76 76
 
77 77
 		// Get the install services.
78 78
 		$this->installs = array(
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 		);
112 112
 		self::$instance = $this;
113 113
 
114
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
114
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
115 115
 
116
-		add_action( 'init', array( $this, 'install' ) );
116
+		add_action('init', array($this, 'install'));
117 117
 
118 118
 	}
119 119
 
@@ -139,30 +139,30 @@  discard block
 block discarded – undo
139 139
 
140 140
 		$version = null;
141 141
 
142
-		if ( $this->install_required() && false === get_transient( '_wl_installing' ) ) {
143
-			set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS );
142
+		if ($this->install_required() && false === get_transient('_wl_installing')) {
143
+			set_transient('_wl_installing', true, 5 * MINUTE_IN_SECONDS);
144 144
 			/** @var Wordlift_Install $install */
145
-			foreach ( $this->installs as $install ) {
145
+			foreach ($this->installs as $install) {
146 146
 				// Get the install version.
147 147
 				$version = $install->get_version();
148 148
 
149
-				if ( version_compare( $version, $this->get_current_version(), '>' )
150
-					 || $install->must_install() ) {
151
-					$class_name = get_class( $install );
149
+				if (version_compare($version, $this->get_current_version(), '>')
150
+					 || $install->must_install()) {
151
+					$class_name = get_class($install);
152 152
 
153
-					$this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." );
153
+					$this->log->info("Current version is {$this->get_current_version()}, installing $class_name...");
154 154
 					// Install version.
155 155
 					$install->install();
156 156
 
157
-					$this->log->info( "$class_name installed." );
157
+					$this->log->info("$class_name installed.");
158 158
 
159 159
 					// Bump the version.
160
-					update_option( 'wl_db_version', $version );
160
+					update_option('wl_db_version', $version);
161 161
 				}
162 162
 			}
163 163
 
164 164
 			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
165
-			@delete_transient( '_wl_installing' );
165
+			@delete_transient('_wl_installing');
166 166
 
167 167
 		}
168 168
 
@@ -171,12 +171,12 @@  discard block
 block discarded – undo
171 171
 	private function install_required() {
172 172
 
173 173
 		/** @var Wordlift_Install $install */
174
-		foreach ( $this->installs as $install ) {
174
+		foreach ($this->installs as $install) {
175 175
 			// Get the install version.
176 176
 			$version = $install->get_version();
177 177
 
178
-			if ( version_compare( $version, $this->get_current_version(), '>' )
179
-				 || $install->must_install() ) {
178
+			if (version_compare($version, $this->get_current_version(), '>')
179
+				 || $install->must_install()) {
180 180
 				return true;
181 181
 			}
182 182
 		}
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	 * @return type
191 191
 	 */
192 192
 	private function get_current_version() {
193
-		return get_option( 'wl_db_version', '0.0.0' );
193
+		return get_option('wl_db_version', '0.0.0');
194 194
 	}
195 195
 
196 196
 }
Please login to merge, or discard this patch.
src/install/class-wordlift-install-3-40-1.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Install_3_40_1 extends Wordlift_Install {
9 9
 
10
-	/**
11
-	 * {@inheritdoc}
12
-	 */
13
-	protected static $version = '3.40.1';
10
+    /**
11
+     * {@inheritdoc}
12
+     */
13
+    protected static $version = '3.40.1';
14 14
 
15
-	public function install() {
16
-		// Flush the rewrite rules.
17
-		flush_rewrite_rules();
18
-	}
15
+    public function install() {
16
+        // Flush the rewrite rules.
17
+        flush_rewrite_rules();
18
+    }
19 19
 }
Please login to merge, or discard this patch.