Completed
Pull Request — develop (#1680)
by Naveen
01:15
created
src/includes/class-wordlift-abstract-post-to-jsonld-converter.php 1 patch
Indentation   +446 added lines, -446 removed lines patch added patch discarded remove patch
@@ -24,114 +24,114 @@  discard block
 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 $relations
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(), $relations = null ) {
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 $relations
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(), $relations = null ) {
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
 		 *
@@ -139,353 +139,353 @@  discard block
 block discarded – undo
139 139
 		 *
140 140
 		 * @since 3.20.0
141 141
 		 */
142
-		$post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
143
-		if ( ! empty( $post_content ) || in_array( 'Product', (array) $type, true ) ) {
144
-			// We're setting the `mainEntityOfPage` to signal which one is the
145
-			// main entity for the specified URL. It might be however that the
146
-			// post/page is actually about another specific entity. How WL deals
147
-			// with that hasn't been defined yet (see https://github.com/insideout10/wordlift-plugin/issues/451).
148
-			//
149
-			// See http://schema.org/mainEntityOfPage
150
-			//
151
-			// No need to specify `'@type' => 'WebPage'.
152
-			//
153
-			// See https://github.com/insideout10/wordlift-plugin/issues/451.
154
-			$jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID );
155
-
156
-			/**
157
-			 * @see https://github.com/insideout10/wordlift-plugin/issues/1207
158
-			 *
159
-			 * @since 3.27.7
160
-			 */
161
-			if ( in_array(
162
-				$type,
163
-				array(
164
-					'Occupation',
165
-					'OccupationAggregationByEmployer',
166
-				),
167
-				true
168
-			) ) {
169
-				$jsonld['mainEntityOfPage'] = array(
170
-					'@type'        => 'WebPage',
171
-					'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ),
172
-				);
173
-			}
174
-		};
175
-
176
-		$this->set_images( $this->attachment_service, $post, $jsonld );
177
-
178
-		// Naveen: Get the entities referenced by this post and set it to the `references`
179
-		// array so that the caller can do further processing, such as printing out
180
-		// more of those references.
181
-		//
182
-		// David: you can't set this to the `references`, because `references` it's an array of post
183
-		// IDs and client are using this. As of 3.42.1 (2023-04-20) I am refactoring this to use a
184
-		// new variable $relations.
185
-		// ** @var Object_Relation_Service $object_relation_service */
186
-		// $object_relation_service      = Object_Relation_Service::get_instance();
187
-		// $references_without_locations = $object_relation_service->get_references( $post_id, Object_Type_Enum::POST );
188
-
189
-		$relation_service = Relation_Service::get_instance();
190
-		$content_id       = Wordpress_Content_Id::create_post( $post_id );
191
-		$relation_service->add_relations( $content_id, $relations );
192
-		$this->add_relations_to_references( $relations, $references );
193
-
194
-		$this->expand_references_with_location( $references );
195
-
196
-		return $jsonld;
197
-	}
198
-
199
-	public function expand_references_with_location( &$references ) {
200
-		$entity_type_service = Wordlift_Entity_Type_Service::get_instance();
201
-
202
-		// check if any of the references has the entity type set to Action, Event or organisation.
203
-		$references_with_location = array_filter(
204
-			$references,
205
-			function ( $post_id ) use ( $entity_type_service ) {
206
-				return ( $entity_type_service->has_entity_type( $post_id, 'http://schema.org/Action' )
207
-				|| $entity_type_service->has_entity_type( $post_id, 'http://schema.org/Event' )
208
-				|| $entity_type_service->has_entity_type( $post_id, 'http://schema.org/Organization' ) );
209
-			}
210
-		);
211
-
212
-		// If set, then get all the location ids and push them to references.
213
-		foreach ( $references_with_location as $post_id ) {
214
-			$post_location_ids = get_post_meta( $post_id, Wordlift_Schema_Service::FIELD_LOCATION );
215
-			$post_location_ids = is_array( $post_location_ids ) ? $post_location_ids : array();
216
-			$references        = array_merge( $post_location_ids, $references );
217
-		}
218
-	}
219
-
220
-	/**
221
-	 * Copies the Post relations to referenced post IDs (legacy).
222
-	 *
223
-	 * @param Relations $relations
224
-	 */
225
-	private function add_relations_to_references( $relations, &$references ) {
226
-		/** @var Relation $relation */
227
-		foreach ( $relations->toArray() as $relation ) {
228
-			$object    = $relation->get_object();
229
-			$object_id = $object->get_id();
230
-			if ( $object->get_type() === Object_Type_Enum::POST && ! in_array( $object_id, $references, true ) ) {
231
-				$references[] = $object_id;
232
-			}
233
-		}
234
-	}
235
-
236
-	// private function add_location_reference_objects() {
237
-	// array_reduce(
238
-	// $references_without_locations,
239
-	// function ( $carry, $reference ) use ( $entity_type_service ) {
240
-	// **
241
-	// * @var $reference Reference
242
-	// */
243
-	// @see https://schema.org/location for the schema.org types using the `location` property.
244
-	// if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' )
245
-	// && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' )
246
-	// && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) {
247
-	//
248
-	// return $carry;
249
-	// }
250
-	// $post_location_ids        = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION );
251
-	// $post_location_references = array_map(
252
-	// function ( $post_id ) {
253
-	// return new Post_Reference( $post_id );
254
-	// },
255
-	// $post_location_ids
256
-	// );
257
-	//
258
-	// return array_merge( $carry, $post_location_references );
259
-	// },
260
-	// array()
261
-	// );
262
-	// }
263
-
264
-	/**
265
-	 * If the provided value starts with the schema.org context, we remove the schema.org
266
-	 * part since it is set with the '@context'.
267
-	 *
268
-	 * @param string $value The property value.
269
-	 *
270
-	 * @return string The property value without the context.
271
-	 * @since 3.10.0
272
-	 */
273
-	public function relative_to_context( $value ) {
274
-		return ! is_array( $value ) && 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value;
275
-	}
276
-
277
-	/**
278
-	 * Set the images, by looking for embedded images, for images loaded via the
279
-	 * gallery and for the featured image.
280
-	 *
281
-	 * Uses the cache service to store the results of this function for a day.
282
-	 *
283
-	 * @param $attachment_service Wordlift_Attachment_Service
284
-	 * @param WP_Post                                        $post The target {@link WP_Post}.
285
-	 * @param array                                          $jsonld The JSON-LD array.
286
-	 *
287
-	 * @since 3.10.0
288
-	 */
289
-	public static function set_images( $attachment_service, $post, &$jsonld ) {
290
-
291
-		// Prepare the attachment ids array.
292
-		$ids = array();
293
-
294
-		// Set the thumbnail id as first attachment id, if any.
295
-		$thumbnail_id = get_post_thumbnail_id( $post->ID );
296
-		if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) {
297
-			$ids[] = $thumbnail_id;
298
-		}
299
-
300
-		// For the time being the following is being removed since the query
301
-		// initiated by `get_image_embeds` is consuming lots of CPU.
302
-		//
303
-		// See https://github.com/insideout10/wordlift-plugin/issues/689.
304
-		//
305
-		// Get the embeds, removing existing ids.
306
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
307
-		if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) {
308
-			$embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids );
309
-		} else {
310
-			$embeds = array();
311
-		}
312
-
313
-		// Get the gallery, removing existing ids.
314
-		$gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds );
315
-
316
-		// Map the attachment ids to images' data structured for schema.org use.
317
-		$images_with_sizes = array_filter(
318
-			array_reduce(
319
-				array_merge( $ids, $embeds, $gallery ),
320
-				function ( $carry, $item ) {
321
-					/*
142
+        $post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
143
+        if ( ! empty( $post_content ) || in_array( 'Product', (array) $type, true ) ) {
144
+            // We're setting the `mainEntityOfPage` to signal which one is the
145
+            // main entity for the specified URL. It might be however that the
146
+            // post/page is actually about another specific entity. How WL deals
147
+            // with that hasn't been defined yet (see https://github.com/insideout10/wordlift-plugin/issues/451).
148
+            //
149
+            // See http://schema.org/mainEntityOfPage
150
+            //
151
+            // No need to specify `'@type' => 'WebPage'.
152
+            //
153
+            // See https://github.com/insideout10/wordlift-plugin/issues/451.
154
+            $jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID );
155
+
156
+            /**
157
+             * @see https://github.com/insideout10/wordlift-plugin/issues/1207
158
+             *
159
+             * @since 3.27.7
160
+             */
161
+            if ( in_array(
162
+                $type,
163
+                array(
164
+                    'Occupation',
165
+                    'OccupationAggregationByEmployer',
166
+                ),
167
+                true
168
+            ) ) {
169
+                $jsonld['mainEntityOfPage'] = array(
170
+                    '@type'        => 'WebPage',
171
+                    'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ),
172
+                );
173
+            }
174
+        };
175
+
176
+        $this->set_images( $this->attachment_service, $post, $jsonld );
177
+
178
+        // Naveen: Get the entities referenced by this post and set it to the `references`
179
+        // array so that the caller can do further processing, such as printing out
180
+        // more of those references.
181
+        //
182
+        // David: you can't set this to the `references`, because `references` it's an array of post
183
+        // IDs and client are using this. As of 3.42.1 (2023-04-20) I am refactoring this to use a
184
+        // new variable $relations.
185
+        // ** @var Object_Relation_Service $object_relation_service */
186
+        // $object_relation_service      = Object_Relation_Service::get_instance();
187
+        // $references_without_locations = $object_relation_service->get_references( $post_id, Object_Type_Enum::POST );
188
+
189
+        $relation_service = Relation_Service::get_instance();
190
+        $content_id       = Wordpress_Content_Id::create_post( $post_id );
191
+        $relation_service->add_relations( $content_id, $relations );
192
+        $this->add_relations_to_references( $relations, $references );
193
+
194
+        $this->expand_references_with_location( $references );
195
+
196
+        return $jsonld;
197
+    }
198
+
199
+    public function expand_references_with_location( &$references ) {
200
+        $entity_type_service = Wordlift_Entity_Type_Service::get_instance();
201
+
202
+        // check if any of the references has the entity type set to Action, Event or organisation.
203
+        $references_with_location = array_filter(
204
+            $references,
205
+            function ( $post_id ) use ( $entity_type_service ) {
206
+                return ( $entity_type_service->has_entity_type( $post_id, 'http://schema.org/Action' )
207
+                || $entity_type_service->has_entity_type( $post_id, 'http://schema.org/Event' )
208
+                || $entity_type_service->has_entity_type( $post_id, 'http://schema.org/Organization' ) );
209
+            }
210
+        );
211
+
212
+        // If set, then get all the location ids and push them to references.
213
+        foreach ( $references_with_location as $post_id ) {
214
+            $post_location_ids = get_post_meta( $post_id, Wordlift_Schema_Service::FIELD_LOCATION );
215
+            $post_location_ids = is_array( $post_location_ids ) ? $post_location_ids : array();
216
+            $references        = array_merge( $post_location_ids, $references );
217
+        }
218
+    }
219
+
220
+    /**
221
+     * Copies the Post relations to referenced post IDs (legacy).
222
+     *
223
+     * @param Relations $relations
224
+     */
225
+    private function add_relations_to_references( $relations, &$references ) {
226
+        /** @var Relation $relation */
227
+        foreach ( $relations->toArray() as $relation ) {
228
+            $object    = $relation->get_object();
229
+            $object_id = $object->get_id();
230
+            if ( $object->get_type() === Object_Type_Enum::POST && ! in_array( $object_id, $references, true ) ) {
231
+                $references[] = $object_id;
232
+            }
233
+        }
234
+    }
235
+
236
+    // private function add_location_reference_objects() {
237
+    // array_reduce(
238
+    // $references_without_locations,
239
+    // function ( $carry, $reference ) use ( $entity_type_service ) {
240
+    // **
241
+    // * @var $reference Reference
242
+    // */
243
+    // @see https://schema.org/location for the schema.org types using the `location` property.
244
+    // if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' )
245
+    // && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' )
246
+    // && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) {
247
+    //
248
+    // return $carry;
249
+    // }
250
+    // $post_location_ids        = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION );
251
+    // $post_location_references = array_map(
252
+    // function ( $post_id ) {
253
+    // return new Post_Reference( $post_id );
254
+    // },
255
+    // $post_location_ids
256
+    // );
257
+    //
258
+    // return array_merge( $carry, $post_location_references );
259
+    // },
260
+    // array()
261
+    // );
262
+    // }
263
+
264
+    /**
265
+     * If the provided value starts with the schema.org context, we remove the schema.org
266
+     * part since it is set with the '@context'.
267
+     *
268
+     * @param string $value The property value.
269
+     *
270
+     * @return string The property value without the context.
271
+     * @since 3.10.0
272
+     */
273
+    public function relative_to_context( $value ) {
274
+        return ! is_array( $value ) && 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value;
275
+    }
276
+
277
+    /**
278
+     * Set the images, by looking for embedded images, for images loaded via the
279
+     * gallery and for the featured image.
280
+     *
281
+     * Uses the cache service to store the results of this function for a day.
282
+     *
283
+     * @param $attachment_service Wordlift_Attachment_Service
284
+     * @param WP_Post                                        $post The target {@link WP_Post}.
285
+     * @param array                                          $jsonld The JSON-LD array.
286
+     *
287
+     * @since 3.10.0
288
+     */
289
+    public static function set_images( $attachment_service, $post, &$jsonld ) {
290
+
291
+        // Prepare the attachment ids array.
292
+        $ids = array();
293
+
294
+        // Set the thumbnail id as first attachment id, if any.
295
+        $thumbnail_id = get_post_thumbnail_id( $post->ID );
296
+        if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) {
297
+            $ids[] = $thumbnail_id;
298
+        }
299
+
300
+        // For the time being the following is being removed since the query
301
+        // initiated by `get_image_embeds` is consuming lots of CPU.
302
+        //
303
+        // See https://github.com/insideout10/wordlift-plugin/issues/689.
304
+        //
305
+        // Get the embeds, removing existing ids.
306
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
307
+        if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) {
308
+            $embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids );
309
+        } else {
310
+            $embeds = array();
311
+        }
312
+
313
+        // Get the gallery, removing existing ids.
314
+        $gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds );
315
+
316
+        // Map the attachment ids to images' data structured for schema.org use.
317
+        $images_with_sizes = array_filter(
318
+            array_reduce(
319
+                array_merge( $ids, $embeds, $gallery ),
320
+                function ( $carry, $item ) {
321
+                    /*
322 322
 					* @todo: we're not sure that we're getting attachment data here, we
323 323
 					* should filter `false`s.
324 324
 					*/
325 325
 
326
-					$sources = array_merge(
327
-						Wordlift_Image_Service::get_sources( $item ),
328
-						array( wp_get_attachment_image_src( $item, 'full' ) )
329
-					);
330
-
331
-					$sources_with_image = array_filter(
332
-						$sources,
333
-						function ( $source ) {
334
-							return ! empty( $source[0] );
335
-						}
336
-					);
337
-
338
-					// Get the attachment data.
339
-					// $attachment = wp_get_attachment_image_src( $item, 'full' );
340
-
341
-					// var_dump( array( "sources-$item" => Wordlift_Image_Service::get_sources( $item ) ) );
342
-
343
-					// Bail if image is not found.
344
-					// In some cases, you can delete the image from the database
345
-					// or from uploads dir, but the image id still exists as featured image
346
-					// or in [gallery] shortcode.
347
-					// if ( empty( $attachment[0] ) ) {
348
-					if ( empty( $sources_with_image ) ) {
349
-						return $carry;
350
-					}
351
-
352
-					// Merge the arrays.
353
-					return array_merge(
354
-						$carry,
355
-						$sources_with_image
356
-					);
357
-				},
358
-				// Initial array.
359
-
360
-				array()
361
-			)
362
-		);
363
-
364
-		// Refactor data as per schema.org specifications.
365
-		$images = array_map(
366
-			function ( $attachment ) {
367
-				return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size(
368
-					array(
369
-						'@type' => 'ImageObject',
370
-						'url'   => $attachment[0],
371
-					),
372
-					$attachment
373
-				);
374
-			},
375
-			$images_with_sizes
376
-		);
377
-
378
-		// Add images if present.
379
-		if ( 0 < count( $images ) ) {
380
-			$jsonld['image'] = $images;
381
-		}
382
-
383
-	}
384
-
385
-	/**
386
-	 * If the provided array of values contains only one value, then one single
387
-	 * value is returned, otherwise the original array is returned.
388
-	 *
389
-	 * @param array $value An array of values.
390
-	 *
391
-	 * @return mixed|array A single value or the original array.
392
-	 * @since 3.20.0 The function has been moved from {@link Wordlift_Entity_Post_To_Jsonld_Converter} to
393
-	 *  {@link Wordlift_Abstract_Post_To_Jsonld_Converter}.
394
-	 * @since  3.8.0
395
-	 * @access private
396
-	 */
397
-	protected static function make_one( $value ) {
398
-
399
-		return 1 === count( $value ) ? $value[0] : $value;
400
-	}
401
-
402
-	/**
403
-	 * Process the provided array by adding the width / height if the values
404
-	 * are available and are greater than 0.
405
-	 *
406
-	 * @param array $image The `ImageObject` array.
407
-	 * @param array $attachment The attachment array.
408
-	 *
409
-	 * @return array The enriched `ImageObject` array.
410
-	 * @since 3.14.0
411
-	 */
412
-	public static function set_image_size( $image, $attachment ) {
413
-
414
-		// If you specify a "width" or "height" value you should leave out
415
-		// 'px'. For example: "width":"4608px" should be "width":"4608".
416
-		//
417
-		// See https://github.com/insideout10/wordlift-plugin/issues/451.
418
-		if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) {
419
-			$image['width'] = $attachment[1];
420
-		}
421
-
422
-		if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) {
423
-			$image['height'] = $attachment[2];
424
-		}
425
-
426
-		return $image;
427
-	}
428
-
429
-	/**
430
-	 * Add data to the JSON-LD using the `custom_fields` array which contains the definitions of property
431
-	 * for the post entity type.
432
-	 *
433
-	 * @param array   $jsonld The JSON-LD array.
434
-	 * @param array   $fields The entity types field array.
435
-	 * @param WP_Post $post The target {@link WP_Post} instance.
436
-	 * @param array   $references The references array.
437
-	 *
438
-	 * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in
439
-	 *  the {@link Wordlift_Schema_Service} class.
440
-	 */
441
-	protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) {
442
-
443
-		// Set a reference to use in closures.
444
-		$converter = $this;
445
-
446
-		// Try each field on the entity.
447
-		foreach ( $fields as $key => $value ) {
448
-
449
-			// Get the predicate.
450
-			$name = $this->relative_to_context( $value['predicate'] );
451
-
452
-			// Get the value, the property service will get the right extractor
453
-			// for that property.
454
-			$value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST );
455
-
456
-			if ( empty( $value ) ) {
457
-				continue;
458
-			}
459
-
460
-			// Map the value to the property name.
461
-			// If we got an array with just one value, we return that one value.
462
-			// If we got a Wordlift_Property_Entity_Reference we get the URL.
463
-			$jsonld[ $name ] = self::make_one(
464
-				array_map(
465
-					function ( $item ) use ( $converter, &$references, &$references_infos ) {
466
-
467
-						if ( $item instanceof Wordlift_Property_Entity_Reference ) {
468
-
469
-							$url = $item->get_url();
470
-
471
-							// The refactored converters require the entity id.
472
-							// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
473
-							$references[] = $item->get_id();
474
-
475
-							// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
476
-							$references_infos[] = array( 'reference' => $item );
477
-
478
-							return array( '@id' => $url );
479
-						}
480
-
481
-						return $converter->relative_to_context( $item );
482
-					},
483
-					$value
484
-				)
485
-			);
486
-
487
-		}
488
-
489
-	}
326
+                    $sources = array_merge(
327
+                        Wordlift_Image_Service::get_sources( $item ),
328
+                        array( wp_get_attachment_image_src( $item, 'full' ) )
329
+                    );
330
+
331
+                    $sources_with_image = array_filter(
332
+                        $sources,
333
+                        function ( $source ) {
334
+                            return ! empty( $source[0] );
335
+                        }
336
+                    );
337
+
338
+                    // Get the attachment data.
339
+                    // $attachment = wp_get_attachment_image_src( $item, 'full' );
340
+
341
+                    // var_dump( array( "sources-$item" => Wordlift_Image_Service::get_sources( $item ) ) );
342
+
343
+                    // Bail if image is not found.
344
+                    // In some cases, you can delete the image from the database
345
+                    // or from uploads dir, but the image id still exists as featured image
346
+                    // or in [gallery] shortcode.
347
+                    // if ( empty( $attachment[0] ) ) {
348
+                    if ( empty( $sources_with_image ) ) {
349
+                        return $carry;
350
+                    }
351
+
352
+                    // Merge the arrays.
353
+                    return array_merge(
354
+                        $carry,
355
+                        $sources_with_image
356
+                    );
357
+                },
358
+                // Initial array.
359
+
360
+                array()
361
+            )
362
+        );
363
+
364
+        // Refactor data as per schema.org specifications.
365
+        $images = array_map(
366
+            function ( $attachment ) {
367
+                return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size(
368
+                    array(
369
+                        '@type' => 'ImageObject',
370
+                        'url'   => $attachment[0],
371
+                    ),
372
+                    $attachment
373
+                );
374
+            },
375
+            $images_with_sizes
376
+        );
377
+
378
+        // Add images if present.
379
+        if ( 0 < count( $images ) ) {
380
+            $jsonld['image'] = $images;
381
+        }
382
+
383
+    }
384
+
385
+    /**
386
+     * If the provided array of values contains only one value, then one single
387
+     * value is returned, otherwise the original array is returned.
388
+     *
389
+     * @param array $value An array of values.
390
+     *
391
+     * @return mixed|array A single value or the original array.
392
+     * @since 3.20.0 The function has been moved from {@link Wordlift_Entity_Post_To_Jsonld_Converter} to
393
+     *  {@link Wordlift_Abstract_Post_To_Jsonld_Converter}.
394
+     * @since  3.8.0
395
+     * @access private
396
+     */
397
+    protected static function make_one( $value ) {
398
+
399
+        return 1 === count( $value ) ? $value[0] : $value;
400
+    }
401
+
402
+    /**
403
+     * Process the provided array by adding the width / height if the values
404
+     * are available and are greater than 0.
405
+     *
406
+     * @param array $image The `ImageObject` array.
407
+     * @param array $attachment The attachment array.
408
+     *
409
+     * @return array The enriched `ImageObject` array.
410
+     * @since 3.14.0
411
+     */
412
+    public static function set_image_size( $image, $attachment ) {
413
+
414
+        // If you specify a "width" or "height" value you should leave out
415
+        // 'px'. For example: "width":"4608px" should be "width":"4608".
416
+        //
417
+        // See https://github.com/insideout10/wordlift-plugin/issues/451.
418
+        if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) {
419
+            $image['width'] = $attachment[1];
420
+        }
421
+
422
+        if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) {
423
+            $image['height'] = $attachment[2];
424
+        }
425
+
426
+        return $image;
427
+    }
428
+
429
+    /**
430
+     * Add data to the JSON-LD using the `custom_fields` array which contains the definitions of property
431
+     * for the post entity type.
432
+     *
433
+     * @param array   $jsonld The JSON-LD array.
434
+     * @param array   $fields The entity types field array.
435
+     * @param WP_Post $post The target {@link WP_Post} instance.
436
+     * @param array   $references The references array.
437
+     *
438
+     * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in
439
+     *  the {@link Wordlift_Schema_Service} class.
440
+     */
441
+    protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) {
442
+
443
+        // Set a reference to use in closures.
444
+        $converter = $this;
445
+
446
+        // Try each field on the entity.
447
+        foreach ( $fields as $key => $value ) {
448
+
449
+            // Get the predicate.
450
+            $name = $this->relative_to_context( $value['predicate'] );
451
+
452
+            // Get the value, the property service will get the right extractor
453
+            // for that property.
454
+            $value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST );
455
+
456
+            if ( empty( $value ) ) {
457
+                continue;
458
+            }
459
+
460
+            // Map the value to the property name.
461
+            // If we got an array with just one value, we return that one value.
462
+            // If we got a Wordlift_Property_Entity_Reference we get the URL.
463
+            $jsonld[ $name ] = self::make_one(
464
+                array_map(
465
+                    function ( $item ) use ( $converter, &$references, &$references_infos ) {
466
+
467
+                        if ( $item instanceof Wordlift_Property_Entity_Reference ) {
468
+
469
+                            $url = $item->get_url();
470
+
471
+                            // The refactored converters require the entity id.
472
+                            // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
473
+                            $references[] = $item->get_id();
474
+
475
+                            // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
476
+                            $references_infos[] = array( 'reference' => $item );
477
+
478
+                            return array( '@id' => $url );
479
+                        }
480
+
481
+                        return $converter->relative_to_context( $item );
482
+                    },
483
+                    $value
484
+                )
485
+            );
486
+
487
+        }
488
+
489
+    }
490 490
 
491 491
 }
Please login to merge, or discard this patch.
src/includes/intf-wordlift-post-converter.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -19,19 +19,19 @@
 block discarded – undo
19 19
  */
20 20
 interface Wordlift_Post_Converter {
21 21
 
22
-	/**
23
-	 * Convert the specified post id.
24
-	 *
25
-	 * @param int                 $post_id The post id.
26
-	 * @param array               $references An array of posts referenced by the specified post.
27
-	 * @param array               $references_infos
28
-	 * @param Relations_Interface $relations The relations
29
-	 *
30
-	 * @return mixed The conversion result.
31
-	 * @since 3.42.1 $reference_objects argument added.
32
-	 * @since 3.16.0 $references argument added.
33
-	 * @since 3.10.0
34
-	 */
35
-	public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null );
22
+    /**
23
+     * Convert the specified post id.
24
+     *
25
+     * @param int                 $post_id The post id.
26
+     * @param array               $references An array of posts referenced by the specified post.
27
+     * @param array               $references_infos
28
+     * @param Relations_Interface $relations The relations
29
+     *
30
+     * @return mixed The conversion result.
31
+     * @since 3.42.1 $reference_objects argument added.
32
+     * @since 3.16.0 $references argument added.
33
+     * @since 3.10.0
34
+     */
35
+    public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null );
36 36
 
37 37
 }
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-property-entity-reference.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -20,120 +20,120 @@
 block discarded – undo
20 20
  */
