Completed
Push — develop ( f11ef2...d41b65 )
by David
06:01 queued 11s
created
src/wordlift/images-licenses/class-image-license-scheduler.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -14,50 +14,50 @@
 block discarded – undo
14 14
 
15 15
 class Image_License_Scheduler {
16 16
 
17
-	const ACTION_NAME = 'wl_image_license_scheduler__run';
17
+    const ACTION_NAME = 'wl_image_license_scheduler__run';
18 18
 
19
-	/**
20
-	 * @var Image_License_Service
21
-	 */
22
-	private $image_license_service;
23
-	/**
24
-	 * @var Ttl_Cache
25
-	 */
26
-	private $cache_service;
19
+    /**
20
+     * @var Image_License_Service
21
+     */
22
+    private $image_license_service;
23
+    /**
24
+     * @var Ttl_Cache
25
+     */
26
+    private $cache_service;
27 27
 
28
-	/**
29
-	 * @param Image_License_Service $image_license_service
30
-	 * @param Ttl_Cache $cache_service
31
-	 */
32
-	public function __construct( $image_license_service, $cache_service ) {
28
+    /**
29
+     * @param Image_License_Service $image_license_service
30
+     * @param Ttl_Cache $cache_service
31
+     */
32
+    public function __construct( $image_license_service, $cache_service ) {
33 33
 
34
-		$this->image_license_service = $image_license_service;
35
-		$this->cache_service         = $cache_service;
34
+        $this->image_license_service = $image_license_service;
35
+        $this->cache_service         = $cache_service;
36 36
 
37
-		// Do not bother to configure scheduled tasks while running on the front-end.
38
-		add_action( 'wp_ajax_' . self::ACTION_NAME, array( $this, 'run' ) );
39
-		add_action( self::ACTION_NAME, array( $this, 'run' ) );
37
+        // Do not bother to configure scheduled tasks while running on the front-end.
38
+        add_action( 'wp_ajax_' . self::ACTION_NAME, array( $this, 'run' ) );
39
+        add_action( self::ACTION_NAME, array( $this, 'run' ) );
40 40
 
41
-		if ( is_admin() && ! wp_next_scheduled( self::ACTION_NAME ) ) {
42
-			wp_schedule_event( time(), 'weekly', self::ACTION_NAME );
43
-		}
41
+        if ( is_admin() && ! wp_next_scheduled( self::ACTION_NAME ) ) {
42
+            wp_schedule_event( time(), 'weekly', self::ACTION_NAME );
43
+        }
44 44
 
45
-	}
45
+    }
46 46
 
47
-	public function run() {
47
+    public function run() {
48 48
 
49
-		// Get and save the domains.
50
-		$data = $this->image_license_service->get_non_public_domain_images();
49
+        // Get and save the domains.
50
+        $data = $this->image_license_service->get_non_public_domain_images();
51 51
 
52
-		// Update the cache.
53
-		$this->cache_service->put( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES, $data );
52
+        // Update the cache.
53
+        $this->cache_service->put( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES, $data );
54 54
 
55
-		if ( apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ) &&
56
-		     ( self::ACTION_NAME === filter_input( INPUT_GET, 'action' )
57
-		       || self::ACTION_NAME === filter_input( INPUT_POST, 'action' ) ) ) {
58
-			wp_send_json_success( $data );
59
-		}
55
+        if ( apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ) &&
56
+             ( self::ACTION_NAME === filter_input( INPUT_GET, 'action' )
57
+               || self::ACTION_NAME === filter_input( INPUT_POST, 'action' ) ) ) {
58
+            wp_send_json_success( $data );
59
+        }
60 60
 
61
-	}
61
+    }
62 62
 
63 63
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -29,17 +29,17 @@  discard block
 block discarded – undo
29 29
 	 * @param Image_License_Service $image_license_service
30 30
 	 * @param Ttl_Cache $cache_service
31 31
 	 */
32
-	public function __construct( $image_license_service, $cache_service ) {
32
+	public function __construct($image_license_service, $cache_service) {
33 33
 
34 34
 		$this->image_license_service = $image_license_service;
35 35
 		$this->cache_service         = $cache_service;
36 36
 
37 37
 		// Do not bother to configure scheduled tasks while running on the front-end.
38
-		add_action( 'wp_ajax_' . self::ACTION_NAME, array( $this, 'run' ) );
39
-		add_action( self::ACTION_NAME, array( $this, 'run' ) );
38
+		add_action('wp_ajax_'.self::ACTION_NAME, array($this, 'run'));
39
+		add_action(self::ACTION_NAME, array($this, 'run'));
40 40
 
41
-		if ( is_admin() && ! wp_next_scheduled( self::ACTION_NAME ) ) {
42
-			wp_schedule_event( time(), 'weekly', self::ACTION_NAME );
41
+		if (is_admin() && ! wp_next_scheduled(self::ACTION_NAME)) {
42
+			wp_schedule_event(time(), 'weekly', self::ACTION_NAME);
43 43
 		}
44 44
 
45 45
 	}
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
 		$data = $this->image_license_service->get_non_public_domain_images();
51 51
 
52 52
 		// Update the cache.
53
-		$this->cache_service->put( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES, $data );
53
+		$this->cache_service->put(Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES, $data);
54 54
 
55
-		if ( apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ) &&
56
-		     ( self::ACTION_NAME === filter_input( INPUT_GET, 'action' )
57
-		       || self::ACTION_NAME === filter_input( INPUT_POST, 'action' ) ) ) {
58
-			wp_send_json_success( $data );
55
+		if (apply_filters('wp_doing_ajax', defined('DOING_AJAX') && DOING_AJAX) &&
56
+		     (self::ACTION_NAME === filter_input(INPUT_GET, 'action')
57
+		       || self::ACTION_NAME === filter_input(INPUT_POST, 'action'))) {
58
+			wp_send_json_success($data);
59 59
 		}
60 60
 
61 61
 	}
Please login to merge, or discard this patch.
src/shortcodes/wordlift_shortcode_faceted_search.php 2 patches
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -18,30 +18,30 @@  discard block
 block discarded – undo
18 18
  */
19 19
 function wl_shortcode_faceted_search( $request ) {
20 20
 
21
-	// Create the cache key.
22
-	$cache_key = array(
23
-		'request_params' => $_GET,
24
-	);
21
+    // Create the cache key.
22
+    $cache_key = array(
23
+        'request_params' => $_GET,
24
+    );
25 25
 
26
-	// Create the TTL cache and try to get the results.
27
-	$cache         = new Ttl_Cache( "faceted-search", 8 * 60 * 60 ); // 8 hours.
28
-	$cache_results = $cache->get( $cache_key );
26
+    // Create the TTL cache and try to get the results.
27
+    $cache         = new Ttl_Cache( "faceted-search", 8 * 60 * 60 ); // 8 hours.
28
+    $cache_results = $cache->get( $cache_key );
29 29
 
30
-	if ( isset( $cache_results ) ) {
31
-		header( 'X-WordLift-Cache: HIT' );
32
-		wl_core_send_json( $cache_results );
30
+    if ( isset( $cache_results ) ) {
31
+        header( 'X-WordLift-Cache: HIT' );
32
+        wl_core_send_json( $cache_results );
33 33
 
34
-		return;
35
-	}
34
+        return;
35
+    }
36 36
 
37
-	header( 'X-WordLift-Cache: MISS' );
37
+    header( 'X-WordLift-Cache: MISS' );
38 38
 
39
-	$results = wl_shortcode_faceted_search_origin( $request );
39
+    $results = wl_shortcode_faceted_search_origin( $request );
40 40
 
41
-	// Put the result before sending the json to the client, since sending the json will terminate us.
42
-	$cache->put( $cache_key, $results );
41
+    // Put the result before sending the json to the client, since sending the json will terminate us.
42
+    $cache->put( $cache_key, $results );
43 43
 
44
-	wl_core_send_json( $results );
44
+    wl_core_send_json( $results );
45 45
 
46 46
 }
47 47
 
@@ -52,134 +52,134 @@  discard block
 block discarded – undo
52 52
  * @since        3.26.0
53 53
  */
54 54
 function wl_shortcode_faceted_search_origin( $request ) {
55
-	// Post ID must be defined.
56
-	if ( ! isset( $_GET['post_id'] ) ) { // WPCS: input var ok; CSRF ok.
57
-		wp_die( 'No post_id given' );
58
-
59
-		return;
60
-	}
61
-
62
-	$current_post_id = $_GET['post_id']; // WPCS: input var ok; CSRF ok.
63
-	$current_post    = get_post( $current_post_id );
64
-
65
-	// Post ID has to match an existing item.
66
-	if ( null === $current_post ) {
67
-		wp_die( 'No valid post_id given' );
68
-
69
-		return;
70
-	}
71
-
72
-	// If the current post is an entity,
73
-	// the current post is used as main entity.
74
-	// Otherwise, current post related entities are used.
75
-	$entity_service = Wordlift_Entity_Service::get_instance();
76
-	$entity_ids     = $entity_service->is_entity( $current_post->ID ) ?
77
-		array( $current_post->ID ) :
78
-		$entity_service->get_related_entities( $current_post->ID );
79
-
80
-	// If there are no entities we cannot render the widget.
81
-	if ( 0 === count( $entity_ids ) ) {
82
-		/**
83
-		 * If this function is not called from ajax
84
-		 * then this should not throw an error.
85
-		 * Note: Used in scripbox longtail project on json endpoint.
86
-		 */
87
-		if ( apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
88
-			wp_die( 'No entities available' );
89
-		}
90
-
91
-	}
92
-
93
-	$limit = ( isset( $_GET['limit'] ) ) ? (int) $_GET['limit'] : 4;  // WPCS: input var ok; CSRF ok.
94
-	$amp   = ( isset( $_GET['amp'] ) ) ? true : false;
95
-
96
-
97
-	/**
98
-	 * see https://github.com/insideout10/wordlift-plugin/issues/1181
99
-	 * The ordering should be descending by date on default.
100
-	 */
101
-	$order_by = 'DESC';
102
-	if ( isset( $_GET['sort'] ) && is_string( $_GET['sort'] ) ) {
103
-		$order_by = (string) $_GET['sort'];
104
-	}
105
-
106
-	$referencing_posts = Wordlift_Relation_Service::get_instance()->get_article_subjects(
107
-		$entity_ids,
108
-		'*',
109
-		null,
110
-		'publish',
111
-		array( $current_post_id ),
112
-		$limit,
113
-		null,
114
-		$order_by
115
-	);
116
-
117
-	$referencing_post_ids = array_map( function ( $p ) {
118
-		return $p->ID;
119
-	}, $referencing_posts );
120
-
121
-	$post_results   = array();
122
-	$entity_results = array();
123
-
124
-	// Populate $post_results
125
-
126
-	$filtered_posts = ( empty( $filtering_entity_uris ) ) ?
127
-		$referencing_posts :
128
-		Wordlift_Relation_Service::get_instance()->get_article_subjects(
129
-			wl_get_entity_post_ids_by_uris( $filtering_entity_uris ),
130
-			'*',
131
-			null,
132
-			null,
133
-			array(),
134
-			null,
135
-			$referencing_post_ids
136
-		);
137
-
138
-	if ( $filtered_posts ) {
139
-		foreach ( $filtered_posts as $post_obj ) {
140
-
141
-			/**
142
-			 * Use the thumbnail.
143
-			 *
144
-			 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
145
-			 * @see https://github.com/insideout10/wordlift-plugin/issues/837
146
-			 *
147
-			 * @since 3.19.3 We're using the medium size image.
148
-			 */
149
-			$thumbnail           = get_the_post_thumbnail_url( $post_obj, 'medium' );
150
-			$post_obj->thumbnail = ( $thumbnail ) ?
151
-				$thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
152
-			$post_obj->permalink = get_permalink( $post_obj->ID );
153
-
154
-			$result         = $post_obj;
155
-			$post_results[] = $result;
156
-		}
157
-	}
158
-
159
-	// Add filler posts if needed
160
-
161
-	$filler_count         = $limit - count( $post_results );
162
-	$filler_posts         = wl_shortcode_faceted_search_filler_posts( $filler_count, $current_post_id, $referencing_post_ids );
163
-	$post_results         = array_merge( $post_results, $filler_posts );
164
-	$referencing_post_ids = array_map( function ( $post ) {
165
-		return $post->ID;
166
-	}, $post_results );
167
-
168
-	// Populate $entity_results
169
-
170
-	global $wpdb;
171
-
172
-	// Retrieve Wordlift relation instances table name.
173
-	$table_name = wl_core_get_relation_instances_table_name();
174
-
175
-	/*
55
+    // Post ID must be defined.
56
+    if ( ! isset( $_GET['post_id'] ) ) { // WPCS: input var ok; CSRF ok.
57
+        wp_die( 'No post_id given' );
58
+
59
+        return;
60
+    }
61
+
62
+    $current_post_id = $_GET['post_id']; // WPCS: input var ok; CSRF ok.
63
+    $current_post    = get_post( $current_post_id );
64
+
65
+    // Post ID has to match an existing item.
66
+    if ( null === $current_post ) {
67
+        wp_die( 'No valid post_id given' );
68
+
69
+        return;
70
+    }
71
+
72
+    // If the current post is an entity,
73
+    // the current post is used as main entity.
74
+    // Otherwise, current post related entities are used.
75
+    $entity_service = Wordlift_Entity_Service::get_instance();
76
+    $entity_ids     = $entity_service->is_entity( $current_post->ID ) ?
77
+        array( $current_post->ID ) :
78
+        $entity_service->get_related_entities( $current_post->ID );
79
+
80
+    // If there are no entities we cannot render the widget.
81
+    if ( 0 === count( $entity_ids ) ) {
82
+        /**
83
+         * If this function is not called from ajax
84
+         * then this should not throw an error.
85
+         * Note: Used in scripbox longtail project on json endpoint.
86
+         */
87
+        if ( apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
88
+            wp_die( 'No entities available' );
89
+        }
90
+
91
+    }
92
+
93
+    $limit = ( isset( $_GET['limit'] ) ) ? (int) $_GET['limit'] : 4;  // WPCS: input var ok; CSRF ok.
94
+    $amp   = ( isset( $_GET['amp'] ) ) ? true : false;
95
+
96
+
97
+    /**
98
+     * see https://github.com/insideout10/wordlift-plugin/issues/1181
99
+     * The ordering should be descending by date on default.
100
+     */
101
+    $order_by = 'DESC';
102
+    if ( isset( $_GET['sort'] ) && is_string( $_GET['sort'] ) ) {
103
+        $order_by = (string) $_GET['sort'];
104
+    }
105
+
106
+    $referencing_posts = Wordlift_Relation_Service::get_instance()->get_article_subjects(
107
+        $entity_ids,
108
+        '*',
109
+        null,
110
+        'publish',
111
+        array( $current_post_id ),
112
+        $limit,
113
+        null,
114
+        $order_by
115
+    );
116
+
117
+    $referencing_post_ids = array_map( function ( $p ) {
118
+        return $p->ID;
119
+    }, $referencing_posts );
120
+
121
+    $post_results   = array();
122
+    $entity_results = array();
123
+
124
+    // Populate $post_results
125
+
126
+    $filtered_posts = ( empty( $filtering_entity_uris ) ) ?
127
+        $referencing_posts :
128
+        Wordlift_Relation_Service::get_instance()->get_article_subjects(
129
+            wl_get_entity_post_ids_by_uris( $filtering_entity_uris ),
130
+            '*',
131
+            null,
132
+            null,
133
+            array(),
134
+            null,
135
+            $referencing_post_ids
136
+        );
137
+
138
+    if ( $filtered_posts ) {
139
+        foreach ( $filtered_posts as $post_obj ) {
140
+
141
+            /**
142
+             * Use the thumbnail.
143
+             *
144
+             * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
145
+             * @see https://github.com/insideout10/wordlift-plugin/issues/837
146
+             *
147
+             * @since 3.19.3 We're using the medium size image.
148
+             */
149
+            $thumbnail           = get_the_post_thumbnail_url( $post_obj, 'medium' );
150
+            $post_obj->thumbnail = ( $thumbnail ) ?
151
+                $thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
152
+            $post_obj->permalink = get_permalink( $post_obj->ID );
153
+
154
+            $result         = $post_obj;
155
+            $post_results[] = $result;
156
+        }
157
+    }
158
+
159
+    // Add filler posts if needed
160
+
161
+    $filler_count         = $limit - count( $post_results );
162
+    $filler_posts         = wl_shortcode_faceted_search_filler_posts( $filler_count, $current_post_id, $referencing_post_ids );
163
+    $post_results         = array_merge( $post_results, $filler_posts );
164
+    $referencing_post_ids = array_map( function ( $post ) {
165
+        return $post->ID;
166
+    }, $post_results );
167
+
168
+    // Populate $entity_results
169
+
170
+    global $wpdb;
171
+
172
+    // Retrieve Wordlift relation instances table name.
173
+    $table_name = wl_core_get_relation_instances_table_name();
174
+
175
+    /*
176 176
 	 * Make sure we have some referenced post, otherwise the IN parts of
177 177
 	 * the SQL will produce an SQL error.
178 178
 	 */
179
-	if ( ! empty( $referencing_post_ids ) ) {
180
-		$subject_ids = implode( ',', $referencing_post_ids );
179
+    if ( ! empty( $referencing_post_ids ) ) {
180
+        $subject_ids = implode( ',', $referencing_post_ids );
181 181
 
182
-		$query = "
182
+        $query = "
183 183
 				SELECT
184 184
 					object_id AS ID,
185 185
 					count( object_id ) AS counter
@@ -191,116 +191,116 @@  discard block
 block discarded – undo
191 191
 				LIMIT $limit;
192 192
 			";
193 193
 
194
-		wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" );
194
+        wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" );
195 195
 
196
-		$entities = $wpdb->get_results( $query, OBJECT ); // No cache ok.
196
+        $entities = $wpdb->get_results( $query, OBJECT ); // No cache ok.
197 197
 
198
-		wl_write_log( 'Entities found ' . count( $entities ) );
198
+        wl_write_log( 'Entities found ' . count( $entities ) );
199 199
 
200
-		foreach ( $entities as $obj ) {
200
+        foreach ( $entities as $obj ) {
201 201
 
202
-			$entity = get_post( $obj->ID );
202
+            $entity = get_post( $obj->ID );
203 203
 
204
-			// Ensure only valid and published entities are returned.
205
-			if ( ( null !== $entity ) && ( 'publish' === $entity->post_status ) ) {
204
+            // Ensure only valid and published entities are returned.
205
+            if ( ( null !== $entity ) && ( 'publish' === $entity->post_status ) ) {
206 206
 
207
-				$serialized_entity                    = wl_serialize_entity( $entity );
208
-				$serialized_entity['label']           = wl_shortcode_faceted_search_get_the_title( $obj->ID );
209
-				$serialized_entity['counter']         = $obj->counter;
210
-				$serialized_entity['createdAt']       = $entity->post_date;
211
-				$serialized_entity['referencedPosts'] = Wordlift_Relation_Service::get_instance()->get_article_subjects(
212
-					$obj->ID,
213
-					'ids',
214
-					null,
215
-					null,
216
-					array(),
217
-					null,
218
-					$referencing_post_ids
219
-				);
220
-				$entity_results[]                     = $serialized_entity;
221
-			}
222
-		}
223
-	}
207
+                $serialized_entity                    = wl_serialize_entity( $entity );
208
+                $serialized_entity['label']           = wl_shortcode_faceted_search_get_the_title( $obj->ID );
209
+                $serialized_entity['counter']         = $obj->counter;
210
+                $serialized_entity['createdAt']       = $entity->post_date;
211
+                $serialized_entity['referencedPosts'] = Wordlift_Relation_Service::get_instance()->get_article_subjects(
212
+                    $obj->ID,
213
+                    'ids',
214
+                    null,
215
+                    null,
216
+                    array(),
217
+                    null,
218
+                    $referencing_post_ids
219
+                );
220
+                $entity_results[]                     = $serialized_entity;
221
+            }
222
+        }
223
+    }
224 224
 
225
-	return array(
226
-		'posts'    => $amp ? array( array( 'values' => $post_results ) ) : $post_results,
227
-		'entities' => $entity_results
228
-	);
225
+    return array(
226
+        'posts'    => $amp ? array( array( 'values' => $post_results ) ) : $post_results,
227
+        'entities' => $entity_results
228
+    );
229 229
 
230 230
 }
231 231
 
232 232
 function wl_shortcode_faceted_search_get_the_title( $post_id ) {
233 233
 
234
-	$title = get_the_title( $post_id );
234
+    $title = get_the_title( $post_id );
235 235
 
236
-	if ( get_post_type( $post_id ) !== Wordlift_Entity_Service::TYPE_NAME ) {
237
-		$alternative_labels = Wordlift_Entity_Service::get_instance()->get_alternative_labels( $post_id );
236
+    if ( get_post_type( $post_id ) !== Wordlift_Entity_Service::TYPE_NAME ) {
237
+        $alternative_labels = Wordlift_Entity_Service::get_instance()->get_alternative_labels( $post_id );
238 238
 
239
-		if ( count( $alternative_labels ) > 0 ) {
240
-			$title = $alternative_labels[0];
241
-		}
242
-	}
239
+        if ( count( $alternative_labels ) > 0 ) {
240
+            $title = $alternative_labels[0];
241
+        }
242
+    }
243 243
 
244
-	return remove_accents( $title );
244
+    return remove_accents( $title );
245 245
 
246 246
 }
247 247
 
248 248
 function wl_shortcode_faceted_search_filler_posts( $filler_count, $current_post_id, $referencing_post_ids ) {
249 249
 
250
-	$filler_posts = array();
251
-
252
-	// First add latest posts from same categories as the current post
253
-	if ( $filler_count > 0 ) {
254
-
255
-		$current_post_categories = wp_get_post_categories( $current_post_id );
256
-
257
-		$args = array(
258
-			'meta_query'          => array(
259
-				array(
260
-					'key' => '_thumbnail_id'
261
-				)
262
-			),
263
-			'category__in'        => $current_post_categories,
264
-			'numberposts'         => $filler_count,
265
-			'post__not_in'        => array_merge( array( $current_post_id ), $referencing_post_ids ),
266
-			'ignore_sticky_posts' => 1
267
-		);
268
-
269
-		$filler_posts = get_posts( $args );
270
-	}
271
-
272
-	$filler_count    = $filler_count - count( $filler_posts );
273
-	$filler_post_ids = array_map( function ( $post ) {
274
-		return $post->ID;
275
-	}, $filler_posts );
276
-
277
-	// If that does not fill, add latest posts irrespective of category
278
-	if ( $filler_count > 0 ) {
279
-
280
-		$args = array(
281
-			'meta_query'          => array(
282
-				array(
283
-					'key' => '_thumbnail_id'
284
-				)
285
-			),
286
-			'numberposts'         => $filler_count,
287
-			'post__not_in'        => array_merge( array( $current_post_id ), $referencing_post_ids, $filler_post_ids ),
288
-			'ignore_sticky_posts' => 1
289
-		);
290
-
291
-		$filler_posts = array_merge( $filler_posts, get_posts( $args ) );
292
-
293
-	}
294
-
295
-	// Add thumbnail and permalink to filler posts
296
-	foreach ( $filler_posts as $post_obj ) {
297
-		$thumbnail           = get_the_post_thumbnail_url( $post_obj, 'medium' );
298
-		$post_obj->thumbnail = ( $thumbnail ) ?
299
-			$thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
300
-		$post_obj->permalink = get_permalink( $post_obj->ID );
301
-	}
302
-
303
-	return $filler_posts;
250
+    $filler_posts = array();
251
+
252
+    // First add latest posts from same categories as the current post
253
+    if ( $filler_count > 0 ) {
254
+
255
+        $current_post_categories = wp_get_post_categories( $current_post_id );
256
+
257
+        $args = array(
258
+            'meta_query'          => array(
259
+                array(
260
+                    'key' => '_thumbnail_id'
261
+                )
262
+            ),
263
+            'category__in'        => $current_post_categories,
264
+            'numberposts'         => $filler_count,
265
+            'post__not_in'        => array_merge( array( $current_post_id ), $referencing_post_ids ),
266
+            'ignore_sticky_posts' => 1
267
+        );
268
+
269
+        $filler_posts = get_posts( $args );
270
+    }
271
+
272
+    $filler_count    = $filler_count - count( $filler_posts );
273
+    $filler_post_ids = array_map( function ( $post ) {
274
+        return $post->ID;
275
+    }, $filler_posts );
276
+
277
+    // If that does not fill, add latest posts irrespective of category
278
+    if ( $filler_count > 0 ) {
279
+
280
+        $args = array(
281
+            'meta_query'          => array(
282
+                array(
283
+                    'key' => '_thumbnail_id'
284
+                )
285
+            ),
286
+            'numberposts'         => $filler_count,
287
+            'post__not_in'        => array_merge( array( $current_post_id ), $referencing_post_ids, $filler_post_ids ),
288
+            'ignore_sticky_posts' => 1
289
+        );
290
+
291
+        $filler_posts = array_merge( $filler_posts, get_posts( $args ) );
292
+
293
+    }
294
+
295
+    // Add thumbnail and permalink to filler posts
296
+    foreach ( $filler_posts as $post_obj ) {
297
+        $thumbnail           = get_the_post_thumbnail_url( $post_obj, 'medium' );
298
+        $post_obj->thumbnail = ( $thumbnail ) ?
299
+            $thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
300
+        $post_obj->permalink = get_permalink( $post_obj->ID );
301
+    }
302
+
303
+    return $filler_posts;
304 304
 
305 305
 }
