@@ -18,406 +18,406 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | protected function __construct() { |
45 | 45 | global $wpdb; |
46 | 46 | |
47 | - self::$log = Wordlift_Log_Service::get_logger( get_class() ); |
|
47 | + self::$log = Wordlift_Log_Service::get_logger(get_class()); |
|
48 | 48 | |
49 | 49 | // The relations table. |
50 | 50 | $this->relation_table = "{$wpdb->prefix}wl_relation_instances"; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public static function get_instance() { |
71 | 71 | |
72 | - if ( ! isset( self::$instance ) ) { |
|
72 | + if ( ! isset(self::$instance)) { |
|
73 | 73 | self::$instance = new self(); |
74 | 74 | } |
75 | 75 | |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | * @return array|object|null Database query results |
97 | 97 | * @since 3.15.0 |
98 | 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 ) { |
|
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 | 100 | global $wpdb; |
101 | 101 | |
102 | 102 | // The output fields. |
103 | - $actual_fields = self::fields( $fields ); |
|
103 | + $actual_fields = self::fields($fields); |
|
104 | 104 | |
105 | - self::$log->trace( 'Getting article subjects for object ' . implode( ', ', (array) $object_id ) . '...' ); |
|
105 | + self::$log->trace('Getting article subjects for object '.implode(', ', (array) $object_id).'...'); |
|
106 | 106 | |
107 | - $objects = $this->article_id_to_entity_id( $object_id ); |
|
107 | + $objects = $this->article_id_to_entity_id($object_id); |
|
108 | 108 | |
109 | 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 ) . '.' ); |
|
110 | + if (empty($objects)) { |
|
111 | + self::$log->debug('No entities found for object '.implode(', ', (array) $object_id).'.'); |
|
112 | 112 | |
113 | 113 | return array(); |
114 | 114 | } |
115 | 115 | |
116 | - self::$log->debug( count( $objects ) . ' entity id(s) found for object ' . implode( ', ', (array) $object_id ) . '.' ); |
|
116 | + self::$log->debug(count($objects).' entity id(s) found for object '.implode(', ', (array) $object_id).'.'); |
|
117 | 117 | |
118 | 118 | $sql = |
119 | 119 | " |
@@ -123,20 +123,20 @@ discard block |
||
123 | 123 | ON p.id = r.subject_id |
124 | 124 | " |
125 | 125 | // Add the status clause. |
126 | - . self::and_status( $status ) |
|
126 | + . self::and_status($status) |
|
127 | 127 | . self::inner_join_is_article() |
128 | - . self::where_object_id( $objects ) |
|
128 | + . self::where_object_id($objects) |
|
129 | 129 | // Since `object_id` can be an article ID we need to exclude it from |
130 | 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 |
|
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 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -148,16 +148,16 @@ discard block |
||
148 | 148 | * @return string The `post_type IN` clause. |
149 | 149 | * @since 3.15.3 |
150 | 150 | */ |
151 | - private static function and_post_type_in( $post_types = array() ) { |
|
151 | + private static function and_post_type_in($post_types = array()) { |
|
152 | 152 | |
153 | - if ( array() === $post_types ) { |
|
153 | + if (array() === $post_types) { |
|
154 | 154 | $post_types = Wordlift_Entity_Service::valid_entity_post_types(); |
155 | 155 | } |
156 | 156 | |
157 | 157 | return " AND p.post_type IN ( '" |
158 | 158 | . implode( |
159 | 159 | "','", |
160 | - array_map( 'esc_sql', $post_types ) |
|
160 | + array_map('esc_sql', $post_types) |
|
161 | 161 | ) |
162 | 162 | . "' )"; |
163 | 163 | } |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * @return string The limit clause (empty if no limit has been specified). |
171 | 171 | * @since 3.15.0 |
172 | 172 | */ |
173 | - private static function limit( $limit = null ) { |
|
173 | + private static function limit($limit = null) { |
|
174 | 174 | |
175 | - if ( null === $limit ) { |
|
175 | + if (null === $limit) { |
|
176 | 176 | return ''; |
177 | 177 | } |
178 | 178 | |
@@ -187,9 +187,9 @@ discard block |
||
187 | 187 | * @return string The offset clause (empty if no offset has been specified). |
188 | 188 | * @since 3.35.11 |
189 | 189 | */ |
190 | - private static function offset( $offset = null ) { |
|
190 | + private static function offset($offset = null) { |
|
191 | 191 | |
192 | - if ( null === $offset || ! is_numeric( $offset ) ) { |
|
192 | + if (null === $offset || ! is_numeric($offset)) { |
|
193 | 193 | return ''; |
194 | 194 | } |
195 | 195 | |
@@ -201,14 +201,14 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @return string |
203 | 203 | */ |
204 | - private static function order_by( $order_by ) { |
|
205 | - if ( ! $order_by ) { |
|
204 | + private static function order_by($order_by) { |
|
205 | + if ( ! $order_by) { |
|
206 | 206 | return ''; |
207 | 207 | } |
208 | 208 | $order_by = (string) $order_by; |
209 | - $order_by_clauses = array( 'DESC', 'ASC' ); |
|
209 | + $order_by_clauses = array('DESC', 'ASC'); |
|
210 | 210 | |
211 | - if ( in_array( $order_by, $order_by_clauses, true ) ) { |
|
211 | + if (in_array($order_by, $order_by_clauses, true)) { |
|
212 | 212 | return " ORDER BY p.post_modified ${order_by} "; |
213 | 213 | } else { |
214 | 214 | return ' ORDER BY p.post_modified DESC '; |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | * @return array An array of entities' ids. |
225 | 225 | * @since 3.15.0 |
226 | 226 | */ |
227 | - private function article_id_to_entity_id( $object_id ) { |
|
227 | + private function article_id_to_entity_id($object_id) { |
|
228 | 228 | |
229 | 229 | $entity_service = Wordlift_Entity_Service::get_instance(); |
230 | 230 | |
@@ -232,12 +232,12 @@ discard block |
||
232 | 232 | |
233 | 233 | return array_reduce( |
234 | 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 ); |
|
235 | + function($carry, $item) use ($entity_service, $relation_service) { |
|
236 | + if ($entity_service->is_entity($item)) { |
|
237 | + return array_merge($carry, (array) $item); |
|
238 | 238 | } |
239 | 239 | |
240 | - return array_merge( $carry, $relation_service->get_objects( $item, 'ids' ) ); |
|
240 | + return array_merge($carry, $relation_service->get_objects($item, 'ids')); |
|
241 | 241 | }, |
242 | 242 | array() |
243 | 243 | ); |
@@ -252,15 +252,15 @@ discard block |
||
252 | 252 | * @return string The WHERE clause. |
253 | 253 | * @since 3.15.0 |
254 | 254 | */ |
255 | - private static function where_object_id( $object_id ) { |
|
255 | + private static function where_object_id($object_id) { |
|
256 | 256 | |
257 | - if ( empty( $object_id ) ) { |
|
257 | + if (empty($object_id)) { |
|
258 | 258 | // self::$log->warn( sprintf( "%s `where_object_id` called with empty `object_id`.", var_export( debug_backtrace( false, 3 ), true ) ) ); |
259 | 259 | |
260 | 260 | return ' WHERE 1 = 1'; |
261 | 261 | } |
262 | 262 | |
263 | - return ' WHERE r.object_id IN ( ' . implode( ',', wp_parse_id_list( (array) $object_id ) ) . ' )'; |
|
263 | + return ' WHERE r.object_id IN ( '.implode(',', wp_parse_id_list((array) $object_id)).' )'; |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -271,9 +271,9 @@ discard block |
||
271 | 271 | * @return string The exclude clause. |
272 | 272 | * @since 3.15.0 |
273 | 273 | */ |
274 | - private static function and_article_not_in( $exclude ) { |
|
274 | + private static function and_article_not_in($exclude) { |
|
275 | 275 | |
276 | - return ' AND NOT p.ID IN ( ' . implode( ',', wp_parse_id_list( (array) $exclude ) ) . ' )'; |
|
276 | + return ' AND NOT p.ID IN ( '.implode(',', wp_parse_id_list((array) $exclude)).' )'; |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -285,13 +285,13 @@ discard block |
||
285 | 285 | * clause. |
286 | 286 | * @since 3.15.0 |
287 | 287 | */ |
288 | - private static function and_article_in( $include = null ) { |
|
288 | + private static function and_article_in($include = null) { |
|
289 | 289 | |
290 | - if ( null === $include ) { |
|
290 | + if (null === $include) { |
|
291 | 291 | return ''; |
292 | 292 | } |
293 | 293 | |
294 | - return ' AND p.ID IN ( ' . implode( ',', wp_parse_id_list( (array) $include ) ) . ' )'; |
|
294 | + return ' AND p.ID IN ( '.implode(',', wp_parse_id_list((array) $include)).' )'; |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -305,23 +305,23 @@ discard block |
||
305 | 305 | * @return array|object|null Database query results |
306 | 306 | * @since 3.15.0 |
307 | 307 | */ |
308 | - public function get_non_article_subjects( $object_id, $fields = '*', $status = null ) { |
|
308 | + public function get_non_article_subjects($object_id, $fields = '*', $status = null) { |
|
309 | 309 | global $wpdb; |
310 | 310 | |
311 | 311 | // The output fields. |
312 | - $actual_fields = self::fields( $fields ); |
|
312 | + $actual_fields = self::fields($fields); |
|
313 | 313 | |
314 | 314 | $sql = $wpdb->prepare( |
315 | 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 | 316 | // Add the status clause. |
317 | - . self::and_status( $status ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
317 | + . self::and_status($status) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
318 | 318 | . self::inner_join_is_not_article() // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
319 | 319 | . ' WHERE r.object_id = %d ' |
320 | 320 | . self::and_post_type_in(), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
321 | 321 | $object_id |
322 | 322 | ); |
323 | 323 | |
324 | - return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
324 | + return '*' === $actual_fields ? $wpdb->get_results($sql) : $wpdb->get_col($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
@@ -338,24 +338,24 @@ discard block |
||
338 | 338 | * @deprecated since it doesn't handle the subject_type nor the object_type |
339 | 339 | * @since 3.15.0 |
340 | 340 | */ |
341 | - public function get_objects( $subject_id, $fields = '*', $predicate = null, $status = null ) { |
|
341 | + public function get_objects($subject_id, $fields = '*', $predicate = null, $status = null) { |
|
342 | 342 | global $wpdb; |
343 | 343 | |
344 | 344 | // The output fields. |
345 | - $actual_fields = self::fields( $fields ); |
|
345 | + $actual_fields = self::fields($fields); |
|
346 | 346 | |
347 | 347 | $sql = $wpdb->prepare( |
348 | 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 | 349 | // Add the status clause. |
350 | - . self::and_status( $status ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
350 | + . self::and_status($status) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
351 | 351 | . self::inner_join_is_not_article() // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
352 | 352 | . ' WHERE r.subject_id = %d ' |
353 | 353 | . self::and_post_type_in() // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
354 | - . self::and_predicate( $predicate ), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
354 | + . self::and_predicate($predicate), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
355 | 355 | $subject_id |
356 | 356 | ); |
357 | 357 | |
358 | - return '*' === $actual_fields ? $wpdb->get_results( $sql ) : $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
358 | + return '*' === $actual_fields ? $wpdb->get_results($sql) : $wpdb->get_col($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -366,13 +366,13 @@ discard block |
||
366 | 366 | * @return string An empty string if $status is null, otherwise the status clause. |
367 | 367 | * @since 3.15.0 |
368 | 368 | */ |
369 | - private static function and_status( $status = null ) { |
|
369 | + private static function and_status($status = null) { |
|
370 | 370 | |
371 | - if ( null === $status ) { |
|
371 | + if (null === $status) { |
|
372 | 372 | return ''; |
373 | 373 | } |
374 | 374 | |
375 | - return " AND p.post_status IN ('" . implode( "', '", array_map( 'esc_sql', (array) $status ) ) . "')"; |
|
375 | + return " AND p.post_status IN ('".implode("', '", array_map('esc_sql', (array) $status))."')"; |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | /** |
@@ -384,13 +384,13 @@ discard block |
||
384 | 384 | * clause. |
385 | 385 | * @since 3.15.0 |
386 | 386 | */ |
387 | - private static function and_predicate( $predicate = null ) { |
|
387 | + private static function and_predicate($predicate = null) { |
|
388 | 388 | |
389 | - if ( null === $predicate ) { |
|
389 | + if (null === $predicate) { |
|
390 | 390 | return ''; |
391 | 391 | } |
392 | 392 | |
393 | - return " AND r.predicate IN ('" . implode( "', '", array_map( 'esc_sql', (array) $predicate ) ) . "')"; |
|
393 | + return " AND r.predicate IN ('".implode("', '", array_map('esc_sql', (array) $predicate))."')"; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | * @return string The `id` field if `ids` otherwise `*`. |
402 | 402 | * @since 3.15.0 |
403 | 403 | */ |
404 | - private static function fields( $fields = '*' ) { |
|
404 | + private static function fields($fields = '*') { |
|
405 | 405 | |
406 | 406 | // The output fields. |
407 | 407 | return 'ids' === $fields ? 'id' : '*'; |
@@ -83,1852 +83,1852 @@ |
||
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 | } |
@@ -638,15 +638,15 @@ discard block |
||
638 | 638 | $that = $this; |
639 | 639 | add_action( |
640 | 640 | 'plugins_loaded', |
641 | - function () use ( $that ) { |
|
642 | - $that->define_admin_hooks( $that ); |
|
643 | - $that->define_public_hooks( $that ); |
|
641 | + function() use ($that) { |
|
642 | + $that->define_admin_hooks($that); |
|
643 | + $that->define_public_hooks($that); |
|
644 | 644 | }, |
645 | 645 | 4 |
646 | 646 | ); |
647 | 647 | |
648 | 648 | // If we're in `WP_CLI` load the related files. |
649 | - if ( class_exists( 'WP_CLI' ) ) { |
|
649 | + if (class_exists('WP_CLI')) { |
|
650 | 650 | $this->load_cli_dependencies(); |
651 | 651 | } |
652 | 652 | |
@@ -686,329 +686,329 @@ discard block |
||
686 | 686 | * The class responsible for orchestrating the actions and filters of the |
687 | 687 | * core plugin. |
688 | 688 | */ |
689 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-loader.php'; |
|
689 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-loader.php'; |
|
690 | 690 | |
691 | 691 | // The class responsible for plugin uninstall. |
692 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-deactivator-feedback.php'; |
|
692 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-deactivator-feedback.php'; |
|
693 | 693 | |
694 | 694 | /** |
695 | 695 | * The class responsible for defining internationalization functionality |
696 | 696 | * of the plugin. |
697 | 697 | */ |
698 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-i18n.php'; |
|
698 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-i18n.php'; |
|
699 | 699 | |
700 | 700 | /** |
701 | 701 | * WordLift's supported languages. |
702 | 702 | */ |
703 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-languages.php'; |
|
703 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-languages.php'; |
|
704 | 704 | |
705 | 705 | /** |
706 | 706 | * WordLift's supported countries. |
707 | 707 | */ |
708 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-countries.php'; |
|
708 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-countries.php'; |
|
709 | 709 | |
710 | 710 | /** |
711 | 711 | * Provide support functions to sanitize data. |
712 | 712 | */ |
713 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-sanitizer.php'; |
|
713 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-sanitizer.php'; |
|
714 | 714 | |
715 | 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'; |
|
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 | 725 | |
726 | 726 | /** |
727 | 727 | * The Schema service. |
728 | 728 | */ |
729 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-schema-service.php'; |
|
729 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-schema-service.php'; |
|
730 | 730 | |
731 | 731 | /** |
732 | 732 | * The schema:url property service. |
733 | 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'; |
|
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 | 736 | |
737 | 737 | /** |
738 | 738 | * The UI service. |
739 | 739 | */ |
740 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-ui-service.php'; |
|
740 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-ui-service.php'; |
|
741 | 741 | |
742 | 742 | /** |
743 | 743 | * The Entity Types Taxonomy service. |
744 | 744 | */ |
745 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-type-taxonomy-service.php'; |
|
745 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-entity-type-taxonomy-service.php'; |
|
746 | 746 | |
747 | 747 | /** |
748 | 748 | * The Entity service. |
749 | 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'; |
|
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 | 752 | |
753 | 753 | // Add the entity rating service. |
754 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-rating-service.php'; |
|
754 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-rating-service.php'; |
|
755 | 755 | |
756 | 756 | /** |
757 | 757 | * The User service. |
758 | 758 | */ |
759 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-user-service.php'; |
|
759 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-user-service.php'; |
|
760 | 760 | |
761 | 761 | /** |
762 | 762 | * The Timeline service. |
763 | 763 | */ |
764 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-timeline-service.php'; |
|
764 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-timeline-service.php'; |
|
765 | 765 | |
766 | 766 | /** |
767 | 767 | * The Topic Taxonomy service. |
768 | 768 | */ |
769 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-topic-taxonomy-service.php'; |
|
769 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-topic-taxonomy-service.php'; |
|
770 | 770 | |
771 | 771 | /** |
772 | 772 | * The WordLift URI service. |
773 | 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'; |
|
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 | 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'; |
|
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 | 780 | |
781 | 781 | /** |
782 | 782 | * Load the converters. |
783 | 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'; |
|
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 | 790 | |
791 | 791 | /** |
792 | 792 | * Load cache-related files. |
793 | 793 | */ |
794 | - require_once plugin_dir_path( __DIR__ ) . 'includes/cache/require.php'; |
|
794 | + require_once plugin_dir_path(__DIR__).'includes/cache/require.php'; |
|
795 | 795 | |
796 | 796 | /** |
797 | 797 | * Load the content filter. |
798 | 798 | */ |
799 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-content-filter-service.php'; |
|
799 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-content-filter-service.php'; |
|
800 | 800 | |
801 | 801 | /* |
802 | 802 | * Load the excerpt helper. |
803 | 803 | */ |
804 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-post-excerpt-helper.php'; |
|
804 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-post-excerpt-helper.php'; |
|
805 | 805 | |
806 | 806 | /** |
807 | 807 | * Load the JSON-LD service to publish entities using JSON-LD.s |
808 | 808 | * |
809 | 809 | * @since 3.8.0 |
810 | 810 | */ |
811 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-jsonld-service.php'; |
|
811 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-jsonld-service.php'; |
|
812 | 812 | |
813 | 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'; |
|
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 | 816 | |
817 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-post-adapter.php'; |
|
817 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-post-adapter.php'; |
|
818 | 818 | |
819 | 819 | /** |
820 | 820 | * Load the WordLift key validation service. |
821 | 821 | */ |
822 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-key-validation-service.php'; |
|
822 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-key-validation-service.php'; |
|
823 | 823 | |
824 | 824 | // Load the `Wordlift_Category_Taxonomy_Service` class definition. |
825 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-category-taxonomy-service.php'; |
|
825 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-category-taxonomy-service.php'; |
|
826 | 826 | |
827 | 827 | // Load the `Wordlift_Entity_Page_Service` class definition. |
828 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-entity-page-service.php'; |
|
828 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-entity-page-service.php'; |
|
829 | 829 | |
830 | 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'; |
|
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 | 842 | |
843 | 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'; |
|
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 | 846 | |
847 | 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'; |
|
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 | 854 | |
855 | 855 | /** Autocomplete. */ |
856 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-autocomplete-adapter.php'; |
|
856 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-autocomplete-adapter.php'; |
|
857 | 857 | |
858 | - require_once plugin_dir_path( __DIR__ ) . 'includes/class-wordlift-remote-image-service.php'; |
|
858 | + require_once plugin_dir_path(__DIR__).'includes/class-wordlift-remote-image-service.php'; |
|
859 | 859 | |
860 | 860 | /** Analytics */ |
861 | - require_once plugin_dir_path( __DIR__ ) . 'includes/analytics/class-wordlift-analytics-connect.php'; |
|
861 | + require_once plugin_dir_path(__DIR__).'includes/analytics/class-wordlift-analytics-connect.php'; |
|
862 | 862 | |
863 | 863 | /** |
864 | 864 | * The class responsible for defining all actions that occur in the admin area. |
865 | 865 | */ |
866 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin.php'; |
|
866 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-admin.php'; |
|
867 | 867 | |
868 | 868 | /** |
869 | 869 | * The class to customize the entity list admin page. |
870 | 870 | */ |
871 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-entity-list-service.php'; |
|
871 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-entity-list-service.php'; |
|
872 | 872 | |
873 | 873 | /** |
874 | 874 | * The Entity Types Taxonomy Walker (transforms checkboxes into radios). |
875 | 875 | */ |
876 | 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'; |
|
877 | + if (version_compare($wp_version, '5.3', '<')) { |
|
878 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
879 | 879 | } else { |
880 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-entity-types-taxonomy-walker-5-3.php'; |
|
880 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-entity-types-taxonomy-walker-5-3.php'; |
|
881 | 881 | } |
882 | 882 | |
883 | 883 | /** |
884 | 884 | * The Notice service. |
885 | 885 | */ |
886 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-notice-service.php'; |
|
886 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-notice-service.php'; |
|
887 | 887 | |
888 | 888 | /** |
889 | 889 | * The PrimaShop adapter. |
890 | 890 | */ |
891 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-primashop-adapter.php'; |
|
891 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-primashop-adapter.php'; |
|
892 | 892 | |
893 | 893 | /** |
894 | 894 | * The WordLift Dashboard service. |
895 | 895 | */ |
896 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-dashboard-service.php'; |
|
896 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-dashboard-service.php'; |
|
897 | 897 | |
898 | 898 | /** |
899 | 899 | * The admin 'Install wizard' page. |
900 | 900 | */ |
901 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-setup.php'; |
|
901 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-admin-setup.php'; |
|
902 | 902 | |
903 | 903 | /** |
904 | 904 | * The WordLift entity type list admin page controller. |
905 | 905 | */ |
906 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-entity-taxonomy-list-page.php'; |
|
906 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-admin-entity-taxonomy-list-page.php'; |
|
907 | 907 | |
908 | 908 | /** |
909 | 909 | * The WordLift entity type settings admin page controller. |
910 | 910 | */ |
911 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-entity-type-settings.php'; |
|
911 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-admin-entity-type-settings.php'; |
|
912 | 912 | |
913 | 913 | /** |
914 | 914 | * The admin 'Download Your Data' page. |
915 | 915 | */ |
916 | - require_once plugin_dir_path( __DIR__ ) . 'admin/class-wordlift-admin-download-your-data-page.php'; |
|
916 | + require_once plugin_dir_path(__DIR__).'admin/class-wordlift-admin-download-your-data-page.php'; |
|
917 | 917 | |
918 | 918 | /** |
919 | 919 | * The admin 'WordLift Settings' page. |
920 | 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'; |
|
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 | 936 | |
937 | 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'; |
|
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 | 940 | |
941 | 941 | /** |
942 | 942 | * The class responsible for defining all actions that occur in the public-facing |
943 | 943 | * side of the site. |
944 | 944 | */ |
945 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-public.php'; |
|
945 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-public.php'; |
|
946 | 946 | |
947 | 947 | /** |
948 | 948 | * The shortcode abstract class. |
949 | 949 | */ |
950 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-shortcode.php'; |
|
950 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-shortcode.php'; |
|
951 | 951 | |
952 | 952 | /** |
953 | 953 | * The Timeline shortcode. |
954 | 954 | */ |
955 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-timeline-shortcode.php'; |
|
955 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-timeline-shortcode.php'; |
|
956 | 956 | |
957 | 957 | /** |
958 | 958 | * The Navigator shortcode. |
959 | 959 | */ |
960 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-navigator-shortcode.php'; |
|
960 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-navigator-shortcode.php'; |
|
961 | 961 | |
962 | 962 | /** |
963 | 963 | * The Products Navigator shortcode. |
964 | 964 | */ |
965 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-products-navigator-shortcode.php'; |
|
965 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-products-navigator-shortcode.php'; |
|
966 | 966 | |
967 | 967 | /** |
968 | 968 | * The chord shortcode. |
969 | 969 | */ |
970 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-chord-shortcode.php'; |
|
970 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-chord-shortcode.php'; |
|
971 | 971 | |
972 | 972 | /** |
973 | 973 | * The geomap shortcode. |
974 | 974 | */ |
975 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-geomap-shortcode.php'; |
|
975 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-geomap-shortcode.php'; |
|
976 | 976 | |
977 | 977 | /** |
978 | 978 | * The entity cloud shortcode. |
979 | 979 | */ |
980 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-related-entities-cloud-shortcode.php'; |
|
980 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-related-entities-cloud-shortcode.php'; |
|
981 | 981 | |
982 | 982 | /** |
983 | 983 | * The entity glossary shortcode. |
984 | 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'; |
|
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 | 987 | |
988 | 988 | /** |
989 | 989 | * Faceted Search shortcode. |
990 | 990 | */ |
991 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-faceted-search-shortcode.php'; |
|
991 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-faceted-search-shortcode.php'; |
|
992 | 992 | |
993 | 993 | /** |
994 | 994 | * The ShareThis service. |
995 | 995 | */ |
996 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-sharethis-service.php'; |
|
996 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-sharethis-service.php'; |
|
997 | 997 | |
998 | 998 | /** |
999 | 999 | * The SEO service. |
1000 | 1000 | */ |
1001 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-seo-service.php'; |
|
1001 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-seo-service.php'; |
|
1002 | 1002 | |
1003 | 1003 | /** |
1004 | 1004 | * The AMP service. |
1005 | 1005 | */ |
1006 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-amp-service.php'; |
|
1006 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-amp-service.php'; |
|
1007 | 1007 | |
1008 | 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'; |
|
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 | 1012 | |
1013 | 1013 | /* |
1014 | 1014 | * Batch Operations. They're similar to Batch Actions but do not require working on post types. |
@@ -1017,8 +1017,8 @@ discard block |
||
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. |
@@ -1026,10 +1026,10 @@ discard block |
||
1026 | 1026 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
1027 | 1027 | */ |
1028 | 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'; |
|
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 | 1033 | new Wordlift_Schemaorg_Sync_Service(); |
1034 | 1034 | $schemaorg_property_service = Wordlift_Schemaorg_Property_Service::get_instance(); |
1035 | 1035 | new Wordlift_Schemaorg_Class_Service(); |
@@ -1045,13 +1045,13 @@ discard block |
||
1045 | 1045 | |
1046 | 1046 | // Instantiate a global logger. |
1047 | 1047 | global $wl_logger; |
1048 | - $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' ); |
|
1048 | + $wl_logger = Wordlift_Log_Service::get_logger('WordLift'); |
|
1049 | 1049 | |
1050 | 1050 | // Load the `wl-api` end-point. |
1051 | 1051 | new Wordlift_Http_Api(); |
1052 | 1052 | |
1053 | 1053 | // Load the Install Service. |
1054 | - require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-service.php'; |
|
1054 | + require_once plugin_dir_path(__DIR__).'install/class-wordlift-install-service.php'; |
|
1055 | 1055 | $this->install_service = new Wordlift_Install_Service(); |
1056 | 1056 | $this->notice_service = new Wordlift_Notice_Service(); |
1057 | 1057 | $this->user_service = Wordlift_User_Service::get_instance(); |
@@ -1073,21 +1073,21 @@ discard block |
||
1073 | 1073 | add_action( |
1074 | 1074 | 'plugins_loaded', |
1075 | 1075 | // phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable |
1076 | - function () use ( &$that, $schemaorg_property_service ) { |
|
1076 | + function() use (&$that, $schemaorg_property_service) { |
|
1077 | 1077 | |
1078 | 1078 | /** Services. */ |
1079 | 1079 | // Create the configuration service. |
1080 | 1080 | new Wordlift_Api_Service(); |
1081 | 1081 | |
1082 | 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() ); |
|
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 | 1084 | |
1085 | 1085 | $schema_url_property_service = new Wordlift_Schema_Url_Property_Service(); |
1086 | 1086 | |
1087 | 1087 | $that->entity_uri_service = Wordlift_Entity_Uri_Service::get_instance(); |
1088 | 1088 | |
1089 | 1089 | // Create a new instance of the Redirect service. |
1090 | - $that->redirect_service = new Wordlift_Redirect_Service( $that->entity_uri_service ); |
|
1090 | + $that->redirect_service = new Wordlift_Redirect_Service($that->entity_uri_service); |
|
1091 | 1091 | |
1092 | 1092 | // Create a new instance of the Timeline service and Timeline shortcode. |
1093 | 1093 | $that->timeline_service = new Wordlift_Timeline_Service(); |
@@ -1100,30 +1100,30 @@ discard block |
||
1100 | 1100 | // Create an instance of the PrimaShop adapter. |
1101 | 1101 | $that->primashop_adapter = new Wordlift_PrimaShop_Adapter(); |
1102 | 1102 | |
1103 | - $uri_service = new Wordlift_Uri_Service( $GLOBALS['wpdb'] ); |
|
1103 | + $uri_service = new Wordlift_Uri_Service($GLOBALS['wpdb']); |
|
1104 | 1104 | |
1105 | 1105 | // Create the entity rating service. |
1106 | 1106 | $that->rating_service = Wordlift_Rating_Service::get_instance(); |
1107 | 1107 | |
1108 | 1108 | // Create entity list customization (wp-admin/edit.php). |
1109 | - $that->entity_list_service = new Wordlift_Entity_List_Service( $that->rating_service ); |
|
1109 | + $that->entity_list_service = new Wordlift_Entity_List_Service($that->rating_service); |
|
1110 | 1110 | |
1111 | 1111 | // Create an instance of the Publisher Service and the AJAX Adapter. |
1112 | 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 ); |
|
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 | 1115 | |
1116 | 1116 | $attachment_service = Wordlift_Attachment_Service::get_instance(); |
1117 | 1117 | |
1118 | 1118 | // Instantiate the JSON-LD service. |
1119 | 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 ); |
|
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 | 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 ); |
|
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 | 1127 | /* |
1128 | 1128 | * Load the `Wordlift_Term_JsonLd_Adapter`. |
1129 | 1129 | * |
@@ -1131,22 +1131,22 @@ discard block |
||
1131 | 1131 | * |
1132 | 1132 | * @since 3.20.0 |
1133 | 1133 | */ |
1134 | - require_once plugin_dir_path( __DIR__ ) . 'public/class-wordlift-term-jsonld-adapter.php'; |
|
1134 | + require_once plugin_dir_path(__DIR__).'public/class-wordlift-term-jsonld-adapter.php'; |
|
1135 | 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 ); |
|
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 | 1138 | |
1139 | 1139 | $jsonld_service = new Jsonld_Service( |
1140 | 1140 | $that->jsonld_service, |
1141 | 1141 | $term_jsonld_adapter, |
1142 | - new Jsonld_User_Service( $that->user_service ) |
|
1142 | + new Jsonld_User_Service($that->user_service) |
|
1143 | 1143 | ); |
1144 | - new Jsonld_Endpoint( $jsonld_service, $that->entity_uri_service ); |
|
1144 | + new Jsonld_Endpoint($jsonld_service, $that->entity_uri_service); |
|
1145 | 1145 | |
1146 | 1146 | // Prints the JSON-LD in the head. |
1147 | - new Jsonld_Adapter( $that->jsonld_service ); |
|
1147 | + new Jsonld_Adapter($that->jsonld_service); |
|
1148 | 1148 | |
1149 | - new Jsonld_By_Id_Endpoint( $that->jsonld_service, $that->entity_uri_service ); |
|
1149 | + new Jsonld_By_Id_Endpoint($that->jsonld_service, $that->entity_uri_service); |
|
1150 | 1150 | |
1151 | 1151 | $that->key_validation_service = new Wordlift_Key_Validation_Service(); |
1152 | 1152 | |
@@ -1154,10 +1154,10 @@ discard block |
||
1154 | 1154 | // Creating Faq Content filter service. |
1155 | 1155 | $that->faq_content_filter_service = new Faq_Content_Filter(); |
1156 | 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 ); |
|
1157 | + $that->sample_data_ajax_adapter = new Wordlift_Sample_Data_Ajax_Adapter($that->sample_data_service); |
|
1158 | 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' ); |
|
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 | 1161 | |
1162 | 1162 | /** |
1163 | 1163 | * Filter: wl_feature__enable__blocks. |
@@ -1167,15 +1167,15 @@ discard block |
||
1167 | 1167 | * @return bool |
1168 | 1168 | * @since 3.27.6 |
1169 | 1169 | */ |
1170 | - if ( apply_filters( 'wl_feature__enable__blocks', true ) ) { |
|
1170 | + if (apply_filters('wl_feature__enable__blocks', true)) { |
|
1171 | 1171 | // Initialize the short-codes. |
1172 | - new Async_Template_Decorator( new Wordlift_Navigator_Shortcode() ); |
|
1172 | + new Async_Template_Decorator(new Wordlift_Navigator_Shortcode()); |
|
1173 | 1173 | new Wordlift_Chord_Shortcode(); |
1174 | 1174 | new Wordlift_Geomap_Shortcode(); |
1175 | 1175 | new Wordlift_Timeline_Shortcode(); |
1176 | - new Wordlift_Related_Entities_Cloud_Shortcode( Wordlift_Relation_Service::get_instance(), Wordlift_Entity_Service::get_instance() ); |
|
1176 | + new Wordlift_Related_Entities_Cloud_Shortcode(Wordlift_Relation_Service::get_instance(), Wordlift_Entity_Service::get_instance()); |
|
1177 | 1177 | new Wordlift_Vocabulary_Shortcode(); |
1178 | - new Async_Template_Decorator( new Wordlift_Faceted_Search_Shortcode() ); |
|
1178 | + new Async_Template_Decorator(new Wordlift_Faceted_Search_Shortcode()); |
|
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | new Wordlift_Products_Navigator_Shortcode(); |
@@ -1187,16 +1187,16 @@ discard block |
||
1187 | 1187 | new Wordlift_Seo_Service(); |
1188 | 1188 | |
1189 | 1189 | // Initialize the AMP service. |
1190 | - new Wordlift_AMP_Service( $that->jsonld_service ); |
|
1190 | + new Wordlift_AMP_Service($that->jsonld_service); |
|
1191 | 1191 | |
1192 | 1192 | /** Services. */ |
1193 | 1193 | $that->google_analytics_export_service = new Wordlift_Google_Analytics_Export_Service(); |
1194 | 1194 | new Wordlift_Image_Service(); |
1195 | 1195 | |
1196 | 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 ); |
|
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 | 1200 | |
1201 | 1201 | /* |
1202 | 1202 | * Exclude our public js from WP-Rocket. |
@@ -1220,14 +1220,14 @@ discard block |
||
1220 | 1220 | $that->language_select_element = new Wordlift_Admin_Language_Select_Element(); |
1221 | 1221 | $that->country_select_element = new Wordlift_Admin_Country_Select_Element(); |
1222 | 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 ); |
|
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 | 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 ); |
|
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 ); |
|
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 | 1231 | $that->analytics_connect = new Wordlift_Analytics_Connect(); |
1232 | 1232 | |
1233 | 1233 | // Pages. |
@@ -1238,9 +1238,9 @@ discard block |
||
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 ); |
|
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 | 1244 | } |
1245 | 1245 | new Wordlift_Entity_Type_Admin_Service(); |
1246 | 1246 | |
@@ -1248,19 +1248,19 @@ discard block |
||
1248 | 1248 | $that->related_entities_cloud_widget = new Wordlift_Related_Entities_Cloud_Widget(); |
1249 | 1249 | |
1250 | 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 ); |
|
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 | 1255 | // User Profile. |
1256 | - new Wordlift_Admin_User_Profile_Page( $that->author_element, $that->user_service ); |
|
1256 | + new Wordlift_Admin_User_Profile_Page($that->author_element, $that->user_service); |
|
1257 | 1257 | |
1258 | 1258 | $that->entity_page_service = new Wordlift_Entity_Page_Service(); |
1259 | 1259 | |
1260 | 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 ); |
|
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 | 1264 | } |
1265 | 1265 | |
1266 | 1266 | // Remote Image Service. |
@@ -1273,12 +1273,12 @@ discard block |
||
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 | 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() ) ); |
|
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. |
@@ -1292,11 +1292,11 @@ discard block |
||
1292 | 1292 | // Taxonomy term rule validator for validating rules for term pages. |
1293 | 1293 | new Taxonomy_Term_Rule_Validator(); |
1294 | 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 ); |
|
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 | 1298 | |
1299 | - new Url_To_Entity_Transform_Function( $that->entity_uri_service ); |
|
1299 | + new Url_To_Entity_Transform_Function($that->entity_uri_service); |
|
1300 | 1300 | new Taxonomy_To_Terms_Transform_Function(); |
1301 | 1301 | new Post_Id_To_Entity_Transform_Function(); |
1302 | 1302 | $mappings_transform_functions_registry = new Mappings_Transform_Functions_Registry(); |
@@ -1306,7 +1306,7 @@ discard block |
||
1306 | 1306 | * Intiailize the acf group data formatter. |
1307 | 1307 | */ |
1308 | 1308 | new Acf_Group_Formatter(); |
1309 | - new Jsonld_Converter( $mappings_validator, $mappings_transform_functions_registry ); |
|
1309 | + new Jsonld_Converter($mappings_validator, $mappings_transform_functions_registry); |
|
1310 | 1310 | |
1311 | 1311 | /** |
1312 | 1312 | * @since 3.26.0 |
@@ -1324,16 +1324,16 @@ discard block |
||
1324 | 1324 | // Call this static method to register FAQ routes to rest api - disabled |
1325 | 1325 | // Faq_Rest_Controller::register_routes(); |
1326 | 1326 | |
1327 | - $that->storage_factory = new Wordlift_Storage_Factory( Wordlift_Entity_Service::get_instance(), $that->user_service, $property_getter ); |
|
1327 | + $that->storage_factory = new Wordlift_Storage_Factory(Wordlift_Entity_Service::get_instance(), $that->user_service, $property_getter); |
|
1328 | 1328 | |
1329 | 1329 | /** WL Autocomplete. */ |
1330 | - $autocomplete_service = new All_Autocomplete_Service( |
|
1330 | + $autocomplete_service = new All_Autocomplete_Service( |
|
1331 | 1331 | array( |
1332 | 1332 | new Local_Autocomplete_Service(), |
1333 | - new Linked_Data_Autocomplete_Service( Entity_Helper::get_instance(), $that->entity_uri_service, Wordlift_Entity_Service::get_instance() ), |
|
1333 | + new Linked_Data_Autocomplete_Service(Entity_Helper::get_instance(), $that->entity_uri_service, Wordlift_Entity_Service::get_instance()), |
|
1334 | 1334 | ) |
1335 | 1335 | ); |
1336 | - $that->autocomplete_adapter = new Wordlift_Autocomplete_Adapter( $autocomplete_service ); |
|
1336 | + $that->autocomplete_adapter = new Wordlift_Autocomplete_Adapter($autocomplete_service); |
|
1337 | 1337 | |
1338 | 1338 | /** |
1339 | 1339 | * @since 3.27.2 |
@@ -1342,10 +1342,10 @@ discard block |
||
1342 | 1342 | */ |
1343 | 1343 | new Recipe_Maker_Post_Type_Hook(); |
1344 | 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 ); |
|
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 | 1349 | |
1350 | 1350 | /** |
1351 | 1351 | * Avada Builder compatibility. |
@@ -1360,7 +1360,7 @@ discard block |
||
1360 | 1360 | * @since 3.27.8 |
1361 | 1361 | * @see https://github.com/insideout10/wordlift-plugin/issues/1248 |
1362 | 1362 | */ |
1363 | - new Key_Validation_Notice( $that->key_validation_service, Wordlift_Configuration_Service::get_instance() ); |
|
1363 | + new Key_Validation_Notice($that->key_validation_service, Wordlift_Configuration_Service::get_instance()); |
|
1364 | 1364 | |
1365 | 1365 | /** |
1366 | 1366 | * @since 3.28.0 |
@@ -1372,7 +1372,7 @@ discard block |
||
1372 | 1372 | * @since 3.29.0 |
1373 | 1373 | * @see https://github.com/insideout10/wordlift-plugin/issues/1304 |
1374 | 1374 | */ |
1375 | - new Entity_Rest_Service( Wordlift_Entity_Type_Service::get_instance() ); |
|
1375 | + new Entity_Rest_Service(Wordlift_Entity_Type_Service::get_instance()); |
|
1376 | 1376 | |
1377 | 1377 | /** |
1378 | 1378 | * Expand author in to references. |
@@ -1381,12 +1381,12 @@ discard block |
||
1381 | 1381 | * @see https://github.com/insideout10/wordlift-plugin/issues/1318 |
1382 | 1382 | */ |
1383 | 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 ); |
|
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 | 1386 | } |
1387 | 1387 | |
1388 | 1388 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
1389 | - if ( apply_filters( 'wl_feature__enable__match-terms', false ) ) { |
|
1389 | + if (apply_filters('wl_feature__enable__match-terms', false)) { |
|
1390 | 1390 | $vocabulary_loader = new Vocabulary_Loader(); |
1391 | 1391 | $vocabulary_loader->init_vocabulary(); |
1392 | 1392 | } |
@@ -1394,7 +1394,7 @@ discard block |
||
1394 | 1394 | /** |
1395 | 1395 | * Added for feature request 1496 (Webhooks) |
1396 | 1396 | */ |
1397 | - if ( apply_filters( 'wl_feature__enable__webhooks', false ) ) { |
|
1397 | + if (apply_filters('wl_feature__enable__webhooks', false)) { |
|
1398 | 1398 | $that->webhook_loader = new Webhooks_Loader(); |
1399 | 1399 | $that->webhook_loader->init(); |
1400 | 1400 | } |
@@ -1423,7 +1423,7 @@ discard block |
||
1423 | 1423 | * @since 3.31.5 |
1424 | 1424 | * Create configuration endpoint for webapp to configure. |
1425 | 1425 | */ |
1426 | - new Config( $that->admin_setup, $that->key_validation_service ); |
|
1426 | + new Config($that->admin_setup, $that->key_validation_service); |
|
1427 | 1427 | /** |
1428 | 1428 | * @since 3.31.7 |
1429 | 1429 | * Remove duplicate videoobject. |
@@ -1435,7 +1435,7 @@ discard block |
||
1435 | 1435 | * @since 3.32.0 |
1436 | 1436 | * Create loader for vocabulary terms. |
1437 | 1437 | */ |
1438 | - $vocabulary_terms_loader = new Vocabulary_Terms_Loader( Wordlift_Entity_Type_Service::get_instance(), $property_getter ); |
|
1438 | + $vocabulary_terms_loader = new Vocabulary_Terms_Loader(Wordlift_Entity_Type_Service::get_instance(), $property_getter); |
|
1439 | 1439 | $vocabulary_terms_loader->init_feature(); |
1440 | 1440 | |
1441 | 1441 | new Entity_Type_Change_Handler( |
@@ -1464,9 +1464,9 @@ discard block |
||
1464 | 1464 | private function set_locale() { |
1465 | 1465 | |
1466 | 1466 | $plugin_i18n = new Wordlift_I18n(); |
1467 | - $plugin_i18n->set_domain( $this->get_plugin_name() ); |
|
1467 | + $plugin_i18n->set_domain($this->get_plugin_name()); |
|
1468 | 1468 | |
1469 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
1469 | + $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); |
|
1470 | 1470 | |
1471 | 1471 | } |
1472 | 1472 | |
@@ -1477,7 +1477,7 @@ discard block |
||
1477 | 1477 | * @since 1.0.0 |
1478 | 1478 | * @access private |
1479 | 1479 | */ |
1480 | - private function define_admin_hooks( $that ) { |
|
1480 | + private function define_admin_hooks($that) { |
|
1481 | 1481 | $plugin_admin = new Wordlift_Admin( |
1482 | 1482 | $that->get_plugin_name(), |
1483 | 1483 | $that->get_version(), |
@@ -1485,51 +1485,51 @@ discard block |
||
1485 | 1485 | $that->user_service |
1486 | 1486 | ); |
1487 | 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 ); |
|
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 | 1490 | |
1491 | 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' ); |
|
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 | 1494 | |
1495 | 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' ); |
|
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 | 1498 | |
1499 | 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' ); |
|
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 | 1502 | |
1503 | 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 ); |
|
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 | 1506 | |
1507 | 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' ); |
|
1508 | + $that->loader->add_action('wp_ajax_wl_timeline', $that->timeline_service, 'ajax_timeline'); |
|
1509 | 1509 | |
1510 | 1510 | // Register custom allowed redirect hosts. |
1511 | - $that->loader->add_filter( 'allowed_redirect_hosts', $that->redirect_service, 'allowed_redirect_hosts' ); |
|
1511 | + $that->loader->add_filter('allowed_redirect_hosts', $that->redirect_service, 'allowed_redirect_hosts'); |
|
1512 | 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' ); |
|
1513 | + $that->loader->add_action('wp_ajax_wordlift_redirect', $that->redirect_service, 'ajax_redirect'); |
|
1514 | 1514 | |
1515 | 1515 | // Hook save_post to the entity service to update custom fields (such as alternate labels). |
1516 | 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 ); |
|
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 | 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' ); |
|
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 | 1522 | |
1523 | 1523 | // Entity listing customization (wp-admin/edit.php) |
1524 | 1524 | // Add custom columns. |
1525 | - $that->loader->add_filter( 'manage_entity_posts_columns', $that->entity_list_service, 'register_custom_columns' ); |
|
1525 | + $that->loader->add_filter('manage_entity_posts_columns', $that->entity_list_service, 'register_custom_columns'); |
|
1526 | 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 ); |
|
1527 | + $that->loader->add_filter('manage_posts_custom_column', $that->entity_list_service, 'render_custom_columns', 10, 2); |
|
1528 | 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' ); |
|
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 | 1533 | |
1534 | 1534 | /* |
1535 | 1535 | * If `All Entity Types` is disable, use the radio button Walker. |
@@ -1537,18 +1537,18 @@ discard block |
||
1537 | 1537 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
1538 | 1538 | */ |
1539 | 1539 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
1540 | - if ( ! apply_filters( 'wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES ) |
|
1540 | + if ( ! apply_filters('wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES) |
|
1541 | 1541 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
1542 | - && ! apply_filters( 'wl_feature__enable__entity-types-professional', false ) |
|
1542 | + && ! apply_filters('wl_feature__enable__entity-types-professional', false) |
|
1543 | 1543 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
1544 | - && ! apply_filters( 'wl_feature__enable__entity-types-business', false ) |
|
1544 | + && ! apply_filters('wl_feature__enable__entity-types-business', false) |
|
1545 | 1545 | ) { |
1546 | - $that->loader->add_filter( 'wp_terms_checklist_args', $that->entity_types_taxonomy_walker, 'terms_checklist_args' ); |
|
1546 | + $that->loader->add_filter('wp_terms_checklist_args', $that->entity_types_taxonomy_walker, 'terms_checklist_args'); |
|
1547 | 1547 | } |
1548 | 1548 | |
1549 | 1549 | // Hook the PrimaShop adapter to <em>prima_metabox_entity_header_args</em> in order to add header support for |
1550 | 1550 | // entities. |
1551 | - $that->loader->add_filter( 'prima_metabox_entity_header_args', $that->primashop_adapter, 'prima_metabox_entity_header_args', 10 ); |
|
1551 | + $that->loader->add_filter('prima_metabox_entity_header_args', $that->primashop_adapter, 'prima_metabox_entity_header_args', 10); |
|
1552 | 1552 | |
1553 | 1553 | /** |
1554 | 1554 | * Filter: wl_feature__enable__settings-download. |
@@ -1568,20 +1568,20 @@ discard block |
||
1568 | 1568 | ); |
1569 | 1569 | |
1570 | 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 ); |
|
1571 | + $that->loader->add_action('wp_ajax_wl_download_your_data', $that->download_your_data_page, 'download_your_data', 10); |
|
1572 | 1572 | |
1573 | 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' ); |
|
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 | 1577 | |
1578 | 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' ); |
|
1579 | + $that->loader->add_action('wp_ajax_wl_validate_key', $that->key_validation_service, 'validate_key'); |
|
1580 | 1580 | |
1581 | 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' ); |
|
1582 | + $that->loader->add_action('wp_ajax_wl_update_country_options', $that->country_select_element, 'get_options_html'); |
|
1583 | 1583 | |
1584 | - $that->loader->add_filter( 'admin_post_thumbnail_html', $that->publisher_service, 'add_featured_image_instruction' ); |
|
1584 | + $that->loader->add_filter('admin_post_thumbnail_html', $that->publisher_service, 'add_featured_image_instruction'); |
|
1585 | 1585 | |
1586 | 1586 | // Hook the menu creation on the general wordlift menu creation. |
1587 | 1587 | /** |
@@ -1595,16 +1595,16 @@ discard block |
||
1595 | 1595 | * Since 3.30.0 this feature is registered using registry. |
1596 | 1596 | */ |
1597 | 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 ); |
|
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 | 1600 | } |
1601 | 1601 | |
1602 | 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 ); |
|
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 | 1605 | |
1606 | 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 ); |
|
1607 | + $that->loader->add_filter('plugin_action_links_wordlift/wordlift.php', $that->settings_page_action_link, 'action_links', 10, 1); |
|
1608 | 1608 | |
1609 | 1609 | /* |
1610 | 1610 | * Remove the Analytics Settings link from the plugin page. |
@@ -1615,23 +1615,23 @@ discard block |
||
1615 | 1615 | // $that->loader->add_filter( 'plugin_action_links_wordlift/wordlift.php', $that->analytics_settings_page_action_link, 'action_links', 10, 1 ); |
1616 | 1616 | |
1617 | 1617 | // Hook the AJAX `wl_publisher` action name. |
1618 | - $that->loader->add_action( 'wp_ajax_wl_publisher', $that->publisher_ajax_adapter, 'publisher' ); |
|
1618 | + $that->loader->add_action('wp_ajax_wl_publisher', $that->publisher_ajax_adapter, 'publisher'); |
|
1619 | 1619 | |
1620 | 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 ); |
|
1621 | + $that->loader->add_filter('wl_entity_type_row_actions', $that->entity_type_admin_page, 'wl_entity_type_row_actions', 10, 2); |
|
1622 | 1622 | |
1623 | 1623 | /** Ajax actions. */ |
1624 | - $that->loader->add_action( 'wp_ajax_wl_google_analytics_export', $that->google_analytics_export_service, 'export' ); |
|
1624 | + $that->loader->add_action('wp_ajax_wl_google_analytics_export', $that->google_analytics_export_service, 'export'); |
|
1625 | 1625 | |
1626 | 1626 | // Hook capabilities manipulation to allow access to entity type admin |
1627 | 1627 | // page on WordPress versions before 4.7. |
1628 | 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 ); |
|
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 | 1631 | } |
1632 | 1632 | |
1633 | 1633 | /** Adapters. */ |
1634 | - $that->loader->add_filter( 'mce_external_plugins', $that->tinymce_adapter, 'mce_external_plugins', 10, 1 ); |
|
1634 | + $that->loader->add_filter('mce_external_plugins', $that->tinymce_adapter, 'mce_external_plugins', 10, 1); |
|
1635 | 1635 | /** |
1636 | 1636 | * Disabling Faq temporarily. |
1637 | 1637 | * Load the tinymce editor button on the tool bar. |
@@ -1642,14 +1642,14 @@ discard block |
||
1642 | 1642 | // $that->loader->add_filter( 'mce_buttons', $that->faq_tinymce_adapter, 'register_faq_toolbar_button', 10, 1 ); |
1643 | 1643 | // $that->loader->add_filter( 'mce_external_plugins', $that->faq_tinymce_adapter, 'register_faq_tinymce_plugin', 10, 1 ); |
1644 | 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' ); |
|
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 | 1647 | |
1648 | 1648 | /** |
1649 | 1649 | * @since 3.26.0 |
1650 | 1650 | */ |
1651 | 1651 | $excerpt_adapter = new Post_Excerpt_Meta_Box_Adapter(); |
1652 | - $that->loader->add_action( 'do_meta_boxes', $excerpt_adapter, 'replace_post_excerpt_meta_box' ); |
|
1652 | + $that->loader->add_action('do_meta_boxes', $excerpt_adapter, 'replace_post_excerpt_meta_box'); |
|
1653 | 1653 | // Adding Rest route for the post excerpt |
1654 | 1654 | Post_Excerpt_Rest_Controller::register_routes(); |
1655 | 1655 | |
@@ -1670,13 +1670,13 @@ discard block |
||
1670 | 1670 | ); |
1671 | 1671 | |
1672 | 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 ); |
|
1673 | + if (is_multisite()) { |
|
1674 | + $that->loader->add_filter('map_meta_cap', $that->entity_type_admin_page, 'restrict_super_admin', 10, 2); |
|
1675 | 1675 | } |
1676 | 1676 | |
1677 | 1677 | $deactivator_feedback = new Wordlift_Deactivator_Feedback(); |
1678 | 1678 | |
1679 | - add_action( 'admin_footer', array( $deactivator_feedback, 'render_feedback_popup' ) ); |
|
1679 | + add_action('admin_footer', array($deactivator_feedback, 'render_feedback_popup')); |
|
1680 | 1680 | add_action( |
1681 | 1681 | 'admin_enqueue_scripts', |
1682 | 1682 | array( |
@@ -1699,13 +1699,13 @@ discard block |
||
1699 | 1699 | */ |
1700 | 1700 | add_filter( |
1701 | 1701 | 'allowed_block_types', |
1702 | - function ( $value ) { |
|
1702 | + function($value) { |
|
1703 | 1703 | |
1704 | - if ( true === $value ) { |
|
1704 | + if (true === $value) { |
|
1705 | 1705 | return $value; |
1706 | 1706 | } |
1707 | 1707 | |
1708 | - return array_merge( (array) $value, array( 'wordlift/classification' ) ); |
|
1708 | + return array_merge((array) $value, array('wordlift/classification')); |
|
1709 | 1709 | }, |
1710 | 1710 | PHP_INT_MAX |
1711 | 1711 | ); |
@@ -1718,23 +1718,23 @@ discard block |
||
1718 | 1718 | |
1719 | 1719 | add_action( |
1720 | 1720 | 'admin_notices', |
1721 | - function () { |
|
1722 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
1721 | + function() { |
|
1722 | + if (apply_filters('wl_feature__enable__notices', true)) { |
|
1723 | 1723 | /** |
1724 | 1724 | * Fired when the notice feature is enabled. |
1725 | 1725 | * |
1726 | 1726 | * @since 3.40.4 |
1727 | 1727 | */ |
1728 | - do_action( 'wordlift_admin_notices' ); |
|
1728 | + do_action('wordlift_admin_notices'); |
|
1729 | 1729 | } |
1730 | 1730 | } |
1731 | 1731 | ); |
1732 | 1732 | |
1733 | 1733 | add_action( |
1734 | 1734 | 'admin_init', |
1735 | - function () { |
|
1735 | + function() { |
|
1736 | 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() ) { |
|
1737 | + if (\Wordlift_Configuration_Service::get_instance()->get_key() && ! \Wordlift_Configuration_Service::get_instance()->get_skip_installation_notice()) { |
|
1738 | 1738 | $installation_complete_notice = new Installation_Complete_Notice(); |
1739 | 1739 | $installation_complete_notice->init(); |
1740 | 1740 | } |
@@ -1750,57 +1750,57 @@ discard block |
||
1750 | 1750 | * @since 1.0.0 |
1751 | 1751 | * @access private |
1752 | 1752 | */ |
1753 | - private function define_public_hooks( $that ) { |
|
1753 | + private function define_public_hooks($that) { |
|
1754 | 1754 | |
1755 | - $plugin_public = new Wordlift_Public( $that->get_plugin_name(), $that->get_version() ); |
|
1755 | + $plugin_public = new Wordlift_Public($that->get_plugin_name(), $that->get_version()); |
|
1756 | 1756 | |
1757 | 1757 | // Register the entity post type. |
1758 | - $that->loader->add_action( 'init', $that->entity_post_type_service, 'register' ); |
|
1758 | + $that->loader->add_action('init', $that->entity_post_type_service, 'register'); |
|
1759 | 1759 | |
1760 | 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 ); |
|
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 | 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' ); |
|
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 | 1767 | |
1768 | 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' ); |
|
1769 | + $that->loader->add_filter('the_content', $that->faq_content_filter_service, 'remove_all_faq_question_and_answer_tags'); |
|
1770 | 1770 | // Hook the content filter service to add entity links. |
1771 | - if ( ! defined( 'WL_DISABLE_CONTENT_FILTER' ) || ! WL_DISABLE_CONTENT_FILTER ) { |
|
1771 | + if ( ! defined('WL_DISABLE_CONTENT_FILTER') || ! WL_DISABLE_CONTENT_FILTER) { |
|
1772 | 1772 | // We run before other filters. |
1773 | - $that->loader->add_filter( 'the_content', $that->content_filter_service, 'the_content', 9 ); |
|
1773 | + $that->loader->add_filter('the_content', $that->content_filter_service, 'the_content', 9); |
|
1774 | 1774 | } |
1775 | 1775 | |
1776 | 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' ); |
|
1777 | + $that->loader->add_action('wp_ajax_nopriv_wl_timeline', $that->timeline_service, 'ajax_timeline'); |
|
1778 | 1778 | |
1779 | 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 ); |
|
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 | 1782 | |
1783 | 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' ); |
|
1784 | + $that->loader->add_action('wp_ajax_nopriv_wl_jsonld', $that->jsonld_service, 'get'); |
|
1785 | 1785 | |
1786 | 1786 | // Hook the `pre_get_posts` action to the `Wordlift_Category_Taxonomy_Service` |
1787 | 1787 | // in order to tweak WP's `WP_Query` to include entities in queries related |
1788 | 1788 | // to categories. |
1789 | - $that->loader->add_action( 'pre_get_posts', $that->category_taxonomy_service, 'pre_get_posts', 10, 1 ); |
|
1789 | + $that->loader->add_action('pre_get_posts', $that->category_taxonomy_service, 'pre_get_posts', 10, 1); |
|
1790 | 1790 | |
1791 | 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 ); |
|
1796 | + $that->loader->add_action('pre_get_posts', $that->entity_page_service, 'pre_get_posts', 10, 1); |
|
1797 | 1797 | |
1798 | 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 ); |
|
1799 | + $that->loader->add_action('save_post', $that->entity_type_adapter, 'save_post', 9, 2); |
|
1800 | 1800 | |
1801 | 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 ); |
|
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 | 1804 | } |
1805 | 1805 | |
1806 | 1806 | } |
@@ -1865,7 +1865,7 @@ discard block |
||
1865 | 1865 | * @since 3.27.6 |
1866 | 1866 | */ |
1867 | 1867 | // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter,WordPress.WP.EnqueuedResourceParameters.MissingVersion |
1868 | - wp_register_script( 'wl_enabled_blocks', false ); |
|
1868 | + wp_register_script('wl_enabled_blocks', false); |
|
1869 | 1869 | |
1870 | 1870 | $enabled_blocks = array(); |
1871 | 1871 | |
@@ -1875,11 +1875,11 @@ discard block |
||
1875 | 1875 | * @since 3.32.3 |
1876 | 1876 | */ |
1877 | 1877 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
1878 | - if ( apply_filters( 'wl_feature__enable__product-navigator', true ) ) { |
|
1878 | + if (apply_filters('wl_feature__enable__product-navigator', true)) { |
|
1879 | 1879 | $enabled_blocks[] = 'wordlift/products-navigator'; |
1880 | 1880 | } |
1881 | 1881 | |
1882 | - if ( apply_filters( 'wl_feature__enable__blocks', true ) ) { |
|
1882 | + if (apply_filters('wl_feature__enable__blocks', true)) { |
|
1883 | 1883 | // To intimate JS |
1884 | 1884 | $enabled_blocks = array_merge( |
1885 | 1885 | $enabled_blocks, |
@@ -1895,8 +1895,8 @@ discard block |
||
1895 | 1895 | ); |
1896 | 1896 | } |
1897 | 1897 | |
1898 | - wp_localize_script( 'wl_enabled_blocks', 'wlEnabledBlocks', $enabled_blocks ); |
|
1899 | - wp_enqueue_script( 'wl_enabled_blocks' ); |
|
1898 | + wp_localize_script('wl_enabled_blocks', 'wlEnabledBlocks', $enabled_blocks); |
|
1899 | + wp_enqueue_script('wl_enabled_blocks'); |
|
1900 | 1900 | } |
1901 | 1901 | |
1902 | 1902 | /** |
@@ -1905,8 +1905,8 @@ discard block |
||
1905 | 1905 | public function register_screens() { |
1906 | 1906 | // Hook the menu to the Download Your Data page. |
1907 | 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" ); |
|
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 | 1910 | add_action( |
1911 | 1911 | 'admin_menu', |
1912 | 1912 | array( |
@@ -1918,7 +1918,7 @@ discard block |
||
1918 | 1918 | ); |
1919 | 1919 | } |
1920 | 1920 | |
1921 | - Assertions::is_set( $this->entity_type_settings_admin_page, "`entity_type_settings_admin_page` can't be null" ); |
|
1921 | + Assertions::is_set($this->entity_type_settings_admin_page, "`entity_type_settings_admin_page` can't be null"); |
|
1922 | 1922 | add_action( |
1923 | 1923 | 'admin_menu', |
1924 | 1924 | array( |
@@ -13,214 +13,214 @@ |
||
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 | } |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @since 3.8.0 |
44 | 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 ); |
|
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 | 47 | $this->schemaorg_property_service = $schemaorg_property_service; |
48 | 48 | $this->post_to_jsonld_converter = $post_to_jsonld_converter; |
49 | 49 | } |
@@ -59,28 +59,28 @@ discard block |
||
59 | 59 | * @return array A JSON-LD array. |
60 | 60 | * @since 3.8.0 |
61 | 61 | */ |
62 | - public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null ) { |
|
62 | + public function convert($post_id, &$references = array(), &$references_infos = array(), $relations = null) { |
|
63 | 63 | |
64 | 64 | // Get the post instance. |
65 | - $post = get_post( $post_id ); |
|
66 | - if ( null === $post ) { |
|
65 | + $post = get_post($post_id); |
|
66 | + if (null === $post) { |
|
67 | 67 | // Post not found. |
68 | 68 | return null; |
69 | 69 | } |
70 | 70 | |
71 | 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 ); |
|
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 | 74 | } else { |
75 | - $jsonld = parent::convert( $post_id, $references, $references_infos, $relations ); |
|
75 | + $jsonld = parent::convert($post_id, $references, $references_infos, $relations); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Get the entity name. |
79 | - $jsonld['name'] = html_entity_decode( $post->post_title ); |
|
79 | + $jsonld['name'] = html_entity_decode($post->post_title); |
|
80 | 80 | |
81 | 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 ) ) { |
|
82 | + $alternative_labels = Wordlift_Entity_Service::get_instance()->get_alternative_labels($post_id); |
|
83 | + if (0 < count($alternative_labels)) { |
|
84 | 84 | $jsonld['alternateName'] = $alternative_labels; |
85 | 85 | } |
86 | 86 | |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | // |
89 | 89 | // This allows us to gather the basic properties as defined by the `Thing` entity type. |
90 | 90 | // Get the configured type custom fields. |
91 | - $custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id ); |
|
91 | + $custom_fields = $this->entity_type_service->get_custom_fields_for_post($post_id); |
|
92 | 92 | |
93 | - if ( isset( $custom_fields ) ) { |
|
94 | - $this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos ); |
|
93 | + if (isset($custom_fields)) { |
|
94 | + $this->process_type_custom_fields($jsonld, $custom_fields, $post, $references, $references_infos); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /* |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
103 | 103 | */ |
104 | 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 ); |
|
105 | + if (apply_filters('wl_feature__enable__all-entity-types', WL_ALL_ENTITY_TYPES)) { |
|
106 | + $this->process_post_properties($jsonld, $post_id); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @api |
122 | 122 | */ |
123 | - $ret_val = apply_filters( |
|
123 | + $ret_val = apply_filters( |
|
124 | 124 | 'wl_entity_jsonld_array', |
125 | 125 | array( |
126 | 126 | 'jsonld' => $jsonld, |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * |
143 | 143 | * @api |
144 | 144 | */ |
145 | - return apply_filters( 'wl_entity_jsonld', $this->post_process( $jsonld ), $post_id, $references ); |
|
145 | + return apply_filters('wl_entity_jsonld', $this->post_process($jsonld), $post_id, $references); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @since 3.20.0 |
155 | 155 | */ |
156 | - private function process_post_properties( &$jsonld, $post_id ) { |
|
156 | + private function process_post_properties(&$jsonld, $post_id) { |
|
157 | 157 | |
158 | 158 | // Get all the props. |
159 | - $props = $this->schemaorg_property_service->get_all( $post_id ); |
|
159 | + $props = $this->schemaorg_property_service->get_all($post_id); |
|
160 | 160 | |
161 | 161 | // Process all the props. |
162 | - foreach ( $props as $name => $instances ) { |
|
162 | + foreach ($props as $name => $instances) { |
|
163 | 163 | |
164 | 164 | // Get the values. |
165 | 165 | $values = array_map( |
166 | - function ( $instance ) { |
|
166 | + function($instance) { |
|
167 | 167 | return $instance['value']; |
168 | 168 | }, |
169 | 169 | $instances |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | // We might receive empty values, remove them. |
173 | 173 | $non_empty_values = array_filter( |
174 | 174 | $values, |
175 | - function ( $value ) { |
|
176 | - return ! empty( $value ); |
|
175 | + function($value) { |
|
176 | + return ! empty($value); |
|
177 | 177 | } |
178 | 178 | ); |
179 | 179 | |
180 | 180 | // Skip empty properties. |
181 | - if ( empty( $non_empty_values ) ) { |
|
181 | + if (empty($non_empty_values)) { |
|
182 | 182 | continue; |
183 | 183 | } |
184 | 184 | |
185 | 185 | // @@todo: need to handle maybe Numbers and URLs differently. |
186 | 186 | // Make an array a single value when possible. |
187 | - $jsonld[ $name ] = self::make_one( $non_empty_values ); |
|
187 | + $jsonld[$name] = self::make_one($non_empty_values); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | } |
@@ -198,25 +198,25 @@ discard block |
||
198 | 198 | * @return array The array remapped. |
199 | 199 | * @since 3.8.0 |
200 | 200 | */ |
201 | - public static function post_process( $jsonld ) { |
|
201 | + public static function post_process($jsonld) { |
|
202 | 202 | |
203 | - foreach ( $jsonld as $key => $value ) { |
|
204 | - if ( 'streetAddress' === $key || 'postalCode' === $key || 'addressLocality' === $key || 'addressRegion' === $key || 'addressCountry' === $key || 'postOfficeBoxNumber' === $key ) { |
|
203 | + foreach ($jsonld as $key => $value) { |
|
204 | + if ('streetAddress' === $key || 'postalCode' === $key || 'addressLocality' === $key || 'addressRegion' === $key || 'addressCountry' === $key || 'postOfficeBoxNumber' === $key) { |
|
205 | 205 | $jsonld['address']['@type'] = 'PostalAddress'; |
206 | - $jsonld['address'][ $key ] = $value; |
|
207 | - unset( $jsonld[ $key ] ); |
|
206 | + $jsonld['address'][$key] = $value; |
|
207 | + unset($jsonld[$key]); |
|
208 | 208 | } |
209 | 209 | |
210 | - if ( 'latitude' === $key || 'longitude' === $key ) { |
|
210 | + if ('latitude' === $key || 'longitude' === $key) { |
|
211 | 211 | $jsonld['geo']['@type'] = 'GeoCoordinates'; |
212 | - $jsonld['geo'][ $key ] = $value; |
|
213 | - unset( $jsonld[ $key ] ); |
|
212 | + $jsonld['geo'][$key] = $value; |
|
213 | + unset($jsonld[$key]); |
|
214 | 214 | } |
215 | 215 | |
216 | - if ( 'calories' === $key ) { |
|
216 | + if ('calories' === $key) { |
|
217 | 217 | $jsonld['nutrition']['@type'] = 'NutritionInformation'; |
218 | - $jsonld['nutrition'][ $key ] = $value; |
|
219 | - unset( $jsonld[ $key ] ); |
|
218 | + $jsonld['nutrition'][$key] = $value; |
|
219 | + unset($jsonld[$key]); |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 |
@@ -16,56 +16,56 @@ |
||
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 | } |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @since 3.8.0 |
38 | 38 | */ |
39 | - public function __construct( $entity_post_to_jsonld_converter, $post_to_jsonld_converter ) { |
|
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 | 43 | $this->entity_post_to_jsonld_converter = $entity_post_to_jsonld_converter; |
44 | 44 | $this->post_to_jsonld_converter = $post_to_jsonld_converter; |
@@ -55,17 +55,17 @@ discard block |
||
55 | 55 | * @return array|NULL A JSON-LD array representation of the post with the provided id, or NULL if not found. |
56 | 56 | * @since 3.8.0 |
57 | 57 | */ |
58 | - public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null ) { |
|
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 | 62 | $entity_service = Wordlift_Entity_Service::get_instance(); |
63 | 63 | |
64 | - return $entity_service->is_entity( $post_id ) |
|
64 | + return $entity_service->is_entity($post_id) |
|
65 | 65 | // Entity. |
66 | - ? $this->entity_post_to_jsonld_converter->convert( $post_id, $references, $references_infos, $relations ) |
|
66 | + ? $this->entity_post_to_jsonld_converter->convert($post_id, $references, $references_infos, $relations) |
|
67 | 67 | // Post/Page. |
68 | - : $this->post_to_jsonld_converter->convert( $post_id, $references, $references_infos, $relations ); |
|
68 | + : $this->post_to_jsonld_converter->convert($post_id, $references, $references_infos, $relations); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | } |
@@ -21,365 +21,365 @@ |
||
21 | 21 | */ |
22 | 22 | class Wordlift_Cached_Post_Converter implements Wordlift_Post_Converter { |
23 | 23 | |
24 | - /** |
|
25 | - * A {@link Wordlift_Post_Converter} instance. |
|
26 | - * |
|
27 | - * @since 3.16.0 |
|
28 | - * |
|
29 | - * @var \Wordlift_Post_Converter $converter A {@link Wordlift_Post_Converter} instance. |
|
30 | - */ |
|
31 | - private $converter; |
|
32 | - |
|
33 | - /** |
|
34 | - * A {@link Wordlift_Log_Service} instance. |
|
35 | - * |
|
36 | - * @since 3.16.0 |
|
37 | - * |
|
38 | - * @var Wordlift_Log_Service \$log A {@link Wordlift_Log_Service} instance. |
|
39 | - */ |
|
40 | - private $log; |
|
41 | - |
|
42 | - /** |
|
43 | - * A list of meta keys that do not cause the cache to update. |
|
44 | - * |
|
45 | - * @since 3.17.3 |
|
46 | - * @var array An array of ignored meta keys. |
|
47 | - */ |
|
48 | - private static $ignored_meta_keys = array( |
|
49 | - '_edit_lock', |
|
50 | - '_edit_last', |
|
51 | - '_wp_page_template', |
|
52 | - '_wp_attachment_is_custom_background', |
|
53 | - '_wp_attachment_backup_sizes', |
|
54 | - '_wp_attachment_is_custom_header', |
|
55 | - ); |
|
56 | - /** |
|
57 | - * @var Ttl_Cache |
|
58 | - */ |
|
59 | - private $cache; |
|
60 | - |
|
61 | - /** |
|
62 | - * Wordlift_Cached_Post_Converter constructor. |
|
63 | - * |
|
64 | - * @param \Wordlift_Post_Converter $converter The {@link Wordlift_Post_Converter} implementation. |
|
65 | - * @param Ttl_Cache $cache The {@link Ttl_Cache} cache instance. |
|
66 | - */ |
|
67 | - public function __construct( $converter, $cache ) { |
|
68 | - |
|
69 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
70 | - |
|
71 | - $this->cache = $cache; |
|
72 | - $this->converter = $converter; |
|
73 | - $this->init_hooks(); |
|
74 | - |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Hooks to catch post/post meta changes in order to invalidate the cache. |
|
79 | - * |
|
80 | - * @since 3.16.0 |
|
81 | - */ |
|
82 | - private function init_hooks() { |
|
83 | - |
|
84 | - // Hook on post save to flush relevant cache. |
|
85 | - add_action( 'save_post', array( $this, 'save_post' ) ); |
|
86 | - |
|
87 | - add_action( |
|
88 | - 'added_post_meta', |
|
89 | - array( |
|
90 | - $this, |
|
91 | - 'changed_post_meta', |
|
92 | - ), |
|
93 | - 10, |
|
94 | - 3 |
|
95 | - ); |
|
96 | - add_action( |
|
97 | - 'updated_post_meta', |
|
98 | - array( |
|
99 | - $this, |
|
100 | - 'changed_post_meta', |
|
101 | - ), |
|
102 | - 10, |
|
103 | - 3 |
|
104 | - ); |
|
105 | - add_action( |
|
106 | - 'deleted_post_meta', |
|
107 | - array( |
|
108 | - $this, |
|
109 | - 'changed_post_meta', |
|
110 | - ), |
|
111 | - 10, |
|
112 | - 3 |
|
113 | - ); |
|
114 | - |
|
115 | - // Flush cache when wordlift settings were updated. |
|
116 | - add_action( |
|
117 | - 'update_option_wl_general_settings', |
|
118 | - array( |
|
119 | - $this, |
|
120 | - 'update_option_wl_general_settings', |
|
121 | - ) |
|
122 | - ); |
|
123 | - |
|
124 | - // Flushes the cache when permalink structure is changed. |
|
125 | - add_action( |
|
126 | - 'update_option_permalink_structure', |
|
127 | - array( |
|
128 | - $this, |
|
129 | - 'permalinks_structure_changed', |
|
130 | - ) |
|
131 | - ); |
|
132 | - |
|
133 | - // Invalid cache on relationship change. |
|
134 | - add_action( 'wl_relation_added', array( $this, 'relation_changed' ) ); |
|
135 | - add_action( 'wl_relation_deleted', array( $this, 'relation_changed' ) ); |
|
136 | - |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Note that the `&$cache` parameter here is used only to report whether the response comes from the cache. It |
|
141 | - * used by `test-issue-626.php` and nowhere else in code. |
|
142 | - * |
|
143 | - * @inheritdoc |
|
144 | - */ |
|
145 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
146 | - public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null, &$cache = false ) { |
|
147 | - |
|
148 | - // Ensure post ID is `int`. Otherwise we may have issues with caching, since caching is strict about |
|
149 | - // key var types. |
|
150 | - $post_id = (int) $post_id; |
|
151 | - |
|
152 | - $this->log->trace( "Converting post $post_id..." ); |
|
153 | - |
|
154 | - // Try to get a cached result. |
|
155 | - $arr = $this->get_cache( $post_id ); |
|
156 | - |
|
157 | - // Return the cached contents if any. |
|
158 | - if ( false !== $arr ) { |
|
159 | - $contents = $arr['jsonld']; |
|
160 | - |
|
161 | - // Add the cached relations if any. |
|
162 | - if ( is_a( $arr['relations'], 'Wordlift\Relation\Relations' ) ) { |
|
163 | - $relations->add( ...$arr['relations']->toArray() ); |
|
164 | - } |
|
165 | - |
|
166 | - if ( is_array( $arr['references'] ) ) { |
|
167 | - $references = $arr['references']; |
|
168 | - } |
|
169 | - |
|
170 | - $this->log->debug( "Cached contents found for post $post_id." ); |
|
171 | - |
|
172 | - // Inform the caller that this is cached result. |
|
173 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
174 | - $cache = true; |
|
175 | - $this->add_http_header( $post_id, true ); |
|
176 | - |
|
177 | - // Return the contents. |
|
178 | - return $contents; |
|
179 | - } |
|
180 | - |
|
181 | - // Set cached to false. |
|
182 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
183 | - $cache = false; |
|
184 | - $this->add_http_header( $post_id, false ); |
|
185 | - |
|
186 | - // Convert the post. |
|
187 | - $jsonld = $this->converter->convert( $post_id, $references, $references_infos, $relations ); |
|
188 | - |
|
189 | - /** |
|
190 | - * @since 3.32.0 |
|
191 | - * We cant apply json_encode on the objects {@link \Wordlift\Jsonld\Reference}, so we decode |
|
192 | - * it here before saving it on cache. |
|
193 | - */ |
|
194 | - // Cache the results. |
|
195 | - $this->set_cache( $post_id, $references, $jsonld, $relations ); |
|
196 | - |
|
197 | - // Finally return the JSON-LD. |
|
198 | - return $jsonld; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Try to get the cached contents. |
|
203 | - * |
|
204 | - * @param int $post_id The {@link WP_Post} id. |
|
205 | - * @param array $references The referenced posts. |
|
206 | - * |
|
207 | - * @return mixed|bool The cached contents or false if the cached isn't found. |
|
208 | - * @since 3.16.0 |
|
209 | - */ |
|
210 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
211 | - private function get_cache( $post_id ) { |
|
212 | - |
|
213 | - // Ensure post ID is int, because cache is strict about var types. |
|
214 | - $post_id = (int) $post_id; |
|
215 | - |
|
216 | - $this->log->trace( "Getting cached contents for post $post_id..." ); |
|
217 | - |
|
218 | - // Get the cache. |
|
219 | - $modified_date_time = get_post_datetime( $post_id, 'modified', 'gmt' ); |
|
220 | - $contents = $this->cache->get( $post_id, $modified_date_time ? $modified_date_time->getTimestamp() : 0 ); |
|
221 | - |
|
222 | - // Bail out if we don't have cached contents or the cached contents are |
|
223 | - // invalid. |
|
224 | - if ( null === $contents || ! isset( $contents['jsonld'] ) || ! isset( $contents['references'] ) || ! isset( $contents['relations'] ) ) { |
|
225 | - $this->log->debug( "Cached contents for post $post_id not found." ); |
|
226 | - |
|
227 | - return false; |
|
228 | - } |
|
229 | - |
|
230 | - return $contents['jsonld'] |
|
231 | - ? array( |
|
232 | - 'jsonld' => $contents['jsonld'], |
|
233 | - 'relations' => Relations::from_json( $contents['relations'] ), |
|
234 | - 'references' => $contents['references'], |
|
235 | - ) |
|
236 | - : false; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Set the cache with the provided results. |
|
241 | - * |
|
242 | - * The function will prepare the provided results and will ask the {@link Ttl_Cache} to cache them. |
|
243 | - * |
|
244 | - * @param int $post_id The {@link WP_Post} id. |
|
245 | - * @param array $references An array of references. |
|
246 | - * @param array $jsonld A JSON-LD structure. |
|
247 | - * |
|
248 | - * @since 3.16.0 |
|
249 | - */ |
|
250 | - private function set_cache( $post_id, $references, $jsonld, $relations ) { |
|
251 | - |
|
252 | - $this->log->trace( "Caching result for post $post_id..." ); |
|
253 | - |
|
254 | - $this->cache->put( |
|
255 | - $post_id, |
|
256 | - array( |
|
257 | - // @@todo check the `references`. |
|
258 | - 'references' => $references, |
|
259 | - 'jsonld' => $jsonld, |
|
260 | - 'relations' => $relations, |
|
261 | - ) |
|
262 | - ); |
|
263 | - |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Hook to 'save_post', will invalidate the cache for that post. |
|
268 | - * |
|
269 | - * @param int $post_id The {@link WP_Post} id. |
|
270 | - * |
|
271 | - * @since 3.16.0 |
|
272 | - */ |
|
273 | - public function save_post( $post_id ) { |
|
274 | - |
|
275 | - $this->log->trace( "Post $post_id saved, invalidating cache..." ); |
|
276 | - |
|
277 | - $this->cache->delete( $post_id ); |
|
278 | - |
|
279 | - $this->flush_cache_if_publisher( $post_id ); |
|
280 | - |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Hook to meta changed for a {@link WP_Post}, will cause the cause to |
|
285 | - * invalidate. |
|
286 | - * |
|
287 | - * @param int $id The {@link WP_Post} meta id. |
|
288 | - * @param int $post_id The {@link WP_Post} id. |
|
289 | - * @param string $meta_key The meta key. |
|
290 | - * |
|
291 | - * @since 3.16.0 |
|
292 | - */ |
|
293 | - public function changed_post_meta( $id, $post_id, $meta_key ) { |
|
294 | - |
|
295 | - if ( in_array( $meta_key, self::$ignored_meta_keys, true ) ) { |
|
296 | - $this->log->trace( "Post $post_id meta $meta_key ignored." ); |
|
297 | - |
|
298 | - return; |
|
299 | - } |
|
300 | - |
|
301 | - $this->log->trace( "Post $post_id meta $meta_key changed, invalidating cache..." ); |
|
302 | - |
|
303 | - // Delete the single cache file. |
|
304 | - $this->cache->delete( $post_id ); |
|
305 | - |
|
306 | - // Flush the cache if it's the publisher. |
|
307 | - $this->flush_cache_if_publisher( $post_id ); |
|
308 | - |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Hook to WordLift's options changes, will flush the cache. |
|
313 | - * |
|
314 | - * @since 3.16.0 |
|
315 | - */ |
|
316 | - public function update_option_wl_general_settings() { |
|
317 | - $this->log->trace( 'WordLift options changed, flushing cache...' ); |
|
318 | - |
|
319 | - $this->cache->flush(); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Hook when permalinks are changed, will flush the cache. |
|
324 | - * |
|
325 | - * @since 3.17.0 |
|
326 | - */ |
|
327 | - public function permalinks_structure_changed() { |
|
328 | - $this->log->trace( 'Permalinks structure changed, flushing cache...' ); |
|
329 | - |
|
330 | - $this->cache->flush(); |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Hook to WordLift's post/entity relation changes, will invalidate the cache. |
|
335 | - * |
|
336 | - * @param int $post_id The {@link WP_Post} id. |
|
337 | - * |
|
338 | - * @since 3.16.0 |
|
339 | - */ |
|
340 | - public function relation_changed( $post_id ) { |
|
341 | - $this->log->trace( "Post $post_id relations changed, invalidating cache..." ); |
|
342 | - |
|
343 | - $this->cache->delete( $post_id ); |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * When in Ajax, prints an http header with the information whether the |
|
348 | - * response is cached or not. |
|
349 | - * |
|
350 | - * @param int $post_id The {@link WP_Post} id. |
|
351 | - * @param bool $cache Whether the response fragment is cached. |
|
352 | - * |
|
353 | - * @since 3.16.0 |
|
354 | - */ |
|
355 | - private function add_http_header( $post_id, $cache ) { |
|
356 | - |
|
357 | - if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || headers_sent() ) { |
|
358 | - return; |
|
359 | - } |
|
360 | - |
|
361 | - header( "X-WordLift-JsonLd-Cache-$post_id: " . ( $cache ? 'HIT' : 'MISS' ) ); |
|
362 | - |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Call the `flush` operation on the {@link Ttl_Cache} if |
|
367 | - * the publisher has changed. |
|
368 | - * |
|
369 | - * @param int $post_id The changed {@link WP_Post}'s id. |
|
370 | - * |
|
371 | - * @since 3.16.0 |
|
372 | - */ |
|
373 | - private function flush_cache_if_publisher( $post_id ) { |
|
374 | - |
|
375 | - // Bail out if it's not the publisher. |
|
376 | - if ( Wordlift_Configuration_Service::get_instance()->get_publisher_id() !== $post_id ) { |
|
377 | - return; |
|
378 | - } |
|
379 | - |
|
380 | - // Flush the cache, since the publisher has changed. |
|
381 | - $this->cache->flush(); |
|
382 | - |
|
383 | - } |
|
24 | + /** |
|
25 | + * A {@link Wordlift_Post_Converter} instance. |
|
26 | + * |
|
27 | + * @since 3.16.0 |
|
28 | + * |
|
29 | + * @var \Wordlift_Post_Converter $converter A {@link Wordlift_Post_Converter} instance. |
|
30 | + */ |
|
31 | + private $converter; |
|
32 | + |
|
33 | + /** |
|
34 | + * A {@link Wordlift_Log_Service} instance. |
|
35 | + * |
|
36 | + * @since 3.16.0 |
|
37 | + * |
|
38 | + * @var Wordlift_Log_Service \$log A {@link Wordlift_Log_Service} instance. |
|
39 | + */ |
|
40 | + private $log; |
|
41 | + |
|
42 | + /** |
|
43 | + * A list of meta keys that do not cause the cache to update. |
|
44 | + * |
|
45 | + * @since 3.17.3 |
|
46 | + * @var array An array of ignored meta keys. |
|
47 | + */ |
|
48 | + private static $ignored_meta_keys = array( |
|
49 | + '_edit_lock', |
|
50 | + '_edit_last', |
|
51 | + '_wp_page_template', |
|
52 | + '_wp_attachment_is_custom_background', |
|
53 | + '_wp_attachment_backup_sizes', |
|
54 | + '_wp_attachment_is_custom_header', |
|
55 | + ); |
|
56 | + /** |
|
57 | + * @var Ttl_Cache |
|
58 | + */ |
|
59 | + private $cache; |
|
60 | + |
|
61 | + /** |
|
62 | + * Wordlift_Cached_Post_Converter constructor. |
|
63 | + * |
|
64 | + * @param \Wordlift_Post_Converter $converter The {@link Wordlift_Post_Converter} implementation. |
|
65 | + * @param Ttl_Cache $cache The {@link Ttl_Cache} cache instance. |
|
66 | + */ |
|
67 | + public function __construct( $converter, $cache ) { |
|
68 | + |
|
69 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
70 | + |
|
71 | + $this->cache = $cache; |
|
72 | + $this->converter = $converter; |
|
73 | + $this->init_hooks(); |
|
74 | + |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Hooks to catch post/post meta changes in order to invalidate the cache. |
|
79 | + * |
|
80 | + * @since 3.16.0 |
|
81 | + */ |
|
82 | + private function init_hooks() { |
|
83 | + |
|
84 | + // Hook on post save to flush relevant cache. |
|
85 | + add_action( 'save_post', array( $this, 'save_post' ) ); |
|
86 | + |
|
87 | + add_action( |
|
88 | + 'added_post_meta', |
|
89 | + array( |
|
90 | + $this, |
|
91 | + 'changed_post_meta', |
|
92 | + ), |
|
93 | + 10, |
|
94 | + 3 |
|
95 | + ); |
|
96 | + add_action( |
|
97 | + 'updated_post_meta', |
|
98 | + array( |
|
99 | + $this, |
|
100 | + 'changed_post_meta', |
|
101 | + ), |
|
102 | + 10, |
|
103 | + 3 |
|
104 | + ); |
|
105 | + add_action( |
|
106 | + 'deleted_post_meta', |
|
107 | + array( |
|
108 | + $this, |
|
109 | + 'changed_post_meta', |
|
110 | + ), |
|
111 | + 10, |
|
112 | + 3 |
|
113 | + ); |
|
114 | + |
|
115 | + // Flush cache when wordlift settings were updated. |
|
116 | + add_action( |
|
117 | + 'update_option_wl_general_settings', |
|
118 | + array( |
|
119 | + $this, |
|
120 | + 'update_option_wl_general_settings', |
|
121 | + ) |
|
122 | + ); |
|
123 | + |
|
124 | + // Flushes the cache when permalink structure is changed. |
|
125 | + add_action( |
|
126 | + 'update_option_permalink_structure', |
|
127 | + array( |
|
128 | + $this, |
|
129 | + 'permalinks_structure_changed', |
|
130 | + ) |
|
131 | + ); |
|
132 | + |
|
133 | + // Invalid cache on relationship change. |
|
134 | + add_action( 'wl_relation_added', array( $this, 'relation_changed' ) ); |
|
135 | + add_action( 'wl_relation_deleted', array( $this, 'relation_changed' ) ); |
|
136 | + |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Note that the `&$cache` parameter here is used only to report whether the response comes from the cache. It |
|
141 | + * used by `test-issue-626.php` and nowhere else in code. |
|
142 | + * |
|
143 | + * @inheritdoc |
|
144 | + */ |
|
145 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
146 | + public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null, &$cache = false ) { |
|
147 | + |
|
148 | + // Ensure post ID is `int`. Otherwise we may have issues with caching, since caching is strict about |
|
149 | + // key var types. |
|
150 | + $post_id = (int) $post_id; |
|
151 | + |
|
152 | + $this->log->trace( "Converting post $post_id..." ); |
|
153 | + |
|
154 | + // Try to get a cached result. |
|
155 | + $arr = $this->get_cache( $post_id ); |
|
156 | + |
|
157 | + // Return the cached contents if any. |
|
158 | + if ( false !== $arr ) { |
|
159 | + $contents = $arr['jsonld']; |
|
160 | + |
|
161 | + // Add the cached relations if any. |
|
162 | + if ( is_a( $arr['relations'], 'Wordlift\Relation\Relations' ) ) { |
|
163 | + $relations->add( ...$arr['relations']->toArray() ); |
|
164 | + } |
|
165 | + |
|
166 | + if ( is_array( $arr['references'] ) ) { |
|
167 | + $references = $arr['references']; |
|
168 | + } |
|
169 | + |
|
170 | + $this->log->debug( "Cached contents found for post $post_id." ); |
|
171 | + |
|
172 | + // Inform the caller that this is cached result. |
|
173 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
174 | + $cache = true; |
|
175 | + $this->add_http_header( $post_id, true ); |
|
176 | + |
|
177 | + // Return the contents. |
|
178 | + return $contents; |
|
179 | + } |
|
180 | + |
|
181 | + // Set cached to false. |
|
182 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
183 | + $cache = false; |
|
184 | + $this->add_http_header( $post_id, false ); |
|
185 | + |
|
186 | + // Convert the post. |
|
187 | + $jsonld = $this->converter->convert( $post_id, $references, $references_infos, $relations ); |
|
188 | + |
|
189 | + /** |
|
190 | + * @since 3.32.0 |
|
191 | + * We cant apply json_encode on the objects {@link \Wordlift\Jsonld\Reference}, so we decode |
|
192 | + * it here before saving it on cache. |
|
193 | + */ |
|
194 | + // Cache the results. |
|
195 | + $this->set_cache( $post_id, $references, $jsonld, $relations ); |
|
196 | + |
|
197 | + // Finally return the JSON-LD. |
|
198 | + return $jsonld; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Try to get the cached contents. |
|
203 | + * |
|
204 | + * @param int $post_id The {@link WP_Post} id. |
|
205 | + * @param array $references The referenced posts. |
|
206 | + * |
|
207 | + * @return mixed|bool The cached contents or false if the cached isn't found. |
|
208 | + * @since 3.16.0 |
|
209 | + */ |
|
210 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
211 | + private function get_cache( $post_id ) { |
|
212 | + |
|
213 | + // Ensure post ID is int, because cache is strict about var types. |
|
214 | + $post_id = (int) $post_id; |
|
215 | + |
|
216 | + $this->log->trace( "Getting cached contents for post $post_id..." ); |
|
217 | + |
|
218 | + // Get the cache. |
|
219 | + $modified_date_time = get_post_datetime( $post_id, 'modified', 'gmt' ); |
|
220 | + $contents = $this->cache->get( $post_id, $modified_date_time ? $modified_date_time->getTimestamp() : 0 ); |
|
221 | + |
|
222 | + // Bail out if we don't have cached contents or the cached contents are |
|
223 | + // invalid. |
|
224 | + if ( null === $contents || ! isset( $contents['jsonld'] ) || ! isset( $contents['references'] ) || ! isset( $contents['relations'] ) ) { |
|
225 | + $this->log->debug( "Cached contents for post $post_id not found." ); |
|
226 | + |
|
227 | + return false; |
|
228 | + } |
|
229 | + |
|
230 | + return $contents['jsonld'] |
|
231 | + ? array( |
|
232 | + 'jsonld' => $contents['jsonld'], |
|
233 | + 'relations' => Relations::from_json( $contents['relations'] ), |
|
234 | + 'references' => $contents['references'], |
|
235 | + ) |
|
236 | + : false; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Set the cache with the provided results. |
|
241 | + * |
|
242 | + * The function will prepare the provided results and will ask the {@link Ttl_Cache} to cache them. |
|
243 | + * |
|
244 | + * @param int $post_id The {@link WP_Post} id. |
|
245 | + * @param array $references An array of references. |
|
246 | + * @param array $jsonld A JSON-LD structure. |
|
247 | + * |
|
248 | + * @since 3.16.0 |
|
249 | + */ |
|
250 | + private function set_cache( $post_id, $references, $jsonld, $relations ) { |
|
251 | + |
|
252 | + $this->log->trace( "Caching result for post $post_id..." ); |
|
253 | + |
|
254 | + $this->cache->put( |
|
255 | + $post_id, |
|
256 | + array( |
|
257 | + // @@todo check the `references`. |
|
258 | + 'references' => $references, |
|
259 | + 'jsonld' => $jsonld, |
|
260 | + 'relations' => $relations, |
|
261 | + ) |
|
262 | + ); |
|
263 | + |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Hook to 'save_post', will invalidate the cache for that post. |
|
268 | + * |
|
269 | + * @param int $post_id The {@link WP_Post} id. |
|
270 | + * |
|
271 | + * @since 3.16.0 |
|
272 | + */ |
|
273 | + public function save_post( $post_id ) { |
|
274 | + |
|
275 | + $this->log->trace( "Post $post_id saved, invalidating cache..." ); |
|
276 | + |
|
277 | + $this->cache->delete( $post_id ); |
|
278 | + |
|
279 | + $this->flush_cache_if_publisher( $post_id ); |
|
280 | + |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Hook to meta changed for a {@link WP_Post}, will cause the cause to |
|
285 | + * invalidate. |
|
286 | + * |
|
287 | + * @param int $id The {@link WP_Post} meta id. |
|
288 | + * @param int $post_id The {@link WP_Post} id. |
|
289 | + * @param string $meta_key The meta key. |
|
290 | + * |
|
291 | + * @since 3.16.0 |
|
292 | + */ |
|
293 | + public function changed_post_meta( $id, $post_id, $meta_key ) { |
|
294 | + |
|
295 | + if ( in_array( $meta_key, self::$ignored_meta_keys, true ) ) { |
|
296 | + $this->log->trace( "Post $post_id meta $meta_key ignored." ); |
|
297 | + |
|
298 | + return; |
|
299 | + } |
|
300 | + |
|
301 | + $this->log->trace( "Post $post_id meta $meta_key changed, invalidating cache..." ); |
|
302 | + |
|
303 | + // Delete the single cache file. |
|
304 | + $this->cache->delete( $post_id ); |
|
305 | + |
|
306 | + // Flush the cache if it's the publisher. |
|
307 | + $this->flush_cache_if_publisher( $post_id ); |
|
308 | + |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Hook to WordLift's options changes, will flush the cache. |
|
313 | + * |
|
314 | + * @since 3.16.0 |
|
315 | + */ |
|
316 | + public function update_option_wl_general_settings() { |
|
317 | + $this->log->trace( 'WordLift options changed, flushing cache...' ); |
|
318 | + |
|
319 | + $this->cache->flush(); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Hook when permalinks are changed, will flush the cache. |
|
324 | + * |
|
325 | + * @since 3.17.0 |
|
326 | + */ |
|
327 | + public function permalinks_structure_changed() { |
|
328 | + $this->log->trace( 'Permalinks structure changed, flushing cache...' ); |
|
329 | + |
|
330 | + $this->cache->flush(); |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Hook to WordLift's post/entity relation changes, will invalidate the cache. |
|
335 | + * |
|
336 | + * @param int $post_id The {@link WP_Post} id. |
|
337 | + * |
|
338 | + * @since 3.16.0 |
|
339 | + */ |
|
340 | + public function relation_changed( $post_id ) { |
|
341 | + $this->log->trace( "Post $post_id relations changed, invalidating cache..." ); |
|
342 | + |
|
343 | + $this->cache->delete( $post_id ); |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * When in Ajax, prints an http header with the information whether the |
|
348 | + * response is cached or not. |
|
349 | + * |
|
350 | + * @param int $post_id The {@link WP_Post} id. |
|
351 | + * @param bool $cache Whether the response fragment is cached. |
|
352 | + * |
|
353 | + * @since 3.16.0 |
|
354 | + */ |
|
355 | + private function add_http_header( $post_id, $cache ) { |
|
356 | + |
|
357 | + if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || headers_sent() ) { |
|
358 | + return; |
|
359 | + } |
|
360 | + |
|
361 | + header( "X-WordLift-JsonLd-Cache-$post_id: " . ( $cache ? 'HIT' : 'MISS' ) ); |
|
362 | + |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Call the `flush` operation on the {@link Ttl_Cache} if |
|
367 | + * the publisher has changed. |
|
368 | + * |
|
369 | + * @param int $post_id The changed {@link WP_Post}'s id. |
|
370 | + * |
|
371 | + * @since 3.16.0 |
|
372 | + */ |
|
373 | + private function flush_cache_if_publisher( $post_id ) { |
|
374 | + |
|
375 | + // Bail out if it's not the publisher. |
|
376 | + if ( Wordlift_Configuration_Service::get_instance()->get_publisher_id() !== $post_id ) { |
|
377 | + return; |
|
378 | + } |
|
379 | + |
|
380 | + // Flush the cache, since the publisher has changed. |
|
381 | + $this->cache->flush(); |
|
382 | + |
|
383 | + } |
|
384 | 384 | |
385 | 385 | } |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | * @param \Wordlift_Post_Converter $converter The {@link Wordlift_Post_Converter} implementation. |
65 | 65 | * @param Ttl_Cache $cache The {@link Ttl_Cache} cache instance. |
66 | 66 | */ |
67 | - public function __construct( $converter, $cache ) { |
|
67 | + public function __construct($converter, $cache) { |
|
68 | 68 | |
69 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
69 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
70 | 70 | |
71 | 71 | $this->cache = $cache; |
72 | 72 | $this->converter = $converter; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | private function init_hooks() { |
83 | 83 | |
84 | 84 | // Hook on post save to flush relevant cache. |
85 | - add_action( 'save_post', array( $this, 'save_post' ) ); |
|
85 | + add_action('save_post', array($this, 'save_post')); |
|
86 | 86 | |
87 | 87 | add_action( |
88 | 88 | 'added_post_meta', |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | ); |
132 | 132 | |
133 | 133 | // Invalid cache on relationship change. |
134 | - add_action( 'wl_relation_added', array( $this, 'relation_changed' ) ); |
|
135 | - add_action( 'wl_relation_deleted', array( $this, 'relation_changed' ) ); |
|
134 | + add_action('wl_relation_added', array($this, 'relation_changed')); |
|
135 | + add_action('wl_relation_deleted', array($this, 'relation_changed')); |
|
136 | 136 | |
137 | 137 | } |
138 | 138 | |
@@ -143,36 +143,36 @@ discard block |
||
143 | 143 | * @inheritdoc |
144 | 144 | */ |
145 | 145 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
146 | - public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null, &$cache = false ) { |
|
146 | + public function convert($post_id, &$references = array(), &$references_infos = array(), $relations = null, &$cache = false) { |
|
147 | 147 | |
148 | 148 | // Ensure post ID is `int`. Otherwise we may have issues with caching, since caching is strict about |
149 | 149 | // key var types. |
150 | 150 | $post_id = (int) $post_id; |
151 | 151 | |
152 | - $this->log->trace( "Converting post $post_id..." ); |
|
152 | + $this->log->trace("Converting post $post_id..."); |
|
153 | 153 | |
154 | 154 | // Try to get a cached result. |
155 | - $arr = $this->get_cache( $post_id ); |
|
155 | + $arr = $this->get_cache($post_id); |
|
156 | 156 | |
157 | 157 | // Return the cached contents if any. |
158 | - if ( false !== $arr ) { |
|
158 | + if (false !== $arr) { |
|
159 | 159 | $contents = $arr['jsonld']; |
160 | 160 | |
161 | 161 | // Add the cached relations if any. |
162 | - if ( is_a( $arr['relations'], 'Wordlift\Relation\Relations' ) ) { |
|
163 | - $relations->add( ...$arr['relations']->toArray() ); |
|
162 | + if (is_a($arr['relations'], 'Wordlift\Relation\Relations')) { |
|
163 | + $relations->add(...$arr['relations']->toArray()); |
|
164 | 164 | } |
165 | 165 | |
166 | - if ( is_array( $arr['references'] ) ) { |
|
166 | + if (is_array($arr['references'])) { |
|
167 | 167 | $references = $arr['references']; |
168 | 168 | } |
169 | 169 | |
170 | - $this->log->debug( "Cached contents found for post $post_id." ); |
|
170 | + $this->log->debug("Cached contents found for post $post_id."); |
|
171 | 171 | |
172 | 172 | // Inform the caller that this is cached result. |
173 | 173 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
174 | 174 | $cache = true; |
175 | - $this->add_http_header( $post_id, true ); |
|
175 | + $this->add_http_header($post_id, true); |
|
176 | 176 | |
177 | 177 | // Return the contents. |
178 | 178 | return $contents; |
@@ -181,10 +181,10 @@ discard block |
||
181 | 181 | // Set cached to false. |
182 | 182 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
183 | 183 | $cache = false; |
184 | - $this->add_http_header( $post_id, false ); |
|
184 | + $this->add_http_header($post_id, false); |
|
185 | 185 | |
186 | 186 | // Convert the post. |
187 | - $jsonld = $this->converter->convert( $post_id, $references, $references_infos, $relations ); |
|
187 | + $jsonld = $this->converter->convert($post_id, $references, $references_infos, $relations); |
|
188 | 188 | |
189 | 189 | /** |
190 | 190 | * @since 3.32.0 |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * it here before saving it on cache. |
193 | 193 | */ |
194 | 194 | // Cache the results. |
195 | - $this->set_cache( $post_id, $references, $jsonld, $relations ); |
|
195 | + $this->set_cache($post_id, $references, $jsonld, $relations); |
|
196 | 196 | |
197 | 197 | // Finally return the JSON-LD. |
198 | 198 | return $jsonld; |
@@ -208,21 +208,21 @@ discard block |
||
208 | 208 | * @since 3.16.0 |
209 | 209 | */ |
210 | 210 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
211 | - private function get_cache( $post_id ) { |
|
211 | + private function get_cache($post_id) { |
|
212 | 212 | |
213 | 213 | // Ensure post ID is int, because cache is strict about var types. |
214 | 214 | $post_id = (int) $post_id; |
215 | 215 | |
216 | - $this->log->trace( "Getting cached contents for post $post_id..." ); |
|
216 | + $this->log->trace("Getting cached contents for post $post_id..."); |
|
217 | 217 | |
218 | 218 | // Get the cache. |
219 | - $modified_date_time = get_post_datetime( $post_id, 'modified', 'gmt' ); |
|
220 | - $contents = $this->cache->get( $post_id, $modified_date_time ? $modified_date_time->getTimestamp() : 0 ); |
|
219 | + $modified_date_time = get_post_datetime($post_id, 'modified', 'gmt'); |
|
220 | + $contents = $this->cache->get($post_id, $modified_date_time ? $modified_date_time->getTimestamp() : 0); |
|
221 | 221 | |
222 | 222 | // Bail out if we don't have cached contents or the cached contents are |
223 | 223 | // invalid. |
224 | - if ( null === $contents || ! isset( $contents['jsonld'] ) || ! isset( $contents['references'] ) || ! isset( $contents['relations'] ) ) { |
|
225 | - $this->log->debug( "Cached contents for post $post_id not found." ); |
|
224 | + if (null === $contents || ! isset($contents['jsonld']) || ! isset($contents['references']) || ! isset($contents['relations'])) { |
|
225 | + $this->log->debug("Cached contents for post $post_id not found."); |
|
226 | 226 | |
227 | 227 | return false; |
228 | 228 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | return $contents['jsonld'] |
231 | 231 | ? array( |
232 | 232 | 'jsonld' => $contents['jsonld'], |
233 | - 'relations' => Relations::from_json( $contents['relations'] ), |
|
233 | + 'relations' => Relations::from_json($contents['relations']), |
|
234 | 234 | 'references' => $contents['references'], |
235 | 235 | ) |
236 | 236 | : false; |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @since 3.16.0 |
249 | 249 | */ |
250 | - private function set_cache( $post_id, $references, $jsonld, $relations ) { |
|
250 | + private function set_cache($post_id, $references, $jsonld, $relations) { |
|
251 | 251 | |
252 | - $this->log->trace( "Caching result for post $post_id..." ); |
|
252 | + $this->log->trace("Caching result for post $post_id..."); |
|
253 | 253 | |
254 | 254 | $this->cache->put( |
255 | 255 | $post_id, |
@@ -270,13 +270,13 @@ discard block |
||
270 | 270 | * |
271 | 271 | * @since 3.16.0 |
272 | 272 | */ |
273 | - public function save_post( $post_id ) { |
|
273 | + public function save_post($post_id) { |
|
274 | 274 | |
275 | - $this->log->trace( "Post $post_id saved, invalidating cache..." ); |
|
275 | + $this->log->trace("Post $post_id saved, invalidating cache..."); |
|
276 | 276 | |
277 | - $this->cache->delete( $post_id ); |
|
277 | + $this->cache->delete($post_id); |
|
278 | 278 | |
279 | - $this->flush_cache_if_publisher( $post_id ); |
|
279 | + $this->flush_cache_if_publisher($post_id); |
|
280 | 280 | |
281 | 281 | } |
282 | 282 | |
@@ -290,21 +290,21 @@ discard block |
||
290 | 290 | * |
291 | 291 | * @since 3.16.0 |
292 | 292 | */ |
293 | - public function changed_post_meta( $id, $post_id, $meta_key ) { |
|
293 | + public function changed_post_meta($id, $post_id, $meta_key) { |
|
294 | 294 | |
295 | - if ( in_array( $meta_key, self::$ignored_meta_keys, true ) ) { |
|
296 | - $this->log->trace( "Post $post_id meta $meta_key ignored." ); |
|
295 | + if (in_array($meta_key, self::$ignored_meta_keys, true)) { |
|
296 | + $this->log->trace("Post $post_id meta $meta_key ignored."); |
|
297 | 297 | |
298 | 298 | return; |
299 | 299 | } |
300 | 300 | |
301 | - $this->log->trace( "Post $post_id meta $meta_key changed, invalidating cache..." ); |
|
301 | + $this->log->trace("Post $post_id meta $meta_key changed, invalidating cache..."); |
|
302 | 302 | |
303 | 303 | // Delete the single cache file. |
304 | - $this->cache->delete( $post_id ); |
|
304 | + $this->cache->delete($post_id); |
|
305 | 305 | |
306 | 306 | // Flush the cache if it's the publisher. |
307 | - $this->flush_cache_if_publisher( $post_id ); |
|
307 | + $this->flush_cache_if_publisher($post_id); |
|
308 | 308 | |
309 | 309 | } |
310 | 310 | |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | * @since 3.16.0 |
315 | 315 | */ |
316 | 316 | public function update_option_wl_general_settings() { |
317 | - $this->log->trace( 'WordLift options changed, flushing cache...' ); |
|
317 | + $this->log->trace('WordLift options changed, flushing cache...'); |
|
318 | 318 | |
319 | 319 | $this->cache->flush(); |
320 | 320 | } |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @since 3.17.0 |
326 | 326 | */ |
327 | 327 | public function permalinks_structure_changed() { |
328 | - $this->log->trace( 'Permalinks structure changed, flushing cache...' ); |
|
328 | + $this->log->trace('Permalinks structure changed, flushing cache...'); |
|
329 | 329 | |
330 | 330 | $this->cache->flush(); |
331 | 331 | } |
@@ -337,10 +337,10 @@ discard block |
||
337 | 337 | * |
338 | 338 | * @since 3.16.0 |
339 | 339 | */ |
340 | - public function relation_changed( $post_id ) { |
|
341 | - $this->log->trace( "Post $post_id relations changed, invalidating cache..." ); |
|
340 | + public function relation_changed($post_id) { |
|
341 | + $this->log->trace("Post $post_id relations changed, invalidating cache..."); |
|
342 | 342 | |
343 | - $this->cache->delete( $post_id ); |
|
343 | + $this->cache->delete($post_id); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
@@ -352,13 +352,13 @@ discard block |
||
352 | 352 | * |
353 | 353 | * @since 3.16.0 |
354 | 354 | */ |
355 | - private function add_http_header( $post_id, $cache ) { |
|
355 | + private function add_http_header($post_id, $cache) { |
|
356 | 356 | |
357 | - if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || headers_sent() ) { |
|
357 | + if ( ! defined('DOING_AJAX') || ! DOING_AJAX || headers_sent()) { |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | - header( "X-WordLift-JsonLd-Cache-$post_id: " . ( $cache ? 'HIT' : 'MISS' ) ); |
|
361 | + header("X-WordLift-JsonLd-Cache-$post_id: ".($cache ? 'HIT' : 'MISS')); |
|
362 | 362 | |
363 | 363 | } |
364 | 364 | |
@@ -370,10 +370,10 @@ discard block |
||
370 | 370 | * |
371 | 371 | * @since 3.16.0 |
372 | 372 | */ |
373 | - private function flush_cache_if_publisher( $post_id ) { |
|
373 | + private function flush_cache_if_publisher($post_id) { |
|
374 | 374 | |
375 | 375 | // Bail out if it's not the publisher. |
376 | - if ( Wordlift_Configuration_Service::get_instance()->get_publisher_id() !== $post_id ) { |
|
376 | + if (Wordlift_Configuration_Service::get_instance()->get_publisher_id() !== $post_id) { |
|
377 | 377 | return; |
378 | 378 | } |
379 | 379 |
@@ -19,229 +19,229 @@ |
||
19 | 19 | */ |
20 | 20 | class Wordlift_Post_Adapter { |
21 | 21 | |
22 | - /** |
|
23 | - * The post id to which the adopter relates. |
|
24 | - * |
|
25 | - * @since 3.14.0 |
|
26 | - * |
|
27 | - * @var integer $post_id . |
|
28 | - */ |
|
29 | - private $post_id; |
|
30 | - |
|
31 | - const TYPE_ENTITY_LINK = 0; |
|
32 | - const TYPE_TERM_LINK = 1; |
|
33 | - |
|
34 | - /** |
|
35 | - * Create the {@link Wordlift_Post_Adatpter} instance. |
|
36 | - * |
|
37 | - * @param integer $post_id the post ID of the post the adopter relates to. |
|
38 | - * |
|
39 | - * @since 3.14.0 |
|
40 | - */ |
|
41 | - public function __construct( $post_id ) { |
|
42 | - |
|
43 | - $this->post_id = $post_id; |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Get the word count of the post content. |
|
49 | - * |
|
50 | - * The count is calculated over the post content after stripping shortcodes and html tags. |
|
51 | - * |
|
52 | - * @return integer the number of words in the content after stripping shortcodes and html tags.. |
|
53 | - * @since 3.14.0 |
|
54 | - */ |
|
55 | - public function word_count() { |
|
56 | - |
|
57 | - $post = get_post( $this->post_id ); |
|
58 | - |
|
59 | - /* |
|
22 | + /** |
|
23 | + * The post id to which the adopter relates. |
|
24 | + * |
|
25 | + * @since 3.14.0 |
|
26 | + * |
|
27 | + * @var integer $post_id . |
|
28 | + */ |
|
29 | + private $post_id; |
|
30 | + |
|
31 | + const TYPE_ENTITY_LINK = 0; |
|
32 | + const TYPE_TERM_LINK = 1; |
|
33 | + |
|
34 | + /** |
|
35 | + * Create the {@link Wordlift_Post_Adatpter} instance. |
|
36 | + * |
|
37 | + * @param integer $post_id the post ID of the post the adopter relates to. |
|
38 | + * |
|
39 | + * @since 3.14.0 |
|
40 | + */ |
|
41 | + public function __construct( $post_id ) { |
|
42 | + |
|
43 | + $this->post_id = $post_id; |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Get the word count of the post content. |
|
49 | + * |
|
50 | + * The count is calculated over the post content after stripping shortcodes and html tags. |
|
51 | + * |
|
52 | + * @return integer the number of words in the content after stripping shortcodes and html tags.. |
|
53 | + * @since 3.14.0 |
|
54 | + */ |
|
55 | + public function word_count() { |
|
56 | + |
|
57 | + $post = get_post( $this->post_id ); |
|
58 | + |
|
59 | + /* |
|
60 | 60 | * Apply the `wl_post_content` filter, in case 3rd parties want to change the post content, e.g. |
61 | 61 | * because the content is written elsewhere. |
62 | 62 | * |
63 | 63 | * @since 3.20.0 |
64 | 64 | */ |
65 | - $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
66 | - |
|
67 | - return self::str_word_count_utf8( wp_strip_all_tags( strip_shortcodes( $post_content ) ) ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Count words in the string, taking into account UTF-8 characters. |
|
72 | - * |
|
73 | - * @see https://github.com/insideout10/wordlift-plugin/issues/884 |
|
74 | - * |
|
75 | - * @since 3.20.0 |
|
76 | - * |
|
77 | - * @param string $str The target string. |
|
78 | - * |
|
79 | - * @return int The number of words. |
|
80 | - */ |
|
81 | - private static function str_word_count_utf8( $str ) { |
|
82 | - |
|
83 | - $words = preg_split( '~[^\p{L}\p{N}\']+~u', $str ); |
|
84 | - |
|
85 | - return $words ? count( $words ) : 0; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Get the {@link WP_Post} permalink allowing 3rd parties to alter the URL. |
|
90 | - * |
|
91 | - * @param int $post_id Post ID. |
|
92 | - * |
|
93 | - * @return string The post permalink. |
|
94 | - * @since 3.20.0 |
|
95 | - */ |
|
96 | - public static function get_production_permalink( $post_id, $object_type = Object_Type_Enum::POST ) { |
|
97 | - |
|
98 | - $object_link_service = Object_Link_Provider::get_instance(); |
|
99 | - $permalink = $object_link_service->get_permalink( $post_id, $object_type ); |
|
100 | - |
|
101 | - /** |
|
102 | - * WordPress 4.4 doesn't support meta queries for terms, therefore we only support post permalinks here. |
|
103 | - * |
|
104 | - * Later on for WordPress 4.5+ we look for terms bound to the entity and we use the term link instead of the |
|
105 | - * post permalink if we find them. |
|
106 | - */ |
|
107 | - global $wp_version; |
|
108 | - if ( version_compare( $wp_version, '4.5', '<' ) ) { |
|
109 | - return apply_filters( 'wl_production_permalink', $permalink, $post_id, self::TYPE_ENTITY_LINK, null ); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * The `wl_production_permalink` filter allows to change the permalink, this is useful in contexts |
|
114 | - * when the production environment is copied over from a staging environment with staging |
|
115 | - * URLs. |
|
116 | - * |
|
117 | - * @param string $permalink_url The default permalink. |
|
118 | - * @param int $post_id The post id. |
|
119 | - * |
|
120 | - * @since 3.23.0 we check whether the entity is bound to a term and, in that case, we link to the term. |
|
121 | - * @since 3.20.0 |
|
122 | - * |
|
123 | - * @see https://github.com/insideout10/wordlift-plugin/issues/850 |
|
124 | - */ |
|
125 | - |
|
126 | - $uris = $object_link_service->get_same_as_uris( |
|
127 | - $post_id, |
|
128 | - $object_type |
|
129 | - ); |
|
130 | - |
|
131 | - // Only try to link a term if `WL_ENABLE_TERM_LINKING` is enabled. |
|
132 | - $terms = array(); |
|
133 | - if ( defined( 'WL_ENABLE_TERM_LINKING' ) && WL_ENABLE_TERM_LINKING ) { |
|
134 | - // Try to find one term matching the entity. |
|
135 | - $terms = get_terms( |
|
136 | - array( |
|
137 | - 'number' => 1, |
|
138 | - 'hide_empty' => false, |
|
139 | - 'update_term_meta_cache' => false, |
|
140 | - 'meta_key' => '_wl_entity_id', |
|
141 | - 'meta_value' => $uris, |
|
142 | - 'meta_compare' => 'IN', |
|
143 | - ) |
|
144 | - ); |
|
145 | - } |
|
146 | - |
|
147 | - $type = self::TYPE_ENTITY_LINK; |
|
148 | - $term = null; |
|
149 | - // If found use the term link, otherwise the permalink. |
|
150 | - if ( 1 === count( $terms ) ) { |
|
151 | - $term = current( $terms ); |
|
152 | - $permalink = get_term_link( $term ); |
|
153 | - $type = self::TYPE_TERM_LINK; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Apply the `wl_production_permalink` filter. |
|
158 | - * |
|
159 | - * @param string $permalink The permalink. |
|
160 | - * @param int $post_id The post id. |
|
161 | - * @param int $type The permalink type: 0 = entity permalink, 1 = term link. |
|
162 | - * @param WP_Term $term The term if type is term link, otherwise null. |
|
163 | - * |
|
164 | - * @since 3.23.0 add the permalink type and term parameters. |
|
165 | - */ |
|
166 | - return apply_filters( 'wl_production_permalink', $permalink, $post_id, $type, $term ); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Get comma separated tags to be used as keywords |
|
171 | - * |
|
172 | - * @return string|void Comma separated tags |
|
173 | - * |
|
174 | - * @since 3.27.2 |
|
175 | - */ |
|
176 | - public function keywords() { |
|
177 | - $tags = get_the_tags( $this->post_id ); |
|
178 | - |
|
179 | - if ( empty( $tags ) ) { |
|
180 | - return; |
|
181 | - } |
|
182 | - |
|
183 | - return implode( |
|
184 | - ',', |
|
185 | - array_map( |
|
186 | - function ( $tag ) { |
|
187 | - return $tag->name; |
|
188 | - }, |
|
189 | - $tags |
|
190 | - ) |
|
191 | - ); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Get comma separated categories to be used as article section |
|
196 | - * |
|
197 | - * @return string[] Comma separated categories |
|
198 | - * |
|
199 | - * @since 3.27.2 |
|
200 | - */ |
|
201 | - public function article_section() { |
|
202 | - $categories = get_the_category( $this->post_id ); |
|
203 | - |
|
204 | - return wp_list_pluck( $categories, 'cat_name' ); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Get comment count |
|
209 | - * |
|
210 | - * @return string|void Comment count |
|
211 | - * |
|
212 | - * @since 3.27.2 |
|
213 | - */ |
|
214 | - public function comment_count() { |
|
215 | - return get_comments_number( $this->post_id ); |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Get Language |
|
220 | - * Try WPML, Polylang for post specific languages, else fallback on get_locale() |
|
221 | - * |
|
222 | - * @return string|void Language code (locale) |
|
223 | - * |
|
224 | - * @since 3.27.2 |
|
225 | - */ |
|
226 | - public function locale() { |
|
227 | - $language = 'en-US'; |
|
228 | - |
|
229 | - if ( function_exists( 'wpml_get_language_information' ) ) { |
|
230 | - // WPML handling |
|
231 | - // WPML: Updated function signature. |
|
232 | - // function wpml_get_language_information( $empty_value = null, $post_id = null ) |
|
233 | - $post_language = wpml_get_language_information( null, $this->post_id ); |
|
234 | - if ( ! $post_language instanceof WP_Error ) { |
|
235 | - $language = $post_language['locale']; |
|
236 | - } |
|
237 | - } elseif ( function_exists( 'pll_get_post_language' ) ) { |
|
238 | - // Polylang handling |
|
239 | - $language = pll_get_post_language( $this->post_id, 'locale' ); |
|
240 | - } else { |
|
241 | - $language = get_locale(); |
|
242 | - } |
|
243 | - |
|
244 | - return str_replace( '_', '-', $language ); |
|
245 | - } |
|
65 | + $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
66 | + |
|
67 | + return self::str_word_count_utf8( wp_strip_all_tags( strip_shortcodes( $post_content ) ) ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Count words in the string, taking into account UTF-8 characters. |
|
72 | + * |
|
73 | + * @see https://github.com/insideout10/wordlift-plugin/issues/884 |
|
74 | + * |
|
75 | + * @since 3.20.0 |
|
76 | + * |
|
77 | + * @param string $str The target string. |
|
78 | + * |
|
79 | + * @return int The number of words. |
|
80 | + */ |
|
81 | + private static function str_word_count_utf8( $str ) { |
|
82 | + |
|
83 | + $words = preg_split( '~[^\p{L}\p{N}\']+~u', $str ); |
|
84 | + |
|
85 | + return $words ? count( $words ) : 0; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Get the {@link WP_Post} permalink allowing 3rd parties to alter the URL. |
|
90 | + * |
|
91 | + * @param int $post_id Post ID. |
|
92 | + * |
|
93 | + * @return string The post permalink. |
|
94 | + * @since 3.20.0 |
|
95 | + */ |
|
96 | + public static function get_production_permalink( $post_id, $object_type = Object_Type_Enum::POST ) { |
|
97 | + |
|
98 | + $object_link_service = Object_Link_Provider::get_instance(); |
|
99 | + $permalink = $object_link_service->get_permalink( $post_id, $object_type ); |
|
100 | + |
|
101 | + /** |
|
102 | + * WordPress 4.4 doesn't support meta queries for terms, therefore we only support post permalinks here. |
|
103 | + * |
|
104 | + * Later on for WordPress 4.5+ we look for terms bound to the entity and we use the term link instead of the |
|
105 | + * post permalink if we find them. |
|
106 | + */ |
|
107 | + global $wp_version; |
|
108 | + if ( version_compare( $wp_version, '4.5', '<' ) ) { |
|
109 | + return apply_filters( 'wl_production_permalink', $permalink, $post_id, self::TYPE_ENTITY_LINK, null ); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * The `wl_production_permalink` filter allows to change the permalink, this is useful in contexts |
|
114 | + * when the production environment is copied over from a staging environment with staging |
|
115 | + * URLs. |
|
116 | + * |
|
117 | + * @param string $permalink_url The default permalink. |
|
118 | + * @param int $post_id The post id. |
|
119 | + * |
|
120 | + * @since 3.23.0 we check whether the entity is bound to a term and, in that case, we link to the term. |
|
121 | + * @since 3.20.0 |
|
122 | + * |
|
123 | + * @see https://github.com/insideout10/wordlift-plugin/issues/850 |
|
124 | + */ |
|
125 | + |
|
126 | + $uris = $object_link_service->get_same_as_uris( |
|
127 | + $post_id, |
|
128 | + $object_type |
|
129 | + ); |
|
130 | + |
|
131 | + // Only try to link a term if `WL_ENABLE_TERM_LINKING` is enabled. |
|
132 | + $terms = array(); |
|
133 | + if ( defined( 'WL_ENABLE_TERM_LINKING' ) && WL_ENABLE_TERM_LINKING ) { |
|
134 | + // Try to find one term matching the entity. |
|
135 | + $terms = get_terms( |
|
136 | + array( |
|
137 | + 'number' => 1, |
|
138 | + 'hide_empty' => false, |
|
139 | + 'update_term_meta_cache' => false, |
|
140 | + 'meta_key' => '_wl_entity_id', |
|
141 | + 'meta_value' => $uris, |
|
142 | + 'meta_compare' => 'IN', |
|
143 | + ) |
|
144 | + ); |
|
145 | + } |
|
146 | + |
|
147 | + $type = self::TYPE_ENTITY_LINK; |
|
148 | + $term = null; |
|
149 | + // If found use the term link, otherwise the permalink. |
|
150 | + if ( 1 === count( $terms ) ) { |
|
151 | + $term = current( $terms ); |
|
152 | + $permalink = get_term_link( $term ); |
|
153 | + $type = self::TYPE_TERM_LINK; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Apply the `wl_production_permalink` filter. |
|
158 | + * |
|
159 | + * @param string $permalink The permalink. |
|
160 | + * @param int $post_id The post id. |
|
161 | + * @param int $type The permalink type: 0 = entity permalink, 1 = term link. |
|
162 | + * @param WP_Term $term The term if type is term link, otherwise null. |
|
163 | + * |
|
164 | + * @since 3.23.0 add the permalink type and term parameters. |
|
165 | + */ |
|
166 | + return apply_filters( 'wl_production_permalink', $permalink, $post_id, $type, $term ); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Get comma separated tags to be used as keywords |
|
171 | + * |
|
172 | + * @return string|void Comma separated tags |
|
173 | + * |
|
174 | + * @since 3.27.2 |
|
175 | + */ |
|
176 | + public function keywords() { |
|
177 | + $tags = get_the_tags( $this->post_id ); |
|
178 | + |
|
179 | + if ( empty( $tags ) ) { |
|
180 | + return; |
|
181 | + } |
|
182 | + |
|
183 | + return implode( |
|
184 | + ',', |
|
185 | + array_map( |
|
186 | + function ( $tag ) { |
|
187 | + return $tag->name; |
|
188 | + }, |
|
189 | + $tags |
|
190 | + ) |
|
191 | + ); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Get comma separated categories to be used as article section |
|
196 | + * |
|
197 | + * @return string[] Comma separated categories |
|
198 | + * |
|
199 | + * @since 3.27.2 |
|
200 | + */ |
|
201 | + public function article_section() { |
|
202 | + $categories = get_the_category( $this->post_id ); |
|
203 | + |
|
204 | + return wp_list_pluck( $categories, 'cat_name' ); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Get comment count |
|
209 | + * |
|
210 | + * @return string|void Comment count |
|
211 | + * |
|
212 | + * @since 3.27.2 |
|
213 | + */ |
|
214 | + public function comment_count() { |
|
215 | + return get_comments_number( $this->post_id ); |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Get Language |
|
220 | + * Try WPML, Polylang for post specific languages, else fallback on get_locale() |
|
221 | + * |
|
222 | + * @return string|void Language code (locale) |
|
223 | + * |
|
224 | + * @since 3.27.2 |
|
225 | + */ |
|
226 | + public function locale() { |
|
227 | + $language = 'en-US'; |
|
228 | + |
|
229 | + if ( function_exists( 'wpml_get_language_information' ) ) { |
|
230 | + // WPML handling |
|
231 | + // WPML: Updated function signature. |
|
232 | + // function wpml_get_language_information( $empty_value = null, $post_id = null ) |
|
233 | + $post_language = wpml_get_language_information( null, $this->post_id ); |
|
234 | + if ( ! $post_language instanceof WP_Error ) { |
|
235 | + $language = $post_language['locale']; |
|
236 | + } |
|
237 | + } elseif ( function_exists( 'pll_get_post_language' ) ) { |
|
238 | + // Polylang handling |
|
239 | + $language = pll_get_post_language( $this->post_id, 'locale' ); |
|
240 | + } else { |
|
241 | + $language = get_locale(); |
|
242 | + } |
|
243 | + |
|
244 | + return str_replace( '_', '-', $language ); |
|
245 | + } |
|
246 | 246 | |
247 | 247 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @since 3.14.0 |
40 | 40 | */ |
41 | - public function __construct( $post_id ) { |
|
41 | + public function __construct($post_id) { |
|
42 | 42 | |
43 | 43 | $this->post_id = $post_id; |
44 | 44 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function word_count() { |
56 | 56 | |
57 | - $post = get_post( $this->post_id ); |
|
57 | + $post = get_post($this->post_id); |
|
58 | 58 | |
59 | 59 | /* |
60 | 60 | * Apply the `wl_post_content` filter, in case 3rd parties want to change the post content, e.g. |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @since 3.20.0 |
64 | 64 | */ |
65 | - $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
65 | + $post_content = apply_filters('wl_post_content', $post->post_content, $post); |
|
66 | 66 | |
67 | - return self::str_word_count_utf8( wp_strip_all_tags( strip_shortcodes( $post_content ) ) ); |
|
67 | + return self::str_word_count_utf8(wp_strip_all_tags(strip_shortcodes($post_content))); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @return int The number of words. |
80 | 80 | */ |
81 | - private static function str_word_count_utf8( $str ) { |
|
81 | + private static function str_word_count_utf8($str) { |
|
82 | 82 | |
83 | - $words = preg_split( '~[^\p{L}\p{N}\']+~u', $str ); |
|
83 | + $words = preg_split('~[^\p{L}\p{N}\']+~u', $str); |
|
84 | 84 | |
85 | - return $words ? count( $words ) : 0; |
|
85 | + return $words ? count($words) : 0; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | * @return string The post permalink. |
94 | 94 | * @since 3.20.0 |
95 | 95 | */ |
96 | - public static function get_production_permalink( $post_id, $object_type = Object_Type_Enum::POST ) { |
|
96 | + public static function get_production_permalink($post_id, $object_type = Object_Type_Enum::POST) { |
|
97 | 97 | |
98 | 98 | $object_link_service = Object_Link_Provider::get_instance(); |
99 | - $permalink = $object_link_service->get_permalink( $post_id, $object_type ); |
|
99 | + $permalink = $object_link_service->get_permalink($post_id, $object_type); |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * WordPress 4.4 doesn't support meta queries for terms, therefore we only support post permalinks here. |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * post permalink if we find them. |
106 | 106 | */ |
107 | 107 | global $wp_version; |
108 | - if ( version_compare( $wp_version, '4.5', '<' ) ) { |
|
109 | - return apply_filters( 'wl_production_permalink', $permalink, $post_id, self::TYPE_ENTITY_LINK, null ); |
|
108 | + if (version_compare($wp_version, '4.5', '<')) { |
|
109 | + return apply_filters('wl_production_permalink', $permalink, $post_id, self::TYPE_ENTITY_LINK, null); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | // Only try to link a term if `WL_ENABLE_TERM_LINKING` is enabled. |
132 | 132 | $terms = array(); |
133 | - if ( defined( 'WL_ENABLE_TERM_LINKING' ) && WL_ENABLE_TERM_LINKING ) { |
|
133 | + if (defined('WL_ENABLE_TERM_LINKING') && WL_ENABLE_TERM_LINKING) { |
|
134 | 134 | // Try to find one term matching the entity. |
135 | 135 | $terms = get_terms( |
136 | 136 | array( |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | $type = self::TYPE_ENTITY_LINK; |
148 | 148 | $term = null; |
149 | 149 | // If found use the term link, otherwise the permalink. |
150 | - if ( 1 === count( $terms ) ) { |
|
151 | - $term = current( $terms ); |
|
152 | - $permalink = get_term_link( $term ); |
|
150 | + if (1 === count($terms)) { |
|
151 | + $term = current($terms); |
|
152 | + $permalink = get_term_link($term); |
|
153 | 153 | $type = self::TYPE_TERM_LINK; |
154 | 154 | } |
155 | 155 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * |
164 | 164 | * @since 3.23.0 add the permalink type and term parameters. |
165 | 165 | */ |
166 | - return apply_filters( 'wl_production_permalink', $permalink, $post_id, $type, $term ); |
|
166 | + return apply_filters('wl_production_permalink', $permalink, $post_id, $type, $term); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -174,16 +174,16 @@ discard block |
||
174 | 174 | * @since 3.27.2 |
175 | 175 | */ |
176 | 176 | public function keywords() { |
177 | - $tags = get_the_tags( $this->post_id ); |
|
177 | + $tags = get_the_tags($this->post_id); |
|
178 | 178 | |
179 | - if ( empty( $tags ) ) { |
|
179 | + if (empty($tags)) { |
|
180 | 180 | return; |
181 | 181 | } |
182 | 182 | |
183 | 183 | return implode( |
184 | 184 | ',', |
185 | 185 | array_map( |
186 | - function ( $tag ) { |
|
186 | + function($tag) { |
|
187 | 187 | return $tag->name; |
188 | 188 | }, |
189 | 189 | $tags |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | * @since 3.27.2 |
200 | 200 | */ |
201 | 201 | public function article_section() { |
202 | - $categories = get_the_category( $this->post_id ); |
|
202 | + $categories = get_the_category($this->post_id); |
|
203 | 203 | |
204 | - return wp_list_pluck( $categories, 'cat_name' ); |
|
204 | + return wp_list_pluck($categories, 'cat_name'); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * @since 3.27.2 |
213 | 213 | */ |
214 | 214 | public function comment_count() { |
215 | - return get_comments_number( $this->post_id ); |
|
215 | + return get_comments_number($this->post_id); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -226,22 +226,22 @@ discard block |
||
226 | 226 | public function locale() { |
227 | 227 | $language = 'en-US'; |
228 | 228 | |
229 | - if ( function_exists( 'wpml_get_language_information' ) ) { |
|
229 | + if (function_exists('wpml_get_language_information')) { |
|
230 | 230 | // WPML handling |
231 | 231 | // WPML: Updated function signature. |
232 | 232 | // function wpml_get_language_information( $empty_value = null, $post_id = null ) |
233 | - $post_language = wpml_get_language_information( null, $this->post_id ); |
|
234 | - if ( ! $post_language instanceof WP_Error ) { |
|
233 | + $post_language = wpml_get_language_information(null, $this->post_id); |
|
234 | + if ( ! $post_language instanceof WP_Error) { |
|
235 | 235 | $language = $post_language['locale']; |
236 | 236 | } |
237 | - } elseif ( function_exists( 'pll_get_post_language' ) ) { |
|
237 | + } elseif (function_exists('pll_get_post_language')) { |
|
238 | 238 | // Polylang handling |
239 | - $language = pll_get_post_language( $this->post_id, 'locale' ); |
|
239 | + $language = pll_get_post_language($this->post_id, 'locale'); |
|
240 | 240 | } else { |
241 | 241 | $language = get_locale(); |
242 | 242 | } |
243 | 243 | |
244 | - return str_replace( '_', '-', $language ); |
|
244 | + return str_replace('_', '-', $language); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | } |
@@ -23,61 +23,61 @@ discard block |
||
23 | 23 | */ |
24 | 24 | function wl_linked_data_save_post( $post_id ) { |
25 | 25 | |
26 | - $log = Wordlift_Log_Service::get_logger( 'wl_linked_data_save_post' ); |
|
27 | - |
|
28 | - $log->trace( "Saving post $post_id to Linked Data..." ); |
|
29 | - |
|
30 | - // If it's not numeric exit from here. |
|
31 | - if ( ! is_numeric( $post_id ) || is_numeric( wp_is_post_revision( $post_id ) ) ) { |
|
32 | - $log->debug( "Skipping $post_id, because id is not numeric or is a post revision." ); |
|
33 | - |
|
34 | - return; |
|
35 | - } |
|
36 | - |
|
37 | - // Get the post type and check whether it supports the editor. |
|
38 | - // |
|
39 | - // @see https://github.com/insideout10/wordlift-plugin/issues/659. |
|
40 | - $post_type = get_post_type( $post_id ); |
|
41 | - /** |
|
42 | - * Use `wl_post_type_supports_editor` which calls a filter to allow 3rd parties to change the setting. |
|
43 | - * |
|
44 | - * @since 3.19.4 |
|
45 | - * |
|
46 | - * @see https://github.com/insideout10/wordlift-plugin/issues/847. |
|
47 | - */ |
|
48 | - $is_editor_supported = wl_post_type_supports_editor( $post_type ); |
|
49 | - |
|
50 | - $is_no_editor_analysis_enabled = Wordlift\No_Editor_Analysis\No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( $post_id ); |
|
51 | - // Bail out if it's not an entity. |
|
52 | - if ( ! $is_editor_supported |
|
53 | - && ! $is_no_editor_analysis_enabled ) { |
|
54 | - $log->debug( "Skipping $post_id, because $post_type doesn't support the editor (content)." ); |
|
55 | - |
|
56 | - return; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Only process valid post types |
|
61 | - * |
|
62 | - * @since 3.25.6 |
|
63 | - */ |
|
64 | - $supported_types = Wordlift_Entity_Service::valid_entity_post_types(); |
|
65 | - |
|
66 | - // Bail out if it's not a valid entity. |
|
67 | - if ( ! in_array( $post_type, $supported_types, true ) && ! $is_no_editor_analysis_enabled ) { |
|
68 | - $log->debug( "Skipping $post_id, because $post_type is not a valid entity." ); |
|
69 | - |
|
70 | - return; |
|
71 | - } |
|
72 | - |
|
73 | - // Unhook this function so it doesn't loop infinitely. |
|
74 | - remove_action( 'save_post', 'wl_linked_data_save_post' ); |
|
75 | - |
|
76 | - // raise the *wl_linked_data_save_post* event. |
|
77 | - do_action( 'wl_linked_data_save_post', $post_id ); |
|
78 | - |
|
79 | - // Re-hook this function. |
|
80 | - add_action( 'save_post', 'wl_linked_data_save_post' ); |
|
26 | + $log = Wordlift_Log_Service::get_logger( 'wl_linked_data_save_post' ); |
|
27 | + |
|
28 | + $log->trace( "Saving post $post_id to Linked Data..." ); |
|
29 | + |
|
30 | + // If it's not numeric exit from here. |
|
31 | + if ( ! is_numeric( $post_id ) || is_numeric( wp_is_post_revision( $post_id ) ) ) { |
|
32 | + $log->debug( "Skipping $post_id, because id is not numeric or is a post revision." ); |
|
33 | + |
|
34 | + return; |
|
35 | + } |
|
36 | + |
|
37 | + // Get the post type and check whether it supports the editor. |
|
38 | + // |
|
39 | + // @see https://github.com/insideout10/wordlift-plugin/issues/659. |
|
40 | + $post_type = get_post_type( $post_id ); |
|
41 | + /** |
|
42 | + * Use `wl_post_type_supports_editor` which calls a filter to allow 3rd parties to change the setting. |
|
43 | + * |
|
44 | + * @since 3.19.4 |
|
45 | + * |
|
46 | + * @see https://github.com/insideout10/wordlift-plugin/issues/847. |
|
47 | + */ |
|
48 | + $is_editor_supported = wl_post_type_supports_editor( $post_type ); |
|
49 | + |
|
50 | + $is_no_editor_analysis_enabled = Wordlift\No_Editor_Analysis\No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( $post_id ); |
|
51 | + // Bail out if it's not an entity. |
|
52 | + if ( ! $is_editor_supported |
|
53 | + && ! $is_no_editor_analysis_enabled ) { |
|
54 | + $log->debug( "Skipping $post_id, because $post_type doesn't support the editor (content)." ); |
|
55 | + |
|
56 | + return; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Only process valid post types |
|
61 | + * |
|
62 | + * @since 3.25.6 |
|
63 | + */ |
|
64 | + $supported_types = Wordlift_Entity_Service::valid_entity_post_types(); |
|
65 | + |
|
66 | + // Bail out if it's not a valid entity. |
|
67 | + if ( ! in_array( $post_type, $supported_types, true ) && ! $is_no_editor_analysis_enabled ) { |
|
68 | + $log->debug( "Skipping $post_id, because $post_type is not a valid entity." ); |
|
69 | + |
|
70 | + return; |
|
71 | + } |
|
72 | + |
|
73 | + // Unhook this function so it doesn't loop infinitely. |
|
74 | + remove_action( 'save_post', 'wl_linked_data_save_post' ); |
|
75 | + |
|
76 | + // raise the *wl_linked_data_save_post* event. |
|
77 | + do_action( 'wl_linked_data_save_post', $post_id ); |
|
78 | + |
|
79 | + // Re-hook this function. |
|
80 | + add_action( 'save_post', 'wl_linked_data_save_post' ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | add_action( 'save_post', 'wl_linked_data_save_post' ); |
@@ -93,204 +93,204 @@ discard block |
||
93 | 93 | */ |
94 | 94 | function wl_linked_data_save_post_and_related_entities( $post_id ) { |
95 | 95 | |
96 | - $log = Wordlift_Log_Service::get_logger( 'wl_linked_data_save_post_and_related_entities' ); |
|
97 | - |
|
98 | - $log->trace( "Saving $post_id to Linked Data along with related entities..." ); |
|
99 | - |
|
100 | - // Ignore auto-saves |
|
101 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
102 | - $log->trace( 'Doing autosave, skipping...' ); |
|
103 | - |
|
104 | - return; |
|
105 | - } |
|
106 | - |
|
107 | - // get the current post. |
|
108 | - $post = get_post( $post_id ); |
|
109 | - |
|
110 | - remove_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
111 | - |
|
112 | - // wl_write_log( "[ post id :: $post_id ][ autosave :: false ][ post type :: $post->post_type ]" ); |
|
113 | - |
|
114 | - // Get the entity service instance. |
|
115 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
116 | - $uri_service = Wordlift_Entity_Uri_Service::get_instance(); |
|
117 | - $content_service = Wordpress_Content_Service::get_instance(); |
|
118 | - |
|
119 | - // Store mapping between tmp new entities uris and real new entities uri |
|
120 | - $entities_uri_mapping = array(); |
|
121 | - |
|
122 | - // Save all the selected internal entity uris to this variable. |
|
123 | - $internal_entity_uris = array(); |
|
124 | - |
|
125 | - // Save the entities coming with POST data. |
|
126 | - if ( isset( $_POST['wl_entities'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
127 | - $data = filter_var_array( $_POST, array( 'wl_entities' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
128 | - $entities_via_post = $data['wl_entities']; |
|
129 | - wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " ); |
|
130 | - wl_write_log( wp_json_encode( $entities_via_post ) ); |
|
131 | - wl_write_log( ']' ); |
|
132 | - |
|
133 | - foreach ( $entities_via_post as $entity_uri => $entity ) { |
|
134 | - |
|
135 | - if ( preg_match( '/^local-entity-.+/', $entity_uri ) ) { |
|
136 | - $existing_entity = get_page_by_title( $entity['label'], OBJECT, Wordlift_Entity_Service::valid_entity_post_types() ); |
|
137 | - if ( isset( $existing_entity ) ) { |
|
138 | - $existing_entity_type = Wordlift_Entity_Type_Service::get_instance()->get( $existing_entity->ID ); |
|
139 | - // Type doesn't match, continue to create a new entity. |
|
140 | - if ( ! isset( $existing_entity_type ) || $existing_entity_type['css_class'] !== $entity['main_type'] ) { |
|
141 | - $existing_entity = null; |
|
142 | - } |
|
143 | - } |
|
144 | - } else { |
|
145 | - // Look if current entity uri matches an internal existing entity, meaning: |
|
146 | - // 1. when $entity_uri is an internal uri |
|
147 | - // 2. when $entity_uri is an external uri used as sameAs of an internal entity |
|
148 | - $existing_entity = $entity_service->get_entity_post_by_uri( $entity_uri ); |
|
149 | - } |
|
150 | - |
|
151 | - // Don't save the entities which are not found, but also local. |
|
152 | - if ( ! isset( $existing_entity ) && $uri_service->is_internal( $entity_uri ) ) { |
|
153 | - $internal_entity_uris[] = $entity_uri; |
|
154 | - continue; |
|
155 | - } |
|
156 | - |
|
157 | - if ( ! isset( $existing_entity ) ) { |
|
158 | - // Update entity data with related post |
|
159 | - $entity['related_post_id'] = $post_id; |
|
160 | - // New entity, save it. |
|
161 | - $existing_entity = wl_save_entity( $entity ); |
|
162 | - } else { |
|
163 | - // Existing entity, update post status. |
|
164 | - if ( $existing_entity instanceof WP_Post && 'publish' !== $existing_entity->post_status ) { |
|
165 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
166 | - $post_status = apply_filters( 'wl_feature__enable__entity-auto-publish', true ) |
|
167 | - ? $post->post_status : 'draft'; |
|
168 | - wl_update_post_status( $existing_entity->ID, $post_status ); |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - $uri = $content_service->get_entity_id( Wordpress_Content_Id::create_post( $existing_entity->ID ) ); |
|
173 | - |
|
174 | - $internal_entity_uris[] = $uri; |
|
175 | - wl_write_log( "Map $entity_uri on $uri" ); |
|
176 | - $entities_uri_mapping[ $entity_uri ] = $uri; |
|
177 | - |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - // Replace tmp uris in content post if needed |
|
182 | - $updated_post_content = $post->post_content; |
|
183 | - |
|
184 | - // Update the post content if we found mappings of new entities. |
|
185 | - if ( ! empty( $entities_uri_mapping ) ) { |
|
186 | - // Save each entity and store the post id. |
|
187 | - foreach ( $entities_uri_mapping as $tmp_uri => $uri ) { |
|
188 | - if ( 1 !== preg_match( '@^(https?://|local-entity-)@', $tmp_uri ) ) { |
|
189 | - continue; |
|
190 | - } |
|
191 | - |
|
192 | - $updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content ); |
|
193 | - } |
|
194 | - |
|
195 | - // Update the post content. |
|
196 | - /** |
|
197 | - * Note: wp_update_post do stripslashes before saving the |
|
198 | - * content, so add the slashes to prevent back slash getting |
|
199 | - * removed. |
|
200 | - */ |
|
201 | - wp_update_post( |
|
202 | - array( |
|
203 | - 'ID' => $post->ID, |
|
204 | - 'post_content' => addslashes( $updated_post_content ), |
|
205 | - ) |
|
206 | - ); |
|
207 | - } |
|
208 | - |
|
209 | - // Reset previously saved instances. |
|
210 | - wl_core_delete_relation_instances( $post_id ); |
|
211 | - |
|
212 | - $content_id = Wordpress_Content_Id::create_post( $post->ID ); |
|
213 | - $relations = Relation_Service::get_instance()->get_relations( $content_id ); |
|
214 | - |
|
215 | - if ( No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( $post_id ) ) { |
|
216 | - $relations->add( ...Relation_Service::get_relations_from_uris( $content_id, $internal_entity_uris ) ); |
|
217 | - } |
|
218 | - /** |
|
219 | - * Filter the relations, we dont want to create a relation |
|
220 | - * to uncategorized term, we are already filtering this on jsonld, |
|
221 | - * |
|
222 | - * @todo: do i need to move this to post-term-relation-service ? |
|
223 | - */ |
|
224 | - $filtered_relations = array_filter( |
|
225 | - $relations->toArray(), |
|
226 | - function ( $item ) { |
|
227 | - /** |
|
228 | - * @var $item Relation |
|
229 | - */ |
|
230 | - $object = $item->get_object(); |
|
231 | - |
|
232 | - return ! ( $object->get_type() === Object_Type_Enum::TERM |
|
233 | - && $object->get_id() === 1 ); |
|
234 | - } |
|
235 | - ); |
|
236 | - |
|
237 | - // Save relation instances |
|
238 | - /** @var Relation $relation */ |
|
239 | - foreach ( $filtered_relations as $relation ) { |
|
240 | - $subject = $relation->get_subject(); |
|
241 | - $object = $relation->get_object(); |
|
242 | - |
|
243 | - wl_core_add_relation_instance( |
|
244 | - // subject id. |
|
245 | - $subject->get_id(), |
|
246 | - // what, where, when, who |
|
247 | - $relation->get_predicate(), |
|
248 | - // object id. |
|
249 | - $object->get_id(), |
|
250 | - // Subject type. |
|
251 | - $subject->get_type(), |
|
252 | - // Object type. |
|
253 | - $object->get_type() |
|
254 | - ); |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - if ( isset( $_POST['wl_entities'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
259 | - // Save post metadata if available |
|
260 | - $metadata_via_post = ( isset( $_POST['wl_metadata'] ) ) ? filter_input_array( INPUT_POST, array( 'wl_metadata' => FILTER_DEFAULT ) ) : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
261 | - |
|
262 | - $fields = array( |
|
263 | - Wordlift_Schema_Service::FIELD_LOCATION_CREATED, |
|
264 | - Wordlift_Schema_Service::FIELD_TOPIC, |
|
265 | - ); |
|
266 | - |
|
267 | - // Unlink topic taxonomy terms |
|
268 | - Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for( $post->ID ); |
|
269 | - |
|
270 | - foreach ( $fields as $field ) { |
|
271 | - |
|
272 | - // Delete current values |
|
273 | - delete_post_meta( $post->ID, $field ); |
|
274 | - // Retrieve the entity uri |
|
275 | - $uri = ( isset( $metadata_via_post[ $field ] ) ) ? |
|
276 | - stripslashes( $metadata_via_post[ $field ] ) : ''; |
|
277 | - |
|
278 | - if ( empty( $uri ) ) { |
|
279 | - continue; |
|
280 | - } |
|
281 | - $entity = $entity_service->get_entity_post_by_uri( $uri ); |
|
282 | - |
|
283 | - if ( $entity ) { |
|
284 | - add_post_meta( $post->ID, $field, $entity->ID, true ); |
|
285 | - // Set also the topic taxonomy |
|
286 | - if ( Wordlift_Schema_Service::FIELD_TOPIC === $field ) { |
|
287 | - Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for( $post->ID, $entity ); |
|
288 | - } |
|
289 | - } |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
96 | + $log = Wordlift_Log_Service::get_logger( 'wl_linked_data_save_post_and_related_entities' ); |
|
97 | + |
|
98 | + $log->trace( "Saving $post_id to Linked Data along with related entities..." ); |
|
99 | + |
|
100 | + // Ignore auto-saves |
|
101 | + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
102 | + $log->trace( 'Doing autosave, skipping...' ); |
|
103 | + |
|
104 | + return; |
|
105 | + } |
|
106 | + |
|
107 | + // get the current post. |
|
108 | + $post = get_post( $post_id ); |
|
109 | + |
|
110 | + remove_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
111 | + |
|
112 | + // wl_write_log( "[ post id :: $post_id ][ autosave :: false ][ post type :: $post->post_type ]" ); |
|
113 | + |
|
114 | + // Get the entity service instance. |
|
115 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
116 | + $uri_service = Wordlift_Entity_Uri_Service::get_instance(); |
|
117 | + $content_service = Wordpress_Content_Service::get_instance(); |
|
118 | + |
|
119 | + // Store mapping between tmp new entities uris and real new entities uri |
|
120 | + $entities_uri_mapping = array(); |
|
121 | + |
|
122 | + // Save all the selected internal entity uris to this variable. |
|
123 | + $internal_entity_uris = array(); |
|
124 | + |
|
125 | + // Save the entities coming with POST data. |
|
126 | + if ( isset( $_POST['wl_entities'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
127 | + $data = filter_var_array( $_POST, array( 'wl_entities' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
128 | + $entities_via_post = $data['wl_entities']; |
|
129 | + wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " ); |
|
130 | + wl_write_log( wp_json_encode( $entities_via_post ) ); |
|
131 | + wl_write_log( ']' ); |
|
132 | + |
|
133 | + foreach ( $entities_via_post as $entity_uri => $entity ) { |
|
134 | + |
|
135 | + if ( preg_match( '/^local-entity-.+/', $entity_uri ) ) { |
|
136 | + $existing_entity = get_page_by_title( $entity['label'], OBJECT, Wordlift_Entity_Service::valid_entity_post_types() ); |
|
137 | + if ( isset( $existing_entity ) ) { |
|
138 | + $existing_entity_type = Wordlift_Entity_Type_Service::get_instance()->get( $existing_entity->ID ); |
|
139 | + // Type doesn't match, continue to create a new entity. |
|
140 | + if ( ! isset( $existing_entity_type ) || $existing_entity_type['css_class'] !== $entity['main_type'] ) { |
|
141 | + $existing_entity = null; |
|
142 | + } |
|
143 | + } |
|
144 | + } else { |
|
145 | + // Look if current entity uri matches an internal existing entity, meaning: |
|
146 | + // 1. when $entity_uri is an internal uri |
|
147 | + // 2. when $entity_uri is an external uri used as sameAs of an internal entity |
|
148 | + $existing_entity = $entity_service->get_entity_post_by_uri( $entity_uri ); |
|
149 | + } |
|
150 | + |
|
151 | + // Don't save the entities which are not found, but also local. |
|
152 | + if ( ! isset( $existing_entity ) && $uri_service->is_internal( $entity_uri ) ) { |
|
153 | + $internal_entity_uris[] = $entity_uri; |
|
154 | + continue; |
|
155 | + } |
|
156 | + |
|
157 | + if ( ! isset( $existing_entity ) ) { |
|
158 | + // Update entity data with related post |
|
159 | + $entity['related_post_id'] = $post_id; |
|
160 | + // New entity, save it. |
|
161 | + $existing_entity = wl_save_entity( $entity ); |
|
162 | + } else { |
|
163 | + // Existing entity, update post status. |
|
164 | + if ( $existing_entity instanceof WP_Post && 'publish' !== $existing_entity->post_status ) { |
|
165 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
166 | + $post_status = apply_filters( 'wl_feature__enable__entity-auto-publish', true ) |
|
167 | + ? $post->post_status : 'draft'; |
|
168 | + wl_update_post_status( $existing_entity->ID, $post_status ); |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + $uri = $content_service->get_entity_id( Wordpress_Content_Id::create_post( $existing_entity->ID ) ); |
|
173 | + |
|
174 | + $internal_entity_uris[] = $uri; |
|
175 | + wl_write_log( "Map $entity_uri on $uri" ); |
|
176 | + $entities_uri_mapping[ $entity_uri ] = $uri; |
|
177 | + |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + // Replace tmp uris in content post if needed |
|
182 | + $updated_post_content = $post->post_content; |
|
183 | + |
|
184 | + // Update the post content if we found mappings of new entities. |
|
185 | + if ( ! empty( $entities_uri_mapping ) ) { |
|
186 | + // Save each entity and store the post id. |
|
187 | + foreach ( $entities_uri_mapping as $tmp_uri => $uri ) { |
|
188 | + if ( 1 !== preg_match( '@^(https?://|local-entity-)@', $tmp_uri ) ) { |
|
189 | + continue; |
|
190 | + } |
|
191 | + |
|
192 | + $updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content ); |
|
193 | + } |
|
194 | + |
|
195 | + // Update the post content. |
|
196 | + /** |
|
197 | + * Note: wp_update_post do stripslashes before saving the |
|
198 | + * content, so add the slashes to prevent back slash getting |
|
199 | + * removed. |
|
200 | + */ |
|
201 | + wp_update_post( |
|
202 | + array( |
|
203 | + 'ID' => $post->ID, |
|
204 | + 'post_content' => addslashes( $updated_post_content ), |
|
205 | + ) |
|
206 | + ); |
|
207 | + } |
|
208 | + |
|
209 | + // Reset previously saved instances. |
|
210 | + wl_core_delete_relation_instances( $post_id ); |
|
211 | + |
|
212 | + $content_id = Wordpress_Content_Id::create_post( $post->ID ); |
|
213 | + $relations = Relation_Service::get_instance()->get_relations( $content_id ); |
|
214 | + |
|
215 | + if ( No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( $post_id ) ) { |
|
216 | + $relations->add( ...Relation_Service::get_relations_from_uris( $content_id, $internal_entity_uris ) ); |
|
217 | + } |
|
218 | + /** |
|
219 | + * Filter the relations, we dont want to create a relation |
|
220 | + * to uncategorized term, we are already filtering this on jsonld, |
|
221 | + * |
|
222 | + * @todo: do i need to move this to post-term-relation-service ? |
|
223 | + */ |
|
224 | + $filtered_relations = array_filter( |
|
225 | + $relations->toArray(), |
|
226 | + function ( $item ) { |
|
227 | + /** |
|
228 | + * @var $item Relation |
|
229 | + */ |
|
230 | + $object = $item->get_object(); |
|
231 | + |
|
232 | + return ! ( $object->get_type() === Object_Type_Enum::TERM |
|
233 | + && $object->get_id() === 1 ); |
|
234 | + } |
|
235 | + ); |
|
236 | + |
|
237 | + // Save relation instances |
|
238 | + /** @var Relation $relation */ |
|
239 | + foreach ( $filtered_relations as $relation ) { |
|
240 | + $subject = $relation->get_subject(); |
|
241 | + $object = $relation->get_object(); |
|
242 | + |
|
243 | + wl_core_add_relation_instance( |
|
244 | + // subject id. |
|
245 | + $subject->get_id(), |
|
246 | + // what, where, when, who |
|
247 | + $relation->get_predicate(), |
|
248 | + // object id. |
|
249 | + $object->get_id(), |
|
250 | + // Subject type. |
|
251 | + $subject->get_type(), |
|
252 | + // Object type. |
|
253 | + $object->get_type() |
|
254 | + ); |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + if ( isset( $_POST['wl_entities'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
259 | + // Save post metadata if available |
|
260 | + $metadata_via_post = ( isset( $_POST['wl_metadata'] ) ) ? filter_input_array( INPUT_POST, array( 'wl_metadata' => FILTER_DEFAULT ) ) : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
261 | + |
|
262 | + $fields = array( |
|
263 | + Wordlift_Schema_Service::FIELD_LOCATION_CREATED, |
|
264 | + Wordlift_Schema_Service::FIELD_TOPIC, |
|
265 | + ); |
|
266 | + |
|
267 | + // Unlink topic taxonomy terms |
|
268 | + Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for( $post->ID ); |
|
269 | + |
|
270 | + foreach ( $fields as $field ) { |
|
271 | + |
|
272 | + // Delete current values |
|
273 | + delete_post_meta( $post->ID, $field ); |
|
274 | + // Retrieve the entity uri |
|
275 | + $uri = ( isset( $metadata_via_post[ $field ] ) ) ? |
|
276 | + stripslashes( $metadata_via_post[ $field ] ) : ''; |
|
277 | + |
|
278 | + if ( empty( $uri ) ) { |
|
279 | + continue; |
|
280 | + } |
|
281 | + $entity = $entity_service->get_entity_post_by_uri( $uri ); |
|
282 | + |
|
283 | + if ( $entity ) { |
|
284 | + add_post_meta( $post->ID, $field, $entity->ID, true ); |
|
285 | + // Set also the topic taxonomy |
|
286 | + if ( Wordlift_Schema_Service::FIELD_TOPIC === $field ) { |
|
287 | + Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for( $post->ID, $entity ); |
|
288 | + } |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
@@ -313,221 +313,221 @@ discard block |
||
313 | 313 | */ |
314 | 314 | function wl_save_entity( $entity_data ) { |
315 | 315 | |
316 | - // Required for REST API calls |
|
317 | - if ( ! function_exists( 'wp_crop_image' ) ) { |
|
318 | - require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
319 | - } |
|
316 | + // Required for REST API calls |
|
317 | + if ( ! function_exists( 'wp_crop_image' ) ) { |
|
318 | + require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
319 | + } |
|
320 | 320 | |
321 | - $log = Wordlift_Log_Service::get_logger( 'wl_save_entity' ); |
|
321 | + $log = Wordlift_Log_Service::get_logger( 'wl_save_entity' ); |
|
322 | 322 | |
323 | - /* |
|
323 | + /* |
|
324 | 324 | * Data is coming from a $_POST, sanitize it. |
325 | 325 | * |
326 | 326 | * @since 3.19.4 |
327 | 327 | * |
328 | 328 | * @see https://github.com/insideout10/wordlift-plugin/issues/841 |
329 | 329 | */ |
330 | - $label = preg_replace( '/\xEF\xBB\xBF/', '', sanitize_text_field( $entity_data['label'] ) ); |
|
331 | - $type_uri = $entity_data['main_type']; |
|
332 | - $entity_types = isset( $entity_data['type'] ) ? $entity_data['type'] : array(); |
|
333 | - $description = $entity_data['description']; |
|
334 | - $images = isset( $entity_data['image'] ) ? (array) $entity_data['image'] : array(); |
|
335 | - $same_as = isset( $entity_data['sameas'] ) ? (array) $entity_data['sameas'] : array(); |
|
336 | - $related_post_id = isset( $entity_data['related_post_id'] ) ? $entity_data['related_post_id'] : null; |
|
337 | - $other_properties = isset( $entity_data['properties'] ) ? $entity_data['properties'] : array(); |
|
338 | - // Get the synonyms. |
|
339 | - $synonyms = isset( $entity_data['synonym'] ) ? $entity_data['synonym'] : array(); |
|
340 | - |
|
341 | - // Check whether an entity already exists with the provided URI. |
|
342 | - $uri = $entity_data['uri']; |
|
343 | - if ( isset( $uri ) ) { |
|
344 | - $post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri ); |
|
345 | - if ( isset( $post ) ) { |
|
346 | - $log->debug( "Post already exists for URI $uri." ); |
|
347 | - |
|
348 | - return $post; |
|
349 | - } |
|
350 | - } |
|
351 | - |
|
352 | - // Prepare properties of the new entity. |
|
353 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
354 | - $post_status = apply_filters( 'wl_feature__enable__entity-auto-publish', true ) && is_numeric( $related_post_id ) |
|
355 | - ? get_post_status( $related_post_id ) : 'draft'; |
|
356 | - |
|
357 | - $params = array( |
|
358 | - // @@todo: we don't want an entity to be automatically published. |
|
359 | - 'post_status' => $post_status, |
|
360 | - 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
361 | - 'post_title' => $label, |
|
362 | - 'post_content' => $description, |
|
363 | - 'post_excerpt' => '', |
|
364 | - // Ensure we're using a valid slug. We're not overwriting an existing |
|
365 | - // entity with a post_name already set, since this call is made only for |
|
366 | - // new entities. |
|
367 | - // |
|
368 | - // See https://github.com/insideout10/wordlift-plugin/issues/282 |
|
369 | - 'post_name' => sanitize_title( $label ), |
|
370 | - ); |
|
371 | - |
|
372 | - // If Yoast is installed and active, we temporary remove the save_postdata hook which causes Yoast to "pass over" |
|
373 | - // the local SEO form values to the created entity (https://github.com/insideout10/wordlift-plugin/issues/156) |
|
374 | - // Same thing applies to SEO Ultimate (https://github.com/insideout10/wordlift-plugin/issues/148) |
|
375 | - // This does NOT affect saving an entity from the entity admin page since this function is called when an entity |
|
376 | - // is created when saving a post. |
|
377 | - global $wpseo_metabox, $seo_ultimate; |
|
378 | - if ( isset( $wpseo_metabox ) ) { |
|
379 | - remove_action( |
|
380 | - 'wp_insert_post', |
|
381 | - array( |
|
382 | - $wpseo_metabox, |
|
383 | - 'save_postdata', |
|
384 | - ) |
|
385 | - ); |
|
386 | - } |
|
387 | - |
|
388 | - if ( isset( $seo_ultimate ) ) { |
|
389 | - remove_action( |
|
390 | - 'save_post', |
|
391 | - array( |
|
392 | - $seo_ultimate, |
|
393 | - 'save_postmeta_box', |
|
394 | - ) |
|
395 | - ); |
|
396 | - } |
|
397 | - |
|
398 | - // The fact that we're calling here wp_insert_post is causing issues with plugins (and ourselves too) that hook to |
|
399 | - // save_post in order to save additional inputs from the edit page. In order to avoid issues, we pop all the hooks |
|
400 | - // to the save_post and restore them after we saved the entity. |
|
401 | - // see https://github.com/insideout10/wordlift-plugin/issues/203 |
|
402 | - // see https://github.com/insideout10/wordlift-plugin/issues/156 |
|
403 | - // see https://github.com/insideout10/wordlift-plugin/issues/148 |
|
404 | - global $wp_filter; |
|
405 | - $save_post_filters = is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks; |
|
406 | - is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
|
407 | - |
|
408 | - $log->trace( 'Going to insert new post...' ); |
|
409 | - |
|
410 | - // create or update the post. |
|
411 | - $post_id = wp_insert_post( $params, true ); |
|
412 | - |
|
413 | - // Setting the alternative labels for this entity. |
|
414 | - Wordlift_Entity_Service::get_instance() |
|
415 | - ->set_alternative_labels( $post_id, $synonyms ); |
|
416 | - |
|
417 | - // Restore all the existing filters. |
|
418 | - is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
|
419 | - |
|
420 | - // If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156) |
|
421 | - if ( isset( $wpseo_metabox ) ) { |
|
422 | - add_action( |
|
423 | - 'wp_insert_post', |
|
424 | - array( |
|
425 | - $wpseo_metabox, |
|
426 | - 'save_postdata', |
|
427 | - ) |
|
428 | - ); |
|
429 | - } |
|
430 | - |
|
431 | - // If SEO Ultimate is installed, add back the hook we removed a few lines above. |
|
432 | - if ( isset( $seo_ultimate ) ) { |
|
433 | - add_action( |
|
434 | - 'save_post', |
|
435 | - array( |
|
436 | - $seo_ultimate, |
|
437 | - 'save_postmeta_box', |
|
438 | - ), |
|
439 | - 10, |
|
440 | - 2 |
|
441 | - ); |
|
442 | - } |
|
443 | - |
|
444 | - // TODO: handle errors. |
|
445 | - if ( is_wp_error( $post_id ) ) { |
|
446 | - $log->error( 'An error occurred: ' . $post_id->get_error_message() ); |
|
447 | - |
|
448 | - // inform an error occurred. |
|
449 | - return null; |
|
450 | - } |
|
451 | - |
|
452 | - wl_set_entity_main_type( $post_id, $type_uri ); |
|
453 | - |
|
454 | - // Save the entity types. |
|
455 | - wl_set_entity_rdf_types( $post_id, $entity_types ); |
|
456 | - |
|
457 | - // Get a dataset URI for the entity. |
|
458 | - $wl_uri = Wordlift_Entity_Service::get_instance()->get_uri( $post_id ); |
|
459 | - |
|
460 | - // Add the uri to the sameAs data if it's not a local URI. |
|
461 | - if ( isset( $uri ) && preg_match( '@https?://.*@', $uri ) && |
|
462 | - $wl_uri !== $uri && |
|
463 | - // Only remote entities |
|
464 | - 0 !== strpos( $uri, Wordlift_Configuration_Service::get_instance()->get_dataset_uri() ) |
|
465 | - ) { |
|
466 | - array_push( $same_as, $uri ); |
|
467 | - } |
|
468 | - |
|
469 | - // Save the sameAs data for the entity. |
|
470 | - wl_schema_set_value( $post_id, 'sameAs', $same_as ); |
|
471 | - |
|
472 | - // Save the other properties (latitude, langitude, startDate, endDate, etc.) |
|
473 | - foreach ( $other_properties as $property_name => $property_value ) { |
|
474 | - wl_schema_set_value( $post_id, $property_name, $property_value ); |
|
475 | - } |
|
476 | - |
|
477 | - // Call hooks. |
|
478 | - do_action( 'wl_save_entity', $post_id ); |
|
479 | - |
|
480 | - foreach ( $images as $image_remote_url ) { |
|
481 | - |
|
482 | - // Check if image is already present in local DB |
|
483 | - if ( strpos( $image_remote_url, site_url() ) !== false ) { |
|
484 | - // Do nothing. |
|
485 | - continue; |
|
486 | - } |
|
487 | - |
|
488 | - // Check if there is an existing attachment for this post ID and source URL. |
|
489 | - $existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url ); |
|
490 | - |
|
491 | - // Skip if an existing image is found. |
|
492 | - if ( null !== $existing_image ) { |
|
493 | - continue; |
|
494 | - } |
|
495 | - |
|
496 | - // Save the image and get the local path. |
|
497 | - $image = Wordlift_Remote_Image_Service::save_from_url( $image_remote_url ); |
|
498 | - |
|
499 | - if ( false === $image || is_wp_error( $image ) ) { |
|
500 | - continue; |
|
501 | - } |
|
502 | - |
|
503 | - // Get the local URL. |
|
504 | - $filename = $image['path']; |
|
505 | - $url = $image['url']; |
|
506 | - $content_type = $image['content_type']; |
|
507 | - |
|
508 | - $attachment = array( |
|
509 | - 'guid' => $url, |
|
510 | - // post_title, post_content (the value for this key should be the empty string), post_status and post_mime_type |
|
511 | - 'post_title' => $label, |
|
512 | - // Set the title to the post title. |
|
513 | - 'post_content' => '', |
|
514 | - 'post_status' => 'inherit', |
|
515 | - 'post_mime_type' => $content_type, |
|
516 | - ); |
|
517 | - |
|
518 | - // Create the attachment in WordPress and generate the related metadata. |
|
519 | - $attachment_id = wp_insert_attachment( $attachment, $filename, $post_id ); |
|
520 | - |
|
521 | - // Set the source URL for the image. |
|
522 | - wl_set_source_url( $attachment_id, $image_remote_url ); |
|
523 | - |
|
524 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
525 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
526 | - |
|
527 | - // Set it as the featured image. |
|
528 | - set_post_thumbnail( $post_id, $attachment_id ); |
|
529 | - } |
|
530 | - |
|
531 | - // finally return the entity post. |
|
532 | - return get_post( $post_id ); |
|
330 | + $label = preg_replace( '/\xEF\xBB\xBF/', '', sanitize_text_field( $entity_data['label'] ) ); |
|
331 | + $type_uri = $entity_data['main_type']; |
|
332 | + $entity_types = isset( $entity_data['type'] ) ? $entity_data['type'] : array(); |
|
333 | + $description = $entity_data['description']; |
|
334 | + $images = isset( $entity_data['image'] ) ? (array) $entity_data['image'] : array(); |
|
335 | + $same_as = isset( $entity_data['sameas'] ) ? (array) $entity_data['sameas'] : array(); |
|
336 | + $related_post_id = isset( $entity_data['related_post_id'] ) ? $entity_data['related_post_id'] : null; |
|
337 | + $other_properties = isset( $entity_data['properties'] ) ? $entity_data['properties'] : array(); |
|
338 | + // Get the synonyms. |
|
339 | + $synonyms = isset( $entity_data['synonym'] ) ? $entity_data['synonym'] : array(); |
|
340 | + |
|
341 | + // Check whether an entity already exists with the provided URI. |
|
342 | + $uri = $entity_data['uri']; |
|
343 | + if ( isset( $uri ) ) { |
|
344 | + $post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri ); |
|
345 | + if ( isset( $post ) ) { |
|
346 | + $log->debug( "Post already exists for URI $uri." ); |
|
347 | + |
|
348 | + return $post; |
|
349 | + } |
|
350 | + } |
|
351 | + |
|
352 | + // Prepare properties of the new entity. |
|
353 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
354 | + $post_status = apply_filters( 'wl_feature__enable__entity-auto-publish', true ) && is_numeric( $related_post_id ) |
|
355 | + ? get_post_status( $related_post_id ) : 'draft'; |
|
356 | + |
|
357 | + $params = array( |
|
358 | + // @@todo: we don't want an entity to be automatically published. |
|
359 | + 'post_status' => $post_status, |
|
360 | + 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
361 | + 'post_title' => $label, |
|
362 | + 'post_content' => $description, |
|
363 | + 'post_excerpt' => '', |
|
364 | + // Ensure we're using a valid slug. We're not overwriting an existing |
|
365 | + // entity with a post_name already set, since this call is made only for |
|
366 | + // new entities. |
|
367 | + // |
|
368 | + // See https://github.com/insideout10/wordlift-plugin/issues/282 |
|
369 | + 'post_name' => sanitize_title( $label ), |
|
370 | + ); |
|
371 | + |
|
372 | + // If Yoast is installed and active, we temporary remove the save_postdata hook which causes Yoast to "pass over" |
|
373 | + // the local SEO form values to the created entity (https://github.com/insideout10/wordlift-plugin/issues/156) |
|
374 | + // Same thing applies to SEO Ultimate (https://github.com/insideout10/wordlift-plugin/issues/148) |
|
375 | + // This does NOT affect saving an entity from the entity admin page since this function is called when an entity |
|
376 | + // is created when saving a post. |
|
377 | + global $wpseo_metabox, $seo_ultimate; |
|
378 | + if ( isset( $wpseo_metabox ) ) { |
|
379 | + remove_action( |
|
380 | + 'wp_insert_post', |
|
381 | + array( |
|
382 | + $wpseo_metabox, |
|
383 | + 'save_postdata', |
|
384 | + ) |
|
385 | + ); |
|
386 | + } |
|
387 | + |
|
388 | + if ( isset( $seo_ultimate ) ) { |
|
389 | + remove_action( |
|
390 | + 'save_post', |
|
391 | + array( |
|
392 | + $seo_ultimate, |
|
393 | + 'save_postmeta_box', |
|
394 | + ) |
|
395 | + ); |
|
396 | + } |
|
397 | + |
|
398 | + // The fact that we're calling here wp_insert_post is causing issues with plugins (and ourselves too) that hook to |
|
399 | + // save_post in order to save additional inputs from the edit page. In order to avoid issues, we pop all the hooks |
|
400 | + // to the save_post and restore them after we saved the entity. |
|
401 | + // see https://github.com/insideout10/wordlift-plugin/issues/203 |
|
402 | + // see https://github.com/insideout10/wordlift-plugin/issues/156 |
|
403 | + // see https://github.com/insideout10/wordlift-plugin/issues/148 |
|
404 | + global $wp_filter; |
|
405 | + $save_post_filters = is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks; |
|
406 | + is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
|
407 | + |
|
408 | + $log->trace( 'Going to insert new post...' ); |
|
409 | + |
|
410 | + // create or update the post. |
|
411 | + $post_id = wp_insert_post( $params, true ); |
|
412 | + |
|
413 | + // Setting the alternative labels for this entity. |
|
414 | + Wordlift_Entity_Service::get_instance() |
|
415 | + ->set_alternative_labels( $post_id, $synonyms ); |
|
416 | + |
|
417 | + // Restore all the existing filters. |
|
418 | + is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
|
419 | + |
|
420 | + // If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156) |
|
421 | + if ( isset( $wpseo_metabox ) ) { |
|
422 | + add_action( |
|
423 | + 'wp_insert_post', |
|
424 | + array( |
|
425 | + $wpseo_metabox, |
|
426 | + 'save_postdata', |
|
427 | + ) |
|
428 | + ); |
|
429 | + } |
|
430 | + |
|
431 | + // If SEO Ultimate is installed, add back the hook we removed a few lines above. |
|
432 | + if ( isset( $seo_ultimate ) ) { |
|
433 | + add_action( |
|
434 | + 'save_post', |
|
435 | + array( |
|
436 | + $seo_ultimate, |
|
437 | + 'save_postmeta_box', |
|
438 | + ), |
|
439 | + 10, |
|
440 | + 2 |
|
441 | + ); |
|
442 | + } |
|
443 | + |
|
444 | + // TODO: handle errors. |
|
445 | + if ( is_wp_error( $post_id ) ) { |
|
446 | + $log->error( 'An error occurred: ' . $post_id->get_error_message() ); |
|
447 | + |
|
448 | + // inform an error occurred. |
|
449 | + return null; |
|
450 | + } |
|
451 | + |
|
452 | + wl_set_entity_main_type( $post_id, $type_uri ); |
|
453 | + |
|
454 | + // Save the entity types. |
|
455 | + wl_set_entity_rdf_types( $post_id, $entity_types ); |
|
456 | + |
|
457 | + // Get a dataset URI for the entity. |
|
458 | + $wl_uri = Wordlift_Entity_Service::get_instance()->get_uri( $post_id ); |
|
459 | + |
|
460 | + // Add the uri to the sameAs data if it's not a local URI. |
|
461 | + if ( isset( $uri ) && preg_match( '@https?://.*@', $uri ) && |
|
462 | + $wl_uri !== $uri && |
|
463 | + // Only remote entities |
|
464 | + 0 !== strpos( $uri, Wordlift_Configuration_Service::get_instance()->get_dataset_uri() ) |
|
465 | + ) { |
|
466 | + array_push( $same_as, $uri ); |
|
467 | + } |
|
468 | + |
|
469 | + // Save the sameAs data for the entity. |
|
470 | + wl_schema_set_value( $post_id, 'sameAs', $same_as ); |
|
471 | + |
|
472 | + // Save the other properties (latitude, langitude, startDate, endDate, etc.) |
|
473 | + foreach ( $other_properties as $property_name => $property_value ) { |
|
474 | + wl_schema_set_value( $post_id, $property_name, $property_value ); |
|
475 | + } |
|
476 | + |
|
477 | + // Call hooks. |
|
478 | + do_action( 'wl_save_entity', $post_id ); |
|
479 | + |
|
480 | + foreach ( $images as $image_remote_url ) { |
|
481 | + |
|
482 | + // Check if image is already present in local DB |
|
483 | + if ( strpos( $image_remote_url, site_url() ) !== false ) { |
|
484 | + // Do nothing. |
|
485 | + continue; |
|
486 | + } |
|
487 | + |
|
488 | + // Check if there is an existing attachment for this post ID and source URL. |
|
489 | + $existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url ); |
|
490 | + |
|
491 | + // Skip if an existing image is found. |
|
492 | + if ( null !== $existing_image ) { |
|
493 | + continue; |
|
494 | + } |
|
495 | + |
|
496 | + // Save the image and get the local path. |
|
497 | + $image = Wordlift_Remote_Image_Service::save_from_url( $image_remote_url ); |
|
498 | + |
|
499 | + if ( false === $image || is_wp_error( $image ) ) { |
|
500 | + continue; |
|
501 | + } |
|
502 | + |
|
503 | + // Get the local URL. |
|
504 | + $filename = $image['path']; |
|
505 | + $url = $image['url']; |
|
506 | + $content_type = $image['content_type']; |
|
507 | + |
|
508 | + $attachment = array( |
|
509 | + 'guid' => $url, |
|
510 | + // post_title, post_content (the value for this key should be the empty string), post_status and post_mime_type |
|
511 | + 'post_title' => $label, |
|
512 | + // Set the title to the post title. |
|
513 | + 'post_content' => '', |
|
514 | + 'post_status' => 'inherit', |
|
515 | + 'post_mime_type' => $content_type, |
|
516 | + ); |
|
517 | + |
|
518 | + // Create the attachment in WordPress and generate the related metadata. |
|
519 | + $attachment_id = wp_insert_attachment( $attachment, $filename, $post_id ); |
|
520 | + |
|
521 | + // Set the source URL for the image. |
|
522 | + wl_set_source_url( $attachment_id, $image_remote_url ); |
|
523 | + |
|
524 | + $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
525 | + wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
526 | + |
|
527 | + // Set it as the featured image. |
|
528 | + set_post_thumbnail( $post_id, $attachment_id ); |
|
529 | + } |
|
530 | + |
|
531 | + // finally return the entity post. |
|
532 | + return get_post( $post_id ); |
|
533 | 533 | } |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @since 3.0.0 |
23 | 23 | */ |
24 | -function wl_linked_data_save_post( $post_id ) { |
|
24 | +function wl_linked_data_save_post($post_id) { |
|
25 | 25 | |
26 | - $log = Wordlift_Log_Service::get_logger( 'wl_linked_data_save_post' ); |
|
26 | + $log = Wordlift_Log_Service::get_logger('wl_linked_data_save_post'); |
|
27 | 27 | |
28 | - $log->trace( "Saving post $post_id to Linked Data..." ); |
|
28 | + $log->trace("Saving post $post_id to Linked Data..."); |
|
29 | 29 | |
30 | 30 | // If it's not numeric exit from here. |
31 | - if ( ! is_numeric( $post_id ) || is_numeric( wp_is_post_revision( $post_id ) ) ) { |
|
32 | - $log->debug( "Skipping $post_id, because id is not numeric or is a post revision." ); |
|
31 | + if ( ! is_numeric($post_id) || is_numeric(wp_is_post_revision($post_id))) { |
|
32 | + $log->debug("Skipping $post_id, because id is not numeric or is a post revision."); |
|
33 | 33 | |
34 | 34 | return; |
35 | 35 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | // Get the post type and check whether it supports the editor. |
38 | 38 | // |
39 | 39 | // @see https://github.com/insideout10/wordlift-plugin/issues/659. |
40 | - $post_type = get_post_type( $post_id ); |
|
40 | + $post_type = get_post_type($post_id); |
|
41 | 41 | /** |
42 | 42 | * Use `wl_post_type_supports_editor` which calls a filter to allow 3rd parties to change the setting. |
43 | 43 | * |
@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @see https://github.com/insideout10/wordlift-plugin/issues/847. |
47 | 47 | */ |
48 | - $is_editor_supported = wl_post_type_supports_editor( $post_type ); |
|
48 | + $is_editor_supported = wl_post_type_supports_editor($post_type); |
|
49 | 49 | |
50 | - $is_no_editor_analysis_enabled = Wordlift\No_Editor_Analysis\No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( $post_id ); |
|
50 | + $is_no_editor_analysis_enabled = Wordlift\No_Editor_Analysis\No_Editor_Analysis_Feature::can_no_editor_analysis_be_used($post_id); |
|
51 | 51 | // Bail out if it's not an entity. |
52 | 52 | if ( ! $is_editor_supported |
53 | - && ! $is_no_editor_analysis_enabled ) { |
|
54 | - $log->debug( "Skipping $post_id, because $post_type doesn't support the editor (content)." ); |
|
53 | + && ! $is_no_editor_analysis_enabled) { |
|
54 | + $log->debug("Skipping $post_id, because $post_type doesn't support the editor (content)."); |
|
55 | 55 | |
56 | 56 | return; |
57 | 57 | } |
@@ -64,23 +64,23 @@ discard block |
||
64 | 64 | $supported_types = Wordlift_Entity_Service::valid_entity_post_types(); |
65 | 65 | |
66 | 66 | // Bail out if it's not a valid entity. |
67 | - if ( ! in_array( $post_type, $supported_types, true ) && ! $is_no_editor_analysis_enabled ) { |
|
68 | - $log->debug( "Skipping $post_id, because $post_type is not a valid entity." ); |
|
67 | + if ( ! in_array($post_type, $supported_types, true) && ! $is_no_editor_analysis_enabled) { |
|
68 | + $log->debug("Skipping $post_id, because $post_type is not a valid entity."); |
|
69 | 69 | |
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
73 | 73 | // Unhook this function so it doesn't loop infinitely. |
74 | - remove_action( 'save_post', 'wl_linked_data_save_post' ); |
|
74 | + remove_action('save_post', 'wl_linked_data_save_post'); |
|
75 | 75 | |
76 | 76 | // raise the *wl_linked_data_save_post* event. |
77 | - do_action( 'wl_linked_data_save_post', $post_id ); |
|
77 | + do_action('wl_linked_data_save_post', $post_id); |
|
78 | 78 | |
79 | 79 | // Re-hook this function. |
80 | - add_action( 'save_post', 'wl_linked_data_save_post' ); |
|
80 | + add_action('save_post', 'wl_linked_data_save_post'); |
|
81 | 81 | } |
82 | 82 | |
83 | -add_action( 'save_post', 'wl_linked_data_save_post' ); |
|
83 | +add_action('save_post', 'wl_linked_data_save_post'); |
|
84 | 84 | |
85 | 85 | /** |
86 | 86 | * Save the post to the triple store. Also saves the entities locally and on the triple store. |
@@ -91,23 +91,23 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @since 3.0.0 |
93 | 93 | */ |
94 | -function wl_linked_data_save_post_and_related_entities( $post_id ) { |
|
94 | +function wl_linked_data_save_post_and_related_entities($post_id) { |
|
95 | 95 | |
96 | - $log = Wordlift_Log_Service::get_logger( 'wl_linked_data_save_post_and_related_entities' ); |
|
96 | + $log = Wordlift_Log_Service::get_logger('wl_linked_data_save_post_and_related_entities'); |
|
97 | 97 | |
98 | - $log->trace( "Saving $post_id to Linked Data along with related entities..." ); |
|
98 | + $log->trace("Saving $post_id to Linked Data along with related entities..."); |
|
99 | 99 | |
100 | 100 | // Ignore auto-saves |
101 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
102 | - $log->trace( 'Doing autosave, skipping...' ); |
|
101 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
102 | + $log->trace('Doing autosave, skipping...'); |
|
103 | 103 | |
104 | 104 | return; |
105 | 105 | } |
106 | 106 | |
107 | 107 | // get the current post. |
108 | - $post = get_post( $post_id ); |
|
108 | + $post = get_post($post_id); |
|
109 | 109 | |
110 | - remove_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
110 | + remove_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities'); |
|
111 | 111 | |
112 | 112 | // wl_write_log( "[ post id :: $post_id ][ autosave :: false ][ post type :: $post->post_type ]" ); |
113 | 113 | |
@@ -123,21 +123,21 @@ discard block |
||
123 | 123 | $internal_entity_uris = array(); |
124 | 124 | |
125 | 125 | // Save the entities coming with POST data. |
126 | - if ( isset( $_POST['wl_entities'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
127 | - $data = filter_var_array( $_POST, array( 'wl_entities' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
126 | + if (isset($_POST['wl_entities'])) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
127 | + $data = filter_var_array($_POST, array('wl_entities' => array('flags' => FILTER_REQUIRE_ARRAY))); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
128 | 128 | $entities_via_post = $data['wl_entities']; |
129 | - wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " ); |
|
130 | - wl_write_log( wp_json_encode( $entities_via_post ) ); |
|
131 | - wl_write_log( ']' ); |
|
129 | + wl_write_log("[ post id :: $post_id ][ POST(wl_entities) :: "); |
|
130 | + wl_write_log(wp_json_encode($entities_via_post)); |
|
131 | + wl_write_log(']'); |
|
132 | 132 | |
133 | - foreach ( $entities_via_post as $entity_uri => $entity ) { |
|
133 | + foreach ($entities_via_post as $entity_uri => $entity) { |
|
134 | 134 | |
135 | - if ( preg_match( '/^local-entity-.+/', $entity_uri ) ) { |
|
136 | - $existing_entity = get_page_by_title( $entity['label'], OBJECT, Wordlift_Entity_Service::valid_entity_post_types() ); |
|
137 | - if ( isset( $existing_entity ) ) { |
|
138 | - $existing_entity_type = Wordlift_Entity_Type_Service::get_instance()->get( $existing_entity->ID ); |
|
135 | + if (preg_match('/^local-entity-.+/', $entity_uri)) { |
|
136 | + $existing_entity = get_page_by_title($entity['label'], OBJECT, Wordlift_Entity_Service::valid_entity_post_types()); |
|
137 | + if (isset($existing_entity)) { |
|
138 | + $existing_entity_type = Wordlift_Entity_Type_Service::get_instance()->get($existing_entity->ID); |
|
139 | 139 | // Type doesn't match, continue to create a new entity. |
140 | - if ( ! isset( $existing_entity_type ) || $existing_entity_type['css_class'] !== $entity['main_type'] ) { |
|
140 | + if ( ! isset($existing_entity_type) || $existing_entity_type['css_class'] !== $entity['main_type']) { |
|
141 | 141 | $existing_entity = null; |
142 | 142 | } |
143 | 143 | } |
@@ -145,35 +145,35 @@ discard block |
||
145 | 145 | // Look if current entity uri matches an internal existing entity, meaning: |
146 | 146 | // 1. when $entity_uri is an internal uri |
147 | 147 | // 2. when $entity_uri is an external uri used as sameAs of an internal entity |
148 | - $existing_entity = $entity_service->get_entity_post_by_uri( $entity_uri ); |
|
148 | + $existing_entity = $entity_service->get_entity_post_by_uri($entity_uri); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | // Don't save the entities which are not found, but also local. |
152 | - if ( ! isset( $existing_entity ) && $uri_service->is_internal( $entity_uri ) ) { |
|
152 | + if ( ! isset($existing_entity) && $uri_service->is_internal($entity_uri)) { |
|
153 | 153 | $internal_entity_uris[] = $entity_uri; |
154 | 154 | continue; |
155 | 155 | } |
156 | 156 | |
157 | - if ( ! isset( $existing_entity ) ) { |
|
157 | + if ( ! isset($existing_entity)) { |
|
158 | 158 | // Update entity data with related post |
159 | 159 | $entity['related_post_id'] = $post_id; |
160 | 160 | // New entity, save it. |
161 | - $existing_entity = wl_save_entity( $entity ); |
|
161 | + $existing_entity = wl_save_entity($entity); |
|
162 | 162 | } else { |
163 | 163 | // Existing entity, update post status. |
164 | - if ( $existing_entity instanceof WP_Post && 'publish' !== $existing_entity->post_status ) { |
|
164 | + if ($existing_entity instanceof WP_Post && 'publish' !== $existing_entity->post_status) { |
|
165 | 165 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
166 | - $post_status = apply_filters( 'wl_feature__enable__entity-auto-publish', true ) |
|
166 | + $post_status = apply_filters('wl_feature__enable__entity-auto-publish', true) |
|
167 | 167 | ? $post->post_status : 'draft'; |
168 | - wl_update_post_status( $existing_entity->ID, $post_status ); |
|
168 | + wl_update_post_status($existing_entity->ID, $post_status); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - $uri = $content_service->get_entity_id( Wordpress_Content_Id::create_post( $existing_entity->ID ) ); |
|
172 | + $uri = $content_service->get_entity_id(Wordpress_Content_Id::create_post($existing_entity->ID)); |
|
173 | 173 | |
174 | 174 | $internal_entity_uris[] = $uri; |
175 | - wl_write_log( "Map $entity_uri on $uri" ); |
|
176 | - $entities_uri_mapping[ $entity_uri ] = $uri; |
|
175 | + wl_write_log("Map $entity_uri on $uri"); |
|
176 | + $entities_uri_mapping[$entity_uri] = $uri; |
|
177 | 177 | |
178 | 178 | } |
179 | 179 | } |
@@ -182,14 +182,14 @@ discard block |
||
182 | 182 | $updated_post_content = $post->post_content; |
183 | 183 | |
184 | 184 | // Update the post content if we found mappings of new entities. |
185 | - if ( ! empty( $entities_uri_mapping ) ) { |
|
185 | + if ( ! empty($entities_uri_mapping)) { |
|
186 | 186 | // Save each entity and store the post id. |
187 | - foreach ( $entities_uri_mapping as $tmp_uri => $uri ) { |
|
188 | - if ( 1 !== preg_match( '@^(https?://|local-entity-)@', $tmp_uri ) ) { |
|
187 | + foreach ($entities_uri_mapping as $tmp_uri => $uri) { |
|
188 | + if (1 !== preg_match('@^(https?://|local-entity-)@', $tmp_uri)) { |
|
189 | 189 | continue; |
190 | 190 | } |
191 | 191 | |
192 | - $updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content ); |
|
192 | + $updated_post_content = str_replace($tmp_uri, $uri, $updated_post_content); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | // Update the post content. |
@@ -201,19 +201,19 @@ discard block |
||
201 | 201 | wp_update_post( |
202 | 202 | array( |
203 | 203 | 'ID' => $post->ID, |
204 | - 'post_content' => addslashes( $updated_post_content ), |
|
204 | + 'post_content' => addslashes($updated_post_content), |
|
205 | 205 | ) |
206 | 206 | ); |
207 | 207 | } |
208 | 208 | |
209 | 209 | // Reset previously saved instances. |
210 | - wl_core_delete_relation_instances( $post_id ); |
|
210 | + wl_core_delete_relation_instances($post_id); |
|
211 | 211 | |
212 | - $content_id = Wordpress_Content_Id::create_post( $post->ID ); |
|
213 | - $relations = Relation_Service::get_instance()->get_relations( $content_id ); |
|
212 | + $content_id = Wordpress_Content_Id::create_post($post->ID); |
|
213 | + $relations = Relation_Service::get_instance()->get_relations($content_id); |
|
214 | 214 | |
215 | - if ( No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( $post_id ) ) { |
|
216 | - $relations->add( ...Relation_Service::get_relations_from_uris( $content_id, $internal_entity_uris ) ); |
|
215 | + if (No_Editor_Analysis_Feature::can_no_editor_analysis_be_used($post_id)) { |
|
216 | + $relations->add(...Relation_Service::get_relations_from_uris($content_id, $internal_entity_uris)); |
|
217 | 217 | } |
218 | 218 | /** |
219 | 219 | * Filter the relations, we dont want to create a relation |
@@ -223,20 +223,20 @@ discard block |
||
223 | 223 | */ |
224 | 224 | $filtered_relations = array_filter( |
225 | 225 | $relations->toArray(), |
226 | - function ( $item ) { |
|
226 | + function($item) { |
|
227 | 227 | /** |
228 | 228 | * @var $item Relation |
229 | 229 | */ |
230 | 230 | $object = $item->get_object(); |
231 | 231 | |
232 | - return ! ( $object->get_type() === Object_Type_Enum::TERM |
|
233 | - && $object->get_id() === 1 ); |
|
232 | + return ! ($object->get_type() === Object_Type_Enum::TERM |
|
233 | + && $object->get_id() === 1); |
|
234 | 234 | } |
235 | 235 | ); |
236 | 236 | |
237 | 237 | // Save relation instances |
238 | 238 | /** @var Relation $relation */ |
239 | - foreach ( $filtered_relations as $relation ) { |
|
239 | + foreach ($filtered_relations as $relation) { |
|
240 | 240 | $subject = $relation->get_subject(); |
241 | 241 | $object = $relation->get_object(); |
242 | 242 | |
@@ -255,9 +255,9 @@ discard block |
||
255 | 255 | |
256 | 256 | } |
257 | 257 | |
258 | - if ( isset( $_POST['wl_entities'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
258 | + if (isset($_POST['wl_entities'])) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
259 | 259 | // Save post metadata if available |
260 | - $metadata_via_post = ( isset( $_POST['wl_metadata'] ) ) ? filter_input_array( INPUT_POST, array( 'wl_metadata' => FILTER_DEFAULT ) ) : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
260 | + $metadata_via_post = (isset($_POST['wl_metadata'])) ? filter_input_array(INPUT_POST, array('wl_metadata' => FILTER_DEFAULT)) : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
261 | 261 | |
262 | 262 | $fields = array( |
263 | 263 | Wordlift_Schema_Service::FIELD_LOCATION_CREATED, |
@@ -265,35 +265,35 @@ discard block |
||
265 | 265 | ); |
266 | 266 | |
267 | 267 | // Unlink topic taxonomy terms |
268 | - Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for( $post->ID ); |
|
268 | + Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for($post->ID); |
|
269 | 269 | |
270 | - foreach ( $fields as $field ) { |
|
270 | + foreach ($fields as $field) { |
|
271 | 271 | |
272 | 272 | // Delete current values |
273 | - delete_post_meta( $post->ID, $field ); |
|
273 | + delete_post_meta($post->ID, $field); |
|
274 | 274 | // Retrieve the entity uri |
275 | - $uri = ( isset( $metadata_via_post[ $field ] ) ) ? |
|
276 | - stripslashes( $metadata_via_post[ $field ] ) : ''; |
|
275 | + $uri = (isset($metadata_via_post[$field])) ? |
|
276 | + stripslashes($metadata_via_post[$field]) : ''; |
|
277 | 277 | |
278 | - if ( empty( $uri ) ) { |
|
278 | + if (empty($uri)) { |
|
279 | 279 | continue; |
280 | 280 | } |
281 | - $entity = $entity_service->get_entity_post_by_uri( $uri ); |
|
281 | + $entity = $entity_service->get_entity_post_by_uri($uri); |
|
282 | 282 | |
283 | - if ( $entity ) { |
|
284 | - add_post_meta( $post->ID, $field, $entity->ID, true ); |
|
283 | + if ($entity) { |
|
284 | + add_post_meta($post->ID, $field, $entity->ID, true); |
|
285 | 285 | // Set also the topic taxonomy |
286 | - if ( Wordlift_Schema_Service::FIELD_TOPIC === $field ) { |
|
287 | - Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for( $post->ID, $entity ); |
|
286 | + if (Wordlift_Schema_Service::FIELD_TOPIC === $field) { |
|
287 | + Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for($post->ID, $entity); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
293 | - add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
293 | + add_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities'); |
|
294 | 294 | } |
295 | 295 | |
296 | -add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
296 | +add_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities'); |
|
297 | 297 | |
298 | 298 | /** |
299 | 299 | * Save the specified data as an entity in WordPress. This method only create new entities. When an existing entity is |
@@ -311,14 +311,14 @@ discard block |
||
311 | 311 | * |
312 | 312 | * @return null|WP_Post A post instance or null in case of failure. |
313 | 313 | */ |
314 | -function wl_save_entity( $entity_data ) { |
|
314 | +function wl_save_entity($entity_data) { |
|
315 | 315 | |
316 | 316 | // Required for REST API calls |
317 | - if ( ! function_exists( 'wp_crop_image' ) ) { |
|
318 | - require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
317 | + if ( ! function_exists('wp_crop_image')) { |
|
318 | + require_once ABSPATH.'wp-admin/includes/image.php'; |
|
319 | 319 | } |
320 | 320 | |
321 | - $log = Wordlift_Log_Service::get_logger( 'wl_save_entity' ); |
|
321 | + $log = Wordlift_Log_Service::get_logger('wl_save_entity'); |
|
322 | 322 | |
323 | 323 | /* |
324 | 324 | * Data is coming from a $_POST, sanitize it. |
@@ -327,23 +327,23 @@ discard block |
||
327 | 327 | * |
328 | 328 | * @see https://github.com/insideout10/wordlift-plugin/issues/841 |
329 | 329 | */ |
330 | - $label = preg_replace( '/\xEF\xBB\xBF/', '', sanitize_text_field( $entity_data['label'] ) ); |
|
330 | + $label = preg_replace('/\xEF\xBB\xBF/', '', sanitize_text_field($entity_data['label'])); |
|
331 | 331 | $type_uri = $entity_data['main_type']; |
332 | - $entity_types = isset( $entity_data['type'] ) ? $entity_data['type'] : array(); |
|
332 | + $entity_types = isset($entity_data['type']) ? $entity_data['type'] : array(); |
|
333 | 333 | $description = $entity_data['description']; |
334 | - $images = isset( $entity_data['image'] ) ? (array) $entity_data['image'] : array(); |
|
335 | - $same_as = isset( $entity_data['sameas'] ) ? (array) $entity_data['sameas'] : array(); |
|
336 | - $related_post_id = isset( $entity_data['related_post_id'] ) ? $entity_data['related_post_id'] : null; |
|
337 | - $other_properties = isset( $entity_data['properties'] ) ? $entity_data['properties'] : array(); |
|
334 | + $images = isset($entity_data['image']) ? (array) $entity_data['image'] : array(); |
|
335 | + $same_as = isset($entity_data['sameas']) ? (array) $entity_data['sameas'] : array(); |
|
336 | + $related_post_id = isset($entity_data['related_post_id']) ? $entity_data['related_post_id'] : null; |
|
337 | + $other_properties = isset($entity_data['properties']) ? $entity_data['properties'] : array(); |
|
338 | 338 | // Get the synonyms. |
339 | - $synonyms = isset( $entity_data['synonym'] ) ? $entity_data['synonym'] : array(); |
|
339 | + $synonyms = isset($entity_data['synonym']) ? $entity_data['synonym'] : array(); |
|
340 | 340 | |
341 | 341 | // Check whether an entity already exists with the provided URI. |
342 | 342 | $uri = $entity_data['uri']; |
343 | - if ( isset( $uri ) ) { |
|
344 | - $post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri ); |
|
345 | - if ( isset( $post ) ) { |
|
346 | - $log->debug( "Post already exists for URI $uri." ); |
|
343 | + if (isset($uri)) { |
|
344 | + $post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri($uri); |
|
345 | + if (isset($post)) { |
|
346 | + $log->debug("Post already exists for URI $uri."); |
|
347 | 347 | |
348 | 348 | return $post; |
349 | 349 | } |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | |
352 | 352 | // Prepare properties of the new entity. |
353 | 353 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
354 | - $post_status = apply_filters( 'wl_feature__enable__entity-auto-publish', true ) && is_numeric( $related_post_id ) |
|
355 | - ? get_post_status( $related_post_id ) : 'draft'; |
|
354 | + $post_status = apply_filters('wl_feature__enable__entity-auto-publish', true) && is_numeric($related_post_id) |
|
355 | + ? get_post_status($related_post_id) : 'draft'; |
|
356 | 356 | |
357 | 357 | $params = array( |
358 | 358 | // @@todo: we don't want an entity to be automatically published. |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | // new entities. |
367 | 367 | // |
368 | 368 | // See https://github.com/insideout10/wordlift-plugin/issues/282 |
369 | - 'post_name' => sanitize_title( $label ), |
|
369 | + 'post_name' => sanitize_title($label), |
|
370 | 370 | ); |
371 | 371 | |
372 | 372 | // If Yoast is installed and active, we temporary remove the save_postdata hook which causes Yoast to "pass over" |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | // This does NOT affect saving an entity from the entity admin page since this function is called when an entity |
376 | 376 | // is created when saving a post. |
377 | 377 | global $wpseo_metabox, $seo_ultimate; |
378 | - if ( isset( $wpseo_metabox ) ) { |
|
378 | + if (isset($wpseo_metabox)) { |
|
379 | 379 | remove_action( |
380 | 380 | 'wp_insert_post', |
381 | 381 | array( |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | ); |
386 | 386 | } |
387 | 387 | |
388 | - if ( isset( $seo_ultimate ) ) { |
|
388 | + if (isset($seo_ultimate)) { |
|
389 | 389 | remove_action( |
390 | 390 | 'save_post', |
391 | 391 | array( |
@@ -402,23 +402,23 @@ discard block |
||
402 | 402 | // see https://github.com/insideout10/wordlift-plugin/issues/156 |
403 | 403 | // see https://github.com/insideout10/wordlift-plugin/issues/148 |
404 | 404 | global $wp_filter; |
405 | - $save_post_filters = is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks; |
|
406 | - is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
|
405 | + $save_post_filters = is_array($wp_filter['save_post']) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks; |
|
406 | + is_array($wp_filter['save_post']) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
|
407 | 407 | |
408 | - $log->trace( 'Going to insert new post...' ); |
|
408 | + $log->trace('Going to insert new post...'); |
|
409 | 409 | |
410 | 410 | // create or update the post. |
411 | - $post_id = wp_insert_post( $params, true ); |
|
411 | + $post_id = wp_insert_post($params, true); |
|
412 | 412 | |
413 | 413 | // Setting the alternative labels for this entity. |
414 | 414 | Wordlift_Entity_Service::get_instance() |
415 | - ->set_alternative_labels( $post_id, $synonyms ); |
|
415 | + ->set_alternative_labels($post_id, $synonyms); |
|
416 | 416 | |
417 | 417 | // Restore all the existing filters. |
418 | - is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
|
418 | + is_array($wp_filter['save_post']) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
|
419 | 419 | |
420 | 420 | // If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156) |
421 | - if ( isset( $wpseo_metabox ) ) { |
|
421 | + if (isset($wpseo_metabox)) { |
|
422 | 422 | add_action( |
423 | 423 | 'wp_insert_post', |
424 | 424 | array( |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | } |
430 | 430 | |
431 | 431 | // If SEO Ultimate is installed, add back the hook we removed a few lines above. |
432 | - if ( isset( $seo_ultimate ) ) { |
|
432 | + if (isset($seo_ultimate)) { |
|
433 | 433 | add_action( |
434 | 434 | 'save_post', |
435 | 435 | array( |
@@ -442,61 +442,61 @@ discard block |
||
442 | 442 | } |
443 | 443 | |
444 | 444 | // TODO: handle errors. |
445 | - if ( is_wp_error( $post_id ) ) { |
|
446 | - $log->error( 'An error occurred: ' . $post_id->get_error_message() ); |
|
445 | + if (is_wp_error($post_id)) { |
|
446 | + $log->error('An error occurred: '.$post_id->get_error_message()); |
|
447 | 447 | |
448 | 448 | // inform an error occurred. |
449 | 449 | return null; |
450 | 450 | } |
451 | 451 | |
452 | - wl_set_entity_main_type( $post_id, $type_uri ); |
|
452 | + wl_set_entity_main_type($post_id, $type_uri); |
|
453 | 453 | |
454 | 454 | // Save the entity types. |
455 | - wl_set_entity_rdf_types( $post_id, $entity_types ); |
|
455 | + wl_set_entity_rdf_types($post_id, $entity_types); |
|
456 | 456 | |
457 | 457 | // Get a dataset URI for the entity. |
458 | - $wl_uri = Wordlift_Entity_Service::get_instance()->get_uri( $post_id ); |
|
458 | + $wl_uri = Wordlift_Entity_Service::get_instance()->get_uri($post_id); |
|
459 | 459 | |
460 | 460 | // Add the uri to the sameAs data if it's not a local URI. |
461 | - if ( isset( $uri ) && preg_match( '@https?://.*@', $uri ) && |
|
461 | + if (isset($uri) && preg_match('@https?://.*@', $uri) && |
|
462 | 462 | $wl_uri !== $uri && |
463 | 463 | // Only remote entities |
464 | - 0 !== strpos( $uri, Wordlift_Configuration_Service::get_instance()->get_dataset_uri() ) |
|
464 | + 0 !== strpos($uri, Wordlift_Configuration_Service::get_instance()->get_dataset_uri()) |
|
465 | 465 | ) { |
466 | - array_push( $same_as, $uri ); |
|
466 | + array_push($same_as, $uri); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | // Save the sameAs data for the entity. |
470 | - wl_schema_set_value( $post_id, 'sameAs', $same_as ); |
|
470 | + wl_schema_set_value($post_id, 'sameAs', $same_as); |
|
471 | 471 | |
472 | 472 | // Save the other properties (latitude, langitude, startDate, endDate, etc.) |
473 | - foreach ( $other_properties as $property_name => $property_value ) { |
|
474 | - wl_schema_set_value( $post_id, $property_name, $property_value ); |
|
473 | + foreach ($other_properties as $property_name => $property_value) { |
|
474 | + wl_schema_set_value($post_id, $property_name, $property_value); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | // Call hooks. |
478 | - do_action( 'wl_save_entity', $post_id ); |
|
478 | + do_action('wl_save_entity', $post_id); |
|
479 | 479 | |
480 | - foreach ( $images as $image_remote_url ) { |
|
480 | + foreach ($images as $image_remote_url) { |
|
481 | 481 | |
482 | 482 | // Check if image is already present in local DB |
483 | - if ( strpos( $image_remote_url, site_url() ) !== false ) { |
|
483 | + if (strpos($image_remote_url, site_url()) !== false) { |
|
484 | 484 | // Do nothing. |
485 | 485 | continue; |
486 | 486 | } |
487 | 487 | |
488 | 488 | // Check if there is an existing attachment for this post ID and source URL. |
489 | - $existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url ); |
|
489 | + $existing_image = wl_get_attachment_for_source_url($post_id, $image_remote_url); |
|
490 | 490 | |
491 | 491 | // Skip if an existing image is found. |
492 | - if ( null !== $existing_image ) { |
|
492 | + if (null !== $existing_image) { |
|
493 | 493 | continue; |
494 | 494 | } |
495 | 495 | |
496 | 496 | // Save the image and get the local path. |
497 | - $image = Wordlift_Remote_Image_Service::save_from_url( $image_remote_url ); |
|
497 | + $image = Wordlift_Remote_Image_Service::save_from_url($image_remote_url); |
|
498 | 498 | |
499 | - if ( false === $image || is_wp_error( $image ) ) { |
|
499 | + if (false === $image || is_wp_error($image)) { |
|
500 | 500 | continue; |
501 | 501 | } |
502 | 502 | |
@@ -516,18 +516,18 @@ discard block |
||
516 | 516 | ); |
517 | 517 | |
518 | 518 | // Create the attachment in WordPress and generate the related metadata. |
519 | - $attachment_id = wp_insert_attachment( $attachment, $filename, $post_id ); |
|
519 | + $attachment_id = wp_insert_attachment($attachment, $filename, $post_id); |
|
520 | 520 | |
521 | 521 | // Set the source URL for the image. |
522 | - wl_set_source_url( $attachment_id, $image_remote_url ); |
|
522 | + wl_set_source_url($attachment_id, $image_remote_url); |
|
523 | 523 | |
524 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
525 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
524 | + $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
525 | + wp_update_attachment_metadata($attachment_id, $attachment_data); |
|
526 | 526 | |
527 | 527 | // Set it as the featured image. |
528 | - set_post_thumbnail( $post_id, $attachment_id ); |
|
528 | + set_post_thumbnail($post_id, $attachment_id); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | // finally return the entity post. |
532 | - return get_post( $post_id ); |
|
532 | + return get_post($post_id); |
|
533 | 533 | } |
@@ -12,37 +12,37 @@ discard block |
||
12 | 12 | */ |
13 | 13 | private $content_service; |
14 | 14 | |
15 | - public function __construct( Content_Service $content_service ) { |
|
15 | + public function __construct(Content_Service $content_service) { |
|
16 | 16 | $this->content_service = $content_service; |
17 | 17 | } |
18 | 18 | |
19 | 19 | public function register_hooks() { |
20 | - add_action( 'wl_post_jsonld', array( $this, 'post_jsonld' ), 10, 2 ); |
|
21 | - add_action( 'wl_entity_jsonld', array( $this, 'post_jsonld' ), 10, 2 ); |
|
20 | + add_action('wl_post_jsonld', array($this, 'post_jsonld'), 10, 2); |
|
21 | + add_action('wl_entity_jsonld', array($this, 'post_jsonld'), 10, 2); |
|
22 | 22 | |
23 | 23 | } |
24 | 24 | |
25 | - public function post_jsonld( $jsonld, $post_id ) { |
|
25 | + public function post_jsonld($jsonld, $post_id) { |
|
26 | 26 | |
27 | 27 | $mentions = array(); |
28 | - $term_ids = $this->get_term_ids( $post_id ); |
|
28 | + $term_ids = $this->get_term_ids($post_id); |
|
29 | 29 | |
30 | - foreach ( $term_ids as $term_id ) { |
|
31 | - $this->add_about_jsonld( $mentions, Wordpress_Content_Id::create_term( $term_id ) ); |
|
30 | + foreach ($term_ids as $term_id) { |
|
31 | + $this->add_about_jsonld($mentions, Wordpress_Content_Id::create_term($term_id)); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | // Add also the post jsonld. |
35 | - $this->add_about_jsonld( $mentions, Wordpress_Content_Id::create_post( $post_id ) ); |
|
35 | + $this->add_about_jsonld($mentions, Wordpress_Content_Id::create_post($post_id)); |
|
36 | 36 | |
37 | - $existing_mentions = array_key_exists( 'mentions', $jsonld ) ? $jsonld['mentions'] : array(); |
|
37 | + $existing_mentions = array_key_exists('mentions', $jsonld) ? $jsonld['mentions'] : array(); |
|
38 | 38 | |
39 | - if ( count( $mentions ) > 0 ) { |
|
40 | - $jsonld['mentions'] = array_merge( $existing_mentions, $mentions ); |
|
39 | + if (count($mentions) > 0) { |
|
40 | + $jsonld['mentions'] = array_merge($existing_mentions, $mentions); |
|
41 | 41 | } |
42 | 42 | return $jsonld; |
43 | 43 | } |
44 | 44 | |
45 | - private function get_term_ids( $post_id ) { |
|
45 | + private function get_term_ids($post_id) { |
|
46 | 46 | global $wpdb; |
47 | 47 | $result = $wpdb->get_col( |
48 | 48 | $wpdb->prepare( |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | ) |
53 | 53 | ); |
54 | 54 | |
55 | - return is_array( $result ) ? $result : array(); |
|
55 | + return is_array($result) ? $result : array(); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -61,19 +61,19 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return void |
63 | 63 | */ |
64 | - private function add_about_jsonld( &$list, $content_id ) { |
|
64 | + private function add_about_jsonld(&$list, $content_id) { |
|
65 | 65 | $about_jsonld = $this->content_service->get_about_jsonld( |
66 | 66 | $content_id |
67 | 67 | ); |
68 | - $decoded_jsonld = json_decode( $about_jsonld, true ); |
|
68 | + $decoded_jsonld = json_decode($about_jsonld, true); |
|
69 | 69 | |
70 | - if ( null === $decoded_jsonld ) { |
|
70 | + if (null === $decoded_jsonld) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | - $value = wp_is_numeric_array( $decoded_jsonld ) ? $decoded_jsonld : array( $decoded_jsonld ); |
|
74 | + $value = wp_is_numeric_array($decoded_jsonld) ? $decoded_jsonld : array($decoded_jsonld); |
|
75 | 75 | |
76 | - $list = array_merge( $list, $value ); |
|
76 | + $list = array_merge($list, $value); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 |
@@ -7,74 +7,74 @@ |
||
7 | 7 | |
8 | 8 | class Jsonld { |
9 | 9 | |
10 | - /** |
|
11 | - * @var Content_Service $content_service |
|
12 | - */ |
|
13 | - private $content_service; |
|
10 | + /** |
|
11 | + * @var Content_Service $content_service |
|
12 | + */ |
|
13 | + private $content_service; |
|
14 | 14 | |
15 | - public function __construct( Content_Service $content_service ) { |
|
16 | - $this->content_service = $content_service; |
|
17 | - } |
|
15 | + public function __construct( Content_Service $content_service ) { |
|
16 | + $this->content_service = $content_service; |
|
17 | + } |
|
18 | 18 | |
19 | - public function register_hooks() { |
|
20 | - add_action( 'wl_post_jsonld', array( $this, 'post_jsonld' ), 10, 2 ); |
|
21 | - add_action( 'wl_entity_jsonld', array( $this, 'post_jsonld' ), 10, 2 ); |
|
19 | + public function register_hooks() { |
|
20 | + add_action( 'wl_post_jsonld', array( $this, 'post_jsonld' ), 10, 2 ); |
|
21 | + add_action( 'wl_entity_jsonld', array( $this, 'post_jsonld' ), 10, 2 ); |
|
22 | 22 | |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | - public function post_jsonld( $jsonld, $post_id ) { |
|
25 | + public function post_jsonld( $jsonld, $post_id ) { |
|
26 | 26 | |
27 | - $mentions = array(); |
|
28 | - $term_ids = $this->get_term_ids( $post_id ); |
|
27 | + $mentions = array(); |
|
28 | + $term_ids = $this->get_term_ids( $post_id ); |
|
29 | 29 | |
30 | - foreach ( $term_ids as $term_id ) { |
|
31 | - $this->add_about_jsonld( $mentions, Wordpress_Content_Id::create_term( $term_id ) ); |
|
32 | - } |
|
30 | + foreach ( $term_ids as $term_id ) { |
|
31 | + $this->add_about_jsonld( $mentions, Wordpress_Content_Id::create_term( $term_id ) ); |
|
32 | + } |
|
33 | 33 | |
34 | - // Add also the post jsonld. |
|
35 | - $this->add_about_jsonld( $mentions, Wordpress_Content_Id::create_post( $post_id ) ); |
|
34 | + // Add also the post jsonld. |
|
35 | + $this->add_about_jsonld( $mentions, Wordpress_Content_Id::create_post( $post_id ) ); |
|
36 | 36 | |
37 | - $existing_mentions = array_key_exists( 'mentions', $jsonld ) ? $jsonld['mentions'] : array(); |
|
37 | + $existing_mentions = array_key_exists( 'mentions', $jsonld ) ? $jsonld['mentions'] : array(); |
|
38 | 38 | |
39 | - if ( count( $mentions ) > 0 ) { |
|
40 | - $jsonld['mentions'] = array_merge( $existing_mentions, $mentions ); |
|
41 | - } |
|
42 | - return $jsonld; |
|
43 | - } |
|
39 | + if ( count( $mentions ) > 0 ) { |
|
40 | + $jsonld['mentions'] = array_merge( $existing_mentions, $mentions ); |
|
41 | + } |
|
42 | + return $jsonld; |
|
43 | + } |
|
44 | 44 | |
45 | - private function get_term_ids( $post_id ) { |
|
46 | - global $wpdb; |
|
47 | - $result = $wpdb->get_col( |
|
48 | - $wpdb->prepare( |
|
49 | - "SELECT tt.term_id from {$wpdb->prefix}term_relationships r |
|
45 | + private function get_term_ids( $post_id ) { |
|
46 | + global $wpdb; |
|
47 | + $result = $wpdb->get_col( |
|
48 | + $wpdb->prepare( |
|
49 | + "SELECT tt.term_id from {$wpdb->prefix}term_relationships r |
|
50 | 50 | INNER JOIN {$wpdb->prefix}term_taxonomy tt ON r.term_taxonomy_id=tt.term_taxonomy_id WHERE r.object_id= %d", |
51 | - $post_id |
|
52 | - ) |
|
53 | - ); |
|
54 | - |
|
55 | - return is_array( $result ) ? $result : array(); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param $list array Adds the jsonld to the list if valid. |
|
60 | - * @param $content_id \Wordlift\Content\Wordpress\Wordpress_Content_Id |
|
61 | - * |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - private function add_about_jsonld( &$list, $content_id ) { |
|
65 | - $about_jsonld = $this->content_service->get_about_jsonld( |
|
66 | - $content_id |
|
67 | - ); |
|
68 | - $decoded_jsonld = json_decode( $about_jsonld, true ); |
|
69 | - |
|
70 | - if ( null === $decoded_jsonld ) { |
|
71 | - return; |
|
72 | - } |
|
73 | - |
|
74 | - $value = wp_is_numeric_array( $decoded_jsonld ) ? $decoded_jsonld : array( $decoded_jsonld ); |
|
75 | - |
|
76 | - $list = array_merge( $list, $value ); |
|
77 | - |
|
78 | - } |
|
51 | + $post_id |
|
52 | + ) |
|
53 | + ); |
|
54 | + |
|
55 | + return is_array( $result ) ? $result : array(); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param $list array Adds the jsonld to the list if valid. |
|
60 | + * @param $content_id \Wordlift\Content\Wordpress\Wordpress_Content_Id |
|
61 | + * |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + private function add_about_jsonld( &$list, $content_id ) { |
|
65 | + $about_jsonld = $this->content_service->get_about_jsonld( |
|
66 | + $content_id |
|
67 | + ); |
|
68 | + $decoded_jsonld = json_decode( $about_jsonld, true ); |
|
69 | + |
|
70 | + if ( null === $decoded_jsonld ) { |
|
71 | + return; |
|
72 | + } |
|
73 | + |
|
74 | + $value = wp_is_numeric_array( $decoded_jsonld ) ? $decoded_jsonld : array( $decoded_jsonld ); |
|
75 | + |
|
76 | + $list = array_merge( $list, $value ); |
|
77 | + |
|
78 | + } |
|
79 | 79 | |
80 | 80 | } |
@@ -19,147 +19,147 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class Wordlift_Entity_Type_Service { |
21 | 21 | |
22 | - /** |
|
23 | - * The {@link Wordlift_Schema_Service} instance. |
|
24 | - * |
|
25 | - * @since 3.7.0 |
|
26 | - * @access private |
|
27 | - * @var \Wordlift_Schema_Service $schema_service The {@link Wordlift_Schema_Service} instance. |
|
28 | - */ |
|
29 | - private $schema_service; |
|
30 | - |
|
31 | - /** |
|
32 | - * A {@link Wordlift_Log_Service} instance. |
|
33 | - * |
|
34 | - * @since 3.8.0 |
|
35 | - * @access private |
|
36 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
37 | - */ |
|
38 | - private $log; |
|
39 | - |
|
40 | - /** |
|
41 | - * Wordlift_Entity_Type_Service constructor. |
|
42 | - * |
|
43 | - * @since 3.7.0 |
|
44 | - */ |
|
45 | - protected function __construct() { |
|
46 | - |
|
47 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Type_Service' ); |
|
48 | - |
|
49 | - $this->schema_service = Wordlift_Schema_Service::get_instance(); |
|
50 | - |
|
51 | - $this->prepare_post_types(); |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Prepare post types for Gutenberg use |
|
57 | - * |
|
58 | - * @since 3.26.0 |
|
59 | - */ |
|
60 | - private function prepare_post_types() { |
|
61 | - |
|
62 | - add_action( |
|
63 | - 'init', |
|
64 | - function () { |
|
65 | - // Add post type support for 'custom-fields' for all post types. Specifically needed in Gutenberg |
|
66 | - $post_types = get_post_types(); |
|
67 | - foreach ( $post_types as $post_type ) { |
|
68 | - add_post_type_support( $post_type, 'custom-fields' ); |
|
69 | - } |
|
70 | - } |
|
71 | - ); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * The {@link Wordlift_Entity_Type_Service} singleton instance. |
|
76 | - * |
|
77 | - * @since 3.7.0 |
|
78 | - * @access private |
|
79 | - * @var \Wordlift_Entity_Type_Service $instance The {@link Wordlift_Entity_Type_Service} singleton instance. |
|
80 | - */ |
|
81 | - private static $instance = null; |
|
82 | - |
|
83 | - /** |
|
84 | - * Get the {@link Wordlift_Entity_Type_Service} singleton instance. |
|
85 | - * |
|
86 | - * @return \Wordlift_Entity_Type_Service The {@link Wordlift_Entity_Type_Service} singleton instance. |
|
87 | - * @since 3.7.0 |
|
88 | - */ |
|
89 | - public static function get_instance() { |
|
90 | - |
|
91 | - if ( ! isset( self::$instance ) ) { |
|
92 | - self::$instance = new self(); |
|
93 | - } |
|
94 | - |
|
95 | - return self::$instance; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Get the types associated with the specified entity post id. |
|
100 | - * |
|
101 | - * We have a strategy to define the entity type, given that everything is |
|
102 | - * an entity, i.e. also posts/pages and custom post types. |
|
103 | - * |
|
104 | - * @param int $post_id The post id. |
|
105 | - * |
|
106 | - * @return array|null { |
|
107 | - * An array of type properties or null if no term is associated |
|
108 | - * |
|
109 | - * @type string css_class The css class, e.g. `wl-thing`. |
|
110 | - * @type string uri The schema.org class URI, e.g. `http://schema.org/Thing`. |
|
111 | - * @type array same_as An array of same as attributes. |
|
112 | - * @type array custom_fields An array of custom fields. |
|
113 | - * } |
|
114 | - * @since 3.33.9 The `linked_data` key has been removed. |
|
115 | - * |
|
116 | - * @since 3.20.0 This function will **not** return entity types introduced with 3.20.0. |
|
117 | - * |
|
118 | - * @since 3.18.0 The cases are the following: |
|
119 | - * 1. the post has a term from the Entity Types Taxonomy: the term defines |
|
120 | - * the entity type, e.g. Organization, Person, ... |
|
121 | - * 2. the post doesn't have a term from the Entity Types Taxonomy: |
|
122 | - * a) the post is a `wl_entity` custom post type, then the post is |
|
123 | - * assigned the `Thing` entity type by default. |
|
124 | - * b) the post is a `post` post type, then the post is |
|
125 | - * assigned the `Article` entity type by default. |
|
126 | - * c) the post is a custom post type then it is |
|
127 | - * assigned the `WebPage` entity type by default. |
|
128 | - */ |
|
129 | - public function get( $post_id ) { |
|
130 | - |
|
131 | - $this->log->trace( "Getting the post type for post $post_id..." ); |
|
132 | - |
|
133 | - // Get the post type. |
|
134 | - $post_type = get_post_type( $post_id ); |
|
135 | - |
|
136 | - // Return `web-page` for non entities. |
|
137 | - if ( ! self::is_valid_entity_post_type( $post_type ) ) { |
|
138 | - $this->log->info( "Returning `web-page` for post $post_id." ); |
|
139 | - |
|
140 | - return $this->schema_service->get_schema( 'web-page' ); |
|
141 | - } |
|
142 | - |
|
143 | - // Get the type from the associated classification. |
|
144 | - $terms = wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
145 | - |
|
146 | - // Return the schema type if there is a term found. |
|
147 | - if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { |
|
148 | - // Cycle through the terms and return the first one with a valid schema. |
|
149 | - foreach ( $terms as $term ) { |
|
150 | - $this->log->debug( "Found `{$term->slug}` term for post $post_id." ); |
|
151 | - |
|
152 | - // Try to get the schema for the term. |
|
153 | - $schema = $this->schema_service->get_schema( $term->slug ); |
|
154 | - |
|
155 | - // If found, return it, ignoring the other types. |
|
156 | - if ( null !== $schema ) { |
|
157 | - // Return the entity type with the specified id. |
|
158 | - return $schema; |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - /* |
|
22 | + /** |
|
23 | + * The {@link Wordlift_Schema_Service} instance. |
|
24 | + * |
|
25 | + * @since 3.7.0 |
|
26 | + * @access private |
|
27 | + * @var \Wordlift_Schema_Service $schema_service The {@link Wordlift_Schema_Service} instance. |
|
28 | + */ |
|
29 | + private $schema_service; |
|
30 | + |
|
31 | + /** |
|
32 | + * A {@link Wordlift_Log_Service} instance. |
|
33 | + * |
|
34 | + * @since 3.8.0 |
|
35 | + * @access private |
|
36 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
37 | + */ |
|
38 | + private $log; |
|
39 | + |
|
40 | + /** |
|
41 | + * Wordlift_Entity_Type_Service constructor. |
|
42 | + * |
|
43 | + * @since 3.7.0 |
|
44 | + */ |
|
45 | + protected function __construct() { |
|
46 | + |
|
47 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Type_Service' ); |
|
48 | + |
|
49 | + $this->schema_service = Wordlift_Schema_Service::get_instance(); |
|
50 | + |
|
51 | + $this->prepare_post_types(); |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Prepare post types for Gutenberg use |
|
57 | + * |
|
58 | + * @since 3.26.0 |
|
59 | + */ |
|
60 | + private function prepare_post_types() { |
|
61 | + |
|
62 | + add_action( |
|
63 | + 'init', |
|
64 | + function () { |
|
65 | + // Add post type support for 'custom-fields' for all post types. Specifically needed in Gutenberg |
|
66 | + $post_types = get_post_types(); |
|
67 | + foreach ( $post_types as $post_type ) { |
|
68 | + add_post_type_support( $post_type, 'custom-fields' ); |
|
69 | + } |
|
70 | + } |
|
71 | + ); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * The {@link Wordlift_Entity_Type_Service} singleton instance. |
|
76 | + * |
|
77 | + * @since 3.7.0 |
|
78 | + * @access private |
|
79 | + * @var \Wordlift_Entity_Type_Service $instance The {@link Wordlift_Entity_Type_Service} singleton instance. |
|
80 | + */ |
|
81 | + private static $instance = null; |
|
82 | + |
|
83 | + /** |
|
84 | + * Get the {@link Wordlift_Entity_Type_Service} singleton instance. |
|
85 | + * |
|
86 | + * @return \Wordlift_Entity_Type_Service The {@link Wordlift_Entity_Type_Service} singleton instance. |
|
87 | + * @since 3.7.0 |
|
88 | + */ |
|
89 | + public static function get_instance() { |
|
90 | + |
|
91 | + if ( ! isset( self::$instance ) ) { |
|
92 | + self::$instance = new self(); |
|
93 | + } |
|
94 | + |
|
95 | + return self::$instance; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Get the types associated with the specified entity post id. |
|
100 | + * |
|
101 | + * We have a strategy to define the entity type, given that everything is |
|
102 | + * an entity, i.e. also posts/pages and custom post types. |
|
103 | + * |
|
104 | + * @param int $post_id The post id. |
|
105 | + * |
|
106 | + * @return array|null { |
|
107 | + * An array of type properties or null if no term is associated |
|
108 | + * |
|
109 | + * @type string css_class The css class, e.g. `wl-thing`. |
|
110 | + * @type string uri The schema.org class URI, e.g. `http://schema.org/Thing`. |
|
111 | + * @type array same_as An array of same as attributes. |
|
112 | + * @type array custom_fields An array of custom fields. |
|
113 | + * } |
|
114 | + * @since 3.33.9 The `linked_data` key has been removed. |
|
115 | + * |
|
116 | + * @since 3.20.0 This function will **not** return entity types introduced with 3.20.0. |
|
117 | + * |
|
118 | + * @since 3.18.0 The cases are the following: |
|
119 | + * 1. the post has a term from the Entity Types Taxonomy: the term defines |
|
120 | + * the entity type, e.g. Organization, Person, ... |
|
121 | + * 2. the post doesn't have a term from the Entity Types Taxonomy: |
|
122 | + * a) the post is a `wl_entity` custom post type, then the post is |
|
123 | + * assigned the `Thing` entity type by default. |
|
124 | + * b) the post is a `post` post type, then the post is |
|
125 | + * assigned the `Article` entity type by default. |
|
126 | + * c) the post is a custom post type then it is |
|
127 | + * assigned the `WebPage` entity type by default. |
|
128 | + */ |
|
129 | + public function get( $post_id ) { |
|
130 | + |
|
131 | + $this->log->trace( "Getting the post type for post $post_id..." ); |
|
132 | + |
|
133 | + // Get the post type. |
|
134 | + $post_type = get_post_type( $post_id ); |
|
135 | + |
|
136 | + // Return `web-page` for non entities. |
|
137 | + if ( ! self::is_valid_entity_post_type( $post_type ) ) { |
|
138 | + $this->log->info( "Returning `web-page` for post $post_id." ); |
|
139 | + |
|
140 | + return $this->schema_service->get_schema( 'web-page' ); |
|
141 | + } |
|
142 | + |
|
143 | + // Get the type from the associated classification. |
|
144 | + $terms = wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
145 | + |
|
146 | + // Return the schema type if there is a term found. |
|
147 | + if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { |
|
148 | + // Cycle through the terms and return the first one with a valid schema. |
|
149 | + foreach ( $terms as $term ) { |
|
150 | + $this->log->debug( "Found `{$term->slug}` term for post $post_id." ); |
|
151 | + |
|
152 | + // Try to get the schema for the term. |
|
153 | + $schema = $this->schema_service->get_schema( $term->slug ); |
|
154 | + |
|
155 | + // If found, return it, ignoring the other types. |
|
156 | + if ( null !== $schema ) { |
|
157 | + // Return the entity type with the specified id. |
|
158 | + return $schema; |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + /* |
|
163 | 163 | * When a schema isn't found, we return `thing`. Schema may not be found because |
164 | 164 | * the new schema classes that we support since #852 aren't configured in the schema |
165 | 165 | * service. |
@@ -169,93 +169,93 @@ discard block |
||
169 | 169 | * @since 3.20.0 |
170 | 170 | */ |
171 | 171 | |
172 | - return $this->schema_service->get_schema( 'thing' ); |
|
173 | - } |
|
174 | - |
|
175 | - // If it's a page or post return `Article`. |
|
176 | - if ( in_array( $post_type, array( 'post', 'page' ), true ) ) { |
|
177 | - $this->log->debug( "Post $post_id has no terms, and it's a `post` type, returning `Article`." ); |
|
178 | - |
|
179 | - // Return "Article" schema type for posts. |
|
180 | - return $this->schema_service->get_schema( 'article' ); |
|
181 | - } |
|
182 | - |
|
183 | - // Return "Thing" schema type for entities. |
|
184 | - $this->log->debug( "Post $post_id has no terms, but it's a `wl_entity` type, returning `Thing`." ); |
|
185 | - |
|
186 | - // Return the entity type with the specified id. |
|
187 | - return $this->schema_service->get_schema( 'thing' ); |
|
188 | - |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Get the term ids of the entity types associated to the specified post. |
|
193 | - * |
|
194 | - * @param int $post_id The post id. |
|
195 | - * |
|
196 | - * @return array|WP_Error An array of entity types ids or a {@link WP_Error}. |
|
197 | - * @since 3.20.0 |
|
198 | - */ |
|
199 | - public function get_ids( $post_id ) { |
|
200 | - |
|
201 | - return wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'fields' => 'ids' ) ); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Get the camel case names of the entity types associated to the specified post. |
|
206 | - * |
|
207 | - * @param int $post_id The post id. |
|
208 | - * |
|
209 | - * @return array|WP_Error An array of entity types camel case names or a {@link WP_Error}. |
|
210 | - * @since 3.20.0 |
|
211 | - */ |
|
212 | - public function get_names( $post_id ) { |
|
213 | - |
|
214 | - $ids = $this->get_ids( $post_id ); |
|
215 | - |
|
216 | - // Filter out invalid terms (ones without _wl_name term meta) |
|
217 | - return array_values( |
|
218 | - array_filter( |
|
219 | - array_map( |
|
220 | - function ( $id ) { |
|
221 | - return get_term_meta( $id, '_wl_name', true ); |
|
222 | - }, |
|
223 | - $ids |
|
224 | - ) |
|
225 | - ) |
|
226 | - ); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Set the main type for the specified entity post, given the type URI. |
|
231 | - * |
|
232 | - * @param int $post_id The post id. |
|
233 | - * @param string $type_uri The type URI. |
|
234 | - * @param bool $replace Whether the provided type must replace the existing types, by default `true`. |
|
235 | - * |
|
236 | - * @since 3.8.0 |
|
237 | - */ |
|
238 | - public function set( $post_id, $type_uri, $replace = true ) { |
|
239 | - |
|
240 | - // If the type URI is empty we remove the type. |
|
241 | - if ( empty( $type_uri ) ) { |
|
242 | - $this->log->debug( "Removing entity type for post $post_id..." ); |
|
243 | - |
|
244 | - wp_set_object_terms( $post_id, null, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
245 | - |
|
246 | - return; |
|
247 | - } |
|
248 | - |
|
249 | - $this->log->debug( "Setting entity type for post $post_id..." ); |
|
250 | - |
|
251 | - // if the `$type_uri` starts with `wl-`, we're looking at the class name, which is `wl-` + slug. |
|
252 | - $term = ( 0 === strpos( $type_uri, 'wl-' ) ) |
|
253 | - // Get term by slug. |
|
254 | - ? $this->get_term_by_slug( substr( $type_uri, 3 ) ) |
|
255 | - // Get term by URI. |
|
256 | - : $this->get_term_by_uri( $type_uri ); |
|
257 | - |
|
258 | - /* |
|
172 | + return $this->schema_service->get_schema( 'thing' ); |
|
173 | + } |
|
174 | + |
|
175 | + // If it's a page or post return `Article`. |
|
176 | + if ( in_array( $post_type, array( 'post', 'page' ), true ) ) { |
|
177 | + $this->log->debug( "Post $post_id has no terms, and it's a `post` type, returning `Article`." ); |
|
178 | + |
|
179 | + // Return "Article" schema type for posts. |
|
180 | + return $this->schema_service->get_schema( 'article' ); |
|
181 | + } |
|
182 | + |
|
183 | + // Return "Thing" schema type for entities. |
|
184 | + $this->log->debug( "Post $post_id has no terms, but it's a `wl_entity` type, returning `Thing`." ); |
|
185 | + |
|
186 | + // Return the entity type with the specified id. |
|
187 | + return $this->schema_service->get_schema( 'thing' ); |
|
188 | + |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Get the term ids of the entity types associated to the specified post. |
|
193 | + * |
|
194 | + * @param int $post_id The post id. |
|
195 | + * |
|
196 | + * @return array|WP_Error An array of entity types ids or a {@link WP_Error}. |
|
197 | + * @since 3.20.0 |
|
198 | + */ |
|
199 | + public function get_ids( $post_id ) { |
|
200 | + |
|
201 | + return wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'fields' => 'ids' ) ); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Get the camel case names of the entity types associated to the specified post. |
|
206 | + * |
|
207 | + * @param int $post_id The post id. |
|
208 | + * |
|
209 | + * @return array|WP_Error An array of entity types camel case names or a {@link WP_Error}. |
|
210 | + * @since 3.20.0 |
|
211 | + */ |
|
212 | + public function get_names( $post_id ) { |
|
213 | + |
|
214 | + $ids = $this->get_ids( $post_id ); |
|
215 | + |
|
216 | + // Filter out invalid terms (ones without _wl_name term meta) |
|
217 | + return array_values( |
|
218 | + array_filter( |
|
219 | + array_map( |
|
220 | + function ( $id ) { |
|
221 | + return get_term_meta( $id, '_wl_name', true ); |
|
222 | + }, |
|
223 | + $ids |
|
224 | + ) |
|
225 | + ) |
|
226 | + ); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Set the main type for the specified entity post, given the type URI. |
|
231 | + * |
|
232 | + * @param int $post_id The post id. |
|
233 | + * @param string $type_uri The type URI. |
|
234 | + * @param bool $replace Whether the provided type must replace the existing types, by default `true`. |
|
235 | + * |
|
236 | + * @since 3.8.0 |
|
237 | + */ |
|
238 | + public function set( $post_id, $type_uri, $replace = true ) { |
|
239 | + |
|
240 | + // If the type URI is empty we remove the type. |
|
241 | + if ( empty( $type_uri ) ) { |
|
242 | + $this->log->debug( "Removing entity type for post $post_id..." ); |
|
243 | + |
|
244 | + wp_set_object_terms( $post_id, null, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
245 | + |
|
246 | + return; |
|
247 | + } |
|
248 | + |
|
249 | + $this->log->debug( "Setting entity type for post $post_id..." ); |
|
250 | + |
|
251 | + // if the `$type_uri` starts with `wl-`, we're looking at the class name, which is `wl-` + slug. |
|
252 | + $term = ( 0 === strpos( $type_uri, 'wl-' ) ) |
|
253 | + // Get term by slug. |
|
254 | + ? $this->get_term_by_slug( substr( $type_uri, 3 ) ) |
|
255 | + // Get term by URI. |
|
256 | + : $this->get_term_by_uri( $type_uri ); |
|
257 | + |
|
258 | + /* |
|
259 | 259 | * We always want to assign a type to an entity otherwise it won't show in the Vocabulary and it won't be |
260 | 260 | * connected to Articles via mentions. We realized that the client JS code is passing `wl-other` when the |
261 | 261 | * entity type isn't "notable". In which case we couldn't find an entity type. |
@@ -266,245 +266,245 @@ discard block |
||
266 | 266 | * |
267 | 267 | * @since 3.23.4 |
268 | 268 | */ |
269 | - if ( false === $term ) { |
|
270 | - $this->log->warn( "No term found for URI $type_uri, will use Thing." ); |
|
271 | - |
|
272 | - $term = $this->get_term_by_slug( 'thing' ); |
|
273 | - |
|
274 | - // We still need to be able to bali out here, for example WordPress 5.1 tests create posts before our taxonomy |
|
275 | - // is installed. |
|
276 | - if ( false === $term ) { |
|
277 | - return; |
|
278 | - } |
|
279 | - } |
|
280 | - |
|
281 | - $this->log->debug( "Setting entity type [ post id :: $post_id ][ term id :: $term->term_id ][ term slug :: $term->slug ][ type uri :: $type_uri ]..." ); |
|
282 | - |
|
283 | - // `$replace` is passed to decide whether to replace or append the term. |
|
284 | - wp_set_object_terms( $post_id, $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, ! $replace ); |
|
285 | - |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Get an entity type term given its slug. |
|
290 | - * |
|
291 | - * @param string $slug The slug. |
|
292 | - * |
|
293 | - * @return false|WP_Term WP_Term instance on success. Will return false if `$taxonomy` does not exist |
|
294 | - * or `$term` was not found. |
|
295 | - * @since 3.20.0 |
|
296 | - */ |
|
297 | - private function get_term_by_slug( $slug ) { |
|
298 | - |
|
299 | - return get_term_by( 'slug', $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Get an entity type term given its URI. |
|
304 | - * |
|
305 | - * @param string $uri The uri. |
|
306 | - * |
|
307 | - * @return false|WP_Term WP_Term instance on success. Will return false if `$taxonomy` does not exist |
|
308 | - * or `$term` was not found. |
|
309 | - * @since 3.20.0 |
|
310 | - */ |
|
311 | - public function get_term_by_uri( $uri ) { |
|
312 | - |
|
313 | - $terms = get_terms( |
|
314 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
315 | - array( |
|
316 | - 'fields' => 'all', |
|
317 | - 'get' => 'all', |
|
318 | - 'number' => 1, |
|
319 | - 'meta_query' => array( |
|
320 | - array( |
|
321 | - // Don't use a reference to Wordlift_Schemaorg_Class_Service, unless |
|
322 | - // `WL_ALL_ENTITY_TYPES` is set to true. |
|
323 | - 'key' => '_wl_uri', |
|
324 | - 'value' => $uri, |
|
325 | - ), |
|
326 | - ), |
|
327 | - 'orderby' => 'term_id', |
|
328 | - 'order' => 'ASC', |
|
329 | - ) |
|
330 | - ); |
|
331 | - |
|
332 | - return is_array( $terms ) && ! empty( $terms ) ? $terms[0] : false; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Check whether an entity type is set for the {@link WP_Post} with the |
|
337 | - * specified id. |
|
338 | - * |
|
339 | - * @param int $post_id The {@link WP_Post}'s `id`. |
|
340 | - * @param string $uri The entity type URI. |
|
341 | - * |
|
342 | - * @return bool True if an entity type is set otherwise false. |
|
343 | - * @since 3.15.0 |
|
344 | - */ |
|
345 | - public function has_entity_type( $post_id, $uri = null ) { |
|
346 | - |
|
347 | - $this->log->debug( "Checking if post $post_id has an entity type [ $uri ]..." ); |
|
348 | - |
|
349 | - // If an URI hasn't been specified just check whether we have at least |
|
350 | - // one entity type. |
|
351 | - if ( null === $uri ) { |
|
352 | - return has_term( '', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $post_id ); |
|
353 | - } |
|
354 | - |
|
355 | - $has_entity_type = $this->has_post_term_by_uri( $post_id, $uri ); |
|
356 | - |
|
357 | - $this->log->debug( "Post $post_id has $uri type: " . ( $has_entity_type ? 'yes' : 'no' ) ); |
|
358 | - |
|
359 | - // Check whether the post has an entity type with that URI. |
|
360 | - return $has_entity_type; |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Get the list of entity types' terms for the specified {@link WP_Post}. |
|
365 | - * |
|
366 | - * @param int $post_id The {@link WP_Post} id. |
|
367 | - * |
|
368 | - * @return array|WP_Error An array of entity types' terms or {@link WP_Error}. |
|
369 | - * @since 3.15.0 |
|
370 | - */ |
|
371 | - private function get_post_terms( $post_id ) { |
|
372 | - |
|
373 | - return wp_get_object_terms( |
|
374 | - $post_id, |
|
375 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
376 | - array( |
|
377 | - 'hide_empty' => false, |
|
378 | - // Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'. |
|
379 | - // An issue has been opened with the AAM plugin author as well. |
|
380 | - // |
|
381 | - // see https://github.com/insideout10/wordlift-plugin/issues/334 |
|
382 | - // see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863 |
|
383 | - 'fields' => 'all', |
|
384 | - ) |
|
385 | - ); |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Get an entity type term given its URI. |
|
390 | - * |
|
391 | - * @param int $post_id The {@link WP_Post} id. |
|
392 | - * @param string $uri The entity type URI. |
|
393 | - * |
|
394 | - * @return bool True if the post has that type URI bound to it otherwise false. |
|
395 | - * @since 3.15.0 |
|
396 | - * |
|
397 | - * @since 3.20.0 function renamed to `has_post_term_by_uri` and return type changed to `bool`. |
|
398 | - */ |
|
399 | - private function has_post_term_by_uri( $post_id, $uri ) { |
|
400 | - |
|
401 | - // Get the post terms bound to the specified post. |
|
402 | - $terms = $this->get_post_terms( $post_id ); |
|
403 | - |
|
404 | - // Look for a term if the specified URI. |
|
405 | - foreach ( $terms as $term ) { |
|
406 | - $term_uri = get_term_meta( $term->term_id, '_wl_uri', true ); |
|
407 | - if ( $uri === $term_uri ) { |
|
408 | - return true; |
|
409 | - } |
|
410 | - } |
|
411 | - |
|
412 | - // Return null. |
|
413 | - return false; |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Get the custom fields for a specific post. |
|
418 | - * |
|
419 | - * @param int $post_id The post ID. |
|
420 | - * |
|
421 | - * @return array An array of custom fields (see `custom_fields` in Wordlift_Schema_Service). |
|
422 | - * @since 3.25.2 |
|
423 | - */ |
|
424 | - public function get_custom_fields_for_post( $post_id ) { |
|
425 | - |
|
426 | - // Return custom fields for this specific entity's type. |
|
427 | - $types = $this->get_ids( $post_id ); |
|
428 | - |
|
429 | - /** @var WP_Term[] $terms */ |
|
430 | - $terms = array_filter( |
|
431 | - array_map( |
|
432 | - function ( $item ) { |
|
433 | - return get_term( $item ); |
|
434 | - }, |
|
435 | - $types |
|
436 | - ), |
|
437 | - function ( $item ) { |
|
438 | - return isset( $item ) && is_a( $item, 'WP_Term' ); |
|
439 | - } |
|
440 | - ); |
|
441 | - |
|
442 | - $term_slugs = array_map( |
|
443 | - function ( $item ) { |
|
444 | - return $item->slug; |
|
445 | - }, |
|
446 | - $terms |
|
447 | - ); |
|
448 | - |
|
449 | - $term_slugs[] = 'thing'; |
|
450 | - |
|
451 | - return $this->get_custom_fields_by_term_slugs( $term_slugs ); |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * Get the custom fields for a specific term. |
|
456 | - * |
|
457 | - * @param int $term_id The term ID. |
|
458 | - * |
|
459 | - * @return array An array of custom fields (see `custom_fields` in Wordlift_Schema_Service). |
|
460 | - * @since 3.32.0 |
|
461 | - */ |
|
462 | - public function get_custom_fields_for_term( $term_id ) { |
|
463 | - $selected_entity_types = get_term_meta( $term_id, 'wl_entity_type' ); |
|
464 | - $selected_entity_types[] = 'thing'; |
|
465 | - $selected_entity_types = array_unique( $selected_entity_types ); |
|
466 | - |
|
467 | - return $this->get_custom_fields_by_term_slugs( $selected_entity_types ); |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * Determines whether a post type can be used for entities. |
|
472 | - * |
|
473 | - * Criteria is that the post type is public. The list of valid post types |
|
474 | - * can be overridden with a filter. |
|
475 | - * |
|
476 | - * @param string $post_type A post type name. |
|
477 | - * |
|
478 | - * @return bool Return true if the post type can be used for entities, otherwise false. |
|
479 | - * @since 3.15.0 |
|
480 | - */ |
|
481 | - public static function is_valid_entity_post_type( $post_type ) { |
|
482 | - |
|
483 | - return in_array( $post_type, Wordlift_Entity_Service::valid_entity_post_types(), true ); |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * @param $term_slugs |
|
488 | - * |
|
489 | - * @return array |
|
490 | - */ |
|
491 | - private function get_custom_fields_by_term_slugs( $term_slugs ) { |
|
492 | - $schema_service = Wordlift_Schema_Service::get_instance(); |
|
493 | - |
|
494 | - return array_reduce( |
|
495 | - $term_slugs, |
|
496 | - function ( $carry, $item ) use ( $schema_service ) { |
|
497 | - |
|
498 | - $schema = $schema_service->get_schema( $item ); |
|
499 | - |
|
500 | - if ( ! isset( $schema['custom_fields'] ) ) { |
|
501 | - return $carry; |
|
502 | - } |
|
503 | - |
|
504 | - return $carry + $schema['custom_fields']; |
|
505 | - }, |
|
506 | - array() |
|
507 | - ); |
|
508 | - } |
|
269 | + if ( false === $term ) { |
|
270 | + $this->log->warn( "No term found for URI $type_uri, will use Thing." ); |
|
271 | + |
|
272 | + $term = $this->get_term_by_slug( 'thing' ); |
|
273 | + |
|
274 | + // We still need to be able to bali out here, for example WordPress 5.1 tests create posts before our taxonomy |
|
275 | + // is installed. |
|
276 | + if ( false === $term ) { |
|
277 | + return; |
|
278 | + } |
|
279 | + } |
|
280 | + |
|
281 | + $this->log->debug( "Setting entity type [ post id :: $post_id ][ term id :: $term->term_id ][ term slug :: $term->slug ][ type uri :: $type_uri ]..." ); |
|
282 | + |
|
283 | + // `$replace` is passed to decide whether to replace or append the term. |
|
284 | + wp_set_object_terms( $post_id, $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, ! $replace ); |
|
285 | + |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Get an entity type term given its slug. |
|
290 | + * |
|
291 | + * @param string $slug The slug. |
|
292 | + * |
|
293 | + * @return false|WP_Term WP_Term instance on success. Will return false if `$taxonomy` does not exist |
|
294 | + * or `$term` was not found. |
|
295 | + * @since 3.20.0 |
|
296 | + */ |
|
297 | + private function get_term_by_slug( $slug ) { |
|
298 | + |
|
299 | + return get_term_by( 'slug', $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Get an entity type term given its URI. |
|
304 | + * |
|
305 | + * @param string $uri The uri. |
|
306 | + * |
|
307 | + * @return false|WP_Term WP_Term instance on success. Will return false if `$taxonomy` does not exist |
|
308 | + * or `$term` was not found. |
|
309 | + * @since 3.20.0 |
|
310 | + */ |
|
311 | + public function get_term_by_uri( $uri ) { |
|
312 | + |
|
313 | + $terms = get_terms( |
|
314 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
315 | + array( |
|
316 | + 'fields' => 'all', |
|
317 | + 'get' => 'all', |
|
318 | + 'number' => 1, |
|
319 | + 'meta_query' => array( |
|
320 | + array( |
|
321 | + // Don't use a reference to Wordlift_Schemaorg_Class_Service, unless |
|
322 | + // `WL_ALL_ENTITY_TYPES` is set to true. |
|
323 | + 'key' => '_wl_uri', |
|
324 | + 'value' => $uri, |
|
325 | + ), |
|
326 | + ), |
|
327 | + 'orderby' => 'term_id', |
|
328 | + 'order' => 'ASC', |
|
329 | + ) |
|
330 | + ); |
|
331 | + |
|
332 | + return is_array( $terms ) && ! empty( $terms ) ? $terms[0] : false; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Check whether an entity type is set for the {@link WP_Post} with the |
|
337 | + * specified id. |
|
338 | + * |
|
339 | + * @param int $post_id The {@link WP_Post}'s `id`. |
|
340 | + * @param string $uri The entity type URI. |
|
341 | + * |
|
342 | + * @return bool True if an entity type is set otherwise false. |
|
343 | + * @since 3.15.0 |
|
344 | + */ |
|
345 | + public function has_entity_type( $post_id, $uri = null ) { |
|
346 | + |
|
347 | + $this->log->debug( "Checking if post $post_id has an entity type [ $uri ]..." ); |
|
348 | + |
|
349 | + // If an URI hasn't been specified just check whether we have at least |
|
350 | + // one entity type. |
|
351 | + if ( null === $uri ) { |
|
352 | + return has_term( '', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $post_id ); |
|
353 | + } |
|
354 | + |
|
355 | + $has_entity_type = $this->has_post_term_by_uri( $post_id, $uri ); |
|
356 | + |
|
357 | + $this->log->debug( "Post $post_id has $uri type: " . ( $has_entity_type ? 'yes' : 'no' ) ); |
|
358 | + |
|
359 | + // Check whether the post has an entity type with that URI. |
|
360 | + return $has_entity_type; |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Get the list of entity types' terms for the specified {@link WP_Post}. |
|
365 | + * |
|
366 | + * @param int $post_id The {@link WP_Post} id. |
|
367 | + * |
|
368 | + * @return array|WP_Error An array of entity types' terms or {@link WP_Error}. |
|
369 | + * @since 3.15.0 |
|
370 | + */ |
|
371 | + private function get_post_terms( $post_id ) { |
|
372 | + |
|
373 | + return wp_get_object_terms( |
|
374 | + $post_id, |
|
375 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
376 | + array( |
|
377 | + 'hide_empty' => false, |
|
378 | + // Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'. |
|
379 | + // An issue has been opened with the AAM plugin author as well. |
|
380 | + // |
|
381 | + // see https://github.com/insideout10/wordlift-plugin/issues/334 |
|
382 | + // see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863 |
|
383 | + 'fields' => 'all', |
|
384 | + ) |
|
385 | + ); |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Get an entity type term given its URI. |
|
390 | + * |
|
391 | + * @param int $post_id The {@link WP_Post} id. |
|
392 | + * @param string $uri The entity type URI. |
|
393 | + * |
|
394 | + * @return bool True if the post has that type URI bound to it otherwise false. |
|
395 | + * @since 3.15.0 |
|
396 | + * |
|
397 | + * @since 3.20.0 function renamed to `has_post_term_by_uri` and return type changed to `bool`. |
|
398 | + */ |
|
399 | + private function has_post_term_by_uri( $post_id, $uri ) { |
|
400 | + |
|
401 | + // Get the post terms bound to the specified post. |
|
402 | + $terms = $this->get_post_terms( $post_id ); |
|
403 | + |
|
404 | + // Look for a term if the specified URI. |
|
405 | + foreach ( $terms as $term ) { |
|
406 | + $term_uri = get_term_meta( $term->term_id, '_wl_uri', true ); |
|
407 | + if ( $uri === $term_uri ) { |
|
408 | + return true; |
|
409 | + } |
|
410 | + } |
|
411 | + |
|
412 | + // Return null. |
|
413 | + return false; |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Get the custom fields for a specific post. |
|
418 | + * |
|
419 | + * @param int $post_id The post ID. |
|
420 | + * |
|
421 | + * @return array An array of custom fields (see `custom_fields` in Wordlift_Schema_Service). |
|
422 | + * @since 3.25.2 |
|
423 | + */ |
|
424 | + public function get_custom_fields_for_post( $post_id ) { |
|
425 | + |
|
426 | + // Return custom fields for this specific entity's type. |
|
427 | + $types = $this->get_ids( $post_id ); |
|
428 | + |
|
429 | + /** @var WP_Term[] $terms */ |
|
430 | + $terms = array_filter( |
|
431 | + array_map( |
|
432 | + function ( $item ) { |
|
433 | + return get_term( $item ); |
|
434 | + }, |
|
435 | + $types |
|
436 | + ), |
|
437 | + function ( $item ) { |
|
438 | + return isset( $item ) && is_a( $item, 'WP_Term' ); |
|
439 | + } |
|
440 | + ); |
|
441 | + |
|
442 | + $term_slugs = array_map( |
|
443 | + function ( $item ) { |
|
444 | + return $item->slug; |
|
445 | + }, |
|
446 | + $terms |
|
447 | + ); |
|
448 | + |
|
449 | + $term_slugs[] = 'thing'; |
|
450 | + |
|
451 | + return $this->get_custom_fields_by_term_slugs( $term_slugs ); |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * Get the custom fields for a specific term. |
|
456 | + * |
|
457 | + * @param int $term_id The term ID. |
|
458 | + * |
|
459 | + * @return array An array of custom fields (see `custom_fields` in Wordlift_Schema_Service). |
|
460 | + * @since 3.32.0 |
|
461 | + */ |
|
462 | + public function get_custom_fields_for_term( $term_id ) { |
|
463 | + $selected_entity_types = get_term_meta( $term_id, 'wl_entity_type' ); |
|
464 | + $selected_entity_types[] = 'thing'; |
|
465 | + $selected_entity_types = array_unique( $selected_entity_types ); |
|
466 | + |
|
467 | + return $this->get_custom_fields_by_term_slugs( $selected_entity_types ); |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * Determines whether a post type can be used for entities. |
|
472 | + * |
|
473 | + * Criteria is that the post type is public. The list of valid post types |
|
474 | + * can be overridden with a filter. |
|
475 | + * |
|
476 | + * @param string $post_type A post type name. |
|
477 | + * |
|
478 | + * @return bool Return true if the post type can be used for entities, otherwise false. |
|
479 | + * @since 3.15.0 |
|
480 | + */ |
|
481 | + public static function is_valid_entity_post_type( $post_type ) { |
|
482 | + |
|
483 | + return in_array( $post_type, Wordlift_Entity_Service::valid_entity_post_types(), true ); |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * @param $term_slugs |
|
488 | + * |
|
489 | + * @return array |
|
490 | + */ |
|
491 | + private function get_custom_fields_by_term_slugs( $term_slugs ) { |
|
492 | + $schema_service = Wordlift_Schema_Service::get_instance(); |
|
493 | + |
|
494 | + return array_reduce( |
|
495 | + $term_slugs, |
|
496 | + function ( $carry, $item ) use ( $schema_service ) { |
|
497 | + |
|
498 | + $schema = $schema_service->get_schema( $item ); |
|
499 | + |
|
500 | + if ( ! isset( $schema['custom_fields'] ) ) { |
|
501 | + return $carry; |
|
502 | + } |
|
503 | + |
|
504 | + return $carry + $schema['custom_fields']; |
|
505 | + }, |
|
506 | + array() |
|
507 | + ); |
|
508 | + } |
|
509 | 509 | |
510 | 510 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected function __construct() { |
46 | 46 | |
47 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Type_Service' ); |
|
47 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Entity_Type_Service'); |
|
48 | 48 | |
49 | 49 | $this->schema_service = Wordlift_Schema_Service::get_instance(); |
50 | 50 | |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | |
62 | 62 | add_action( |
63 | 63 | 'init', |
64 | - function () { |
|
64 | + function() { |
|
65 | 65 | // Add post type support for 'custom-fields' for all post types. Specifically needed in Gutenberg |
66 | 66 | $post_types = get_post_types(); |
67 | - foreach ( $post_types as $post_type ) { |
|
68 | - add_post_type_support( $post_type, 'custom-fields' ); |
|
67 | + foreach ($post_types as $post_type) { |
|
68 | + add_post_type_support($post_type, 'custom-fields'); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | ); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public static function get_instance() { |
90 | 90 | |
91 | - if ( ! isset( self::$instance ) ) { |
|
91 | + if ( ! isset(self::$instance)) { |
|
92 | 92 | self::$instance = new self(); |
93 | 93 | } |
94 | 94 | |
@@ -126,34 +126,34 @@ discard block |
||
126 | 126 | * c) the post is a custom post type then it is |
127 | 127 | * assigned the `WebPage` entity type by default. |
128 | 128 | */ |
129 | - public function get( $post_id ) { |
|
129 | + public function get($post_id) { |
|
130 | 130 | |
131 | - $this->log->trace( "Getting the post type for post $post_id..." ); |
|
131 | + $this->log->trace("Getting the post type for post $post_id..."); |
|
132 | 132 | |
133 | 133 | // Get the post type. |
134 | - $post_type = get_post_type( $post_id ); |
|
134 | + $post_type = get_post_type($post_id); |
|
135 | 135 | |
136 | 136 | // Return `web-page` for non entities. |
137 | - if ( ! self::is_valid_entity_post_type( $post_type ) ) { |
|
138 | - $this->log->info( "Returning `web-page` for post $post_id." ); |
|
137 | + if ( ! self::is_valid_entity_post_type($post_type)) { |
|
138 | + $this->log->info("Returning `web-page` for post $post_id."); |
|
139 | 139 | |
140 | - return $this->schema_service->get_schema( 'web-page' ); |
|
140 | + return $this->schema_service->get_schema('web-page'); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | // Get the type from the associated classification. |
144 | - $terms = wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
144 | + $terms = wp_get_object_terms($post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
145 | 145 | |
146 | 146 | // Return the schema type if there is a term found. |
147 | - if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { |
|
147 | + if ( ! is_wp_error($terms) && ! empty($terms)) { |
|
148 | 148 | // Cycle through the terms and return the first one with a valid schema. |
149 | - foreach ( $terms as $term ) { |
|
150 | - $this->log->debug( "Found `{$term->slug}` term for post $post_id." ); |
|
149 | + foreach ($terms as $term) { |
|
150 | + $this->log->debug("Found `{$term->slug}` term for post $post_id."); |
|
151 | 151 | |
152 | 152 | // Try to get the schema for the term. |
153 | - $schema = $this->schema_service->get_schema( $term->slug ); |
|
153 | + $schema = $this->schema_service->get_schema($term->slug); |
|
154 | 154 | |
155 | 155 | // If found, return it, ignoring the other types. |
156 | - if ( null !== $schema ) { |
|
156 | + if (null !== $schema) { |
|
157 | 157 | // Return the entity type with the specified id. |
158 | 158 | return $schema; |
159 | 159 | } |
@@ -169,22 +169,22 @@ discard block |
||
169 | 169 | * @since 3.20.0 |
170 | 170 | */ |
171 | 171 | |
172 | - return $this->schema_service->get_schema( 'thing' ); |
|
172 | + return $this->schema_service->get_schema('thing'); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | // If it's a page or post return `Article`. |
176 | - if ( in_array( $post_type, array( 'post', 'page' ), true ) ) { |
|
177 | - $this->log->debug( "Post $post_id has no terms, and it's a `post` type, returning `Article`." ); |
|
176 | + if (in_array($post_type, array('post', 'page'), true)) { |
|
177 | + $this->log->debug("Post $post_id has no terms, and it's a `post` type, returning `Article`."); |
|
178 | 178 | |
179 | 179 | // Return "Article" schema type for posts. |
180 | - return $this->schema_service->get_schema( 'article' ); |
|
180 | + return $this->schema_service->get_schema('article'); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | // Return "Thing" schema type for entities. |
184 | - $this->log->debug( "Post $post_id has no terms, but it's a `wl_entity` type, returning `Thing`." ); |
|
184 | + $this->log->debug("Post $post_id has no terms, but it's a `wl_entity` type, returning `Thing`."); |
|
185 | 185 | |
186 | 186 | // Return the entity type with the specified id. |
187 | - return $this->schema_service->get_schema( 'thing' ); |
|
187 | + return $this->schema_service->get_schema('thing'); |
|
188 | 188 | |
189 | 189 | } |
190 | 190 | |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | * @return array|WP_Error An array of entity types ids or a {@link WP_Error}. |
197 | 197 | * @since 3.20.0 |
198 | 198 | */ |
199 | - public function get_ids( $post_id ) { |
|
199 | + public function get_ids($post_id) { |
|
200 | 200 | |
201 | - return wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'fields' => 'ids' ) ); |
|
201 | + return wp_get_object_terms($post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array('fields' => 'ids')); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,16 +209,16 @@ discard block |
||
209 | 209 | * @return array|WP_Error An array of entity types camel case names or a {@link WP_Error}. |
210 | 210 | * @since 3.20.0 |
211 | 211 | */ |
212 | - public function get_names( $post_id ) { |
|
212 | + public function get_names($post_id) { |
|
213 | 213 | |
214 | - $ids = $this->get_ids( $post_id ); |
|
214 | + $ids = $this->get_ids($post_id); |
|
215 | 215 | |
216 | 216 | // Filter out invalid terms (ones without _wl_name term meta) |
217 | 217 | return array_values( |
218 | 218 | array_filter( |
219 | 219 | array_map( |
220 | - function ( $id ) { |
|
221 | - return get_term_meta( $id, '_wl_name', true ); |
|
220 | + function($id) { |
|
221 | + return get_term_meta($id, '_wl_name', true); |
|
222 | 222 | }, |
223 | 223 | $ids |
224 | 224 | ) |
@@ -235,25 +235,25 @@ discard block |
||
235 | 235 | * |
236 | 236 | * @since 3.8.0 |
237 | 237 | */ |
238 | - public function set( $post_id, $type_uri, $replace = true ) { |
|
238 | + public function set($post_id, $type_uri, $replace = true) { |
|
239 | 239 | |
240 | 240 | // If the type URI is empty we remove the type. |
241 | - if ( empty( $type_uri ) ) { |
|
242 | - $this->log->debug( "Removing entity type for post $post_id..." ); |
|
241 | + if (empty($type_uri)) { |
|
242 | + $this->log->debug("Removing entity type for post $post_id..."); |
|
243 | 243 | |
244 | - wp_set_object_terms( $post_id, null, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
244 | + wp_set_object_terms($post_id, null, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
245 | 245 | |
246 | 246 | return; |
247 | 247 | } |
248 | 248 | |
249 | - $this->log->debug( "Setting entity type for post $post_id..." ); |
|
249 | + $this->log->debug("Setting entity type for post $post_id..."); |
|
250 | 250 | |
251 | 251 | // if the `$type_uri` starts with `wl-`, we're looking at the class name, which is `wl-` + slug. |
252 | - $term = ( 0 === strpos( $type_uri, 'wl-' ) ) |
|
252 | + $term = (0 === strpos($type_uri, 'wl-')) |
|
253 | 253 | // Get term by slug. |
254 | - ? $this->get_term_by_slug( substr( $type_uri, 3 ) ) |
|
254 | + ? $this->get_term_by_slug(substr($type_uri, 3)) |
|
255 | 255 | // Get term by URI. |
256 | - : $this->get_term_by_uri( $type_uri ); |
|
256 | + : $this->get_term_by_uri($type_uri); |
|
257 | 257 | |
258 | 258 | /* |
259 | 259 | * We always want to assign a type to an entity otherwise it won't show in the Vocabulary and it won't be |
@@ -266,22 +266,22 @@ discard block |
||
266 | 266 | * |
267 | 267 | * @since 3.23.4 |
268 | 268 | */ |
269 | - if ( false === $term ) { |
|
270 | - $this->log->warn( "No term found for URI $type_uri, will use Thing." ); |
|
269 | + if (false === $term) { |
|
270 | + $this->log->warn("No term found for URI $type_uri, will use Thing."); |
|
271 | 271 | |
272 | - $term = $this->get_term_by_slug( 'thing' ); |
|
272 | + $term = $this->get_term_by_slug('thing'); |
|
273 | 273 | |
274 | 274 | // We still need to be able to bali out here, for example WordPress 5.1 tests create posts before our taxonomy |
275 | 275 | // is installed. |
276 | - if ( false === $term ) { |
|
276 | + if (false === $term) { |
|
277 | 277 | return; |
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | - $this->log->debug( "Setting entity type [ post id :: $post_id ][ term id :: $term->term_id ][ term slug :: $term->slug ][ type uri :: $type_uri ]..." ); |
|
281 | + $this->log->debug("Setting entity type [ post id :: $post_id ][ term id :: $term->term_id ][ term slug :: $term->slug ][ type uri :: $type_uri ]..."); |
|
282 | 282 | |
283 | 283 | // `$replace` is passed to decide whether to replace or append the term. |
284 | - wp_set_object_terms( $post_id, $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, ! $replace ); |
|
284 | + wp_set_object_terms($post_id, $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, ! $replace); |
|
285 | 285 | |
286 | 286 | } |
287 | 287 | |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | * or `$term` was not found. |
295 | 295 | * @since 3.20.0 |
296 | 296 | */ |
297 | - private function get_term_by_slug( $slug ) { |
|
297 | + private function get_term_by_slug($slug) { |
|
298 | 298 | |
299 | - return get_term_by( 'slug', $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
299 | + return get_term_by('slug', $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * or `$term` was not found. |
309 | 309 | * @since 3.20.0 |
310 | 310 | */ |
311 | - public function get_term_by_uri( $uri ) { |
|
311 | + public function get_term_by_uri($uri) { |
|
312 | 312 | |
313 | 313 | $terms = get_terms( |
314 | 314 | Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | ) |
330 | 330 | ); |
331 | 331 | |
332 | - return is_array( $terms ) && ! empty( $terms ) ? $terms[0] : false; |
|
332 | + return is_array($terms) && ! empty($terms) ? $terms[0] : false; |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -342,19 +342,19 @@ discard block |
||
342 | 342 | * @return bool True if an entity type is set otherwise false. |
343 | 343 | * @since 3.15.0 |
344 | 344 | */ |
345 | - public function has_entity_type( $post_id, $uri = null ) { |
|
345 | + public function has_entity_type($post_id, $uri = null) { |
|
346 | 346 | |
347 | - $this->log->debug( "Checking if post $post_id has an entity type [ $uri ]..." ); |
|
347 | + $this->log->debug("Checking if post $post_id has an entity type [ $uri ]..."); |
|
348 | 348 | |
349 | 349 | // If an URI hasn't been specified just check whether we have at least |
350 | 350 | // one entity type. |
351 | - if ( null === $uri ) { |
|
352 | - return has_term( '', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $post_id ); |
|
351 | + if (null === $uri) { |
|
352 | + return has_term('', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $post_id); |
|
353 | 353 | } |
354 | 354 | |
355 | - $has_entity_type = $this->has_post_term_by_uri( $post_id, $uri ); |
|
355 | + $has_entity_type = $this->has_post_term_by_uri($post_id, $uri); |
|
356 | 356 | |
357 | - $this->log->debug( "Post $post_id has $uri type: " . ( $has_entity_type ? 'yes' : 'no' ) ); |
|
357 | + $this->log->debug("Post $post_id has $uri type: ".($has_entity_type ? 'yes' : 'no')); |
|
358 | 358 | |
359 | 359 | // Check whether the post has an entity type with that URI. |
360 | 360 | return $has_entity_type; |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | * @return array|WP_Error An array of entity types' terms or {@link WP_Error}. |
369 | 369 | * @since 3.15.0 |
370 | 370 | */ |
371 | - private function get_post_terms( $post_id ) { |
|
371 | + private function get_post_terms($post_id) { |
|
372 | 372 | |
373 | 373 | return wp_get_object_terms( |
374 | 374 | $post_id, |
@@ -396,15 +396,15 @@ discard block |
||
396 | 396 | * |
397 | 397 | * @since 3.20.0 function renamed to `has_post_term_by_uri` and return type changed to `bool`. |
398 | 398 | */ |
399 | - private function has_post_term_by_uri( $post_id, $uri ) { |
|
399 | + private function has_post_term_by_uri($post_id, $uri) { |
|
400 | 400 | |
401 | 401 | // Get the post terms bound to the specified post. |
402 | - $terms = $this->get_post_terms( $post_id ); |
|
402 | + $terms = $this->get_post_terms($post_id); |
|
403 | 403 | |
404 | 404 | // Look for a term if the specified URI. |
405 | - foreach ( $terms as $term ) { |
|
406 | - $term_uri = get_term_meta( $term->term_id, '_wl_uri', true ); |
|
407 | - if ( $uri === $term_uri ) { |
|
405 | + foreach ($terms as $term) { |
|
406 | + $term_uri = get_term_meta($term->term_id, '_wl_uri', true); |
|
407 | + if ($uri === $term_uri) { |
|
408 | 408 | return true; |
409 | 409 | } |
410 | 410 | } |
@@ -421,26 +421,26 @@ discard block |
||
421 | 421 | * @return array An array of custom fields (see `custom_fields` in Wordlift_Schema_Service). |
422 | 422 | * @since 3.25.2 |
423 | 423 | */ |
424 | - public function get_custom_fields_for_post( $post_id ) { |
|
424 | + public function get_custom_fields_for_post($post_id) { |
|
425 | 425 | |
426 | 426 | // Return custom fields for this specific entity's type. |
427 | - $types = $this->get_ids( $post_id ); |
|
427 | + $types = $this->get_ids($post_id); |
|
428 | 428 | |
429 | 429 | /** @var WP_Term[] $terms */ |
430 | 430 | $terms = array_filter( |
431 | 431 | array_map( |
432 | - function ( $item ) { |
|
433 | - return get_term( $item ); |
|
432 | + function($item) { |
|
433 | + return get_term($item); |
|
434 | 434 | }, |
435 | 435 | $types |
436 | 436 | ), |
437 | - function ( $item ) { |
|
438 | - return isset( $item ) && is_a( $item, 'WP_Term' ); |
|
437 | + function($item) { |
|
438 | + return isset($item) && is_a($item, 'WP_Term'); |
|
439 | 439 | } |
440 | 440 | ); |
441 | 441 | |
442 | 442 | $term_slugs = array_map( |
443 | - function ( $item ) { |
|
443 | + function($item) { |
|
444 | 444 | return $item->slug; |
445 | 445 | }, |
446 | 446 | $terms |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | |
449 | 449 | $term_slugs[] = 'thing'; |
450 | 450 | |
451 | - return $this->get_custom_fields_by_term_slugs( $term_slugs ); |
|
451 | + return $this->get_custom_fields_by_term_slugs($term_slugs); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
@@ -459,12 +459,12 @@ discard block |
||
459 | 459 | * @return array An array of custom fields (see `custom_fields` in Wordlift_Schema_Service). |
460 | 460 | * @since 3.32.0 |
461 | 461 | */ |
462 | - public function get_custom_fields_for_term( $term_id ) { |
|
463 | - $selected_entity_types = get_term_meta( $term_id, 'wl_entity_type' ); |
|
462 | + public function get_custom_fields_for_term($term_id) { |
|
463 | + $selected_entity_types = get_term_meta($term_id, 'wl_entity_type'); |
|
464 | 464 | $selected_entity_types[] = 'thing'; |
465 | - $selected_entity_types = array_unique( $selected_entity_types ); |
|
465 | + $selected_entity_types = array_unique($selected_entity_types); |
|
466 | 466 | |
467 | - return $this->get_custom_fields_by_term_slugs( $selected_entity_types ); |
|
467 | + return $this->get_custom_fields_by_term_slugs($selected_entity_types); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /** |
@@ -478,9 +478,9 @@ discard block |
||
478 | 478 | * @return bool Return true if the post type can be used for entities, otherwise false. |
479 | 479 | * @since 3.15.0 |
480 | 480 | */ |
481 | - public static function is_valid_entity_post_type( $post_type ) { |
|
481 | + public static function is_valid_entity_post_type($post_type) { |
|
482 | 482 | |
483 | - return in_array( $post_type, Wordlift_Entity_Service::valid_entity_post_types(), true ); |
|
483 | + return in_array($post_type, Wordlift_Entity_Service::valid_entity_post_types(), true); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
@@ -488,16 +488,16 @@ discard block |
||
488 | 488 | * |
489 | 489 | * @return array |
490 | 490 | */ |
491 | - private function get_custom_fields_by_term_slugs( $term_slugs ) { |
|
491 | + private function get_custom_fields_by_term_slugs($term_slugs) { |
|
492 | 492 | $schema_service = Wordlift_Schema_Service::get_instance(); |
493 | 493 | |
494 | 494 | return array_reduce( |
495 | 495 | $term_slugs, |
496 | - function ( $carry, $item ) use ( $schema_service ) { |
|
496 | + function($carry, $item) use ($schema_service) { |
|
497 | 497 | |
498 | - $schema = $schema_service->get_schema( $item ); |
|
498 | + $schema = $schema_service->get_schema($item); |
|
499 | 499 | |
500 | - if ( ! isset( $schema['custom_fields'] ) ) { |
|
500 | + if ( ! isset($schema['custom_fields'])) { |
|
501 | 501 | return $carry; |
502 | 502 | } |
503 | 503 |