21 21
 class Wordlift_Property_Entity_Reference {
22 22
 
23
-	/**
24
-	 * The URL associated with this entity reference.
25
-	 *
26
-	 * @since  3.8.0
27
-	 * @access private
28
-	 * @var string $url The URL associated with the entity reference.
29
-	 */
30
-	private $url;
31
-
32
-	/**
33
-	 * The entity post id.
34
-	 *
35
-	 * @since  3.10.0
36
-	 * @access private
37
-	 * @var int $id The entity post id.
38
-	 */
39
-	private $id;
40
-
41
-	private $required;
42
-
43
-	/**
44
-	 * @var int
45
-	 */
46
-	private $type;
47
-
48
-	/**
49
-	 * Create a Wordlift_Property_Entity_Reference instance with the provided URL.
50
-	 *
51
-	 * @param string $entity_uri The URL.
52
-	 * @param int    $id The entity post id.
53
-	 * @param bool   $required Whether this property is always required in SD output, default false.
54
-	 * @param int    $type Instance of Object_Enum_Type
55
-	 *
56
-	 * @since 3.8.0
57
-	 */
58
-	public function __construct( $entity_uri, $id, $required = false, $type = Object_Type_Enum::POST ) {
59
-
60
-		$this->url      = $entity_uri;
61
-		$this->id       = $id;
62
-		$this->required = $required;
63
-		$this->type     = $type;
64
-
65
-	}
66
-
67
-	/**
68
-	 * Return the type of the reference, one of the values in Object_Type_Enum
69
-	 *
70
-	 * @return int
71
-	 * @since 3.38.0
72
-	 */
73
-	public function get_type() {
74
-		return $this->type;
75
-	}
76
-
77
-	/**
78
-	 * Get the URL associated with this entity reference.
79
-	 *
80
-	 * @return string The URL associated with the entity reference.
81
-	 * @since 3.8.0
82
-	 */
83
-	public function get_url() {
84
-
85
-		return $this->url;
86
-	}
87
-
88
-	/**
89
-	 * Get the entity id.
90
-	 *
91
-	 * @return int The entity id.
92
-	 * @since 3.10.0
93
-	 */
94
-	public function get_id() {
95
-
96
-		return $this->id;
97
-	}
98
-
99
-	/**
100
-	 * Get the required flag for this {@link Wordlift_Property_Entity_Reference}.
101
-	 *
102
-	 * The required flag may tell converters or consumers (like {@link \Wordlift\Jsonld\Jsonld_Service} that this
103
-	 * property needs to be output to SD (JSON-LD).
104
-	 *
105
-	 * @since 3.27.1
106
-	 */
107
-	public function get_required() {
108
-
109
-		return $this->required;
110
-
111
-	}
112
-
113
-	/**
114
-	 * Set the required flag for this {@link Wordlift_Property_Entity_Reference}.
115
-	 *
116
-	 * The required flag may tell converters or consumers (like {@link \Wordlift\Jsonld\Jsonld_Service} that this
117
-	 * property needs to be output to SD (JSON-LD).
118
-	 *
119
-	 * @param bool $value
120
-	 *
121
-	 * @since 3.27.1
122
-	 */
123
-	public function set_required( $value ) {
124
-
125
-		$this->required = $value;
126
-
127
-	}
128
-
129
-	public function to_reference() {
130
-
131
-		if ( Object_Type_Enum::POST === $this->type ) {
132
-			return new Post_Reference( $this->id );
133
-		}
134
-		if ( Object_Type_Enum::TERM === $this->type ) {
135
-			return new Term_Reference( $this->id );
136
-		}
137
-	}
23
+    /**
24
+     * The URL associated with this entity reference.
25
+     *
26
+     * @since  3.8.0
27
+     * @access private
28
+     * @var string $url The URL associated with the entity reference.
29
+     */
30
+    private $url;
31
+
32
+    /**
33
+     * The entity post id.
34
+     *
35
+     * @since  3.10.0
36
+     * @access private
37
+     * @var int $id The entity post id.
38
+     */
39
+    private $id;
40
+
41
+    private $required;
42
+
43
+    /**
44
+     * @var int
45
+     */
46
+    private $type;
47
+
48
+    /**
49
+     * Create a Wordlift_Property_Entity_Reference instance with the provided URL.
50
+     *
51
+     * @param string $entity_uri The URL.
52
+     * @param int    $id The entity post id.
53
+     * @param bool   $required Whether this property is always required in SD output, default false.
54
+     * @param int    $type Instance of Object_Enum_Type
55
+     *
56
+     * @since 3.8.0
57
+     */
58
+    public function __construct( $entity_uri, $id, $required = false, $type = Object_Type_Enum::POST ) {
59
+
60
+        $this->url      = $entity_uri;
61
+        $this->id       = $id;
62
+        $this->required = $required;
63
+        $this->type     = $type;
64
+
65
+    }
66
+
67
+    /**
68
+     * Return the type of the reference, one of the values in Object_Type_Enum
69
+     *
70
+     * @return int
71
+     * @since 3.38.0
72
+     */
73
+    public function get_type() {
74
+        return $this->type;
75
+    }
76
+
77
+    /**
78
+     * Get the URL associated with this entity reference.
79
+     *
80
+     * @return string The URL associated with the entity reference.
81
+     * @since 3.8.0
82
+     */
83
+    public function get_url() {
84
+
85
+        return $this->url;
86
+    }
87
+
88
+    /**
89
+     * Get the entity id.
90
+     *
91
+     * @return int The entity id.
92
+     * @since 3.10.0
93
+     */
94
+    public function get_id() {
95
+
96
+        return $this->id;
97
+    }
98
+
99
+    /**
100
+     * Get the required flag for this {@link Wordlift_Property_Entity_Reference}.
101
+     *
102
+     * The required flag may tell converters or consumers (like {@link \Wordlift\Jsonld\Jsonld_Service} that this
103
+     * property needs to be output to SD (JSON-LD).
104
+     *
105
+     * @since 3.27.1
106
+     */
107
+    public function get_required() {
108
+
109
+        return $this->required;
110
+
111
+    }
112
+
113
+    /**
114
+     * Set the required flag for this {@link Wordlift_Property_Entity_Reference}.
115
+     *
116
+     * The required flag may tell converters or consumers (like {@link \Wordlift\Jsonld\Jsonld_Service} that this
117
+     * property needs to be output to SD (JSON-LD).
118
+     *
119
+     * @param bool $value
120
+     *
121
+     * @since 3.27.1
122
+     */
123
+    public function set_required( $value ) {
124
+
125
+        $this->required = $value;
126
+
127
+    }
128
+
129
+    public function to_reference() {
130
+
131
+        if ( Object_Type_Enum::POST === $this->type ) {
132
+            return new Post_Reference( $this->id );
133
+        }
134
+        if ( Object_Type_Enum::TERM === $this->type ) {
135
+            return new Term_Reference( $this->id );
136
+        }
137
+    }
138 138
 
139 139
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-relation-service.php 1 patch
Indentation   +430 added lines, -430 removed lines patch added patch discarded remove patch
@@ -18,406 +18,406 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Relation_Service {
20 20
 
21
-	/**
22
-	 * The relation table name in MySQL, set during instantiation.
23
-	 *
24
-	 * @since  3.15.0
25
-	 * @access private
26
-	 * @var string $relation_table The relation table name.
27
-	 */
28
-	private $relation_table;
29
-
30
-	/**
31
-	 * A {@link Wordlift_Log_Service} instance.
32
-	 *
33
-	 * @since 3.15.3
34
-	 *
35
-	 * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
36
-	 */
37
-	private static $log;
38
-
39
-	/**
40
-	 * Create a {@link Wordlift_Relation_Service} instance.
41
-	 *
42
-	 * @since 3.15.0
43
-	 */
44
-	protected function __construct() {
45
-		global $wpdb;
46
-
47
-		self::$log = Wordlift_Log_Service::get_logger( get_class() );
48
-
49
-		// The relations table.
50
-		$this->relation_table = "{$wpdb->prefix}wl_relation_instances";
51
-
52
-	}
53
-
54
-	/**
55
-	 * The singleton instance.
56
-	 *
57
-	 * @since  3.15.0
58
-	 * @access private
59
-	 * @var Wordlift_Relation_Service $instance The singleton instance.
60
-	 */
61
-	private static $instance = null;
62
-
63
-	/**
64
-	 * Get the singleton instance.
65
-	 *
66
-	 * @return Wordlift_Relation_Service The {@link Wordlift_Relation_Service} singleton instance.
67
-	 * @since  3.15.0
68
-	 * @access public
69
-	 */
70
-	public static function get_instance() {
71
-
72
-		if ( ! isset( self::$instance ) ) {
73
-			self::$instance = new self();
74
-		}
75
-
76
-		return self::$instance;
77
-	}
78
-
79
-	/**
80
-	 * Get the articles referencing the specified entity {@link WP_Post}.
81
-	 *
82
-	 * @param int|array     $object_id The entity {@link WP_Post}'s id.
83
-	 * @param string        $fields The fields to return, 'ids' to only return ids or
84
-	 *                                             '*' to return all fields, by default '*'.
85
-	 * @param null|string   $predicate The predicate (who|what|...), by default all.
86
-	 * @param null|string   $status The status, by default all.
87
-	 * @param array         $excludes An array of ids to exclude from the results.
88
-	 * @param null|int      $limit The maximum number of results, by default
89
-	 *                                         no limit.
90
-	 * @param null|array    $include The {@link WP_Post}s' ids to include.
91
-	 *
92
-	 * @param null | string $order_by
93
-	 *
94
-	 * @param array         $post_types
95
-	 *
96
-	 * @return array|object|null Database query results
97
-	 * @since 3.15.0
98
-	 */
99
-	public function get_article_subjects( $object_id, $fields = '*', $predicate = null, $status = null, $excludes = array(), $limit = null, $include = null, $order_by = null, $post_types = array(), $offset = null ) {
100
-		global $wpdb;
101
-
102
-		// The output fields.
103
-		$actual_fields = self::fields( $fields );
104
-
105
-		self::$log->trace( 'Getting article subjects for object ' . implode( ', ', (array) $object_id ) . '...' );
106
-
107
-		$objects = $this->article_id_to_entity_id( $object_id );
108
-
109
-		// If there are no related objects, return an empty array.
110
-		if ( empty( $objects ) ) {
111
-			self::$log->debug( 'No entities found for object ' . implode( ', ', (array) $object_id ) . '.' );
112
-
113
-			return array();
114
-		}
115
-
116
-		self::$log->debug( count( $objects ) . ' entity id(s) found for object ' . implode( ', ', (array) $object_id ) . '.' );
117
-
118
-		$sql =
119
-			"
21
+    /**
22
+     * The relation table name in MySQL, set during instantiation.
23
+     *
24
+     * @since  3.15.0
25
+     * @access private
26
+     * @var string $relation_table The relation table name.
27
+     */
28
+    private $relation_table;
29
+
30
+    /**
31
+     * A {@link Wordlift_Log_Service} instance.
32
+     *
33
+     * @since 3.15.3
34
+     *
35
+     * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
36
+     */
37
+    private static $log;
38
+
39
+    /**
40
+     * Create a {@link Wordlift_Relation_Service} instance.
41
+     *
42
+     * @since 3.15.0
43
+     */
44
+    protected function __construct() {
45
+        global $wpdb;
46
+
47
+        self::$log = Wordlift_Log_Service::get_logger( get_class() );
48
+
49
+        // The relations table.
50
+        $this->relation_table = "{$wpdb->prefix}wl_relation_instances";
51
+
52
+    }
53
+
54
+    /**
55
+     * The singleton instance.
56
+     *
57
+     * @since  3.15.0
58
+     * @access private
59
+     * @var Wordlift_Relation_Service $instance The singleton instance.
60
+     */
61
+    private static $instance = null;
62
+
63
+    /**
64
+     * Get the singleton instance.
65
+     *
66
+     * @return Wordlift_Relation_Service The {@link Wordlift_Relation_Service} singleton instance.
67
+     * @since  3.15.0
68
+     * @access public
69
+     */
70
+    public static function get_instance() {
71
+
72
+        if ( ! isset( self::$instance ) ) {
73
+            self::$instance = new self();
74
+        }
75
+
76
+        return self::$instance;
77
+    }
78
+
79
+    /**
80
+     * Get the articles referencing the specified entity {@link WP_Post}.
81
+     *
82
+     * @param int|array     $object_id The entity {@link WP_Post}'s id.
83
+     * @param string        $fields The fields to return, 'ids' to only return ids or
84
+     *                                             '*' to return all fields, by default '*'.
85
+     * @param null|string   $predicate The predicate (who|what|...), by default all.
86
+     * @param null|string   $status The status, by default all.
87
+     * @param array         $excludes An array of ids to exclude from the results.
88
+     * @param null|int      $limit The maximum number of results, by default
89
+     *                                         no limit.
90
+     * @param null|array    $include The {@link WP_Post}s' ids to include.
91
+     *
92
+     * @param null | string $order_by
93
+     *
94
+     * @param array         $post_types
95
+     *
96
+     * @return array|object|null Database query results
97
+     * @since 3.15.0
98
+     */
99
+    public function get_article_subjects( $object_id, $fields = '*', $predicate = null, $status = null, $excludes = array(), $limit = null, $include = null, $order_by = null, $post_types = array(), $offset = null ) {
100
+        global $wpdb;
101
+
102
+        // The output fields.
103
+        $actual_fields = self::fields( $fields );
104
+
105
+        self::$log->trace( 'Getting article subjects for object ' . implode( ', ', (array) $object_id ) . '...' );
106
+
107
+        $objects = $this->article_id_to_entity_id( $object_id );
108
+
109
+        // If there are no related objects, return an empty array.
110
+        if ( empty( $objects ) ) {
111
+            self::$log->debug( 'No entities found for object ' . implode( ', ', (array) $object_id ) . '.' );
112
+
113
+            return array();
114
+        }
115
+
116
+        self::$log->debug( count( $objects ) . ' entity id(s) found for object ' . implode( ', ', (array) $object_id ) . '.' );
117
+
118
+        $sql =
119
+            "
120 120
 			SELECT DISTINCT p.$actual_fields
121 121
 			FROM {$this->relation_table} r
122 122
 			INNER JOIN $wpdb->posts p
123 123
 				ON p.id = r.subject_id
124 124
 			"
125
-			// Add the status clause.
126
-			. self::and_status( $status )
127
-			. self::inner_join_is_article()
128
-			. self::where_object_id( $objects )
129
-			// Since `object_id` can be an article ID we need to exclude it from
130
-			// the results.
131
-			. self::and_article_not_in( array_merge( $excludes, (array) $object_id ) )
132
-			. self::and_article_in( $include )
133
-			. self::and_post_type_in( $post_types )
134
-			. self::and_predicate( $predicate )
135
-			. self::order_by( $order_by )
136
-			. self::limit( $limit )
137
-			. self::offset( $offset );
138
-
139
-		return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql );  // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
140
-	}
141
-
142
-	/**
143
-	 * The `post_type IN` clause.
144
-	 *
145
-	 * @param array $post_types If the post type is not provided then the valid
146
-	 * entity post types are used.
147
-	 *
148
-	 * @return string The `post_type IN` clause.
149
-	 * @since 3.15.3
150
-	 */
151
-	private static function and_post_type_in( $post_types = array() ) {
152
-
153
-		if ( array() === $post_types ) {
154
-			$post_types = Wordlift_Entity_Service::valid_entity_post_types();
155
-		}
156
-
157
-		return " AND p.post_type IN ( '"
158
-			. implode(
159
-				"','",
160
-				array_map( 'esc_sql', $post_types )
161
-			)
162
-			   . "' )";
163
-	}
164
-
165
-	/**
166
-	 * Add the limit clause if specified.
167
-	 *
168
-	 * @param null|int $limit The maximum number of results.
169
-	 *
170
-	 * @return string The limit clause (empty if no limit has been specified).
171
-	 * @since 3.15.0
172
-	 */
173
-	private static function limit( $limit = null ) {
174
-
175
-		if ( null === $limit ) {
176
-			return '';
177
-		}
178
-
179
-		return "LIMIT $limit";
180
-	}
181
-
182
-	/**
183
-	 * Add the OFFSET clause if specified.
184
-	 *
185
-	 * @param null|int $offset The number of results to skip.
186
-	 *
187
-	 * @return string The offset clause (empty if no offset has been specified).
188
-	 * @since 3.35.11
189
-	 */
190
-	private static function offset( $offset = null ) {
191
-
192
-		if ( null === $offset || ! is_numeric( $offset ) ) {
193
-			return '';
194
-		}
195
-
196
-		return " OFFSET $offset";
197
-	}
198
-
199
-	/**
200
-	 * @param $order_by string | null
201
-	 *
202
-	 * @return string
203
-	 */
204
-	private static function order_by( $order_by ) {
205
-		if ( ! $order_by ) {
206
-			return '';
207
-		}
208
-		$order_by         = (string) $order_by;
209
-		$order_by_clauses = array( 'DESC', 'ASC' );
210
-
211
-		if ( in_array( $order_by, $order_by_clauses, true ) ) {
212
-			return " ORDER BY p.post_modified ${order_by} ";
213
-		} else {
214
-			return ' ORDER BY p.post_modified DESC ';
215
-		}
216
-	}
217
-
218
-	/**
219
-	 * Map the provided ids into entities (i.e. return the id if it's an entity
220
-	 * or get the entities if it's a post).
221
-	 *
222
-	 * @param int|array $object_id An array of posts/entities' ids.
223
-	 *
224
-	 * @return array An array of entities' ids.
225
-	 * @since 3.15.0
226
-	 */
227
-	private function article_id_to_entity_id( $object_id ) {
228
-
229
-		$entity_service = Wordlift_Entity_Service::get_instance();
230
-
231
-		$relation_service = $this;
232
-
233
-		return array_reduce(
234
-			(array) $object_id,
235
-			function ( $carry, $item ) use ( $entity_service, $relation_service ) {
236
-				if ( $entity_service->is_entity( $item ) ) {
237
-					return array_merge( $carry, (array) $item );
238
-				}
239
-
240
-				return array_merge( $carry, $relation_service->get_objects( $item, 'ids' ) );
241
-			},
242
-			array()
243
-		);
244
-
245
-	}
246
-
247
-	/**
248
-	 * Add the WHERE clause.
249
-	 *
250
-	 * @param int|array $object_id An array of {@link WP_Post}s' ids.
251
-	 *
252
-	 * @return string The WHERE clause.
253
-	 * @since 3.15.0
254
-	 */
255
-	private static function where_object_id( $object_id ) {
256
-
257
-		if ( empty( $object_id ) ) {
258
-			// self::$log->warn( sprintf( "%s `where_object_id` called with empty `object_id`.", var_export( debug_backtrace( false, 3 ), true ) ) );
259
-
260
-			return ' WHERE 1 = 1';
261
-		}
262
-
263
-		return ' WHERE r.object_id IN ( ' . implode( ',', wp_parse_id_list( (array) $object_id ) ) . ' )';
264
-	}
265
-
266
-	/**
267
-	 * Add the exclude clause.
268
-	 *
269
-	 * @param int|array $exclude An array of {@link WP_Post}s' ids to exclude.
270
-	 *
271
-	 * @return string The exclude clause.
272
-	 * @since 3.15.0
273
-	 */
274
-	private static function and_article_not_in( $exclude ) {
275
-
276
-		return ' AND NOT p.ID IN ( ' . implode( ',', wp_parse_id_list( (array) $exclude ) ) . ' )';
277
-	}
278
-
279
-	/**
280
-	 * Add the include clause.
281
-	 *
282
-	 * @param null|int|array $include An array of {@link WP_Post}s' ids.
283
-	 *
284
-	 * @return string An empty string if $include is null otherwise the include
285
-	 *                clause.
286
-	 * @since 3.15.0
287
-	 */
288
-	private static function and_article_in( $include = null ) {
289
-
290
-		if ( null === $include ) {
291
-			return '';
292
-		}
293
-
294
-		return ' AND p.ID IN ( ' . implode( ',', wp_parse_id_list( (array) $include ) ) . ' )';
295
-	}
296
-
297
-	/**
298
-	 * Get the entities' {@link WP_Post}s' ids referencing the specified {@link WP_Post}.
299
-	 *
300
-	 * @param int         $object_id The object {@link WP_Post}'s id.
301
-	 * @param string      $fields The fields to return, 'ids' to only return ids or
302
-	 *                                         '*' to return all fields, by default '*'.
303
-	 * @param null|string $status The status, by default all.
304
-	 *
305
-	 * @return array|object|null Database query results
306
-	 * @since 3.15.0
307
-	 */
308
-	public function get_non_article_subjects( $object_id, $fields = '*', $status = null ) {
309
-		global $wpdb;
310
-
311
-		// The output fields.
312
-		$actual_fields = self::fields( $fields );
313
-
314
-		$sql = $wpdb->prepare(
315
-			"SELECT p.$actual_fields FROM {$wpdb->prefix}wl_relation_instances r INNER JOIN $wpdb->posts p ON p.id = r.subject_id" // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
316
-			// Add the status clause.
317
-			. self::and_status( $status ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
318
-			. self::inner_join_is_not_article() // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
319
-			. ' WHERE r.object_id = %d '
320
-			. self::and_post_type_in(), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
321
-			$object_id
322
-		);
323
-
324
-		return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
325
-	}
326
-
327
-	/**
328
-	 * Get the entities referenced by the specified {@link WP_Post}.
329
-	 *
330
-	 * @param int         $subject_id The {@link WP_Post}'s id.
331
-	 * @param string      $fields The fields to return, 'ids' to only return ids or
332
-	 *                                          '*' to return all fields, by default '*'.
333
-	 * @param null|string $predicate The predicate (who|what|...), by default all.
334
-	 * @param null|string $status The status, by default all.
335
-	 *
336
-	 * @return array|object|null Database query results
337
-	 *
338
-	 * @deprecated since it doesn't handle the subject_type nor the object_type
339
-	 * @since 3.15.0
340
-	 */
341
-	public function get_objects( $subject_id, $fields = '*', $predicate = null, $status = null ) {
342
-		global $wpdb;
343
-
344
-		// The output fields.
345
-		$actual_fields = self::fields( $fields );
346
-
347
-		$sql = $wpdb->prepare(
348
-			"SELECT p.$actual_fields FROM {$this->relation_table} r INNER JOIN $wpdb->posts p ON p.id = r.object_id" // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
349
-			// Add the status clause.
350
-			. self::and_status( $status ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
351
-			. self::inner_join_is_not_article() // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
352
-			. ' WHERE r.subject_id = %d '
353
-			. self::and_post_type_in() // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
354
-			. self::and_predicate( $predicate ), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
355
-			$subject_id
356
-		);
357
-
358
-		return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
359
-	}
360
-
361
-	/**
362
-	 * Add the `post_status` clause.
363
-	 *
364
-	 * @param null|string|array $status The status values.
365
-	 *
366
-	 * @return string An empty string if $status is null, otherwise the status clause.
367
-	 * @since 3.15.0
368
-	 */
369
-	private static function and_status( $status = null ) {
370
-
371
-		if ( null === $status ) {
372
-			return '';
373
-		}
374
-
375
-		return " AND p.post_status IN ('" . implode( "', '", array_map( 'esc_sql', (array) $status ) ) . "')";
376
-	}
377
-
378
-	/**
379
-	 * Add the `predicate` clause.
380
-	 *
381
-	 * @param null|string|array $predicate An array of predicates.
382
-	 *
383
-	 * @return string An empty string if $predicate is null otherwise the predicate
384
-	 *                clause.
385
-	 * @since 3.15.0
386
-	 */
387
-	private static function and_predicate( $predicate = null ) {
388
-
389
-		if ( null === $predicate ) {
390
-			return '';
391
-		}
392
-
393
-		return " AND r.predicate IN ('" . implode( "', '", array_map( 'esc_sql', (array) $predicate ) ) . "')";
394
-	}
395
-
396
-	/**
397
-	 * The select fields.
398
-	 *
399
-	 * @param string $fields Either 'ids' or '*', by default '*'.
400
-	 *
401
-	 * @return string The `id` field if `ids` otherwise `*`.
402
-	 * @since 3.15.0
403
-	 */
404
-	private static function fields( $fields = '*' ) {
405
-
406
-		// The output fields.
407
-		return 'ids' === $fields ? 'id' : '*';
408
-	}
409
-
410
-	/**
411
-	 * The inner join clause for articles.
412
-	 *
413
-	 * @return string The articles inner join clause.
414
-	 * @since 3.15.0
415
-	 */
416
-	private static function inner_join_is_article() {
417
-		global $wpdb;
418
-
419
-		return $wpdb->prepare(
420
-			"
125
+            // Add the status clause.
126
+            . self::and_status( $status )
127
+            . self::inner_join_is_article()
128
+            . self::where_object_id( $objects )
129
+            // Since `object_id` can be an article ID we need to exclude it from
130
+            // the results.
131
+            . self::and_article_not_in( array_merge( $excludes, (array) $object_id ) )
132
+            . self::and_article_in( $include )
133
+            . self::and_post_type_in( $post_types )
134
+            . self::and_predicate( $predicate )
135
+            . self::order_by( $order_by )
136
+            . self::limit( $limit )
137
+            . self::offset( $offset );
138
+
139
+        return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql );  // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
140
+    }
141
+
142
+    /**
143
+     * The `post_type IN` clause.
144
+     *
145
+     * @param array $post_types If the post type is not provided then the valid
146
+     * entity post types are used.
147
+     *
148
+     * @return string The `post_type IN` clause.
149
+     * @since 3.15.3
150
+     */
151
+    private static function and_post_type_in( $post_types = array() ) {
152
+
153
+        if ( array() === $post_types ) {
154
+            $post_types = Wordlift_Entity_Service::valid_entity_post_types();
155
+        }
156
+
157
+        return " AND p.post_type IN ( '"
158
+            . implode(
159
+                "','",
160
+                array_map( 'esc_sql', $post_types )
161
+            )
162
+                . "' )";
163
+    }
164
+
165
+    /**
166
+     * Add the limit clause if specified.
167
+     *
168
+     * @param null|int $limit The maximum number of results.
169
+     *
170
+     * @return string The limit clause (empty if no limit has been specified).
171
+     * @since 3.15.0
172
+     */
173
+    private static function limit( $limit = null ) {
174
+
175
+        if ( null === $limit ) {
176
+            return '';
177
+        }
178
+
179
+        return "LIMIT $limit";
180
+    }
181
+
182
+    /**
183
+     * Add the OFFSET clause if specified.
184
+     *
185
+     * @param null|int $offset The number of results to skip.
186
+     *
187
+     * @return string The offset clause (empty if no offset has been specified).
188
+     * @since 3.35.11
189
+     */
190
+    private static function offset( $offset = null ) {
191
+
192
+        if ( null === $offset || ! is_numeric( $offset ) ) {
193
+            return '';
194
+        }
195
+
196
+        return " OFFSET $offset";
197
+    }
198
+
199
+    /**
200
+     * @param $order_by string | null
201
+     *
202
+     * @return string
203
+     */
204
+    private static function order_by( $order_by ) {
205
+        if ( ! $order_by ) {
206
+            return '';
207
+        }
208
+        $order_by         = (string) $order_by;
209
+        $order_by_clauses = array( 'DESC', 'ASC' );
210
+
211
+        if ( in_array( $order_by, $order_by_clauses, true ) ) {
212
+            return " ORDER BY p.post_modified ${order_by} ";
213
+        } else {
214
+            return ' ORDER BY p.post_modified DESC ';
215
+        }
216
+    }
217
+
218
+    /**
219
+     * Map the provided ids into entities (i.e. return the id if it's an entity
220
+     * or get the entities if it's a post).
221
+     *
222
+     * @param int|array $object_id An array of posts/entities' ids.
223
+     *
224
+     * @return array An array of entities' ids.
225
+     * @since 3.15.0
226
+     */
227
+    private function article_id_to_entity_id( $object_id ) {
228
+
229
+        $entity_service = Wordlift_Entity_Service::get_instance();
230
+
231
+        $relation_service = $this;
232
+
233
+        return array_reduce(
234
+            (array) $object_id,
235
+            function ( $carry, $item ) use ( $entity_service, $relation_service ) {
236
+                if ( $entity_service->is_entity( $item ) ) {
237
+                    return array_merge( $carry, (array) $item );
238
+                }
239
+
240
+                return array_merge( $carry, $relation_service->get_objects( $item, 'ids' ) );
241
+            },
242
+            array()
243
+        );
244
+
245
+    }
246
+
247
+    /**
248
+     * Add the WHERE clause.
249
+     *
250
+     * @param int|array $object_id An array of {@link WP_Post}s' ids.
251
+     *
252
+     * @return string The WHERE clause.
253
+     * @since 3.15.0
254
+     */
255
+    private static function where_object_id( $object_id ) {
256
+
257
+        if ( empty( $object_id ) ) {
258
+            // self::$log->warn( sprintf( "%s `where_object_id` called with empty `object_id`.", var_export( debug_backtrace( false, 3 ), true ) ) );
259
+
260
+            return ' WHERE 1 = 1';
261
+        }
262
+
263
+        return ' WHERE r.object_id IN ( ' . implode( ',', wp_parse_id_list( (array) $object_id ) ) . ' )';
264
+    }
265
+
266
+    /**
267
+     * Add the exclude clause.
268
+     *
269
+     * @param int|array $exclude An array of {@link WP_Post}s' ids to exclude.
270
+     *
271
+     * @return string The exclude clause.
272
+     * @since 3.15.0
273
+     */
274
+    private static function and_article_not_in( $exclude ) {
275
+
276
+        return ' AND NOT p.ID IN ( ' . implode( ',', wp_parse_id_list( (array) $exclude ) ) . ' )';
277
+    }
278
+
279
+    /**
280
+     * Add the include clause.
281
+     *
282
+     * @param null|int|array $include An array of {@link WP_Post}s' ids.
283
+     *
284
+     * @return string An empty string if $include is null otherwise the include
285
+     *                clause.
286
+     * @since 3.15.0
287
+     */
288
+    private static function and_article_in( $include = null ) {
289
+
290
+        if ( null === $include ) {
291
+            return '';
292
+        }
293
+
294
+        return ' AND p.ID IN ( ' . implode( ',', wp_parse_id_list( (array) $include ) ) . ' )';
295
+    }
296
+
297
+    /**
298
+     * Get the entities' {@link WP_Post}s' ids referencing the specified {@link WP_Post}.
299
+     *
300
+     * @param int         $object_id The object {@link WP_Post}'s id.
301
+     * @param string      $fields The fields to return, 'ids' to only return ids or
302
+     *                                         '*' to return all fields, by default '*'.
303
+     * @param null|string $status The status, by default all.
304
+     *
305
+     * @return array|object|null Database query results
306
+     * @since 3.15.0
307
+     */
308
+    public function get_non_article_subjects( $object_id, $fields = '*', $status = null ) {
309
+        global $wpdb;
310
+
311
+        // The output fields.
312
+        $actual_fields = self::fields( $fields );
313
+
314
+        $sql = $wpdb->prepare(
315
+            "SELECT p.$actual_fields FROM {$wpdb->prefix}wl_relation_instances r INNER JOIN $wpdb->posts p ON p.id = r.subject_id" // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
316
+            // Add the status clause.
317
+            . self::and_status( $status ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
318
+            . self::inner_join_is_not_article() // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
319
+            . ' WHERE r.object_id = %d '
320
+            . self::and_post_type_in(), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
321
+            $object_id
322
+        );
323
+
324
+        return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
325
+    }
326
+
327
+    /**
328
+     * Get the entities referenced by the specified {@link WP_Post}.
329
+     *
330
+     * @param int         $subject_id The {@link WP_Post}'s id.
331
+     * @param string      $fields The fields to return, 'ids' to only return ids or
332
+     *                                          '*' to return all fields, by default '*'.
333
+     * @param null|string $predicate The predicate (who|what|...), by default all.
334
+     * @param null|string $status The status, by default all.
335
+     *
336
+     * @return array|object|null Database query results
337
+     *
338
+     * @deprecated since it doesn't handle the subject_type nor the object_type
339
+     * @since 3.15.0
340
+     */
341
+    public function get_objects( $subject_id, $fields = '*', $predicate = null, $status = null ) {
342
+        global $wpdb;
343
+
344
+        // The output fields.
345
+        $actual_fields = self::fields( $fields );
346
+
347
+        $sql = $wpdb->prepare(
348
+            "SELECT p.$actual_fields FROM {$this->relation_table} r INNER JOIN $wpdb->posts p ON p.id = r.object_id" // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
349
+            // Add the status clause.
350
+            . self::and_status( $status ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
351
+            . self::inner_join_is_not_article() // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
352
+            . ' WHERE r.subject_id = %d '
353
+            . self::and_post_type_in() // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
354
+            . self::and_predicate( $predicate ), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
355
+            $subject_id
356
+        );
357
+
358
+        return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
359
+    }
360
+
361
+    /**
362
+     * Add the `post_status` clause.
363
+     *
364
+     * @param null|string|array $status The status values.
365
+     *
366
+     * @return string An empty string if $status is null, otherwise the status clause.
367
+     * @since 3.15.0
368
+     */
369
+    private static function and_status( $status = null ) {
370
+
371
+        if ( null === $status ) {
372
+            return '';
373
+        }
374
+
375
+        return " AND p.post_status IN ('" . implode( "', '", array_map( 'esc_sql', (array) $status ) ) . "')";
376
+    }
377
+
378
+    /**
379
+     * Add the `predicate` clause.
380
+     *
381
+     * @param null|string|array $predicate An array of predicates.
382
+     *
383
+     * @return string An empty string if $predicate is null otherwise the predicate
384
+     *                clause.
385
+     * @since 3.15.0
386
+     */
387
+    private static function and_predicate( $predicate = null ) {
388
+
389
+        if ( null === $predicate ) {
390
+            return '';
391
+        }
392
+
393
+        return " AND r.predicate IN ('" . implode( "', '", array_map( 'esc_sql', (array) $predicate ) ) . "')";
394
+    }
395
+
396
+    /**
397
+     * The select fields.
398
+     *
399
+     * @param string $fields Either 'ids' or '*', by default '*'.
400
+     *
401
+     * @return string The `id` field if `ids` otherwise `*`.
402
+     * @since 3.15.0
403
+     */
404
+    private static function fields( $fields = '*' ) {
405
+
406
+        // The output fields.
407
+        return 'ids' === $fields ? 'id' : '*';
408
+    }
409
+
410
+    /**
411
+     * The inner join clause for articles.
412
+     *
413
+     * @return string The articles inner join clause.
414
+     * @since 3.15.0
415
+     */
416
+    private static function inner_join_is_article() {
417
+        global $wpdb;
418
+
419
+        return $wpdb->prepare(
420
+            "
421 421
 			INNER JOIN $wpdb->term_relationships tr
422 422
 			 ON p.id = tr.object_id
423 423
 			INNER JOIN $wpdb->term_taxonomy tt
@@ -427,22 +427,22 @@  discard block
 block discarded – undo
427 427
 			 ON t.term_id = tt.term_id
428 428
 			  AND t.slug = %s
429 429
 			",
430
-			'wl_entity_type',
431
-			'article'
432
-		);
433
-	}
434
-
435
-	/**
436
-	 * The inner join clause for non-articles.
437
-	 *
438
-	 * @return string The non-articles inner join clause.
439
-	 * @since 3.15.0
440
-	 */
441
-	private static function inner_join_is_not_article() {
442
-		global $wpdb;
443
-
444
-		return $wpdb->prepare(
445
-			"
430
+            'wl_entity_type',
431
+            'article'
432
+        );
433
+    }
434
+
435
+    /**
436
+     * The inner join clause for non-articles.
437
+     *
438
+     * @return string The non-articles inner join clause.
439
+     * @since 3.15.0
440
+     */
441
+    private static function inner_join_is_not_article() {
442
+        global $wpdb;
443
+
444
+        return $wpdb->prepare(
445
+            "
446 446
 			INNER JOIN $wpdb->term_relationships tr
447 447
 			 ON p.id = tr.object_id
448 448
 			INNER JOIN $wpdb->term_taxonomy tt
@@ -452,29 +452,29 @@  discard block
 block discarded – undo
452 452
 			 ON t.term_id = tt.term_id
453 453
 			  AND NOT t.slug = %s
454 454
 			",
455
-			'wl_entity_type',
456
-			'article'
457
-		);
458
-	}
459
-
460
-	/**
461
-	 * Find all the subject IDs and their referenced/related object IDs. The
462
-	 * object IDs are returned as comma separated IDs in the `object_ids` key.
463
-	 *
464
-	 * @return mixed Database query results
465
-	 * @since 3.18.0
466
-	 */
467
-	public function find_all_grouped_by_subject_id() {
468
-		global $wpdb;
469
-
470
-		return $wpdb->get_results(
471
-			"
455
+            'wl_entity_type',
456
+            'article'
457
+        );
458
+    }
459
+
460
+    /**
461
+     * Find all the subject IDs and their referenced/related object IDs. The
462
+     * object IDs are returned as comma separated IDs in the `object_ids` key.
463
+     *
464
+     * @return mixed Database query results
465
+     * @since 3.18.0
466
+     */
467
+    public function find_all_grouped_by_subject_id() {
468
+        global $wpdb;
469
+
470
+        return $wpdb->get_results(
471
+            "
472 472
 			SELECT subject_id, GROUP_CONCAT( DISTINCT object_id ORDER BY object_id SEPARATOR ',' ) AS object_ids
473 473
 			FROM {$wpdb->prefix}wl_relation_instances
474 474
 			GROUP BY subject_id
475 475
 			"
476
-		);
476
+        );
477 477
 
478
-	}
478
+    }
479 479
 
480 480
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-post-to-jsonld-converter.php 1 patch
Indentation   +400 added lines, -400 removed lines patch added patch discarded remove patch
@@ -18,424 +18,424 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Post_To_Jsonld_Converter extends Wordlift_Abstract_Post_To_Jsonld_Converter {
20 20
 
21
-	/**
22
-	 * @var Wordlift_Post_To_Jsonld_Converter
23
-	 */
24
-	private static $instance;
25
-
26
-	/**
27
-	 * A {@link Wordlift_Log_Service} instance.
28
-	 *
29
-	 * @since  3.10.0
30
-	 * @access private
31
-	 * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
32
-	 */
33
-	private $log;
34
-
35
-	/**
36
-	 * @var false
37
-	 */
38
-	private $disable_convert_filters;
39
-
40
-	/**
41
-	 * Wordlift_Post_To_Jsonld_Converter constructor.
42
-	 *
43
-	 * @param Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
44
-	 * @param Wordlift_User_Service        $user_service A {@link Wordlift_User_Service} instance.
45
-	 * @param Wordlift_Attachment_Service  $attachment_service A {@link Wordlift_Attachment_Service} instance.
46
-	 *
47
-	 * @since 3.10.0
48
-	 */
49
-	public function __construct( $entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false ) {
50
-		parent::__construct( $entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create() );
51
-		$this->disable_convert_filters = $disable_convert_filters;
52
-		// Set a reference to the logger.
53
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' );
54
-
55
-		self::$instance = $this;
56
-
57
-	}
58
-
59
-	public static function get_instance() {
60
-
61
-		return self::$instance;
62
-	}
63
-
64
-	public function new_instance_with_filters_disabled() {
65
-		return new static( $this->entity_type_service, $this->user_service, $this->attachment_service, true );
66
-	}
67
-
68
-	/**
69
-	 * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference
70
-	 * found while processing the post is set in the $references array.
71
-	 *
72
-	 * @param int              $post_id The post id.
73
-	 * @param array<Reference> $references An array of entity references.
74
-	 * @param array            $references_infos
75
-	 *
76
-	 * @return array A JSON-LD array.
77
-	 * @since 3.10.0
78
-	 */
79
-	public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null ) {
80
-
81
-		// Get the post instance.
82
-		$post = get_post( $post_id );
83
-		if ( null === $post ) {
84
-			// Post not found.
85
-			return null;
86
-		}
87
-
88
-		// Get the base JSON-LD and the list of entities referenced by this entity.
89
-		$jsonld = parent::convert( $post_id, $references, $references_infos, $relations );
90
-
91
-		// Set WebPage by default.
92
-		if ( empty( $jsonld['@type'] ) ) {
93
-			$jsonld['@type'] = 'WebPage';
94
-		}
95
-
96
-		// Get the entity name.
97
-		$jsonld['headline'] = $post->post_title;
98
-
99
-		$custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id );
100
-
101
-		if ( isset( $custom_fields ) ) {
102
-			$this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos );
103
-		}
104
-
105
-		// Set the published and modified dates.
106
-		/*
21
+    /**
22
+     * @var Wordlift_Post_To_Jsonld_Converter
23
+     */
24
+    private static $instance;
25
+
26
+    /**
27
+     * A {@link Wordlift_Log_Service} instance.
28
+     *
29
+     * @since  3.10.0
30
+     * @access private
31
+     * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
32
+     */
33
+    private $log;
34
+
35
+    /**
36
+     * @var false
37
+     */
38
+    private $disable_convert_filters;
39
+
40
+    /**
41
+     * Wordlift_Post_To_Jsonld_Converter constructor.
42
+     *
43
+     * @param Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
44
+     * @param Wordlift_User_Service        $user_service A {@link Wordlift_User_Service} instance.
45
+     * @param Wordlift_Attachment_Service  $attachment_service A {@link Wordlift_Attachment_Service} instance.
46
+     *
47
+     * @since 3.10.0
48
+     */
49
+    public function __construct( $entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false ) {
50
+        parent::__construct( $entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create() );
51
+        $this->disable_convert_filters = $disable_convert_filters;
52
+        // Set a reference to the logger.
53
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' );
54
+
55
+        self::$instance = $this;
56
+
57
+    }
58
+
59
+    public static function get_instance() {
60
+
61
+        return self::$instance;
62
+    }
63
+
64
+    public function new_instance_with_filters_disabled() {
65
+        return new static( $this->entity_type_service, $this->user_service, $this->attachment_service, true );
66
+    }
67
+
68
+    /**
69
+     * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference
70
+     * found while processing the post is set in the $references array.
71
+     *
72
+     * @param int              $post_id The post id.
73
+     * @param array<Reference> $references An array of entity references.
74
+     * @param array            $references_infos
75
+     *
76
+     * @return array A JSON-LD array.
77
+     * @since 3.10.0
78
+     */
79
+    public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null ) {
80
+
81
+        // Get the post instance.
82
+        $post = get_post( $post_id );
83
+        if ( null === $post ) {
84
+            // Post not found.
85
+            return null;
86
+        }
87
+
88
+        // Get the base JSON-LD and the list of entities referenced by this entity.
89
+        $jsonld = parent::convert( $post_id, $references, $references_infos, $relations );
90
+
91
+        // Set WebPage by default.
92
+        if ( empty( $jsonld['@type'] ) ) {
93
+            $jsonld['@type'] = 'WebPage';
94
+        }
95
+
96
+        // Get the entity name.
97
+        $jsonld['headline'] = $post->post_title;
98
+
99
+        $custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id );
100
+
101
+        if ( isset( $custom_fields ) ) {
102
+            $this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos );
103
+        }
104
+
105
+        // Set the published and modified dates.
106
+        /*
107 107
 		 * Set the `datePublished` and `dateModified` using the local timezone.
108 108
 		 *
109 109
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/887
110 110
 		 *
111 111
 		 * @since 3.20.0
112 112
 		 */
113
-		try {
114
-			$default_timezone = date_default_timezone_get();
115
-			$timezone         = get_option( 'timezone_string' );
116
-			if ( ! empty( $timezone ) ) {
117
-				date_default_timezone_set( $timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
118
-				$jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i:sP', false, $post );
119
-				$jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i:sP', false, $post );
120
-				date_default_timezone_set( $default_timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
121
-			} else {
122
-				$jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false );
123
-				$jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false );
124
-			}
125
-		} catch ( Exception $e ) {
126
-			$jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false );
127
-			$jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false );
128
-		}
129
-
130
-		// Get the word count for the post.
131
-		/*
113
+        try {
114
+            $default_timezone = date_default_timezone_get();
115
+            $timezone         = get_option( 'timezone_string' );
116
+            if ( ! empty( $timezone ) ) {
117
+                date_default_timezone_set( $timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
118
+                $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i:sP', false, $post );
119
+                $jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i:sP', false, $post );
120
+                date_default_timezone_set( $default_timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
121
+            } else {
122
+                $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false );
123
+                $jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false );
124
+            }
125
+        } catch ( Exception $e ) {
126
+            $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false );
127
+            $jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false );
128
+        }
129
+
130
+        // Get the word count for the post.
131
+        /*
132 132
 		 * Do not display the `wordCount` on a `WebPage`.
133 133
 		 *
134 134
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/888
135 135
 		 *
136 136
 		 * @since 3.20.0
137 137
 		 */
138
-		if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) {
139
-			$post_adapter        = new Wordlift_Post_Adapter( $post_id );
140
-			$jsonld['wordCount'] = $post_adapter->word_count();
141
-		}
138
+        if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) {
139
+            $post_adapter        = new Wordlift_Post_Adapter( $post_id );
140
+            $jsonld['wordCount'] = $post_adapter->word_count();
141
+        }
142 142
 
143
-		/*
143
+        /*
144 144
 		 * Add keywords, articleSection, commentCount and inLanguage properties to `Article` JSON-LD
145 145
 		 *
146 146
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/1140
147 147
 		 *
148 148
 		 * @since 3.27.2
149 149
 		 */