306 306
 
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
  * Adding `rest_api_init` action for network faceted-search
309 309
  */
310 310
 add_action( 'rest_api_init', function () {
311
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/faceted-search', array(
312
-		'methods'  => 'GET',
313
-		'callback' => 'wl_shortcode_faceted_search',
314
-	) );
311
+    register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/faceted-search', array(
312
+        'methods'  => 'GET',
313
+        'callback' => 'wl_shortcode_faceted_search',
314
+    ) );
315 315
 } );
Please login to merge, or discard this patch.
Spacing   +76 added lines, -78 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @since 3.21.4 fix the cache key by also using the request body.
17 17
  * @since 3.21.2 add a caching layer.
18 18
  */
19
-function wl_shortcode_faceted_search( $request ) {
19
+function wl_shortcode_faceted_search($request) {
20 20
 
21 21
 	// Create the cache key.
22 22
 	$cache_key = array(
@@ -24,24 +24,24 @@  discard block
 block discarded – undo
24 24
 	);
25 25
 
26 26
 	// Create the TTL cache and try to get the results.
27
-	$cache         = new Ttl_Cache( "faceted-search", 8 * 60 * 60 ); // 8 hours.
28
-	$cache_results = $cache->get( $cache_key );
27
+	$cache         = new Ttl_Cache("faceted-search", 8 * 60 * 60); // 8 hours.
28
+	$cache_results = $cache->get($cache_key);
29 29
 
30
-	if ( isset( $cache_results ) ) {
31
-		header( 'X-WordLift-Cache: HIT' );
32
-		wl_core_send_json( $cache_results );
30
+	if (isset($cache_results)) {
31
+		header('X-WordLift-Cache: HIT');
32
+		wl_core_send_json($cache_results);
33 33
 
34 34
 		return;
35 35
 	}
36 36
 
37
-	header( 'X-WordLift-Cache: MISS' );
37
+	header('X-WordLift-Cache: MISS');
38 38
 
39
-	$results = wl_shortcode_faceted_search_origin( $request );
39
+	$results = wl_shortcode_faceted_search_origin($request);
40 40
 
41 41
 	// Put the result before sending the json to the client, since sending the json will terminate us.
42
-	$cache->put( $cache_key, $results );
42
+	$cache->put($cache_key, $results);
43 43
 
44
-	wl_core_send_json( $results );
44
+	wl_core_send_json($results);
45 45
 
46 46
 }
47 47
 
@@ -51,20 +51,20 @@  discard block
 block discarded – undo
51 51
  * @return array $results
52 52
  * @since        3.26.0
53 53
  */
54
-function wl_shortcode_faceted_search_origin( $request ) {
54
+function wl_shortcode_faceted_search_origin($request) {
55 55
 	// Post ID must be defined.
56
-	if ( ! isset( $_GET['post_id'] ) ) { // WPCS: input var ok; CSRF ok.
57
-		wp_die( 'No post_id given' );
56
+	if ( ! isset($_GET['post_id'])) { // WPCS: input var ok; CSRF ok.
57
+		wp_die('No post_id given');
58 58
 
59 59
 		return;
60 60
 	}
61 61
 
62 62
 	$current_post_id = $_GET['post_id']; // WPCS: input var ok; CSRF ok.
63
-	$current_post    = get_post( $current_post_id );
63
+	$current_post    = get_post($current_post_id);
64 64
 
65 65
 	// Post ID has to match an existing item.
66
-	if ( null === $current_post ) {
67
-		wp_die( 'No valid post_id given' );
66
+	if (null === $current_post) {
67
+		wp_die('No valid post_id given');
68 68
 
69 69
 		return;
70 70
 	}
@@ -73,25 +73,24 @@  discard block
 block discarded – undo
73 73
 	// the current post is used as main entity.
74 74
 	// Otherwise, current post related entities are used.
75 75
 	$entity_service = Wordlift_Entity_Service::get_instance();
76
-	$entity_ids     = $entity_service->is_entity( $current_post->ID ) ?
77
-		array( $current_post->ID ) :
78
-		$entity_service->get_related_entities( $current_post->ID );
76
+	$entity_ids     = $entity_service->is_entity($current_post->ID) ?
77
+		array($current_post->ID) : $entity_service->get_related_entities($current_post->ID);
79 78
 
80 79
 	// If there are no entities we cannot render the widget.
81
-	if ( 0 === count( $entity_ids ) ) {
80
+	if (0 === count($entity_ids)) {
82 81
 		/**
83 82
 		 * If this function is not called from ajax
84 83
 		 * then this should not throw an error.
85 84
 		 * Note: Used in scripbox longtail project on json endpoint.
86 85
 		 */
87
-		if ( apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
88
-			wp_die( 'No entities available' );
86
+		if (apply_filters('wp_doing_ajax', defined('DOING_AJAX') && DOING_AJAX)) {
87
+			wp_die('No entities available');
89 88
 		}
90 89
 
91 90
 	}
92 91
 
93
-	$limit = ( isset( $_GET['limit'] ) ) ? (int) $_GET['limit'] : 4;  // WPCS: input var ok; CSRF ok.
94
-	$amp   = ( isset( $_GET['amp'] ) ) ? true : false;
92
+	$limit = (isset($_GET['limit'])) ? (int) $_GET['limit'] : 4; // WPCS: input var ok; CSRF ok.
93
+	$amp   = (isset($_GET['amp'])) ? true : false;
95 94
 
96 95
 
97 96
 	/**
@@ -99,7 +98,7 @@  discard block
 block discarded – undo
99 98
 	 * The ordering should be descending by date on default.
100 99
 	 */
101 100
 	$order_by = 'DESC';
102
-	if ( isset( $_GET['sort'] ) && is_string( $_GET['sort'] ) ) {
101
+	if (isset($_GET['sort']) && is_string($_GET['sort'])) {
103 102
 		$order_by = (string) $_GET['sort'];
104 103
 	}
105 104
 
@@ -108,25 +107,24 @@  discard block
 block discarded – undo
108 107
 		'*',
109 108
 		null,
110 109
 		'publish',
111
-		array( $current_post_id ),
110
+		array($current_post_id),
112 111
 		$limit,
113 112
 		null,
114 113
 		$order_by
115 114
 	);
116 115
 
117
-	$referencing_post_ids = array_map( function ( $p ) {
116
+	$referencing_post_ids = array_map(function($p) {
118 117
 		return $p->ID;
119
-	}, $referencing_posts );
118
+	}, $referencing_posts);
120 119
 
121 120
 	$post_results   = array();
122 121
 	$entity_results = array();
123 122
 
124 123
 	// Populate $post_results
125 124
 
126
-	$filtered_posts = ( empty( $filtering_entity_uris ) ) ?
127
-		$referencing_posts :
128
-		Wordlift_Relation_Service::get_instance()->get_article_subjects(
129
-			wl_get_entity_post_ids_by_uris( $filtering_entity_uris ),
125
+	$filtered_posts = (empty($filtering_entity_uris)) ?
126
+		$referencing_posts : Wordlift_Relation_Service::get_instance()->get_article_subjects(
127
+			wl_get_entity_post_ids_by_uris($filtering_entity_uris),
130 128
 			'*',
131 129
 			null,
132 130
 			null,
@@ -135,8 +133,8 @@  discard block
 block discarded – undo
135 133
 			$referencing_post_ids
136 134
 		);
137 135
 
138
-	if ( $filtered_posts ) {
139
-		foreach ( $filtered_posts as $post_obj ) {
136
+	if ($filtered_posts) {
137
+		foreach ($filtered_posts as $post_obj) {
140 138
 
141 139
 			/**
142 140
 			 * Use the thumbnail.
@@ -146,10 +144,10 @@  discard block
 block discarded – undo
146 144
 			 *
147 145
 			 * @since 3.19.3 We're using the medium size image.
148 146
 			 */
149
-			$thumbnail           = get_the_post_thumbnail_url( $post_obj, 'medium' );
150
-			$post_obj->thumbnail = ( $thumbnail ) ?
147
+			$thumbnail           = get_the_post_thumbnail_url($post_obj, 'medium');
148
+			$post_obj->thumbnail = ($thumbnail) ?
151 149
 				$thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
152
-			$post_obj->permalink = get_permalink( $post_obj->ID );
150
+			$post_obj->permalink = get_permalink($post_obj->ID);
153 151
 
154 152
 			$result         = $post_obj;
155 153
 			$post_results[] = $result;
@@ -158,12 +156,12 @@  discard block
 block discarded – undo
158 156
 
159 157
 	// Add filler posts if needed
160 158
 
161
-	$filler_count         = $limit - count( $post_results );
162
-	$filler_posts         = wl_shortcode_faceted_search_filler_posts( $filler_count, $current_post_id, $referencing_post_ids );
163
-	$post_results         = array_merge( $post_results, $filler_posts );
164
-	$referencing_post_ids = array_map( function ( $post ) {
159
+	$filler_count         = $limit - count($post_results);
160
+	$filler_posts         = wl_shortcode_faceted_search_filler_posts($filler_count, $current_post_id, $referencing_post_ids);
161
+	$post_results         = array_merge($post_results, $filler_posts);
162
+	$referencing_post_ids = array_map(function($post) {
165 163
 		return $post->ID;
166
-	}, $post_results );
164
+	}, $post_results);
167 165
 
168 166
 	// Populate $entity_results
169 167
 
@@ -176,8 +174,8 @@  discard block
 block discarded – undo
176 174
 	 * Make sure we have some referenced post, otherwise the IN parts of
177 175
 	 * the SQL will produce an SQL error.
178 176
 	 */
179
-	if ( ! empty( $referencing_post_ids ) ) {
180
-		$subject_ids = implode( ',', $referencing_post_ids );
177
+	if ( ! empty($referencing_post_ids)) {
178
+		$subject_ids = implode(',', $referencing_post_ids);
181 179
 
182 180
 		$query = "
183 181
 				SELECT
@@ -191,21 +189,21 @@  discard block
 block discarded – undo
191 189
 				LIMIT $limit;
192 190
 			";
193 191
 
194
-		wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" );
192
+		wl_write_log("Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]");
195 193
 
196
-		$entities = $wpdb->get_results( $query, OBJECT ); // No cache ok.
194
+		$entities = $wpdb->get_results($query, OBJECT); // No cache ok.
197 195
 
198
-		wl_write_log( 'Entities found ' . count( $entities ) );
196
+		wl_write_log('Entities found '.count($entities));
199 197
 
200
-		foreach ( $entities as $obj ) {
198
+		foreach ($entities as $obj) {
201 199
 
202
-			$entity = get_post( $obj->ID );
200
+			$entity = get_post($obj->ID);
203 201
 
204 202
 			// Ensure only valid and published entities are returned.
205
-			if ( ( null !== $entity ) && ( 'publish' === $entity->post_status ) ) {
203
+			if ((null !== $entity) && ('publish' === $entity->post_status)) {
206 204
 
207
-				$serialized_entity                    = wl_serialize_entity( $entity );
208
-				$serialized_entity['label']           = wl_shortcode_faceted_search_get_the_title( $obj->ID );
205
+				$serialized_entity                    = wl_serialize_entity($entity);
206
+				$serialized_entity['label']           = wl_shortcode_faceted_search_get_the_title($obj->ID);
209 207
 				$serialized_entity['counter']         = $obj->counter;
210 208
 				$serialized_entity['createdAt']       = $entity->post_date;
211 209
 				$serialized_entity['referencedPosts'] = Wordlift_Relation_Service::get_instance()->get_article_subjects(
@@ -217,42 +215,42 @@  discard block
 block discarded – undo
217 215
 					null,
218 216
 					$referencing_post_ids
219 217
 				);
220
-				$entity_results[]                     = $serialized_entity;
218
+				$entity_results[] = $serialized_entity;
221 219
 			}
222 220
 		}
223 221
 	}
224 222
 
225 223
 	return array(
226
-		'posts'    => $amp ? array( array( 'values' => $post_results ) ) : $post_results,
224
+		'posts'    => $amp ? array(array('values' => $post_results)) : $post_results,
227 225
 		'entities' => $entity_results
228 226
 	);
229 227
 
230 228
 }
231 229
 
232
-function wl_shortcode_faceted_search_get_the_title( $post_id ) {
230
+function wl_shortcode_faceted_search_get_the_title($post_id) {
233 231
 
234
-	$title = get_the_title( $post_id );
232
+	$title = get_the_title($post_id);
235 233
 
236
-	if ( get_post_type( $post_id ) !== Wordlift_Entity_Service::TYPE_NAME ) {
237
-		$alternative_labels = Wordlift_Entity_Service::get_instance()->get_alternative_labels( $post_id );
234
+	if (get_post_type($post_id) !== Wordlift_Entity_Service::TYPE_NAME) {
235
+		$alternative_labels = Wordlift_Entity_Service::get_instance()->get_alternative_labels($post_id);
238 236
 
239
-		if ( count( $alternative_labels ) > 0 ) {
237
+		if (count($alternative_labels) > 0) {
240 238
 			$title = $alternative_labels[0];
241 239
 		}
242 240
 	}
243 241
 
244
-	return remove_accents( $title );
242
+	return remove_accents($title);
245 243
 
246 244
 }
247 245
 
248
-function wl_shortcode_faceted_search_filler_posts( $filler_count, $current_post_id, $referencing_post_ids ) {
246
+function wl_shortcode_faceted_search_filler_posts($filler_count, $current_post_id, $referencing_post_ids) {
249 247
 
250 248
 	$filler_posts = array();
251 249
 
252 250
 	// First add latest posts from same categories as the current post
253
-	if ( $filler_count > 0 ) {
251
+	if ($filler_count > 0) {
254 252
 
255
-		$current_post_categories = wp_get_post_categories( $current_post_id );
253
+		$current_post_categories = wp_get_post_categories($current_post_id);
256 254
 
257 255
 		$args = array(
258 256
 			'meta_query'          => array(
@@ -262,20 +260,20 @@  discard block
 block discarded – undo
262 260
 			),
263 261
 			'category__in'        => $current_post_categories,
264 262
 			'numberposts'         => $filler_count,
265
-			'post__not_in'        => array_merge( array( $current_post_id ), $referencing_post_ids ),
263
+			'post__not_in'        => array_merge(array($current_post_id), $referencing_post_ids),
266 264
 			'ignore_sticky_posts' => 1
267 265
 		);
268 266
 
269
-		$filler_posts = get_posts( $args );
267
+		$filler_posts = get_posts($args);
270 268
 	}
271 269
 
272
-	$filler_count    = $filler_count - count( $filler_posts );
273
-	$filler_post_ids = array_map( function ( $post ) {
270
+	$filler_count    = $filler_count - count($filler_posts);
271
+	$filler_post_ids = array_map(function($post) {
274 272
 		return $post->ID;
275
-	}, $filler_posts );
273
+	}, $filler_posts);
276 274
 
277 275
 	// If that does not fill, add latest posts irrespective of category
278
-	if ( $filler_count > 0 ) {
276
+	if ($filler_count > 0) {
279 277
 
280 278
 		$args = array(
281 279
 			'meta_query'          => array(
@@ -284,20 +282,20 @@  discard block
 block discarded – undo
284 282
 				)
285 283
 			),
286 284
 			'numberposts'         => $filler_count,
287
-			'post__not_in'        => array_merge( array( $current_post_id ), $referencing_post_ids, $filler_post_ids ),
285
+			'post__not_in'        => array_merge(array($current_post_id), $referencing_post_ids, $filler_post_ids),
288 286
 			'ignore_sticky_posts' => 1
289 287
 		);
290 288
 
291
-		$filler_posts = array_merge( $filler_posts, get_posts( $args ) );
289
+		$filler_posts = array_merge($filler_posts, get_posts($args));
292 290
 
293 291
 	}
294 292
 
295 293
 	// Add thumbnail and permalink to filler posts
296
-	foreach ( $filler_posts as $post_obj ) {
297
-		$thumbnail           = get_the_post_thumbnail_url( $post_obj, 'medium' );
298
-		$post_obj->thumbnail = ( $thumbnail ) ?
294
+	foreach ($filler_posts as $post_obj) {
295
+		$thumbnail           = get_the_post_thumbnail_url($post_obj, 'medium');
296
+		$post_obj->thumbnail = ($thumbnail) ?
299 297
 			$thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
300
-		$post_obj->permalink = get_permalink( $post_obj->ID );
298
+		$post_obj->permalink = get_permalink($post_obj->ID);
301 299
 	}
302 300
 
303 301
 	return $filler_posts;
@@ -307,9 +305,9 @@  discard block
 block discarded – undo
307 305
 /**
308 306
  * Adding `rest_api_init` action for network faceted-search
309 307
  */
310
-add_action( 'rest_api_init', function () {
311
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/faceted-search', array(
308
+add_action('rest_api_init', function() {
309
+	register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/faceted-search', array(
312 310
 		'methods'  => 'GET',
313 311
 		'callback' => 'wl_shortcode_faceted_search',
314
-	) );
312
+	));
315 313
 } );
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-setup.php 2 patches
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  */
14 14
 
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -28,140 +28,140 @@  discard block
 block discarded – undo
28 28
  */
29 29
 class Wordlift_Admin_Setup {
30 30
 
31
-	/**
32
-	 * A {@link Wordlift_Configuration_Service} instance.
33
-	 *
34
-	 * @since  3.9.0
35
-	 * @access private
36
-	 * @var Wordlift_Configuration_Service A {@link Wordlift_Configuration_Service} instance.
37
-	 */
38
-	private $configuration_service;
39
-
40
-	/**
41
-	 * A {@link Wordlift_Key_Validation_Service} instance.
42
-	 *
43
-	 * @since  3.9.0
44
-	 * @access private
45
-	 * @var Wordlift_Key_Validation_Service A {@link Wordlift_Key_Validation_Service} instance.
46
-	 */
47
-	private $key_validation_service;
48
-
49
-	/**
50
-	 * A {@link Wordlift_Entity_Service} instance.
51
-	 *
52
-	 * @since  3.9.0
53
-	 * @access private
54
-	 * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
55
-	 */
56
-	private $entity_service;
57
-
58
-	/**
59
-	 * A {@link Wordlift_Admin_Language_Select_Element} element renderer.
60
-	 *
61
-	 * @since  3.20.0
62
-	 * @access private
63
-	 * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
64
-	 */
65
-	private $language_select_element;
66
-
67
-	/**
68
-	 * A {@link Wordlift_Admin_Country_Select_Element} element renderer.
69
-	 *
70
-	 * @since  3.20.0
71
-	 * @access private
72
-	 * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer.
73
-	 */
74
-	private $country_select_element;
75
-
76
-	/**
77
-	 * Initialize the class and set its properties.
78
-	 *
79
-	 * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
80
-	 * @param \Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance.
81
-	 * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
82
-	 * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
83
-	 * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer.
84
-	 *
85
-	 * @since    3.9.0
86
-	 *
87
-	 */
88
-	public function __construct( $configuration_service, $key_validation_service, $entity_service, $language_select_element, $country_select_element ) {
89
-
90
-		// Set a reference to the configuration service.
91
-		$this->configuration_service = $configuration_service;
92
-
93
-		// Set a reference to the key validation service.
94
-		$this->key_validation_service = $key_validation_service;
95
-
96
-		// Set a reference to the entity service.
97
-		$this->entity_service = $entity_service;
98
-
99
-		// Set a reference to the UI elements language and country.
100
-		$this->language_select_element = $language_select_element;
101
-		$this->country_select_element  = $country_select_element;
102
-
103
-		// Hook to some WP's events:
104
-		// When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up.
105
-		add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
106
-
107
-		// Hook to `admin_menu` in order to add our own setup wizard page.
108
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
109
-
110
-		// Triggered when the user accesses the admin area, we decide whether to show our own wizard.
111
-		add_action( 'admin_init', array( $this, 'show_page' ) );
112
-
113
-		/**
114
-		 * Filter: wl_feature__enable__notices.
115
-		 *
116
-		 * @param bool whether the notices needs to be enabled or not.
117
-		 *
118
-		 * @return bool
119
-		 * @since 3.27.6
120
-		 */
121
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
122
-			// Hook to `admin_notices` to display our notices.
123
-			add_action( 'admin_notices', array( $this, 'admin_notices' ) );
124
-		}
125
-	}
126
-
127
-	/**
128
-	 * Hook to `admin_init` and redirect to WordLift's setup page if the `_wl_activation_redirect` transient flag is set.
129
-	 *
130
-	 * @since 3.9.0
131
-	 */
132
-	public function admin_init() {
133
-
134
-		// If the `_wl_activation_redirect` is set, the redirect to the setup page.
135
-		if ( get_transient( '_wl_activation_redirect' ) ) {
136
-			delete_transient( '_wl_activation_redirect' );
137
-
138
-			// If the user asked to skip the wizard then comply.
139
-			if ( $this->configuration_service->is_skip_wizard() ) {
140
-				return;
141
-			}
142
-
143
-			// If we're already on the page or the user doesn't have permissions, return.
144
-			if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) {
145
-				return;
146
-			}
147
-
148
-			// Finally redirect to the setup page.
149
-			wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) );
150
-
151
-			exit;
152
-		}
153
-
154
-	}
155
-
156
-	/**
157
-	 * Generate an admin notice suggesting to start the wizard if there is no configuration.
158
-	 *
159
-	 * @since    3.9.0
160
-	 */
161
-	public function admin_notices() {
162
-
163
-		// Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard.
164
-		if ( '' === $this->configuration_service->get_key() && ! $this->configuration_service->is_skip_wizard() ) { ?>
31
+    /**
32
+     * A {@link Wordlift_Configuration_Service} instance.
33
+     *
34
+     * @since  3.9.0
35
+     * @access private
36
+     * @var Wordlift_Configuration_Service A {@link Wordlift_Configuration_Service} instance.
37
+     */
38
+    private $configuration_service;
39
+
40
+    /**
41
+     * A {@link Wordlift_Key_Validation_Service} instance.
42
+     *
43
+     * @since  3.9.0
44
+     * @access private
45
+     * @var Wordlift_Key_Validation_Service A {@link Wordlift_Key_Validation_Service} instance.
46
+     */
47
+    private $key_validation_service;
48
+
49
+    /**
50
+     * A {@link Wordlift_Entity_Service} instance.
51
+     *
52
+     * @since  3.9.0
53
+     * @access private
54
+     * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
55
+     */
56
+    private $entity_service;
57
+
58
+    /**
59
+     * A {@link Wordlift_Admin_Language_Select_Element} element renderer.
60
+     *
61
+     * @since  3.20.0
62
+     * @access private
63
+     * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
64
+     */
65
+    private $language_select_element;
66
+
67
+    /**
68
+     * A {@link Wordlift_Admin_Country_Select_Element} element renderer.
69
+     *
70
+     * @since  3.20.0
71
+     * @access private
72
+     * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer.
73
+     */
74
+    private $country_select_element;
75
+
76
+    /**
77
+     * Initialize the class and set its properties.
78
+     *
79
+     * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
80
+     * @param \Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance.
81
+     * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
82
+     * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
83
+     * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer.
84
+     *
85
+     * @since    3.9.0
86
+     *
87
+     */
88
+    public function __construct( $configuration_service, $key_validation_service, $entity_service, $language_select_element, $country_select_element ) {
89
+
90
+        // Set a reference to the configuration service.
91
+        $this->configuration_service = $configuration_service;
92
+
93
+        // Set a reference to the key validation service.
94
+        $this->key_validation_service = $key_validation_service;
95
+
96
+        // Set a reference to the entity service.
97
+        $this->entity_service = $entity_service;
98
+
99
+        // Set a reference to the UI elements language and country.
100
+        $this->language_select_element = $language_select_element;
101
+        $this->country_select_element  = $country_select_element;
102
+
103
+        // Hook to some WP's events:
104
+        // When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up.
105
+        add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
106
+
107
+        // Hook to `admin_menu` in order to add our own setup wizard page.
108
+        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
109
+
110
+        // Triggered when the user accesses the admin area, we decide whether to show our own wizard.
111
+        add_action( 'admin_init', array( $this, 'show_page' ) );
112
+
113
+        /**
114
+         * Filter: wl_feature__enable__notices.
115
+         *
116
+         * @param bool whether the notices needs to be enabled or not.
117
+         *
118
+         * @return bool
119
+         * @since 3.27.6
120
+         */
121
+        if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
122
+            // Hook to `admin_notices` to display our notices.
123
+            add_action( 'admin_notices', array( $this, 'admin_notices' ) );
124
+        }
125
+    }
126
+
127
+    /**
128
+     * Hook to `admin_init` and redirect to WordLift's setup page if the `_wl_activation_redirect` transient flag is set.
129
+     *
130
+     * @since 3.9.0
131
+     */
132
+    public function admin_init() {
133
+
134
+        // If the `_wl_activation_redirect` is set, the redirect to the setup page.
135
+        if ( get_transient( '_wl_activation_redirect' ) ) {
136
+            delete_transient( '_wl_activation_redirect' );
137
+
138
+            // If the user asked to skip the wizard then comply.
139
+            if ( $this->configuration_service->is_skip_wizard() ) {
140
+                return;
141
+            }
142
+
143
+            // If we're already on the page or the user doesn't have permissions, return.
144
+            if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) {
145
+                return;
146
+            }
147
+
148
+            // Finally redirect to the setup page.
149
+            wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) );
150
+
151
+            exit;
152
+        }
153
+
154
+    }
155
+
156
+    /**
157
+     * Generate an admin notice suggesting to start the wizard if there is no configuration.
158
+     *
159
+     * @since    3.9.0
160
+     */
161
+    public function admin_notices() {
162
+
163
+        // Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard.
164
+        if ( '' === $this->configuration_service->get_key() && ! $this->configuration_service->is_skip_wizard() ) { ?>
165 165
             <div id="wl-message" class="updated">
166 166
                 <p><?php esc_html_e( 'Welcome to WordLift &#8211; You&lsquo;re almost ready to start', 'wordlift' ); ?></p>
167 167
                 <p class="submit">
@@ -173,144 +173,144 @@  discard block
 block discarded – undo
173 173
             </div>
174 174
 		<?php }
175 175
 
176
-	}
177
-
178
-	/**
179
-	 * Handle hiding the wizard notices by user request.
180
-	 *
181
-	 * @since    3.9.0
182
-	 */
183
-	public function hide_notices() {
184
-
185
-		// If it's not a `wl-hide-notice` or the nonce is not set, return.
186
-		if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) {
187
-			return;
188
-		}
189
-
190
-		// If the nonce is invalid, return an error.
191
-		if ( ! wp_verify_nonce( $_GET['_wl_notice_nonce'], 'wordlift_hide_notices_nonce' ) ) {
192
-			wp_die( __( 'Action failed. Please refresh the page and retry.', 'wordlift' ) );
193
-		}
194
-
195
-		// If the user doesn't have the right privileges, return an error.
196
-		if ( ! current_user_can( 'manage_options' ) ) {
197
-			wp_die( __( 'Cheatin&#8217; huh?', 'wordlift' ) );
198
-		}
199
-
200
-		// Store a flag telling to skip the wizard.
201
-		$this->configuration_service->set_skip_wizard( true );
202
-
203
-	}
204
-
205
-	/**
206
-	 * Register the wizard page to be able to access it.
207
-	 *
208
-	 * @since    3.9.0
209
-	 */
210
-	public function admin_menu() {
211
-		/**
212
-		 * Filter: wl_feature__enable__screens.
213
-		 *
214
-		 * @param bool whether the screens needed to be registered, defaults to true.
215
-		 *
216
-		 * @return bool
217
-		 * @since 3.27.6
218
-		 */
219
-		if ( apply_filters( 'wl_feature__enable__screens', true ) ) {
220
-			// @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu.
221
-			add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' );
222
-		}
223
-	}
224
-
225
-	/**
226
-	 * Displays the wizard page.
227
-	 *
228
-	 * @since    3.9.0
229
-	 */
230
-	public function show_page() {
231
-
232
-		// First check if we are in the wizard page at all, if not do nothing.
233
-		if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) {
234
-			return;
235
-		}
236
-
237
-		// If it's a POST and the `wl-save-configuration` action is set, save the configuration.
238
-		if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) {
239
-
240
-			// Check the nonce and the user capabilities.
241
-			check_admin_referer( 'wl-save-configuration' );
242
-
243
-			// Check if the user has the right privileges.
244
-			if ( ! current_user_can( 'manage_options' ) ) {
245
-				wp_die( __( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) );
246
-			}
247
-
248
-			// Save the configuration.
249
-			$this->save_configuration( $_POST );
250
-
251
-			// Redirect to the admin's page.
252
-			wp_redirect( admin_url() );
253
-
254
-			exit;
255
-		}
256
-
257
-		$language_select = $this->language_select_element;
258
-		$country_select  = $this->country_select_element;
259
-
260
-		include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-setup.php';
261
-
262
-		exit;
263
-	}
264
-
265
-	/**
266
-	 * Save WordLift's configuration using the provided parameters.
267
-	 *
268
-	 * @param array $params An array of configuration parameters.
269
-	 *
270
-	 * @since 3.9.0
271
-	 *
272
-	 */
273
-	private function save_configuration( $params ) {
274
-
275
-		// We have the following parameters:
276
-		// `key`, holding WL's key,
277
-		// `vocabulary`, holding the vocabulary path,
278
-		// `language`, with the language code (e.g. `en`),
279
-		// `send_diagnostic`, the user preferences about sharing data with us.
280
-		// `user_type`, the user type either `personal` or `company`,
281
-		// `name`, with the `personal` or `company`'s name,
282
-		// `logo`, the attachment id for the `personal` or `company` entity.
283
-
284
-		// Store the key:
285
-		$this->configuration_service->set_key( $params['key'] );
286
-
287
-		// Store the vocabulary path:
288
-		$this->configuration_service->set_entity_base_path( $params['vocabulary'] );
289
-
290
-		// Store the site's language:
291
-		$this->configuration_service->set_language_code( $params['wl-site-language'] );
292
-
293
-		// Store the site's country:
294
-		$this->configuration_service->set_country_code( $params['wl-country-code'] );
295
-
296
-		// Store the preferences in variable, because if the checkbox is not checked
297
-		// the `share-diagnostic` will not exists in `$params` array.
298
-		$share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes';
299
-
300
-		// Store the diagnostic preferences:
301
-		$this->configuration_service->set_diagnostic_preferences( $share_diagnostic_preferences );
302
-
303
-		// Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
304
-		$type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' );
305
-
306
-		// Create an entity for the publisher.
307
-		$publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' );
308
-
309
-		// Store the publisher entity post id in the configuration.
310
-		$this->configuration_service->set_publisher_id( $publisher_post_id );
311
-
312
-		flush_rewrite_rules(); // Needed because of possible change to the entity base path.
313
-
314
-	}
176
+    }
177
+
178
+    /**
179
+     * Handle hiding the wizard notices by user request.
180
+     *
181
+     * @since    3.9.0
182
+     */
183
+    public function hide_notices() {
184
+
185
+        // If it's not a `wl-hide-notice` or the nonce is not set, return.
186
+        if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) {
187
+            return;
188
+        }
189
+
190
+        // If the nonce is invalid, return an error.
191
+        if ( ! wp_verify_nonce( $_GET['_wl_notice_nonce'], 'wordlift_hide_notices_nonce' ) ) {
192
+            wp_die( __( 'Action failed. Please refresh the page and retry.', 'wordlift' ) );
193
+        }
194
+
195
+        // If the user doesn't have the right privileges, return an error.
196
+        if ( ! current_user_can( 'manage_options' ) ) {
197
+            wp_die( __( 'Cheatin&#8217; huh?', 'wordlift' ) );
198
+        }
199
+
200
+        // Store a flag telling to skip the wizard.
201
+        $this->configuration_service->set_skip_wizard( true );
202
+
203
+    }
204
+
205
+    /**
206
+     * Register the wizard page to be able to access it.
207
+     *
208
+     * @since    3.9.0
209
+     */
210
+    public function admin_menu() {
211
+        /**
212
+         * Filter: wl_feature__enable__screens.
213
+         *
214
+         * @param bool whether the screens needed to be registered, defaults to true.
215
+         *
216
+         * @return bool
217
+         * @since 3.27.6
218
+         */
219
+        if ( apply_filters( 'wl_feature__enable__screens', true ) ) {
220
+            // @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu.
221
+            add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' );
222
+        }
223
+    }
224
+
225
+    /**
226
+     * Displays the wizard page.
227
+     *
228
+     * @since    3.9.0
229
+     */
230
+    public function show_page() {
231
+
232
+        // First check if we are in the wizard page at all, if not do nothing.
233
+        if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) {
234
+            return;
235
+        }
236
+
237
+        // If it's a POST and the `wl-save-configuration` action is set, save the configuration.
238
+        if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) {
239
+
240
+            // Check the nonce and the user capabilities.
241
+            check_admin_referer( 'wl-save-configuration' );
242
+
243
+            // Check if the user has the right privileges.
244
+            if ( ! current_user_can( 'manage_options' ) ) {
245
+                wp_die( __( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) );
246
+            }
247
+
248
+            // Save the configuration.
249
+            $this->save_configuration( $_POST );
250
+
251
+            // Redirect to the admin's page.
252
+            wp_redirect( admin_url() );
253
+
254
+            exit;
255
+        }
256
+
257
+        $language_select = $this->language_select_element;
258
+        $country_select  = $this->country_select_element;
259
+
260
+        include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-setup.php';
261
+
262
+        exit;
263
+    }
264
+
265
+    /**
266
+     * Save WordLift's configuration using the provided parameters.
267
+     *
268
+     * @param array $params An array of configuration parameters.
269
+     *
270
+     * @since 3.9.0
271
+     *
272
+     */
273
+    private function save_configuration( $params ) {
274
+
275
+        // We have the following parameters:
276
+        // `key`, holding WL's key,
277
+        // `vocabulary`, holding the vocabulary path,
278
+        // `language`, with the language code (e.g. `en`),
279
+        // `send_diagnostic`, the user preferences about sharing data with us.
280
+        // `user_type`, the user type either `personal` or `company`,
281
+        // `name`, with the `personal` or `company`'s name,
282
+        // `logo`, the attachment id for the `personal` or `company` entity.
283
+
284
+        // Store the key:
285
+        $this->configuration_service->set_key( $params['key'] );
286
+
287
+        // Store the vocabulary path:
288
+        $this->configuration_service->set_entity_base_path( $params['vocabulary'] );
289
+
290
+        // Store the site's language:
291
+        $this->configuration_service->set_language_code( $params['wl-site-language'] );
292
+
293
+        // Store the site's country:
294
+        $this->configuration_service->set_country_code( $params['wl-country-code'] );
295
+
296
+        // Store the preferences in variable, because if the checkbox is not checked
297
+        // the `share-diagnostic` will not exists in `$params` array.
298
+        $share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes';
299
+
300
+        // Store the diagnostic preferences:
301
+        $this->configuration_service->set_diagnostic_preferences( $share_diagnostic_preferences );
302
+
303
+        // Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
304
+        $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' );
305
+
306
+        // Create an entity for the publisher.
307
+        $publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' );
308
+
309
+        // Store the publisher entity post id in the configuration.
310
+        $this->configuration_service->set_publisher_id( $publisher_post_id );
311
+
312
+        flush_rewrite_rules(); // Needed because of possible change to the entity base path.
313
+
314
+    }
315 315
 
316 316
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @since      3.9.0
13 13
  */
14 14
 
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 * @since    3.9.0
86 86
 	 *
87 87
 	 */
88
-	public function __construct( $configuration_service, $key_validation_service, $entity_service, $language_select_element, $country_select_element ) {
88
+	public function __construct($configuration_service, $key_validation_service, $entity_service, $language_select_element, $country_select_element) {
89 89
 
90 90
 		// Set a reference to the configuration service.
91 91
 		$this->configuration_service = $configuration_service;
@@ -102,13 +102,13 @@  discard block
 block discarded – undo
102 102
 
103 103
 		// Hook to some WP's events:
104 104
 		// When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up.
105
-		add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
105
+		add_action('wp_loaded', array($this, 'hide_notices'));
106 106
 
107 107
 		// Hook to `admin_menu` in order to add our own setup wizard page.
108
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
108
+		add_action('admin_menu', array($this, 'admin_menu'));
109 109
 
110 110
 		// Triggered when the user accesses the admin area, we decide whether to show our own wizard.
111
-		add_action( 'admin_init', array( $this, 'show_page' ) );
111
+		add_action('admin_init', array($this, 'show_page'));
112 112
 
113 113
 		/**
114 114
 		 * Filter: wl_feature__enable__notices.
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
 		 * @return bool
119 119
 		 * @since 3.27.6
120 120
 		 */
121
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
121
+		if (apply_filters('wl_feature__enable__notices', true)) {
122 122
 			// Hook to `admin_notices` to display our notices.
123
-			add_action( 'admin_notices', array( $this, 'admin_notices' ) );
123
+			add_action('admin_notices', array($this, 'admin_notices'));
124 124
 		}
125 125
 	}
126 126
 
@@ -132,21 +132,21 @@  discard block
 block discarded – undo
132 132
 	public function admin_init() {
133 133
 
134 134
 		// If the `_wl_activation_redirect` is set, the redirect to the setup page.
135
-		if ( get_transient( '_wl_activation_redirect' ) ) {
136
-			delete_transient( '_wl_activation_redirect' );
135
+		if (get_transient('_wl_activation_redirect')) {
136
+			delete_transient('_wl_activation_redirect');
137 137
 
138 138
 			// If the user asked to skip the wizard then comply.
139
-			if ( $this->configuration_service->is_skip_wizard() ) {
139
+			if ($this->configuration_service->is_skip_wizard()) {
140 140
 				return;
141 141
 			}
142 142
 
143 143
 			// If we're already on the page or the user doesn't have permissions, return.
144
-			if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) {
144
+			if (( ! empty($_GET['page']) && 'wl-setup' === $_GET['page']) || is_network_admin() || isset($_GET['activate-multi']) || ! current_user_can('manage_options')) {
145 145
 				return;
146 146
 			}
147 147
 
148 148
 			// Finally redirect to the setup page.
149
-			wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) );
149
+			wp_safe_redirect(admin_url('index.php?page=wl-setup'));
150 150
 
151 151
 			exit;
152 152
 		}
@@ -161,14 +161,14 @@  discard block
 block discarded – undo
161 161
 	public function admin_notices() {
162 162
 
163 163
 		// Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard.
164
-		if ( '' === $this->configuration_service->get_key() && ! $this->configuration_service->is_skip_wizard() ) { ?>
164
+		if ('' === $this->configuration_service->get_key() && ! $this->configuration_service->is_skip_wizard()) { ?>
165 165
             <div id="wl-message" class="updated">
166
-                <p><?php esc_html_e( 'Welcome to WordLift &#8211; You&lsquo;re almost ready to start', 'wordlift' ); ?></p>
166
+                <p><?php esc_html_e('Welcome to WordLift &#8211; You&lsquo;re almost ready to start', 'wordlift'); ?></p>
167 167
                 <p class="submit">
168
-                    <a href="<?php echo esc_url( admin_url( 'admin.php?page=wl-setup' ) ); ?>"
169
-                       class="button-primary"><?php esc_html_e( 'Run the Setup Wizard', 'wordlift' ); ?></a>
168
+                    <a href="<?php echo esc_url(admin_url('admin.php?page=wl-setup')); ?>"
169
+                       class="button-primary"><?php esc_html_e('Run the Setup Wizard', 'wordlift'); ?></a>
170 170
                     <a class="button-secondary skip"
171
-                       href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wl-hide-notice', 'install' ), 'wordlift_hide_notices_nonce', '_wl_notice_nonce' ) ); ?>"><?php esc_html_e( 'Skip Setup', 'wordlift' ); ?></a>
171
+                       href="<?php echo esc_url(wp_nonce_url(add_query_arg('wl-hide-notice', 'install'), 'wordlift_hide_notices_nonce', '_wl_notice_nonce')); ?>"><?php esc_html_e('Skip Setup', 'wordlift'); ?></a>
172 172
                 </p>
173 173
             </div>
174 174
 		<?php }
@@ -183,22 +183,22 @@  discard block
 block discarded – undo
183 183
 	public function hide_notices() {
184 184
 
185 185
 		// If it's not a `wl-hide-notice` or the nonce is not set, return.
186
-		if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) {
186
+		if ( ! isset($_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'])) {
187 187
 			return;
188 188
 		}
189 189
 
190 190
 		// If the nonce is invalid, return an error.
191
-		if ( ! wp_verify_nonce( $_GET['_wl_notice_nonce'], 'wordlift_hide_notices_nonce' ) ) {
192
-			wp_die( __( 'Action failed. Please refresh the page and retry.', 'wordlift' ) );
191
+		if ( ! wp_verify_nonce($_GET['_wl_notice_nonce'], 'wordlift_hide_notices_nonce')) {
192
+			wp_die(__('Action failed. Please refresh the page and retry.', 'wordlift'));
193 193
 		}
194 194
 
195 195
 		// If the user doesn't have the right privileges, return an error.
196
-		if ( ! current_user_can( 'manage_options' ) ) {
197
-			wp_die( __( 'Cheatin&#8217; huh?', 'wordlift' ) );
196
+		if ( ! current_user_can('manage_options')) {
197
+			wp_die(__('Cheatin&#8217; huh?', 'wordlift'));
198 198
 		}
199 199
 
200 200
 		// Store a flag telling to skip the wizard.
201
-		$this->configuration_service->set_skip_wizard( true );
201
+		$this->configuration_service->set_skip_wizard(true);
202 202
 
203 203
 	}
204 204
 
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 		 * @return bool
217 217
 		 * @since 3.27.6
218 218
 		 */
219
-		if ( apply_filters( 'wl_feature__enable__screens', true ) ) {
219
+		if (apply_filters('wl_feature__enable__screens', true)) {
220 220
 			// @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu.
221
-			add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' );
221
+			add_dashboard_page('', '', 'manage_options', 'wl-setup', '');
222 222
 		}
223 223
 	}
224 224
 
@@ -230,26 +230,26 @@  discard block
 block discarded – undo
230 230
 	public function show_page() {
231 231
 
232 232
 		// First check if we are in the wizard page at all, if not do nothing.
233
-		if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) {
233
+		if (empty($_GET['page']) || 'wl-setup' !== $_GET['page']) {
234 234
 			return;
235 235
 		}
236 236
 
237 237
 		// If it's a POST and the `wl-save-configuration` action is set, save the configuration.
238
-		if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) {
238
+		if (isset($_POST['action']) && 'wl-save-configuration' === $_POST['action']) {
239 239
 
240 240
 			// Check the nonce and the user capabilities.
241
-			check_admin_referer( 'wl-save-configuration' );
241
+			check_admin_referer('wl-save-configuration');
242 242
 
243 243
 			// Check if the user has the right privileges.
244
-			if ( ! current_user_can( 'manage_options' ) ) {
245
-				wp_die( __( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) );
244
+			if ( ! current_user_can('manage_options')) {
245
+				wp_die(__('Sorry, you do not have a permission to save the settings', 'wordlift'));
246 246
 			}
247 247
 
248 248
 			// Save the configuration.
249
-			$this->save_configuration( $_POST );
249
+			$this->save_configuration($_POST);
250 250
 
251 251
 			// Redirect to the admin's page.
252
-			wp_redirect( admin_url() );
252
+			wp_redirect(admin_url());
253 253
 
254 254
 			exit;
255 255
 		}
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 		$language_select = $this->language_select_element;
258 258
 		$country_select  = $this->country_select_element;
259 259
 
260
-		include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-setup.php';
260
+		include plugin_dir_path(dirname(__FILE__)).'admin/partials/wordlift-admin-setup.php';
261 261
 
262 262
 		exit;
263 263
 	}
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	 * @since 3.9.0
271 271
 	 *
272 272
 	 */
273
-	private function save_configuration( $params ) {
273
+	private function save_configuration($params) {
274 274
 
275 275
 		// We have the following parameters:
276 276
 		// `key`, holding WL's key,
@@ -282,32 +282,32 @@  discard block
 block discarded – undo
282 282
 		// `logo`, the attachment id for the `personal` or `company` entity.
283 283
 
284 284
 		// Store the key:
285
-		$this->configuration_service->set_key( $params['key'] );
285
+		$this->configuration_service->set_key($params['key']);
286 286
 
287 287
 		// Store the vocabulary path:
288
-		$this->configuration_service->set_entity_base_path( $params['vocabulary'] );
288
+		$this->configuration_service->set_entity_base_path($params['vocabulary']);
289 289
 
290 290
 		// Store the site's language:
291
-		$this->configuration_service->set_language_code( $params['wl-site-language'] );
291
+		$this->configuration_service->set_language_code($params['wl-site-language']);
292 292
 
293 293
 		// Store the site's country:
294
-		$this->configuration_service->set_country_code( $params['wl-country-code'] );
294
+		$this->configuration_service->set_country_code($params['wl-country-code']);
295 295
 
296 296
 		// Store the preferences in variable, because if the checkbox is not checked
297 297
 		// the `share-diagnostic` will not exists in `$params` array.
298
-		$share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes';
298
+		$share_diagnostic_preferences = empty($params['share-diagnostic']) ? 'no' : 'yes';
299 299
 
300 300
 		// Store the diagnostic preferences:
301
-		$this->configuration_service->set_diagnostic_preferences( $share_diagnostic_preferences );
301
+		$this->configuration_service->set_diagnostic_preferences($share_diagnostic_preferences);
302 302
 
303 303
 		// Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
304
-		$type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' );
304
+		$type_uri = sprintf('http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person');
305 305
 
306 306
 		// Create an entity for the publisher.
307
-		$publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' );
307
+		$publisher_post_id = $this->entity_service->create($params['name'], $type_uri, $params['logo'], 'publish');
308 308
 
309 309
 		// Store the publisher entity post id in the configuration.
310
-		$this->configuration_service->set_publisher_id( $publisher_post_id );
310
+		$this->configuration_service->set_publisher_id($publisher_post_id);
311 311
 
312 312
 		flush_rewrite_rules(); // Needed because of possible change to the entity base path.
313 313
 
Please login to merge, or discard this patch.
src/modules/analyzer/wordlift_analyzer.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -9,15 +9,15 @@  discard block
 block discarded – undo
9 9
  * @since 3.27.6
10 10
  */
11 11
 function wl_ajax_analyze_disabled_action() {
12
-	// adding the below header for debugging purpose.
13
-	if ( ! headers_sent() ) {
14
-		header( 'X-WordLift-Analysis: OFF' );
15
-	}
16
-	wp_send_json_success( array(
17
-		'entities'    => array(),
18
-		'annotations' => array(),
19
-		'topics'      => array()
20
-	) );
12
+    // adding the below header for debugging purpose.
13
+    if ( ! headers_sent() ) {
14
+        header( 'X-WordLift-Analysis: OFF' );
15
+    }
16
+    wp_send_json_success( array(
17
+        'entities'    => array(),
18
+        'annotations' => array(),
19
+        'topics'      => array()
20
+    ) );
21 21
 }
22 22
 
23 23
 /**
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
  */
32 32
 function wl_ajax_analyze_action() {
33 33
 
34
-	check_admin_referer( 'wl_analyze' );
34
+    check_admin_referer( 'wl_analyze' );
35 35
 
36
-	$data = filter_input( INPUT_POST, 'data' );
36
+    $data = filter_input( INPUT_POST, 'data' );
37 37
 
38
-	wp_send_json_success( wl_analyze_content( $data, 'application/json; charset=' . strtolower( get_bloginfo( 'charset' ) ) ) );
38
+    wp_send_json_success( wl_analyze_content( $data, 'application/json; charset=' . strtolower( get_bloginfo( 'charset' ) ) ) );
39 39
 
40 40
 }
41 41
 
@@ -57,59 +57,59 @@  discard block
 block discarded – undo
57 57
  */
58 58
 function wl_analyze_content( $data, $content_type ) {
59 59
 
60
-	$default_response = json_decode( '{ "entities": {}, "annotations": {}, "topics": {} }' );
61
-	$request_body = json_decode( $data, true );
60
+    $default_response = json_decode( '{ "entities": {}, "annotations": {}, "topics": {} }' );
61
+    $request_body = json_decode( $data, true );
62 62
 
63
-	// If dataset is not enabled, return a locally prepared response without analysis API.
64
-	if ( ! apply_filters( 'wl_features__enable__dataset', true ) ) {
63
+    // If dataset is not enabled, return a locally prepared response without analysis API.
64
+    if ( ! apply_filters( 'wl_features__enable__dataset', true ) ) {
65 65
 
66
-		return Analysis_Response_Ops_Factory::get_instance()
67
-		                                    ->create( $default_response )
68
-		                                    ->make_entities_local()
69
-		                                    ->add_occurrences( $request_body['content'] )
70
-		                                    ->add_local_entities()
71
-		                                    ->get_json();
72
-	}
66
+        return Analysis_Response_Ops_Factory::get_instance()
67
+                                            ->create( $default_response )
68
+                                            ->make_entities_local()
69
+                                            ->add_occurrences( $request_body['content'] )
70
+                                            ->add_local_entities()
71
+                                            ->get_json();
72
+    }
73 73
 
74
-	add_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' );
75
-	$json = Wordlift_Api_Service::get_instance()
76
-	                            ->post_custom_content_type( 'analysis/single', $data, $content_type );
77
-	remove_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' );
74
+    add_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' );
75
+    $json = Wordlift_Api_Service::get_instance()
76
+                                ->post_custom_content_type( 'analysis/single', $data, $content_type );
77
+    remove_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' );
78 78
 
79
-	// If it's an error log it.
80
-	if ( is_wp_error( $json ) ) {
79
+    // If it's an error log it.
80
+    if ( is_wp_error( $json ) ) {
81 81
 
82
-		return Analysis_Response_Ops_Factory::get_instance()
83
-		                                    ->create( $default_response )
84
-		                                    ->make_entities_local()
85
-		                                    ->add_occurrences( $request_body['content'] )
86
-		                                    ->get_json();
87
-	}
82
+        return Analysis_Response_Ops_Factory::get_instance()
83
+                                            ->create( $default_response )
84
+                                            ->make_entities_local()
85
+                                            ->add_occurrences( $request_body['content'] )
86
+                                            ->get_json();
87
+    }
88 88
 
89
-	/*
89
+    /*
90 90
 	 * We pass the response to the Analysis_Response_Ops to ensure that we make remote entities local.
91 91
 	 *
92 92
 	 * @see https://github.com/insideout10/wordlift-plugin/issues/944
93 93
 	 * @since 3.21.5
94 94
 	 */
95 95
 
96
-	// Get the actual content sent to the analysis, so that we can pass it to the Analysis_Response_Ops to populate
97
-	// the occurrences for the local entities.
98
-	if ( 0 === strpos( $content_type, 'application/json' ) ) {
99
-		$request_content = $request_body['content'];
100
-	} else {
101
-		$request_content = $data;
102
-	}
96
+    // Get the actual content sent to the analysis, so that we can pass it to the Analysis_Response_Ops to populate
97
+    // the occurrences for the local entities.
98
+    if ( 0 === strpos( $content_type, 'application/json' ) ) {
99
+        $request_content = $request_body['content'];
100
+    } else {
101
+        $request_content = $data;
102
+    }
103 103
 
104
-	return Analysis_Response_Ops_Factory::get_instance()
105
-	                                    ->create( $json )
106
-	                                    ->make_entities_local()
107
-	                                    ->add_occurrences( $request_content )
108
-	                                    ->get_json();
104
+    return Analysis_Response_Ops_Factory::get_instance()
105
+                                        ->create( $json )
106
+                                        ->make_entities_local()
107
+                                        ->add_occurrences( $request_content )
108
+                                        ->get_json();
109 109
 
110 110
 }
111 111
 
112 112
 function wl_use_analysis_on_api_wordlift_io( $value ) {
113 113
 
114
-	return preg_replace( '|https://api\.wordlift\.it/|', apply_filters( 'wl_api_base_url', 'https://api.wordlift.io' ) . '/', $value );
114
+    return preg_replace( '|https://api\.wordlift\.it/|', apply_filters( 'wl_api_base_url', 'https://api.wordlift.io' ) . '/', $value );
115 115
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -10,14 +10,14 @@  discard block
 block discarded – undo
10 10
  */
11 11
 function wl_ajax_analyze_disabled_action() {
12 12
 	// adding the below header for debugging purpose.
13
-	if ( ! headers_sent() ) {
14
-		header( 'X-WordLift-Analysis: OFF' );
13
+	if ( ! headers_sent()) {
14
+		header('X-WordLift-Analysis: OFF');
15 15
 	}
16
-	wp_send_json_success( array(
16
+	wp_send_json_success(array(
17 17
 		'entities'    => array(),
18 18
 		'annotations' => array(),
19 19
 		'topics'      => array()
20
-	) );
20
+	));
21 21
 }
22 22
 
23 23
 /**
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
  */
32 32
 function wl_ajax_analyze_action() {
33 33
 
34
-	check_admin_referer( 'wl_analyze' );
34
+	check_admin_referer('wl_analyze');
35 35
 
36
-	$data = filter_input( INPUT_POST, 'data' );
36
+	$data = filter_input(INPUT_POST, 'data');
37 37
 
38
-	wp_send_json_success( wl_analyze_content( $data, 'application/json; charset=' . strtolower( get_bloginfo( 'charset' ) ) ) );
38
+	wp_send_json_success(wl_analyze_content($data, 'application/json; charset='.strtolower(get_bloginfo('charset'))));
39 39
 
40 40
 }
41 41
 
@@ -55,34 +55,34 @@  discard block
 block discarded – undo
55 55
  * @since 3.24.2 We don't return an error anymore, but an empty analysis response. This is required to allow the editor
56 56
  *   to manage entities or to manually add them even when analysis isn't available.
57 57
  */
58
-function wl_analyze_content( $data, $content_type ) {
58
+function wl_analyze_content($data, $content_type) {
59 59
 
60
-	$default_response = json_decode( '{ "entities": {}, "annotations": {}, "topics": {} }' );
61
-	$request_body = json_decode( $data, true );
60
+	$default_response = json_decode('{ "entities": {}, "annotations": {}, "topics": {} }');
61
+	$request_body = json_decode($data, true);
62 62
 
63 63
 	// If dataset is not enabled, return a locally prepared response without analysis API.
64
-	if ( ! apply_filters( 'wl_features__enable__dataset', true ) ) {
64
+	if ( ! apply_filters('wl_features__enable__dataset', true)) {
65 65
 
66 66
 		return Analysis_Response_Ops_Factory::get_instance()
67
-		                                    ->create( $default_response )
67
+		                                    ->create($default_response)
68 68
 		                                    ->make_entities_local()
69
-		                                    ->add_occurrences( $request_body['content'] )
69
+		                                    ->add_occurrences($request_body['content'])
70 70
 		                                    ->add_local_entities()
71 71
 		                                    ->get_json();
72 72
 	}
73 73
 
74
-	add_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' );
74
+	add_filter('wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io');
75 75
 	$json = Wordlift_Api_Service::get_instance()
76
-	                            ->post_custom_content_type( 'analysis/single', $data, $content_type );
77
-	remove_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' );
76
+	                            ->post_custom_content_type('analysis/single', $data, $content_type);
77
+	remove_filter('wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io');
78 78
 
79 79
 	// If it's an error log it.
80
-	if ( is_wp_error( $json ) ) {
80
+	if (is_wp_error($json)) {
81 81
 
82 82
 		return Analysis_Response_Ops_Factory::get_instance()
83
-		                                    ->create( $default_response )
83
+		                                    ->create($default_response)
84 84
 		                                    ->make_entities_local()
85
-		                                    ->add_occurrences( $request_body['content'] )
85
+		                                    ->add_occurrences($request_body['content'])
86 86
 		                                    ->get_json();
87 87
 	}
88 88
 
@@ -95,21 +95,21 @@  discard block
 block discarded – undo
95 95
 
96 96
 	// Get the actual content sent to the analysis, so that we can pass it to the Analysis_Response_Ops to populate
97 97
 	// the occurrences for the local entities.
98
-	if ( 0 === strpos( $content_type, 'application/json' ) ) {
98
+	if (0 === strpos($content_type, 'application/json')) {
99 99
 		$request_content = $request_body['content'];
100 100
 	} else {
101 101
 		$request_content = $data;
102 102
 	}
103 103
 
104 104
 	return Analysis_Response_Ops_Factory::get_instance()
105
-	                                    ->create( $json )
105
+	                                    ->create($json)
106 106
 	                                    ->make_entities_local()
107
-	                                    ->add_occurrences( $request_content )
107
+	                                    ->add_occurrences($request_content)
108 108
 	                                    ->get_json();
109 109
 
110 110
 }
111 111
 
112
-function wl_use_analysis_on_api_wordlift_io( $value ) {
112
+function wl_use_analysis_on_api_wordlift_io($value) {
113 113
 
114
-	return preg_replace( '|https://api\.wordlift\.it/|', apply_filters( 'wl_api_base_url', 'https://api.wordlift.io' ) . '/', $value );
114
+	return preg_replace('|https://api\.wordlift\.it/|', apply_filters('wl_api_base_url', 'https://api.wordlift.io').'/', $value);
115 115
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-uri-service.php 2 patches
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -17,280 +17,280 @@
 block discarded – undo
17 17
  */
18 18
 class Wordlift_Entity_Uri_Service {
19 19
 
20
-	/**
21
-	 * Holds the {@link Wordlift_Entity_Uri_Service} instance.
22
-	 *
23
-	 * @since 3.21.5
24
-	 * @access private
25
-	 * @var Wordlift_Entity_Uri_Service $instance The {@link Wordlift_Entity_Uri_Service} singleton.
26
-	 */
27
-	private static $instance;
28
-
29
-	/**
30
-	 * A {@link Wordlift_Log_Service} instance.
31
-	 *
32
-	 * @since  3.16.3
33
-	 * @access private
34
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
35
-	 */
36
-	private $log;
37
-
38
-	/**
39
-	 * The {@link Wordlift_Configuration_Service} instance.
40
-	 *
41
-	 * @since  3.16.3
42
-	 * @access private
43
-	 * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
44
-	 */
45
-	private $configuration_service;
46
-
47
-	/**
48
-	 * An array of URIs to post ID valid for the current request.
49
-	 *
50
-	 * @since  3.16.3
51
-	 * @access private
52
-	 * @var array $uri_to_post An array of URIs to post ID valid for the current request.
53
-	 */
54
-	protected $uri_to_post;
55
-
56
-	/**
57
-	 * Create a {@link Wordlift_Entity_Uri_Service} instance.
58
-	 *
59
-	 * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
60
-	 *
61
-	 * @since 3.16.3
62
-	 *
63
-	 */
64
-	public function __construct( $configuration_service ) {
65
-
66
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
67
-
68
-		$this->configuration_service = $configuration_service;
69
-
70
-		// Add a filter to the `rest_post_dispatch` filter to add the wl_entity_url meta as `wl:entity_url`.
71
-		add_filter( 'rest_post_dispatch', array( $this, 'rest_post_dispatch' ) );
72
-
73
-		self::$instance = $this;
74
-
75
-	}
76
-
77
-	/**
78
-	 * Get the singleton.
79
-	 *
80
-	 * @return Wordlift_Entity_Uri_Service The singleton instance.
81
-	 * @since 3.21.5
82
-	 */
83
-	public static function get_instance() {
84
-
85
-		return self::$instance;
86
-	}
87
-
88
-	/**
89
-	 * Preload the provided URIs in the local cache.
90
-	 *
91
-	 * This function will populate the local `$uri_to_post` array by running a
92
-	 * single query with all the URIs and returning the mappings in the array.
93
-	 *
94
-	 * @param array $uris An array of URIs.
95
-	 *
96
-	 * @since 3.16.3
97
-	 *
98
-	 */
99
-	public function preload_uris( $uris ) {
100
-
101
-		// Bail out if there are no URIs.
102
-		if ( 0 === count( $uris ) ) {
103
-			return;
104
-		}
105
-
106
-		$this->log->trace( 'Preloading ' . count( $uris ) . ' URI(s)...' );
107
-
108
-		$that          = $this;
109
-		$external_uris = array_filter( $uris, function ( $item ) use ( $that ) {
110
-			return ! $that->is_internal( $item );
111
-		} );
112
-
113
-		$query_args = array(
114
-			// See https://github.com/insideout10/wordlift-plugin/issues/654.
115
-			'ignore_sticky_posts' => 1,
116
-			'cache_results'       => false,
117
-			'numberposts'         => - 1,
118
-			'post_status'         => 'any',
119
-			'post_type'           => Wordlift_Entity_Service::valid_entity_post_types(),
120
-			'meta_query'          => array(
121
-				array(
122
-					'key'     => WL_ENTITY_URL_META_NAME,
123
-					'value'   => $uris,
124
-					'compare' => 'IN',
125
-				),
126
-			),
127
-		);
128
-
129
-		// Only if the current uri is not an internal uri, entity search is
130
-		// performed also looking at sameAs values.
131
-		//
132
-		// This solve issues like https://github.com/insideout10/wordlift-plugin/issues/237
133
-		if ( 0 < count( $external_uris ) ) {
134
-
135
-			$query_args['meta_query']['relation'] = 'OR';
136
-			$query_args['meta_query'][]           = array(
137
-				'key'     => Wordlift_Schema_Service::FIELD_SAME_AS,
138
-				'value'   => $external_uris,
139
-				'compare' => 'IN',
140
-			);
141
-
142
-		}
143
-
144
-		// Get the posts.
145
-		$posts = get_posts( $query_args );
146
-
147
-		// Populate the array. We reinitialize the array on purpose because
148
-		// we don't want these data to long live.
149
-		$this->uri_to_post = array_reduce( $posts, function ( $carry, $item ) use ( $that ) {
150
-			$uris = array_merge(
151
-				get_post_meta( $item->ID, WL_ENTITY_URL_META_NAME ),
152
-				get_post_meta( $item->ID, Wordlift_Schema_Service::FIELD_SAME_AS )
153
-			);
154
-
155
-			return $carry
156
-			       // Get the URI related to the post and fill them with the item id.
157
-			       + array_fill_keys( $uris, $item );
158
-		}, array() );
159
-
160
-		// Add the not found URIs.
161
-		$this->uri_to_post += array_fill_keys( $uris, null );
162
-
163
-		$this->log->debug( count( $this->uri_to_post ) . " URI(s) preloaded." );
164
-
165
-	}
166
-
167
-	/**
168
-	 * Reset the URI to post local cache.
169
-	 *
170
-	 * @since 3.16.3
171
-	 */
172
-	public function reset_uris() {
173
-
174
-		$this->uri_to_post = array();
175
-
176
-	}
177
-
178
-	/**
179
-	 * Find entity posts by the entity URI. Entity as searched by their entity URI or same as.
180
-	 *
181
-	 * @param string $uri The entity URI.
182
-	 *
183
-	 * @return WP_Post|null A WP_Post instance or null if not found.
184
-	 * @since 3.2.0
185
-	 *
186
-	 */
187
-	public function get_entity( $uri ) {
188
-
189
-		$this->log->trace( "Getting an entity post for URI $uri..." );
190
-
191
-		// Check if we've been provided with a value otherwise return null.
192
-		if ( empty( $uri ) ) {
193
-			return null;
194
-		}
195
-
196
-		$this->log->debug( "Querying post for $uri..." );
197
-
198
-		$query_args = array(
199
-			// See https://github.com/insideout10/wordlift-plugin/issues/654.
200
-			'ignore_sticky_posts' => 1,
201
-			'posts_per_page'      => 1,
202
-			'post_status'         => 'any',
203
-			'post_type'           => Wordlift_Entity_Service::valid_entity_post_types(),
204
-			'meta_query'          => array(
205
-				array(
206
-					'key'     => WL_ENTITY_URL_META_NAME,
207
-					'value'   => $uri,
208
-					'compare' => '=',
209
-				),
210
-			),
211
-		);
212
-
213
-		// Only if the current uri is not an internal uri, entity search is
214
-		// performed also looking at sameAs values.
215
-		//
216
-		// This solve issues like https://github.com/insideout10/wordlift-plugin/issues/237
217
-		if ( ! $this->is_internal( $uri ) ) {
218
-
219
-			$query_args['meta_query']['relation'] = 'OR';
220
-			$query_args['meta_query'][]           = array(
221
-				'key'     => Wordlift_Schema_Service::FIELD_SAME_AS,
222
-				'value'   => $uri,
223
-				'compare' => '=',
224
-			);
225
-		}
226
-
227
-		$posts = get_posts( $query_args );
228
-
229
-		// Attempt to find post by URI (only for local entity URLs)
230
-		if ( empty( $posts ) ) {
231
-
232
-			$this->log->debug( "Finding post by $uri..." );
233
-			$postid = url_to_postid( $uri );
234
-			if ( $postid !== 0 ) {
235
-				$this->log->trace( "Found post $postid by URL" );
236
-
237
-				return get_post( $postid );
238
-			}
239
-
240
-		}
241
-
242
-		// Return null if no post is found.
243
-		if ( empty( $posts ) ) {
244
-			$this->log->warn( "No post for URI $uri." );
245
-
246
-			return null;
247
-		}
248
-
249
-		// Return the found post.
250
-		return current( $posts );
251
-	}
252
-
253
-	/**
254
-	 * Determines whether a given uri is an internal uri or not.
255
-	 *
256
-	 * @param string $uri An uri.
257
-	 *
258
-	 * @return true if the uri internal to the current dataset otherwise false.
259
-	 * @since 3.16.3
260
-	 *
261
-	 */
262
-	public function is_internal( $uri ) {
263
-
264
-		return ( 0 === strrpos( $uri, (string) $this->configuration_service->get_dataset_uri() ) );
265
-	}
266
-
267
-	/**
268
-	 * Hook to `rest_post_dispatch` to alter the response and add the `wl_entity_url` post meta as `wl:entity_url`.
269
-	 *
270
-	 * We're using this filter instead of the well known `register_meta` / `register_rest_field` because we still need
271
-	 * to provide full compatibility with WordPress 4.4+.
272
-	 *
273
-	 * @param WP_HTTP_Response $result Result to send to the client. Usually a WP_REST_Response.
274
-	 *
275
-	 * @return WP_HTTP_Response The result to send to the client.
276
-	 *
277
-	 * @since 3.23.0
278
-	 */
279
-	public function rest_post_dispatch( $result ) {
280
-
281
-		// Get a reference to the actual data.
282
-		$data = &$result->data;
283
-
284
-		// Bail out if we don't have the required parameters, or if the type is not a valid entity.
285
-		if ( ! is_array( $data ) || ! isset( $data['id'] ) || ! isset( $data['type'] )
286
-		     || ! Wordlift_Entity_Type_Service::is_valid_entity_post_type( $data['type'] ) ) {
287
-			return $result;
288
-		}
289
-
290
-		// Add the `wl:entity_url`.
291
-		$data['wl:entity_url'] = Wordlift_Entity_Service::get_instance()->get_uri( $data['id'] );
292
-
293
-		return $result;
294
-	}
20
+    /**
21
+     * Holds the {@link Wordlift_Entity_Uri_Service} instance.
22
+     *
23
+     * @since 3.21.5
24
+     * @access private
25
+     * @var Wordlift_Entity_Uri_Service $instance The {@link Wordlift_Entity_Uri_Service} singleton.
26
+     */
27
+    private static $instance;
28
+
29
+    /**
30
+     * A {@link Wordlift_Log_Service} instance.
31
+     *
32
+     * @since  3.16.3
33
+     * @access private
34
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
35
+     */
36
+    private $log;
37
+
38
+    /**
39
+     * The {@link Wordlift_Configuration_Service} instance.
40
+     *
41
+     * @since  3.16.3
42
+     * @access private
43
+     * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
44
+     */
45
+    private $configuration_service;
46
+
47
+    /**
48
+     * An array of URIs to post ID valid for the current request.
49
+     *
50
+     * @since  3.16.3
51
+     * @access private
52
+     * @var array $uri_to_post An array of URIs to post ID valid for the current request.
53
+     */
54
+    protected $uri_to_post;
55
+
56
+    /**
57
+     * Create a {@link Wordlift_Entity_Uri_Service} instance.
58
+     *
59
+     * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
60
+     *
61
+     * @since 3.16.3
62
+     *
63
+     */
64
+    public function __construct( $configuration_service ) {
65
+
66
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
67
+
68
+        $this->configuration_service = $configuration_service;
69
+
70
+        // Add a filter to the `rest_post_dispatch` filter to add the wl_entity_url meta as `wl:entity_url`.
71
+        add_filter( 'rest_post_dispatch', array( $this, 'rest_post_dispatch' ) );
72
+
73
+        self::$instance = $this;
74
+
75
+    }
76
+
77
+    /**
78
+     * Get the singleton.
79
+     *
80
+     * @return Wordlift_Entity_Uri_Service The singleton instance.
81
+     * @since 3.21.5
82
+     */
83
+    public static function get_instance() {
84
+
85
+        return self::$instance;
86
+    }
87
+
88
+    /**
89
+     * Preload the provided URIs in the local cache.
90
+     *
91
+     * This function will populate the local `$uri_to_post` array by running a
92
+     * single query with all the URIs and returning the mappings in the array.
93
+     *
94
+     * @param array $uris An array of URIs.
95
+     *
96
+     * @since 3.16.3
97
+     *
98
+     */
99
+    public function preload_uris( $uris ) {
100
+
101
+        // Bail out if there are no URIs.
102
+        if ( 0 === count( $uris ) ) {
103
+            return;
104
+        }
105
+
106
+        $this->log->trace( 'Preloading ' . count( $uris ) . ' URI(s)...' );
107
+
108
+        $that          = $this;
109
+        $external_uris = array_filter( $uris, function ( $item ) use ( $that ) {
110
+            return ! $that->is_internal( $item );
111
+        } );
112
+
113
+        $query_args = array(
114
+            // See https://github.com/insideout10/wordlift-plugin/issues/654.
115
+            'ignore_sticky_posts' => 1,
116
+            'cache_results'       => false,
117
+            'numberposts'         => - 1,
118
+            'post_status'         => 'any',
119
+            'post_type'           => Wordlift_Entity_Service::valid_entity_post_types(),
120
+            'meta_query'          => array(
121
+                array(
122
+                    'key'     => WL_ENTITY_URL_META_NAME,
123
+                    'value'   => $uris,
124
+                    'compare' => 'IN',
125
+                ),
126
+            ),
127
+        );
128
+
129
+        // Only if the current uri is not an internal uri, entity search is
130
+        // performed also looking at sameAs values.
131
+        //
132
+        // This solve issues like https://github.com/insideout10/wordlift-plugin/issues/237
133
+        if ( 0 < count( $external_uris ) ) {
134
+
135
+            $query_args['meta_query']['relation'] = 'OR';
136
+            $query_args['meta_query'][]           = array(
137
+                'key'     => Wordlift_Schema_Service::FIELD_SAME_AS,
138
+                'value'   => $external_uris,
139
+                'compare' => 'IN',
140
+            );
141
+
142
+        }
143
+
144
+        // Get the posts.
145
+        $posts = get_posts( $query_args );
146
+
147
+        // Populate the array. We reinitialize the array on purpose because
148
+        // we don't want these data to long live.
149
+        $this->uri_to_post = array_reduce( $posts, function ( $carry, $item ) use ( $that ) {
150
+            $uris = array_merge(
151
+                get_post_meta( $item->ID, WL_ENTITY_URL_META_NAME ),
152
+                get_post_meta( $item->ID, Wordlift_Schema_Service::FIELD_SAME_AS )
153
+            );
154
+
155
+            return $carry
156
+                    // Get the URI related to the post and fill them with the item id.
157
+                   + array_fill_keys( $uris, $item );
158
+        }, array() );
159
+
160
+        // Add the not found URIs.
161
+        $this->uri_to_post += array_fill_keys( $uris, null );
162
+
163
+        $this->log->debug( count( $this->uri_to_post ) . " URI(s) preloaded." );
164
+
165
+    }
166
+
167
+    /**
168
+     * Reset the URI to post local cache.
169
+     *
170
+     * @since 3.16.3
171
+     */
172
+    public function reset_uris() {
173
+
174
+        $this->uri_to_post = array();
175
+
176
+    }
177
+
178
+    /**
179
+     * Find entity posts by the entity URI. Entity as searched by their entity URI or same as.
180
+     *
181
+     * @param string $uri The entity URI.
182
+     *
183
+     * @return WP_Post|null A WP_Post instance or null if not found.
184
+     * @since 3.2.0
185
+     *
186
+     */
187
+    public function get_entity( $uri ) {
188
+
189
+        $this->log->trace( "Getting an entity post for URI $uri..." );
190
+
191
+        // Check if we've been provided with a value otherwise return null.
192
+        if ( empty( $uri ) ) {
193
+            return null;
194
+        }
195
+
196
+        $this->log->debug( "Querying post for $uri..." );
197
+
198
+        $query_args = array(
199
+            // See https://github.com/insideout10/wordlift-plugin/issues/654.
200
+            'ignore_sticky_posts' => 1,
201
+            'posts_per_page'      => 1,
202
+            'post_status'         => 'any',
203
+            'post_type'           => Wordlift_Entity_Service::valid_entity_post_types(),
204
+            'meta_query'          => array(
205
+                array(
206
+                    'key'     => WL_ENTITY_URL_META_NAME,
207
+                    'value'   => $uri,
208
+                    'compare' => '=',
209
+                ),
210
+            ),
211
+        );
212
+
213
+        // Only if the current uri is not an internal uri, entity search is
214
+        // performed also looking at sameAs values.
215
+        //
216
+        // This solve issues like https://github.com/insideout10/wordlift-plugin/issues/237
217
+        if ( ! $this->is_internal( $uri ) ) {
218
+
219
+            $query_args['meta_query']['relation'] = 'OR';
220
+            $query_args['meta_query'][]           = array(
221
+                'key'     => Wordlift_Schema_Service::FIELD_SAME_AS,
222
+                'value'   => $uri,
223
+                'compare' => '=',
224
+            );
225
+        }
226
+
227
+        $posts = get_posts( $query_args );
228
+
229
+        // Attempt to find post by URI (only for local entity URLs)
230
+        if ( empty( $posts ) ) {
231
+
232
+            $this->log->debug( "Finding post by $uri..." );
233
+            $postid = url_to_postid( $uri );
234
+            if ( $postid !== 0 ) {
235
+                $this->log->trace( "Found post $postid by URL" );
236
+
237
+                return get_post( $postid );
238
+            }
239
+
240
+        }
241
+
242
+        // Return null if no post is found.
243
+        if ( empty( $posts ) ) {
244
+            $this->log->warn( "No post for URI $uri." );
245
+
246
+            return null;
247
+        }
248
+
249
+        // Return the found post.
250
+        return current( $posts );
251
+    }
252
+
253
+    /**
254
+     * Determines whether a given uri is an internal uri or not.
255
+     *
256
+     * @param string $uri An uri.
257
+     *
258
+     * @return true if the uri internal to the current dataset otherwise false.
259
+     * @since 3.16.3
260
+     *
261
+     */
262
+    public function is_internal( $uri ) {
263
+
264
+        return ( 0 === strrpos( $uri, (string) $this->configuration_service->get_dataset_uri() ) );
265
+    }
266
+
267
+    /**
268
+     * Hook to `rest_post_dispatch` to alter the response and add the `wl_entity_url` post meta as `wl:entity_url`.
269
+     *
270
+     * We're using this filter instead of the well known `register_meta` / `register_rest_field` because we still need
271
+     * to provide full compatibility with WordPress 4.4+.
272
+     *
273
+     * @param WP_HTTP_Response $result Result to send to the client. Usually a WP_REST_Response.
274
+     *
275
+     * @return WP_HTTP_Response The result to send to the client.
276
+     *
277
+     * @since 3.23.0
278
+     */
279
+    public function rest_post_dispatch( $result ) {
280
+
281
+        // Get a reference to the actual data.
282
+        $data = &$result->data;
283
+
284
+        // Bail out if we don't have the required parameters, or if the type is not a valid entity.
285
+        if ( ! is_array( $data ) || ! isset( $data['id'] ) || ! isset( $data['type'] )
286
+             || ! Wordlift_Entity_Type_Service::is_valid_entity_post_type( $data['type'] ) ) {
287
+            return $result;
288
+        }
289
+
290
+        // Add the `wl:entity_url`.
291
+        $data['wl:entity_url'] = Wordlift_Entity_Service::get_instance()->get_uri( $data['id'] );
292
+
293
+        return $result;
294
+    }
295 295
 
296 296
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -61,14 +61,14 @@  discard block
 block discarded – undo
61 61
 	 * @since 3.16.3
62 62
 	 *
63 63
 	 */
64
-	public function __construct( $configuration_service ) {
64
+	public function __construct($configuration_service) {
65 65
 
66
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
66
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
67 67
 
68 68
 		$this->configuration_service = $configuration_service;
69 69
 
70 70
 		// Add a filter to the `rest_post_dispatch` filter to add the wl_entity_url meta as `wl:entity_url`.
71
-		add_filter( 'rest_post_dispatch', array( $this, 'rest_post_dispatch' ) );
71
+		add_filter('rest_post_dispatch', array($this, 'rest_post_dispatch'));
72 72
 
73 73
 		self::$instance = $this;
74 74
 
@@ -96,25 +96,25 @@  discard block
 block discarded – undo
96 96
 	 * @since 3.16.3
97 97
 	 *
98 98
 	 */
99
-	public function preload_uris( $uris ) {
99
+	public function preload_uris($uris) {
100 100
 
101 101
 		// Bail out if there are no URIs.
102
-		if ( 0 === count( $uris ) ) {
102
+		if (0 === count($uris)) {
103 103
 			return;
104 104
 		}
105 105
 
106
-		$this->log->trace( 'Preloading ' . count( $uris ) . ' URI(s)...' );
106
+		$this->log->trace('Preloading '.count($uris).' URI(s)...');
107 107
 
108 108
 		$that          = $this;
109
-		$external_uris = array_filter( $uris, function ( $item ) use ( $that ) {
110
-			return ! $that->is_internal( $item );
109
+		$external_uris = array_filter($uris, function($item) use ($that) {
110
+			return ! $that->is_internal($item);
111 111
 		} );
112 112
 
113 113
 		$query_args = array(
114 114
 			// See https://github.com/insideout10/wordlift-plugin/issues/654.
115 115
 			'ignore_sticky_posts' => 1,
116 116
 			'cache_results'       => false,
117
-			'numberposts'         => - 1,
117
+			'numberposts'         => -1,
118 118
 			'post_status'         => 'any',
119 119
 			'post_type'           => Wordlift_Entity_Service::valid_entity_post_types(),
120 120
 			'meta_query'          => array(
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 		// performed also looking at sameAs values.
131 131
 		//
132 132
 		// This solve issues like https://github.com/insideout10/wordlift-plugin/issues/237
133
-		if ( 0 < count( $external_uris ) ) {
133
+		if (0 < count($external_uris)) {
134 134
 
135 135
 			$query_args['meta_query']['relation'] = 'OR';
136 136
 			$query_args['meta_query'][]           = array(
@@ -142,25 +142,25 @@  discard block
 block discarded – undo
142 142
 		}
143 143
 
144 144
 		// Get the posts.
145
-		$posts = get_posts( $query_args );
145
+		$posts = get_posts($query_args);
146 146
 
147 147
 		// Populate the array. We reinitialize the array on purpose because
148 148
 		// we don't want these data to long live.
149
-		$this->uri_to_post = array_reduce( $posts, function ( $carry, $item ) use ( $that ) {
149
+		$this->uri_to_post = array_reduce($posts, function($carry, $item) use ($that) {
150 150
 			$uris = array_merge(
151
-				get_post_meta( $item->ID, WL_ENTITY_URL_META_NAME ),
152
-				get_post_meta( $item->ID, Wordlift_Schema_Service::FIELD_SAME_AS )
151
+				get_post_meta($item->ID, WL_ENTITY_URL_META_NAME),
152
+				get_post_meta($item->ID, Wordlift_Schema_Service::FIELD_SAME_AS)
153 153
 			);
154 154
 
155 155
 			return $carry
156 156
 			       // Get the URI related to the post and fill them with the item id.
157
-			       + array_fill_keys( $uris, $item );
158
-		}, array() );
157
+			       + array_fill_keys($uris, $item);
158
+		}, array());
159 159
 
160 160
 		// Add the not found URIs.
161
-		$this->uri_to_post += array_fill_keys( $uris, null );
161
+		$this->uri_to_post += array_fill_keys($uris, null);
162 162
 
163
-		$this->log->debug( count( $this->uri_to_post ) . " URI(s) preloaded." );
163
+		$this->log->debug(count($this->uri_to_post)." URI(s) preloaded.");
164 164
 
165 165
 	}
166 166
 
@@ -184,16 +184,16 @@  discard block
 block discarded – undo
184 184
 	 * @since 3.2.0
185 185
 	 *
186 186
 	 */
187
-	public function get_entity( $uri ) {
187
+	public function get_entity($uri) {
188 188
 
189
-		$this->log->trace( "Getting an entity post for URI $uri..." );
189
+		$this->log->trace("Getting an entity post for URI $uri...");
190 190
 
191 191
 		// Check if we've been provided with a value otherwise return null.
192
-		if ( empty( $uri ) ) {
192
+		if (empty($uri)) {
193 193
 			return null;
194 194
 		}
195 195
 
196
-		$this->log->debug( "Querying post for $uri..." );
196
+		$this->log->debug("Querying post for $uri...");
197 197
 
198 198
 		$query_args = array(
199 199
 			// See https://github.com/insideout10/wordlift-plugin/issues/654.
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 		// performed also looking at sameAs values.
215 215
 		//
216 216
 		// This solve issues like https://github.com/insideout10/wordlift-plugin/issues/237
217
-		if ( ! $this->is_internal( $uri ) ) {
217
+		if ( ! $this->is_internal($uri)) {
218 218
 
219 219
 			$query_args['meta_query']['relation'] = 'OR';
220 220
 			$query_args['meta_query'][]           = array(
@@ -224,30 +224,30 @@  discard block
 block discarded – undo
224 224
 			);
225 225
 		}
226 226
 
227
-		$posts = get_posts( $query_args );
227
+		$posts = get_posts($query_args);
228 228
 
229 229
 		// Attempt to find post by URI (only for local entity URLs)
230
-		if ( empty( $posts ) ) {
230
+		if (empty($posts)) {
231 231
 
232
-			$this->log->debug( "Finding post by $uri..." );
233
-			$postid = url_to_postid( $uri );
234
-			if ( $postid !== 0 ) {
235
-				$this->log->trace( "Found post $postid by URL" );
232
+			$this->log->debug("Finding post by $uri...");
233
+			$postid = url_to_postid($uri);
234
+			if ($postid !== 0) {
235
+				$this->log->trace("Found post $postid by URL");
236 236
 
237
-				return get_post( $postid );
237
+				return get_post($postid);
238 238
 			}
239 239
 
240 240
 		}
241 241
 
242 242
 		// Return null if no post is found.
243
-		if ( empty( $posts ) ) {
244
-			$this->log->warn( "No post for URI $uri." );
243
+		if (empty($posts)) {
244
+			$this->log->warn("No post for URI $uri.");
245 245
 
246 246
 			return null;
247 247
 		}
248 248
 
249 249
 		// Return the found post.
250
-		return current( $posts );
250
+		return current($posts);
251 251
 	}
252 252
 
253 253
 	/**
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
 	 * @since 3.16.3
260 260
 	 *
261 261
 	 */
262
-	public function is_internal( $uri ) {
262
+	public function is_internal($uri) {
263 263
 
264
-		return ( 0 === strrpos( $uri, (string) $this->configuration_service->get_dataset_uri() ) );
264
+		return (0 === strrpos($uri, (string) $this->configuration_service->get_dataset_uri()));
265 265
 	}
266 266
 
267 267
 	/**
@@ -276,19 +276,19 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @since 3.23.0
278 278
 	 */
279
-	public function rest_post_dispatch( $result ) {
279
+	public function rest_post_dispatch($result) {
280 280
 
281 281
 		// Get a reference to the actual data.
282 282
 		$data = &$result->data;
283 283
 
284 284
 		// Bail out if we don't have the required parameters, or if the type is not a valid entity.
285
-		if ( ! is_array( $data ) || ! isset( $data['id'] ) || ! isset( $data['type'] )
286
-		     || ! Wordlift_Entity_Type_Service::is_valid_entity_post_type( $data['type'] ) ) {
285
+		if ( ! is_array($data) || ! isset($data['id']) || ! isset($data['type'])
286
+		     || ! Wordlift_Entity_Type_Service::is_valid_entity_post_type($data['type'])) {
287 287
 			return $result;
288 288
 		}
289 289
 
290 290
 		// Add the `wl:entity_url`.
291
-		$data['wl:entity_url'] = Wordlift_Entity_Service::get_instance()->get_uri( $data['id'] );
291
+		$data['wl:entity_url'] = Wordlift_Entity_Service::get_instance()->get_uri($data['id']);
292 292
 
293 293
 		return $result;
294 294
 	}
Please login to merge, or discard this patch.
src/vendor/composer/InstalledVersions.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
 class InstalledVersions
13 13
 {
14 14
 private static $installed = array (
15
-  'root' => 
16
-  array (
15
+    'root' => 
16
+    array (
17 17
     'pretty_version' => 'dev-develop',
18 18
     'version' => 'dev-develop',
19 19
     'aliases' => 
@@ -21,28 +21,28 @@  discard block
 block discarded – undo
21 21
     ),
22 22
     'reference' => '795b4ba4abfb8776e40f340700694718875f006f',
23 23
     'name' => '__root__',
24
-  ),
25
-  'versions' => 
26
-  array (
24
+    ),
25
+    'versions' => 
26
+    array (
27 27
     '__root__' => 
28 28
     array (
29
-      'pretty_version' => 'dev-develop',
30
-      'version' => 'dev-develop',
31
-      'aliases' => 
32
-      array (
33
-      ),
34
-      'reference' => '795b4ba4abfb8776e40f340700694718875f006f',
29
+        'pretty_version' => 'dev-develop',
30
+        'version' => 'dev-develop',
31
+        'aliases' => 
32
+        array (
33
+        ),
34
+        'reference' => '795b4ba4abfb8776e40f340700694718875f006f',
35 35
     ),
36 36
     'deliciousbrains/wp-background-processing' => 
37 37
     array (
38
-      'pretty_version' => '1.0.2',
39
-      'version' => '1.0.2.0',
40
-      'aliases' => 
41
-      array (
42
-      ),
43
-      'reference' => '2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800',
38
+        'pretty_version' => '1.0.2',
39
+        'version' => '1.0.2.0',
40
+        'aliases' => 
41
+        array (
42
+        ),
43
+        'reference' => '2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800',
44
+    ),
44 45
     ),
45
-  ),
46 46
 );
47 47
 
48 48
 
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,34 +11,34 @@  discard block
 block discarded – undo
11 11
 
12 12
 class InstalledVersions
13 13
 {
14
-private static $installed = array (
14
+private static $installed = array(
15 15
   'root' => 
16
-  array (
16
+  array(
17 17
     'pretty_version' => 'dev-develop',
18 18
     'version' => 'dev-develop',
19 19
     'aliases' => 
20
-    array (
20
+    array(
21 21
     ),
22 22
     'reference' => '795b4ba4abfb8776e40f340700694718875f006f',
23 23
     'name' => '__root__',
24 24
   ),
25 25
   'versions' => 
26
-  array (
26
+  array(
27 27
     '__root__' => 
28
-    array (
28
+    array(
29 29
       'pretty_version' => 'dev-develop',
30 30
       'version' => 'dev-develop',
31 31
       'aliases' => 
32
-      array (
32
+      array(
33 33
       ),
34 34
       'reference' => '795b4ba4abfb8776e40f340700694718875f006f',
35 35
     ),
36 36
     'deliciousbrains/wp-background-processing' => 
37
-    array (
37
+    array(
38 38
       'pretty_version' => '1.0.2',
39 39
       'version' => '1.0.2.0',
40 40
       'aliases' => 
41
-      array (
41
+      array(
42 42
       ),
43 43
       'reference' => '2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800',
44 44
     ),
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 
102 102
 public static function getVersionRanges($packageName)
103 103
 {
104
-if (!isset(self::$installed['versions'][$packageName])) {
105
-throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
104
+if ( ! isset(self::$installed['versions'][$packageName])) {
105
+throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed');
106 106
 }
107 107
 
108 108
 $ranges = array();
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
 
129 129
 public static function getVersion($packageName)
130 130
 {
131
-if (!isset(self::$installed['versions'][$packageName])) {
132
-throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
131
+if ( ! isset(self::$installed['versions'][$packageName])) {
132
+throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed');
133 133
 }
134 134
 
135
-if (!isset(self::$installed['versions'][$packageName]['version'])) {
135
+if ( ! isset(self::$installed['versions'][$packageName]['version'])) {
136 136
 return null;
137 137
 }
138 138
 
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
 
146 146
 public static function getPrettyVersion($packageName)
147 147
 {
148
-if (!isset(self::$installed['versions'][$packageName])) {
149
-throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
148
+if ( ! isset(self::$installed['versions'][$packageName])) {
149
+throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed');
150 150
 }
151 151
 
152
-if (!isset(self::$installed['versions'][$packageName]['pretty_version'])) {
152
+if ( ! isset(self::$installed['versions'][$packageName]['pretty_version'])) {
153 153
 return null;
154 154
 }
155 155
 
@@ -162,11 +162,11 @@  discard block
 block discarded – undo
162 162
 
163 163
 public static function getReference($packageName)
164 164
 {
165
-if (!isset(self::$installed['versions'][$packageName])) {
166
-throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
165
+if ( ! isset(self::$installed['versions'][$packageName])) {
166
+throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed');
167 167
 }
168 168
 
169
-if (!isset(self::$installed['versions'][$packageName]['reference'])) {
169
+if ( ! isset(self::$installed['versions'][$packageName]['reference'])) {
170 170
 return null;
171 171
 }
172 172
 
Please login to merge, or discard this patch.
src/vendor/composer/installed.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php return array (
2
-  'root' => 
3
-  array (
2
+    'root' => 
3
+    array (
4 4
     'pretty_version' => 'dev-develop',
5 5
     'version' => 'dev-develop',
6 6
     'aliases' => 
@@ -8,26 +8,26 @@  discard block
 block discarded – undo
8 8
     ),
9 9
     'reference' => '795b4ba4abfb8776e40f340700694718875f006f',
10 10
     'name' => '__root__',
11
-  ),
12
-  'versions' => 
13
-  array (
11
+    ),
12
+    'versions' => 
13
+    array (
14 14
     '__root__' => 
15 15
     array (
16
-      'pretty_version' => 'dev-develop',
17
-      'version' => 'dev-develop',
18
-      'aliases' => 
19
-      array (
20
-      ),
21
-      'reference' => '795b4ba4abfb8776e40f340700694718875f006f',
16
+        'pretty_version' => 'dev-develop',
17
+        'version' => 'dev-develop',
18
+        'aliases' => 
19
+        array (
20
+        ),
21
+        'reference' => '795b4ba4abfb8776e40f340700694718875f006f',
22 22
     ),
23 23
     'deliciousbrains/wp-background-processing' => 
24 24
     array (
25
-      'pretty_version' => '1.0.2',
26
-      'version' => '1.0.2.0',
27
-      'aliases' => 
28
-      array (
29
-      ),
30
-      'reference' => '2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800',
25
+        'pretty_version' => '1.0.2',
26
+        'version' => '1.0.2.0',
27
+        'aliases' => 
28
+        array (
29
+        ),
30
+        'reference' => '2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800',
31
+    ),
31 32
     ),
32
-  ),
33 33
 );
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,31 +1,31 @@
 block discarded – undo
1
-<?php return array (
1
+<?php return array(
2 2
   'root' => 
3
-  array (
3
+  array(
4 4
     'pretty_version' => 'dev-develop',
5 5
     'version' => 'dev-develop',
6 6
     'aliases' => 
7
-    array (
7
+    array(
8 8
     ),
9 9
     'reference' => '795b4ba4abfb8776e40f340700694718875f006f',
10 10
     'name' => '__root__',
11 11
   ),
12 12
   'versions' => 
13
-  array (
13
+  array(
14 14
     '__root__' => 
15
-    array (
15
+    array(
16 16
       'pretty_version' => 'dev-develop',
17 17
       'version' => 'dev-develop',
18 18
       'aliases' => 
19
-      array (
19
+      array(
20 20
       ),
21 21
       'reference' => '795b4ba4abfb8776e40f340700694718875f006f',
22 22
     ),
23 23
     'deliciousbrains/wp-background-processing' => 
24
-    array (
24
+    array(
25 25
       'pretty_version' => '1.0.2',
26 26
       'version' => '1.0.2.0',
27 27
       'aliases' => 
28
-      array (
28
+      array(
29 29
       ),
30 30
       'reference' => '2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800',
31 31
     ),
Please login to merge, or discard this patch.
src/includes/class-wordlift-linked-data-service.php 2 patches
Indentation   +327 added lines, -327 removed lines patch added patch discarded remove patch
@@ -18,336 +18,336 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Linked_Data_Service {
20 20
 
21
-	//<editor-fold desc="## FIELDS">
22
-	/**
23
-	 * A {@link Wordlift_Log_Service} instance.
24
-	 *
25
-	 * @since  3.15.0
26
-	 * @access private
27
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
28
-	 */
29
-	private $log;
30
-
31
-	/**
32
-	 * The {@link Wordlift_Entity_Service} instance.
33
-	 *
34
-	 * @since  3.15.0
35
-	 * @access private
36
-	 * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
37
-	 */
38
-	private $entity_service;
39
-
40
-	/**
41
-	 * The {@link Wordlift_Entity_Type_Service} instance.
42
-	 *
43
-	 * @since  3.15.0
44
-	 * @access private
45
-	 * @var \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance.
46
-	 */
47
-	private $entity_type_service;
48
-
49
-	/**
50
-	 * The {@link Wordlift_Schema_Service} instance.
51
-	 *
52
-	 * @since  3.15.0
53
-	 * @access private
54
-	 * @var \Wordlift_Schema_Service $schema_service The {@link Wordlift_Schema_Service} instance.
55
-	 */
56
-	private $schema_service;
57
-
58
-	/**
59
-	 * The {@link Wordlift_Sparql_Service} instance.
60
-	 *
61
-	 * @since  3.15.0
62
-	 * @access private
63
-	 * @var \Wordlift_Sparql_Service $sparql_service The {@link Wordlift_Sparql_Service} instance.
64
-	 */
65
-	private $sparql_service;
66
-
67
-	/**
68
-	 * The {@link Wordlift_Linked_Data_Service} singleton instance.
69
-	 *
70
-	 * @since  3.15.0
71
-	 * @access private
72
-	 * @var \Wordlift_Linked_Data_Service $instance The {@link Wordlift_Linked_Data_Service} singleton instance.
73
-	 */
74
-	private static $instance;
75
-	//</editor-fold>
76
-
77
-	/**
78
-	 * Create a {@link Wordlift_Linked_Data_Service} instance.
79
-	 *
80
-	 * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
81
-	 * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance.
82
-	 * @param \Wordlift_Schema_Service $schema_service The {@link Wordlift_Schema_Service} instance.
83
-	 * @param \Wordlift_Sparql_Service $sparql_service The {@link Wordlift_Sparql_Service} instance.
84
-	 *
85
-	 * @since 3.15.0
86
-	 *
87
-	 */
88
-	public function __construct( $entity_service, $entity_type_service, $schema_service, $sparql_service ) {
89
-
90
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Linked_Data_Service' );
91
-
92
-		$this->entity_service      = $entity_service;
93
-		$this->entity_type_service = $entity_type_service;
94
-		$this->schema_service      = $schema_service;
95
-		$this->sparql_service      = $sparql_service;
96
-
97
-		/*
21
+    //<editor-fold desc="## FIELDS">
22
+    /**
23
+     * A {@link Wordlift_Log_Service} instance.
24
+     *
25
+     * @since  3.15.0
26
+     * @access private
27
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
28
+     */
29
+    private $log;
30
+
31
+    /**
32
+     * The {@link Wordlift_Entity_Service} instance.
33
+     *
34
+     * @since  3.15.0
35
+     * @access private
36
+     * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
37
+     */
38
+    private $entity_service;
39
+
40
+    /**
41
+     * The {@link Wordlift_Entity_Type_Service} instance.
42
+     *
43
+     * @since  3.15.0
44
+     * @access private
45
+     * @var \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance.
46
+     */
47
+    private $entity_type_service;
48
+
49
+    /**
50
+     * The {@link Wordlift_Schema_Service} instance.
51
+     *
52
+     * @since  3.15.0
53
+     * @access private
54
+     * @var \Wordlift_Schema_Service $schema_service The {@link Wordlift_Schema_Service} instance.
55
+     */
56
+    private $schema_service;
57
+
58
+    /**
59
+     * The {@link Wordlift_Sparql_Service} instance.
60
+     *
61
+     * @since  3.15.0
62
+     * @access private
63
+     * @var \Wordlift_Sparql_Service $sparql_service The {@link Wordlift_Sparql_Service} instance.
64
+     */
65
+    private $sparql_service;
66
+
67
+    /**
68
+     * The {@link Wordlift_Linked_Data_Service} singleton instance.
69
+     *
70
+     * @since  3.15.0
71
+     * @access private
72
+     * @var \Wordlift_Linked_Data_Service $instance The {@link Wordlift_Linked_Data_Service} singleton instance.
73
+     */
74
+    private static $instance;
75
+    //</editor-fold>
76
+
77
+    /**
78
+     * Create a {@link Wordlift_Linked_Data_Service} instance.
79
+     *
80
+     * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
81
+     * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance.
82
+     * @param \Wordlift_Schema_Service $schema_service The {@link Wordlift_Schema_Service} instance.
83
+     * @param \Wordlift_Sparql_Service $sparql_service The {@link Wordlift_Sparql_Service} instance.
84
+     *
85
+     * @since 3.15.0
86
+     *
87
+     */
88
+    public function __construct( $entity_service, $entity_type_service, $schema_service, $sparql_service ) {
89
+
90
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Linked_Data_Service' );
91
+
92
+        $this->entity_service      = $entity_service;
93
+        $this->entity_type_service = $entity_type_service;
94
+        $this->schema_service      = $schema_service;
95
+        $this->sparql_service      = $sparql_service;
96
+
97
+        /*
98 98
 		 * Allow callers to call the `push` and `remove` methods using WordPress' hooks.
99 99
 		 *
100 100
 		 * @since 3.27.6
101 101
 		 */
102
-		add_action( 'wl_legacy_linked_data__push', array( $this, 'push' ) );
103
-		add_action( 'wl_legacy_linked_data__remove', array( $this, 'remove' ) );
104
-
105
-		self::$instance = $this;
106
-
107
-	}
108
-
109
-	/**
110
-	 * Get the singleton instance of {@link Wordlift_Linked_Data_Service}.
111
-	 *
112
-	 * @return Wordlift_Linked_Data_Service The singleton instance of <a href='psi_element://Wordlift_Linked_Data_Service'>Wordlift_Linked_Data_Service</a>.
113
-	 * @since 3.15.0
114
-	 *
115
-	 */
116
-	public static function get_instance() {
117
-
118
-		return self::$instance;
119
-	}
120
-
121
-	//<editor-fold desc="## FUNCTIONS">
122
-
123
-	/**
124
-	 * Push a {@link WP_Post} to the Linked Data store.
125
-	 *
126
-	 * If the {@link WP_Post} is an entity and it's not of the `Article` type,
127
-	 * then it is pushed to the remote Linked Data store.
128
-	 *
129
-	 * @param int $post_id The {@link WP_Post}'s id.
130
-	 *
131
-	 * @since 3.15.0
132
-	 *
133
-	 */
134
-	public function push( $post_id ) {
135
-
136
-		$this->log->debug( "Pushing post $post_id..." );
137
-
138
-		// @since 3.18.0 we don't check anymore if the post is an entity, i.e.
139
-		// we removed the following:
140
-		//		if ( ! $this->entity_service->is_entity( $post_id ) ) {
141
-		//			$this->log->debug( "Post $post_id is not an entity." );
142
-		//
143
-		//			return;
144
-		//		}
145
-
146
-		// Get the post and push it to the Linked Data store.
147
-		$this->do_push( $post_id );
148
-
149
-		// Reindex the triple store if buffering is turned off.
150
-		if ( false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) {
151
-			wordlift_reindex_triple_store();
152
-		}
153
-
154
-	}
155
-
156
-	/**
157
-	 * Push an entity to the Linked Data store.
158
-	 *
159
-	 * @param int $post_id The {@link WP_Post}'s id.
160
-	 *
161
-	 * @since 3.15.0
162
-	 *
163
-	 */
164
-	private function do_push( $post_id ) {
165
-		$this->log->debug( "Doing post $post_id push..." );
166
-
167
-		// Get the post.
168
-		$post = get_post( $post_id );
169
-
170
-		// Bail out if the post isn't found.
171
-		if ( null === $post ) {
172
-			$this->log->warn( "Post $post_id not found." );
173
-
174
-			return;
175
-		}
176
-
177
-		// Bail out if the post isn't published.
178
-		if ( 'publish' !== $post->post_status ) {
179
-			$this->log->info( "Post $post_id not published." );
180
-
181
-			return;
182
-		}
183
-
184
-		// Bail out if the URI isn't valid.
185
-		if ( ! $this->has_valid_uri( $post_id ) ) {
186
-			$this->log->warn( "Post $post_id URI invalid." );
187
-
188
-			return;
189
-		}
190
-
191
-		// First remove the post data.
192
-		$this->remove( $post_id );
193
-
194
-		// Then execute the insert query.
195
-		$this->insert( $post_id );
196
-	}
197
-
198
-	/**
199
-	 * Check if an entity's {@link WP_Post} has a valid URI.
200
-	 *
201
-	 * @param int $post_id The entity's {@link WP_Post}'s id.
202
-	 *
203
-	 * @return bool True if the URI is valid otherwise false.
204
-	 * @since 3.15.0
205
-	 *
206
-	 */
207
-	private function has_valid_uri( $post_id ) {
208
-
209
-		// Get the entity's URI.
210
-		$uri = $this->entity_service->get_uri( $post_id );
211
-
212
-		// If the URI isn't found, return false.
213
-		if ( null === $uri ) {
214
-			return false;
215
-		}
216
-
217
-		// If the URI ends with a trailing slash, return false.
218
-		if ( '/' === substr( $uri, - 1 ) ) {
219
-			return false;
220
-		}
221
-
222
-		// URI is valid.
223
-		return true;
224
-	}
225
-
226
-	/**
227
-	 * Remove the specified {@link WP_Post} from the Linked Data.
228
-	 *
229
-	 * @param int $post_id The {@link WP_Post}'s id.
230
-	 *
231
-	 * @since 3.18.0
232
-	 *
233
-	 */
234
-	public function remove( $post_id ) {
235
-		$delete_query = '';
236
-
237
-		// Get the delete statements.
238
-		$triples = $this->get_delete_triples( $post_id );
239
-
240
-		// Loop through all triples and add the statement to delete query.
241
-		foreach ( $triples as $item ) {
242
-			$delete_query .= "DELETE { $item } WHERE { $item }; \n";
243
-		}
244
-
245
-		$this->log->trace( "Delete Query generated [ $delete_query ]." );
246
-
247
-		$this->sparql_service->execute( $delete_query );
248
-	}
249
-
250
-	/**
251
-	 * Insert the specific {@link WP_Post} to Linked Data store.
252
-	 *
253
-	 * @param int $post_id The {@link WP_Post}'s id.
254
-	 *
255
-	 * @since 3.18.0
256
-	 *
257
-	 */
258
-	private function insert( $post_id ) {
259
-		// Get the insert statements.
260
-		$insert_triples = $this->get_insert_triples( $post_id );
261
-
262
-		// Convert all statements to single string.
263
-		$insert_query_body = implode( "\n", $insert_triples );
264
-
265
-		// Build the insert query.
266
-		$insert_query = "INSERT DATA { $insert_query_body };";
267
-
268
-		$this->log->trace( "Insert Query generated [ $insert_query ]." );
269
-
270
-		$this->sparql_service->execute( $insert_query );
271
-	}
272
-
273
-	/**
274
-	 * Get the delete statements.
275
-	 *
276
-	 * @param int $post_id The {@link WP_Post}'s id.
277
-	 *
278
-	 * @return array An array of delete statements.
279
-	 * @since 3.18.0
280
-	 *
281
-	 */
282
-	private function get_delete_triples( $post_id ) {
283
-		$delete_triples = array();
284
-
285
-		// Loop through all renditions and get the triples.
286
-		foreach ( $this->schema_service->get_renditions() as $rendition ) {
287
-			// Push the rendition delete triple to $delete_triples.
288
-			$delete_triples = array_merge(
289
-				$delete_triples,
290
-				(array) $rendition->get_delete_triples( $post_id )
291
-			);
292
-		}
293
-
294
-		/**
295
-		 * Filter: 'wl_delete_triples' - Allow third parties to hook and add additional delete triples.
296
-		 *
297
-		 * @param array $delete_triples Delete triples.
298
-		 * @param int $post_id The current post ID.
299
-		 *
300
-		 * @since 3.18.0
301
-		 *
302
-		 */
303
-		return apply_filters( 'wl_delete_triples', array_unique( $delete_triples ), $post_id );
304
-	}
305
-
306
-	/**
307
-	 * Get the SPARQL insert triples ( ?s ?p ?o ) for the specified {@link WP_Post}.
308
-	 *
309
-	 * @param int $post_id The {@link WP_Post}'s id.
310
-	 *
311
-	 * @return array An array of insert triples.
312
-	 * @since 3.15.0
313
-	 *
314
-	 */
315
-	private function get_insert_triples( $post_id ) {
316
-
317
-		// Get the entity type.
318
-		$type = $this->entity_type_service->get( $post_id );
319
-
320
-		// Get the `linked_data` parameter.
321
-		$properties = $type['linked_data'];
322
-
323
-		// Accumulate the triples.
324
-		$triples = array();
325
-
326
-		/** @var Wordlift_Default_Sparql_Tuple_Rendition $property A {@link Wordlift_Sparql_Tuple_Rendition} instance. */
327
-		foreach ( $properties as $property ) {
328
-			foreach ( $property->get_insert_triples( $post_id ) as $triple ) {
329
-				$triples[] = $triple;
330
-			}
331
-		}
332
-
333
-		$this->log->trace( count( $properties ) . ' properties and ' . count( $triples ) . " triples found for post $post_id." );
334
-
335
-		/**
336
-		 * Get the INSERT triples properties.
337
-		 *
338
-		 * The `wl_insert_triples` filter allows 3rd parties to extend
339
-		 * the list of triples for SPARQL INSERT statements.
340
-		 *
341
-		 * @param array $linked_data A {@link Wordlift_Sparql_Tuple_Rendition} instances.
342
-		 * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance.
343
-		 * @param int $post_id The {@link WP_Post}'s id.
344
-		 *
345
-		 * @since 3.18.0 The hook has been renamed from `wl_insert_tuples_properties` to `wl_insert_triples`.
346
-		 *
347
-		 * @since 3.17.0
348
-		 */
349
-		return apply_filters( 'wl_insert_triples', $triples, $this->entity_service, $post_id );
350
-	}
351
-	//</editor-fold>
102
+        add_action( 'wl_legacy_linked_data__push', array( $this, 'push' ) );
103
+        add_action( 'wl_legacy_linked_data__remove', array( $this, 'remove' ) );
104
+
105
+        self::$instance = $this;
106
+
107
+    }
108
+
109
+    /**
110
+     * Get the singleton instance of {@link Wordlift_Linked_Data_Service}.
111
+     *
112
+     * @return Wordlift_Linked_Data_Service The singleton instance of <a href='psi_element://Wordlift_Linked_Data_Service'>Wordlift_Linked_Data_Service</a>.
113
+     * @since 3.15.0
114
+     *
115
+     */
116
+    public static function get_instance() {
117
+
118
+        return self::$instance;
119
+    }
120
+
121
+    //<editor-fold desc="## FUNCTIONS">
122
+
123
+    /**
124
+     * Push a {@link WP_Post} to the Linked Data store.
125
+     *
126
+     * If the {@link WP_Post} is an entity and it's not of the `Article` type,
127
+     * then it is pushed to the remote Linked Data store.
128
+     *
129
+     * @param int $post_id The {@link WP_Post}'s id.
130
+     *
131
+     * @since 3.15.0
132
+     *
133
+     */
134
+    public function push( $post_id ) {
135
+
136
+        $this->log->debug( "Pushing post $post_id..." );
137
+
138
+        // @since 3.18.0 we don't check anymore if the post is an entity, i.e.
139
+        // we removed the following:
140
+        //		if ( ! $this->entity_service->is_entity( $post_id ) ) {
141
+        //			$this->log->debug( "Post $post_id is not an entity." );
142
+        //
143
+        //			return;
144
+        //		}
145
+
146
+        // Get the post and push it to the Linked Data store.
147
+        $this->do_push( $post_id );
148
+
149
+        // Reindex the triple store if buffering is turned off.
150
+        if ( false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) {
151
+            wordlift_reindex_triple_store();
152
+        }
153
+
154
+    }
155
+
156
+    /**
157
+     * Push an entity to the Linked Data store.
158
+     *
159
+     * @param int $post_id The {@link WP_Post}'s id.
160
+     *
161
+     * @since 3.15.0
162
+     *
163
+     */
164
+    private function do_push( $post_id ) {
165
+        $this->log->debug( "Doing post $post_id push..." );
166
+
167
+        // Get the post.
168
+        $post = get_post( $post_id );
169
+
170
+        // Bail out if the post isn't found.
171
+        if ( null === $post ) {
172
+            $this->log->warn( "Post $post_id not found." );
173
+
174
+            return;
175
+        }
176
+
177
+        // Bail out if the post isn't published.
178
+        if ( 'publish' !== $post->post_status ) {
179
+            $this->log->info( "Post $post_id not published." );
180
+
181
+            return;
182
+        }
183
+
184
+        // Bail out if the URI isn't valid.
185
+        if ( ! $this->has_valid_uri( $post_id ) ) {
186
+            $this->log->warn( "Post $post_id URI invalid." );
187
+
188
+            return;
189
+        }
190
+
191
+        // First remove the post data.
192
+        $this->remove( $post_id );
193
+
194
+        // Then execute the insert query.
195
+        $this->insert( $post_id );
196
+    }
197
+
198
+    /**
199
+     * Check if an entity's {@link WP_Post} has a valid URI.
200
+     *
201
+     * @param int $post_id The entity's {@link WP_Post}'s id.
202
+     *
203
+     * @return bool True if the URI is valid otherwise false.
204
+     * @since 3.15.0
205
+     *
206
+     */
207
+    private function has_valid_uri( $post_id ) {
208
+
209
+        // Get the entity's URI.
210
+        $uri = $this->entity_service->get_uri( $post_id );
211
+
212
+        // If the URI isn't found, return false.
213
+        if ( null === $uri ) {
214
+            return false;
215
+        }
216
+
217
+        // If the URI ends with a trailing slash, return false.
218
+        if ( '/' === substr( $uri, - 1 ) ) {
219
+            return false;
220
+        }
221
+
222
+        // URI is valid.
223
+        return true;
224
+    }
225
+
226
+    /**
227
+     * Remove the specified {@link WP_Post} from the Linked Data.
228
+     *
229
+     * @param int $post_id The {@link WP_Post}'s id.
230
+     *
231
+     * @since 3.18.0
232
+     *
233
+     */
234
+    public function remove( $post_id ) {
235
+        $delete_query = '';
236
+
237
+        // Get the delete statements.
238
+        $triples = $this->get_delete_triples( $post_id );
239
+
240
+        // Loop through all triples and add the statement to delete query.
241
+        foreach ( $triples as $item ) {
242
+            $delete_query .= "DELETE { $item } WHERE { $item }; \n";
243
+        }
244
+
245
+        $this->log->trace( "Delete Query generated [ $delete_query ]." );
246
+
247
+        $this->sparql_service->execute( $delete_query );
248
+    }
249
+
250
+    /**
251
+     * Insert the specific {@link WP_Post} to Linked Data store.
252
+     *
253
+     * @param int $post_id The {@link WP_Post}'s id.
254
+     *
255
+     * @since 3.18.0
256
+     *
257
+     */
258
+    private function insert( $post_id ) {
259
+        // Get the insert statements.
260
+        $insert_triples = $this->get_insert_triples( $post_id );
261
+
262
+        // Convert all statements to single string.
263
+        $insert_query_body = implode( "\n", $insert_triples );
264
+
265
+        // Build the insert query.
266
+        $insert_query = "INSERT DATA { $insert_query_body };";
267
+
268
+        $this->log->trace( "Insert Query generated [ $insert_query ]." );
269
+
270
+        $this->sparql_service->execute( $insert_query );
271
+    }
272
+
273
+    /**
274
+     * Get the delete statements.
275
+     *
276
+     * @param int $post_id The {@link WP_Post}'s id.
277
+     *
278
+     * @return array An array of delete statements.
279
+     * @since 3.18.0
280
+     *
281
+     */
282
+    private function get_delete_triples( $post_id ) {
283
+        $delete_triples = array();
284
+
285
+        // Loop through all renditions and get the triples.
286
+        foreach ( $this->schema_service->get_renditions() as $rendition ) {
287
+            // Push the rendition delete triple to $delete_triples.
288
+            $delete_triples = array_merge(
289
+                $delete_triples,
290
+                (array) $rendition->get_delete_triples( $post_id )
291
+            );
292
+        }
293
+
294
+        /**
295
+         * Filter: 'wl_delete_triples' - Allow third parties to hook and add additional delete triples.
296
+         *
297
+         * @param array $delete_triples Delete triples.
298
+         * @param int $post_id The current post ID.
299
+         *
300
+         * @since 3.18.0
301
+         *
302
+         */
303
+        return apply_filters( 'wl_delete_triples', array_unique( $delete_triples ), $post_id );
304
+    }
305
+
306
+    /**
307
+     * Get the SPARQL insert triples ( ?s ?p ?o ) for the specified {@link WP_Post}.
308
+     *
309
+     * @param int $post_id The {@link WP_Post}'s id.
310
+     *
311
+     * @return array An array of insert triples.
312
+     * @since 3.15.0
313
+     *
314
+     */
315
+    private function get_insert_triples( $post_id ) {
316
+
317
+        // Get the entity type.
318
+        $type = $this->entity_type_service->get( $post_id );
319
+
320
+        // Get the `linked_data` parameter.
321
+        $properties = $type['linked_data'];
322
+
323
+        // Accumulate the triples.
324
+        $triples = array();
325
+
326
+        /** @var Wordlift_Default_Sparql_Tuple_Rendition $property A {@link Wordlift_Sparql_Tuple_Rendition} instance. */
327
+        foreach ( $properties as $property ) {
328
+            foreach ( $property->get_insert_triples( $post_id ) as $triple ) {
329
+                $triples[] = $triple;
330
+            }
331
+        }
332
+
333
+        $this->log->trace( count( $properties ) . ' properties and ' . count( $triples ) . " triples found for post $post_id." );
334
+
335
+        /**
336
+         * Get the INSERT triples properties.
337
+         *
338
+         * The `wl_insert_triples` filter allows 3rd parties to extend
339
+         * the list of triples for SPARQL INSERT statements.
340
+         *
341
+         * @param array $linked_data A {@link Wordlift_Sparql_Tuple_Rendition} instances.
342
+         * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance.
343
+         * @param int $post_id The {@link WP_Post}'s id.
344
+         *
345
+         * @since 3.18.0 The hook has been renamed from `wl_insert_tuples_properties` to `wl_insert_triples`.
346
+         *
347
+         * @since 3.17.0
348
+         */
349
+        return apply_filters( 'wl_insert_triples', $triples, $this->entity_service, $post_id );
350
+    }
351
+    //</editor-fold>
352 352
 
353 353
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	 * @since 3.15.0
86 86
 	 *
87 87
 	 */
88
-	public function __construct( $entity_service, $entity_type_service, $schema_service, $sparql_service ) {
88
+	public function __construct($entity_service, $entity_type_service, $schema_service, $sparql_service) {
89 89
 
90
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Linked_Data_Service' );
90
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Linked_Data_Service');
91 91
 
92 92
 		$this->entity_service      = $entity_service;
93 93
 		$this->entity_type_service = $entity_type_service;
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
 		 *
100 100
 		 * @since 3.27.6
101 101
 		 */
102
-		add_action( 'wl_legacy_linked_data__push', array( $this, 'push' ) );
103
-		add_action( 'wl_legacy_linked_data__remove', array( $this, 'remove' ) );
102
+		add_action('wl_legacy_linked_data__push', array($this, 'push'));
103
+		add_action('wl_legacy_linked_data__remove', array($this, 'remove'));
104 104
 
105 105
 		self::$instance = $this;
106 106
 
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 	 * @since 3.15.0
132 132
 	 *
133 133
 	 */
134
-	public function push( $post_id ) {
134
+	public function push($post_id) {
135 135
 
136
-		$this->log->debug( "Pushing post $post_id..." );
136
+		$this->log->debug("Pushing post $post_id...");
137 137
 
138 138
 		// @since 3.18.0 we don't check anymore if the post is an entity, i.e.
139 139
 		// we removed the following:
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
 		//		}
145 145
 
146 146
 		// Get the post and push it to the Linked Data store.
147
-		$this->do_push( $post_id );
147
+		$this->do_push($post_id);
148 148
 
149 149
 		// Reindex the triple store if buffering is turned off.
150
-		if ( false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) {
150
+		if (false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING) {
151 151
 			wordlift_reindex_triple_store();
152 152
 		}
153 153
 
@@ -161,38 +161,38 @@  discard block
 block discarded – undo
161 161
 	 * @since 3.15.0
162 162
 	 *
163 163
 	 */
164
-	private function do_push( $post_id ) {
165
-		$this->log->debug( "Doing post $post_id push..." );
164
+	private function do_push($post_id) {
165
+		$this->log->debug("Doing post $post_id push...");
166 166
 
167 167
 		// Get the post.
168
-		$post = get_post( $post_id );
168
+		$post = get_post($post_id);
169 169
 
170 170
 		// Bail out if the post isn't found.
171
-		if ( null === $post ) {
172
-			$this->log->warn( "Post $post_id not found." );
171
+		if (null === $post) {
172
+			$this->log->warn("Post $post_id not found.");
173 173
 
174 174
 			return;
175 175
 		}
176 176
 
177 177
 		// Bail out if the post isn't published.
178
-		if ( 'publish' !== $post->post_status ) {
179
-			$this->log->info( "Post $post_id not published." );
178
+		if ('publish' !== $post->post_status) {
179
+			$this->log->info("Post $post_id not published.");
180 180
 
181 181
 			return;
182 182
 		}
183 183
 
184 184
 		// Bail out if the URI isn't valid.
185
-		if ( ! $this->has_valid_uri( $post_id ) ) {
186
-			$this->log->warn( "Post $post_id URI invalid." );
185
+		if ( ! $this->has_valid_uri($post_id)) {
186
+			$this->log->warn("Post $post_id URI invalid.");
187 187
 
188 188
 			return;
189 189
 		}
190 190
 
191 191
 		// First remove the post data.
192
-		$this->remove( $post_id );
192
+		$this->remove($post_id);
193 193
 
194 194
 		// Then execute the insert query.
195
-		$this->insert( $post_id );
195
+		$this->insert($post_id);
196 196
 	}
197 197
 
198 198
 	/**
@@ -204,18 +204,18 @@  discard block
 block discarded – undo
204 204
 	 * @since 3.15.0
205 205
 	 *
206 206
 	 */
207
-	private function has_valid_uri( $post_id ) {
207
+	private function has_valid_uri($post_id) {
208 208
 
209 209
 		// Get the entity's URI.
210
-		$uri = $this->entity_service->get_uri( $post_id );
210
+		$uri = $this->entity_service->get_uri($post_id);
211 211
 
212 212
 		// If the URI isn't found, return false.
213
-		if ( null === $uri ) {
213
+		if (null === $uri) {
214 214
 			return false;
215 215
 		}
216 216
 
217 217
 		// If the URI ends with a trailing slash, return false.
218
-		if ( '/' === substr( $uri, - 1 ) ) {
218
+		if ('/' === substr($uri, - 1)) {
219 219
 			return false;
220 220
 		}
221 221
 
@@ -231,20 +231,20 @@  discard block
 block discarded – undo
231 231
 	 * @since 3.18.0
232 232
 	 *
233 233
 	 */
234
-	public function remove( $post_id ) {
234
+	public function remove($post_id) {
235 235
 		$delete_query = '';
236 236
 
237 237
 		// Get the delete statements.
238
-		$triples = $this->get_delete_triples( $post_id );
238
+		$triples = $this->get_delete_triples($post_id);
239 239
 
240 240
 		// Loop through all triples and add the statement to delete query.
241
-		foreach ( $triples as $item ) {
241
+		foreach ($triples as $item) {
242 242
 			$delete_query .= "DELETE { $item } WHERE { $item }; \n";
243 243
 		}
244 244
 
245
-		$this->log->trace( "Delete Query generated [ $delete_query ]." );
245
+		$this->log->trace("Delete Query generated [ $delete_query ].");
246 246
 
247
-		$this->sparql_service->execute( $delete_query );
247
+		$this->sparql_service->execute($delete_query);
248 248
 	}
249 249
 
250 250
 	/**
@@ -255,19 +255,19 @@  discard block
 block discarded – undo
255 255
 	 * @since 3.18.0
256 256
 	 *
257 257
 	 */
258
-	private function insert( $post_id ) {
258
+	private function insert($post_id) {
259 259
 		// Get the insert statements.
260
-		$insert_triples = $this->get_insert_triples( $post_id );
260
+		$insert_triples = $this->get_insert_triples($post_id);
261 261
 
262 262
 		// Convert all statements to single string.
263
-		$insert_query_body = implode( "\n", $insert_triples );
263
+		$insert_query_body = implode("\n", $insert_triples);
264 264
 
265 265
 		// Build the insert query.
266 266
 		$insert_query = "INSERT DATA { $insert_query_body };";
267 267
 
268
-		$this->log->trace( "Insert Query generated [ $insert_query ]." );
268
+		$this->log->trace("Insert Query generated [ $insert_query ].");
269 269
 
270
-		$this->sparql_service->execute( $insert_query );
270
+		$this->sparql_service->execute($insert_query);
271 271
 	}
272 272
 
273 273
 	/**
@@ -279,15 +279,15 @@  discard block
 block discarded – undo
279 279
 	 * @since 3.18.0
280 280
 	 *
281 281
 	 */
282
-	private function get_delete_triples( $post_id ) {
282
+	private function get_delete_triples($post_id) {
283 283
 		$delete_triples = array();
284 284
 
285 285
 		// Loop through all renditions and get the triples.
286
-		foreach ( $this->schema_service->get_renditions() as $rendition ) {
286
+		foreach ($this->schema_service->get_renditions() as $rendition) {
287 287
 			// Push the rendition delete triple to $delete_triples.
288 288
 			$delete_triples = array_merge(
289 289
 				$delete_triples,
290
-				(array) $rendition->get_delete_triples( $post_id )
290
+				(array) $rendition->get_delete_triples($post_id)
291 291
 			);
292 292
 		}
293 293
 
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 		 * @since 3.18.0
301 301
 		 *
302 302
 		 */
303
-		return apply_filters( 'wl_delete_triples', array_unique( $delete_triples ), $post_id );
303
+		return apply_filters('wl_delete_triples', array_unique($delete_triples), $post_id);
304 304
 	}
305 305
 
306 306
 	/**
@@ -312,10 +312,10 @@  discard block
 block discarded – undo
312 312
 	 * @since 3.15.0
313 313
 	 *
314 314
 	 */
315
-	private function get_insert_triples( $post_id ) {
315
+	private function get_insert_triples($post_id) {
316 316
 
317 317
 		// Get the entity type.
318
-		$type = $this->entity_type_service->get( $post_id );
318
+		$type = $this->entity_type_service->get($post_id);
319 319
 
320 320
 		// Get the `linked_data` parameter.
321 321
 		$properties = $type['linked_data'];
@@ -324,13 +324,13 @@  discard block
 block discarded – undo
324 324
 		$triples = array();
325 325
 
326 326
 		/** @var Wordlift_Default_Sparql_Tuple_Rendition $property A {@link Wordlift_Sparql_Tuple_Rendition} instance. */
327
-		foreach ( $properties as $property ) {
328
-			foreach ( $property->get_insert_triples( $post_id ) as $triple ) {
327
+		foreach ($properties as $property) {
328
+			foreach ($property->get_insert_triples($post_id) as $triple) {
329 329
 				$triples[] = $triple;
330 330
 			}
331 331
 		}
332 332
 
333
-		$this->log->trace( count( $properties ) . ' properties and ' . count( $triples ) . " triples found for post $post_id." );
333
+		$this->log->trace(count($properties).' properties and '.count($triples)." triples found for post $post_id.");
334 334
 
335 335
 		/**
336 336
 		 * Get the INSERT triples properties.
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 		 *
347 347
 		 * @since 3.17.0
348 348
 		 */
349
-		return apply_filters( 'wl_insert_triples', $triples, $this->entity_service, $post_id );
349
+		return apply_filters('wl_insert_triples', $triples, $this->entity_service, $post_id);
350 350
 	}
351 351
 	//</editor-fold>
352 352
 
Please login to merge, or discard this patch.
src/wordlift.php 2 patches
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -48,16 +48,16 @@  discard block
 block discarded – undo
48 48
 
49 49
 // If this file is called directly, abort.
50 50
 if ( ! defined( 'WPINC' ) ) {
51
-	die;
51
+    die;
52 52
 }
53 53
 
54 54
 if ( apply_filters( 'wl_features__enable__dataset', false ) ) {
55
-	/*
55
+    /*
56 56
 	 * Add Composer Autoload with Mozart support.
57 57
 	 *
58 58
 	 * @since 3.27.6
59 59
 	 */
60
-	require __DIR__ . '/vendor/autoload.php';
60
+    require __DIR__ . '/vendor/autoload.php';
61 61
 }
62 62
 
63 63
 // Include WordLift constants.
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
  */
79 79
 function wl_write_log( $log ) {
80 80
 
81
-	Wordlift_Log_Service::get_instance()->debug( $log );
81
+    Wordlift_Log_Service::get_instance()->debug( $log );
82 82
 
83 83
 }
84 84
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
  */
96 96
 function wl_write_log_hide_key( $text ) {
97 97
 
98
-	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
98
+    return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
99 99
 }
100 100
 
101 101
 /**
@@ -103,21 +103,21 @@  discard block
 block discarded – undo
103 103
  * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/
104 104
  */
105 105
 function wordlift_allowed_post_tags() {
106
-	global $allowedposttags;
107
-
108
-	$tags           = array( 'span' );
109
-	$new_attributes = array(
110
-		'itemscope' => array(),
111
-		'itemtype'  => array(),
112
-		'itemprop'  => array(),
113
-		'itemid'    => array(),
114
-	);
115
-
116
-	foreach ( $tags as $tag ) {
117
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
118
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
119
-		}
120
-	}
106
+    global $allowedposttags;
107
+
108
+    $tags           = array( 'span' );
109
+    $new_attributes = array(
110
+        'itemscope' => array(),
111
+        'itemtype'  => array(),
112
+        'itemprop'  => array(),
113
+        'itemid'    => array(),
114
+    );
115
+
116
+    foreach ( $tags as $tag ) {
117
+        if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
118
+            $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
119
+        }
120
+    }
121 121
 }
122 122
 
123 123
 // add allowed post tags.
@@ -128,18 +128,18 @@  discard block
 block discarded – undo
128 128
  */
129 129
 function wordlift_admin_enqueue_scripts() {
130 130
 
131
-	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
132
-	wp_enqueue_script( 'wpdialogs' );
133
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
131
+    // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
132
+    wp_enqueue_script( 'wpdialogs' );
133
+    wp_enqueue_style( 'wp-jquery-ui-dialog' );
134 134
 
135
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
135
+    wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
136 136
 
137
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
137
+    wp_enqueue_script( 'jquery-ui-autocomplete' );
138 138
 
139
-	// Disable auto-save for custom entity posts only
140
-	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
141
-		wp_dequeue_script( 'autosave' );
142
-	}
139
+    // Disable auto-save for custom entity posts only
140
+    if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
141
+        wp_dequeue_script( 'autosave' );
142
+    }
143 143
 
144 144
 }
145 145
 
@@ -155,18 +155,18 @@  discard block
 block discarded – undo
155 155
  */
156 156
 function wordlift_allowed_html( $allowedtags, $context ) {
157 157
 
158
-	if ( 'post' !== $context ) {
159
-		return $allowedtags;
160
-	}
161
-
162
-	return array_merge_recursive( $allowedtags, array(
163
-		'span' => array(
164
-			'itemscope' => true,
165
-			'itemtype'  => true,
166
-			'itemid'    => true,
167
-			'itemprop'  => true,
168
-		),
169
-	) );
158
+    if ( 'post' !== $context ) {
159
+        return $allowedtags;
160
+    }
161
+
162
+    return array_merge_recursive( $allowedtags, array(
163
+        'span' => array(
164
+            'itemscope' => true,
165
+            'itemtype'  => true,
166
+            'itemid'    => true,
167
+            'itemprop'  => true,
168
+        ),
169
+    ) );
170 170
 }
171 171
 
172 172
 add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
@@ -180,16 +180,16 @@  discard block
 block discarded – undo
180 180
  */
181 181
 function wl_get_coordinates( $post_id ) {
182 182
 
183
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
184
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
183
+    $latitude  = wl_schema_get_value( $post_id, 'latitude' );
184
+    $longitude = wl_schema_get_value( $post_id, 'longitude' );
185 185
 
186
-	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific
187
-	// place on the globe:"The zero/zero point of this system is located in the
188
-	// Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
189
-	return array(
190
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
191
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
192
-	);
186
+    // DO NOT set latitude/longitude to 0/0 as default values. It's a specific
187
+    // place on the globe:"The zero/zero point of this system is located in the
188
+    // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
189
+    return array(
190
+        'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
191
+        'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
192
+    );
193 193
 }
194 194
 
195 195
 /**
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
  */
204 204
 function wl_get_image_urls( $post_id ) {
205 205
 
206
-	return Wordlift_Storage_Factory::get_instance()
207
-	                               ->post_images()
208
-	                               ->get( $post_id );
206
+    return Wordlift_Storage_Factory::get_instance()
207
+                                    ->post_images()
208
+                                    ->get( $post_id );
209 209
 
210 210
 }
211 211
 
@@ -219,24 +219,24 @@  discard block
 block discarded – undo
219 219
  */
220 220
 function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
221 221
 
222
-	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
222
+    // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
223 223
 
224
-	$posts = get_posts( array(
225
-		'post_type'      => 'attachment',
226
-		'posts_per_page' => 1,
227
-		'post_status'    => 'any',
228
-		'post_parent'    => $parent_post_id,
229
-		'meta_key'       => 'wl_source_url',
230
-		'meta_value'     => $source_url,
231
-	) );
224
+    $posts = get_posts( array(
225
+        'post_type'      => 'attachment',
226
+        'posts_per_page' => 1,
227
+        'post_status'    => 'any',
228
+        'post_parent'    => $parent_post_id,
229
+        'meta_key'       => 'wl_source_url',
230
+        'meta_value'     => $source_url,
231
+    ) );
232 232
 
233
-	// Return the found post.
234
-	if ( 1 === count( $posts ) ) {
235
-		return $posts[0];
236
-	}
233
+    // Return the found post.
234
+    if ( 1 === count( $posts ) ) {
235
+        return $posts[0];
236
+    }
237 237
 
238
-	// Return null.
239
-	return null;
238
+    // Return null.
239
+    return null;
240 240
 }
241 241
 
242 242
 /**
@@ -247,8 +247,8 @@  discard block
 block discarded – undo
247 247
  */
248 248
 function wl_set_source_url( $post_id, $source_url ) {
249 249
 
250
-	delete_post_meta( $post_id, 'wl_source_url' );
251
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
250
+    delete_post_meta( $post_id, 'wl_source_url' );
251
+    add_post_meta( $post_id, 'wl_source_url', $source_url );
252 252
 }
253 253
 
254 254
 /**
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
  */
266 266
 function wl_sanitize_uri_path( $path, $char = '_' ) {
267 267
 
268
-	return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
268
+    return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
269 269
 }
270 270
 
271 271
 /**
@@ -277,47 +277,47 @@  discard block
 block discarded – undo
277 277
  */
278 278
 function wl_replace_item_id_with_uri( $content ) {
279 279
 
280
-	$log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' );
281
-	$log->trace( 'Replacing item IDs with URIs...' );
280
+    $log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' );
281
+    $log->trace( 'Replacing item IDs with URIs...' );
282 282
 
283
-	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
284
-	$content = stripslashes( $content );
283
+    // Strip slashes, see https://core.trac.wordpress.org/ticket/21767
284
+    $content = stripslashes( $content );
285 285
 
286
-	// If any match are found.
287
-	$matches = array();
288
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
286
+    // If any match are found.
287
+    $matches = array();
288
+    if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
289 289
 
290
-		foreach ( $matches as $match ) {
290
+        foreach ( $matches as $match ) {
291 291
 
292
-			// Get the item ID.
293
-			$item_id = $match[1];
292
+            // Get the item ID.
293
+            $item_id = $match[1];
294 294
 
295
-			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
296
-			$post = Wordlift_Entity_Service::get_instance()
297
-			                               ->get_entity_post_by_uri( $item_id );
295
+            // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
296
+            $post = Wordlift_Entity_Service::get_instance()
297
+                                            ->get_entity_post_by_uri( $item_id );
298 298
 
299
-			// If no entity is found, continue to the next one.
300
-			if ( null === $post ) {
301
-				continue;
302
-			}
299
+            // If no entity is found, continue to the next one.
300
+            if ( null === $post ) {
301
+                continue;
302
+            }
303 303
 
304
-			// Get the URI for that post.
305
-			$uri = wl_get_entity_uri( $post->ID );
304
+            // Get the URI for that post.
305
+            $uri = wl_get_entity_uri( $post->ID );
306 306
 
307
-			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
307
+            // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
308 308
 
309
-			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
310
-			if ( $item_id !== $uri ) {
311
-				$uri_e   = esc_html( $uri );
312
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
313
-			}
314
-		}
315
-	}
309
+            // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
310
+            if ( $item_id !== $uri ) {
311
+                $uri_e   = esc_html( $uri );
312
+                $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
313
+            }
314
+        }
315
+    }
316 316
 
317
-	// Reapply slashes.
318
-	$content = addslashes( $content );
317
+    // Reapply slashes.
318
+    $content = addslashes( $content );
319 319
 
320
-	return $content;
320
+    return $content;
321 321
 }
322 322
 
323 323
 add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
@@ -380,24 +380,24 @@  discard block
 block discarded – undo
380 380
  */
381 381
 function activate_wordlift() {
382 382
 
383
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
383
+    $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
384 384
 
385
-	$log->info( 'Activating WordLift...' );
385
+    $log->info( 'Activating WordLift...' );
386 386
 
387
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
388
-	Wordlift_Activator::activate();
387
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
388
+    Wordlift_Activator::activate();
389 389
 
390
-	/**
391
-	 * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
392
-	 *
393
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
394
-	 * @since 3.19.2
395
-	 */
396
-	Wordlift_Http_Api::activate();
390
+    /**
391
+     * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
392
+     *
393
+     * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
394
+     * @since 3.19.2
395
+     */
396
+    Wordlift_Http_Api::activate();
397 397
 
398
-	// Ensure the post type is registered before flushing the rewrite rules.
399
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
400
-	flush_rewrite_rules();
398
+    // Ensure the post type is registered before flushing the rewrite rules.
399
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
400
+    flush_rewrite_rules();
401 401
 }
402 402
 
403 403
 /**
@@ -406,11 +406,11 @@  discard block
 block discarded – undo
406 406
  */
407 407
 function deactivate_wordlift() {
408 408
 
409
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
410
-	Wordlift_Deactivator::deactivate();
411
-	Wordlift_Http_Api::deactivate();
412
-	Ttl_Cache_Cleaner::deactivate();
413
-	flush_rewrite_rules();
409
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
410
+    Wordlift_Deactivator::deactivate();
411
+    Wordlift_Http_Api::deactivate();
412
+    Ttl_Cache_Cleaner::deactivate();
413
+    flush_rewrite_rules();
414 414
 
415 415
 }
416 416
 
@@ -433,93 +433,93 @@  discard block
 block discarded – undo
433 433
  * @since    1.0.0
434 434
  */
435 435
 function run_wordlift() {
436
-	/**
437
-	 * Filter: wl_feature__enable__widgets.
438
-	 *
439
-	 * @param bool whether the widgets needed to be registered, defaults to true.
440
-	 *
441
-	 * @return bool
442
-	 * @since 3.27.6
443
-	 */
444
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
445
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
446
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
447
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
448
-	}
449
-	add_filter( 'widget_text', 'do_shortcode' );
450
-
451
-
452
-	/**
453
-	 * Filter: wl_feature__enable__analysis
454
-	 *
455
-	 * @param bool Whether to send api request to analysis or not
456
-	 *
457
-	 * @return bool
458
-	 * @since 3.27.6
459
-	 */
460
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
461
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
462
-	} else {
463
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
464
-	}
465
-
466
-	/*
436
+    /**
437
+     * Filter: wl_feature__enable__widgets.
438
+     *
439
+     * @param bool whether the widgets needed to be registered, defaults to true.
440
+     *
441
+     * @return bool
442
+     * @since 3.27.6
443
+     */
444
+    if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
445
+        add_action( 'widgets_init', 'wl_register_chord_widget' );
446
+        add_action( 'widgets_init', 'wl_register_geo_widget' );
447
+        add_action( 'widgets_init', 'wl_register_timeline_widget' );
448
+    }
449
+    add_filter( 'widget_text', 'do_shortcode' );
450
+
451
+
452
+    /**
453
+     * Filter: wl_feature__enable__analysis
454
+     *
455
+     * @param bool Whether to send api request to analysis or not
456
+     *
457
+     * @return bool
458
+     * @since 3.27.6
459
+     */
460
+    if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
461
+        add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
462
+    } else {
463
+        add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
464
+    }
465
+
466
+    /*
467 467
 	 * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http.
468 468
 	 *
469 469
 	 * @since 3.21.2
470 470
 	 */
471
-	wordlift_plugin_autoload_register();
471
+    wordlift_plugin_autoload_register();
472 472
 
473
-	$plugin = new Wordlift();
474
-	$plugin->run();
473
+    $plugin = new Wordlift();
474
+    $plugin->run();
475 475
 
476
-	// Initialize the TTL Cache Cleaner.
477
-	new Ttl_Cache_Cleaner();
476
+    // Initialize the TTL Cache Cleaner.
477
+    new Ttl_Cache_Cleaner();
478 478
 
479
-	// Load the new Post Adapter.
480
-	new Post_Adapter();
479
+    // Load the new Post Adapter.
480
+    new Post_Adapter();
481 481
 
482
-	// Load the API Data Hooks.
483
-	new Api_Data_Hooks();
482
+    // Load the API Data Hooks.
483
+    new Api_Data_Hooks();
484 484
 
485
-	add_action( 'plugins_loaded', function () use ( $plugin ) {
486
-		// Licenses Images.
487
-		$user_agent                   = User_Agent::get_user_agent();
488
-		$wordlift_key                 = Wordlift_Configuration_Service::get_instance()->get_key();
489
-		$api_service                  = new Default_Api_Service( apply_filters( 'wl_api_base_url', 'https://api.wordlift.io' ), 60, $user_agent, $wordlift_key );
490
-		$image_license_factory        = new Image_License_Factory();
491
-		$image_license_service        = new Image_License_Service( $api_service, $image_license_factory );
492
-		$image_license_cache          = new Ttl_Cache( 'image-license', 86400 * 30 ); // 30 days.
493
-		$cached_image_license_service = new Cached_Image_License_Service( $image_license_service, $image_license_cache );
485
+    add_action( 'plugins_loaded', function () use ( $plugin ) {
486
+        // Licenses Images.
487
+        $user_agent                   = User_Agent::get_user_agent();
488
+        $wordlift_key                 = Wordlift_Configuration_Service::get_instance()->get_key();
489
+        $api_service                  = new Default_Api_Service( apply_filters( 'wl_api_base_url', 'https://api.wordlift.io' ), 60, $user_agent, $wordlift_key );
490
+        $image_license_factory        = new Image_License_Factory();
491
+        $image_license_service        = new Image_License_Service( $api_service, $image_license_factory );
492
+        $image_license_cache          = new Ttl_Cache( 'image-license', 86400 * 30 ); // 30 days.
493
+        $cached_image_license_service = new Cached_Image_License_Service( $image_license_service, $image_license_cache );
494 494
 
495
-		$image_license_scheduler       = new Image_License_Scheduler( $image_license_service, $image_license_cache );
496
-		$image_license_cleanup_service = new Image_License_Cleanup_Service();
495
+        $image_license_scheduler       = new Image_License_Scheduler( $image_license_service, $image_license_cache );
496
+        $image_license_cleanup_service = new Image_License_Cleanup_Service();
497 497
 
498
-		// Get the cached data. If we have cached data, we load the notifier.
499
-		$image_license_data = $image_license_cache->get( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES );
500
-		if ( null !== $image_license_data ) {
501
-			$image_license_page = new Image_License_Page( $image_license_data, Wordlift::get_instance()->get_version() );
502
-			new Image_License_Notifier( $image_license_data, $image_license_page );
503
-		}
498
+        // Get the cached data. If we have cached data, we load the notifier.
499
+        $image_license_data = $image_license_cache->get( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES );
500
+        if ( null !== $image_license_data ) {
501
+            $image_license_page = new Image_License_Page( $image_license_data, Wordlift::get_instance()->get_version() );
502
+            new Image_License_Notifier( $image_license_data, $image_license_page );
503
+        }
504 504
 
505
-		$remove_all_images_task         = new Remove_All_Images_Task( $cached_image_license_service );
506
-		$remove_all_images_task_adapter = new Task_Ajax_Adapter( $remove_all_images_task );
505
+        $remove_all_images_task         = new Remove_All_Images_Task( $cached_image_license_service );
506
+        $remove_all_images_task_adapter = new Task_Ajax_Adapter( $remove_all_images_task );
507 507
 
508
-		$reload_data_task         = new Reload_Data_Task();
509
-		$reload_data_task_adapter = new Task_Ajax_Adapter( $reload_data_task );
508
+        $reload_data_task         = new Reload_Data_Task();
509
+        $reload_data_task_adapter = new Task_Ajax_Adapter( $reload_data_task );
510 510
 
511
-		$add_license_caption_or_remove_task         = new Add_License_Caption_Or_Remove_Task( $cached_image_license_service );
512
-		$add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter( $add_license_caption_or_remove_task );
511
+        $add_license_caption_or_remove_task         = new Add_License_Caption_Or_Remove_Task( $cached_image_license_service );
512
+        $add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter( $add_license_caption_or_remove_task );
513 513
 
514
-		$remove_all_images_task_page             = new Remove_All_Images_Page( new Task_Ajax_Adapters_Registry( $remove_all_images_task_adapter ), $plugin->get_version() );
515
-		$reload_data_task_page                   = new Reload_Data_Page( new Task_Ajax_Adapters_Registry( $reload_data_task_adapter ), $plugin->get_version() );
516
-		$add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page( new Task_Ajax_Adapters_Registry( $add_license_caption_or_remove_task_adapter ), $plugin->get_version() );
514
+        $remove_all_images_task_page             = new Remove_All_Images_Page( new Task_Ajax_Adapters_Registry( $remove_all_images_task_adapter ), $plugin->get_version() );
515
+        $reload_data_task_page                   = new Reload_Data_Page( new Task_Ajax_Adapters_Registry( $reload_data_task_adapter ), $plugin->get_version() );
516
+        $add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page( new Task_Ajax_Adapters_Registry( $add_license_caption_or_remove_task_adapter ), $plugin->get_version() );
517 517
 
518
-		new Wordlift_Products_Navigator_Shortcode_REST();
518
+        new Wordlift_Products_Navigator_Shortcode_REST();
519 519
 
520
-		// Register the Dataset module, requires `$api_service`.
521
-		require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
522
-	} );
520
+        // Register the Dataset module, requires `$api_service`.
521
+        require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
522
+    } );
523 523
 
524 524
 }
525 525
 
@@ -533,45 +533,45 @@  discard block
 block discarded – undo
533 533
  */
534 534
 function wordlift_plugin_autoload_register() {
535 535
 
536
-	spl_autoload_register( function ( $class_name ) {
536
+    spl_autoload_register( function ( $class_name ) {
537 537
 
538
-		// Bail out if these are not our classes.
539
-		if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
540
-			return false;
541
-		}
538
+        // Bail out if these are not our classes.
539
+        if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
540
+            return false;
541
+        }
542 542
 
543
-		$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
543
+        $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
544 544
 
545
-		preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
545
+        preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
546 546
 
547
-		$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
548
-		$file = 'class-' . $matches[2] . '.php';
547
+        $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
548
+        $file = 'class-' . $matches[2] . '.php';
549 549
 
550
-		$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
550
+        $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
551 551
 
552
-		if ( ! file_exists( $full_path ) ) {
553
-			echo( "Class $class_name not found at $full_path." );
552
+        if ( ! file_exists( $full_path ) ) {
553
+            echo( "Class $class_name not found at $full_path." );
554 554
 
555
-			return false;
556
-		}
555
+            return false;
556
+        }
557 557
 
558
-		require_once $full_path;
558
+        require_once $full_path;
559 559
 
560
-		return true;
561
-	} );
560
+        return true;
561
+    } );
562 562
 
563 563
 }
564 564
 
565 565
 function wl_block_categories( $categories, $post ) {
566
-	return array_merge(
567
-		$categories,
568
-		array(
569
-			array(
570
-				'slug'  => 'wordlift',
571
-				'title' => __( 'WordLift', 'wordlift' ),
572
-			),
573
-		)
574
-	);
566
+    return array_merge(
567
+        $categories,
568
+        array(
569
+            array(
570
+                'slug'  => 'wordlift',
571
+                'title' => __( 'WordLift', 'wordlift' ),
572
+            ),
573
+        )
574
+    );
575 575
 }
576 576
 
577 577
 add_filter( 'block_categories', 'wl_block_categories', 10, 2 );
Please login to merge, or discard this patch.
Spacing   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -47,24 +47,24 @@  discard block
 block discarded – undo
47 47
 use Wordlift\Tasks\Task_Ajax_Adapters_Registry;
48 48
 
49 49
 // If this file is called directly, abort.
50
-if ( ! defined( 'WPINC' ) ) {
50
+if ( ! defined('WPINC')) {
51 51
 	die;
52 52
 }
53 53
 
54
-if ( apply_filters( 'wl_features__enable__dataset', false ) ) {
54
+if (apply_filters('wl_features__enable__dataset', false)) {
55 55
 	/*
56 56
 	 * Add Composer Autoload with Mozart support.
57 57
 	 *
58 58
 	 * @since 3.27.6
59 59
 	 */
60
-	require __DIR__ . '/vendor/autoload.php';
60
+	require __DIR__.'/vendor/autoload.php';
61 61
 }
62 62
 
63 63
 // Include WordLift constants.
64
-require_once( 'wordlift_constants.php' );
64
+require_once('wordlift_constants.php');
65 65
 
66 66
 // Load modules.
67
-require_once( 'modules/core/wordlift_core.php' );
67
+require_once('modules/core/wordlift_core.php');
68 68
 
69 69
 /**
70 70
  * Log to the debug.log file.
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
  * @deprecated use Wordlift_Log_Service::get_instance()->info( $log );
77 77
  *
78 78
  */
79
-function wl_write_log( $log ) {
79
+function wl_write_log($log) {
80 80
 
81
-	Wordlift_Log_Service::get_instance()->debug( $log );
81
+	Wordlift_Log_Service::get_instance()->debug($log);
82 82
 
83 83
 }
84 84
 
@@ -93,9 +93,9 @@  discard block
 block discarded – undo
93 93
  * @since 3.0.0
94 94
  *
95 95
  */
96
-function wl_write_log_hide_key( $text ) {
96
+function wl_write_log_hide_key($text) {
97 97
 
98
-	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
98
+	return str_ireplace(wl_configuration_get_key(), '<hidden>', $text);
99 99
 }
100 100
 
101 101
 /**
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 function wordlift_allowed_post_tags() {
106 106
 	global $allowedposttags;
107 107
 
108
-	$tags           = array( 'span' );
108
+	$tags           = array('span');
109 109
 	$new_attributes = array(
110 110
 		'itemscope' => array(),
111 111
 		'itemtype'  => array(),
@@ -113,15 +113,15 @@  discard block
 block discarded – undo
113 113
 		'itemid'    => array(),
114 114
 	);
115 115
 
116
-	foreach ( $tags as $tag ) {
117
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
118
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
116
+	foreach ($tags as $tag) {
117
+		if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) {
118
+			$allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes);
119 119
 		}
120 120
 	}
121 121
 }
122 122
 
123 123
 // add allowed post tags.
124
-add_action( 'init', 'wordlift_allowed_post_tags' );
124
+add_action('init', 'wordlift_allowed_post_tags');
125 125
 
126 126
 /**
127 127
  * Register additional scripts for the admin UI.
@@ -129,21 +129,21 @@  discard block
 block discarded – undo
129 129
 function wordlift_admin_enqueue_scripts() {
130 130
 
131 131
 	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
132
-	wp_enqueue_script( 'wpdialogs' );
133
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
132
+	wp_enqueue_script('wpdialogs');
133
+	wp_enqueue_style('wp-jquery-ui-dialog');
134 134
 
135
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
135
+	wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css');
136 136
 
137
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
137
+	wp_enqueue_script('jquery-ui-autocomplete');
138 138
 
139 139
 	// Disable auto-save for custom entity posts only
140
-	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
141
-		wp_dequeue_script( 'autosave' );
140
+	if (Wordlift_Entity_Service::TYPE_NAME === get_post_type()) {
141
+		wp_dequeue_script('autosave');
142 142
 	}
143 143
 
144 144
 }
145 145
 
146
-add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
146
+add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts');
147 147
 
148 148
 /**
149 149
  * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes.
@@ -153,23 +153,23 @@  discard block
 block discarded – undo
153 153
  *
154 154
  * @return array An array which contains allowed microdata attributes.
155 155
  */
156
-function wordlift_allowed_html( $allowedtags, $context ) {
156
+function wordlift_allowed_html($allowedtags, $context) {
157 157
 
158
-	if ( 'post' !== $context ) {
158
+	if ('post' !== $context) {
159 159
 		return $allowedtags;
160 160
 	}
161 161
 
162
-	return array_merge_recursive( $allowedtags, array(
162
+	return array_merge_recursive($allowedtags, array(
163 163
 		'span' => array(
164 164
 			'itemscope' => true,
165 165
 			'itemtype'  => true,
166 166
 			'itemid'    => true,
167 167
 			'itemprop'  => true,
168 168
 		),
169
-	) );
169
+	));
170 170
 }
171 171
 
172
-add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
172
+add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2);
173 173
 
174 174
 /**
175 175
  * Get the coordinates for the specified post ID.
@@ -178,17 +178,17 @@  discard block
 block discarded – undo
178 178
  *
179 179
  * @return array|null An array of coordinates or null.
180 180
  */
181
-function wl_get_coordinates( $post_id ) {
181
+function wl_get_coordinates($post_id) {
182 182
 
183
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
184
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
183
+	$latitude  = wl_schema_get_value($post_id, 'latitude');
184
+	$longitude = wl_schema_get_value($post_id, 'longitude');
185 185
 
186 186
 	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific
187 187
 	// place on the globe:"The zero/zero point of this system is located in the
188 188
 	// Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
189 189
 	return array(
190
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
191
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
190
+		'latitude'  => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '',
191
+		'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : '',
192 192
 	);
193 193
 }
194 194
 
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
  * @deprecated use Wordlift_Storage_Factory::get_instance()->post_images()->get( $post_id )
202 202
  *
203 203
  */
204
-function wl_get_image_urls( $post_id ) {
204
+function wl_get_image_urls($post_id) {
205 205
 
206 206
 	return Wordlift_Storage_Factory::get_instance()
207 207
 	                               ->post_images()
208
-	                               ->get( $post_id );
208
+	                               ->get($post_id);
209 209
 
210 210
 }
211 211
 
@@ -217,21 +217,21 @@  discard block
 block discarded – undo
217 217
  *
218 218
  * @return WP_Post|null A post instance or null if not found.
219 219
  */
220
-function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
220
+function wl_get_attachment_for_source_url($parent_post_id, $source_url) {
221 221
 
222 222
 	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
223 223
 
224
-	$posts = get_posts( array(
224
+	$posts = get_posts(array(
225 225
 		'post_type'      => 'attachment',
226 226
 		'posts_per_page' => 1,
227 227
 		'post_status'    => 'any',
228 228
 		'post_parent'    => $parent_post_id,
229 229
 		'meta_key'       => 'wl_source_url',
230 230
 		'meta_value'     => $source_url,
231
-	) );
231
+	));
232 232
 
233 233
 	// Return the found post.
234
-	if ( 1 === count( $posts ) ) {
234
+	if (1 === count($posts)) {
235 235
 		return $posts[0];
236 236
 	}
237 237
 
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
  * @param int $post_id The post ID.
246 246
  * @param string $source_url The source URL.
247 247
  */
248
-function wl_set_source_url( $post_id, $source_url ) {
248
+function wl_set_source_url($post_id, $source_url) {
249 249
 
250
-	delete_post_meta( $post_id, 'wl_source_url' );
251
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
250
+	delete_post_meta($post_id, 'wl_source_url');
251
+	add_post_meta($post_id, 'wl_source_url', $source_url);
252 252
 }
253 253
 
254 254
 /**
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
  * @see        https://codex.wordpress.org/Function_Reference/sanitize_title
264 264
  *
265 265
  */
266
-function wl_sanitize_uri_path( $path, $char = '_' ) {
266
+function wl_sanitize_uri_path($path, $char = '_') {
267 267
 
268
-	return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
268
+	return Wordlift_Uri_Service::get_instance()->sanitize_path($path, $char);
269 269
 }
270 270
 
271 271
 /**
@@ -275,104 +275,104 @@  discard block
 block discarded – undo
275 275
  *
276 276
  * @return string The updated post content.
277 277
  */
278
-function wl_replace_item_id_with_uri( $content ) {
278
+function wl_replace_item_id_with_uri($content) {
279 279
 
280
-	$log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' );
281
-	$log->trace( 'Replacing item IDs with URIs...' );
280
+	$log = Wordlift_Log_Service::get_logger('wl_replace_item_id_with_uri');
281
+	$log->trace('Replacing item IDs with URIs...');
282 282
 
283 283
 	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
284
-	$content = stripslashes( $content );
284
+	$content = stripslashes($content);
285 285
 
286 286
 	// If any match are found.
287 287
 	$matches = array();
288
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
288
+	if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) {
289 289
 
290
-		foreach ( $matches as $match ) {
290
+		foreach ($matches as $match) {
291 291
 
292 292
 			// Get the item ID.
293 293
 			$item_id = $match[1];
294 294
 
295 295
 			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
296 296
 			$post = Wordlift_Entity_Service::get_instance()
297
-			                               ->get_entity_post_by_uri( $item_id );
297
+			                               ->get_entity_post_by_uri($item_id);
298 298
 
299 299
 			// If no entity is found, continue to the next one.
300
-			if ( null === $post ) {
300
+			if (null === $post) {
301 301
 				continue;
302 302
 			}
303 303
 
304 304
 			// Get the URI for that post.
305
-			$uri = wl_get_entity_uri( $post->ID );
305
+			$uri = wl_get_entity_uri($post->ID);
306 306
 
307 307
 			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
308 308
 
309 309
 			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
310
-			if ( $item_id !== $uri ) {
311
-				$uri_e   = esc_html( $uri );
312
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
310
+			if ($item_id !== $uri) {
311
+				$uri_e   = esc_html($uri);
312
+				$content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content);
313 313
 			}
314 314
 		}
315 315
 	}
316 316
 
317 317
 	// Reapply slashes.
318
-	$content = addslashes( $content );
318
+	$content = addslashes($content);
319 319
 
320 320
 	return $content;
321 321
 }
322 322
 
323
-add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
323
+add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1);
324 324
 
325
-require_once( 'wordlift_entity_functions.php' );
325
+require_once('wordlift_entity_functions.php');
326 326
 
327 327
 // add editor related methods.
328
-require_once( 'wordlift_editor.php' );
328
+require_once('wordlift_editor.php');
329 329
 
330 330
 // add the WordLift entity custom type.
331
-require_once( 'wordlift_entity_type.php' );
331
+require_once('wordlift_entity_type.php');
332 332
 
333 333
 // add callbacks on post save to notify data changes from wp to redlink triple store
334
-require_once( 'wordlift_to_redlink_data_push_callbacks.php' );
334
+require_once('wordlift_to_redlink_data_push_callbacks.php');
335 335
 
336
-require_once( 'modules/configuration/wordlift_configuration_settings.php' );
336
+require_once('modules/configuration/wordlift_configuration_settings.php');
337 337
 
338 338
 // Load modules
339
-require_once( 'modules/analyzer/wordlift_analyzer.php' );
340
-require_once( 'modules/linked_data/wordlift_linked_data.php' );
341
-require_once( 'modules/prefixes/wordlift_prefixes.php' );
339
+require_once('modules/analyzer/wordlift_analyzer.php');
340
+require_once('modules/linked_data/wordlift_linked_data.php');
341
+require_once('modules/prefixes/wordlift_prefixes.php');
342 342
 
343 343
 // Shortcodes
344 344
 
345
-require_once( 'modules/geo_widget/wordlift_geo_widget.php' );
346
-require_once( 'shortcodes/class-wordlift-shortcode-rest.php' );
347
-require_once( 'shortcodes/wordlift_shortcode_chord.php' );
348
-require_once( 'shortcodes/wordlift_shortcode_geomap.php' );
349
-require_once( 'shortcodes/wordlift_shortcode_field.php' );
350
-require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' );
351
-require_once( 'shortcodes/wordlift_shortcode_navigator.php' );
352
-require_once( 'shortcodes/class-wordlift-products-navigator-shortcode-rest.php' );
345
+require_once('modules/geo_widget/wordlift_geo_widget.php');
346
+require_once('shortcodes/class-wordlift-shortcode-rest.php');
347
+require_once('shortcodes/wordlift_shortcode_chord.php');
348
+require_once('shortcodes/wordlift_shortcode_geomap.php');
349
+require_once('shortcodes/wordlift_shortcode_field.php');
350
+require_once('shortcodes/wordlift_shortcode_faceted_search.php');
351
+require_once('shortcodes/wordlift_shortcode_navigator.php');
352
+require_once('shortcodes/class-wordlift-products-navigator-shortcode-rest.php');
353 353
 
354
-require_once( 'widgets/wordlift_widget_geo.php' );
355
-require_once( 'widgets/class-wordlift-chord-widget.php' );
356
-require_once( 'widgets/wordlift_widget_timeline.php' );
354
+require_once('widgets/wordlift_widget_geo.php');
355
+require_once('widgets/class-wordlift-chord-widget.php');
356
+require_once('widgets/wordlift_widget_timeline.php');
357 357
 
358
-require_once( 'wordlift_redlink.php' );
358
+require_once('wordlift_redlink.php');
359 359
 
360 360
 // Add admin functions.
361 361
 // TODO: find a way to make 'admin' UI tests work.
362 362
 //if ( is_admin() ) {
363 363
 
364
-require_once( 'admin/wordlift_admin.php' );
365
-require_once( 'admin/wordlift_admin_edit_post.php' );
366
-require_once( 'admin/wordlift_admin_save_post.php' );
364
+require_once('admin/wordlift_admin.php');
365
+require_once('admin/wordlift_admin_edit_post.php');
366
+require_once('admin/wordlift_admin_save_post.php');
367 367
 
368 368
 // add the entities meta box.
369
-require_once( 'admin/wordlift_admin_meta_box_entities.php' );
369
+require_once('admin/wordlift_admin_meta_box_entities.php');
370 370
 
371 371
 // add the entity creation AJAX.
372
-require_once( 'admin/wordlift_admin_ajax_related_posts.php' );
372
+require_once('admin/wordlift_admin_ajax_related_posts.php');
373 373
 
374 374
 // Load the wl_chord TinyMCE button and configuration dialog.
375
-require_once( 'admin/wordlift_admin_shortcodes.php' );
375
+require_once('admin/wordlift_admin_shortcodes.php');
376 376
 
377 377
 /**
378 378
  * The code that runs during plugin activation.
@@ -380,11 +380,11 @@  discard block
 block discarded – undo
380 380
  */
381 381
 function activate_wordlift() {
382 382
 
383
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
383
+	$log = Wordlift_Log_Service::get_logger('activate_wordlift');
384 384
 
385
-	$log->info( 'Activating WordLift...' );
385
+	$log->info('Activating WordLift...');
386 386
 
387
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
387
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
388 388
 	Wordlift_Activator::activate();
389 389
 
390 390
 	/**
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
  */
407 407
 function deactivate_wordlift() {
408 408
 
409
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
409
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
410 410
 	Wordlift_Deactivator::deactivate();
411 411
 	Wordlift_Http_Api::deactivate();
412 412
 	Ttl_Cache_Cleaner::deactivate();
@@ -414,14 +414,14 @@  discard block
 block discarded – undo
414 414
 
415 415
 }
416 416
 
417
-register_activation_hook( __FILE__, 'activate_wordlift' );
418
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
417
+register_activation_hook(__FILE__, 'activate_wordlift');
418
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
419 419
 
420 420
 /**
421 421
  * The core plugin class that is used to define internationalization,
422 422
  * admin-specific hooks, and public-facing site hooks.
423 423
  */
424
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
424
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
425 425
 
426 426
 /**
427 427
  * Begins execution of the plugin.
@@ -441,12 +441,12 @@  discard block
 block discarded – undo
441 441
 	 * @return bool
442 442
 	 * @since 3.27.6
443 443
 	 */
444
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
445
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
446
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
447
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
444
+	if (apply_filters('wl_feature__enable__widgets', true)) {
445
+		add_action('widgets_init', 'wl_register_chord_widget');
446
+		add_action('widgets_init', 'wl_register_geo_widget');
447
+		add_action('widgets_init', 'wl_register_timeline_widget');
448 448
 	}
449
-	add_filter( 'widget_text', 'do_shortcode' );
449
+	add_filter('widget_text', 'do_shortcode');
450 450
 
451 451
 
452 452
 	/**
@@ -457,10 +457,10 @@  discard block
 block discarded – undo
457 457
 	 * @return bool
458 458
 	 * @since 3.27.6
459 459
 	 */
460
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
461
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
460
+	if (apply_filters('wl_feature__enable__analysis', true)) {
461
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action');
462 462
 	} else {
463
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
463
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action');
464 464
 	}
465 465
 
466 466
 	/*
@@ -482,43 +482,43 @@  discard block
 block discarded – undo
482 482
 	// Load the API Data Hooks.
483 483
 	new Api_Data_Hooks();
484 484
 
485
-	add_action( 'plugins_loaded', function () use ( $plugin ) {
485
+	add_action('plugins_loaded', function() use ($plugin) {
486 486
 		// Licenses Images.
487 487
 		$user_agent                   = User_Agent::get_user_agent();
488 488
 		$wordlift_key                 = Wordlift_Configuration_Service::get_instance()->get_key();
489
-		$api_service                  = new Default_Api_Service( apply_filters( 'wl_api_base_url', 'https://api.wordlift.io' ), 60, $user_agent, $wordlift_key );
489
+		$api_service                  = new Default_Api_Service(apply_filters('wl_api_base_url', 'https://api.wordlift.io'), 60, $user_agent, $wordlift_key);
490 490
 		$image_license_factory        = new Image_License_Factory();
491
-		$image_license_service        = new Image_License_Service( $api_service, $image_license_factory );
492
-		$image_license_cache          = new Ttl_Cache( 'image-license', 86400 * 30 ); // 30 days.
493
-		$cached_image_license_service = new Cached_Image_License_Service( $image_license_service, $image_license_cache );
491
+		$image_license_service        = new Image_License_Service($api_service, $image_license_factory);
492
+		$image_license_cache          = new Ttl_Cache('image-license', 86400 * 30); // 30 days.
493
+		$cached_image_license_service = new Cached_Image_License_Service($image_license_service, $image_license_cache);
494 494
 
495
-		$image_license_scheduler       = new Image_License_Scheduler( $image_license_service, $image_license_cache );
495
+		$image_license_scheduler       = new Image_License_Scheduler($image_license_service, $image_license_cache);
496 496
 		$image_license_cleanup_service = new Image_License_Cleanup_Service();
497 497
 
498 498
 		// Get the cached data. If we have cached data, we load the notifier.
499
-		$image_license_data = $image_license_cache->get( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES );
500
-		if ( null !== $image_license_data ) {
501
-			$image_license_page = new Image_License_Page( $image_license_data, Wordlift::get_instance()->get_version() );
502
-			new Image_License_Notifier( $image_license_data, $image_license_page );
499
+		$image_license_data = $image_license_cache->get(Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES);
500
+		if (null !== $image_license_data) {
501
+			$image_license_page = new Image_License_Page($image_license_data, Wordlift::get_instance()->get_version());
502
+			new Image_License_Notifier($image_license_data, $image_license_page);
503 503
 		}
504 504
 
505
-		$remove_all_images_task         = new Remove_All_Images_Task( $cached_image_license_service );
506
-		$remove_all_images_task_adapter = new Task_Ajax_Adapter( $remove_all_images_task );
505
+		$remove_all_images_task         = new Remove_All_Images_Task($cached_image_license_service);
506
+		$remove_all_images_task_adapter = new Task_Ajax_Adapter($remove_all_images_task);
507 507
 
508 508
 		$reload_data_task         = new Reload_Data_Task();
509
-		$reload_data_task_adapter = new Task_Ajax_Adapter( $reload_data_task );
509
+		$reload_data_task_adapter = new Task_Ajax_Adapter($reload_data_task);
510 510
 
511
-		$add_license_caption_or_remove_task         = new Add_License_Caption_Or_Remove_Task( $cached_image_license_service );
512
-		$add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter( $add_license_caption_or_remove_task );
511
+		$add_license_caption_or_remove_task         = new Add_License_Caption_Or_Remove_Task($cached_image_license_service);
512
+		$add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter($add_license_caption_or_remove_task);
513 513
 
514
-		$remove_all_images_task_page             = new Remove_All_Images_Page( new Task_Ajax_Adapters_Registry( $remove_all_images_task_adapter ), $plugin->get_version() );
515
-		$reload_data_task_page                   = new Reload_Data_Page( new Task_Ajax_Adapters_Registry( $reload_data_task_adapter ), $plugin->get_version() );
516
-		$add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page( new Task_Ajax_Adapters_Registry( $add_license_caption_or_remove_task_adapter ), $plugin->get_version() );
514
+		$remove_all_images_task_page             = new Remove_All_Images_Page(new Task_Ajax_Adapters_Registry($remove_all_images_task_adapter), $plugin->get_version());
515
+		$reload_data_task_page                   = new Reload_Data_Page(new Task_Ajax_Adapters_Registry($reload_data_task_adapter), $plugin->get_version());
516
+		$add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page(new Task_Ajax_Adapters_Registry($add_license_caption_or_remove_task_adapter), $plugin->get_version());
517 517
 
518 518
 		new Wordlift_Products_Navigator_Shortcode_REST();
519 519
 
520 520
 		// Register the Dataset module, requires `$api_service`.
521
-		require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
521
+		require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php';
522 522
 	} );
523 523
 
524 524
 }
@@ -533,24 +533,24 @@  discard block
 block discarded – undo
533 533
  */
534 534
 function wordlift_plugin_autoload_register() {
535 535
 
536
-	spl_autoload_register( function ( $class_name ) {
536
+	spl_autoload_register(function($class_name) {
537 537
 
538 538
 		// Bail out if these are not our classes.
539
-		if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
539
+		if (0 !== strpos($class_name, 'Wordlift\\')) {
540 540
 			return false;
541 541
 		}
542 542
 
543
-		$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
543
+		$class_name_lc = strtolower(str_replace('_', '-', $class_name));
544 544
 
545
-		preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
545
+		preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches);
546 546
 
547
-		$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
548
-		$file = 'class-' . $matches[2] . '.php';
547
+		$path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]);
548
+		$file = 'class-'.$matches[2].'.php';
549 549
 
550
-		$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
550
+		$full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file;
551 551
 
552
-		if ( ! file_exists( $full_path ) ) {
553
-			echo( "Class $class_name not found at $full_path." );
552
+		if ( ! file_exists($full_path)) {
553
+			echo("Class $class_name not found at $full_path.");
554 554
 
555 555
 			return false;
556 556
 		}
@@ -562,16 +562,16 @@  discard block
 block discarded – undo
562 562
 
563 563
 }
564 564
 
565
-function wl_block_categories( $categories, $post ) {
565
+function wl_block_categories($categories, $post) {
566 566
 	return array_merge(
567 567
 		$categories,
568 568
 		array(
569 569
 			array(
570 570
 				'slug'  => 'wordlift',
571
-				'title' => __( 'WordLift', 'wordlift' ),
571
+				'title' => __('WordLift', 'wordlift'),
572 572
 			),
573 573
 		)
574 574
 	);
575 575
 }
576 576
 
577
-add_filter( 'block_categories', 'wl_block_categories', 10, 2 );
577
+add_filter('block_categories', 'wl_block_categories', 10, 2);
Please login to merge, or discard this patch.