Completed
Pull Request — develop (#1665)
by
unknown
01:21
created
src/includes/class-wordlift-key-validation-service.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -42,20 +42,20 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	public function __construct() {
44 44
 
45
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' );
45
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Key_Validation_Service');
46 46
 
47
-		add_action( 'admin_init', array( $this, 'wl_load_plugin' ) );
47
+		add_action('admin_init', array($this, 'wl_load_plugin'));
48 48
 		/**
49 49
 		 * Filter: wl_feature__enable__notices.
50 50
 		 *
51 51
 		 * @return bool
52 52
 		 * @since 3.27.6
53 53
 		 */
54
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
55
-			add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) );
54
+		if (apply_filters('wl_feature__enable__notices', true)) {
55
+			add_action('admin_notices', array($this, 'wl_key_update_notice'));
56 56
 		}
57 57
 
58
-		$this->ttl_cache_service = new Ttl_Cache( 'key-validation-notification' );
58
+		$this->ttl_cache_service = new Ttl_Cache('key-validation-notification');
59 59
 
60 60
 	}
61 61
 
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
 	 * @return WP_Error|array The response or WP_Error on failure.
68 68
 	 * @since 3.9.0
69 69
 	 */
70
-	public function get_account_info( $key ) {
70
+	public function get_account_info($key) {
71 71
 
72
-		$this->log->debug( 'Validating key...' );
72
+		$this->log->debug('Validating key...');
73 73
 
74 74
 		$response = Default_Api_Service::get_instance()->get(
75 75
 			'/accounts/info',
@@ -84,39 +84,39 @@  discard block
 block discarded – undo
84 84
 		 * @since 3.38.5
85 85
 		 * This action is fired when the key is validated.
86 86
 		 */
87
-		do_action( 'wl_key_validation_response', $response );
87
+		do_action('wl_key_validation_response', $response);
88 88
 
89 89
 		return $response->get_response();
90 90
 	}
91 91
 
92
-	private function key_validation_request( $key ) {
93
-		$response = $this->get_account_info( $key );
92
+	private function key_validation_request($key) {
93
+		$response = $this->get_account_info($key);
94 94
 
95
-		if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) {
96
-			throw new \Exception( __( 'An error occurred, please contact us at [email protected]', 'wordlift' ) );
95
+		if (is_wp_error($response) || 2 !== (int) $response['response']['code'] / 100) {
96
+			throw new \Exception(__('An error occurred, please contact us at [email protected]', 'wordlift'));
97 97
 		}
98 98
 
99
-		$res_body = json_decode( wp_remote_retrieve_body( $response ), true );
99
+		$res_body = json_decode(wp_remote_retrieve_body($response), true);
100 100
 
101 101
 		$url = $res_body['url'];
102 102
 
103
-		$enabled_features = array_keys( array_filter( $res_body['features'] ) );
103
+		$enabled_features = array_keys(array_filter($res_body['features']));
104 104
 		$plugin_features  = array(
105 105
 			Entity_Type_Setter::STARTER_PLAN,
106 106
 			Entity_Type_Setter::PROFESSIONAL_PLAN,
107 107
 			Entity_Type_Setter::BUSINESS_PLAN,
108 108
 		);
109 109
 
110
-		if ( count( array_intersect( $enabled_features, $plugin_features ) ) === 0 ) {
111
-			throw new \Exception( __( 'This key is not valid. Start building your Knowledge Graph by purchasing a WordLift subscription <a href=\'https://wordlift.io/pricing/\'>here</a>.', 'wordlift' ) );
110
+		if (count(array_intersect($enabled_features, $plugin_features)) === 0) {
111
+			throw new \Exception(__('This key is not valid. Start building your Knowledge Graph by purchasing a WordLift subscription <a href=\'https://wordlift.io/pricing/\'>here</a>.', 'wordlift'));
112 112
 		}
113 113
 
114 114
 		// Considering that production URL may be filtered.
115
-		$home_url = get_option( 'home' );
116
-		$site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) );
115
+		$home_url = get_option('home');
116
+		$site_url = apply_filters('wl_production_site_url', untrailingslashit($home_url));
117 117
 
118
-		if ( ! empty( $url ) && $url !== $site_url ) {
119
-			throw new \Exception( __( 'The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift' ) );
118
+		if ( ! empty($url) && $url !== $site_url) {
119
+			throw new \Exception(__('The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift'));
120 120
 		}
121 121
 
122 122
 		return true;
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @return bool
131 131
 	 */
132
-	public function is_key_valid( $key ) {
132
+	public function is_key_valid($key) {
133 133
 		try {
134
-			$this->key_validation_request( $key );
134
+			$this->key_validation_request($key);
135 135
 
136 136
 			return true;
137
-		} catch ( \Exception $e ) {
137
+		} catch (\Exception $e) {
138 138
 			return false;
139 139
 		}
140 140
 	}
@@ -150,14 +150,14 @@  discard block
 block discarded – undo
150 150
 		ob_clean();
151 151
 
152 152
 		// Check if we have a key.
153
-		if ( ! isset( $_POST['key'] ) ) {  //phpcs:ignore WordPress.Security.NonceVerification.Missing
154
-			wp_send_json_error( 'The key parameter is required.' );
153
+		if ( ! isset($_POST['key'])) {  //phpcs:ignore WordPress.Security.NonceVerification.Missing
154
+			wp_send_json_error('The key parameter is required.');
155 155
 		}
156 156
 
157
-		$this->ttl_cache_service->delete( 'is_key_valid' );
157
+		$this->ttl_cache_service->delete('is_key_valid');
158 158
 
159 159
 		try {
160
-			$this->key_validation_request( sanitize_text_field( wp_unslash( (string) $_POST['key'] ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Missing
160
+			$this->key_validation_request(sanitize_text_field(wp_unslash((string) $_POST['key']))); //phpcs:ignore WordPress.Security.NonceVerification.Missing
161 161
 			wp_send_json_success(
162 162
 				array(
163 163
 					'valid'   => true,
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
 				)
166 166
 			);
167 167
 
168
-		} catch ( \Exception $e ) {
169
-			Wordlift_Configuration_Service::get_instance()->set_key( '' );
168
+		} catch (\Exception $e) {
169
+			Wordlift_Configuration_Service::get_instance()->set_key('');
170 170
 			wp_send_json_success(
171 171
 				array(
172 172
 					'valid'   => false,
@@ -182,15 +182,15 @@  discard block
 block discarded – undo
182 182
 	 */
183 183
 	public function wl_load_plugin() {
184 184
 
185
-		$wl_blog_url = get_option( '_wl_blog_url' );
186
-		$home_url    = get_option( 'home' );
185
+		$wl_blog_url = get_option('_wl_blog_url');
186
+		$home_url    = get_option('home');
187 187
 
188
-		if ( ! $wl_blog_url ) {
189
-			update_option( '_wl_blog_url', $home_url, true );
190
-		} elseif ( $wl_blog_url !== $home_url ) {
191
-			update_option( '_wl_blog_url', $home_url, true );
192
-			Wordlift_Configuration_Service::get_instance()->set_key( '' );
193
-			set_transient( 'wl-key-error-msg', __( "Your web site URL has changed. To avoid data corruption, WordLift's key has been removed. Please provide a new key in WordLift Settings. If you believe this to be an error, please contact us at [email protected]", 'wordlift' ), 10 );
188
+		if ( ! $wl_blog_url) {
189
+			update_option('_wl_blog_url', $home_url, true);
190
+		} elseif ($wl_blog_url !== $home_url) {
191
+			update_option('_wl_blog_url', $home_url, true);
192
+			Wordlift_Configuration_Service::get_instance()->set_key('');
193
+			set_transient('wl-key-error-msg', __("Your web site URL has changed. To avoid data corruption, WordLift's key has been removed. Please provide a new key in WordLift Settings. If you believe this to be an error, please contact us at [email protected]", 'wordlift'), 10);
194 194
 		}
195 195
 
196 196
 	}
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
 	 * This function is hooked to the `admin_notices` to show admin notification.
200 200
 	 */
201 201
 	public function wl_key_update_notice() {
202
-		if ( get_transient( 'wl-key-error-msg' ) ) {
202
+		if (get_transient('wl-key-error-msg')) {
203 203
 			?>
204 204
 		  <div class="updated notice is-dismissible error">
205
-			<p><?php esc_html( get_transient( 'wl-key-error-msg' ) ); ?></p>
205
+			<p><?php esc_html(get_transient('wl-key-error-msg')); ?></p>
206 206
 		  </div>
207 207
 			<?php
208 208
 		}
Please login to merge, or discard this patch.
src/wordlift.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -31,29 +31,29 @@  discard block
 block discarded – undo
31 31
 use Wordlift\Features\Features_Registry;
32 32
 use Wordlift\Post\Post_Adapter;
33 33
 // If this file is called directly, abort.
34
-if ( ! defined( 'WPINC' ) ) {
34
+if ( ! defined('WPINC')) {
35 35
 	die;
36 36
 }
37 37
 define(
38 38
 	'WORDLIFT_PLUGIN_FILE',
39 39
 	__FILE__
40 40
 );
41
-define( 'WORDLIFT_VERSION', '3.40.8' );
41
+define('WORDLIFT_VERSION', '3.40.8');
42 42
 
43
-require_once plugin_dir_path( __FILE__ ) . '/libraries/action-scheduler/action-scheduler.php';
44
-require_once __DIR__ . '/modules/common/load.php';
45
-require_once __DIR__ . '/modules/include-exclude/load.php';
43
+require_once plugin_dir_path(__FILE__).'/libraries/action-scheduler/action-scheduler.php';
44
+require_once __DIR__.'/modules/common/load.php';
45
+require_once __DIR__.'/modules/include-exclude/load.php';
46 46
 
47 47
 /**
48 48
  * Filter to disable WLP on any request, defaults to true.
49 49
  *
50 50
  * @since 3.33.6
51 51
  */
52
-if ( ! apply_filters( 'wl_is_enabled', true ) ) {
52
+if ( ! apply_filters('wl_is_enabled', true)) {
53 53
 	return;
54 54
 }
55 55
 
56
-require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
56
+require_once plugin_dir_path(__FILE__).'vendor/autoload.php';
57 57
 
58 58
 /*
59 59
 	 * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http.
@@ -63,15 +63,15 @@  discard block
 block discarded – undo
63 63
 wordlift_plugin_autoload_register();
64 64
 
65 65
 // Include WordLift constants.
66
-require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php';
66
+require_once plugin_dir_path(__FILE__).'wordlift-constants.php';
67 67
 
68 68
 // Load modules.
69
-require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php';
69
+require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php';
70 70
 
71
-require_once plugin_dir_path( __FILE__ ) . 'deprecations.php';
71
+require_once plugin_dir_path(__FILE__).'deprecations.php';
72 72
 
73 73
 // Load early to enable/disable features.
74
-require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php';
74
+require_once plugin_dir_path(__FILE__).'wordlift/features/index.php';
75 75
 
76 76
 /**
77 77
  * The code that runs during plugin activation.
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
  */
80 80
 function activate_wordlift() {
81 81
 
82
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
82
+	$log = Wordlift_Log_Service::get_logger('activate_wordlift');
83 83
 
84
-	$log->info( 'Activating WordLift...' );
84
+	$log->info('Activating WordLift...');
85 85
 
86
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
86
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
87 87
 	Wordlift_Activator::activate();
88 88
 
89 89
 	/**
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 	 */
104 104
 	Top_Entities::activate();
105 105
 
106
-	if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) {
107
-		wp_schedule_event( time(), 'daily', 'wl_daily_cron' );
106
+	if ( ! wp_next_scheduled('wl_daily_cron')) {
107
+		wp_schedule_event(time(), 'daily', 'wl_daily_cron');
108 108
 	}
109 109
 
110 110
 }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
  */
116 116
 function deactivate_wordlift() {
117 117
 
118
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
118
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
119 119
 	Wordlift_Deactivator::deactivate();
120 120
 	Wordlift_Http_Api::deactivate();
121 121
 	Ttl_Cache_Cleaner::deactivate();
@@ -131,18 +131,18 @@  discard block
 block discarded – undo
131 131
 	Key_Validation_Notice::remove_notification_flag();
132 132
 	flush_rewrite_rules();
133 133
 
134
-	wp_clear_scheduled_hook( 'wl_daily_cron' );
134
+	wp_clear_scheduled_hook('wl_daily_cron');
135 135
 
136 136
 }
137 137
 
138
-register_activation_hook( __FILE__, 'activate_wordlift' );
139
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
138
+register_activation_hook(__FILE__, 'activate_wordlift');
139
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
140 140
 
141 141
 /**
142 142
  * The core plugin class that is used to define internationalization,
143 143
  * admin-specific hooks, and public-facing site hooks.
144 144
  */
145
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
145
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
146 146
 
147 147
 /**
148 148
  * Begins execution of the plugin.
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
 	 * @return bool
163 163
 	 * @since 3.27.6
164 164
 	 */
165
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
166
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
167
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
168
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
165
+	if (apply_filters('wl_feature__enable__widgets', true)) {
166
+		add_action('widgets_init', 'wl_register_chord_widget');
167
+		add_action('widgets_init', 'wl_register_geo_widget');
168
+		add_action('widgets_init', 'wl_register_timeline_widget');
169 169
 	}
170
-	add_filter( 'widget_text', 'do_shortcode' );
170
+	add_filter('widget_text', 'do_shortcode');
171 171
 
172 172
 	/**
173 173
 	 * Filter: wl_feature__enable__analysis
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
 	 * @return bool
178 178
 	 * @since 3.27.6
179 179
 	 */
180
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
181
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
180
+	if (apply_filters('wl_feature__enable__analysis', true)) {
181
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action');
182 182
 	} else {
183
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
183
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action');
184 184
 	}
185 185
 
186 186
 	$plugin = new Wordlift();
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 
198 198
 	add_action(
199 199
 		'plugins_loaded',
200
-		function () {
200
+		function() {
201 201
 			// All features from registry should be initialized here.
202 202
 			$features_registry = Features_Registry::get_instance();
203 203
 			$features_registry->initialize_all_features();
@@ -208,27 +208,27 @@  discard block
 block discarded – undo
208 208
 	add_action(
209 209
 		'plugins_loaded',
210 210
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
211
-		function () use ( $plugin ) {
211
+		function() use ($plugin) {
212 212
 
213 213
 			new Wordlift_Products_Navigator_Shortcode_REST();
214 214
 
215 215
 			// Register the Dataset module, requires `$api_service`.
216
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
217
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
216
+			require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php';
217
+			require_once plugin_dir_path(__FILE__).'wordlift/shipping-data/index.php';
218 218
 
219 219
 			/*
220 220
 			* Require the Entity annotation cleanup module.
221 221
 			*
222 222
 			* @since 3.34.6
223 223
 			*/
224
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
224
+			require_once plugin_dir_path(__FILE__).'wordlift/cleanup/index.php';
225 225
 
226 226
 			/*
227 227
 			* Import LOD entities.
228 228
 			*
229 229
 			* @since 3.35.0
230 230
 			*/
231
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php';
231
+			require_once plugin_dir_path(__FILE__).'wordlift/lod-import/index.php';
232 232
 
233 233
 		}
234 234
 	);
@@ -246,23 +246,23 @@  discard block
 block discarded – undo
246 246
 function wordlift_plugin_autoload_register() {
247 247
 
248 248
 	spl_autoload_register(
249
-		function ( $class_name ) {
249
+		function($class_name) {
250 250
 
251 251
 			// Bail out if these are not our classes.
252
-			if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
252
+			if (0 !== strpos($class_name, 'Wordlift\\')) {
253 253
 				return false;
254 254
 			}
255 255
 
256
-			$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
256
+			$class_name_lc = strtolower(str_replace('_', '-', $class_name));
257 257
 
258
-			preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
258
+			preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches);
259 259
 
260
-			$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
261
-			$file = 'class-' . $matches[2] . '.php';
260
+			$path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]);
261
+			$file = 'class-'.$matches[2].'.php';
262 262
 
263
-			$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
263
+			$full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file;
264 264
 
265
-			if ( ! file_exists( $full_path ) ) {
265
+			if ( ! file_exists($full_path)) {
266 266
 				return false;
267 267
 			}
268 268
 
@@ -274,13 +274,13 @@  discard block
 block discarded – undo
274 274
 
275 275
 }
276 276
 
277
-function wl_block_categories( $categories ) {
277
+function wl_block_categories($categories) {
278 278
 	return array_merge(
279 279
 		$categories,
280 280
 		array(
281 281
 			array(
282 282
 				'slug'  => 'wordlift',
283
-				'title' => __( 'WordLift', 'wordlift' ),
283
+				'title' => __('WordLift', 'wordlift'),
284 284
 			),
285 285
 		)
286 286
 	);
@@ -290,45 +290,45 @@  discard block
 block discarded – undo
290 290
  * This function is created temporarily to handle the legacy library,
291 291
  * this has to be removed when removing the legacy fields from the ui.
292 292
  */
293
-function wl_enqueue_leaflet( $in_footer = false ) {
293
+function wl_enqueue_leaflet($in_footer = false) {
294 294
 	// Leaflet.
295
-	wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
296
-	wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
295
+	wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0');
296
+	wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer);
297 297
 }
298 298
 
299
-add_filter( 'block_categories', 'wl_block_categories', 10 );
299
+add_filter('block_categories', 'wl_block_categories', 10);
300 300
 
301 301
 // Temporary fix for a typo in WooCommerce Extension.
302 302
 add_filter(
303 303
 	'wl_feature__enable__dataset',
304
-	function ( $value ) {
305
-		return apply_filters( 'wl_features__enable__dataset', $value );
304
+	function($value) {
305
+		return apply_filters('wl_features__enable__dataset', $value);
306 306
 	}
307 307
 );
308 308
 
309
-require_once __DIR__ . '/modules/food-kg/load.php';
310
-require_once __DIR__ . '/modules/acf4so/load.php';
311
-require_once __DIR__ . '/modules/pods/load.php';
312
-require_once __DIR__ . '/modules/include-exclude-push-config/load.php';
309
+require_once __DIR__.'/modules/food-kg/load.php';
310
+require_once __DIR__.'/modules/acf4so/load.php';
311
+require_once __DIR__.'/modules/pods/load.php';
312
+require_once __DIR__.'/modules/include-exclude-push-config/load.php';
313 313
 
314 314
 add_action(
315 315
 	'update_plugins_adthrive.wordlift.io',
316
-	function ( $update, $plugin_data, $plugin_file ) {
316
+	function($update, $plugin_data, $plugin_file) {
317 317
 		// Bail out if it's not our plugin.
318 318
 		$update_uri = $plugin_data['UpdateURI'];
319
-		if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) {
319
+		if ('wordlift/wordlift.php' !== $plugin_file || ! isset($update_uri)) {
320 320
 			return $update;
321 321
 		}
322 322
 
323
-		$response = wp_remote_get( "$update_uri?nocache=" . time() );
323
+		$response = wp_remote_get("$update_uri?nocache=".time());
324 324
 
325
-		if ( is_wp_error( $response ) ) {
325
+		if (is_wp_error($response)) {
326 326
 			return $update;
327 327
 		}
328 328
 
329 329
 		try {
330
-			return json_decode( wp_remote_retrieve_body( $response ) );
331
-		} catch ( Exception $e ) {
330
+			return json_decode(wp_remote_retrieve_body($response));
331
+		} catch (Exception $e) {
332 332
 			return $update;
333 333
 		}
334 334
 	},
Please login to merge, or discard this patch.
src/wordlift/cache/class-ttl-cache.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -66,19 +66,19 @@  discard block
 block discarded – undo
66 66
 	 *
67 67
 	 * @since 3.21.2
68 68
 	 */
69
-	public function __construct( $name, $ttl = 900 ) {
69
+	public function __construct($name, $ttl = 900) {
70 70
 
71
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
71
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
72 72
 
73 73
 		$this->name = $name;
74 74
 		$this->ttl  = $ttl;
75 75
 
76
-		$this->cache_dir = self::get_cache_folder() . DIRECTORY_SEPARATOR . md5( $name );
76
+		$this->cache_dir = self::get_cache_folder().DIRECTORY_SEPARATOR.md5($name);
77 77
 
78
-		$this->log->trace( "Creating the cache folder {$this->cache_dir}..." );
79
-		wp_mkdir_p( $this->cache_dir );
78
+		$this->log->trace("Creating the cache folder {$this->cache_dir}...");
79
+		wp_mkdir_p($this->cache_dir);
80 80
 
81
-		self::$caches[ $name ] = $this;
81
+		self::$caches[$name] = $this;
82 82
 
83 83
 	}
84 84
 
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
 
95 95
 		// Get the temp dir and add the directory separator if missing.
96 96
 		$temp_dir = get_temp_dir();
97
-		if ( DIRECTORY_SEPARATOR !== substr( $temp_dir, - strlen( DIRECTORY_SEPARATOR ) ) ) {
97
+		if (DIRECTORY_SEPARATOR !== substr($temp_dir, - strlen(DIRECTORY_SEPARATOR))) {
98 98
 			$temp_dir .= DIRECTORY_SEPARATOR;
99 99
 		}
100 100
 
101
-		return $temp_dir . 'wl.cache' . DIRECTORY_SEPARATOR . md5( home_url() );
101
+		return $temp_dir.'wl.cache'.DIRECTORY_SEPARATOR.md5(home_url());
102 102
 	}
103 103
 
104 104
 	/**
@@ -109,64 +109,64 @@  discard block
 block discarded – undo
109 109
 	 * @return mixed|null
110 110
 	 * @since 3.21.2
111 111
 	 */
112
-	public function get( $key, $mintime = 0 ) {
112
+	public function get($key, $mintime = 0) {
113 113
 
114
-		$filename = $this->get_filename( $key );
114
+		$filename = $this->get_filename($key);
115 115
 
116 116
 		// No cache.
117
-		if ( ! file_exists( $filename ) ) {
117
+		if ( ! file_exists($filename)) {
118 118
 			return null;
119 119
 		}
120 120
 
121 121
 		// The cache is not updated or the ttl expired. Delete.
122
-		$filemtime = filemtime( $filename );
123
-		if ( $filemtime < $mintime || $this->ttl < ( time() - $filemtime ) ) {
124
-			$this->delete( $key );
122
+		$filemtime = filemtime($filename);
123
+		if ($filemtime < $mintime || $this->ttl < (time() - $filemtime)) {
124
+			$this->delete($key);
125 125
 
126 126
 			return null;
127 127
 		}
128 128
 
129 129
 
130
-		$this->log->trace( "Cache HIT.\n" );
130
+		$this->log->trace("Cache HIT.\n");
131 131
 
132 132
 		// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
133
-		return json_decode( file_get_contents( $filename ), true );
133
+		return json_decode(file_get_contents($filename), true);
134 134
 	}
135 135
 
136
-	public function put( $key, $data ) {
136
+	public function put($key, $data) {
137 137
 
138
-		$filename = $this->get_filename( $key );
138
+		$filename = $this->get_filename($key);
139 139
 
140 140
 		// Cache.
141
-		if ( file_exists( $filename ) ) {
141
+		if (file_exists($filename)) {
142 142
 			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
143
-			@unlink( $filename );
143
+			@unlink($filename);
144 144
 		}
145 145
 
146 146
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged,WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
147
-		@file_put_contents( $filename, wp_json_encode( $data ) );
147
+		@file_put_contents($filename, wp_json_encode($data));
148 148
 
149 149
 	}
150 150
 
151
-	public function delete( $key ) {
151
+	public function delete($key) {
152 152
 
153
-		$filename = $this->get_filename( $key );
153
+		$filename = $this->get_filename($key);
154 154
 
155 155
 		// Delete.
156
-		if ( file_exists( $filename ) ) {
156
+		if (file_exists($filename)) {
157 157
 			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
158
-			@unlink( $filename );
158
+			@unlink($filename);
159 159
 		}
160 160
 
161 161
 	}
162 162
 
163 163
 	public function flush() {
164 164
 
165
-		$files = glob( $this->cache_dir . DIRECTORY_SEPARATOR . '*' );
166
-		foreach ( $files as $file ) { // iterate files
167
-			if ( is_file( $file ) ) {
165
+		$files = glob($this->cache_dir.DIRECTORY_SEPARATOR.'*');
166
+		foreach ($files as $file) { // iterate files
167
+			if (is_file($file)) {
168 168
 				// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
169
-				@unlink( $file );
169
+				@unlink($file);
170 170
 			}
171 171
 		}
172 172
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	public static function flush_all() {
176 176
 
177 177
 		/** @var Ttl_Cache $cache */
178
-		foreach ( self::$caches as $cache ) {
178
+		foreach (self::$caches as $cache) {
179 179
 			$cache->flush();
180 180
 		}
181 181
 
@@ -189,16 +189,16 @@  discard block
 block discarded – undo
189 189
 	 * @return string The full path to the file.
190 190
 	 * @since 3.21.2
191 191
 	 */
192
-	private function get_path( $hash ) {
192
+	private function get_path($hash) {
193 193
 
194
-		return $this->cache_dir . DIRECTORY_SEPARATOR . $hash;
194
+		return $this->cache_dir.DIRECTORY_SEPARATOR.$hash;
195 195
 	}
196 196
 
197
-	private function get_filename( $key ) {
197
+	private function get_filename($key) {
198 198
 
199 199
 		// Create a hash and a path to the cache file.
200
-		$hash     = md5( wp_json_encode( $key ) );
201
-		$filename = $this->get_path( $hash );
200
+		$hash     = md5(wp_json_encode($key));
201
+		$filename = $this->get_path($hash);
202 202
 
203 203
 		return $filename;
204 204
 	}
Please login to merge, or discard this patch.
src/includes/class-wordlift-abstract-post-to-jsonld-converter.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @since 3.10.0
74 74
 	 */
75
-	public function __construct( $entity_type_service, $user_service, $attachment_service, $property_getter ) {
75
+	public function __construct($entity_type_service, $user_service, $attachment_service, $property_getter) {
76 76
 		$this->entity_type_service = $entity_type_service;
77 77
 		$this->user_service        = $user_service;
78 78
 		$this->attachment_service  = $attachment_service;
@@ -91,19 +91,19 @@  discard block
 block discarded – undo
91 91
 	 * @since 3.10.0
92 92
 	 */
93 93
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
94
-	public function convert( $post_id, &$references = array(), &$references_infos = array() ) {
94
+	public function convert($post_id, &$references = array(), &$references_infos = array()) {
95 95
 
96 96
 		// Get the post instance.
97
-		$post = get_post( $post_id );
98
-		if ( null === $post ) {
97
+		$post = get_post($post_id);
98
+		if (null === $post) {
99 99
 			// Post not found.
100 100
 			return null;
101 101
 		}
102 102
 
103 103
 		// Get the post URI @id.
104
-		$id = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID );
105
-		if ( $id === null ) {
106
-			$id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri();
104
+		$id = Wordlift_Entity_Service::get_instance()->get_uri($post->ID);
105
+		if ($id === null) {
106
+			$id = 'get_uri returned null, dataset is '.wl_configuration_get_redlink_dataset_uri();
107 107
 		}
108 108
 
109 109
 		/*
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 		 */
116 116
 		// Get the entity @type. We consider `post` BlogPostings.
117 117
 		// $type = $this->entity_type_service->get( $post_id );
118
-		$types = $this->entity_type_service->get_names( $post_id );
119
-		$type  = self::make_one( $types );
118
+		$types = $this->entity_type_service->get_names($post_id);
119
+		$type  = self::make_one($types);
120 120
 
121 121
 		// Prepare the response.
122 122
 		$jsonld = array(
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
 			'@type'    => $type,
126 126
 		);
127 127
 
128
-		if ( post_type_supports( $post->post_type, 'excerpt' ) ) {
129
-			$jsonld['description'] = Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post );
128
+		if (post_type_supports($post->post_type, 'excerpt')) {
129
+			$jsonld['description'] = Wordlift_Post_Excerpt_Helper::get_text_excerpt($post);
130 130
 		}
131 131
 
132 132
 		// Set the `mainEntityOfPage` property if the post has some contents.
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 		 *
137 137
 		 * @since 3.20.0
138 138
 		 */
139
-		$post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
140
-		if ( ! empty( $post_content ) || in_array( 'Product', (array) $type, true ) ) {
139
+		$post_content = apply_filters('wl_post_content', $post->post_content, $post);
140
+		if ( ! empty($post_content) || in_array('Product', (array) $type, true)) {
141 141
 			// We're setting the `mainEntityOfPage` to signal which one is the
142 142
 			// main entity for the specified URL. It might be however that the
143 143
 			// post/page is actually about another specific entity. How WL deals
@@ -148,35 +148,35 @@  discard block
 block discarded – undo
148 148
 			// No need to specify `'@type' => 'WebPage'.
149 149
 			//
150 150
 			// See https://github.com/insideout10/wordlift-plugin/issues/451.
151
-			$jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID );
151
+			$jsonld['mainEntityOfPage'] = get_the_permalink($post->ID);
152 152
 
153 153
 			/**
154 154
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/1207
155 155
 			 *
156 156
 			 * @since 3.27.7
157 157
 			 */
158
-			if ( in_array(
158
+			if (in_array(
159 159
 				$type,
160 160
 				array(
161 161
 					'Occupation',
162 162
 					'OccupationAggregationByEmployer',
163 163
 				),
164 164
 				true
165
-			) ) {
165
+			)) {
166 166
 				$jsonld['mainEntityOfPage'] = array(
167 167
 					'@type'        => 'WebPage',
168
-					'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ),
168
+					'lastReviewed' => get_post_time('Y-m-d\TH:i:sP', true, $post, false),
169 169
 				);
170 170
 			}
171 171
 		};
172 172
 
173
-		$this->set_images( $this->attachment_service, $post, $jsonld );
173
+		$this->set_images($this->attachment_service, $post, $jsonld);
174 174
 
175 175
 		// Get the entities referenced by this post and set it to the `references`
176 176
 		// array so that the caller can do further processing, such as printing out
177 177
 		// more of those references.
178 178
 		$references_without_locations = Object_Relation_Service::get_instance()
179
-															   ->get_references( $post_id, Object_Type_Enum::POST );
179
+															   ->get_references($post_id, Object_Type_Enum::POST);
180 180
 
181 181
 		/*
182 182
 		 * Add the locations to the references.
@@ -189,33 +189,33 @@  discard block
 block discarded – undo
189 189
 		$entity_type_service = $this->entity_type_service;
190 190
 		$locations           = array_reduce(
191 191
 			$references_without_locations,
192
-			function ( $carry, $reference ) use ( $entity_type_service ) {
192
+			function($carry, $reference) use ($entity_type_service) {
193 193
 				/**
194 194
 				 * @var $reference Reference
195 195
 				 */
196 196
 				// @see https://schema.org/location for the schema.org types using the `location` property.
197
-				if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' )
198
-					 && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' )
199
-					 && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) {
197
+				if ( ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Action')
198
+					 && ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Event')
199
+					 && ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Organization')) {
200 200
 
201 201
 					return $carry;
202 202
 				}
203
-				$post_location_ids        = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION );
203
+				$post_location_ids        = get_post_meta($reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION);
204 204
 				$post_location_references = array_map(
205
-					function ( $post_id ) {
206
-						return new Post_Reference( $post_id );
205
+					function($post_id) {
206
+						return new Post_Reference($post_id);
207 207
 					},
208 208
 					$post_location_ids
209 209
 				);
210 210
 
211
-				return array_merge( $carry, $post_location_references );
211
+				return array_merge($carry, $post_location_references);
212 212
 			},
213 213
 			array()
214 214
 		);
215 215
 
216 216
 		// Merge the references with the referenced locations if any.
217 217
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
218
-		$references = array_merge( $references_without_locations, $locations );
218
+		$references = array_merge($references_without_locations, $locations);
219 219
 
220 220
 		return $jsonld;
221 221
 	}
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
 	 * @return string The property value without the context.
230 230
 	 * @since 3.10.0
231 231
 	 */
232
-	public function relative_to_context( $value ) {
233
-		return ! is_array( $value ) && 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value;
232
+	public function relative_to_context($value) {
233
+		return ! is_array($value) && 0 === strpos($value, self::CONTEXT.'/') ? substr($value, strlen(self::CONTEXT) + 1) : $value;
234 234
 	}
235 235
 
236 236
 	/**
@@ -245,14 +245,14 @@  discard block
 block discarded – undo
245 245
 	 *
246 246
 	 * @since 3.10.0
247 247
 	 */
248
-	public static function set_images( $attachment_service, $post, &$jsonld ) {
248
+	public static function set_images($attachment_service, $post, &$jsonld) {
249 249
 
250 250
 		// Prepare the attachment ids array.
251 251
 		$ids = array();
252 252
 
253 253
 		// Set the thumbnail id as first attachment id, if any.
254
-		$thumbnail_id = get_post_thumbnail_id( $post->ID );
255
-		if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) {
254
+		$thumbnail_id = get_post_thumbnail_id($post->ID);
255
+		if ('' !== $thumbnail_id && 0 !== $thumbnail_id) {
256 256
 			$ids[] = $thumbnail_id;
257 257
 		}
258 258
 
@@ -263,34 +263,34 @@  discard block
 block discarded – undo
263 263
 		//
264 264
 		// Get the embeds, removing existing ids.
265 265
 		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
266
-		if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) {
267
-			$embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids );
266
+		if (apply_filters('wl_feature__enable__image-embeds', false)) {
267
+			$embeds = array_diff($attachment_service->get_image_embeds($post->post_content), $ids);
268 268
 		} else {
269 269
 			$embeds = array();
270 270
 		}
271 271
 
272 272
 		// Get the gallery, removing existing ids.
273
-		$gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds );
273
+		$gallery = array_diff($attachment_service->get_gallery($post), $ids, $embeds);
274 274
 
275 275
 		// Map the attachment ids to images' data structured for schema.org use.
276 276
 		$images_with_sizes = array_filter(
277 277
 			array_reduce(
278
-				array_merge( $ids, $embeds, $gallery ),
279
-				function ( $carry, $item ) {
278
+				array_merge($ids, $embeds, $gallery),
279
+				function($carry, $item) {
280 280
 					/*
281 281
 					* @todo: we're not sure that we're getting attachment data here, we
282 282
 					* should filter `false`s.
283 283
 					*/
284 284
 
285 285
 					$sources = array_merge(
286
-						Wordlift_Image_Service::get_sources( $item ),
287
-						array( wp_get_attachment_image_src( $item, 'full' ) )
286
+						Wordlift_Image_Service::get_sources($item),
287
+						array(wp_get_attachment_image_src($item, 'full'))
288 288
 					);
289 289
 
290 290
 					$sources_with_image = array_filter(
291 291
 						$sources,
292
-						function ( $source ) {
293
-							return ! empty( $source[0] );
292
+						function($source) {
293
+							return ! empty($source[0]);
294 294
 						}
295 295
 					);
296 296
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 					// or from uploads dir, but the image id still exists as featured image
305 305
 					// or in [gallery] shortcode.
306 306
 					// if ( empty( $attachment[0] ) ) {
307
-					if ( empty( $sources_with_image ) ) {
307
+					if (empty($sources_with_image)) {
308 308
 						return $carry;
309 309
 					}
310 310
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 
323 323
 		// Refactor data as per schema.org specifications.
324 324
 		$images = array_map(
325
-			function ( $attachment ) {
325
+			function($attachment) {
326 326
 				return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size(
327 327
 					array(
328 328
 						'@type' => 'ImageObject',
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 		);
336 336
 
337 337
 		// Add images if present.
338
-		if ( 0 < count( $images ) ) {
338
+		if (0 < count($images)) {
339 339
 			$jsonld['image'] = $images;
340 340
 		}
341 341
 
@@ -353,9 +353,9 @@  discard block
 block discarded – undo
353 353
 	 * @since  3.8.0
354 354
 	 * @access private
355 355
 	 */
356
-	protected static function make_one( $value ) {
356
+	protected static function make_one($value) {
357 357
 
358
-		return 1 === count( $value ) ? $value[0] : $value;
358
+		return 1 === count($value) ? $value[0] : $value;
359 359
 	}
360 360
 
361 361
 	/**
@@ -368,17 +368,17 @@  discard block
 block discarded – undo
368 368
 	 * @return array The enriched `ImageObject` array.
369 369
 	 * @since 3.14.0
370 370
 	 */
371
-	public static function set_image_size( $image, $attachment ) {
371
+	public static function set_image_size($image, $attachment) {
372 372
 
373 373
 		// If you specify a "width" or "height" value you should leave out
374 374
 		// 'px'. For example: "width":"4608px" should be "width":"4608".
375 375
 		//
376 376
 		// See https://github.com/insideout10/wordlift-plugin/issues/451.
377
-		if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) {
377
+		if (isset($attachment[1]) && is_numeric($attachment[1]) && 0 < $attachment[1]) {
378 378
 			$image['width'] = $attachment[1];
379 379
 		}
380 380
 
381
-		if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) {
381
+		if (isset($attachment[2]) && is_numeric($attachment[2]) && 0 < $attachment[2]) {
382 382
 			$image['height'] = $attachment[2];
383 383
 		}
384 384
 
@@ -397,33 +397,33 @@  discard block
 block discarded – undo
397 397
 	 * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in
398 398
 	 *  the {@link Wordlift_Schema_Service} class.
399 399
 	 */
400
-	protected function process_type_custom_fields( &$jsonld, $fields, $post, &$references, &$references_infos ) {
400
+	protected function process_type_custom_fields(&$jsonld, $fields, $post, &$references, &$references_infos) {
401 401
 
402 402
 		// Set a reference to use in closures.
403 403
 		$converter = $this;
404 404
 
405 405
 		// Try each field on the entity.
406
-		foreach ( $fields as $key => $value ) {
406
+		foreach ($fields as $key => $value) {
407 407
 
408 408
 			// Get the predicate.
409
-			$name = $this->relative_to_context( $value['predicate'] );
409
+			$name = $this->relative_to_context($value['predicate']);
410 410
 
411 411
 			// Get the value, the property service will get the right extractor
412 412
 			// for that property.
413
-			$value = $this->property_getter->get( $post->ID, $key, Object_Type_Enum::POST );
413
+			$value = $this->property_getter->get($post->ID, $key, Object_Type_Enum::POST);
414 414
 
415
-			if ( empty( $value ) ) {
415
+			if (empty($value)) {
416 416
 				continue;
417 417
 			}
418 418
 
419 419
 			// Map the value to the property name.
420 420
 			// If we got an array with just one value, we return that one value.
421 421
 			// If we got a Wordlift_Property_Entity_Reference we get the URL.
422
-			$jsonld[ $name ] = self::make_one(
422
+			$jsonld[$name] = self::make_one(
423 423
 				array_map(
424
-					function ( $item ) use ( $converter, &$references, &$references_infos ) {
424
+					function($item) use ($converter, &$references, &$references_infos) {
425 425
 
426
-						if ( $item instanceof Wordlift_Property_Entity_Reference ) {
426
+						if ($item instanceof Wordlift_Property_Entity_Reference) {
427 427
 
428 428
 							$url = $item->get_url();
429 429
 
@@ -432,12 +432,12 @@  discard block
 block discarded – undo
432 432
 							$references[] = $item->to_reference();
433 433
 
434 434
 							// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
435
-							$references_infos[] = array( 'reference' => $item );
435
+							$references_infos[] = array('reference' => $item);
436 436
 
437
-							return array( '@id' => $url );
437
+							return array('@id' => $url);
438 438
 						}
439 439
 
440
-						return $converter->relative_to_context( $item );
440
+						return $converter->relative_to_context($item);
441 441
 					},
442 442
 					$value
443 443
 				)
Please login to merge, or discard this patch.
src/includes/cache/class-wordlift-cached-post-converter.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
 	 * @param \Wordlift_Post_Converter $converter The {@link Wordlift_Post_Converter} implementation.
69 69
 	 * @param Ttl_Cache                $cache The {@link Ttl_Cache} cache instance.
70 70
 	 */
71
-	public function __construct( $converter, $cache ) {
71
+	public function __construct($converter, $cache) {
72 72
 
73
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
73
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
74 74
 
75 75
 		$this->cache               = $cache;
76 76
 		$this->converter           = $converter;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	private function init_hooks() {
88 88
 
89 89
 		// Hook on post save to flush relevant cache.
90
-		add_action( 'save_post', array( $this, 'save_post' ) );
90
+		add_action('save_post', array($this, 'save_post'));
91 91
 
92 92
 		add_action(
93 93
 			'added_post_meta',
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 		);
137 137
 
138 138
 		// Invalid cache on relationship change.
139
-		add_action( 'wl_relation_added', array( $this, 'relation_changed' ) );
140
-		add_action( 'wl_relation_deleted', array( $this, 'relation_changed' ) );
139
+		add_action('wl_relation_added', array($this, 'relation_changed'));
140
+		add_action('wl_relation_deleted', array($this, 'relation_changed'));
141 141
 
142 142
 	}
143 143
 
@@ -148,25 +148,25 @@  discard block
 block discarded – undo
148 148
 	 * @inheritdoc
149 149
 	 */
150 150
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
151
-	public function convert( $post_id, &$references = array(), &$references_infos = array(), &$cache = false ) {
151
+	public function convert($post_id, &$references = array(), &$references_infos = array(), &$cache = false) {
152 152
 
153 153
 		// Ensure post ID is `int`. Otherwise we may have issues with caching, since caching is strict about
154 154
 		// key var types.
155 155
 		$post_id = (int) $post_id;
156 156
 
157
-		$this->log->trace( "Converting post $post_id..." );
157
+		$this->log->trace("Converting post $post_id...");
158 158
 
159 159
 		// Try to get a cached result.
160
-		$contents = $this->get_cache( $post_id, $references );
160
+		$contents = $this->get_cache($post_id, $references);
161 161
 
162 162
 		// Return the cached contents if any.
163
-		if ( false !== $contents ) {
164
-			$this->log->debug( "Cached contents found for post $post_id." );
163
+		if (false !== $contents) {
164
+			$this->log->debug("Cached contents found for post $post_id.");
165 165
 
166 166
 			// Inform the caller that this is cached result.
167 167
 			// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
168 168
 			$cache = true;
169
-			$this->add_http_header( $post_id, true );
169
+			$this->add_http_header($post_id, true);
170 170
 
171 171
 			// Return the contents.
172 172
 			return $contents;
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
 		// Set cached to false.
176 176
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
177 177
 		$cache = false;
178
-		$this->add_http_header( $post_id, false );
178
+		$this->add_http_header($post_id, false);
179 179
 
180 180
 		// Convert the post.
181
-		$jsonld = $this->converter->convert( $post_id, $references, $references_infos );
181
+		$jsonld = $this->converter->convert($post_id, $references, $references_infos);
182 182
 
183 183
 		/**
184 184
 		 * @since 3.32.0
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 		 * it here before saving it on cache.
187 187
 		 */
188 188
 		// Cache the results.
189
-		$this->set_cache( $post_id, $references, $jsonld );
189
+		$this->set_cache($post_id, $references, $jsonld);
190 190
 
191 191
 		// Finally return the JSON-LD.
192 192
 		return $jsonld;
@@ -202,28 +202,28 @@  discard block
 block discarded – undo
202 202
 	 * @since 3.16.0
203 203
 	 */
204 204
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
205
-	private function get_cache( $post_id, &$references = array() ) {
205
+	private function get_cache($post_id, &$references = array()) {
206 206
 
207 207
 		// Ensure post ID is int, because cache is strict about var types.
208 208
 		$post_id = (int) $post_id;
209 209
 
210
-		$this->log->trace( "Getting cached contents for post $post_id..." );
210
+		$this->log->trace("Getting cached contents for post $post_id...");
211 211
 
212 212
 		// Get the cache.
213
-		$modified_date_time = get_post_datetime( $post_id, 'modified', 'gmt' );
214
-		$contents           = $this->cache->get( $post_id, $modified_date_time->getTimestamp() );
213
+		$modified_date_time = get_post_datetime($post_id, 'modified', 'gmt');
214
+		$contents           = $this->cache->get($post_id, $modified_date_time->getTimestamp());
215 215
 
216 216
 		// Bail out if we don't have cached contents or the cached contents are
217 217
 		// invalid.
218
-		if ( null === $contents || ! isset( $contents['jsonld'] ) || ! isset( $contents['references'] ) ) {
219
-			$this->log->debug( "Cached contents for post $post_id not found." );
218
+		if (null === $contents || ! isset($contents['jsonld']) || ! isset($contents['references'])) {
219
+			$this->log->debug("Cached contents for post $post_id not found.");
220 220
 
221 221
 			return false;
222 222
 		}
223 223
 
224 224
 		// Remap the cache.
225 225
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
226
-		$references = $this->reference_processor->deserialize_references( $contents['references'] );
226
+		$references = $this->reference_processor->deserialize_references($contents['references']);
227 227
 
228 228
 		return $contents['jsonld'];
229 229
 	}
@@ -239,14 +239,14 @@  discard block
 block discarded – undo
239 239
 	 *
240 240
 	 * @since 3.16.0
241 241
 	 */
242
-	private function set_cache( $post_id, $references, $jsonld ) {
242
+	private function set_cache($post_id, $references, $jsonld) {
243 243
 
244
-		$this->log->trace( "Caching result for post $post_id..." );
244
+		$this->log->trace("Caching result for post $post_id...");
245 245
 
246 246
 		$this->cache->put(
247 247
 			$post_id,
248 248
 			array(
249
-				'references' => $this->reference_processor->serialize_references( $references ),
249
+				'references' => $this->reference_processor->serialize_references($references),
250 250
 				'jsonld'     => $jsonld,
251 251
 			)
252 252
 		);
@@ -260,13 +260,13 @@  discard block
 block discarded – undo
260 260
 	 *
261 261
 	 * @since 3.16.0
262 262
 	 */
263
-	public function save_post( $post_id ) {
263
+	public function save_post($post_id) {
264 264
 
265
-		$this->log->trace( "Post $post_id saved, invalidating cache..." );
265
+		$this->log->trace("Post $post_id saved, invalidating cache...");
266 266
 
267
-		$this->cache->delete( $post_id );
267
+		$this->cache->delete($post_id);
268 268
 
269
-		$this->flush_cache_if_publisher( $post_id );
269
+		$this->flush_cache_if_publisher($post_id);
270 270
 
271 271
 	}
272 272
 
@@ -280,21 +280,21 @@  discard block
 block discarded – undo
280 280
 	 *
281 281
 	 * @since 3.16.0
282 282
 	 */
283
-	public function changed_post_meta( $id, $post_id, $meta_key ) {
283
+	public function changed_post_meta($id, $post_id, $meta_key) {
284 284
 
285
-		if ( in_array( $meta_key, self::$ignored_meta_keys, true ) ) {
286
-			$this->log->trace( "Post $post_id meta $meta_key ignored." );
285
+		if (in_array($meta_key, self::$ignored_meta_keys, true)) {
286
+			$this->log->trace("Post $post_id meta $meta_key ignored.");
287 287
 
288 288
 			return;
289 289
 		}
290 290
 
291
-		$this->log->trace( "Post $post_id meta $meta_key changed, invalidating cache..." );
291
+		$this->log->trace("Post $post_id meta $meta_key changed, invalidating cache...");
292 292
 
293 293
 		// Delete the single cache file.
294
-		$this->cache->delete( $post_id );
294
+		$this->cache->delete($post_id);
295 295
 
296 296
 		// Flush the cache if it's the publisher.
297
-		$this->flush_cache_if_publisher( $post_id );
297
+		$this->flush_cache_if_publisher($post_id);
298 298
 
299 299
 	}
300 300
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 	 * @since 3.16.0
305 305
 	 */
306 306
 	public function update_option_wl_general_settings() {
307
-		$this->log->trace( 'WordLift options changed, flushing cache...' );
307
+		$this->log->trace('WordLift options changed, flushing cache...');
308 308
 
309 309
 		$this->cache->flush();
310 310
 	}
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 * @since 3.17.0
316 316
 	 */
317 317
 	public function permalinks_structure_changed() {
318
-		$this->log->trace( 'Permalinks structure changed, flushing cache...' );
318
+		$this->log->trace('Permalinks structure changed, flushing cache...');
319 319
 
320 320
 		$this->cache->flush();
321 321
 	}
@@ -327,10 +327,10 @@  discard block
 block discarded – undo
327 327
 	 *
328 328
 	 * @since 3.16.0
329 329
 	 */
330
-	public function relation_changed( $post_id ) {
331
-		$this->log->trace( "Post $post_id relations changed, invalidating cache..." );
330
+	public function relation_changed($post_id) {
331
+		$this->log->trace("Post $post_id relations changed, invalidating cache...");
332 332
 
333
-		$this->cache->delete( $post_id );
333
+		$this->cache->delete($post_id);
334 334
 	}
335 335
 
336 336
 	/**
@@ -342,13 +342,13 @@  discard block
 block discarded – undo
342 342
 	 *
343 343
 	 * @since 3.16.0
344 344
 	 */
345
-	private function add_http_header( $post_id, $cache ) {
345
+	private function add_http_header($post_id, $cache) {
346 346
 
347
-		if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || headers_sent() ) {
347
+		if ( ! defined('DOING_AJAX') || ! DOING_AJAX || headers_sent()) {
348 348
 			return;
349 349
 		}
350 350
 
351
-		header( "X-WordLift-JsonLd-Cache-$post_id: " . ( $cache ? 'HIT' : 'MISS' ) );
351
+		header("X-WordLift-JsonLd-Cache-$post_id: ".($cache ? 'HIT' : 'MISS'));
352 352
 
353 353
 	}
354 354
 
@@ -360,10 +360,10 @@  discard block
 block discarded – undo
360 360
 	 *
361 361
 	 * @since 3.16.0
362 362
 	 */
363
-	private function flush_cache_if_publisher( $post_id ) {
363
+	private function flush_cache_if_publisher($post_id) {
364 364
 
365 365
 		// Bail out if it's not the publisher.
366
-		if ( Wordlift_Configuration_Service::get_instance()->get_publisher_id() !== $post_id ) {
366
+		if (Wordlift_Configuration_Service::get_instance()->get_publisher_id() !== $post_id) {
367 367
 			return;
368 368
 		}
369 369
 
Please login to merge, or discard this patch.