150
-		if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) {
151
-			$post_adapter    = new Wordlift_Post_Adapter( $post_id );
152
-			$keywords        = $post_adapter->keywords();
153
-			$article_section = $post_adapter->article_section();
154
-			$comment_count   = $post_adapter->comment_count();
155
-			$locale          = $post_adapter->locale();
156
-
157
-			if ( isset( $keywords ) ) {
158
-				$jsonld['keywords'] = $keywords;
159
-			}
160
-			if ( ! empty( $article_section ) ) {
161
-				$jsonld['articleSection'] = $article_section;
162
-			}
163
-			$jsonld['commentCount'] = $comment_count;
164
-			$jsonld['inLanguage']   = $locale;
165
-		}
166
-
167
-		// Set the publisher.
168
-		$this->set_publisher( $jsonld );
169
-
170
-		// Finally set the author.
171
-		$jsonld['author'] = $this->get_author( $post->post_author, $references );
172
-
173
-		// Return the JSON-LD if filters are disabled by the client.
174
-		if ( $this->disable_convert_filters ) {
175
-			return $jsonld;
176
-		}
177
-
178
-		/**
179
-		 * Call the `wl_post_jsonld_array` filter. This filter allows 3rd parties to also modify the references.
180
-		 *
181
-		 * @param array $value {
182
-		 *
183
-		 * @type array $jsonld The JSON-LD structure.
184
-		 * @type int[] $references An array of post IDs.
185
-		 * @type Relations $relations A set of `Relation`s.
186
-		 * }
187
-		 * @since 3.25.0
188
-		 * @since 3.43.0 The filter provides a `Relations` instance.
189
-		 *
190
-		 * @see https://www.geeklab.info/2010/04/wordpress-pass-variables-by-reference-with-apply_filter/
191
-		 *
192
-		 * @api
193
-		 */
194
-		$ret_val = apply_filters(
195
-			'wl_post_jsonld_array',
196
-			array(
197
-				'jsonld'           => $jsonld,
198
-				'references'       => $references, // This one is only an array of post IDs.
199
-				'references_infos' => $references_infos,
200
-				'relations'        => $relations,
201
-			),
202
-			$post_id
203
-		);
204
-
205
-		$jsonld     = $ret_val['jsonld'];
206
-		$references = $ret_val['references'];
207
-
208
-		/**
209
-		 * Call the `wl_post_jsonld` filter.
210
-		 *
211
-		 * @param array $jsonld The JSON-LD structure.
212
-		 * @param int $post_id The {@link WP_Post} `id`.
213
-		 * @param array $references The array of referenced entities.
214
-		 *
215
-		 * @since 3.14.0
216
-		 *
217
-		 * @api
218
-		 */
219
-		return apply_filters( 'wl_post_jsonld', $jsonld, $post_id, $references );
220
-	}
221
-
222
-	/**
223
-	 * Get the author's JSON-LD fragment.
224
-	 *
225
-	 * The JSON-LD fragment is generated using the {@link WP_User}'s data or
226
-	 * the referenced entity if configured for the {@link WP_User}.
227
-	 *
228
-	 * @param int   $author_id The author {@link WP_User}'s `id`.
229
-	 * @param array $references An array of referenced entities.
230
-	 *
231
-	 * @return string|array A JSON-LD structure.
232
-	 * @since 3.14.0
233
-	 */
234
-	public function get_author( $author_id, &$references ) {
235
-
236
-		// Get the entity bound to this user.
237
-		$entity_id = $this->user_service->get_entity( $author_id );
238
-
239
-		// If there's no entity bound return a simple author structure.
240
-		if ( empty( $entity_id ) || 'publish' !== get_post_status( $entity_id ) ) {
241
-
242
-			$author            = get_the_author_meta( 'display_name', $author_id );
243
-			$author_first_name = get_the_author_meta( 'first_name', $author_id );
244
-			$author_last_name  = get_the_author_meta( 'last_name', $author_id );
245
-			$author_uri        = $this->user_service->get_uri( $author_id );
246
-
247
-			return array(
248
-				'@type'      => 'Person',
249
-				'@id'        => $author_uri,
250
-				'name'       => $author,
251
-				'givenName'  => $author_first_name,
252
-				'familyName' => $author_last_name,
253
-				'url'        => get_author_posts_url( $author_id ),
254
-			);
255
-		}
256
-
257
-		// Add the author to the references.
258
-		$author_uri   = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id );
259
-		$references[] = $entity_id;
260
-
261
-		// Return the JSON-LD for the referenced entity.
262
-		return array(
263
-			'@id' => $author_uri,
264
-		);
265
-	}
266
-
267
-	/**
268
-	 * Enrich the provided params array with publisher data, if available.
269
-	 *
270
-	 * @param array $params The parameters array.
271
-	 *
272
-	 * @since 3.10.0
273
-	 */
274
-	protected function set_publisher( &$params ) {
275
-
276
-		// If the publisher id isn't set don't do anything.
277
-		$publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id();
278
-		if ( null === $publisher_id ) {
279
-			return;
280
-		}
281
-
282
-		// Get the post instance.
283
-		$post = get_post( $publisher_id );
284
-		if ( null === $post ) {
285
-			// Publisher not found.
286
-			return;
287
-		}
288
-
289
-		// Get the item id.
290
-		$id = Wordlift_Entity_Service::get_instance()->get_uri( $publisher_id );
291
-
292
-		// Get the type.
293
-		$type = $this->entity_type_service->get( $publisher_id );
294
-
295
-		// Get the name.
296
-		$name = $post->post_title;
297
-
298
-		// Set the publisher data.
299
-		$params['publisher'] = array(
300
-			'@type' => $this->relative_to_context( $type['uri'] ),
301
-			'@id'   => $id,
302
-			'name'  => $name,
303
-		);
304
-
305
-		// Add the sameAs values associated with the publisher.
306
-		$storage_factory = Wordlift_Storage_Factory::get_instance();
307
-		$sameas          = $storage_factory->post_meta( Wordlift_Schema_Service::FIELD_SAME_AS )->get( $publisher_id );
308
-		if ( ! empty( $sameas ) ) {
309
-			$params['publisher']['sameAs'] = $sameas;
310
-		}
311
-
312
-		// Set the logo, only for http://schema.org/Organization as Person doesn't
313
-		// support the logo property.
314
-		//
315
-		// See http://schema.org/logo.
316
-		if ( 1 !== preg_match( '~Organization$~', $type['uri'] ) ) {
317
-			return;
318
-		}
319
-
320
-		// Get the publisher logo.
321
-		$publisher_logo = $this->get_publisher_logo( $post->ID );
322
-
323
-		// Bail out if the publisher logo isn't set.
324
-		if ( false === $publisher_logo ) {
325
-			return;
326
-		}
327
-
328
-		// Copy over some useful properties.
329
-		//
330
-		// See https://developers.google.com/search/docs/data-types/articles.
331
-		$params['publisher']['logo']['@type'] = 'ImageObject';
332
-		$params['publisher']['logo']['url']   = $publisher_logo['url'];
333
-
334
-		// If you specify a "width" or "height" value you should leave out
335
-		// 'px'. For example: "width":"4608px" should be "width":"4608".
336
-		//
337
-		// See https://github.com/insideout10/wordlift-plugin/issues/451.
338
-		$params['publisher']['logo']['width']  = $publisher_logo['width'];
339
-		$params['publisher']['logo']['height'] = $publisher_logo['height'];
340
-
341
-	}
342
-
343
-	/**
344
-	 * Get the publisher logo structure.
345
-	 *
346
-	 * The function returns false when the publisher logo cannot be determined, i.e.:
347
-	 *  - the post has no featured image.
348
-	 *  - the featured image has no file.
349
-	 *  - a wp_image_editor instance cannot be instantiated on the original file or on the publisher logo file.
350
-	 *
351
-	 * @param int $post_id The post id.
352
-	 *
353
-	 * @return array|false Returns an array with the `url`, `width` and `height` for the publisher logo or false in case
354
-	 *  of errors.
355
-	 * @since 3.19.2
356
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/823 related issue.
357
-	 */
358
-	private function get_publisher_logo( $post_id ) {
359
-
360
-		// Get the featured image for the post.
361
-		$thumbnail_id = get_post_thumbnail_id( $post_id );
362
-
363
-		// Bail out if thumbnail not available.
364
-		if ( empty( $thumbnail_id ) || 0 === $thumbnail_id ) {
365
-			$this->log->info( "Featured image not set for post $post_id." );
366
-
367
-			return false;
368
-		}
369
-
370
-		// Get the uploads base URL.
371
-		$uploads_dir = wp_upload_dir();
372
-
373
-		// Get the attachment metadata.
374
-		$metadata = wp_get_attachment_metadata( $thumbnail_id );
375
-
376
-		// Bail out if the file isn't set.
377
-		if ( ! isset( $metadata['file'] ) ) {
378
-			$this->log->warn( "Featured image file not found for post $post_id." );
379
-
380
-			return false;
381
-		}
382
-
383
-		// Retrieve the relative filename, e.g. "2018/05/logo_publisher.png"
384
-		$path = $uploads_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file'];
385
-
386
-		// Use image src, if local file does not exist. @see https://github.com/insideout10/wordlift-plugin/issues/1149
387
-		if ( ! file_exists( $path ) ) {
388
-			$this->log->warn( "Featured image file $path doesn't exist for post $post_id." );
389
-
390
-			$attachment_image_src = wp_get_attachment_image_src( $thumbnail_id, '' );
391
-			if ( $attachment_image_src ) {
392
-				return array(
393
-					'url'    => $attachment_image_src[0],
394
-					'width'  => $attachment_image_src[1],
395
-					'height' => $attachment_image_src[2],
396
-				);
397
-			}
398
-
399
-			// Bail out if we cant fetch wp_get_attachment_image_src
400
-			return false;
401
-
402
-		}
403
-
404
-		// Try to get the image editor and bail out if the editor cannot be instantiated.
405
-		$original_file_editor = wp_get_image_editor( $path );
406
-		if ( is_wp_error( $original_file_editor ) ) {
407
-			$this->log->warn( "Cannot instantiate WP Image Editor on file $path for post $post_id." );
408
-
409
-			return false;
410
-		}
411
-
412
-		// Generate the publisher logo filename, we cannot use the `width` and `height` because we're scaling
413
-		// and we don't actually know the end values.
414
-		$publisher_logo_path = $original_file_editor->generate_filename( '-publisher-logo' );
415
-
416
-		// If the file doesn't exist yet, create it.
417
-		if ( ! file_exists( $publisher_logo_path ) ) {
418
-			$original_file_editor->resize( 600, 60 );
419
-			$original_file_editor->save( $publisher_logo_path );
420
-		}
421
-
422
-		// Try to get the image editor and bail out if the editor cannot be instantiated.
423
-		$publisher_logo_editor = wp_get_image_editor( $publisher_logo_path );
424
-		if ( is_wp_error( $publisher_logo_editor ) ) {
425
-			$this->log->warn( "Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id." );
426
-
427
-			return false;
428
-		}
429
-
430
-		// Get the actual size.
431
-		$size = $publisher_logo_editor->get_size();
432
-
433
-		// Finally return the array with data.
434
-		return array(
435
-			'url'    => $uploads_dir['baseurl'] . substr( $publisher_logo_path, strlen( $uploads_dir['basedir'] ) ),
436
-			'width'  => $size['width'],
437
-			'height' => $size['height'],
438
-		);
439
-	}
150
+        if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) {
151
+            $post_adapter    = new Wordlift_Post_Adapter( $post_id );
152
+            $keywords        = $post_adapter->keywords();
153
+            $article_section = $post_adapter->article_section();
154
+            $comment_count   = $post_adapter->comment_count();
155
+            $locale          = $post_adapter->locale();
156
+
157
+            if ( isset( $keywords ) ) {
158
+                $jsonld['keywords'] = $keywords;
159
+            }
160
+            if ( ! empty( $article_section ) ) {
161
+                $jsonld['articleSection'] = $article_section;
162
+            }
163
+            $jsonld['commentCount'] = $comment_count;
164
+            $jsonld['inLanguage']   = $locale;
165
+        }
166
+
167
+        // Set the publisher.
168
+        $this->set_publisher( $jsonld );
169
+
170
+        // Finally set the author.
171
+        $jsonld['author'] = $this->get_author( $post->post_author, $references );
172
+
173
+        // Return the JSON-LD if filters are disabled by the client.
174
+        if ( $this->disable_convert_filters ) {
175
+            return $jsonld;
176
+        }
177
+
178
+        /**
179
+         * Call the `wl_post_jsonld_array` filter. This filter allows 3rd parties to also modify the references.
180
+         *
181
+         * @param array $value {
182
+         *
183
+         * @type array $jsonld The JSON-LD structure.
184
+         * @type int[] $references An array of post IDs.
185
+         * @type Relations $relations A set of `Relation`s.
186
+         * }
187
+         * @since 3.25.0
188
+         * @since 3.43.0 The filter provides a `Relations` instance.
189
+         *
190
+         * @see https://www.geeklab.info/2010/04/wordpress-pass-variables-by-reference-with-apply_filter/
191
+         *
192
+         * @api
193
+         */
194
+        $ret_val = apply_filters(
195
+            'wl_post_jsonld_array',
196
+            array(
197
+                'jsonld'           => $jsonld,
198
+                'references'       => $references, // This one is only an array of post IDs.
199
+                'references_infos' => $references_infos,
200
+                'relations'        => $relations,
201
+            ),
202
+            $post_id
203
+        );
204
+
205
+        $jsonld     = $ret_val['jsonld'];
206
+        $references = $ret_val['references'];
207
+
208
+        /**
209
+         * Call the `wl_post_jsonld` filter.
210
+         *
211
+         * @param array $jsonld The JSON-LD structure.
212
+         * @param int $post_id The {@link WP_Post} `id`.
213
+         * @param array $references The array of referenced entities.
214
+         *
215
+         * @since 3.14.0
216
+         *
217
+         * @api
218
+         */
219
+        return apply_filters( 'wl_post_jsonld', $jsonld, $post_id, $references );
220
+    }
221
+
222
+    /**
223
+     * Get the author's JSON-LD fragment.
224
+     *
225
+     * The JSON-LD fragment is generated using the {@link WP_User}'s data or
226
+     * the referenced entity if configured for the {@link WP_User}.
227
+     *
228
+     * @param int   $author_id The author {@link WP_User}'s `id`.
229
+     * @param array $references An array of referenced entities.
230
+     *
231
+     * @return string|array A JSON-LD structure.
232
+     * @since 3.14.0
233
+     */
234
+    public function get_author( $author_id, &$references ) {
235
+
236
+        // Get the entity bound to this user.
237
+        $entity_id = $this->user_service->get_entity( $author_id );
238
+
239
+        // If there's no entity bound return a simple author structure.
240
+        if ( empty( $entity_id ) || 'publish' !== get_post_status( $entity_id ) ) {
241
+
242
+            $author            = get_the_author_meta( 'display_name', $author_id );
243
+            $author_first_name = get_the_author_meta( 'first_name', $author_id );
244
+            $author_last_name  = get_the_author_meta( 'last_name', $author_id );
245
+            $author_uri        = $this->user_service->get_uri( $author_id );
246
+
247
+            return array(
248
+                '@type'      => 'Person',
249
+                '@id'        => $author_uri,
250
+                'name'       => $author,
251
+                'givenName'  => $author_first_name,
252
+                'familyName' => $author_last_name,
253
+                'url'        => get_author_posts_url( $author_id ),
254
+            );
255
+        }
256
+
257
+        // Add the author to the references.
258
+        $author_uri   = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id );
259
+        $references[] = $entity_id;
260
+
261
+        // Return the JSON-LD for the referenced entity.
262
+        return array(
263
+            '@id' => $author_uri,
264
+        );
265
+    }
266
+
267
+    /**
268
+     * Enrich the provided params array with publisher data, if available.
269
+     *
270
+     * @param array $params The parameters array.
271
+     *
272
+     * @since 3.10.0
273
+     */
274
+    protected function set_publisher( &$params ) {
275
+
276
+        // If the publisher id isn't set don't do anything.
277
+        $publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id();
278
+        if ( null === $publisher_id ) {
279
+            return;
280
+        }
281
+
282
+        // Get the post instance.
283
+        $post = get_post( $publisher_id );
284
+        if ( null === $post ) {
285
+            // Publisher not found.
286
+            return;
287
+        }
288
+
289
+        // Get the item id.
290
+        $id = Wordlift_Entity_Service::get_instance()->get_uri( $publisher_id );
291
+
292
+        // Get the type.
293
+        $type = $this->entity_type_service->get( $publisher_id );
294
+
295
+        // Get the name.
296
+        $name = $post->post_title;
297
+
298
+        // Set the publisher data.
299
+        $params['publisher'] = array(
300
+            '@type' => $this->relative_to_context( $type['uri'] ),
301
+            '@id'   => $id,
302
+            'name'  => $name,
303
+        );
304
+
305
+        // Add the sameAs values associated with the publisher.
306
+        $storage_factory = Wordlift_Storage_Factory::get_instance();
307
+        $sameas          = $storage_factory->post_meta( Wordlift_Schema_Service::FIELD_SAME_AS )->get( $publisher_id );
308
+        if ( ! empty( $sameas ) ) {
309
+            $params['publisher']['sameAs'] = $sameas;
310
+        }
311
+
312
+        // Set the logo, only for http://schema.org/Organization as Person doesn't
313
+        // support the logo property.
314
+        //
315
+        // See http://schema.org/logo.
316
+        if ( 1 !== preg_match( '~Organization$~', $type['uri'] ) ) {
317
+            return;
318
+        }
319
+
320
+        // Get the publisher logo.
321
+        $publisher_logo = $this->get_publisher_logo( $post->ID );
322
+
323
+        // Bail out if the publisher logo isn't set.
324
+        if ( false === $publisher_logo ) {
325
+            return;
326
+        }
327
+
328
+        // Copy over some useful properties.
329
+        //
330
+        // See https://developers.google.com/search/docs/data-types/articles.
331
+        $params['publisher']['logo']['@type'] = 'ImageObject';
332
+        $params['publisher']['logo']['url']   = $publisher_logo['url'];
333
+
334
+        // If you specify a "width" or "height" value you should leave out
335
+        // 'px'. For example: "width":"4608px" should be "width":"4608".
336
+        //
337
+        // See https://github.com/insideout10/wordlift-plugin/issues/451.
338
+        $params['publisher']['logo']['width']  = $publisher_logo['width'];
339
+        $params['publisher']['logo']['height'] = $publisher_logo['height'];
340
+
341
+    }
342
+
343
+    /**
344
+     * Get the publisher logo structure.
345
+     *
346
+     * The function returns false when the publisher logo cannot be determined, i.e.:
347
+     *  - the post has no featured image.
348
+     *  - the featured image has no file.
349
+     *  - a wp_image_editor instance cannot be instantiated on the original file or on the publisher logo file.
350
+     *
351
+     * @param int $post_id The post id.
352
+     *
353
+     * @return array|false Returns an array with the `url`, `width` and `height` for the publisher logo or false in case
354
+     *  of errors.
355
+     * @since 3.19.2
356
+     * @see https://github.com/insideout10/wordlift-plugin/issues/823 related issue.
357
+     */
358
+    private function get_publisher_logo( $post_id ) {
359
+
360
+        // Get the featured image for the post.
361
+        $thumbnail_id = get_post_thumbnail_id( $post_id );
362
+
363
+        // Bail out if thumbnail not available.
364
+        if ( empty( $thumbnail_id ) || 0 === $thumbnail_id ) {
365
+            $this->log->info( "Featured image not set for post $post_id." );
366
+
367
+            return false;
368
+        }
369
+
370
+        // Get the uploads base URL.
371
+        $uploads_dir = wp_upload_dir();
372
+
373
+        // Get the attachment metadata.
374
+        $metadata = wp_get_attachment_metadata( $thumbnail_id );
375
+
376
+        // Bail out if the file isn't set.
377
+        if ( ! isset( $metadata['file'] ) ) {
378
+            $this->log->warn( "Featured image file not found for post $post_id." );
379
+
380
+            return false;
381
+        }
382
+
383
+        // Retrieve the relative filename, e.g. "2018/05/logo_publisher.png"
384
+        $path = $uploads_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file'];
385
+
386
+        // Use image src, if local file does not exist. @see https://github.com/insideout10/wordlift-plugin/issues/1149
387
+        if ( ! file_exists( $path ) ) {
388
+            $this->log->warn( "Featured image file $path doesn't exist for post $post_id." );
389
+
390
+            $attachment_image_src = wp_get_attachment_image_src( $thumbnail_id, '' );
391
+            if ( $attachment_image_src ) {
392
+                return array(
393
+                    'url'    => $attachment_image_src[0],
394
+                    'width'  => $attachment_image_src[1],
395
+                    'height' => $attachment_image_src[2],
396
+                );
397
+            }
398
+
399
+            // Bail out if we cant fetch wp_get_attachment_image_src
400
+            return false;
401
+
402
+        }
403
+
404
+        // Try to get the image editor and bail out if the editor cannot be instantiated.
405
+        $original_file_editor = wp_get_image_editor( $path );
406
+        if ( is_wp_error( $original_file_editor ) ) {
407
+            $this->log->warn( "Cannot instantiate WP Image Editor on file $path for post $post_id." );
408
+
409
+            return false;
410
+        }
411
+
412
+        // Generate the publisher logo filename, we cannot use the `width` and `height` because we're scaling
413
+        // and we don't actually know the end values.
414
+        $publisher_logo_path = $original_file_editor->generate_filename( '-publisher-logo' );
415
+
416
+        // If the file doesn't exist yet, create it.
417
+        if ( ! file_exists( $publisher_logo_path ) ) {
418
+            $original_file_editor->resize( 600, 60 );
419
+            $original_file_editor->save( $publisher_logo_path );
420
+        }
421
+
422
+        // Try to get the image editor and bail out if the editor cannot be instantiated.
423
+        $publisher_logo_editor = wp_get_image_editor( $publisher_logo_path );
424
+        if ( is_wp_error( $publisher_logo_editor ) ) {
425
+            $this->log->warn( "Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id." );
426
+
427
+            return false;
428
+        }
429
+
430
+        // Get the actual size.
431
+        $size = $publisher_logo_editor->get_size();
432
+
433
+        // Finally return the array with data.
434
+        return array(
435
+            'url'    => $uploads_dir['baseurl'] . substr( $publisher_logo_path, strlen( $uploads_dir['basedir'] ) ),
436
+            'width'  => $size['width'],
437
+            'height' => $size['height'],
438
+        );
439
+    }
440 440
 
441 441
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift.php 1 patch
Indentation   +1770 added lines, -1770 removed lines patch added patch discarded remove patch
@@ -83,1852 +83,1852 @@
 block discarded – undo
83 83
  */
84 84
 class Wordlift {
85 85
 
86
-	/**
87
-	 * The loader that's responsible for maintaining and registering all hooks that power
88
-	 * the plugin.
89
-	 *
90
-	 * @since    1.0.0
91
-	 * @access   protected
92
-	 * @var      Wordlift_Loader $loader Maintains and registers all hooks for the plugin.
93
-	 */
94
-	protected $loader;
95
-
96
-	/**
97
-	 * The unique identifier of this plugin.
98
-	 *
99
-	 * @since    1.0.0
100
-	 * @access   protected
101
-	 * @var      string $plugin_name The string used to uniquely identify this plugin.
102
-	 */
103
-	protected $plugin_name;
104
-
105
-	/**
106
-	 * The current version of the plugin.
107
-	 *
108
-	 * @since    1.0.0
109
-	 * @access   protected
110
-	 * @var      string $version The current version of the plugin.
111
-	 */
112
-	protected $version;
113
-
114
-	/**
115
-	 * The {@link Wordlift_Tinymce_Adapter} instance.
116
-	 *
117
-	 * @since  3.12.0
118
-	 * @access protected
119
-	 * @var \Wordlift_Tinymce_Adapter $tinymce_adapter The {@link Wordlift_Tinymce_Adapter} instance.
120
-	 */
121
-	protected $tinymce_adapter;
122
-
123
-	/**
124
-	 * The Schema service.
125
-	 *
126
-	 * @since  3.3.0
127
-	 * @access protected
128
-	 * @var \Wordlift_Schema_Service $schema_service The Schema service.
129
-	 */
130
-	protected $schema_service;
131
-
132
-	/**
133
-	 * The Topic Taxonomy service.
134
-	 *
135
-	 * @since  3.5.0
136
-	 * @access private
137
-	 * @var \Wordlift_Topic_Taxonomy_Service The Topic Taxonomy service.
138
-	 */
139
-	private $topic_taxonomy_service;
140
-
141
-	/**
142
-	 * The Entity Types Taxonomy service.
143
-	 *
144
-	 * @since  3.18.0
145
-	 * @access private
146
-	 * @var \Wordlift_Entity_Type_Taxonomy_Service The Entity Types Taxonomy service.
147
-	 */
148
-	private $entity_types_taxonomy_service;
149
-
150
-	/**
151
-	 * The User service.
152
-	 *
153
-	 * @since  3.1.7
154
-	 * @access protected
155
-	 * @var \Wordlift_User_Service $user_service The User service.
156
-	 */
157
-	protected $user_service;
158
-
159
-	/**
160
-	 * The Timeline service.
161
-	 *
162
-	 * @since  3.1.0
163
-	 * @access private
164
-	 * @var \Wordlift_Timeline_Service $timeline_service The Timeline service.
165
-	 */
166
-	private $timeline_service;
167
-
168
-	/**
169
-	 * The Redirect service.
170
-	 *
171
-	 * @since  3.2.0
172
-	 * @access private
173
-	 * @var \Wordlift_Redirect_Service $redirect_service The Redirect service.
174
-	 */
175
-	private $redirect_service;
176
-
177
-	/**
178
-	 * The Notice service.
179
-	 *
180
-	 * @since  3.3.0
181
-	 * @access private
182
-	 * @var \Wordlift_Notice_Service $notice_service The Notice service.
183
-	 */
184
-	private $notice_service;
185
-
186
-	/**
187
-	 * The Entity list customization.
188
-	 *
189
-	 * @since  3.3.0
190
-	 * @access protected
191
-	 * @var \Wordlift_Entity_List_Service $entity_list_service The Entity list service.
192
-	 */
193
-	protected $entity_list_service;
194
-
195
-	/**
196
-	 * The Entity Types Taxonomy Walker.
197
-	 *
198
-	 * @since  3.1.0
199
-	 * @access private
200
-	 * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker
201
-	 */
202
-	private $entity_types_taxonomy_walker;
203
-
204
-	/**
205
-	 * The ShareThis service.
206
-	 *
207
-	 * @since  3.2.0
208
-	 * @access private
209
-	 * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service.
210
-	 */
211
-	private $sharethis_service;
212
-
213
-	/**
214
-	 * The PrimaShop adapter.
215
-	 *
216
-	 * @since  3.2.3
217
-	 * @access private
218
-	 * @var \Wordlift_PrimaShop_Adapter $primashop_adapter The PrimaShop adapter.
219
-	 */
220
-	private $primashop_adapter;
221
-
222
-	/**
223
-	 * The entity type service.
224
-	 *
225
-	 * @since  3.6.0
226
-	 * @access private
227
-	 * @var \Wordlift_Entity_Post_Type_Service
228
-	 */
229
-	private $entity_post_type_service;
230
-
231
-	/**
232
-	 * The entity link service used to mangle links to entities with a custom slug or even w/o a slug.
233
-	 *
234
-	 * @since  3.6.0
235
-	 * @access private
236
-	 * @var \Wordlift_Entity_Link_Service $entity_link_service The {@link Wordlift_Entity_Link_Service} instance.
237
-	 */
238
-	private $entity_link_service;
239
-
240
-	/**
241
-	 * A {@link Wordlift_Jsonld_Service} instance.
242
-	 *
243
-	 * @since  3.7.0
244
-	 * @access protected
245
-	 * @var \Wordlift_Jsonld_Service $jsonld_service A {@link Wordlift_Jsonld_Service} instance.
246
-	 */
247
-	protected $jsonld_service;
248
-
249
-	/**
250
-	 * A {@link Wordlift_Website_Jsonld_Converter} instance.
251
-	 *
252
-	 * @since  3.14.0
253
-	 * @access protected
254
-	 * @var \Wordlift_Website_Jsonld_Converter $jsonld_website_converter A {@link Wordlift_Website_Jsonld_Converter} instance.
255
-	 */
256
-	protected $jsonld_website_converter;
257
-
258
-	/**
259
-	 * A {@link Wordlift_Property_Factory} instance.
260
-	 *
261
-	 * @since  3.7.0
262
-	 * @access private
263
-	 * @var \Wordlift_Property_Factory $property_factory
264
-	 */
265
-	private $property_factory;
266
-
267
-	/**
268
-	 * The 'Download Your Data' page.
269
-	 *
270
-	 * @since  3.6.0
271
-	 * @access private
272
-	 * @var \Wordlift_Admin_Download_Your_Data_Page $download_your_data_page The 'Download Your Data' page.
273
-	 */
274
-	private $download_your_data_page;
275
-
276
-	/**
277
-	 * The 'WordLift Settings' page.
278
-	 *
279
-	 * @since  3.11.0
280
-	 * @access protected
281
-	 * @var \Wordlift_Admin_Settings_Page $settings_page The 'WordLift Settings' page.
282
-	 */
283
-	protected $settings_page;
284
-
285
-	/**
286
-	 * The install wizard page.
287
-	 *
288
-	 * @since  3.9.0
289
-	 * @access private
290
-	 * @var \Wordlift_Admin_Setup $admin_setup The Install wizard.
291
-	 */
292
-	public $admin_setup;
293
-
294
-	/**
295
-	 * The Content Filter Service hooks up to the 'the_content' filter and provides
296
-	 * linking of entities to their pages.
297
-	 *
298
-	 * @since  3.8.0
299
-	 * @access private
300
-	 * @var \Wordlift_Content_Filter_Service $content_filter_service A {@link Wordlift_Content_Filter_Service} instance.
301
-	 */
302
-	private $content_filter_service;
303
-
304
-	/**
305
-	 * The Faq Content filter service
306
-	 *
307
-	 * @since  3.26.0
308
-	 * @access private
309
-	 * @var Faq_Content_Filter $faq_content_filter_service A {@link Faq_Content_Filter} instance.
310
-	 */
311
-	private $faq_content_filter_service;
312
-
313
-	/**
314
-	 * A {@link Wordlift_Key_Validation_Service} instance.
315
-	 *
316
-	 * @since  3.9.0
317
-	 * @access private
318
-	 * @var Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance.
319
-	 */
320
-	private $key_validation_service;
321
-
322
-	/**
323
-	 * A {@link Wordlift_Rating_Service} instance.
324
-	 *
325
-	 * @since  3.10.0
326
-	 * @access private
327
-	 * @var \Wordlift_Rating_Service $rating_service A {@link Wordlift_Rating_Service} instance.
328
-	 */
329
-	private $rating_service;
330
-
331
-	/**
332
-	 * A {@link Wordlift_Post_To_Jsonld_Converter} instance.
333
-	 *
334
-	 * @since  3.10.0
335
-	 * @access protected
336
-	 * @var \Wordlift_Post_To_Jsonld_Converter $post_to_jsonld_converter A {@link Wordlift_Post_To_Jsonld_Converter} instance.
337
-	 */
338
-	protected $post_to_jsonld_converter;
339
-
340
-	/**
341
-	 * A {@link Wordlift_Install_Service} instance.
342
-	 *
343
-	 * @since  3.18.0
344
-	 * @access protected
345
-	 * @var \Wordlift_Install_Service $install_service A {@link Wordlift_Install_Service} instance.
346
-	 */
347
-	protected $install_service;
348
-
349
-	/**
350
-	 * A {@link Wordlift_Entity_Post_To_Jsonld_Converter} instance.
351
-	 *
352
-	 * @since  3.10.0
353
-	 * @access protected
354
-	 * @var \Wordlift_Entity_Post_To_Jsonld_Converter $entity_post_to_jsonld_converter A {@link Wordlift_Entity_Post_To_Jsonld_Converter} instance.
355
-	 */
356
-	protected $entity_post_to_jsonld_converter;
357
-
358
-	/**
359
-	 * A {@link Wordlift_Postid_To_Jsonld_Converter} instance.
360
-	 *
361
-	 * @since  3.10.0
362
-	 * @access protected
363
-	 * @var \Wordlift_Postid_To_Jsonld_Converter $postid_to_jsonld_converter A {@link Wordlift_Postid_To_Jsonld_Converter} instance.
364
-	 */
365
-	protected $postid_to_jsonld_converter;
366
-
367
-	/**
368
-	 * The {@link Wordlift_Category_Taxonomy_Service} instance.
369
-	 *
370
-	 * @since  3.11.0
371
-	 * @access protected
372
-	 * @var \Wordlift_Category_Taxonomy_Service $category_taxonomy_service The {@link Wordlift_Category_Taxonomy_Service} instance.
373
-	 */
374
-	protected $category_taxonomy_service;
375
-
376
-	/**
377
-	 * The {@link Wordlift_Entity_Page_Service} instance.
378
-	 *
379
-	 * @since  3.11.0
380
-	 * @access protected
381
-	 * @var \Wordlift_Entity_Page_Service $entity_page_service The {@link Wordlift_Entity_Page_Service} instance.
382
-	 */
383
-	protected $entity_page_service;
384
-
385
-	/**
386
-	 * The {@link Wordlift_Admin_Settings_Page_Action_Link} class.
387
-	 *
388
-	 * @since  3.11.0
389
-	 * @access protected
390
-	 * @var \Wordlift_Admin_Settings_Page_Action_Link $settings_page_action_link The {@link Wordlift_Admin_Settings_Page_Action_Link} class.
391
-	 */
392
-	protected $settings_page_action_link;
393
-
394
-	/**
395
-	 * The {@link Wordlift_Admin_Settings_Page_Action_Link} class.
396
-	 *
397
-	 * @since  3.11.0
398
-	 * @access protected
399
-	 * @var \Wordlift_Admin_Settings_Page_Action_Link $settings_page_action_link The {@link Wordlift_Admin_Settings_Page_Action_Link} class.
400
-	 */
401
-	protected $analytics_settings_page_action_link;
402
-
403
-	/**
404
-	 * The {@link Wordlift_Analytics_Connect} class.
405
-	 *
406
-	 * @since  3.11.0
407
-	 * @access protected
408
-	 * @var \Wordlift_Analytics_Connect $analytics_connect The {@link Wordlift_Analytics_Connect} class.
409
-	 */
410
-	protected $analytics_connect;
411
-
412
-	/**
413
-	 * The {@link Wordlift_Publisher_Ajax_Adapter} instance.
414
-	 *
415
-	 * @since  3.11.0
416
-	 * @access protected
417
-	 * @var \Wordlift_Publisher_Ajax_Adapter $publisher_ajax_adapter The {@link Wordlift_Publisher_Ajax_Adapter} instance.
418
-	 */
419
-	protected $publisher_ajax_adapter;
420
-
421
-	/**
422
-	 * The {@link Wordlift_Admin_Input_Element} element renderer.
423
-	 *
424
-	 * @since  3.11.0
425
-	 * @access protected
426
-	 * @var \Wordlift_Admin_Input_Element $input_element The {@link Wordlift_Admin_Input_Element} element renderer.
427
-	 */
428
-	protected $input_element;
429
-
430
-	/**
431
-	 * The {@link Wordlift_Admin_Radio_Input_Element} element renderer.
432
-	 *
433
-	 * @since  3.13.0
434
-	 * @access protected
435
-	 * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element The {@link Wordlift_Admin_Radio_Input_Element} element renderer.
436
-	 */
437
-	protected $radio_input_element;
438
-
439
-	/**
440
-	 * The {@link Wordlift_Admin_Language_Select_Element} element renderer.
441
-	 *
442
-	 * @since  3.11.0
443
-	 * @access protected
444
-	 * @var \Wordlift_Admin_Language_Select_Element $language_select_element The {@link Wordlift_Admin_Language_Select_Element} element renderer.
445
-	 */
446
-	protected $language_select_element;
447
-
448
-	/**
449
-	 * The {@link Wordlift_Admin_Country_Select_Element} element renderer.
450
-	 *
451
-	 * @since  3.18.0
452
-	 * @access protected
453
-	 * @var \Wordlift_Admin_Country_Select_Element $country_select_element The {@link Wordlift_Admin_Country_Select_Element} element renderer.
454
-	 */
455
-	protected $country_select_element;
456
-
457
-	/**
458
-	 * The {@link Wordlift_Admin_Publisher_Element} element renderer.
459
-	 *
460
-	 * @since  3.11.0
461
-	 * @access protected
462
-	 * @var \Wordlift_Admin_Publisher_Element $publisher_element The {@link Wordlift_Admin_Publisher_Element} element renderer.
463
-	 */
464
-	protected $publisher_element;
465
-
466
-	/**
467
-	 * The {@link Wordlift_Admin_Select2_Element} element renderer.
468
-	 *
469
-	 * @since  3.11.0
470
-	 * @access protected
471
-	 * @var \Wordlift_Admin_Select2_Element $select2_element The {@link Wordlift_Admin_Select2_Element} element renderer.
472
-	 */
473
-	protected $select2_element;
474
-
475
-	/**
476
-	 * The controller for the entity type list admin page
477
-	 *
478
-	 * @since  3.11.0
479
-	 * @access private
480
-	 * @var \Wordlift_Admin_Entity_Taxonomy_List_Page $entity_type_admin_page The {@link Wordlift_Admin_Entity_Taxonomy_List_Page} class.
481
-	 */
482
-	private $entity_type_admin_page;
483
-
484
-	/**
485
-	 * The controller for the entity type settings admin page
486
-	 *
487
-	 * @since  3.11.0
488
-	 * @access private
489
-	 * @var \Wordlift_Admin_Entity_Type_Settings $entity_type_settings_admin_page The {@link Wordlift_Admin_Entity_Type_Settings} class.
490
-	 */
491
-	private $entity_type_settings_admin_page;
492
-
493
-	/**
494
-	 * The {@link Wordlift_Related_Entities_Cloud_Widget} instance.
495
-	 *
496
-	 * @since  3.11.0
497
-	 * @access protected
498
-	 * @var \Wordlift_Related_Entities_Cloud_Widget $related_entities_cloud_widget The {@link Wordlift_Related_Entities_Cloud_Widget} instance.
499
-	 */
500
-	protected $related_entities_cloud_widget;
501
-
502
-	/**
503
-	 * The {@link Wordlift_Admin_Author_Element} instance.
504
-	 *
505
-	 * @since  3.14.0
506
-	 * @access protected
507
-	 * @var \Wordlift_Admin_Author_Element $author_element The {@link Wordlift_Admin_Author_Element} instance.
508
-	 */
509
-	protected $author_element;
510
-
511
-	/**
512
-	 * The {@link Wordlift_Sample_Data_Service} instance.
513
-	 *
514
-	 * @since  3.12.0
515
-	 * @access protected
516
-	 * @var \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance.
517
-	 */
518
-	protected $sample_data_service;
519
-
520
-	/**
521
-	 * The {@link Wordlift_Sample_Data_Ajax_Adapter} instance.
522
-	 *
523
-	 * @since  3.12.0
524
-	 * @access protected
525
-	 * @var \Wordlift_Sample_Data_Ajax_Adapter $sample_data_ajax_adapter The {@link Wordlift_Sample_Data_Ajax_Adapter} instance.
526
-	 */
527
-	protected $sample_data_ajax_adapter;
528
-
529
-	/**
530
-	 * The {@link Wordlift_Google_Analytics_Export_Service} instance.
531
-	 *
532
-	 * @since  3.16.0
533
-	 * @access protected
534
-	 * @var \Wordlift_Google_Analytics_Export_Service $google_analytics_export_service The {@link Wordlift_Google_Analytics_Export_Service} instance.
535
-	 */
536
-	protected $google_analytics_export_service;
537
-
538
-	/**
539
-	 * {@link Wordlift}'s singleton instance.
540
-	 *
541
-	 * @since  3.15.0
542
-	 * @access protected
543
-	 * @var \Wordlift_Entity_Type_Adapter $entity_type_adapter The {@link Wordlift_Entity_Type_Adapter} instance.
544
-	 */
545
-	protected $entity_type_adapter;
546
-
547
-	/**
548
-	 * The {@link Wordlift_Storage_Factory} instance.
549
-	 *
550
-	 * @since  3.15.0
551
-	 * @access protected
552
-	 * @var \Wordlift_Storage_Factory $storage_factory The {@link Wordlift_Storage_Factory} instance.
553
-	 */
554
-	protected $storage_factory;
555
-
556
-	/**
557
-	 * The {@link Wordlift_Autocomplete_Adapter} instance.
558
-	 *
559
-	 * @since  3.15.0
560
-	 * @access private
561
-	 * @var \Wordlift_Autocomplete_Adapter $autocomplete_adapter The {@link Wordlift_Autocomplete_Adapter} instance.
562
-	 */
563
-	private $autocomplete_adapter;
564
-
565
-	/**
566
-	 * The {@link Wordlift_Cached_Post_Converter} instance.
567
-	 *
568
-	 * @since  3.16.0
569
-	 * @access protected
570
-	 * @var  \Wordlift_Cached_Post_Converter $cached_postid_to_jsonld_converter The {@link Wordlift_Cached_Post_Converter} instance.
571
-	 */
572
-	protected $cached_postid_to_jsonld_converter;
573
-
574
-	/**
575
-	 * The {@link Wordlift_Entity_Uri_Service} instance.
576
-	 *
577
-	 * @since  3.16.3
578
-	 * @access protected
579
-	 * @var \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance.
580
-	 */
581
-	protected $entity_uri_service;
582
-
583
-	/**
584
-	 * The {@link Wordlift_Publisher_Service} instance.
585
-	 *
586
-	 * @since  3.19.0
587
-	 * @access protected
588
-	 * @var \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
589
-	 */
590
-	protected $publisher_service;
591
-
592
-	/**
593
-	 * The {@link Wordlift_Context_Cards_Service} instance.
594
-	 *
595
-	 * @var \Wordlift_Context_Cards_Service The {@link Wordlift_Context_Cards_Service} instance.
596
-	 */
597
-	protected $context_cards_service;
598
-
599
-	/**
600
-	 * {@link Wordlift}'s singleton instance.
601
-	 *
602
-	 * @since  3.11.2
603
-	 * @access private
604
-	 * @var Wordlift $instance {@link Wordlift}'s singleton instance.
605
-	 */
606
-	private static $instance;
607
-
608
-	/**
609
-	 * A singleton instance of features registry.
610
-	 *
611
-	 * @since 3.30.0
612
-	 * @var Features_Registry
613
-	 */
614
-	private $features_registry;
615
-
616
-	private $analytics_settings_page;
617
-
618
-	private $webhook_loader;
619
-
620
-	/**
621
-	 * Define the core functionality of the plugin.
622
-	 *
623
-	 * Set the plugin name and the plugin version that can be used throughout the plugin.
624
-	 * Load the dependencies, define the locale, and set the hooks for the admin area and
625
-	 * the public-facing side of the site.
626
-	 *
627
-	 * @since    1.0.0
628
-	 */
629
-	public function __construct() {
630
-
631
-		self::$instance = $this;
632
-
633
-		$this->plugin_name = 'wordlift';
634
-		$this->version     = WORDLIFT_VERSION;
635
-		$this->load_dependencies();
636
-		$this->set_locale();
637
-
638
-		$that = $this;
639
-		add_action(
640
-			'plugins_loaded',
641
-			function () use ( $that ) {
642
-				$that->define_admin_hooks( $that );
643
-				$that->define_public_hooks( $that );
644
-			},
645
-			4
646
-		);
647
-
648
-		// If we're in `WP_CLI` load the related files.
649
-		if ( class_exists( 'WP_CLI' ) ) {
650
-			$this->load_cli_dependencies();
651
-		}
652
-
653
-	}
654
-
655
-	/**
656
-	 * Get the singleton instance.
657
-	 *
658
-	 * @return Wordlift The {@link Wordlift} singleton instance.
659
-	 * @since 3.11.2
660
-	 */
661
-	public static function get_instance() {
662
-
663
-		return self::$instance;
664
-	}
665
-
666
-	/**
667
-	 * Load the required dependencies for this plugin.
668
-	 *
669
-	 * Include the following files that make up the plugin:
670
-	 *
671
-	 * - Wordlift_Loader. Orchestrates the hooks of the plugin.
672
-	 * - Wordlift_i18n. Defines internationalization functionality.
673
-	 * - Wordlift_Admin. Defines all hooks for the admin area.
674
-	 * - Wordlift_Public. Defines all hooks for the public side of the site.
675
-	 *
676
-	 * Create an instance of the loader which will be used to register the hooks
677
-	 * with WordPress.
678
-	 *
679
-	 * @throws Exception when an error occurs.
680
-	 * @since    1.0.0
681
-	 * @access   private
682
-	 */
683
-	private function load_dependencies() {
684
-
685
-		/**
686
-		 * The class responsible for orchestrating the actions and filters of the
687
-		 * core plugin.
688
-		 */
689
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-loader.php';
690
-
691
-		// The class responsible for plugin uninstall.
692
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-deactivator-feedback.php';
693
-
694
-		/**
695
-		 * The class responsible for defining internationalization functionality
696
-		 * of the plugin.
697
-		 */
698
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-i18n.php';
699
-
700
-		/**
701
-		 * WordLift's supported languages.
702
-		 */
703
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-languages.php';
704
-
705
-		/**
706
-		 * WordLift's supported countries.
707
-		 */
708
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-countries.php';
709
-
710
-		/**
711
-		 * Provide support functions to sanitize data.
712
-		 */
713
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-sanitizer.php';
714
-
715
-		/** Services. */
716
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-log-service.php';
717
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-http-api.php';
718
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-redirect-service.php';
719
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-configuration-service.php';
720
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-post-type-service.php';
721
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-type-service.php';
722
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-link-service.php';
723
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-relation-service.php';
724
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-image-service.php';
725
-
726
-		/**
727
-		 * The Schema service.
728
-		 */
729
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-schema-service.php';
730
-
731
-		/**
732
-		 * The schema:url property service.
733
-		 */
734
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-property-service.php';
735
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-schema-url-property-service.php';
736
-
737
-		/**
738
-		 * The UI service.
739
-		 */
740
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-ui-service.php';
741
-
742
-		/**
743
-		 * The Entity Types Taxonomy service.
744
-		 */
745
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-type-taxonomy-service.php';
746
-
747
-		/**
748
-		 * The Entity service.
749
-		 */
750
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-uri-service.php';
751
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-service.php';
752
-
753
-		// Add the entity rating service.
754
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-rating-service.php';
755
-
756
-		/**
757
-		 * The User service.
758
-		 */
759
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-user-service.php';
760
-
761
-		/**
762
-		 * The Timeline service.
763
-		 */
764
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-timeline-service.php';
765
-
766
-		/**
767
-		 * The Topic Taxonomy service.
768
-		 */
769
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-topic-taxonomy-service.php';
770
-
771
-		/**
772
-		 * The WordLift URI service.
773
-		 */
774
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-uri-service.php';
775
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-property-factory.php';
776
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-sample-data-service.php';
777
-
778
-		require_once plugin_dir_path( __DIR__ ) . 'includes/properties/class-wordlift-property-getter-factory.php';
779
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-attachment-service.php';
780
-
781
-		/**
782
-		 * Load the converters.
783
-		 */
784
-		require_once plugin_dir_path( __DIR__ ) . 'includes/intf-wordlift-post-converter.php';
785
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-abstract-post-to-jsonld-converter.php';
786
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-postid-to-jsonld-converter.php';
787
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-post-to-jsonld-converter.php';
788
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-post-to-jsonld-converter.php';
789
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-website-jsonld-converter.php';
790
-
791
-		/**
792
-		 * Load cache-related files.
793
-		 */
794
-		require_once plugin_dir_path( __DIR__ ) . 'includes/cache/require.php';
795
-
796
-		/**
797
-		 * Load the content filter.
798
-		 */
799
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-content-filter-service.php';
800
-
801
-		/*
86
+    /**
87
+     * The loader that's responsible for maintaining and registering all hooks that power
88
+     * the plugin.
89
+     *
90
+     * @since    1.0.0
91
+     * @access   protected
92
+     * @var      Wordlift_Loader $loader Maintains and registers all hooks for the plugin.
93
+     */
94
+    protected $loader;
95
+
96
+    /**
97
+     * The unique identifier of this plugin.
98
+     *
99
+     * @since    1.0.0
100
+     * @access   protected
101
+     * @var      string $plugin_name The string used to uniquely identify this plugin.
102
+     */
103
+    protected $plugin_name;
104
+
105
+    /**
106
+     * The current version of the plugin.
107
+     *
108
+     * @since    1.0.0
109
+     * @access   protected
110
+     * @var      string $version The current version of the plugin.
111
+     */
112
+    protected $version;
113
+
114
+    /**
115
+     * The {@link Wordlift_Tinymce_Adapter} instance.
116
+     *
117
+     * @since  3.12.0
118
+     * @access protected
119
+     * @var \Wordlift_Tinymce_Adapter $tinymce_adapter The {@link Wordlift_Tinymce_Adapter} instance.
120
+     */
121
+    protected $tinymce_adapter;
122
+
123
+    /**
124
+     * The Schema service.
125
+     *
126
+     * @since  3.3.0
127
+     * @access protected
128
+     * @var \Wordlift_Schema_Service $schema_service The Schema service.
129
+     */
130
+    protected $schema_service;
131
+
132
+    /**
133
+     * The Topic Taxonomy service.
134
+     *
135
+     * @since  3.5.0
136
+     * @access private
137
+     * @var \Wordlift_Topic_Taxonomy_Service The Topic Taxonomy service.
138
+     */
139
+    private $topic_taxonomy_service;
140
+
141
+    /**
142
+     * The Entity Types Taxonomy service.
143
+     *
144
+     * @since  3.18.0
145
+     * @access private
146
+     * @var \Wordlift_Entity_Type_Taxonomy_Service The Entity Types Taxonomy service.
147
+     */
148
+    private $entity_types_taxonomy_service;
149
+
150
+    /**
151
+     * The User service.
152
+     *
153
+     * @since  3.1.7
154
+     * @access protected
155
+     * @var \Wordlift_User_Service $user_service The User service.
156
+     */
157
+    protected $user_service;
158
+
159
+    /**
160
+     * The Timeline service.
161
+     *
162
+     * @since  3.1.0
163
+     * @access private
164
+     * @var \Wordlift_Timeline_Service $timeline_service The Timeline service.
165
+     */
166
+    private $timeline_service;
167
+
168
+    /**
169
+     * The Redirect service.
170
+     *
171
+     * @since  3.2.0
172
+     * @access private
173
+     * @var \Wordlift_Redirect_Service $redirect_service The Redirect service.
174
+     */
175
+    private $redirect_service;
176
+
177
+    /**
178
+     * The Notice service.
179
+     *
180
+     * @since  3.3.0
181
+     * @access private
182
+     * @var \Wordlift_Notice_Service $notice_service The Notice service.
183
+     */
184
+    private $notice_service;
185
+
186
+    /**
187
+     * The Entity list customization.
188
+     *
189
+     * @since  3.3.0
190
+     * @access protected
191
+     * @var \Wordlift_Entity_List_Service $entity_list_service The Entity list service.
192
+     */
193
+    protected $entity_list_service;
194
+
195
+    /**
196
+     * The Entity Types Taxonomy Walker.
197
+     *
198
+     * @since  3.1.0
199
+     * @access private
200
+     * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker
201
+     */
202
+    private $entity_types_taxonomy_walker;
203
+
204
+    /**
205
+     * The ShareThis service.
206
+     *
207
+     * @since  3.2.0
208
+     * @access private
209
+     * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service.
210
+     */
211
+    private $sharethis_service;
212
+
213
+    /**
214
+     * The PrimaShop adapter.
215
+     *
216
+     * @since  3.2.3
217
+     * @access private
218
+     * @var \Wordlift_PrimaShop_Adapter $primashop_adapter The PrimaShop adapter.
219
+     */
220
+    private $primashop_adapter;
221
+
222
+    /**
223
+     * The entity type service.
224
+     *
225
+     * @since  3.6.0
226
+     * @access private
227
+     * @var \Wordlift_Entity_Post_Type_Service
228
+     */
229
+    private $entity_post_type_service;
230
+
231
+    /**
232
+     * The entity link service used to mangle links to entities with a custom slug or even w/o a slug.
233
+     *
234
+     * @since  3.6.0
235
+     * @access private
236
+     * @var \Wordlift_Entity_Link_Service $entity_link_service The {@link Wordlift_Entity_Link_Service} instance.
237
+     */
238
+    private $entity_link_service;
239
+
240
+    /**
241
+     * A {@link Wordlift_Jsonld_Service} instance.
242
+     *
243
+     * @since  3.7.0
244
+     * @access protected
245
+     * @var \Wordlift_Jsonld_Service $jsonld_service A {@link Wordlift_Jsonld_Service} instance.
246
+     */
247
+    protected $jsonld_service;
248
+
249
+    /**
250
+     * A {@link Wordlift_Website_Jsonld_Converter} instance.
251
+     *
252
+     * @since  3.14.0
253
+     * @access protected
254
+     * @var \Wordlift_Website_Jsonld_Converter $jsonld_website_converter A {@link Wordlift_Website_Jsonld_Converter} instance.
255
+     */
256
+    protected $jsonld_website_converter;
257
+
258
+    /**
259
+     * A {@link Wordlift_Property_Factory} instance.
260
+     *
261
+     * @since  3.7.0
262
+     * @access private
263
+     * @var \Wordlift_Property_Factory $property_factory
264
+     */
265
+    private $property_factory;
266
+
267
+    /**
268
+     * The 'Download Your Data' page.
269
+     *
270
+     * @since  3.6.0
271
+     * @access private
272
+     * @var \Wordlift_Admin_Download_Your_Data_Page $download_your_data_page The 'Download Your Data' page.
273
+     */
274
+    private $download_your_data_page;
275
+
276
+    /**
277
+     * The 'WordLift Settings' page.
278
+     *
279
+     * @since  3.11.0
280
+     * @access protected
281
+     * @var \Wordlift_Admin_Settings_Page $settings_page The 'WordLift Settings' page.
282
+     */
283
+    protected $settings_page;
284
+
285
+    /**
286
+     * The install wizard page.
287
+     *
288
+     * @since  3.9.0
289
+     * @access private
290
+     * @var \Wordlift_Admin_Setup $admin_setup The Install wizard.
291
+     */
292
+    public $admin_setup;
293
+
294
+    /**
295
+     * The Content Filter Service hooks up to the 'the_content' filter and provides
296
+     * linking of entities to their pages.
297
+     *
298
+     * @since  3.8.0
299
+     * @access private
300
+     * @var \Wordlift_Content_Filter_Service $content_filter_service A {@link Wordlift_Content_Filter_Service} instance.
301
+     */
302
+    private $content_filter_service;
303
+
304
+    /**
305
+     * The Faq Content filter service
306
+     *
307
+     * @since  3.26.0
308
+     * @access private
309
+     * @var Faq_Content_Filter $faq_content_filter_service A {@link Faq_Content_Filter} instance.
310
+     */
311
+    private $faq_content_filter_service;
312
+
313
+    /**
314
+     * A {@link Wordlift_Key_Validation_Service} instance.
315
+     *
316
+     * @since  3.9.0
317
+     * @access private
318
+     * @var Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance.
319
+     */
320
+    private $key_validation_service;
321
+
322
+    /**
323
+     * A {@link Wordlift_Rating_Service} instance.
324
+     *
325
+     * @since  3.10.0
326
+     * @access private
327
+     * @var \Wordlift_Rating_Service $rating_service A {@link Wordlift_Rating_Service} instance.
328
+     */
329
+    private $rating_service;
330
+
331
+    /**
332
+     * A {@link Wordlift_Post_To_Jsonld_Converter} instance.
333
+     *
334
+     * @since  3.10.0
335
+     * @access protected
336
+     * @var \Wordlift_Post_To_Jsonld_Converter $post_to_jsonld_converter A {@link Wordlift_Post_To_Jsonld_Converter} instance.
337
+     */
338
+    protected $post_to_jsonld_converter;
339
+
340
+    /**
341
+     * A {@link Wordlift_Install_Service} instance.
342
+     *
343
+     * @since  3.18.0
344
+     * @access protected
345
+     * @var \Wordlift_Install_Service $install_service A {@link Wordlift_Install_Service} instance.
346
+     */
347
+    protected $install_service;
348
+
349
+    /**
350
+     * A {@link Wordlift_Entity_Post_To_Jsonld_Converter} instance.
351
+     *
352
+     * @since  3.10.0
353
+     * @access protected
354
+     * @var \Wordlift_Entity_Post_To_Jsonld_Converter $entity_post_to_jsonld_converter A {@link Wordlift_Entity_Post_To_Jsonld_Converter} instance.
355
+     */
356
+    protected $entity_post_to_jsonld_converter;
357
+
358
+    /**
359
+     * A {@link Wordlift_Postid_To_Jsonld_Converter} instance.
360
+     *
361
+     * @since  3.10.0
362
+     * @access protected
363
+     * @var \Wordlift_Postid_To_Jsonld_Converter $postid_to_jsonld_converter A {@link Wordlift_Postid_To_Jsonld_Converter} instance.
364
+     */
365
+    protected $postid_to_jsonld_converter;
366
+
367
+    /**
368
+     * The {@link Wordlift_Category_Taxonomy_Service} instance.
369
+     *
370
+     * @since  3.11.0
371
+     * @access protected
372
+     * @var \Wordlift_Category_Taxonomy_Service $category_taxonomy_service The {@link Wordlift_Category_Taxonomy_Service} instance.
373
+     */
374
+    protected $category_taxonomy_service;
375
+
376
+    /**
377
+     * The {@link Wordlift_Entity_Page_Service} instance.
378
+     *
379
+     * @since  3.11.0
380
+     * @access protected
381
+     * @var \Wordlift_Entity_Page_Service $entity_page_service The {@link Wordlift_Entity_Page_Service} instance.
382
+     */
383
+    protected $entity_page_service;
384
+
385
+    /**
386
+     * The {@link Wordlift_Admin_Settings_Page_Action_Link} class.
387
+     *
388
+     * @since  3.11.0
389
+     * @access protected
390
+     * @var \Wordlift_Admin_Settings_Page_Action_Link $settings_page_action_link The {@link Wordlift_Admin_Settings_Page_Action_Link} class.
391
+     */
392
+    protected $settings_page_action_link;
393
+
394
+    /**
395
+     * The {@link Wordlift_Admin_Settings_Page_Action_Link} class.
396
+     *
397
+     * @since  3.11.0
398
+     * @access protected
399
+     * @var \Wordlift_Admin_Settings_Page_Action_Link $settings_page_action_link The {@link Wordlift_Admin_Settings_Page_Action_Link} class.
400
+     */
401
+    protected $analytics_settings_page_action_link;
402
+
403
+    /**
404
+     * The {@link Wordlift_Analytics_Connect} class.
405
+     *
406
+     * @since  3.11.0
407
+     * @access protected
408
+     * @var \Wordlift_Analytics_Connect $analytics_connect The {@link Wordlift_Analytics_Connect} class.
409
+     */
410
+    protected $analytics_connect;
411
+
412
+    /**
413
+     * The {@link Wordlift_Publisher_Ajax_Adapter} instance.
414
+     *
415
+     * @since  3.11.0
416
+     * @access protected
417
+     * @var \Wordlift_Publisher_Ajax_Adapter $publisher_ajax_adapter The {@link Wordlift_Publisher_Ajax_Adapter} instance.
418
+     */
419
+    protected $publisher_ajax_adapter;
420
+
421
+    /**
422
+     * The {@link Wordlift_Admin_Input_Element} element renderer.
423
+     *
424
+     * @since  3.11.0
425
+     * @access protected
426
+     * @var \Wordlift_Admin_Input_Element $input_element The {@link Wordlift_Admin_Input_Element} element renderer.
427
+     */
428
+    protected $input_element;
429
+
430
+    /**
431
+     * The {@link Wordlift_Admin_Radio_Input_Element} element renderer.
432
+     *
433
+     * @since  3.13.0
434
+     * @access protected
435
+     * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element The {@link Wordlift_Admin_Radio_Input_Element} element renderer.
436
+     */
437
+    protected $radio_input_element;
438
+
439
+    /**
440
+     * The {@link Wordlift_Admin_Language_Select_Element} element renderer.
441
+     *
442
+     * @since  3.11.0
443
+     * @access protected
444
+     * @var \Wordlift_Admin_Language_Select_Element $language_select_element The {@link Wordlift_Admin_Language_Select_Element} element renderer.
445
+     */
446
+    protected $language_select_element;
447
+
448
+    /**
449
+     * The {@link Wordlift_Admin_Country_Select_Element} element renderer.
450
+     *
451
+     * @since  3.18.0
452
+     * @access protected
453
+     * @var \Wordlift_Admin_Country_Select_Element $country_select_element The {@link Wordlift_Admin_Country_Select_Element} element renderer.
454
+     */
455
+    protected $country_select_element;
456
+
457
+    /**
458
+     * The {@link Wordlift_Admin_Publisher_Element} element renderer.
459
+     *
460
+     * @since  3.11.0
461
+     * @access protected
462
+     * @var \Wordlift_Admin_Publisher_Element $publisher_element The {@link Wordlift_Admin_Publisher_Element} element renderer.
463
+     */
464
+    protected $publisher_element;
465
+
466
+    /**
467
+     * The {@link Wordlift_Admin_Select2_Element} element renderer.
468
+     *
469
+     * @since  3.11.0
470
+     * @access protected
471
+     * @var \Wordlift_Admin_Select2_Element $select2_element The {@link Wordlift_Admin_Select2_Element} element renderer.
472
+     */
473
+    protected $select2_element;
474
+
475
+    /**
476
+     * The controller for the entity type list admin page
477
+     *
478
+     * @since  3.11.0
479
+     * @access private
480
+     * @var \Wordlift_Admin_Entity_Taxonomy_List_Page $entity_type_admin_page The {@link Wordlift_Admin_Entity_Taxonomy_List_Page} class.
481
+     */
482
+    private $entity_type_admin_page;
483
+
484
+    /**
485
+     * The controller for the entity type settings admin page
486
+     *
487
+     * @since  3.11.0
488
+     * @access private
489
+     * @var \Wordlift_Admin_Entity_Type_Settings $entity_type_settings_admin_page The {@link Wordlift_Admin_Entity_Type_Settings} class.
490
+     */
491
+    private $entity_type_settings_admin_page;
492
+
493
+    /**
494
+     * The {@link Wordlift_Related_Entities_Cloud_Widget} instance.
495
+     *
496
+     * @since  3.11.0
497
+     * @access protected
498
+     * @var \Wordlift_Related_Entities_Cloud_Widget $related_entities_cloud_widget The {@link Wordlift_Related_Entities_Cloud_Widget} instance.
499
+     */
500
+    protected $related_entities_cloud_widget;
501
+
502
+    /**
503
+     * The {@link Wordlift_Admin_Author_Element} instance.
504
+     *
505
+     * @since  3.14.0
506
+     * @access protected
507
+     * @var \Wordlift_Admin_Author_Element $author_element The {@link Wordlift_Admin_Author_Element} instance.
508
+     */
509
+    protected $author_element;
510
+
511
+    /**
512
+     * The {@link Wordlift_Sample_Data_Service} instance.
513
+     *
514
+     * @since  3.12.0
515
+     * @access protected
516
+     * @var \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance.
517
+     */
518
+    protected $sample_data_service;
519
+
520
+    /**
521
+     * The {@link Wordlift_Sample_Data_Ajax_Adapter} instance.
522
+     *
523
+     * @since  3.12.0
524
+     * @access protected
525
+     * @var \Wordlift_Sample_Data_Ajax_Adapter $sample_data_ajax_adapter The {@link Wordlift_Sample_Data_Ajax_Adapter} instance.
526
+     */
527
+    protected $sample_data_ajax_adapter;
528
+
529
+    /**
530
+     * The {@link Wordlift_Google_Analytics_Export_Service} instance.
531
+     *
532
+     * @since  3.16.0
533
+     * @access protected
534
+     * @var \Wordlift_Google_Analytics_Export_Service $google_analytics_export_service The {@link Wordlift_Google_Analytics_Export_Service} instance.
535
+     */
536
+    protected $google_analytics_export_service;
537
+
538
+    /**
539
+     * {@link Wordlift}'s singleton instance.
540
+     *
541
+     * @since  3.15.0
542
+     * @access protected
543
+     * @var \Wordlift_Entity_Type_Adapter $entity_type_adapter The {@link Wordlift_Entity_Type_Adapter} instance.
544
+     */
545
+    protected $entity_type_adapter;
546
+
547
+    /**
548
+     * The {@link Wordlift_Storage_Factory} instance.
549
+     *
550
+     * @since  3.15.0
551
+     * @access protected
552
+     * @var \Wordlift_Storage_Factory $storage_factory The {@link Wordlift_Storage_Factory} instance.
553
+     */
554
+    protected $storage_factory;
555
+
556
+    /**
557
+     * The {@link Wordlift_Autocomplete_Adapter} instance.
558
+     *
559
+     * @since  3.15.0
560
+     * @access private
561
+     * @var \Wordlift_Autocomplete_Adapter $autocomplete_adapter The {@link Wordlift_Autocomplete_Adapter} instance.
562
+     */
563
+    private $autocomplete_adapter;
564
+
565
+    /**
566
+     * The {@link Wordlift_Cached_Post_Converter} instance.
567
+     *
568
+     * @since  3.16.0
569
+     * @access protected
570
+     * @var  \Wordlift_Cached_Post_Converter $cached_postid_to_jsonld_converter The {@link Wordlift_Cached_Post_Converter} instance.
571
+     */
572
+    protected $cached_postid_to_jsonld_converter;
573
+
574
+    /**
575
+     * The {@link Wordlift_Entity_Uri_Service} instance.
576
+     *
577
+     * @since  3.16.3
578
+     * @access protected
579
+     * @var \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance.
580
+     */
581
+    protected $entity_uri_service;
582
+
583
+    /**
584
+     * The {@link Wordlift_Publisher_Service} instance.
585
+     *
586
+     * @since  3.19.0
587
+     * @access protected
588
+     * @var \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
589
+     */
590
+    protected $publisher_service;
591
+
592
+    /**
593
+     * The {@link Wordlift_Context_Cards_Service} instance.
594
+     *
595
+     * @var \Wordlift_Context_Cards_Service The {@link Wordlift_Context_Cards_Service} instance.
596
+     */
597
+    protected $context_cards_service;
598
+
599
+    /**
600
+     * {@link Wordlift}'s singleton instance.
601
+     *
602
+     * @since  3.11.2
603
+     * @access private
604
+     * @var Wordlift $instance {@link Wordlift}'s singleton instance.
605
+     */
606
+    private static $instance;
607
+
608
+    /**
609
+     * A singleton instance of features registry.
610
+     *
611
+     * @since 3.30.0
612
+     * @var Features_Registry
613
+     */
614
+    private $features_registry;
615
+
616
+    private $analytics_settings_page;
617
+
618
+    private $webhook_loader;
619
+
620
+    /**
621
+     * Define the core functionality of the plugin.
622
+     *
623
+     * Set the plugin name and the plugin version that can be used throughout the plugin.
624
+     * Load the dependencies, define the locale, and set the hooks for the admin area and
625
+     * the public-facing side of the site.
626
+     *
627
+     * @since    1.0.0
628
+     */
629
+    public function __construct() {
630
+
631
+        self::$instance = $this;
632
+
633
+        $this->plugin_name = 'wordlift';
634
+        $this->version     = WORDLIFT_VERSION;
635
+        $this->load_dependencies();
636
+        $this->set_locale();
637
+
638
+        $that = $this;
639
+        add_action(
640
+            'plugins_loaded',
641
+            function () use ( $that ) {
642
+                $that->define_admin_hooks( $that );
643
+                $that->define_public_hooks( $that );
644
+            },
645
+            4
646
+        );
647
+
648
+        // If we're in `WP_CLI` load the related files.
649
+        if ( class_exists( 'WP_CLI' ) ) {
650
+            $this->load_cli_dependencies();
651
+        }
652
+
653
+    }
654
+
655
+    /**
656
+     * Get the singleton instance.
657
+     *
658
+     * @return Wordlift The {@link Wordlift} singleton instance.
659
+     * @since 3.11.2
660
+     */
661
+    public static function get_instance() {
662
+
663
+        return self::$instance;
664
+    }
665
+
666
+    /**
667
+     * Load the required dependencies for this plugin.
668
+     *
669
+     * Include the following files that make up the plugin:
670
+     *
671
+     * - Wordlift_Loader. Orchestrates the hooks of the plugin.
672
+     * - Wordlift_i18n. Defines internationalization functionality.
673
+     * - Wordlift_Admin. Defines all hooks for the admin area.
674
+     * - Wordlift_Public. Defines all hooks for the public side of the site.
675
+     *
676
+     * Create an instance of the loader which will be used to register the hooks
677
+     * with WordPress.
678
+     *
679
+     * @throws Exception when an error occurs.
680
+     * @since    1.0.0
681
+     * @access   private
682
+     */
683
+    private function load_dependencies() {
684
+
685
+        /**
686
+         * The class responsible for orchestrating the actions and filters of the
687
+         * core plugin.
688
+         */
689
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-loader.php';
690
+
691
+        // The class responsible for plugin uninstall.
692
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-deactivator-feedback.php';
693
+
694
+        /**
695
+         * The class responsible for defining internationalization functionality
696
+         * of the plugin.
697
+         */
698
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-i18n.php';
699
+
700
+        /**
701
+         * WordLift's supported languages.
702
+         */
703
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-languages.php';
704
+
705
+        /**
706
+         * WordLift's supported countries.
707
+         */
708
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-countries.php';
709
+
710
+        /**
711
+         * Provide support functions to sanitize data.
712
+         */
713
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-sanitizer.php';
714
+
715
+        /** Services. */
716
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-log-service.php';
717
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-http-api.php';
718
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-redirect-service.php';
719
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-configuration-service.php';
720
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-post-type-service.php';
721
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-type-service.php';
722
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-link-service.php';
723
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-relation-service.php';
724
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-image-service.php';
725
+
726
+        /**
727
+         * The Schema service.
728
+         */
729
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-schema-service.php';
730
+
731
+        /**
732
+         * The schema:url property service.
733
+         */
734
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-property-service.php';
735
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-schema-url-property-service.php';
736
+
737
+        /**
738
+         * The UI service.
739
+         */
740
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-ui-service.php';
741
+
742
+        /**
743
+         * The Entity Types Taxonomy service.
744
+         */
745
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-type-taxonomy-service.php';
746
+
747
+        /**
748
+         * The Entity service.
749
+         */
750
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-uri-service.php';
751
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-service.php';
752
+
753
+        // Add the entity rating service.
754
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-rating-service.php';
755
+
756
+        /**
757
+         * The User service.
758
+         */
759
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-user-service.php';
760
+
761
+        /**
762
+         * The Timeline service.
763
+         */
764
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-timeline-service.php';
765
+
766
+        /**
767
+         * The Topic Taxonomy service.
768
+         */
769
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-topic-taxonomy-service.php';
770
+
771
+        /**
772
+         * The WordLift URI service.
773
+         */
774
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-uri-service.php';
775
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-property-factory.php';
776
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-sample-data-service.php';
777
+
778
+        require_once plugin_dir_path( __DIR__ ) . 'includes/properties/class-wordlift-property-getter-factory.php';
779
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-attachment-service.php';
780
+
781
+        /**
782
+         * Load the converters.
783
+         */
784
+        require_once plugin_dir_path( __DIR__ ) . 'includes/intf-wordlift-post-converter.php';
785
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-abstract-post-to-jsonld-converter.php';
786
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-postid-to-jsonld-converter.php';
787
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-post-to-jsonld-converter.php';
788
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-post-to-jsonld-converter.php';
789
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-website-jsonld-converter.php';
790
+
791
+        /**
792
+         * Load cache-related files.
793
+         */
794
+        require_once plugin_dir_path( __DIR__ ) . 'includes/cache/require.php';
795
+
796
+        /**
797
+         * Load the content filter.
798
+         */
799
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-content-filter-service.php';
800
+
801
+        /*
802 802
 		 * Load the excerpt helper.
803 803
 		 */
804
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-post-excerpt-helper.php';
805
-
806
-		/**
807
-		 * Load the JSON-LD service to publish entities using JSON-LD.s
808
-		 *
809
-		 * @since 3.8.0
810
-		 */
811
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-jsonld-service.php';
812
-
813
-		// The Publisher Service and the AJAX adapter.
814
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-publisher-service.php';
815
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-publisher-ajax-adapter.php';
816
-
817
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-post-adapter.php';
818
-
819
-		/**
820
-		 * Load the WordLift key validation service.
821
-		 */
822
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-key-validation-service.php';
823
-
824
-		// Load the `Wordlift_Category_Taxonomy_Service` class definition.
825
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-category-taxonomy-service.php';
826
-
827
-		// Load the `Wordlift_Entity_Page_Service` class definition.
828
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-page-service.php';
829
-
830
-		/** Linked Data. */
831
-		require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-storage.php';
832
-		require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-meta-storage.php';
833
-		require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-property-storage.php';
834
-		require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-taxonomy-storage.php';
835
-		require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-schema-class-storage.php';
836
-		require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-author-storage.php';
837
-		require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-meta-uri-storage.php';
838
-		require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-image-storage.php';
839
-		require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-related-storage.php';
840
-		require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-url-property-storage.php';
841
-		require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-storage-factory.php';
842
-
843
-		/** Services. */
844
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-google-analytics-export-service.php';
845
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-api-service.php';
846
-
847
-		/** Adapters. */
848
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-tinymce-adapter.php';
849
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-newrelic-adapter.php';
850
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-sample-data-ajax-adapter.php';
851
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-type-adapter.php';
852
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-wprocket-adapter.php';
853
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-nitropack-adapter.php';
854
-
855
-		/** Autocomplete. */
856
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-autocomplete-adapter.php';
857
-
858
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-remote-image-service.php';
859
-
860
-		/** Analytics */
861
-		require_once plugin_dir_path( __DIR__ ) . 'includes/analytics/class-wordlift-analytics-connect.php';
862
-
863
-		/**
864
-		 * The class responsible for defining all actions that occur in the admin area.
865
-		 */
866
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin.php';
867
-
868
-		/**
869
-		 * The class to customize the entity list admin page.
870
-		 */
871
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-entity-list-service.php';
872
-
873
-		/**
874
-		 * The Entity Types Taxonomy Walker (transforms checkboxes into radios).
875
-		 */
876
-		global $wp_version;
877
-		if ( version_compare( $wp_version, '5.3', '<' ) ) {
878
-			require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php';
879
-		} else {
880
-			require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-entity-types-taxonomy-walker-5-3.php';
881
-		}
882
-
883
-		/**
884
-		 * The Notice service.
885
-		 */
886
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-notice-service.php';
887
-
888
-		/**
889
-		 * The PrimaShop adapter.
890
-		 */
891
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-primashop-adapter.php';
892
-
893
-		/**
894
-		 * The WordLift Dashboard service.
895
-		 */
896
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-dashboard-service.php';
897
-
898
-		/**
899
-		 * The admin 'Install wizard' page.
900
-		 */
901
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-setup.php';
902
-
903
-		/**
904
-		 * The WordLift entity type list admin page controller.
905
-		 */
906
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-entity-taxonomy-list-page.php';
907
-
908
-		/**
909
-		 * The WordLift entity type settings admin page controller.
910
-		 */
911
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-entity-type-settings.php';
912
-
913
-		/**
914
-		 * The admin 'Download Your Data' page.
915
-		 */
916
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-download-your-data-page.php';
917
-
918
-		/**
919
-		 * The admin 'WordLift Settings' page.
920
-		 */
921
-		require_once plugin_dir_path( __DIR__ ) . 'admin/elements/intf-wordlift-admin-element.php';
922
-		require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-input-element.php';
923
-		require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-radio-input-element.php';
924
-		require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-select-element.php';
925
-		require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-select2-element.php';
926
-		require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-language-select-element.php';
927
-		require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-country-select-element.php';
928
-		require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-tabs-element.php';
929
-		require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-author-element.php';
930
-		require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-publisher-element.php';
931
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-page.php';
932
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-settings-page.php';
933
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-settings-analytics-page.php';
934
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-settings-page-action-link.php';
935
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-settings-analytics-page-action-link.php';
936
-
937
-		/** Admin Pages */
938
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-user-profile-page.php';
939
-		require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-entity-type-admin-service.php';
940
-
941
-		/**
942
-		 * The class responsible for defining all actions that occur in the public-facing
943
-		 * side of the site.
944
-		 */
945
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-public.php';
946
-
947
-		/**
948
-		 * The shortcode abstract class.
949
-		 */
950
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-shortcode.php';
951
-
952
-		/**
953
-		 * The Timeline shortcode.
954
-		 */
955
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-timeline-shortcode.php';
956
-
957
-		/**
958
-		 * The Navigator shortcode.
959
-		 */
960
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-navigator-shortcode.php';
961
-
962
-		/**
963
-		 * The Products Navigator shortcode.
964
-		 */
965
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-products-navigator-shortcode.php';
966
-
967
-		/**
968
-		 * The chord shortcode.
969
-		 */
970
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-chord-shortcode.php';
971
-
972
-		/**
973
-		 * The geomap shortcode.
974
-		 */
975
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-geomap-shortcode.php';
976
-
977
-		/**
978
-		 * The entity cloud shortcode.
979
-		 */
980
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-related-entities-cloud-shortcode.php';
981
-
982
-		/**
983
-		 * The entity glossary shortcode.
984
-		 */
985
-		require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-alphabet-service.php';
986
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-vocabulary-shortcode.php';
987
-
988
-		/**
989
-		 * Faceted Search shortcode.
990
-		 */
991
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-faceted-search-shortcode.php';
992
-
993
-		/**
994
-		 * The ShareThis service.
995
-		 */
996
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-sharethis-service.php';
997
-
998
-		/**
999
-		 * The SEO service.
1000
-		 */
1001
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-seo-service.php';
1002
-
1003
-		/**
1004
-		 * The AMP service.
1005
-		 */
1006
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-amp-service.php';
1007
-
1008
-		/** Widgets */
1009
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-widget.php';
1010
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-related-entities-cloud-widget.php';
1011
-		require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-context-cards-service.php';
1012
-
1013
-		/*
804
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-post-excerpt-helper.php';
805
+
806
+        /**
807
+         * Load the JSON-LD service to publish entities using JSON-LD.s
808
+         *
809
+         * @since 3.8.0
810
+         */
811
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-jsonld-service.php';
812
+
813
+        // The Publisher Service and the AJAX adapter.
814
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-publisher-service.php';
815
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-publisher-ajax-adapter.php';
816
+
817
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-post-adapter.php';
818
+
819
+        /**
820
+         * Load the WordLift key validation service.
821
+         */
822
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-key-validation-service.php';
823
+
824
+        // Load the `Wordlift_Category_Taxonomy_Service` class definition.
825
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-category-taxonomy-service.php';
826
+
827
+        // Load the `Wordlift_Entity_Page_Service` class definition.
828
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-page-service.php';
829
+
830
+        /** Linked Data. */
831
+        require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-storage.php';
832
+        require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-meta-storage.php';
833
+        require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-property-storage.php';
834
+        require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-taxonomy-storage.php';
835
+        require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-schema-class-storage.php';
836
+        require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-author-storage.php';
837
+        require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-meta-uri-storage.php';
838
+        require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-image-storage.php';
839
+        require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-post-related-storage.php';
840
+        require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-url-property-storage.php';
841
+        require_once plugin_dir_path( __DIR__ ) . 'includes/linked-data/storage/class-wordlift-storage-factory.php';
842
+
843
+        /** Services. */
844
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-google-analytics-export-service.php';
845
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-api-service.php';
846
+
847
+        /** Adapters. */
848
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-tinymce-adapter.php';
849
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-newrelic-adapter.php';
850
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-sample-data-ajax-adapter.php';
851
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-type-adapter.php';
852
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-wprocket-adapter.php';
853
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-nitropack-adapter.php';
854
+
855
+        /** Autocomplete. */
856
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-autocomplete-adapter.php';
857
+
858
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-remote-image-service.php';
859
+
860
+        /** Analytics */
861
+        require_once plugin_dir_path( __DIR__ ) . 'includes/analytics/class-wordlift-analytics-connect.php';
862
+
863
+        /**
864
+         * The class responsible for defining all actions that occur in the admin area.
865
+         */
866
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin.php';
867
+
868
+        /**
869
+         * The class to customize the entity list admin page.
870
+         */
871
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-entity-list-service.php';
872
+
873
+        /**
874
+         * The Entity Types Taxonomy Walker (transforms checkboxes into radios).
875
+         */
876
+        global $wp_version;
877
+        if ( version_compare( $wp_version, '5.3', '<' ) ) {
878
+            require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php';
879
+        } else {
880
+            require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-entity-types-taxonomy-walker-5-3.php';
881
+        }
882
+
883
+        /**
884
+         * The Notice service.
885
+         */
886
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-notice-service.php';
887
+
888
+        /**
889
+         * The PrimaShop adapter.
890
+         */
891
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-primashop-adapter.php';
892
+
893
+        /**
894
+         * The WordLift Dashboard service.
895
+         */
896
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-dashboard-service.php';
897
+
898
+        /**
899
+         * The admin 'Install wizard' page.
900
+         */
901
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-setup.php';
902
+
903
+        /**
904
+         * The WordLift entity type list admin page controller.
905
+         */
906
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-entity-taxonomy-list-page.php';
907
+
908
+        /**
909
+         * The WordLift entity type settings admin page controller.
910
+         */
911
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-entity-type-settings.php';
912
+
913
+        /**
914
+         * The admin 'Download Your Data' page.
915
+         */
916
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-download-your-data-page.php';
917
+
918
+        /**
919
+         * The admin 'WordLift Settings' page.
920
+         */
921
+        require_once plugin_dir_path( __DIR__ ) . 'admin/elements/intf-wordlift-admin-element.php';
922
+        require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-input-element.php';
923
+        require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-radio-input-element.php';
924
+        require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-select-element.php';
925
+        require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-select2-element.php';
926
+        require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-language-select-element.php';
927
+        require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-country-select-element.php';
928
+        require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-tabs-element.php';
929
+        require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-author-element.php';
930
+        require_once plugin_dir_path( __DIR__ ) . 'admin/elements/class-wordlift-admin-publisher-element.php';
931
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-page.php';
932
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-settings-page.php';
933
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-settings-analytics-page.php';
934
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-settings-page-action-link.php';
935
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-settings-analytics-page-action-link.php';
936
+
937
+        /** Admin Pages */
938
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-user-profile-page.php';
939
+        require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-entity-type-admin-service.php';
940
+
941
+        /**
942
+         * The class responsible for defining all actions that occur in the public-facing
943
+         * side of the site.
944
+         */
945
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-public.php';
946
+
947
+        /**
948
+         * The shortcode abstract class.
949
+         */
950
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-shortcode.php';
951
+
952
+        /**
953
+         * The Timeline shortcode.
954
+         */
955
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-timeline-shortcode.php';
956
+
957
+        /**
958
+         * The Navigator shortcode.
959
+         */
960
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-navigator-shortcode.php';
961
+
962
+        /**
963
+         * The Products Navigator shortcode.
964
+         */
965
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-products-navigator-shortcode.php';
966
+
967
+        /**
968
+         * The chord shortcode.
969
+         */
970
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-chord-shortcode.php';
971
+
972
+        /**
973
+         * The geomap shortcode.
974
+         */
975
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-geomap-shortcode.php';
976
+
977
+        /**
978
+         * The entity cloud shortcode.
979
+         */
980
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-related-entities-cloud-shortcode.php';
981
+
982
+        /**
983
+         * The entity glossary shortcode.
984
+         */
985
+        require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-alphabet-service.php';
986
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-vocabulary-shortcode.php';
987
+
988
+        /**
989
+         * Faceted Search shortcode.
990
+         */
991
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-faceted-search-shortcode.php';
992
+
993
+        /**
994
+         * The ShareThis service.
995
+         */
996
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-sharethis-service.php';
997
+
998
+        /**
999
+         * The SEO service.
1000
+         */
1001
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-seo-service.php';
1002
+
1003
+        /**
1004
+         * The AMP service.
1005
+         */
1006
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-amp-service.php';
1007
+
1008
+        /** Widgets */
1009
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-widget.php';
1010
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-related-entities-cloud-widget.php';
1011
+        require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-context-cards-service.php';
1012
+
1013
+        /*
1014 1014
 		 * Batch Operations. They're similar to Batch Actions but do not require working on post types.
1015 1015
 		 *
1016 1016
 		 * Eventually Batch Actions will become Batch Operations.
1017 1017
 		 *
1018 1018
 		 * @since 3.20.0
1019 1019
 		 */
1020
-		require_once plugin_dir_path( __DIR__ ) . 'includes/batch/intf-wordlift-batch-operation.php';
1021
-		require_once plugin_dir_path( __DIR__ ) . 'includes/batch/class-wordlift-batch-operation-ajax-adapter.php';
1020
+        require_once plugin_dir_path( __DIR__ ) . 'includes/batch/intf-wordlift-batch-operation.php';
1021
+        require_once plugin_dir_path( __DIR__ ) . 'includes/batch/class-wordlift-batch-operation-ajax-adapter.php';
1022 1022
 
1023
-		/*
1023
+        /*
1024 1024
 		 * Schema.org Services.
1025 1025
 		 *
1026 1026
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/835
1027 1027
 		 */
1028
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1029
-		if ( apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES ) ) {
1030
-			require_once plugin_dir_path( __DIR__ ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-service.php';
1031
-			require_once plugin_dir_path( __DIR__ ) . 'includes/schemaorg/class-wordlift-schemaorg-property-service.php';
1032
-			require_once plugin_dir_path( __DIR__ ) . 'includes/schemaorg/class-wordlift-schemaorg-class-service.php';
1033
-			new Wordlift_Schemaorg_Sync_Service();
1034
-			$schemaorg_property_service = Wordlift_Schemaorg_Property_Service::get_instance();
1035
-			new Wordlift_Schemaorg_Class_Service();
1036
-		} else {
1037
-			$schemaorg_property_service = null;
1038
-		}
1039
-
1040
-		$this->loader = new Wordlift_Loader();
1041
-		/**
1042
-		 * @since 3.30.0
1043
-		 */
1044
-		$this->features_registry = Features_Registry::get_instance();
1045
-
1046
-		// Instantiate a global logger.
1047
-		global $wl_logger;
1048
-		$wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' );
1049
-
1050
-		// Load the `wl-api` end-point.
1051
-		new Wordlift_Http_Api();
1052
-
1053
-		// Load the Install Service.
1054
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-service.php';
1055
-		$this->install_service = new Wordlift_Install_Service();
1056
-		$this->notice_service  = new Wordlift_Notice_Service();
1057
-		$this->user_service    = Wordlift_User_Service::get_instance();
1058
-		// create an instance of the entity type list admin page controller.
1059
-		$this->entity_type_admin_page        = new Wordlift_Admin_Entity_Taxonomy_List_Page();
1060
-		$this->topic_taxonomy_service        = new Wordlift_Topic_Taxonomy_Service();
1061
-		$this->entity_types_taxonomy_service = new Wordlift_Entity_Type_Taxonomy_Service();
1062
-		// Create an entity type service instance. It'll be later bound to the init action.
1063
-		$this->entity_post_type_service = new Wordlift_Entity_Post_Type_Service(
1064
-			Wordlift_Entity_Service::TYPE_NAME,
1065
-			Wordlift_Configuration_Service::get_instance()->get_entity_base_path()
1066
-		);
1067
-		/* WordPress Admin. */
1068
-		$this->download_your_data_page = new Wordlift_Admin_Download_Your_Data_Page();
1069
-		// create an instance of the entity type setting admin page controller.
1070
-		$this->entity_type_settings_admin_page = new Wordlift_Admin_Entity_Type_Settings();
1071
-
1072
-		$that = $this;
1073
-		add_action(
1074
-			'plugins_loaded',
1075
-			// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
1076
-			function () use ( &$that, $schemaorg_property_service ) {
1077
-
1078
-				/** Services. */
1079
-				// Create the configuration service.
1080
-				new Wordlift_Api_Service();
1081
-
1082
-				// Create an entity link service instance. It'll be later bound to the post_type_link and pre_get_posts actions.
1083
-				$that->entity_link_service = new Wordlift_Entity_Link_Service( $that->entity_post_type_service, Wordlift_Configuration_Service::get_instance()->get_entity_base_path() );
1084
-
1085
-				$schema_url_property_service = new Wordlift_Schema_Url_Property_Service();
1086
-
1087
-				$that->entity_uri_service = Wordlift_Entity_Uri_Service::get_instance();
1088
-
1089
-				// Create a new instance of the Redirect service.
1090
-				$that->redirect_service = new Wordlift_Redirect_Service( $that->entity_uri_service );
1091
-
1092
-				// Create a new instance of the Timeline service and Timeline shortcode.
1093
-				$that->timeline_service = new Wordlift_Timeline_Service();
1094
-
1095
-				$that->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker();
1096
-
1097
-				// Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters.
1098
-				$that->sharethis_service = new Wordlift_ShareThis_Service();
1099
-
1100
-				// Create an instance of the PrimaShop adapter.
1101
-				$that->primashop_adapter = new Wordlift_PrimaShop_Adapter();
1102
-
1103
-				$uri_service = new Wordlift_Uri_Service( $GLOBALS['wpdb'] );
1104
-
1105
-				// Create the entity rating service.
1106
-				$that->rating_service = Wordlift_Rating_Service::get_instance();
1107
-
1108
-				// Create entity list customization (wp-admin/edit.php).
1109
-				$that->entity_list_service = new Wordlift_Entity_List_Service( $that->rating_service );
1110
-
1111
-				// Create an instance of the Publisher Service and the AJAX Adapter.
1112
-				$that->publisher_service = Wordlift_Publisher_Service::get_instance();
1113
-				$that->property_factory  = new Wordlift_Property_Factory( $schema_url_property_service );
1114
-				$that->property_factory->register( Wordlift_Schema_Url_Property_Service::META_KEY, $schema_url_property_service );
1115
-
1116
-				$attachment_service = Wordlift_Attachment_Service::get_instance();
1117
-
1118
-				// Instantiate the JSON-LD service.
1119
-				$property_getter                       = Wordlift_Property_Getter_Factory::create();
1120
-				$that->post_to_jsonld_converter        = new Wordlift_Post_To_Jsonld_Converter( Wordlift_Entity_Type_Service::get_instance(), $that->user_service, $attachment_service );
1121
-				$that->entity_post_to_jsonld_converter = new Wordlift_Entity_Post_To_Jsonld_Converter( Wordlift_Entity_Type_Service::get_instance(), $that->user_service, $attachment_service, $property_getter, $schemaorg_property_service, $that->post_to_jsonld_converter );
1122
-				$that->postid_to_jsonld_converter      = new Wordlift_Postid_To_Jsonld_Converter( $that->entity_post_to_jsonld_converter, $that->post_to_jsonld_converter );
1123
-				$that->jsonld_website_converter        = new Wordlift_Website_Jsonld_Converter( Wordlift_Entity_Type_Service::get_instance(), $that->user_service, $attachment_service );
1124
-
1125
-				$jsonld_cache                            = new Ttl_Cache( 'jsonld', 86400 );
1126
-				$that->cached_postid_to_jsonld_converter = new Wordlift_Cached_Post_Converter( $that->postid_to_jsonld_converter, $jsonld_cache );
1127
-				/*
1028
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1029
+        if ( apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES ) ) {
1030
+            require_once plugin_dir_path( __DIR__ ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-service.php';
1031
+            require_once plugin_dir_path( __DIR__ ) . 'includes/schemaorg/class-wordlift-schemaorg-property-service.php';
1032
+            require_once plugin_dir_path( __DIR__ ) . 'includes/schemaorg/class-wordlift-schemaorg-class-service.php';
1033
+            new Wordlift_Schemaorg_Sync_Service();
1034
+            $schemaorg_property_service = Wordlift_Schemaorg_Property_Service::get_instance();
1035
+            new Wordlift_Schemaorg_Class_Service();
1036
+        } else {
1037
+            $schemaorg_property_service = null;
1038
+        }
1039
+
1040
+        $this->loader = new Wordlift_Loader();
1041
+        /**
1042
+         * @since 3.30.0
1043
+         */
1044
+        $this->features_registry = Features_Registry::get_instance();
1045
+
1046
+        // Instantiate a global logger.
1047
+        global $wl_logger;
1048
+        $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' );
1049
+
1050
+        // Load the `wl-api` end-point.
1051
+        new Wordlift_Http_Api();
1052
+
1053
+        // Load the Install Service.
1054
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-service.php';
1055
+        $this->install_service = new Wordlift_Install_Service();
1056
+        $this->notice_service  = new Wordlift_Notice_Service();
1057
+        $this->user_service    = Wordlift_User_Service::get_instance();
1058
+        // create an instance of the entity type list admin page controller.
1059
+        $this->entity_type_admin_page        = new Wordlift_Admin_Entity_Taxonomy_List_Page();
1060
+        $this->topic_taxonomy_service        = new Wordlift_Topic_Taxonomy_Service();
1061
+        $this->entity_types_taxonomy_service = new Wordlift_Entity_Type_Taxonomy_Service();
1062
+        // Create an entity type service instance. It'll be later bound to the init action.
1063
+        $this->entity_post_type_service = new Wordlift_Entity_Post_Type_Service(
1064
+            Wordlift_Entity_Service::TYPE_NAME,
1065
+            Wordlift_Configuration_Service::get_instance()->get_entity_base_path()
1066
+        );
1067
+        /* WordPress Admin. */
1068
+        $this->download_your_data_page = new Wordlift_Admin_Download_Your_Data_Page();
1069
+        // create an instance of the entity type setting admin page controller.
1070
+        $this->entity_type_settings_admin_page = new Wordlift_Admin_Entity_Type_Settings();
1071
+
1072
+        $that = $this;
1073
+        add_action(
1074
+            'plugins_loaded',
1075
+            // phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
1076
+            function () use ( &$that, $schemaorg_property_service ) {
1077
+
1078
+                /** Services. */
1079
+                // Create the configuration service.
1080
+                new Wordlift_Api_Service();
1081
+
1082
+                // Create an entity link service instance. It'll be later bound to the post_type_link and pre_get_posts actions.
1083
+                $that->entity_link_service = new Wordlift_Entity_Link_Service( $that->entity_post_type_service, Wordlift_Configuration_Service::get_instance()->get_entity_base_path() );
1084
+
1085
+                $schema_url_property_service = new Wordlift_Schema_Url_Property_Service();
1086
+
1087
+                $that->entity_uri_service = Wordlift_Entity_Uri_Service::get_instance();
1088
+
1089
+                // Create a new instance of the Redirect service.
1090
+                $that->redirect_service = new Wordlift_Redirect_Service( $that->entity_uri_service );
1091
+
1092
+                // Create a new instance of the Timeline service and Timeline shortcode.
1093
+                $that->timeline_service = new Wordlift_Timeline_Service();
1094
+
1095
+                $that->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker();
1096
+
1097
+                // Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters.
1098
+                $that->sharethis_service = new Wordlift_ShareThis_Service();
1099
+
1100
+                // Create an instance of the PrimaShop adapter.
1101
+                $that->primashop_adapter = new Wordlift_PrimaShop_Adapter();
1102
+
1103
+                $uri_service = new Wordlift_Uri_Service( $GLOBALS['wpdb'] );
1104
+
1105
+                // Create the entity rating service.
1106
+                $that->rating_service = Wordlift_Rating_Service::get_instance();
1107
+
1108
+                // Create entity list customization (wp-admin/edit.php).
1109
+                $that->entity_list_service = new Wordlift_Entity_List_Service( $that->rating_service );
1110
+
1111
+                // Create an instance of the Publisher Service and the AJAX Adapter.
1112
+                $that->publisher_service = Wordlift_Publisher_Service::get_instance();
1113
+                $that->property_factory  = new Wordlift_Property_Factory( $schema_url_property_service );
1114
+                $that->property_factory->register( Wordlift_Schema_Url_Property_Service::META_KEY, $schema_url_property_service );
1115
+
1116
+                $attachment_service = Wordlift_Attachment_Service::get_instance();
1117
+
1118
+                // Instantiate the JSON-LD service.
1119
+                $property_getter                       = Wordlift_Property_Getter_Factory::create();
1120
+                $that->post_to_jsonld_converter        = new Wordlift_Post_To_Jsonld_Converter( Wordlift_Entity_Type_Service::get_instance(), $that->user_service, $attachment_service );
1121
+                $that->entity_post_to_jsonld_converter = new Wordlift_Entity_Post_To_Jsonld_Converter( Wordlift_Entity_Type_Service::get_instance(), $that->user_service, $attachment_service, $property_getter, $schemaorg_property_service, $that->post_to_jsonld_converter );
1122
+                $that->postid_to_jsonld_converter      = new Wordlift_Postid_To_Jsonld_Converter( $that->entity_post_to_jsonld_converter, $that->post_to_jsonld_converter );
1123
+                $that->jsonld_website_converter        = new Wordlift_Website_Jsonld_Converter( Wordlift_Entity_Type_Service::get_instance(), $that->user_service, $attachment_service );
1124
+
1125
+                $jsonld_cache                            = new Ttl_Cache( 'jsonld', 86400 );
1126
+                $that->cached_postid_to_jsonld_converter = new Wordlift_Cached_Post_Converter( $that->postid_to_jsonld_converter, $jsonld_cache );
1127
+                /*
1128 1128
 				* Load the `Wordlift_Term_JsonLd_Adapter`.
1129 1129
 				*
1130 1130
 				* @see https://github.com/insideout10/wordlift-plugin/issues/892
1131 1131
 				*
1132 1132
 				* @since 3.20.0
1133 1133
 				*/
1134
-				require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-term-jsonld-adapter.php';
1135
-
1136
-				$term_jsonld_adapter  = new Wordlift_Term_JsonLd_Adapter( $that->entity_uri_service, $that->cached_postid_to_jsonld_converter );
1137
-				$that->jsonld_service = new Wordlift_Jsonld_Service( Wordlift_Entity_Service::get_instance(), $that->cached_postid_to_jsonld_converter, $that->jsonld_website_converter, $term_jsonld_adapter );
1138
-
1139
-				$jsonld_service = new Jsonld_Service(
1140
-					$that->jsonld_service,
1141
-					$term_jsonld_adapter,
1142
-					new Jsonld_User_Service( $that->user_service )
1143
-				);
1144
-				new Jsonld_Endpoint( $jsonld_service, $that->entity_uri_service );
1145
-
1146
-				// Prints the JSON-LD in the head.
1147
-				new Jsonld_Adapter( $that->jsonld_service );
1148
-
1149
-				new Jsonld_By_Id_Endpoint( $that->jsonld_service, $that->entity_uri_service );
1150
-
1151
-				$that->key_validation_service = new Wordlift_Key_Validation_Service();
1152
-
1153
-				$that->content_filter_service = Wordlift_Content_Filter_Service::get_instance();
1154
-				// Creating Faq Content filter service.
1155
-				$that->faq_content_filter_service = new Faq_Content_Filter();
1156
-				$that->sample_data_service        = Wordlift_Sample_Data_Service::get_instance();
1157
-				$that->sample_data_ajax_adapter   = new Wordlift_Sample_Data_Ajax_Adapter( $that->sample_data_service );
1158
-
1159
-				$that->loader->add_action( 'enqueue_block_editor_assets', $that, 'add_wl_enabled_blocks' );
1160
-				$that->loader->add_action( 'admin_enqueue_scripts', $that, 'add_wl_enabled_blocks' );
1161
-
1162
-				/**
1163
-				 * Filter: wl_feature__enable__blocks.
1164
-				 *
1165
-				 * @param bool whether the blocks needed to be registered, defaults to true.
1166
-				 *
1167
-				 * @return bool
1168
-				 * @since 3.27.6
1169
-				 */
1170
-				if ( apply_filters( 'wl_feature__enable__blocks', true ) ) {
1171
-					// Initialize the short-codes.
1172
-					new Async_Template_Decorator( new Wordlift_Navigator_Shortcode() );
1173
-					new Wordlift_Chord_Shortcode();
1174
-					new Wordlift_Geomap_Shortcode();
1175
-					new Wordlift_Timeline_Shortcode();
1176
-					new Wordlift_Related_Entities_Cloud_Shortcode( Wordlift_Relation_Service::get_instance(), Wordlift_Entity_Service::get_instance() );
1177
-					new Wordlift_Vocabulary_Shortcode();
1178
-					new Async_Template_Decorator( new Wordlift_Faceted_Search_Shortcode() );
1179
-				}
1180
-
1181
-				new Wordlift_Products_Navigator_Shortcode();
1182
-
1183
-				// Initialize the Context Cards Service
1184
-				$that->context_cards_service = new Wordlift_Context_Cards_Service();
1185
-
1186
-				// Initialize the SEO service.
1187
-				new Wordlift_Seo_Service();
1188
-
1189
-				// Initialize the AMP service.
1190
-				new Wordlift_AMP_Service( $that->jsonld_service );
1191
-
1192
-				/** Services. */
1193
-				$that->google_analytics_export_service = new Wordlift_Google_Analytics_Export_Service();
1194
-				new Wordlift_Image_Service();
1195
-
1196
-				/** Adapters. */
1197
-				$that->entity_type_adapter    = new Wordlift_Entity_Type_Adapter( Wordlift_Entity_Type_Service::get_instance() );
1198
-				$that->publisher_ajax_adapter = new Wordlift_Publisher_Ajax_Adapter( $that->publisher_service );
1199
-				$that->tinymce_adapter        = new Wordlift_Tinymce_Adapter( $that );
1200
-
1201
-				/*
1134
+                require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-term-jsonld-adapter.php';
1135
+
1136
+                $term_jsonld_adapter  = new Wordlift_Term_JsonLd_Adapter( $that->entity_uri_service, $that->cached_postid_to_jsonld_converter );
1137
+                $that->jsonld_service = new Wordlift_Jsonld_Service( Wordlift_Entity_Service::get_instance(), $that->cached_postid_to_jsonld_converter, $that->jsonld_website_converter, $term_jsonld_adapter );
1138
+
1139
+                $jsonld_service = new Jsonld_Service(
1140
+                    $that->jsonld_service,
1141
+                    $term_jsonld_adapter,
1142
+                    new Jsonld_User_Service( $that->user_service )
1143
+                );
1144
+                new Jsonld_Endpoint( $jsonld_service, $that->entity_uri_service );
1145
+
1146
+                // Prints the JSON-LD in the head.
1147
+                new Jsonld_Adapter( $that->jsonld_service );
1148
+
1149
+                new Jsonld_By_Id_Endpoint( $that->jsonld_service, $that->entity_uri_service );
1150
+
1151
+                $that->key_validation_service = new Wordlift_Key_Validation_Service();
1152
+
1153
+                $that->content_filter_service = Wordlift_Content_Filter_Service::get_instance();
1154
+                // Creating Faq Content filter service.
1155
+                $that->faq_content_filter_service = new Faq_Content_Filter();
1156
+                $that->sample_data_service        = Wordlift_Sample_Data_Service::get_instance();
1157
+                $that->sample_data_ajax_adapter   = new Wordlift_Sample_Data_Ajax_Adapter( $that->sample_data_service );
1158
+
1159
+                $that->loader->add_action( 'enqueue_block_editor_assets', $that, 'add_wl_enabled_blocks' );
1160
+                $that->loader->add_action( 'admin_enqueue_scripts', $that, 'add_wl_enabled_blocks' );
1161
+
1162
+                /**
1163
+                 * Filter: wl_feature__enable__blocks.
1164
+                 *
1165
+                 * @param bool whether the blocks needed to be registered, defaults to true.
1166
+                 *
1167
+                 * @return bool
1168
+                 * @since 3.27.6
1169
+                 */
1170
+                if ( apply_filters( 'wl_feature__enable__blocks', true ) ) {
1171
+                    // Initialize the short-codes.
1172
+                    new Async_Template_Decorator( new Wordlift_Navigator_Shortcode() );
1173
+                    new Wordlift_Chord_Shortcode();
1174
+                    new Wordlift_Geomap_Shortcode();
1175
+                    new Wordlift_Timeline_Shortcode();
1176
+                    new Wordlift_Related_Entities_Cloud_Shortcode( Wordlift_Relation_Service::get_instance(), Wordlift_Entity_Service::get_instance() );
1177
+                    new Wordlift_Vocabulary_Shortcode();
1178
+                    new Async_Template_Decorator( new Wordlift_Faceted_Search_Shortcode() );
1179
+                }
1180
+
1181
+                new Wordlift_Products_Navigator_Shortcode();
1182
+
1183
+                // Initialize the Context Cards Service
1184
+                $that->context_cards_service = new Wordlift_Context_Cards_Service();
1185
+
1186
+                // Initialize the SEO service.
1187
+                new Wordlift_Seo_Service();
1188
+
1189
+                // Initialize the AMP service.
1190
+                new Wordlift_AMP_Service( $that->jsonld_service );
1191
+
1192
+                /** Services. */
1193
+                $that->google_analytics_export_service = new Wordlift_Google_Analytics_Export_Service();
1194
+                new Wordlift_Image_Service();
1195
+
1196
+                /** Adapters. */
1197
+                $that->entity_type_adapter    = new Wordlift_Entity_Type_Adapter( Wordlift_Entity_Type_Service::get_instance() );
1198
+                $that->publisher_ajax_adapter = new Wordlift_Publisher_Ajax_Adapter( $that->publisher_service );
1199
+                $that->tinymce_adapter        = new Wordlift_Tinymce_Adapter( $that );
1200
+
1201
+                /*
1202 1202
 				* Exclude our public js from WP-Rocket.
1203 1203
 				*
1204 1204
 				* @since 3.19.4
1205 1205
 				*
1206 1206
 				* @see https://github.com/insideout10/wordlift-plugin/issues/842.
1207 1207
 				*/
1208
-				new Wordlift_WpRocket_Adapter();
1208
+                new Wordlift_WpRocket_Adapter();
1209 1209
 
1210
-				// Add support for NitroPack compatibility.
1211
-				$nitropack_adapter = new Wordlift_NitroPack_Adapter();
1212
-				$nitropack_adapter->register_hooks();
1210
+                // Add support for NitroPack compatibility.
1211
+                $nitropack_adapter = new Wordlift_NitroPack_Adapter();
1212
+                $nitropack_adapter->register_hooks();
1213 1213
 
1214
-				/** WordPress Admin UI. */
1214
+                /** WordPress Admin UI. */
1215 1215
 
1216
-				// UI elements.
1217
-				$that->input_element           = new Wordlift_Admin_Input_Element();
1218
-				$that->radio_input_element     = new Wordlift_Admin_Radio_Input_Element();
1219
-				$that->select2_element         = new Wordlift_Admin_Select2_Element();
1220
-				$that->language_select_element = new Wordlift_Admin_Language_Select_Element();
1221
-				$that->country_select_element  = new Wordlift_Admin_Country_Select_Element();
1222
-				$tabs_element                  = new Wordlift_Admin_Tabs_Element();
1223
-				$that->publisher_element       = new Wordlift_Admin_Publisher_Element( $that->publisher_service, $tabs_element, $that->select2_element );
1224
-				$that->author_element          = new Wordlift_Admin_Author_Element( $that->publisher_service, $that->select2_element );
1216
+                // UI elements.
1217
+                $that->input_element           = new Wordlift_Admin_Input_Element();
1218
+                $that->radio_input_element     = new Wordlift_Admin_Radio_Input_Element();
1219
+                $that->select2_element         = new Wordlift_Admin_Select2_Element();
1220
+                $that->language_select_element = new Wordlift_Admin_Language_Select_Element();
1221
+                $that->country_select_element  = new Wordlift_Admin_Country_Select_Element();
1222
+                $tabs_element                  = new Wordlift_Admin_Tabs_Element();
1223
+                $that->publisher_element       = new Wordlift_Admin_Publisher_Element( $that->publisher_service, $tabs_element, $that->select2_element );
1224
+                $that->author_element          = new Wordlift_Admin_Author_Element( $that->publisher_service, $that->select2_element );
1225 1225
 
1226
-				$that->settings_page             = Wordlift_Admin_Settings_Page::get_instance();
1227
-				$that->settings_page_action_link = new Wordlift_Admin_Settings_Page_Action_Link( $that->settings_page );
1226
+                $that->settings_page             = Wordlift_Admin_Settings_Page::get_instance();
1227
+                $that->settings_page_action_link = new Wordlift_Admin_Settings_Page_Action_Link( $that->settings_page );
1228 1228
 
1229
-				$that->analytics_settings_page             = new Wordlift_Admin_Settings_Analytics_Page( $that->input_element, $that->radio_input_element );
1230
-				$that->analytics_settings_page_action_link = new Wordlift_Admin_Settings_Analytics_Page_Action_Link( $that->analytics_settings_page );
1231
-				$that->analytics_connect                   = new Wordlift_Analytics_Connect();
1229
+                $that->analytics_settings_page             = new Wordlift_Admin_Settings_Analytics_Page( $that->input_element, $that->radio_input_element );
1230
+                $that->analytics_settings_page_action_link = new Wordlift_Admin_Settings_Analytics_Page_Action_Link( $that->analytics_settings_page );
1231
+                $that->analytics_connect                   = new Wordlift_Analytics_Connect();
1232 1232
 
1233
-				// Pages.
1234
-				/*
1233
+                // Pages.
1234
+                /*
1235 1235
 				* Call the `wl_can_see_classification_box` filter to determine whether we can display the classification box.
1236 1236
 				*
1237 1237
 				* @since 3.20.3
1238 1238
 				*
1239 1239
 				* @see https://github.com/insideout10/wordlift-plugin/issues/914
1240 1240
 				*/
1241
-				if ( apply_filters( 'wl_can_see_classification_box', true ) ) {
1242
-					require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-post-edit-page.php';
1243
-					new Wordlift_Admin_Post_Edit_Page( $that );
1244
-				}
1245
-				new Wordlift_Entity_Type_Admin_Service();
1241
+                if ( apply_filters( 'wl_can_see_classification_box', true ) ) {
1242
+                    require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-post-edit-page.php';
1243
+                    new Wordlift_Admin_Post_Edit_Page( $that );
1244
+                }
1245
+                new Wordlift_Entity_Type_Admin_Service();
1246 1246
 
1247
-				/** Widgets */
1248
-				$that->related_entities_cloud_widget = new Wordlift_Related_Entities_Cloud_Widget();
1247
+                /** Widgets */
1248
+                $that->related_entities_cloud_widget = new Wordlift_Related_Entities_Cloud_Widget();
1249 1249
 
1250
-				// Create an instance of the install wizard.
1251
-				$that->admin_setup = new Wordlift_Admin_Setup( $that->key_validation_service, Wordlift_Entity_Service::get_instance(), $that->language_select_element, $that->country_select_element );
1250
+                // Create an instance of the install wizard.
1251
+                $that->admin_setup = new Wordlift_Admin_Setup( $that->key_validation_service, Wordlift_Entity_Service::get_instance(), $that->language_select_element, $that->country_select_element );
1252 1252
 
1253
-				$that->category_taxonomy_service = new Wordlift_Category_Taxonomy_Service( $that->entity_post_type_service );
1253
+                $that->category_taxonomy_service = new Wordlift_Category_Taxonomy_Service( $that->entity_post_type_service );
1254 1254
 
1255
-				// User Profile.
1256
-				new Wordlift_Admin_User_Profile_Page( $that->author_element, $that->user_service );
1255
+                // User Profile.
1256
+                new Wordlift_Admin_User_Profile_Page( $that->author_element, $that->user_service );
1257 1257
 
1258
-				$that->entity_page_service = new Wordlift_Entity_Page_Service();
1258
+                $that->entity_page_service = new Wordlift_Entity_Page_Service();
1259 1259
 
1260
-				// Load the debug service if WP is in debug mode.
1261
-				if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1262
-					require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-debug-service.php';
1263
-					new Wordlift_Debug_Service( Wordlift_Entity_Service::get_instance(), $uri_service );
1264
-				}
1260
+                // Load the debug service if WP is in debug mode.
1261
+                if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1262
+                    require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-debug-service.php';
1263
+                    new Wordlift_Debug_Service( Wordlift_Entity_Service::get_instance(), $uri_service );
1264
+                }
1265 1265
 
1266
-				// Remote Image Service.
1267
-				new Wordlift_Remote_Image_Service();
1266
+                // Remote Image Service.
1267
+                new Wordlift_Remote_Image_Service();
1268 1268
 
1269
-				/*
1269
+                /*
1270 1270
 				* Provides mappings between post types and entity types.
1271 1271
 				*
1272 1272
 				* @since 3.20.0
1273 1273
 				*
1274 1274
 				* @see https://github.com/insideout10/wordlift-plugin/issues/852.
1275 1275
 				*/
1276
-				require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-batch-action.php';
1277
-				require_once plugin_dir_path( __DIR__ ) . 'includes/mapping/class-wordlift-mapping-service.php';
1278
-				require_once plugin_dir_path( __DIR__ ) . 'includes/mapping/class-wordlift-mapping-ajax-adapter.php';
1276
+                require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-batch-action.php';
1277
+                require_once plugin_dir_path( __DIR__ ) . 'includes/mapping/class-wordlift-mapping-service.php';
1278
+                require_once plugin_dir_path( __DIR__ ) . 'includes/mapping/class-wordlift-mapping-ajax-adapter.php';
1279 1279
 
1280
-				// Create an instance of the Mapping Service and assign it to the Ajax Adapter.
1281
-				new Wordlift_Mapping_Ajax_Adapter( new Wordlift_Mapping_Service( Wordlift_Entity_Type_Service::get_instance() ) );
1280
+                // Create an instance of the Mapping Service and assign it to the Ajax Adapter.
1281
+                new Wordlift_Mapping_Ajax_Adapter( new Wordlift_Mapping_Service( Wordlift_Entity_Type_Service::get_instance() ) );
1282 1282
 
1283
-				/*
1283
+                /*
1284 1284
 				* Load the Mappings JSON-LD post processing.
1285 1285
 				*
1286 1286
 				* @since 3.25.0
1287 1287
 				*/
1288 1288
 
1289
-				$mappings_dbo           = new Mappings_DBO();
1290
-				$default_rule_validator = new Taxonomy_Rule_Validator();
1291
-				new Post_Type_Rule_Validator();
1292
-				// Taxonomy term rule validator for validating rules for term pages.
1293
-				new Taxonomy_Term_Rule_Validator();
1294
-				new Post_Taxonomy_Term_Rule_Validator();
1295
-				$rule_validators_registry = new Rule_Validators_Registry( $default_rule_validator );
1296
-				$rule_groups_validator    = new Rule_Groups_Validator( $rule_validators_registry );
1297
-				$mappings_validator       = new Mappings_Validator( $mappings_dbo, $rule_groups_validator );
1298
-
1299
-				new Url_To_Entity_Transform_Function( $that->entity_uri_service );
1300
-				new Taxonomy_To_Terms_Transform_Function();
1301
-				new Post_Id_To_Entity_Transform_Function();
1302
-				$mappings_transform_functions_registry = new Mappings_Transform_Functions_Registry();
1303
-
1304
-				/**
1305
-				 * @since 3.27.1
1306
-				 * Intiailize the acf group data formatter.
1307
-				 */
1308
-				new Acf_Group_Formatter();
1309
-				new Jsonld_Converter( $mappings_validator, $mappings_transform_functions_registry );
1310
-
1311
-				/**
1312
-				 * @since 3.26.0
1313
-				 * Initialize the Faq JSON LD converter here - disabled.
1314
-				 */
1315
-				// new Faq_To_Jsonld_Converter();
1316
-				/*
1289
+                $mappings_dbo           = new Mappings_DBO();
1290
+                $default_rule_validator = new Taxonomy_Rule_Validator();
1291
+                new Post_Type_Rule_Validator();
1292
+                // Taxonomy term rule validator for validating rules for term pages.
1293
+                new Taxonomy_Term_Rule_Validator();
1294
+                new Post_Taxonomy_Term_Rule_Validator();
1295
+                $rule_validators_registry = new Rule_Validators_Registry( $default_rule_validator );
1296
+                $rule_groups_validator    = new Rule_Groups_Validator( $rule_validators_registry );
1297
+                $mappings_validator       = new Mappings_Validator( $mappings_dbo, $rule_groups_validator );
1298
+
1299
+                new Url_To_Entity_Transform_Function( $that->entity_uri_service );
1300
+                new Taxonomy_To_Terms_Transform_Function();
1301
+                new Post_Id_To_Entity_Transform_Function();
1302
+                $mappings_transform_functions_registry = new Mappings_Transform_Functions_Registry();
1303
+
1304
+                /**
1305
+                 * @since 3.27.1
1306
+                 * Intiailize the acf group data formatter.
1307
+                 */
1308
+                new Acf_Group_Formatter();
1309
+                new Jsonld_Converter( $mappings_validator, $mappings_transform_functions_registry );
1310
+
1311
+                /**
1312
+                 * @since 3.26.0
1313
+                 * Initialize the Faq JSON LD converter here - disabled.
1314
+                 */
1315
+                // new Faq_To_Jsonld_Converter();
1316
+                /*
1317 1317
 				* Use the Templates Ajax Endpoint to load HTML templates for the legacy Angular app via admin-ajax.php
1318 1318
 				* end-point.
1319 1319
 				*
1320 1320
 				* @see https://github.com/insideout10/wordlift-plugin/issues/834
1321 1321
 				* @since 3.24.4
1322 1322
 				*/
1323
-				new Templates_Ajax_Endpoint();
1324
-				// Call this static method to register FAQ routes to rest api - disabled
1325
-				// Faq_Rest_Controller::register_routes();
1326
-
1327
-				$that->storage_factory = new Wordlift_Storage_Factory( Wordlift_Entity_Service::get_instance(), $that->user_service, $property_getter );
1328
-
1329
-				/** WL Autocomplete. */
1330
-				$autocomplete_service       = new All_Autocomplete_Service(
1331
-					array(
1332
-						new Local_Autocomplete_Service(),
1333
-						new Linked_Data_Autocomplete_Service( Entity_Helper::get_instance(), $that->entity_uri_service, Wordlift_Entity_Service::get_instance() ),
1334
-					)
1335
-				);
1336
-				$that->autocomplete_adapter = new Wordlift_Autocomplete_Adapter( $autocomplete_service );
1337
-
1338
-				/**
1339
-				 * @since 3.27.2
1340
-				 * Integrate the recipe maker jsonld & set recipe
1341
-				 * as default entity type to the wprm_recipe CPT.
1342
-				 */
1343
-				new Recipe_Maker_Post_Type_Hook();
1344
-				$recipe_maker_validation_service = new Recipe_Maker_Validation_Service();
1345
-				new Recipe_Maker_Jsonld_Hook( $attachment_service, $recipe_maker_validation_service );
1346
-				new Recipe_Maker_After_Get_Jsonld_Hook( $recipe_maker_validation_service );
1347
-				new Recipe_Maker_Jsonld_Swap( $recipe_maker_validation_service, $that->jsonld_service );
1348
-				new Recipe_Maker_Warning( $recipe_maker_validation_service );
1349
-
1350
-				/**
1351
-				 * Avada Builder compatibility.
1352
-				 *
1353
-				 * @since 3.40.0
1354
-				 */
1355
-				new Avada_Builder_Support();
1356
-
1357
-				new Duplicate_Markup_Remover();
1358
-
1359
-				/**
1360
-				 * @since 3.27.8
1361
-				 * @see https://github.com/insideout10/wordlift-plugin/issues/1248
1362
-				 */
1363
-				new Key_Validation_Notice( $that->key_validation_service, Wordlift_Configuration_Service::get_instance() );
1364
-
1365
-				/**
1366
-				 * @since 3.28.0
1367
-				 * @see https://github.com/insideout10/wordlift-plugin/issues?q=assignee%3Anaveen17797+is%3Aopen
1368
-				 */
1369
-				new Entity_No_Index_Flag();
1370
-
1371
-				/**
1372
-				 * @since 3.29.0
1373
-				 * @see https://github.com/insideout10/wordlift-plugin/issues/1304
1374
-				 */
1375
-				new Entity_Rest_Service( Wordlift_Entity_Type_Service::get_instance() );
1376
-
1377
-				/**
1378
-				 * Expand author in to references.
1379
-				 *
1380
-				 * @since 3.30.0
1381
-				 * @see https://github.com/insideout10/wordlift-plugin/issues/1318
1382
-				 */
1383
-				// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1384
-				if ( apply_filters( 'wl_feature__enable__article-wrapper', false ) ) {
1385
-					new Jsonld_Article_Wrapper( Wordlift_Post_To_Jsonld_Converter::get_instance(), $that->cached_postid_to_jsonld_converter );
1386
-				}
1387
-
1388
-				// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1389
-				if ( apply_filters( 'wl_feature__enable__match-terms', false ) ) {
1390
-					$vocabulary_loader = new Vocabulary_Loader();
1391
-					$vocabulary_loader->init_vocabulary();
1392
-				}
1393
-
1394
-				/**
1395
-				 * Added for feature request 1496 (Webhooks)
1396
-				 */
1397
-				if ( apply_filters( 'wl_feature__enable__webhooks', false ) ) {
1398
-					$that->webhook_loader = new Webhooks_Loader();
1399
-					$that->webhook_loader->init();
1400
-				}
1401
-
1402
-				/**
1403
-				 * @since 3.30.0
1404
-				 * Add a checkbox to user option screen for wordlift admin.
1405
-				 */
1406
-				$wordlift_admin_checkbox = new Admin_User_Option();
1407
-				$wordlift_admin_checkbox->connect_hook();
1408
-
1409
-				/**
1410
-				 * @since 3.31.0
1411
-				 * Init loader class for videoobject.
1412
-				 */
1413
-				$videoobject_loader = new Loader();
1414
-				$videoobject_loader->init_feature();
1415
-
1416
-				/**
1417
-				 * @since 3.35.0
1418
-				 */
1419
-				$google_addon_integration_loader = new \Wordlift\Google_Addon_Integration\Loader();
1420
-				$google_addon_integration_loader->init_feature();
1421
-
1422
-				/**
1423
-				 * @since 3.31.5
1424
-				 * Create configuration endpoint for webapp to configure.
1425
-				 */
1426
-				new Config( $that->admin_setup, $that->key_validation_service );
1427
-				/**
1428
-				 * @since 3.31.7
1429
-				 * Remove duplicate videoobject.
1430
-				 */
1431
-				new Videoobject_Duplicate_Remover();
1432
-				$synonym_loader = new \Wordlift\Synonym\Loader();
1433
-				$synonym_loader->init_feature();
1434
-				/**
1435
-				 * @since 3.32.0
1436
-				 * Create loader for vocabulary terms.
1437
-				 */
1438
-				$vocabulary_terms_loader = new Vocabulary_Terms_Loader( Wordlift_Entity_Type_Service::get_instance(), $property_getter );
1439
-				$vocabulary_terms_loader->init_feature();
1440
-
1441
-				new Entity_Type_Change_Handler(
1442
-					Wordlift_Entity_Service::get_instance(),
1443
-					Wordlift_Entity_Type_Service::get_instance()
1444
-				);
1445
-
1446
-			},
1447
-			3
1448
-		);
1449
-
1450
-		new Entity_Type_Setter();
1451
-		$no_editor_analysis_loader = new \Wordlift\No_Editor_Analysis\Loader();
1452
-		$no_editor_analysis_loader->init_feature();
1453
-	}
1454
-
1455
-	/**
1456
-	 * Define the locale for this plugin for internationalization.
1457
-	 *
1458
-	 * Uses the Wordlift_i18n class in order to set the domain and to register the hook
1459
-	 * with WordPress.
1460
-	 *
1461
-	 * @since    1.0.0
1462
-	 * @access   private
1463
-	 */
1464
-	private function set_locale() {
1465
-
1466
-		$plugin_i18n = new Wordlift_I18n();
1467
-		$plugin_i18n->set_domain( $this->get_plugin_name() );
1468
-
1469
-		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
1470
-
1471
-	}
1472
-
1473
-	/**
1474
-	 * Register all of the hooks related to the admin area functionality
1475
-	 * of the plugin.
1476
-	 *
1477
-	 * @since    1.0.0
1478
-	 * @access   private
1479
-	 */
1480
-	private function define_admin_hooks( $that ) {
1481
-		$plugin_admin = new Wordlift_Admin(
1482
-			$that->get_plugin_name(),
1483
-			$that->get_version(),
1484
-			$that->notice_service,
1485
-			$that->user_service
1486
-		);
1487
-
1488
-		$that->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
1489
-		$that->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts', 11 );
1490
-
1491
-		// Hook the `admin_init` function to the Admin Setup.
1492
-		Assertions::is_set( $that->admin_setup, '`admin_setup` must be set' );
1493
-		$that->loader->add_action( 'admin_init', $that->admin_setup, 'admin_init' );
1494
-
1495
-		// Hook the admin_init to the settings page.
1496
-		Assertions::is_set( $that->settings_page, '`setting_page` must be set' );
1497
-		$that->loader->add_action( 'admin_init', $that->settings_page, 'admin_init' );
1498
-
1499
-		// Hook the admin_init to the analytics settings page.
1500
-		Assertions::is_set( $that->analytics_settings_page, '`analytics_setting_page` must be set' );
1501
-		$that->loader->add_action( 'admin_init', $that->analytics_settings_page, 'admin_init' );
1502
-
1503
-		// Hook the init action to taxonomy services.
1504
-		$that->loader->add_action( 'init', $that->topic_taxonomy_service, 'init', 0 );
1505
-		$that->loader->add_action( 'init', $that->entity_types_taxonomy_service, 'init', 0 );
1506
-
1507
-		// Hook the AJAX wl_timeline action to the Timeline service.
1508
-		$that->loader->add_action( 'wp_ajax_wl_timeline', $that->timeline_service, 'ajax_timeline' );
1509
-
1510
-		// Register custom allowed redirect hosts.
1511
-		$that->loader->add_filter( 'allowed_redirect_hosts', $that->redirect_service, 'allowed_redirect_hosts' );
1512
-		// Hook the AJAX wordlift_redirect action to the Redirect service.
1513
-		$that->loader->add_action( 'wp_ajax_wordlift_redirect', $that->redirect_service, 'ajax_redirect' );
1514
-
1515
-		// Hook save_post to the entity service to update custom fields (such as alternate labels).
1516
-		// We have a priority of 9 because we want to be executed before data is sent to Redlink.
1517
-		$that->loader->add_action( 'save_post', Wordlift_Entity_Service::get_instance(), 'save_post', 9, 2 );
1518
-		$that->loader->add_action( 'save_post', $that->rating_service, 'set_rating_for', 20, 1 );
1519
-
1520
-		$that->loader->add_action( 'edit_form_before_permalink', Wordlift_Entity_Service::get_instance(), 'edit_form_before_permalink', 10, 1 );
1521
-		$that->loader->add_action( 'in_admin_header', $that->rating_service, 'in_admin_header' );
1522
-
1523
-		// Entity listing customization (wp-admin/edit.php)
1524
-		// Add custom columns.
1525
-		$that->loader->add_filter( 'manage_entity_posts_columns', $that->entity_list_service, 'register_custom_columns' );
1526
-		// no explicit entity as it prevents handling of other post types.
1527
-		$that->loader->add_filter( 'manage_posts_custom_column', $that->entity_list_service, 'render_custom_columns', 10, 2 );
1528
-		// Add 4W selection.
1529
-		$that->loader->add_action( 'restrict_manage_posts', $that->entity_list_service, 'restrict_manage_posts_classification_scope' );
1530
-		$that->loader->add_filter( 'posts_clauses', $that->entity_list_service, 'posts_clauses_classification_scope' );
1531
-		$that->loader->add_action( 'pre_get_posts', $that->entity_list_service, 'pre_get_posts' );
1532
-		$that->loader->add_action( 'load-edit.php', $that->entity_list_service, 'load_edit' );
1533
-
1534
-		/*
1323
+                new Templates_Ajax_Endpoint();
1324
+                // Call this static method to register FAQ routes to rest api - disabled
1325
+                // Faq_Rest_Controller::register_routes();
1326
+
1327
+                $that->storage_factory = new Wordlift_Storage_Factory( Wordlift_Entity_Service::get_instance(), $that->user_service, $property_getter );
1328
+
1329
+                /** WL Autocomplete. */
1330
+                $autocomplete_service       = new All_Autocomplete_Service(
1331
+                    array(
1332
+                        new Local_Autocomplete_Service(),
1333
+                        new Linked_Data_Autocomplete_Service( Entity_Helper::get_instance(), $that->entity_uri_service, Wordlift_Entity_Service::get_instance() ),
1334
+                    )
1335
+                );
1336
+                $that->autocomplete_adapter = new Wordlift_Autocomplete_Adapter( $autocomplete_service );
1337
+
1338
+                /**
1339
+                 * @since 3.27.2
1340
+                 * Integrate the recipe maker jsonld & set recipe
1341
+                 * as default entity type to the wprm_recipe CPT.
1342
+                 */
1343
+                new Recipe_Maker_Post_Type_Hook();
1344
+                $recipe_maker_validation_service = new Recipe_Maker_Validation_Service();
1345
+                new Recipe_Maker_Jsonld_Hook( $attachment_service, $recipe_maker_validation_service );
1346
+                new Recipe_Maker_After_Get_Jsonld_Hook( $recipe_maker_validation_service );
1347
+                new Recipe_Maker_Jsonld_Swap( $recipe_maker_validation_service, $that->jsonld_service );
1348
+                new Recipe_Maker_Warning( $recipe_maker_validation_service );
1349
+
1350
+                /**
1351
+                 * Avada Builder compatibility.
1352
+                 *
1353
+                 * @since 3.40.0
1354
+                 */
1355
+                new Avada_Builder_Support();
1356
+
1357
+                new Duplicate_Markup_Remover();
1358
+
1359
+                /**
1360
+                 * @since 3.27.8
1361
+                 * @see https://github.com/insideout10/wordlift-plugin/issues/1248
1362
+                 */
1363
+                new Key_Validation_Notice( $that->key_validation_service, Wordlift_Configuration_Service::get_instance() );
1364
+
1365
+                /**
1366
+                 * @since 3.28.0
1367
+                 * @see https://github.com/insideout10/wordlift-plugin/issues?q=assignee%3Anaveen17797+is%3Aopen
1368
+                 */
1369
+                new Entity_No_Index_Flag();
1370
+
1371
+                /**
1372
+                 * @since 3.29.0
1373
+                 * @see https://github.com/insideout10/wordlift-plugin/issues/1304
1374
+                 */
1375
+                new Entity_Rest_Service( Wordlift_Entity_Type_Service::get_instance() );
1376
+
1377
+                /**
1378
+                 * Expand author in to references.
1379
+                 *
1380
+                 * @since 3.30.0
1381
+                 * @see https://github.com/insideout10/wordlift-plugin/issues/1318
1382
+                 */
1383
+                // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1384
+                if ( apply_filters( 'wl_feature__enable__article-wrapper', false ) ) {
1385
+                    new Jsonld_Article_Wrapper( Wordlift_Post_To_Jsonld_Converter::get_instance(), $that->cached_postid_to_jsonld_converter );
1386
+                }
1387
+
1388
+                // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1389
+                if ( apply_filters( 'wl_feature__enable__match-terms', false ) ) {
1390
+                    $vocabulary_loader = new Vocabulary_Loader();
1391
+                    $vocabulary_loader->init_vocabulary();
1392
+                }
1393
+
1394
+                /**
1395
+                 * Added for feature request 1496 (Webhooks)
1396
+                 */
1397
+                if ( apply_filters( 'wl_feature__enable__webhooks', false ) ) {
1398
+                    $that->webhook_loader = new Webhooks_Loader();
1399
+                    $that->webhook_loader->init();
1400
+                }
1401
+
1402
+                /**
1403
+                 * @since 3.30.0
1404
+                 * Add a checkbox to user option screen for wordlift admin.
1405
+                 */
1406
+                $wordlift_admin_checkbox = new Admin_User_Option();
1407
+                $wordlift_admin_checkbox->connect_hook();
1408
+
1409
+                /**
1410
+                 * @since 3.31.0
1411
+                 * Init loader class for videoobject.
1412
+                 */
1413
+                $videoobject_loader = new Loader();
1414
+                $videoobject_loader->init_feature();
1415
+
1416
+                /**
1417
+                 * @since 3.35.0
1418
+                 */
1419
+                $google_addon_integration_loader = new \Wordlift\Google_Addon_Integration\Loader();
1420
+                $google_addon_integration_loader->init_feature();
1421
+
1422
+                /**
1423
+                 * @since 3.31.5
1424
+                 * Create configuration endpoint for webapp to configure.
1425
+                 */
1426
+                new Config( $that->admin_setup, $that->key_validation_service );
1427
+                /**
1428
+                 * @since 3.31.7
1429
+                 * Remove duplicate videoobject.
1430
+                 */
1431
+                new Videoobject_Duplicate_Remover();
1432
+                $synonym_loader = new \Wordlift\Synonym\Loader();
1433
+                $synonym_loader->init_feature();
1434
+                /**
1435
+                 * @since 3.32.0
1436
+                 * Create loader for vocabulary terms.
1437
+                 */
1438
+                $vocabulary_terms_loader = new Vocabulary_Terms_Loader( Wordlift_Entity_Type_Service::get_instance(), $property_getter );
1439
+                $vocabulary_terms_loader->init_feature();
1440
+
1441
+                new Entity_Type_Change_Handler(
1442
+                    Wordlift_Entity_Service::get_instance(),
1443
+                    Wordlift_Entity_Type_Service::get_instance()
1444
+                );
1445
+
1446
+            },
1447
+            3
1448
+        );
1449
+
1450
+        new Entity_Type_Setter();
1451
+        $no_editor_analysis_loader = new \Wordlift\No_Editor_Analysis\Loader();
1452
+        $no_editor_analysis_loader->init_feature();
1453
+    }
1454
+
1455
+    /**
1456
+     * Define the locale for this plugin for internationalization.
1457
+     *
1458
+     * Uses the Wordlift_i18n class in order to set the domain and to register the hook
1459
+     * with WordPress.
1460
+     *
1461
+     * @since    1.0.0
1462
+     * @access   private
1463
+     */
1464
+    private function set_locale() {
1465
+
1466
+        $plugin_i18n = new Wordlift_I18n();
1467
+        $plugin_i18n->set_domain( $this->get_plugin_name() );
1468
+
1469
+        $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
1470
+
1471
+    }
1472
+
1473
+    /**
1474
+     * Register all of the hooks related to the admin area functionality
1475
+     * of the plugin.
1476
+     *
1477
+     * @since    1.0.0
1478
+     * @access   private
1479
+     */
1480
+    private function define_admin_hooks( $that ) {
1481
+        $plugin_admin = new Wordlift_Admin(
1482
+            $that->get_plugin_name(),
1483
+            $that->get_version(),
1484
+            $that->notice_service,
1485
+            $that->user_service
1486
+        );
1487
+
1488
+        $that->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
1489
+        $that->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts', 11 );
1490
+
1491
+        // Hook the `admin_init` function to the Admin Setup.
1492
+        Assertions::is_set( $that->admin_setup, '`admin_setup` must be set' );
1493
+        $that->loader->add_action( 'admin_init', $that->admin_setup, 'admin_init' );
1494
+
1495
+        // Hook the admin_init to the settings page.
1496
+        Assertions::is_set( $that->settings_page, '`setting_page` must be set' );
1497
+        $that->loader->add_action( 'admin_init', $that->settings_page, 'admin_init' );
1498
+
1499
+        // Hook the admin_init to the analytics settings page.
1500
+        Assertions::is_set( $that->analytics_settings_page, '`analytics_setting_page` must be set' );
1501
+        $that->loader->add_action( 'admin_init', $that->analytics_settings_page, 'admin_init' );
1502
+
1503
+        // Hook the init action to taxonomy services.
1504
+        $that->loader->add_action( 'init', $that->topic_taxonomy_service, 'init', 0 );
1505
+        $that->loader->add_action( 'init', $that->entity_types_taxonomy_service, 'init', 0 );
1506
+
1507
+        // Hook the AJAX wl_timeline action to the Timeline service.
1508
+        $that->loader->add_action( 'wp_ajax_wl_timeline', $that->timeline_service, 'ajax_timeline' );
1509
+
1510
+        // Register custom allowed redirect hosts.
1511
+        $that->loader->add_filter( 'allowed_redirect_hosts', $that->redirect_service, 'allowed_redirect_hosts' );
1512
+        // Hook the AJAX wordlift_redirect action to the Redirect service.
1513
+        $that->loader->add_action( 'wp_ajax_wordlift_redirect', $that->redirect_service, 'ajax_redirect' );
1514
+
1515
+        // Hook save_post to the entity service to update custom fields (such as alternate labels).
1516
+        // We have a priority of 9 because we want to be executed before data is sent to Redlink.
1517
+        $that->loader->add_action( 'save_post', Wordlift_Entity_Service::get_instance(), 'save_post', 9, 2 );
1518
+        $that->loader->add_action( 'save_post', $that->rating_service, 'set_rating_for', 20, 1 );
1519
+
1520
+        $that->loader->add_action( 'edit_form_before_permalink', Wordlift_Entity_Service::get_instance(), 'edit_form_before_permalink', 10, 1 );
1521
+        $that->loader->add_action( 'in_admin_header', $that->rating_service, 'in_admin_header' );
1522
+
1523
+        // Entity listing customization (wp-admin/edit.php)
1524
+        // Add custom columns.
1525
+        $that->loader->add_filter( 'manage_entity_posts_columns', $that->entity_list_service, 'register_custom_columns' );
1526
+        // no explicit entity as it prevents handling of other post types.
1527
+        $that->loader->add_filter( 'manage_posts_custom_column', $that->entity_list_service, 'render_custom_columns', 10, 2 );
1528
+        // Add 4W selection.
1529
+        $that->loader->add_action( 'restrict_manage_posts', $that->entity_list_service, 'restrict_manage_posts_classification_scope' );
1530
+        $that->loader->add_filter( 'posts_clauses', $that->entity_list_service, 'posts_clauses_classification_scope' );
1531
+        $that->loader->add_action( 'pre_get_posts', $that->entity_list_service, 'pre_get_posts' );
1532
+        $that->loader->add_action( 'load-edit.php', $that->entity_list_service, 'load_edit' );
1533
+
1534
+        /*
1535 1535
 		 * If `All Entity Types` is disable, use the radio button Walker.
1536 1536
 		 *
1537 1537
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/835
1538 1538
 		 */
1539
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1540
-		if ( ! apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES )
1541
-		     // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1542
-			 && ! apply_filters( 'wl_feature__enable__entity-types-professional', false )
1543
-		     // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1544
-			 && ! apply_filters( 'wl_feature__enable__entity-types-business', false )
1545
-		) {
1546
-			$that->loader->add_filter( 'wp_terms_checklist_args', $that->entity_types_taxonomy_walker, 'terms_checklist_args' );
1547
-		}
1548
-
1549
-		// Hook the PrimaShop adapter to <em>prima_metabox_entity_header_args</em> in order to add header support for
1550
-		// entities.
1551
-		$that->loader->add_filter( 'prima_metabox_entity_header_args', $that->primashop_adapter, 'prima_metabox_entity_header_args', 10 );
1552
-
1553
-		/**
1554
-		 * Filter: wl_feature__enable__settings-download.
1555
-		 *
1556
-		 * @param bool whether the screens needed to be registered, defaults to true.
1557
-		 *
1558
-		 * @return bool
1559
-		 * @since 3.27.6
1560
-		 */
1561
-		$that->features_registry->register_feature_from_slug(
1562
-			'settings-download',
1563
-			true,
1564
-			array(
1565
-				$that,
1566
-				'register_screens',
1567
-			)
1568
-		);
1569
-
1570
-		// Hook the admin-ajax.php?action=wl_download_your_data&out=xyz links.
1571
-		$that->loader->add_action( 'wp_ajax_wl_download_your_data', $that->download_your_data_page, 'download_your_data', 10 );
1572
-
1573
-		// Hook the AJAX wl_jsonld action to the JSON-LD service.
1574
-		$that->loader->add_action( 'wp_ajax_wl_jsonld', $that->jsonld_service, 'get' );
1575
-		$that->loader->add_action( 'admin_post_wl_jsonld', $that->jsonld_service, 'get' );
1576
-		$that->loader->add_action( 'admin_post_nopriv_wl_jsonld', $that->jsonld_service, 'get' );
1577
-
1578
-		// Hook the AJAX wl_validate_key action to the Key Validation service.
1579
-		$that->loader->add_action( 'wp_ajax_wl_validate_key', $that->key_validation_service, 'validate_key' );
1580
-
1581
-		// Hook the AJAX wl_update_country_options action to the countries.
1582
-		$that->loader->add_action( 'wp_ajax_wl_update_country_options', $that->country_select_element, 'get_options_html' );
1583
-
1584
-		$that->loader->add_filter( 'admin_post_thumbnail_html', $that->publisher_service, 'add_featured_image_instruction' );
1585
-
1586
-		// Hook the menu creation on the general wordlift menu creation.
1587
-		/**
1588
-		 * Filter: wl_feature__enable__screens.
1589
-		 *
1590
-		 * @param bool whether the screens needed to be registered, defaults to true.
1591
-		 *
1592
-		 * @return bool
1593
-		 * @since 3.27.6
1594
-		 *
1595
-		 * Since 3.30.0 this feature is registered using registry.
1596
-		 */
1597
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1598
-		if ( apply_filters( 'wl_feature__enable__settings-screen', true ) || Admin_User_Option::is_wordlift_admin() ) {
1599
-			add_action( 'wl_admin_menu', array( $that->settings_page, 'admin_menu' ), 10, 2 );
1600
-		}
1601
-
1602
-		// Hook key update.
1603
-		$that->loader->add_action( 'pre_update_option_wl_general_settings', Wordlift_Configuration_Service::get_instance(), 'maybe_update_dataset_uri', 10, 2 );
1604
-		$that->loader->add_action( 'update_option_wl_general_settings', Wordlift_Configuration_Service::get_instance(), 'update_key', 10, 2 );
1605
-
1606
-		// Add additional action links to the WordLift plugin in the plugins page.
1607
-		$that->loader->add_filter( 'plugin_action_links_wordlift/wordlift.php', $that->settings_page_action_link, 'action_links', 10, 1 );
1608
-
1609
-		/*
1539
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1540
+        if ( ! apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES )
1541
+                // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1542
+             && ! apply_filters( 'wl_feature__enable__entity-types-professional', false )
1543
+                // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1544
+             && ! apply_filters( 'wl_feature__enable__entity-types-business', false )
1545
+        ) {
1546
+            $that->loader->add_filter( 'wp_terms_checklist_args', $that->entity_types_taxonomy_walker, 'terms_checklist_args' );
1547
+        }
1548
+
1549
+        // Hook the PrimaShop adapter to <em>prima_metabox_entity_header_args</em> in order to add header support for
1550
+        // entities.
1551
+        $that->loader->add_filter( 'prima_metabox_entity_header_args', $that->primashop_adapter, 'prima_metabox_entity_header_args', 10 );
1552
+
1553
+        /**
1554
+         * Filter: wl_feature__enable__settings-download.
1555
+         *
1556
+         * @param bool whether the screens needed to be registered, defaults to true.
1557
+         *
1558
+         * @return bool
1559
+         * @since 3.27.6
1560
+         */
1561
+        $that->features_registry->register_feature_from_slug(
1562
+            'settings-download',
1563
+            true,
1564
+            array(
1565
+                $that,
1566
+                'register_screens',
1567
+            )
1568
+        );
1569
+
1570
+        // Hook the admin-ajax.php?action=wl_download_your_data&out=xyz links.
1571
+        $that->loader->add_action( 'wp_ajax_wl_download_your_data', $that->download_your_data_page, 'download_your_data', 10 );
1572
+
1573
+        // Hook the AJAX wl_jsonld action to the JSON-LD service.
1574
+        $that->loader->add_action( 'wp_ajax_wl_jsonld', $that->jsonld_service, 'get' );
1575
+        $that->loader->add_action( 'admin_post_wl_jsonld', $that->jsonld_service, 'get' );
1576
+        $that->loader->add_action( 'admin_post_nopriv_wl_jsonld', $that->jsonld_service, 'get' );
1577
+
1578
+        // Hook the AJAX wl_validate_key action to the Key Validation service.
1579
+        $that->loader->add_action( 'wp_ajax_wl_validate_key', $that->key_validation_service, 'validate_key' );
1580
+
1581
+        // Hook the AJAX wl_update_country_options action to the countries.
1582
+        $that->loader->add_action( 'wp_ajax_wl_update_country_options', $that->country_select_element, 'get_options_html' );
1583
+
1584
+        $that->loader->add_filter( 'admin_post_thumbnail_html', $that->publisher_service, 'add_featured_image_instruction' );
1585
+
1586
+        // Hook the menu creation on the general wordlift menu creation.
1587
+        /**
1588
+         * Filter: wl_feature__enable__screens.
1589
+         *
1590
+         * @param bool whether the screens needed to be registered, defaults to true.
1591
+         *
1592
+         * @return bool
1593
+         * @since 3.27.6
1594
+         *
1595
+         * Since 3.30.0 this feature is registered using registry.
1596
+         */
1597
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1598
+        if ( apply_filters( 'wl_feature__enable__settings-screen', true ) || Admin_User_Option::is_wordlift_admin() ) {
1599
+            add_action( 'wl_admin_menu', array( $that->settings_page, 'admin_menu' ), 10, 2 );
1600
+        }
1601
+
1602
+        // Hook key update.
1603
+        $that->loader->add_action( 'pre_update_option_wl_general_settings', Wordlift_Configuration_Service::get_instance(), 'maybe_update_dataset_uri', 10, 2 );
1604
+        $that->loader->add_action( 'update_option_wl_general_settings', Wordlift_Configuration_Service::get_instance(), 'update_key', 10, 2 );
1605
+
1606
+        // Add additional action links to the WordLift plugin in the plugins page.
1607
+        $that->loader->add_filter( 'plugin_action_links_wordlift/wordlift.php', $that->settings_page_action_link, 'action_links', 10, 1 );
1608
+
1609
+        /*
1610 1610
 		 * Remove the Analytics Settings link from the plugin page.
1611 1611
 		 *
1612 1612
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/932
1613 1613
 		 * @since 3.21.1
1614 1614
 		 */
1615
-		// $that->loader->add_filter( 'plugin_action_links_wordlift/wordlift.php', $that->analytics_settings_page_action_link, 'action_links', 10, 1 );
1616
-
1617
-		// Hook the AJAX `wl_publisher` action name.
1618
-		$that->loader->add_action( 'wp_ajax_wl_publisher', $that->publisher_ajax_adapter, 'publisher' );
1619
-
1620
-		// Hook row actions for the entity type list admin.
1621
-		$that->loader->add_filter( 'wl_entity_type_row_actions', $that->entity_type_admin_page, 'wl_entity_type_row_actions', 10, 2 );
1622
-
1623
-		/** Ajax actions. */
1624
-		$that->loader->add_action( 'wp_ajax_wl_google_analytics_export', $that->google_analytics_export_service, 'export' );
1625
-
1626
-		// Hook capabilities manipulation to allow access to entity type admin
1627
-		// page  on WordPress versions before 4.7.
1628
-		global $wp_version;
1629
-		if ( version_compare( $wp_version, '4.7', '<' ) ) {
1630
-			$that->loader->add_filter( 'map_meta_cap', $that->entity_type_admin_page, 'enable_admin_access_pre_47', 10, 2 );
1631
-		}
1632
-
1633
-		/** Adapters. */
1634
-		$that->loader->add_filter( 'mce_external_plugins', $that->tinymce_adapter, 'mce_external_plugins', 10, 1 );
1635
-		/**
1636
-		 * Disabling Faq temporarily.
1637
-		 * Load the tinymce editor button on the tool bar.
1638
-		 *
1639
-		 * @since 3.26.0
1640
-		 */
1641
-		// $that->loader->add_filter( 'tiny_mce_before_init', $that->faq_tinymce_adapter, 'register_custom_tags' );
1642
-		// $that->loader->add_filter( 'mce_buttons', $that->faq_tinymce_adapter, 'register_faq_toolbar_button', 10, 1 );
1643
-		// $that->loader->add_filter( 'mce_external_plugins', $that->faq_tinymce_adapter, 'register_faq_tinymce_plugin', 10, 1 );
1644
-
1645
-		$that->loader->add_action( 'wp_ajax_wl_sample_data_create', $that->sample_data_ajax_adapter, 'create' );
1646
-		$that->loader->add_action( 'wp_ajax_wl_sample_data_delete', $that->sample_data_ajax_adapter, 'delete' );
1647
-
1648
-		/**
1649
-		 * @since 3.26.0
1650
-		 */
1651
-		$excerpt_adapter = new Post_Excerpt_Meta_Box_Adapter();
1652
-		$that->loader->add_action( 'do_meta_boxes', $excerpt_adapter, 'replace_post_excerpt_meta_box' );
1653
-		// Adding Rest route for the post excerpt
1654
-		Post_Excerpt_Rest_Controller::register_routes();
1655
-
1656
-		// Handle the autocomplete request.
1657
-		add_action(
1658
-			'wp_ajax_wl_autocomplete',
1659
-			array(
1660
-				$that->autocomplete_adapter,
1661
-				'wl_autocomplete',
1662
-			)
1663
-		);
1664
-		add_action(
1665
-			'wp_ajax_nopriv_wl_autocomplete',
1666
-			array(
1667
-				$that->autocomplete_adapter,
1668
-				'wl_autocomplete',
1669
-			)
1670
-		);
1671
-
1672
-		// Hooks to restrict multisite super admin from manipulating entity types.
1673
-		if ( is_multisite() ) {
1674
-			$that->loader->add_filter( 'map_meta_cap', $that->entity_type_admin_page, 'restrict_super_admin', 10, 2 );
1675
-		}
1676
-
1677
-		$deactivator_feedback = new Wordlift_Deactivator_Feedback();
1678
-
1679
-		add_action( 'admin_footer', array( $deactivator_feedback, 'render_feedback_popup' ) );
1680
-		add_action(
1681
-			'admin_enqueue_scripts',
1682
-			array(
1683
-				$deactivator_feedback,
1684
-				'enqueue_popup_scripts',
1685
-			)
1686
-		);
1687
-		add_action(
1688
-			'wp_ajax_wl_deactivation_feedback',
1689
-			array(
1690
-				$deactivator_feedback,
1691
-				'wl_deactivation_feedback',
1692
-			)
1693
-		);
1694
-
1695
-		/**
1696
-		 * Always allow the `wordlift/classification` block.
1697
-		 *
1698
-		 * @since 3.23.0
1699
-		 */
1700
-		add_filter(
1701
-			'allowed_block_types',
1702
-			function ( $value ) {
1703
-
1704
-				if ( true === $value ) {
1705
-					return $value;
1706
-				}
1707
-
1708
-				return array_merge( (array) $value, array( 'wordlift/classification' ) );
1709
-			},
1710
-			PHP_INT_MAX
1711
-		);
1712
-
1713
-		/**
1714
-		 * @since 3.27.7
1715
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
1716
-		 */
1717
-		new Top_Entities();
1718
-
1719
-		add_action(
1720
-			'admin_notices',
1721
-			function () {
1722
-				if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
1723
-					/**
1724
-					 * Fired when the notice feature is enabled.
1725
-					 *
1726
-					 * @since 3.40.4
1727
-					 */
1728
-					do_action( 'wordlift_admin_notices' );
1729
-				}
1730
-			}
1731
-		);
1732
-
1733
-		add_action(
1734
-			'admin_init',
1735
-			function () {
1736
-				// Only show the notice when the key is set or skipped.
1737
-				if ( \Wordlift_Configuration_Service::get_instance()->get_key() && ! \Wordlift_Configuration_Service::get_instance()->get_skip_installation_notice() ) {
1738
-					$installation_complete_notice = new Installation_Complete_Notice();
1739
-					$installation_complete_notice->init();
1740
-				}
1741
-			}
1742
-		);
1743
-
1744
-	}
1745
-
1746
-	/**
1747
-	 * Register all of the hooks related to the public-facing functionality
1748
-	 * of the plugin.
1749
-	 *
1750
-	 * @since    1.0.0
1751
-	 * @access   private
1752
-	 */
1753
-	private function define_public_hooks( $that ) {
1754
-
1755
-		$plugin_public = new Wordlift_Public( $that->get_plugin_name(), $that->get_version() );
1756
-
1757
-		// Register the entity post type.
1758
-		$that->loader->add_action( 'init', $that->entity_post_type_service, 'register' );
1759
-
1760
-		// Bind the link generation and handling hooks to the entity link service.
1761
-		$that->loader->add_filter( 'post_type_link', $that->entity_link_service, 'post_type_link', 10, 2 );
1762
-		$that->loader->add_action( 'pre_get_posts', $that->entity_link_service, 'pre_get_posts', PHP_INT_MAX, 1 );
1763
-
1764
-		$that->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
1765
-		$that->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
1766
-		$that->loader->add_action( 'wp_enqueue_scripts', $that->context_cards_service, 'enqueue_scripts' );
1767
-
1768
-		// Registering Faq_Content_Filter service used for removing faq question and answer tags from the html.
1769
-		$that->loader->add_filter( 'the_content', $that->faq_content_filter_service, 'remove_all_faq_question_and_answer_tags' );
1770
-		// Hook the content filter service to add entity links.
1771
-		if ( ! defined( 'WL_DISABLE_CONTENT_FILTER' ) || ! WL_DISABLE_CONTENT_FILTER ) {
1772
-			// We run before other filters.
1773
-			$that->loader->add_filter( 'the_content', $that->content_filter_service, 'the_content', 9 );
1774
-		}
1775
-
1776
-		// Hook the AJAX wl_timeline action to the Timeline service.
1777
-		$that->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $that->timeline_service, 'ajax_timeline' );
1778
-
1779
-		// Hook the ShareThis service.
1780
-		$that->loader->add_filter( 'the_content', $that->sharethis_service, 'the_content', 99 );
1781
-		$that->loader->add_filter( 'the_excerpt', $that->sharethis_service, 'the_excerpt', 99 );
1782
-
1783
-		// Hook the AJAX wl_jsonld action to the JSON-LD service.
1784
-		$that->loader->add_action( 'wp_ajax_nopriv_wl_jsonld', $that->jsonld_service, 'get' );
1785
-
1786
-		// Hook the `pre_get_posts` action to the `Wordlift_Category_Taxonomy_Service`
1787
-		// in order to tweak WP's `WP_Query` to include entities in queries related
1788
-		// to categories.
1789
-		$that->loader->add_action( 'pre_get_posts', $that->category_taxonomy_service, 'pre_get_posts', 10, 1 );
1790
-
1791
-		/*
1615
+        // $that->loader->add_filter( 'plugin_action_links_wordlift/wordlift.php', $that->analytics_settings_page_action_link, 'action_links', 10, 1 );
1616
+
1617
+        // Hook the AJAX `wl_publisher` action name.
1618
+        $that->loader->add_action( 'wp_ajax_wl_publisher', $that->publisher_ajax_adapter, 'publisher' );
1619
+
1620
+        // Hook row actions for the entity type list admin.
1621
+        $that->loader->add_filter( 'wl_entity_type_row_actions', $that->entity_type_admin_page, 'wl_entity_type_row_actions', 10, 2 );
1622
+
1623
+        /** Ajax actions. */
1624
+        $that->loader->add_action( 'wp_ajax_wl_google_analytics_export', $that->google_analytics_export_service, 'export' );
1625
+
1626
+        // Hook capabilities manipulation to allow access to entity type admin
1627
+        // page  on WordPress versions before 4.7.
1628
+        global $wp_version;
1629
+        if ( version_compare( $wp_version, '4.7', '<' ) ) {
1630
+            $that->loader->add_filter( 'map_meta_cap', $that->entity_type_admin_page, 'enable_admin_access_pre_47', 10, 2 );
1631
+        }
1632
+
1633
+        /** Adapters. */
1634
+        $that->loader->add_filter( 'mce_external_plugins', $that->tinymce_adapter, 'mce_external_plugins', 10, 1 );
1635
+        /**
1636
+         * Disabling Faq temporarily.
1637
+         * Load the tinymce editor button on the tool bar.
1638
+         *
1639
+         * @since 3.26.0
1640
+         */
1641
+        // $that->loader->add_filter( 'tiny_mce_before_init', $that->faq_tinymce_adapter, 'register_custom_tags' );
1642
+        // $that->loader->add_filter( 'mce_buttons', $that->faq_tinymce_adapter, 'register_faq_toolbar_button', 10, 1 );
1643
+        // $that->loader->add_filter( 'mce_external_plugins', $that->faq_tinymce_adapter, 'register_faq_tinymce_plugin', 10, 1 );
1644
+
1645
+        $that->loader->add_action( 'wp_ajax_wl_sample_data_create', $that->sample_data_ajax_adapter, 'create' );
1646
+        $that->loader->add_action( 'wp_ajax_wl_sample_data_delete', $that->sample_data_ajax_adapter, 'delete' );
1647
+
1648
+        /**
1649
+         * @since 3.26.0
1650
+         */
1651
+        $excerpt_adapter = new Post_Excerpt_Meta_Box_Adapter();
1652
+        $that->loader->add_action( 'do_meta_boxes', $excerpt_adapter, 'replace_post_excerpt_meta_box' );
1653
+        // Adding Rest route for the post excerpt
1654
+        Post_Excerpt_Rest_Controller::register_routes();
1655
+
1656
+        // Handle the autocomplete request.
1657
+        add_action(
1658
+            'wp_ajax_wl_autocomplete',
1659
+            array(
1660
+                $that->autocomplete_adapter,
1661
+                'wl_autocomplete',
1662
+            )
1663
+        );
1664
+        add_action(
1665
+            'wp_ajax_nopriv_wl_autocomplete',
1666
+            array(
1667
+                $that->autocomplete_adapter,
1668
+                'wl_autocomplete',
1669
+            )
1670
+        );
1671
+
1672
+        // Hooks to restrict multisite super admin from manipulating entity types.
1673
+        if ( is_multisite() ) {
1674
+            $that->loader->add_filter( 'map_meta_cap', $that->entity_type_admin_page, 'restrict_super_admin', 10, 2 );
1675
+        }
1676
+
1677
+        $deactivator_feedback = new Wordlift_Deactivator_Feedback();
1678
+
1679
+        add_action( 'admin_footer', array( $deactivator_feedback, 'render_feedback_popup' ) );
1680
+        add_action(
1681
+            'admin_enqueue_scripts',
1682
+            array(
1683
+                $deactivator_feedback,
1684
+                'enqueue_popup_scripts',
1685
+            )
1686
+        );
1687
+        add_action(
1688
+            'wp_ajax_wl_deactivation_feedback',
1689
+            array(
1690
+                $deactivator_feedback,
1691
+                'wl_deactivation_feedback',
1692
+            )
1693
+        );
1694
+
1695
+        /**
1696
+         * Always allow the `wordlift/classification` block.
1697
+         *
1698
+         * @since 3.23.0
1699
+         */
1700
+        add_filter(
1701
+            'allowed_block_types',
1702
+            function ( $value ) {
1703
+
1704
+                if ( true === $value ) {
1705
+                    return $value;
1706
+                }
1707
+
1708
+                return array_merge( (array) $value, array( 'wordlift/classification' ) );
1709
+            },
1710
+            PHP_INT_MAX
1711
+        );
1712
+
1713
+        /**
1714
+         * @since 3.27.7
1715
+         * @see https://github.com/insideout10/wordlift-plugin/issues/1214
1716
+         */
1717
+        new Top_Entities();
1718
+
1719
+        add_action(
1720
+            'admin_notices',
1721
+            function () {
1722
+                if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
1723
+                    /**
1724
+                     * Fired when the notice feature is enabled.
1725
+                     *
1726
+                     * @since 3.40.4
1727
+                     */
1728
+                    do_action( 'wordlift_admin_notices' );
1729
+                }
1730
+            }
1731
+        );
1732
+
1733
+        add_action(
1734
+            'admin_init',
1735
+            function () {
1736
+                // Only show the notice when the key is set or skipped.
1737
+                if ( \Wordlift_Configuration_Service::get_instance()->get_key() && ! \Wordlift_Configuration_Service::get_instance()->get_skip_installation_notice() ) {
1738
+                    $installation_complete_notice = new Installation_Complete_Notice();
1739
+                    $installation_complete_notice->init();
1740
+                }
1741
+            }
1742
+        );
1743
+
1744
+    }
1745
+
1746
+    /**
1747
+     * Register all of the hooks related to the public-facing functionality
1748
+     * of the plugin.
1749
+     *
1750
+     * @since    1.0.0
1751
+     * @access   private
1752
+     */
1753
+    private function define_public_hooks( $that ) {
1754
+
1755
+        $plugin_public = new Wordlift_Public( $that->get_plugin_name(), $that->get_version() );
1756
+
1757
+        // Register the entity post type.
1758
+        $that->loader->add_action( 'init', $that->entity_post_type_service, 'register' );
1759
+
1760
+        // Bind the link generation and handling hooks to the entity link service.
1761
+        $that->loader->add_filter( 'post_type_link', $that->entity_link_service, 'post_type_link', 10, 2 );
1762
+        $that->loader->add_action( 'pre_get_posts', $that->entity_link_service, 'pre_get_posts', PHP_INT_MAX, 1 );
1763
+
1764
+        $that->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
1765
+        $that->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
1766
+        $that->loader->add_action( 'wp_enqueue_scripts', $that->context_cards_service, 'enqueue_scripts' );
1767
+
1768
+        // Registering Faq_Content_Filter service used for removing faq question and answer tags from the html.
1769
+        $that->loader->add_filter( 'the_content', $that->faq_content_filter_service, 'remove_all_faq_question_and_answer_tags' );
1770
+        // Hook the content filter service to add entity links.
1771
+        if ( ! defined( 'WL_DISABLE_CONTENT_FILTER' ) || ! WL_DISABLE_CONTENT_FILTER ) {
1772
+            // We run before other filters.
1773
+            $that->loader->add_filter( 'the_content', $that->content_filter_service, 'the_content', 9 );
1774
+        }
1775
+
1776
+        // Hook the AJAX wl_timeline action to the Timeline service.
1777
+        $that->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $that->timeline_service, 'ajax_timeline' );
1778
+
1779
+        // Hook the ShareThis service.
1780
+        $that->loader->add_filter( 'the_content', $that->sharethis_service, 'the_content', 99 );
1781
+        $that->loader->add_filter( 'the_excerpt', $that->sharethis_service, 'the_excerpt', 99 );
1782
+
1783
+        // Hook the AJAX wl_jsonld action to the JSON-LD service.
1784
+        $that->loader->add_action( 'wp_ajax_nopriv_wl_jsonld', $that->jsonld_service, 'get' );
1785
+
1786
+        // Hook the `pre_get_posts` action to the `Wordlift_Category_Taxonomy_Service`
1787
+        // in order to tweak WP's `WP_Query` to include entities in queries related
1788
+        // to categories.
1789
+        $that->loader->add_action( 'pre_get_posts', $that->category_taxonomy_service, 'pre_get_posts', 10, 1 );
1790
+
1791
+        /*
1792 1792
 		 * Hook the `pre_get_posts` action to the `Wordlift_Entity_Page_Service`
1793 1793
 		 * in order to tweak WP's `WP_Query` to show event related entities in reverse
1794 1794
 		 * order of start time.
1795 1795
 		 */
1796
-		$that->loader->add_action( 'pre_get_posts', $that->entity_page_service, 'pre_get_posts', 10, 1 );
1797
-
1798
-		// This hook have to run before the rating service, as otherwise the post might not be a proper entity when rating is done.
1799
-		$that->loader->add_action( 'save_post', $that->entity_type_adapter, 'save_post', 9, 2 );
1800
-
1801
-		// Analytics Script Frontend.
1802
-		if ( apply_filters( 'wl_feature__enable__analytics', true ) && Wordlift_Configuration_Service::get_instance()->is_analytics_enable() ) {
1803
-			$that->loader->add_action( 'wp_enqueue_scripts', $that->analytics_connect, 'enqueue_scripts', 10 );
1804
-		}
1805
-
1806
-	}
1807
-
1808
-	/**
1809
-	 * Run the loader to execute all of the hooks with WordPress.
1810
-	 *
1811
-	 * @since    1.0.0
1812
-	 */
1813
-	public function run() {
1814
-		$this->loader->run();
1815
-	}
1816
-
1817
-	/**
1818
-	 * The name of the plugin used to uniquely identify it within the context of
1819
-	 * WordPress and to define internationalization functionality.
1820
-	 *
1821
-	 * @return    string    The name of the plugin.
1822
-	 * @since     1.0.0
1823
-	 */
1824
-	public function get_plugin_name() {
1825
-		return $this->plugin_name;
1826
-	}
1827
-
1828
-	/**
1829
-	 * The reference to the class that orchestrates the hooks with the plugin.
1830
-	 *
1831
-	 * @return    Wordlift_Loader    Orchestrates the hooks of the plugin.
1832
-	 * @since     1.0.0
1833
-	 */
1834
-	public function get_loader() {
1835
-		return $this->loader;
1836
-	}
1837
-
1838
-	/**
1839
-	 * Retrieve the version number of the plugin.
1840
-	 *
1841
-	 * @return    string    The version number of the plugin.
1842
-	 * @since     1.0.0
1843
-	 */
1844
-	public function get_version() {
1845
-		return $this->version;
1846
-	}
1847
-
1848
-	/**
1849
-	 * Load dependencies for WP-CLI.
1850
-	 *
1851
-	 * @throws Exception when an error occurs.
1852
-	 * @since 3.18.0
1853
-	 */
1854
-	private function load_cli_dependencies() {
1855
-
1856
-	}
1857
-
1858
-	public function add_wl_enabled_blocks() {
1859
-		/**
1860
-		 * Filter: wl_feature__enable__blocks.
1861
-		 *
1862
-		 * @param bool whether the blocks needed to be registered, defaults to true.
1863
-		 *
1864
-		 * @return bool
1865
-		 * @since 3.27.6
1866
-		 */
1867
-		// phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter,WordPress.WP.EnqueuedResourceParameters.MissingVersion
1868
-		wp_register_script( 'wl_enabled_blocks', false );
1869
-
1870
-		$enabled_blocks = array();
1871
-
1872
-		/**
1873
-		 * Filter name: wl_feature__enable__product-navigator
1874
-		 *
1875
-		 * @since 3.32.3
1876
-		 */
1877
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1878
-		if ( apply_filters( 'wl_feature__enable__product-navigator', true ) ) {
1879
-			$enabled_blocks[] = 'wordlift/products-navigator';
1880
-		}
1881
-
1882
-		if ( apply_filters( 'wl_feature__enable__blocks', true ) ) {
1883
-			// To intimate JS
1884
-			$enabled_blocks = array_merge(
1885
-				$enabled_blocks,
1886
-				array(
1887
-					'wordlift/navigator',
1888
-					'wordlift/chord',
1889
-					'wordlift/geomap',
1890
-					'wordlift/timeline',
1891
-					'wordlift/cloud',
1892
-					'wordlift/vocabulary',
1893
-					'wordlift/faceted-search',
1894
-				)
1895
-			);
1896
-		}
1897
-
1898
-		wp_localize_script( 'wl_enabled_blocks', 'wlEnabledBlocks', $enabled_blocks );
1899
-		wp_enqueue_script( 'wl_enabled_blocks' );
1900
-	}
1901
-
1902
-	/**
1903
-	 * Register screens based on the filter.
1904
-	 */
1905
-	public function register_screens() {
1906
-		// Hook the menu to the Download Your Data page.
1907
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1908
-		if ( apply_filters( 'wl_feature__enable__settings-download', true ) ) {
1909
-			Assertions::is_set( $this->download_your_data_page, "`download_your_data_page` can't be null" );
1910
-			add_action(
1911
-				'admin_menu',
1912
-				array(
1913
-					$this->download_your_data_page,
1914
-					'admin_menu',
1915
-				),
1916
-				100,
1917
-				0
1918
-			);
1919
-		}
1920
-
1921
-		Assertions::is_set( $this->entity_type_settings_admin_page, "`entity_type_settings_admin_page` can't be null" );
1922
-		add_action(
1923
-			'admin_menu',
1924
-			array(
1925
-				$this->entity_type_settings_admin_page,
1926
-				'admin_menu',
1927
-			),
1928
-			100,
1929
-			0
1930
-		);
1931
-
1932
-	}
1796
+        $that->loader->add_action( 'pre_get_posts', $that->entity_page_service, 'pre_get_posts', 10, 1 );
1797
+
1798
+        // This hook have to run before the rating service, as otherwise the post might not be a proper entity when rating is done.
1799
+        $that->loader->add_action( 'save_post', $that->entity_type_adapter, 'save_post', 9, 2 );
1800
+
1801
+        // Analytics Script Frontend.
1802
+        if ( apply_filters( 'wl_feature__enable__analytics', true ) && Wordlift_Configuration_Service::get_instance()->is_analytics_enable() ) {
1803
+            $that->loader->add_action( 'wp_enqueue_scripts', $that->analytics_connect, 'enqueue_scripts', 10 );
1804
+        }
1805
+
1806
+    }
1807
+
1808
+    /**
1809
+     * Run the loader to execute all of the hooks with WordPress.
1810
+     *
1811
+     * @since    1.0.0
1812
+     */
1813
+    public function run() {
1814
+        $this->loader->run();
1815
+    }
1816
+
1817
+    /**
1818
+     * The name of the plugin used to uniquely identify it within the context of
1819
+     * WordPress and to define internationalization functionality.
1820
+     *
1821
+     * @return    string    The name of the plugin.
1822
+     * @since     1.0.0
1823
+     */
1824
+    public function get_plugin_name() {
1825
+        return $this->plugin_name;
1826
+    }
1827
+
1828
+    /**
1829
+     * The reference to the class that orchestrates the hooks with the plugin.
1830
+     *
1831
+     * @return    Wordlift_Loader    Orchestrates the hooks of the plugin.
1832
+     * @since     1.0.0
1833
+     */
1834
+    public function get_loader() {
1835
+        return $this->loader;
1836
+    }
1837
+
1838
+    /**
1839
+     * Retrieve the version number of the plugin.
1840
+     *
1841
+     * @return    string    The version number of the plugin.
1842
+     * @since     1.0.0
1843
+     */
1844
+    public function get_version() {
1845
+        return $this->version;
1846
+    }
1847
+
1848
+    /**
1849
+     * Load dependencies for WP-CLI.
1850
+     *
1851
+     * @throws Exception when an error occurs.
1852
+     * @since 3.18.0
1853
+     */
1854
+    private function load_cli_dependencies() {
1855
+
1856
+    }
1857
+
1858
+    public function add_wl_enabled_blocks() {
1859
+        /**
1860
+         * Filter: wl_feature__enable__blocks.
1861
+         *
1862
+         * @param bool whether the blocks needed to be registered, defaults to true.
1863
+         *
1864
+         * @return bool
1865
+         * @since 3.27.6
1866
+         */
1867
+        // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter,WordPress.WP.EnqueuedResourceParameters.MissingVersion
1868
+        wp_register_script( 'wl_enabled_blocks', false );
1869
+
1870
+        $enabled_blocks = array();
1871
+
1872
+        /**
1873
+         * Filter name: wl_feature__enable__product-navigator
1874
+         *
1875
+         * @since 3.32.3
1876
+         */
1877
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1878
+        if ( apply_filters( 'wl_feature__enable__product-navigator', true ) ) {
1879
+            $enabled_blocks[] = 'wordlift/products-navigator';
1880
+        }
1881
+
1882
+        if ( apply_filters( 'wl_feature__enable__blocks', true ) ) {
1883
+            // To intimate JS
1884
+            $enabled_blocks = array_merge(
1885
+                $enabled_blocks,
1886
+                array(
1887
+                    'wordlift/navigator',
1888
+                    'wordlift/chord',
1889
+                    'wordlift/geomap',
1890
+                    'wordlift/timeline',
1891
+                    'wordlift/cloud',
1892
+                    'wordlift/vocabulary',
1893
+                    'wordlift/faceted-search',
1894
+                )
1895
+            );
1896
+        }
1897
+
1898
+        wp_localize_script( 'wl_enabled_blocks', 'wlEnabledBlocks', $enabled_blocks );
1899
+        wp_enqueue_script( 'wl_enabled_blocks' );
1900
+    }
1901
+
1902
+    /**
1903
+     * Register screens based on the filter.
1904
+     */
1905
+    public function register_screens() {
1906
+        // Hook the menu to the Download Your Data page.
1907
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1908
+        if ( apply_filters( 'wl_feature__enable__settings-download', true ) ) {
1909
+            Assertions::is_set( $this->download_your_data_page, "`download_your_data_page` can't be null" );
1910
+            add_action(
1911
+                'admin_menu',
1912
+                array(
1913
+                    $this->download_your_data_page,
1914
+                    'admin_menu',
1915
+                ),
1916
+                100,
1917
+                0
1918
+            );
1919
+        }
1920
+
1921
+        Assertions::is_set( $this->entity_type_settings_admin_page, "`entity_type_settings_admin_page` can't be null" );
1922
+        add_action(
1923
+            'admin_menu',
1924
+            array(
1925
+                $this->entity_type_settings_admin_page,
1926
+                'admin_menu',
1927
+            ),
1928
+            100,
1929
+            0
1930
+        );
1931
+
1932
+    }
1933 1933
 
1934 1934
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-post-to-jsonld-converter.php 1 patch
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -13,214 +13,214 @@
 block discarded – undo
13 13
  */
14 14
 class Wordlift_Entity_Post_To_Jsonld_Converter extends Wordlift_Abstract_Post_To_Jsonld_Converter {
15 15
 
16
-	/**
17
-	 * The {@link Wordlift_Schemaorg_Property_Service} or null if not provided.
18
-	 *
19
-	 * @since 3.20.0
20
-	 * @access private
21
-	 * @var null|Wordlift_Schemaorg_Property_Service The {@link Wordlift_Schemaorg_Property_Service} or null if not provided.
22
-	 */
23
-	private $schemaorg_property_service;
24
-
25
-	/**
26
-	 * The {@link Wordlift_Post_To_Jsonld_Converter} is used to convert entities that also have the `article` term.
27
-	 *
28
-	 * @since 3.25.2
29
-	 * @var \Wordlift_Post_To_Jsonld_Converter $post_to_jsonld_converter The {@link Wordlift_Post_To_Jsonld_Converter} instance.
30
-	 */
31
-	private $post_to_jsonld_converter;
32
-
33
-	/**
34
-	 * Wordlift_Entity_To_Jsonld_Converter constructor.
35
-	 *
36
-	 * @param \Wordlift_Entity_Type_Service        $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
37
-	 * @param \Wordlift_User_Service               $user_service A {@link Wordlift_User_Service} instance.
38
-	 * @param \Wordlift_Attachment_Service         $attachment_service A {@link Wordlift_Attachment_Service} instance.
39
-	 * @param \Wordlift_Property_Getter            $property_getter A {@link Wordlift_Property_Getter} instance.
40
-	 * @param \Wordlift_Schemaorg_Property_Service $schemaorg_property_service A {@link Wordlift_Schemaorg_Property_Service} instance.
41
-	 * @param \Wordlift_Post_To_Jsonld_Converter   $post_to_jsonld_converter The {@link Wordlift_Post_To_Jsonld_Converter} instance.
42
-	 *
43
-	 * @since 3.8.0
44
-	 */
45
-	public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter, $schemaorg_property_service, $post_to_jsonld_converter ) {
46
-		parent::__construct( $entity_type_service, $user_service, $attachment_service, $property_getter );
47
-		$this->schemaorg_property_service = $schemaorg_property_service;
48
-		$this->post_to_jsonld_converter   = $post_to_jsonld_converter;
49
-	}
50
-
51
-	/**
52
-	 * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference
53
-	 * found while processing the post is set in the $references array.
54
-	 *
55
-	 * @param int   $post_id The {@link WP_Post} id.
56
-	 * @param array $references An array of entity references.
57
-	 * @param array $references_infos
58
-	 *
59
-	 * @return array A JSON-LD array.
60
-	 * @since 3.8.0
61
-	 */
62
-	public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null ) {
63
-
64
-		// Get the post instance.
65
-		$post = get_post( $post_id );
66
-		if ( null === $post ) {
67
-			// Post not found.
68
-			return null;
69
-		}
70
-
71
-		// Get the base JSON-LD and the list of entities referenced by this entity.
72
-		if ( has_term( 'article', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $post_id ) ) {
73
-			$jsonld = $this->post_to_jsonld_converter->convert( $post_id, $references, $references_infos, $relations );
74
-		} else {
75
-			$jsonld = parent::convert( $post_id, $references, $references_infos, $relations );
76
-		}
77
-
78
-		// Get the entity name.
79
-		$jsonld['name'] = html_entity_decode( $post->post_title );
80
-
81
-		// 3.13.0, add alternate names.
82
-		$alternative_labels = Wordlift_Entity_Service::get_instance()->get_alternative_labels( $post_id );
83
-		if ( 0 < count( $alternative_labels ) ) {
84
-			$jsonld['alternateName'] = $alternative_labels;
85
-		}
86
-
87
-		// Get the entity `@type` with custom fields set by the Wordlift_Schema_Service.
88
-		//
89
-		// This allows us to gather the basic properties as defined by the `Thing` entity type.
90
-		// Get the configured type custom fields.
91
-		$custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id );
92
-
93
-		if ( isset( $custom_fields ) ) {
94
-			$this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos );
95
-		}
96
-
97
-		/*
16
+    /**
17
+     * The {@link Wordlift_Schemaorg_Property_Service} or null if not provided.
18
+     *
19
+     * @since 3.20.0
20
+     * @access private
21
+     * @var null|Wordlift_Schemaorg_Property_Service The {@link Wordlift_Schemaorg_Property_Service} or null if not provided.
22
+     */
23
+    private $schemaorg_property_service;
24
+
25
+    /**
26
+     * The {@link Wordlift_Post_To_Jsonld_Converter} is used to convert entities that also have the `article` term.
27
+     *
28
+     * @since 3.25.2
29
+     * @var \Wordlift_Post_To_Jsonld_Converter $post_to_jsonld_converter The {@link Wordlift_Post_To_Jsonld_Converter} instance.
30
+     */
31
+    private $post_to_jsonld_converter;
32
+
33
+    /**
34
+     * Wordlift_Entity_To_Jsonld_Converter constructor.
35
+     *
36
+     * @param \Wordlift_Entity_Type_Service        $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
37
+     * @param \Wordlift_User_Service               $user_service A {@link Wordlift_User_Service} instance.
38
+     * @param \Wordlift_Attachment_Service         $attachment_service A {@link Wordlift_Attachment_Service} instance.
39
+     * @param \Wordlift_Property_Getter            $property_getter A {@link Wordlift_Property_Getter} instance.
40
+     * @param \Wordlift_Schemaorg_Property_Service $schemaorg_property_service A {@link Wordlift_Schemaorg_Property_Service} instance.
41
+     * @param \Wordlift_Post_To_Jsonld_Converter   $post_to_jsonld_converter The {@link Wordlift_Post_To_Jsonld_Converter} instance.
42
+     *
43
+     * @since 3.8.0
44
+     */
45
+    public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter, $schemaorg_property_service, $post_to_jsonld_converter ) {
46
+        parent::__construct( $entity_type_service, $user_service, $attachment_service, $property_getter );
47
+        $this->schemaorg_property_service = $schemaorg_property_service;
48
+        $this->post_to_jsonld_converter   = $post_to_jsonld_converter;
49
+    }
50
+
51
+    /**
52
+     * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference
53
+     * found while processing the post is set in the $references array.
54
+     *
55
+     * @param int   $post_id The {@link WP_Post} id.
56
+     * @param array $references An array of entity references.
57
+     * @param array $references_infos
58
+     *
59
+     * @return array A JSON-LD array.
60
+     * @since 3.8.0
61
+     */
62
+    public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null ) {
63
+
64
+        // Get the post instance.
65
+        $post = get_post( $post_id );
66
+        if ( null === $post ) {
67
+            // Post not found.
68
+            return null;
69
+        }
70
+
71
+        // Get the base JSON-LD and the list of entities referenced by this entity.
72
+        if ( has_term( 'article', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $post_id ) ) {
73
+            $jsonld = $this->post_to_jsonld_converter->convert( $post_id, $references, $references_infos, $relations );
74
+        } else {
75
+            $jsonld = parent::convert( $post_id, $references, $references_infos, $relations );
76
+        }
77
+
78
+        // Get the entity name.
79
+        $jsonld['name'] = html_entity_decode( $post->post_title );
80
+
81
+        // 3.13.0, add alternate names.
82
+        $alternative_labels = Wordlift_Entity_Service::get_instance()->get_alternative_labels( $post_id );
83
+        if ( 0 < count( $alternative_labels ) ) {
84
+            $jsonld['alternateName'] = $alternative_labels;
85
+        }
86
+
87
+        // Get the entity `@type` with custom fields set by the Wordlift_Schema_Service.
88
+        //
89
+        // This allows us to gather the basic properties as defined by the `Thing` entity type.
90
+        // Get the configured type custom fields.
91
+        $custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id );
92
+
93
+        if ( isset( $custom_fields ) ) {
94
+            $this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos );
95
+        }
96
+
97
+        /*
98 98
 		 * Get the properties attached to the post.
99 99
 		 *
100 100
 		 * @since 3.20.0 We attach properties directly to the posts.
101 101
 		 *
102 102
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/835
103 103
 		 */
104
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
105
-		if ( apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES ) ) {
106
-			$this->process_post_properties( $jsonld, $post_id );
107
-		}
108
-
109
-		/**
110
-		 * Call the `wl_post_jsonld_array` filter. This filter allows 3rd parties to also modify the references.
111
-		 *
112
-		 * @param array $value {
113
-		 *
114
-		 * @type array $jsonld The JSON-LD structure.
115
-		 * @type int[] $references An array of post IDs.
116
-		 * }
117
-		 * @since 3.25.0
118
-		 *
119
-		 * @see https://www.geeklab.info/2010/04/wordpress-pass-variables-by-reference-with-apply_filter/
120
-		 *
121
-		 * @api
122
-		 */
123
-		$ret_val    = apply_filters(
124
-			'wl_entity_jsonld_array',
125
-			array(
126
-				'jsonld'     => $jsonld,
127
-				'references' => $references,
128
-			),
129
-			$post_id
130
-		);
131
-		$jsonld     = $ret_val['jsonld'];
132
-		$references = $ret_val['references'];
133
-
134
-		/**
135
-		 * Call the `wl_entity_jsonld` filter.
136
-		 *
137
-		 * @param array $jsonld The JSON-LD structure.
138
-		 * @param int $post_id The {@link WP_Post} `id`.
139
-		 * @param array $references The array of referenced entities.
140
-		 *
141
-		 * @since 3.20.0
142
-		 *
143
-		 * @api
144
-		 */
145
-		return apply_filters( 'wl_entity_jsonld', $this->post_process( $jsonld ), $post_id, $references );
146
-	}
147
-
148
-	/**
149
-	 * Process the properties attached to the {@link WP_Post}.
150
-	 *
151
-	 * @param array $jsonld The JSON-LD array.
152
-	 * @param int   $post_id The target {@link WP_Post} id.
153
-	 *
154
-	 * @since 3.20.0
155
-	 */
156
-	private function process_post_properties( &$jsonld, $post_id ) {
157
-
158
-		// Get all the props.
159
-		$props = $this->schemaorg_property_service->get_all( $post_id );
160
-
161
-		// Process all the props.
162
-		foreach ( $props as $name => $instances ) {
163
-
164
-			// Get the values.
165
-			$values = array_map(
166
-				function ( $instance ) {
167
-					return $instance['value'];
168
-				},
169
-				$instances
170
-			);
171
-
172
-			// We might receive empty values, remove them.
173
-			$non_empty_values = array_filter(
174
-				$values,
175
-				function ( $value ) {
176
-					return ! empty( $value );
177
-				}
178
-			);
179
-
180
-			// Skip empty properties.
181
-			if ( empty( $non_empty_values ) ) {
182
-				continue;
183
-			}
184
-
185
-			// @@todo: need to handle maybe Numbers and URLs differently.
186
-			// Make an array a single value when possible.
187
-			$jsonld[ $name ] = self::make_one( $non_empty_values );
188
-		}
189
-
190
-	}
191
-
192
-	/**
193
-	 * Post process the generated JSON to reorganize values which are stored as 1st
194
-	 * level in WP but are really 2nd level.
195
-	 *
196
-	 * @param array $jsonld An array of JSON-LD properties and values.
197
-	 *
198
-	 * @return array The array remapped.
199
-	 * @since 3.8.0
200
-	 */
201
-	public static function post_process( $jsonld ) {
202
-
203
-		foreach ( $jsonld as $key => $value ) {
204
-			if ( 'streetAddress' === $key || 'postalCode' === $key || 'addressLocality' === $key || 'addressRegion' === $key || 'addressCountry' === $key || 'postOfficeBoxNumber' === $key ) {
205
-				$jsonld['address']['@type'] = 'PostalAddress';
206
-				$jsonld['address'][ $key ]  = $value;
207
-				unset( $jsonld[ $key ] );
208
-			}
209
-
210
-			if ( 'latitude' === $key || 'longitude' === $key ) {
211
-				$jsonld['geo']['@type'] = 'GeoCoordinates';
212
-				$jsonld['geo'][ $key ]  = $value;
213
-				unset( $jsonld[ $key ] );
214
-			}
215
-
216
-			if ( 'calories' === $key ) {
217
-				$jsonld['nutrition']['@type'] = 'NutritionInformation';
218
-				$jsonld['nutrition'][ $key ]  = $value;
219
-				unset( $jsonld[ $key ] );
220
-			}
221
-		}
222
-
223
-		return $jsonld;
224
-	}
104
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
105
+        if ( apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES ) ) {
106
+            $this->process_post_properties( $jsonld, $post_id );
107
+        }
108
+
109
+        /**
110
+         * Call the `wl_post_jsonld_array` filter. This filter allows 3rd parties to also modify the references.
111
+         *
112
+         * @param array $value {
113
+         *
114
+         * @type array $jsonld The JSON-LD structure.
115
+         * @type int[] $references An array of post IDs.
116
+         * }
117
+         * @since 3.25.0
118
+         *
119
+         * @see https://www.geeklab.info/2010/04/wordpress-pass-variables-by-reference-with-apply_filter/
120
+         *
121
+         * @api
122
+         */
123
+        $ret_val    = apply_filters(
124
+            'wl_entity_jsonld_array',
125
+            array(
126
+                'jsonld'     => $jsonld,
127
+                'references' => $references,
128
+            ),
129
+            $post_id
130
+        );
131
+        $jsonld     = $ret_val['jsonld'];
132
+        $references = $ret_val['references'];
133
+
134
+        /**
135
+         * Call the `wl_entity_jsonld` filter.
136
+         *
137
+         * @param array $jsonld The JSON-LD structure.
138
+         * @param int $post_id The {@link WP_Post} `id`.
139
+         * @param array $references The array of referenced entities.
140
+         *
141
+         * @since 3.20.0
142
+         *
143
+         * @api
144
+         */
145
+        return apply_filters( 'wl_entity_jsonld', $this->post_process( $jsonld ), $post_id, $references );
146
+    }
147
+
148
+    /**
149
+     * Process the properties attached to the {@link WP_Post}.
150
+     *
151
+     * @param array $jsonld The JSON-LD array.
152
+     * @param int   $post_id The target {@link WP_Post} id.
153
+     *
154
+     * @since 3.20.0
155
+     */
156
+    private function process_post_properties( &$jsonld, $post_id ) {
157
+
158
+        // Get all the props.
159
+        $props = $this->schemaorg_property_service->get_all( $post_id );
160
+
161
+        // Process all the props.
162
+        foreach ( $props as $name => $instances ) {
163
+
164
+            // Get the values.
165
+            $values = array_map(
166
+                function ( $instance ) {
167
+                    return $instance['value'];
168
+                },
169
+                $instances
170
+            );
171
+
172
+            // We might receive empty values, remove them.
173
+            $non_empty_values = array_filter(
174
+                $values,
175
+                function ( $value ) {
176
+                    return ! empty( $value );
177
+                }
178
+            );
179
+
180
+            // Skip empty properties.
181
+            if ( empty( $non_empty_values ) ) {
182
+                continue;
183
+            }
184
+
185
+            // @@todo: need to handle maybe Numbers and URLs differently.
186
+            // Make an array a single value when possible.
187
+            $jsonld[ $name ] = self::make_one( $non_empty_values );
188
+        }
189
+
190
+    }
191
+
192
+    /**
193
+     * Post process the generated JSON to reorganize values which are stored as 1st
194
+     * level in WP but are really 2nd level.
195
+     *
196
+     * @param array $jsonld An array of JSON-LD properties and values.
197
+     *
198
+     * @return array The array remapped.
199
+     * @since 3.8.0
200
+     */
201
+    public static function post_process( $jsonld ) {
202
+
203
+        foreach ( $jsonld as $key => $value ) {
204
+            if ( 'streetAddress' === $key || 'postalCode' === $key || 'addressLocality' === $key || 'addressRegion' === $key || 'addressCountry' === $key || 'postOfficeBoxNumber' === $key ) {
205
+                $jsonld['address']['@type'] = 'PostalAddress';
206
+                $jsonld['address'][ $key ]  = $value;
207
+                unset( $jsonld[ $key ] );
208
+            }
209
+
210
+            if ( 'latitude' === $key || 'longitude' === $key ) {
211
+                $jsonld['geo']['@type'] = 'GeoCoordinates';
212
+                $jsonld['geo'][ $key ]  = $value;
213
+                unset( $jsonld[ $key ] );
214
+            }
215
+
216
+            if ( 'calories' === $key ) {
217
+                $jsonld['nutrition']['@type'] = 'NutritionInformation';
218
+                $jsonld['nutrition'][ $key ]  = $value;
219
+                unset( $jsonld[ $key ] );
220
+            }
221
+        }
222
+
223
+        return $jsonld;
224
+    }
225 225
 
226 226
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-postid-to-jsonld-converter.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -16,56 +16,56 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Postid_To_Jsonld_Converter implements Wordlift_Post_Converter {
18 18
 
19
-	private $entity_post_to_jsonld_converter;
20
-	private $post_to_jsonld_converter;
19
+    private $entity_post_to_jsonld_converter;
20
+    private $post_to_jsonld_converter;
21 21
 
22
-	/**
23
-	 * A {@link Wordlift_Log_Service} instance.
24
-	 *
25
-	 * @since  3.16.0
26
-	 * @access private
27
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
28
-	 */
29
-	private $log;
22
+    /**
23
+     * A {@link Wordlift_Log_Service} instance.
24
+     *
25
+     * @since  3.16.0
26
+     * @access private
27
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
28
+     */
29
+    private $log;
30 30
 
31
-	/**
32
-	 * Wordlift_Entity_To_Jsonld_Converter constructor.
33
-	 *
34
-	 * @param \Wordlift_Entity_Post_To_Jsonld_Converter $entity_post_to_jsonld_converter
35
-	 * @param \Wordlift_Post_To_Jsonld_Converter        $post_to_jsonld_converter
36
-	 *
37
-	 * @since 3.8.0
38
-	 */
39
-	public function __construct( $entity_post_to_jsonld_converter, $post_to_jsonld_converter ) {
31
+    /**
32
+     * Wordlift_Entity_To_Jsonld_Converter constructor.
33
+     *
34
+     * @param \Wordlift_Entity_Post_To_Jsonld_Converter $entity_post_to_jsonld_converter
35
+     * @param \Wordlift_Post_To_Jsonld_Converter        $post_to_jsonld_converter
36
+     *
37
+     * @since 3.8.0
38
+     */
39
+    public function __construct( $entity_post_to_jsonld_converter, $post_to_jsonld_converter ) {
40 40
 
41
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
41
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
42 42
 
43
-		$this->entity_post_to_jsonld_converter = $entity_post_to_jsonld_converter;
44
-		$this->post_to_jsonld_converter        = $post_to_jsonld_converter;
43
+        $this->entity_post_to_jsonld_converter = $entity_post_to_jsonld_converter;
44
+        $this->post_to_jsonld_converter        = $post_to_jsonld_converter;
45 45
 
46
-	}
46
+    }
47 47
 
48
-	/**
49
-	 * Convert a post to JSON-LD.
50
-	 *
51
-	 * @param string $post_id A post id (post or entity).
52
-	 * @param array  $references
53
-	 * @param array  $relations
54
-	 *
55
-	 * @return array|NULL A JSON-LD array representation of the post with the provided id, or NULL if not found.
56
-	 * @since 3.8.0
57
-	 */
58
-	public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null ) {
48
+    /**
49
+     * Convert a post to JSON-LD.
50
+     *
51
+     * @param string $post_id A post id (post or entity).
52
+     * @param array  $references
53
+     * @param array  $relations
54
+     *
55
+     * @return array|NULL A JSON-LD array representation of the post with the provided id, or NULL if not found.
56
+     * @since 3.8.0
57
+     */
58
+    public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null ) {
59 59
 
60
-		$this->log->trace( "Converting post $post_id..." );
60
+        $this->log->trace( "Converting post $post_id..." );
61 61
 
62
-		$entity_service = Wordlift_Entity_Service::get_instance();
62
+        $entity_service = Wordlift_Entity_Service::get_instance();
63 63
 
64
-		return $entity_service->is_entity( $post_id )
65
-			// Entity.
66
-			? $this->entity_post_to_jsonld_converter->convert( $post_id, $references, $references_infos, $relations )
67
-			// Post/Page.
68
-			: $this->post_to_jsonld_converter->convert( $post_id, $references, $references_infos, $relations );
69
-	}
64
+        return $entity_service->is_entity( $post_id )
65
+            // Entity.
66
+            ? $this->entity_post_to_jsonld_converter->convert( $post_id, $references, $references_infos, $relations )
67
+            // Post/Page.
68
+            : $this->post_to_jsonld_converter->convert( $post_id, $references, $references_infos, $relations );
69
+    }
70 70
 
71 71
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-service.php 1 patch
Indentation   +586 added lines, -586 removed lines patch added patch discarded remove patch
@@ -21,507 +21,507 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Wordlift_Entity_Service {
23 23
 
24
-	/**
25
-	 * The Log service.
26
-	 *
27
-	 * @since  3.2.0
28
-	 * @access private
29
-	 * @var \Wordlift_Log_Service $log The Log service.
30
-	 */
31
-	private $log;
32
-
33
-	/**
34
-	 * The {@link Wordlift_Relation_Service} instance.
35
-	 *
36
-	 * @since  3.15.0
37
-	 * @access private
38
-	 * @var \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
39
-	 */
40
-	private $relation_service;
41
-
42
-	/**
43
-	 * The {@link Wordlift_Entity_Uri_Service} instance.
44
-	 *
45
-	 * @since  3.16.3
46
-	 * @access private
47
-	 * @var \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance.
48
-	 */
49
-	private $entity_uri_service;
50
-
51
-	/**
52
-	 * The entity post type name.
53
-	 *
54
-	 * @since 3.1.0
55
-	 */
56
-	const TYPE_NAME = 'entity';
57
-
58
-	/**
59
-	 * The alternative label meta key.
60
-	 *
61
-	 * @since 3.2.0
62
-	 */
63
-	const ALTERNATIVE_LABEL_META_KEY = '_wl_alt_label';
64
-
65
-	/**
66
-	 * The alternative label input template.
67
-	 *
68
-	 * @since 3.2.0
69
-	 */
70
-	// TODO: this should be moved to a class that deals with HTML code.
71
-	const ALTERNATIVE_LABEL_INPUT_TEMPLATE = '<div class="wl-alternative-label">
24
+    /**
25
+     * The Log service.
26
+     *
27
+     * @since  3.2.0
28
+     * @access private
29
+     * @var \Wordlift_Log_Service $log The Log service.
30
+     */
31
+    private $log;
32
+
33
+    /**
34
+     * The {@link Wordlift_Relation_Service} instance.
35
+     *
36
+     * @since  3.15.0
37
+     * @access private
38
+     * @var \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
39
+     */
40
+    private $relation_service;
41
+
42
+    /**
43
+     * The {@link Wordlift_Entity_Uri_Service} instance.
44
+     *
45
+     * @since  3.16.3
46
+     * @access private
47
+     * @var \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance.
48
+     */
49
+    private $entity_uri_service;
50
+
51
+    /**
52
+     * The entity post type name.
53
+     *
54
+     * @since 3.1.0
55
+     */
56
+    const TYPE_NAME = 'entity';
57
+
58
+    /**
59
+     * The alternative label meta key.
60
+     *
61
+     * @since 3.2.0
62
+     */
63
+    const ALTERNATIVE_LABEL_META_KEY = '_wl_alt_label';
64
+
65
+    /**
66
+     * The alternative label input template.
67
+     *
68
+     * @since 3.2.0
69
+     */
70
+    // TODO: this should be moved to a class that deals with HTML code.
71
+    const ALTERNATIVE_LABEL_INPUT_TEMPLATE = '<div class="wl-alternative-label">
72 72
                 <label class="screen-reader-text" id="wl-alternative-label-prompt-text" for="wl-alternative-label">Enter alternative label here</label>
73 73
                 <input name="wl_alternative_label[]" size="30" value="%s" id="wl-alternative-label" type="text">
74 74
                 <button class="button wl-delete-button">%s</button>
75 75
                 </div>';
76 76
 
77
-	/**
78
-	 * Create a Wordlift_Entity_Service instance.
79
-	 *
80
-	 * @throws Exception if the `$content_service` is not of the `Content_Service` type.
81
-	 * @since 3.2.0
82
-	 */
83
-	protected function __construct() {
84
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
85
-
86
-		$this->entity_uri_service = Wordlift_Entity_Uri_Service::get_instance();
87
-		$this->relation_service   = Wordlift_Relation_Service::get_instance();
88
-
89
-	}
90
-
91
-	/**
92
-	 * A singleton instance of the Entity service.
93
-	 *
94
-	 * @since  3.2.0
95
-	 * @access private
96
-	 * @var Wordlift_Entity_Service $instance A singleton instance of the Entity service.
97
-	 */
98
-	private static $instance = null;
99
-
100
-	/**
101
-	 * Get the singleton instance of the Entity service.
102
-	 *
103
-	 * @return Wordlift_Entity_Service The singleton instance of the Entity service.
104
-	 * @since 3.2.0
105
-	 */
106
-	public static function get_instance() {
107
-
108
-		if ( ! isset( self::$instance ) ) {
109
-			self::$instance = new self();
110
-		}
111
-
112
-		return self::$instance;
113
-	}
114
-
115
-	/**
116
-	 * Determines whether a post is an entity or not. Entity is in this context
117
-	 * something which is not an article.
118
-	 *
119
-	 * @param int $post_id A post id.
120
-	 *
121
-	 * @return bool Return true if the post is an entity otherwise false.
122
-	 * @since 3.1.0
123
-	 */
124
-	public function is_entity( $post_id ) {
125
-
126
-		// Improve performance by giving for granted that a product is an entity.
127
-		if ( 'product' === get_post_type( $post_id ) ) {
128
-			return true;
129
-		}
130
-
131
-		$terms = wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
132
-
133
-		if ( is_wp_error( $terms ) ) {
134
-			$this->log->error( "Cannot get the terms for post $post_id: " . $terms->get_error_message() );
135
-
136
-			return false;
137
-		}
138
-
139
-		if ( empty( $terms ) ) {
140
-			return false;
141
-		}
142
-
143
-		/*
77
+    /**
78
+     * Create a Wordlift_Entity_Service instance.
79
+     *
80
+     * @throws Exception if the `$content_service` is not of the `Content_Service` type.
81
+     * @since 3.2.0
82
+     */
83
+    protected function __construct() {
84
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
85
+
86
+        $this->entity_uri_service = Wordlift_Entity_Uri_Service::get_instance();
87
+        $this->relation_service   = Wordlift_Relation_Service::get_instance();
88
+
89
+    }
90
+
91
+    /**
92
+     * A singleton instance of the Entity service.
93
+     *
94
+     * @since  3.2.0
95
+     * @access private
96
+     * @var Wordlift_Entity_Service $instance A singleton instance of the Entity service.
97
+     */
98
+    private static $instance = null;
99
+
100
+    /**
101
+     * Get the singleton instance of the Entity service.
102
+     *
103
+     * @return Wordlift_Entity_Service The singleton instance of the Entity service.
104
+     * @since 3.2.0
105
+     */
106
+    public static function get_instance() {
107
+
108
+        if ( ! isset( self::$instance ) ) {
109
+            self::$instance = new self();
110
+        }
111
+
112
+        return self::$instance;
113
+    }
114
+
115
+    /**
116
+     * Determines whether a post is an entity or not. Entity is in this context
117
+     * something which is not an article.
118
+     *
119
+     * @param int $post_id A post id.
120
+     *
121
+     * @return bool Return true if the post is an entity otherwise false.
122
+     * @since 3.1.0
123
+     */
124
+    public function is_entity( $post_id ) {
125
+
126
+        // Improve performance by giving for granted that a product is an entity.
127
+        if ( 'product' === get_post_type( $post_id ) ) {
128
+            return true;
129
+        }
130
+
131
+        $terms = wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
132
+
133
+        if ( is_wp_error( $terms ) ) {
134
+            $this->log->error( "Cannot get the terms for post $post_id: " . $terms->get_error_message() );
135
+
136
+            return false;
137
+        }
138
+
139
+        if ( empty( $terms ) ) {
140
+            return false;
141
+        }
142
+
143
+        /*
144 144
 		 * We don't consider an `article` to be an entity.
145 145
 		 *
146 146
 		 * @since 3.20.0 At least one associated mustn't be an `article`.
147 147
 		 *
148 148
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/835
149 149
 		 */
150
-		foreach ( $terms as $term ) {
151
-			if ( 1 !== preg_match( '~(^|-)article$~', $term->slug ) ) {
152
-				return true;
153
-			}
154
-		}
155
-
156
-		return false;
157
-	}
158
-
159
-	/**
160
-	 * Get the proper classification scope for a given entity post
161
-	 *
162
-	 * @param integer $post_id An entity post id.
163
-	 *
164
-	 * @param string  $default The default classification scope, `what` if not
165
-	 *                             provided.
166
-	 *
167
-	 * @return string Returns a classification scope (e.g. 'what').
168
-	 * @since 3.5.0
169
-	 */
170
-	public function get_classification_scope_for( $post_id, $default = WL_WHAT_RELATION ) {
171
-
172
-		if ( false === $this->is_entity( $post_id ) ) {
173
-			return $default;
174
-		}
175
-
176
-		// Retrieve the entity type
177
-		$entity_type_arr = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
178
-		$entity_type     = str_replace( 'wl-', '', $entity_type_arr['css_class'] );
179
-		// Retrieve classification boxes configuration
180
-		// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
181
-		$classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES );
182
-		foreach ( $classification_boxes as $cb ) {
183
-			if ( in_array( $entity_type, $cb['registeredTypes'], true ) ) {
184
-				return $cb['id'];
185
-			}
186
-		}
187
-
188
-		return $default;
189
-	}
190
-
191
-	/**
192
-	 * Check whether a {@link WP_Post} is used.
193
-	 *
194
-	 * @param int $post_id The {@link WP_Post}'s id.
195
-	 *
196
-	 * @return bool|null Null if it's not an entity, otherwise true if it's used.
197
-	 */
198
-	public function is_used( $post_id ) {
199
-
200
-		if ( false === $this->is_entity( $post_id ) ) {
201
-			return null;
202
-		}
203
-		// Retrieve the post
204
-		$entity = get_post( $post_id );
205
-
206
-		global $wpdb;
207
-
208
-		// Perform the query
209
-		$relation_instances = (int) $wpdb->get_var(
210
-			$wpdb->prepare(
211
-				"SELECT COUNT(*) FROM {$wpdb->prefix}wl_relation_instances WHERE  object_id = %d",
212
-				$entity->ID
213
-			)
214
-		);
215
-		// If there is at least one relation instance for the current entity, then it's used
216
-		if ( 0 < $relation_instances ) {
217
-			return true;
218
-		}
219
-
220
-		// Perform the query
221
-		$meta_instances = (int) $wpdb->get_var(
222
-			$wpdb->prepare(
223
-				"SELECT COUNT(*) FROM $wpdb->postmeta WHERE post_id != %d AND meta_value = %s",
224
-				$entity->ID,
225
-				wl_get_entity_uri( $entity->ID )
226
-			)
227
-		);
228
-
229
-		// If there is at least one meta that refers the current entity uri, then current entity is used
230
-		if ( 0 < $meta_instances ) {
231
-			return true;
232
-		}
233
-
234
-		// If we are here, it means the current entity is not used at the moment
235
-		return false;
236
-	}
237
-
238
-	/**
239
-	 * Find entity posts by the entity URI. Entity as searched by their entity URI or same as.
240
-	 *
241
-	 * @param string $uri The entity URI.
242
-	 *
243
-	 * @return WP_Post|null A WP_Post instance or null if not found.
244
-	 * @deprecated in favor of Wordlift_Entity_Uri_Service->get_entity( $uri );
245
-	 *
246
-	 * @since      3.16.3 deprecated in favor of Wordlift_Entity_Uri_Service->get_entity( $uri );
247
-	 * @since      3.2.0
248
-	 */
249
-	public function get_entity_post_by_uri( $uri ) {
250
-
251
-		return $this->entity_uri_service->get_entity( $uri );
252
-	}
253
-
254
-	/**
255
-	 * Fires once a post has been saved. This function uses the $_REQUEST, therefore
256
-	 * we check that the post we're saving is the current post.
257
-	 *
258
-	 * This function is called by a hook, so we're not the ones that need to check the `nonce`.
259
-	 *
260
-	 * @see   https://github.com/insideout10/wordlift-plugin/issues/363
261
-	 *
262
-	 * @since 3.2.0
263
-	 *
264
-	 * @param int     $post_id Post ID.
265
-	 * @param WP_Post $post Post object.
266
-	 */
267
-	public function save_post( $post_id, $post ) {
268
-		// Avoid doing anything if post is autosave or a revision.
269
-		if ( wp_is_post_autosave( $post ) || wp_is_post_revision( $post ) ) {
270
-			return;
271
-		}
272
-
273
-		// We expect a numeric value here.
274
-		if ( ! isset( $_REQUEST['post_ID'] ) || ! is_numeric( $_REQUEST['post_ID'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
275
-			return;
276
-		}
277
-
278
-		// Get the numeric post ID from the request.
279
-		$request_post_id = intval( $_REQUEST['post_ID'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
280
-
281
-		// We're setting the alternative label that have been provided via the UI
282
-		// (in fact we're using $_REQUEST), while save_post may be also called
283
-		// programmatically by some other function: we need to check therefore if
284
-		// the $post_id in the save_post call matches the post id set in the request.
285
-		//
286
-		// If this is not the current post being saved or if it's not an entity, return.
287
-		if ( $request_post_id !== $post_id || ! $this->is_entity( $post_id ) ) {
288
-			return;
289
-		}
290
-
291
-		if ( isset( $_REQUEST['wl_alternative_label'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
292
-			$data = filter_var_array( $_REQUEST, array( 'wl_alternative_label' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
293
-			// Get the alt labels from the request (or empty array).
294
-			$alt_labels = isset( $data['wl_alternative_label'] ) ? $data['wl_alternative_label'] : array();
295
-			// This is via classic editor, so set the alternative labels.
296
-			$this->set_alternative_labels( $post_id, $alt_labels );
297
-		}
298
-
299
-	}
300
-
301
-	/**
302
-	 * Set the alternative labels.
303
-	 *
304
-	 * @param int   $post_id The post id.
305
-	 * @param array $alt_labels An array of labels.
306
-	 *
307
-	 * @since 3.2.0
308
-	 */
309
-	public function set_alternative_labels( $post_id, $alt_labels ) {
310
-
311
-		// Bail out if post id is not numeric. We add this check as we found a WP install that was sending a WP_Error
312
-		// instead of post id.
313
-		if ( ! is_numeric( $post_id ) ) {
314
-			return;
315
-		}
316
-
317
-		// Force $alt_labels to be an array
318
-		if ( ! is_array( $alt_labels ) ) {
319
-			$alt_labels = array( $alt_labels );
320
-		}
321
-
322
-		$this->log->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . ' ]' );
323
-
324
-		// Delete all the existing alternate labels.
325
-		delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
326
-
327
-		// Save only unique synonymns.
328
-		$alt_labels = array_unique( $alt_labels );
329
-
330
-		// Set the alternative labels.
331
-		foreach ( $alt_labels as $alt_label ) {
332
-
333
-			// Strip html code from synonym.
334
-			$alt_label = wp_strip_all_tags( $alt_label );
335
-
336
-			if ( ! empty( $alt_label ) ) {
337
-				add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, (string) $alt_label );
338
-			}
339
-		}
340
-
341
-	}
342
-
343
-	public function append_alternative_labels( $post_id, $labels_to_append ) {
344
-
345
-		$merged_labels = $this->get_alternative_labels( $post_id );
346
-
347
-		// Append new synonyms to the end.
348
-		$merged_labels = array_merge( $merged_labels, $labels_to_append );
349
-
350
-		$this->set_alternative_labels( $post_id, $merged_labels );
351
-
352
-	}
353
-
354
-	/**
355
-	 * Retrieve the alternate labels.
356
-	 *
357
-	 * @param int $post_id Post id.
358
-	 *
359
-	 * @return mixed An array  of alternative labels.
360
-	 * @since 3.2.0
361
-	 */
362
-	public function get_alternative_labels( $post_id ) {
363
-
364
-		return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
365
-	}
366
-
367
-	/**
368
-	 * Retrieve the labels for an entity, i.e. the title + the synonyms.
369
-	 *
370
-	 * @param int $id The entity {@link WP_Post} id.
371
-	 * @param int $object_type The object type {@link Object_Type_Enum}
372
-	 *
373
-	 * @return array An array with the entity title and labels.
374
-	 * @since 3.12.0
375
-	 */
376
-	public function get_labels( $id, $object_type = Object_Type_Enum::POST ) {
377
-		if ( Object_Type_Enum::POST === $object_type ) {
378
-			return array_merge( (array) get_the_title( $id ), $this->get_alternative_labels( $id ) );
379
-		}
380
-
381
-		if ( Object_Type_Enum::TERM === $object_type ) {
382
-			$term = get_term( $id );
383
-			if ( ! is_a( $term, 'WP_Term' ) ) {
384
-				return array();
385
-			}
386
-
387
-			// @@todo add support for terms' synonyms.
388
-			return (array) $term->name;
389
-		}
390
-
391
-		return array();
392
-	}
393
-
394
-	/**
395
-	 * Fires before the permalink field in the edit form (this event is available in WP from 4.1.0).
396
-	 *
397
-	 * @param WP_Post $post Post object.
398
-	 *
399
-	 * @since 3.2.0
400
-	 */
401
-	public function edit_form_before_permalink( $post ) {
402
-
403
-		// If it's not an entity, return.
404
-		if ( ! $this->is_entity( $post->ID ) ) {
405
-			return;
406
-		}
407
-
408
-		// If disabled by filter, return.
409
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
410
-		if ( ! apply_filters( 'wl_feature__enable__add-synonyms', true ) ) {
411
-			return;
412
-		}
413
-
414
-		// Print the input template.
415
-		Wordlift_UI_Service::print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
416
-
417
-		// Print all the currently set alternative labels.
418
-		foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) {
419
-
420
-			echo wp_kses( $this->get_alternative_label_input( $alt_label ), Wordlift_UI_Service::get_template_allowed_html() );
421
-
422
-		};
423
-
424
-		// Print the button.
425
-		Wordlift_UI_Service::print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
426
-
427
-	}
428
-
429
-	public function get_uri( $object_id, $type = Object_Type_Enum::POST ) {
430
-		$content_service = Wordpress_Content_Service::get_instance();
431
-		$entity_id       = $content_service->get_entity_id( new Wordpress_Content_Id( $object_id, $type ) );
432
-		$dataset_uri     = Wordlift_Configuration_Service::get_instance()->get_dataset_uri();
433
-
434
-		if ( ! isset( $entity_id ) ||
435
-			 ( ! empty( $dataset_uri ) && 0 !== strpos( $entity_id, $dataset_uri ) ) ) {
436
-			$rel_uri = Entity_Uri_Generator::create_uri( $type, $object_id );
437
-			try {
438
-				$content_service->set_entity_id( new Wordpress_Content_Id( $object_id, $type ), $rel_uri );
439
-				$entity_id = $content_service->get_entity_id( new Wordpress_Content_Id( $object_id, $type ) );
440
-			} catch ( Exception $e ) {
441
-				return null;
442
-			}
443
-		}
444
-
445
-		return $entity_id;
446
-	}
447
-
448
-	/**
449
-	 * Get the alternative label input HTML code.
450
-	 *
451
-	 * @param string $value The input value.
452
-	 *
453
-	 * @return string The input HTML code.
454
-	 * @since 3.2.0
455
-	 */
456
-	private function get_alternative_label_input( $value = '' ) {
457
-
458
-		return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), esc_html__( 'Delete', 'wordlift' ) );
459
-	}
460
-
461
-	/**
462
-	 * Get the number of entity posts published in this blog.
463
-	 *
464
-	 * @return int The number of published entity posts.
465
-	 * @since 3.6.0
466
-	 */
467
-	public function count() {
468
-		global $wpdb;
469
-
470
-		// Try to get the count from the transient.
471
-		$count = get_transient( '_wl_entity_service__count' );
472
-		if ( false !== $count ) {
473
-			return $count;
474
-		}
475
-
476
-		// Query the count.
477
-		$count = $wpdb->get_var(
478
-			$wpdb->prepare(
479
-				'SELECT COUNT( DISTINCT( tr.object_id ) )'
480
-				. " FROM {$wpdb->term_relationships} tr"
481
-				. " INNER JOIN {$wpdb->term_taxonomy} tt"
482
-				. '  ON tt.taxonomy = %s AND tt.term_taxonomy_id = tr.term_taxonomy_id'
483
-				. " INNER JOIN {$wpdb->terms} t"
484
-				. '  ON t.term_id = tt.term_id AND t.name != %s',
485
-				Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
486
-				'article'
487
-			)
488
-		);
489
-
490
-		// Store the count in cache.
491
-		set_transient( '_wl_entity_service__count', $count, 900 );
492
-
493
-		return $count;
494
-	}
495
-
496
-	/**
497
-	 * Add the entity filtering criterias to the arguments for a `get_posts`
498
-	 * call.
499
-	 *
500
-	 * @param array $args The arguments for a `get_posts` call.
501
-	 *
502
-	 * @return array The arguments for a `get_posts` call.
503
-	 * @since 3.15.0
504
-	 */
505
-	public static function add_criterias( $args ) {
506
-
507
-		// Build an optimal tax-query.
508
-		$tax_query = array(
509
-			'relation' => 'AND',
510
-			array(
511
-				'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
512
-				'operator' => 'EXISTS',
513
-			),
514
-			array(
515
-				'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
516
-				'field'    => 'slug',
517
-				'terms'    => 'article',
518
-				'operator' => 'NOT IN',
519
-			),
520
-		);
521
-
522
-		return $args + array(
523
-			'post_type' => self::valid_entity_post_types(),
524
-			/*
150
+        foreach ( $terms as $term ) {
151
+            if ( 1 !== preg_match( '~(^|-)article$~', $term->slug ) ) {
152
+                return true;
153
+            }
154
+        }
155
+
156
+        return false;
157
+    }
158
+
159
+    /**
160
+     * Get the proper classification scope for a given entity post
161
+     *
162
+     * @param integer $post_id An entity post id.
163
+     *
164
+     * @param string  $default The default classification scope, `what` if not
165
+     *                             provided.
166
+     *
167
+     * @return string Returns a classification scope (e.g. 'what').
168
+     * @since 3.5.0
169
+     */
170
+    public function get_classification_scope_for( $post_id, $default = WL_WHAT_RELATION ) {
171
+
172
+        if ( false === $this->is_entity( $post_id ) ) {
173
+            return $default;
174
+        }
175
+
176
+        // Retrieve the entity type
177
+        $entity_type_arr = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
178
+        $entity_type     = str_replace( 'wl-', '', $entity_type_arr['css_class'] );
179
+        // Retrieve classification boxes configuration
180
+        // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
181
+        $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES );
182
+        foreach ( $classification_boxes as $cb ) {
183
+            if ( in_array( $entity_type, $cb['registeredTypes'], true ) ) {
184
+                return $cb['id'];
185
+            }
186
+        }
187
+
188
+        return $default;
189
+    }
190
+
191
+    /**
192
+     * Check whether a {@link WP_Post} is used.
193
+     *
194
+     * @param int $post_id The {@link WP_Post}'s id.
195
+     *
196
+     * @return bool|null Null if it's not an entity, otherwise true if it's used.
197
+     */
198
+    public function is_used( $post_id ) {
199
+
200
+        if ( false === $this->is_entity( $post_id ) ) {
201
+            return null;
202
+        }
203
+        // Retrieve the post
204
+        $entity = get_post( $post_id );
205
+
206
+        global $wpdb;
207
+
208
+        // Perform the query
209
+        $relation_instances = (int) $wpdb->get_var(
210
+            $wpdb->prepare(
211
+                "SELECT COUNT(*) FROM {$wpdb->prefix}wl_relation_instances WHERE  object_id = %d",
212
+                $entity->ID
213
+            )
214
+        );
215
+        // If there is at least one relation instance for the current entity, then it's used
216
+        if ( 0 < $relation_instances ) {
217
+            return true;
218
+        }
219
+
220
+        // Perform the query
221
+        $meta_instances = (int) $wpdb->get_var(
222
+            $wpdb->prepare(
223
+                "SELECT COUNT(*) FROM $wpdb->postmeta WHERE post_id != %d AND meta_value = %s",
224
+                $entity->ID,
225
+                wl_get_entity_uri( $entity->ID )
226
+            )
227
+        );
228
+
229
+        // If there is at least one meta that refers the current entity uri, then current entity is used
230
+        if ( 0 < $meta_instances ) {
231
+            return true;
232
+        }
233
+
234
+        // If we are here, it means the current entity is not used at the moment
235
+        return false;
236
+    }
237
+
238
+    /**
239
+     * Find entity posts by the entity URI. Entity as searched by their entity URI or same as.
240
+     *
241
+     * @param string $uri The entity URI.
242
+     *
243
+     * @return WP_Post|null A WP_Post instance or null if not found.
244
+     * @deprecated in favor of Wordlift_Entity_Uri_Service->get_entity( $uri );
245
+     *
246
+     * @since      3.16.3 deprecated in favor of Wordlift_Entity_Uri_Service->get_entity( $uri );
247
+     * @since      3.2.0
248
+     */
249
+    public function get_entity_post_by_uri( $uri ) {
250
+
251
+        return $this->entity_uri_service->get_entity( $uri );
252
+    }
253
+
254
+    /**
255
+     * Fires once a post has been saved. This function uses the $_REQUEST, therefore
256
+     * we check that the post we're saving is the current post.
257
+     *
258
+     * This function is called by a hook, so we're not the ones that need to check the `nonce`.
259
+     *
260
+     * @see   https://github.com/insideout10/wordlift-plugin/issues/363
261
+     *
262
+     * @since 3.2.0
263
+     *
264
+     * @param int     $post_id Post ID.
265
+     * @param WP_Post $post Post object.
266
+     */
267
+    public function save_post( $post_id, $post ) {
268
+        // Avoid doing anything if post is autosave or a revision.
269
+        if ( wp_is_post_autosave( $post ) || wp_is_post_revision( $post ) ) {
270
+            return;
271
+        }
272
+
273
+        // We expect a numeric value here.
274
+        if ( ! isset( $_REQUEST['post_ID'] ) || ! is_numeric( $_REQUEST['post_ID'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
275
+            return;
276
+        }
277
+
278
+        // Get the numeric post ID from the request.
279
+        $request_post_id = intval( $_REQUEST['post_ID'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
280
+
281
+        // We're setting the alternative label that have been provided via the UI
282
+        // (in fact we're using $_REQUEST), while save_post may be also called
283
+        // programmatically by some other function: we need to check therefore if
284
+        // the $post_id in the save_post call matches the post id set in the request.
285
+        //
286
+        // If this is not the current post being saved or if it's not an entity, return.
287
+        if ( $request_post_id !== $post_id || ! $this->is_entity( $post_id ) ) {
288
+            return;
289
+        }
290
+
291
+        if ( isset( $_REQUEST['wl_alternative_label'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
292
+            $data = filter_var_array( $_REQUEST, array( 'wl_alternative_label' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
293
+            // Get the alt labels from the request (or empty array).
294
+            $alt_labels = isset( $data['wl_alternative_label'] ) ? $data['wl_alternative_label'] : array();
295
+            // This is via classic editor, so set the alternative labels.
296
+            $this->set_alternative_labels( $post_id, $alt_labels );
297
+        }
298
+
299
+    }
300
+
301
+    /**
302
+     * Set the alternative labels.
303
+     *
304
+     * @param int   $post_id The post id.
305
+     * @param array $alt_labels An array of labels.
306
+     *
307
+     * @since 3.2.0
308
+     */
309
+    public function set_alternative_labels( $post_id, $alt_labels ) {
310
+
311
+        // Bail out if post id is not numeric. We add this check as we found a WP install that was sending a WP_Error
312
+        // instead of post id.
313
+        if ( ! is_numeric( $post_id ) ) {
314
+            return;
315
+        }
316
+
317
+        // Force $alt_labels to be an array
318
+        if ( ! is_array( $alt_labels ) ) {
319
+            $alt_labels = array( $alt_labels );
320
+        }
321
+
322
+        $this->log->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . ' ]' );
323
+
324
+        // Delete all the existing alternate labels.
325
+        delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
326
+
327
+        // Save only unique synonymns.
328
+        $alt_labels = array_unique( $alt_labels );
329
+
330
+        // Set the alternative labels.
331
+        foreach ( $alt_labels as $alt_label ) {
332
+
333
+            // Strip html code from synonym.
334
+            $alt_label = wp_strip_all_tags( $alt_label );
335
+
336
+            if ( ! empty( $alt_label ) ) {
337
+                add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, (string) $alt_label );
338
+            }
339
+        }
340
+
341
+    }
342
+
343
+    public function append_alternative_labels( $post_id, $labels_to_append ) {
344
+
345
+        $merged_labels = $this->get_alternative_labels( $post_id );
346
+
347
+        // Append new synonyms to the end.
348
+        $merged_labels = array_merge( $merged_labels, $labels_to_append );
349
+
350
+        $this->set_alternative_labels( $post_id, $merged_labels );
351
+
352
+    }
353
+
354
+    /**
355
+     * Retrieve the alternate labels.
356
+     *
357
+     * @param int $post_id Post id.
358
+     *
359
+     * @return mixed An array  of alternative labels.
360
+     * @since 3.2.0
361
+     */
362
+    public function get_alternative_labels( $post_id ) {
363
+
364
+        return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
365
+    }
366
+
367
+    /**
368
+     * Retrieve the labels for an entity, i.e. the title + the synonyms.
369
+     *
370
+     * @param int $id The entity {@link WP_Post} id.
371
+     * @param int $object_type The object type {@link Object_Type_Enum}
372
+     *
373
+     * @return array An array with the entity title and labels.
374
+     * @since 3.12.0
375
+     */
376
+    public function get_labels( $id, $object_type = Object_Type_Enum::POST ) {
377
+        if ( Object_Type_Enum::POST === $object_type ) {
378
+            return array_merge( (array) get_the_title( $id ), $this->get_alternative_labels( $id ) );
379
+        }
380
+
381
+        if ( Object_Type_Enum::TERM === $object_type ) {
382
+            $term = get_term( $id );
383
+            if ( ! is_a( $term, 'WP_Term' ) ) {
384
+                return array();
385
+            }
386
+
387
+            // @@todo add support for terms' synonyms.
388
+            return (array) $term->name;
389
+        }
390
+
391
+        return array();
392
+    }
393
+
394
+    /**
395
+     * Fires before the permalink field in the edit form (this event is available in WP from 4.1.0).
396
+     *
397
+     * @param WP_Post $post Post object.
398
+     *
399
+     * @since 3.2.0
400
+     */
401
+    public function edit_form_before_permalink( $post ) {
402
+
403
+        // If it's not an entity, return.
404
+        if ( ! $this->is_entity( $post->ID ) ) {
405
+            return;
406
+        }
407
+
408
+        // If disabled by filter, return.
409
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
410
+        if ( ! apply_filters( 'wl_feature__enable__add-synonyms', true ) ) {
411
+            return;
412
+        }
413
+
414
+        // Print the input template.
415
+        Wordlift_UI_Service::print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
416
+
417
+        // Print all the currently set alternative labels.
418
+        foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) {
419
+
420
+            echo wp_kses( $this->get_alternative_label_input( $alt_label ), Wordlift_UI_Service::get_template_allowed_html() );
421
+
422
+        };
423
+
424
+        // Print the button.
425
+        Wordlift_UI_Service::print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
426
+
427
+    }
428
+
429
+    public function get_uri( $object_id, $type = Object_Type_Enum::POST ) {
430
+        $content_service = Wordpress_Content_Service::get_instance();
431
+        $entity_id       = $content_service->get_entity_id( new Wordpress_Content_Id( $object_id, $type ) );
432
+        $dataset_uri     = Wordlift_Configuration_Service::get_instance()->get_dataset_uri();
433
+
434
+        if ( ! isset( $entity_id ) ||
435
+             ( ! empty( $dataset_uri ) && 0 !== strpos( $entity_id, $dataset_uri ) ) ) {
436
+            $rel_uri = Entity_Uri_Generator::create_uri( $type, $object_id );
437
+            try {
438
+                $content_service->set_entity_id( new Wordpress_Content_Id( $object_id, $type ), $rel_uri );
439
+                $entity_id = $content_service->get_entity_id( new Wordpress_Content_Id( $object_id, $type ) );
440
+            } catch ( Exception $e ) {
441
+                return null;
442
+            }
443
+        }
444
+
445
+        return $entity_id;
446
+    }
447
+
448
+    /**
449
+     * Get the alternative label input HTML code.
450
+     *
451
+     * @param string $value The input value.
452
+     *
453
+     * @return string The input HTML code.
454
+     * @since 3.2.0
455
+     */
456
+    private function get_alternative_label_input( $value = '' ) {
457
+
458
+        return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), esc_html__( 'Delete', 'wordlift' ) );
459
+    }
460
+
461
+    /**
462
+     * Get the number of entity posts published in this blog.
463
+     *
464
+     * @return int The number of published entity posts.
465
+     * @since 3.6.0
466
+     */
467
+    public function count() {
468
+        global $wpdb;
469
+
470
+        // Try to get the count from the transient.
471
+        $count = get_transient( '_wl_entity_service__count' );
472
+        if ( false !== $count ) {
473
+            return $count;
474
+        }
475
+
476
+        // Query the count.
477
+        $count = $wpdb->get_var(
478
+            $wpdb->prepare(
479
+                'SELECT COUNT( DISTINCT( tr.object_id ) )'
480
+                . " FROM {$wpdb->term_relationships} tr"
481
+                . " INNER JOIN {$wpdb->term_taxonomy} tt"
482
+                . '  ON tt.taxonomy = %s AND tt.term_taxonomy_id = tr.term_taxonomy_id'
483
+                . " INNER JOIN {$wpdb->terms} t"
484
+                . '  ON t.term_id = tt.term_id AND t.name != %s',
485
+                Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
486
+                'article'
487
+            )
488
+        );
489
+
490
+        // Store the count in cache.
491
+        set_transient( '_wl_entity_service__count', $count, 900 );
492
+
493
+        return $count;
494
+    }
495
+
496
+    /**
497
+     * Add the entity filtering criterias to the arguments for a `get_posts`
498
+     * call.
499
+     *
500
+     * @param array $args The arguments for a `get_posts` call.
501
+     *
502
+     * @return array The arguments for a `get_posts` call.
503
+     * @since 3.15.0
504
+     */
505
+    public static function add_criterias( $args ) {
506
+
507
+        // Build an optimal tax-query.
508
+        $tax_query = array(
509
+            'relation' => 'AND',
510
+            array(
511
+                'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
512
+                'operator' => 'EXISTS',
513
+            ),
514
+            array(
515
+                'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
516
+                'field'    => 'slug',
517
+                'terms'    => 'article',
518
+                'operator' => 'NOT IN',
519
+            ),
520
+        );
521
+
522
+        return $args + array(
523
+            'post_type' => self::valid_entity_post_types(),
524
+            /*
525 525
 			 * Ensure compatibility with Polylang.
526 526
 			 *
527 527
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/855.
@@ -529,101 +529,101 @@  discard block
 block discarded – undo
529 529
 			 *
530 530
 			 * @since 3.19.5
531 531
 			 */
532
-			'lang'      => '',
533
-			'tax_query' => $tax_query,
534
-		);
535
-	}
536
-
537
-	/**
538
-	 * Create a new entity.
539
-	 *
540
-	 * @param string $name The entity name.
541
-	 * @param string $type_uri The entity's type URI.
542
-	 * @param null   $logo The entity logo id (or NULL if none).
543
-	 * @param string $status The post status, by default 'publish'.
544
-	 *
545
-	 * @return int|WP_Error The entity post id or a {@link WP_Error} in case the `wp_insert_post` call fails.
546
-	 * @since 3.9.0
547
-	 */
548
-	public function create( $name, $type_uri, $logo = null, $status = 'publish' ) {
549
-
550
-		// Create an entity for the publisher.
551
-		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
552
-		$post_id = @wp_insert_post(
553
-			array(
554
-				'post_type'    => self::TYPE_NAME,
555
-				'post_title'   => $name,
556
-				'post_status'  => $status,
557
-				'post_content' => '',
558
-			)
559
-		);
560
-
561
-		// Return the error if any.
562
-		if ( is_wp_error( $post_id ) ) {
563
-			return $post_id;
564
-		}
565
-
566
-		// Set the entity logo.
567
-		if ( $logo && is_numeric( $logo ) ) {
568
-			set_post_thumbnail( $post_id, $logo );
569
-		}
570
-
571
-		// Set the entity type.
572
-		Wordlift_Entity_Type_Service::get_instance()->set( $post_id, $type_uri );
573
-
574
-		return $post_id;
575
-	}
576
-
577
-	/**
578
-	 * Get the entities related to the one with the specified id. By default only
579
-	 * published entities will be returned.
580
-	 *
581
-	 * @param int    $id The post id.
582
-	 * @param string $post_status The target post status (default = publish).
583
-	 *
584
-	 * @return array An array of post ids.
585
-	 * @since 3.10.0
586
-	 */
587
-	public function get_related_entities( $id, $post_status = 'publish' ) {
588
-
589
-		return $this->relation_service->get_objects( $id, 'ids', null, $post_status );
590
-	}
591
-
592
-	/**
593
-	 * Get the list of entities.
594
-	 *
595
-	 * @param array $params Custom parameters for WordPress' own {@link get_posts} function.
596
-	 *
597
-	 * @return array An array of entity posts.
598
-	 * @since 3.12.2
599
-	 */
600
-	public function get( $params = array() ) {
601
-
602
-		// Set the defaults.
603
-		$defaults = array( 'post_type' => 'entity' );
604
-
605
-		// Merge the defaults with the provided parameters.
606
-		$args = wp_parse_args( $params, $defaults );
607
-
608
-		// Call the `get_posts` function.
609
-		return get_posts( $args );
610
-	}
611
-
612
-	/**
613
-	 * The list of post type names which can be used for entities
614
-	 *
615
-	 * Criteria is that the post type is public. The list of valid post types
616
-	 * can be overridden with a filter.
617
-	 *
618
-	 * @return array Array containing the names of the valid post types.
619
-	 * @since 3.15.0
620
-	 */
621
-	public static function valid_entity_post_types() {
622
-
623
-		// Ignore builtins in the call to avoid getting attachments.
624
-		$post_types = array( 'post', 'page', self::TYPE_NAME, 'product' );
625
-
626
-		return apply_filters( 'wl_valid_entity_post_types', $post_types );
627
-	}
532
+            'lang'      => '',
533
+            'tax_query' => $tax_query,
534
+        );
535
+    }
536
+
537
+    /**
538
+     * Create a new entity.
539
+     *
540
+     * @param string $name The entity name.
541
+     * @param string $type_uri The entity's type URI.
542
+     * @param null   $logo The entity logo id (or NULL if none).
543
+     * @param string $status The post status, by default 'publish'.
544
+     *
545
+     * @return int|WP_Error The entity post id or a {@link WP_Error} in case the `wp_insert_post` call fails.
546
+     * @since 3.9.0
547
+     */
548
+    public function create( $name, $type_uri, $logo = null, $status = 'publish' ) {
549
+
550
+        // Create an entity for the publisher.
551
+        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
552
+        $post_id = @wp_insert_post(
553
+            array(
554
+                'post_type'    => self::TYPE_NAME,
555
+                'post_title'   => $name,
556
+                'post_status'  => $status,
557
+                'post_content' => '',
558
+            )
559
+        );
560
+
561
+        // Return the error if any.
562
+        if ( is_wp_error( $post_id ) ) {
563
+            return $post_id;
564
+        }
565
+
566
+        // Set the entity logo.
567
+        if ( $logo && is_numeric( $logo ) ) {
568
+            set_post_thumbnail( $post_id, $logo );
569
+        }
570
+
571
+        // Set the entity type.
572
+        Wordlift_Entity_Type_Service::get_instance()->set( $post_id, $type_uri );
573
+
574
+        return $post_id;
575
+    }
576
+
577
+    /**
578
+     * Get the entities related to the one with the specified id. By default only
579
+     * published entities will be returned.
580
+     *
581
+     * @param int    $id The post id.
582
+     * @param string $post_status The target post status (default = publish).
583
+     *
584
+     * @return array An array of post ids.
585
+     * @since 3.10.0
586
+     */
587
+    public function get_related_entities( $id, $post_status = 'publish' ) {
588
+
589
+        return $this->relation_service->get_objects( $id, 'ids', null, $post_status );
590
+    }
591
+
592
+    /**
593
+     * Get the list of entities.
594
+     *
595
+     * @param array $params Custom parameters for WordPress' own {@link get_posts} function.
596
+     *
597
+     * @return array An array of entity posts.
598
+     * @since 3.12.2
599
+     */
600
+    public function get( $params = array() ) {
601
+
602
+        // Set the defaults.
603
+        $defaults = array( 'post_type' => 'entity' );
604
+
605
+        // Merge the defaults with the provided parameters.
606
+        $args = wp_parse_args( $params, $defaults );
607
+
608
+        // Call the `get_posts` function.
609
+        return get_posts( $args );
610
+    }
611
+
612
+    /**
613
+     * The list of post type names which can be used for entities
614
+     *
615
+     * Criteria is that the post type is public. The list of valid post types
616
+     * can be overridden with a filter.
617
+     *
618
+     * @return array Array containing the names of the valid post types.
619
+     * @since 3.15.0
620
+     */
621
+    public static function valid_entity_post_types() {
622
+
623
+        // Ignore builtins in the call to avoid getting attachments.
624
+        $post_types = array( 'post', 'page', self::TYPE_NAME, 'product' );
625
+
626
+        return apply_filters( 'wl_valid_entity_post_types', $post_types );
627
+    }
628 628
 
629 629
 }
Please login to merge, or discard this patch.