Completed
Push — develop ( dd9396...6243cc )
by David
01:19
created
src/wordlift.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -31,26 +31,26 @@  discard block
 block discarded – undo
31 31
 use Wordlift\Features\Features_Registry;
32 32
 use Wordlift\Post\Post_Adapter;
33 33
 
34
-define( 'WORDLIFT_PLUGIN_FILE', __FILE__ );
35
-define( 'WORDLIFT_VERSION', '3.50.0-1' );
34
+define('WORDLIFT_PLUGIN_FILE', __FILE__);
35
+define('WORDLIFT_VERSION', '3.50.0-1');
36 36
 
37 37
 // ## DO NOT REMOVE THIS LINE: WHITELABEL PLACEHOLDER ##
38 38
 
39
-require_once plugin_dir_path( __FILE__ ) . '/libraries/action-scheduler/action-scheduler.php';
40
-require_once __DIR__ . '/modules/common/load.php';
41
-require_once __DIR__ . '/modules/app/load.php';
42
-require_once __DIR__ . '/modules/include-exclude/load.php';
39
+require_once plugin_dir_path(__FILE__).'/libraries/action-scheduler/action-scheduler.php';
40
+require_once __DIR__.'/modules/common/load.php';
41
+require_once __DIR__.'/modules/app/load.php';
42
+require_once __DIR__.'/modules/include-exclude/load.php';
43 43
 
44 44
 /**
45 45
  * Filter to disable WLP on any request, defaults to true.
46 46
  *
47 47
  * @since 3.33.6
48 48
  */
49
-if ( ! apply_filters( 'wl_is_enabled', true ) ) {
49
+if ( ! apply_filters('wl_is_enabled', true)) {
50 50
 	return;
51 51
 }
52 52
 
53
-require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
53
+require_once plugin_dir_path(__FILE__).'vendor/autoload.php';
54 54
 
55 55
 /*
56 56
  * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http.
@@ -60,15 +60,15 @@  discard block
 block discarded – undo
60 60
 wordlift_plugin_autoload_register();
61 61
 
62 62
 // Include WordLift constants.
63
-require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php';
63
+require_once plugin_dir_path(__FILE__).'wordlift-constants.php';
64 64
 
65 65
 // Load modules.
66
-require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php';
66
+require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php';
67 67
 
68
-require_once plugin_dir_path( __FILE__ ) . 'deprecations.php';
68
+require_once plugin_dir_path(__FILE__).'deprecations.php';
69 69
 
70 70
 // Load early to enable/disable features.
71
-require_once plugin_dir_path( __FILE__ ) . 'classes/features/index.php';
71
+require_once plugin_dir_path(__FILE__).'classes/features/index.php';
72 72
 
73 73
 /**
74 74
  * The code that runs during plugin activation.
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
  */
77 77
 function activate_wordlift() {
78 78
 
79
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
79
+	$log = Wordlift_Log_Service::get_logger('activate_wordlift');
80 80
 
81
-	$log->info( 'Activating WordLift...' );
81
+	$log->info('Activating WordLift...');
82 82
 
83
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
83
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
84 84
 	Wordlift_Activator::activate();
85 85
 
86 86
 	/**
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
 	 */
101 101
 	Top_Entities::activate();
102 102
 
103
-	if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) {
104
-		wp_schedule_event( time(), 'daily', 'wl_daily_cron' );
103
+	if ( ! wp_next_scheduled('wl_daily_cron')) {
104
+		wp_schedule_event(time(), 'daily', 'wl_daily_cron');
105 105
 	}
106 106
 
107 107
 }
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
  */
113 113
 function deactivate_wordlift() {
114 114
 
115
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
115
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
116 116
 	Wordlift_Deactivator::deactivate();
117 117
 	Wordlift_Http_Api::deactivate();
118 118
 	Ttl_Cache_Cleaner::deactivate();
@@ -128,18 +128,18 @@  discard block
 block discarded – undo
128 128
 	Key_Validation_Notice::remove_notification_flag();
129 129
 	flush_rewrite_rules();
130 130
 
131
-	wp_clear_scheduled_hook( 'wl_daily_cron' );
131
+	wp_clear_scheduled_hook('wl_daily_cron');
132 132
 
133 133
 }
134 134
 
135
-register_activation_hook( __FILE__, 'activate_wordlift' );
136
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
135
+register_activation_hook(__FILE__, 'activate_wordlift');
136
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
137 137
 
138 138
 /**
139 139
  * The core plugin class that is used to define internationalization,
140 140
  * admin-specific hooks, and public-facing site hooks.
141 141
  */
142
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
142
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
143 143
 
144 144
 /**
145 145
  * Begins execution of the plugin.
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
 	 * @return bool
160 160
 	 * @since 3.27.6
161 161
 	 */
162
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
163
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
164
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
165
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
162
+	if (apply_filters('wl_feature__enable__widgets', true)) {
163
+		add_action('widgets_init', 'wl_register_chord_widget');
164
+		add_action('widgets_init', 'wl_register_geo_widget');
165
+		add_action('widgets_init', 'wl_register_timeline_widget');
166 166
 	}
167
-	add_filter( 'widget_text', 'do_shortcode' );
167
+	add_filter('widget_text', 'do_shortcode');
168 168
 
169 169
 	/**
170 170
 	 * Filter: wl_feature__enable__analysis
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 	 * @return bool
175 175
 	 * @since 3.27.6
176 176
 	 */
177
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
178
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
177
+	if (apply_filters('wl_feature__enable__analysis', true)) {
178
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action');
179 179
 	} else {
180
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
180
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action');
181 181
 	}
182 182
 
183 183
 	$plugin = new Wordlift();
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 
195 195
 	add_action(
196 196
 		'plugins_loaded',
197
-		function () {
197
+		function() {
198 198
 			// All features from registry should be initialized here.
199 199
 			$features_registry = Features_Registry::get_instance();
200 200
 			$features_registry->initialize_all_features();
@@ -205,27 +205,27 @@  discard block
 block discarded – undo
205 205
 	add_action(
206 206
 		'plugins_loaded',
207 207
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
208
-		function () use ( $plugin ) {
208
+		function() use ($plugin) {
209 209
 
210 210
 			new Wordlift_Products_Navigator_Shortcode_REST();
211 211
 
212 212
 			// Register the Dataset module, requires `$api_service`.
213
-			require_once plugin_dir_path( __FILE__ ) . 'classes/dataset/index.php';
214
-			require_once plugin_dir_path( __FILE__ ) . 'classes/shipping-data/index.php';
213
+			require_once plugin_dir_path(__FILE__).'classes/dataset/index.php';
214
+			require_once plugin_dir_path(__FILE__).'classes/shipping-data/index.php';
215 215
 
216 216
 			/*
217 217
 			* Require the Entity annotation cleanup module.
218 218
 			*
219 219
 			* @since 3.34.6
220 220
 			*/
221
-			require_once plugin_dir_path( __FILE__ ) . 'classes/cleanup/index.php';
221
+			require_once plugin_dir_path(__FILE__).'classes/cleanup/index.php';
222 222
 
223 223
 			/*
224 224
 			* Import LOD entities.
225 225
 			*
226 226
 			* @since 3.35.0
227 227
 			*/
228
-			require_once plugin_dir_path( __FILE__ ) . 'classes/lod-import/index.php';
228
+			require_once plugin_dir_path(__FILE__).'classes/lod-import/index.php';
229 229
 
230 230
 		}
231 231
 	);
@@ -243,31 +243,31 @@  discard block
 block discarded – undo
243 243
 function wordlift_plugin_autoload_register() {
244 244
 
245 245
 	spl_autoload_register(
246
-		function ( $class_name ) {
246
+		function($class_name) {
247 247
 
248 248
 			// Bail out if these are not our classes.
249
-			if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
249
+			if (0 !== strpos($class_name, 'Wordlift\\')) {
250 250
 				return false;
251 251
 			}
252 252
 
253
-			$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
253
+			$class_name_lc = strtolower(str_replace('_', '-', $class_name));
254 254
 
255
-			preg_match( '|^wordlift\\\\(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
255
+			preg_match('|^wordlift\\\\(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches);
256 256
 
257
-			$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
258
-			$file = 'class-' . $matches[2] . '.php';
257
+			$path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]);
258
+			$file = 'class-'.$matches[2].'.php';
259 259
 
260
-			$full_path = plugin_dir_path( __FILE__ ) . 'classes' . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $file;
260
+			$full_path = plugin_dir_path(__FILE__).'classes'.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$file;
261 261
 
262
-			if ( ! file_exists( $full_path ) ) {
262
+			if ( ! file_exists($full_path)) {
263 263
 				return false;
264 264
 			}
265 265
 
266 266
 			try {
267 267
 				require_once $full_path;
268
-			} catch ( Exception $e ) {
268
+			} catch (Exception $e) {
269 269
 				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
270
-				error_log( "[WordLift] $full_path not found, cannot include." );
270
+				error_log("[WordLift] $full_path not found, cannot include.");
271 271
 			}
272 272
 
273 273
 			return true;
@@ -276,13 +276,13 @@  discard block
 block discarded – undo
276 276
 
277 277
 }
278 278
 
279
-function wl_block_categories( $categories ) {
279
+function wl_block_categories($categories) {
280 280
 	return array_merge(
281 281
 		$categories,
282 282
 		array(
283 283
 			array(
284 284
 				'slug'  => 'wordlift',
285
-				'title' => __( 'WordLift', 'wordlift' ),
285
+				'title' => __('WordLift', 'wordlift'),
286 286
 			),
287 287
 		)
288 288
 	);
@@ -292,49 +292,49 @@  discard block
 block discarded – undo
292 292
  * This function is created temporarily to handle the legacy library,
293 293
  * this has to be removed when removing the legacy fields from the ui.
294 294
  */
295
-function wl_enqueue_leaflet( $in_footer = false ) {
295
+function wl_enqueue_leaflet($in_footer = false) {
296 296
 	// Leaflet.
297
-	wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
298
-	wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
297
+	wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0');
298
+	wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer);
299 299
 }
300 300
 
301
-add_filter( 'block_categories', 'wl_block_categories', 10 );
301
+add_filter('block_categories', 'wl_block_categories', 10);
302 302
 
303 303
 // Temporary fix for a typo in WooCommerce Extension.
304 304
 add_filter(
305 305
 	'wl_feature__enable__dataset',
306
-	function ( $value ) {
307
-		return apply_filters( 'wl_features__enable__dataset', $value );
306
+	function($value) {
307
+		return apply_filters('wl_features__enable__dataset', $value);
308 308
 	}
309 309
 );
310 310
 
311
-require_once __DIR__ . '/modules/food-kg/load.php';
312
-require_once __DIR__ . '/modules/gardening-kg/load.php';
313
-require_once __DIR__ . '/modules/acf4so/load.php';
314
-require_once __DIR__ . '/modules/dashboard/load.php';
315
-require_once __DIR__ . '/modules/pods/load.php';
316
-require_once __DIR__ . '/modules/include-exclude-push-config/load.php';
317
-require_once __DIR__ . '/modules/super-resolution/load.php';
318
-require_once __DIR__ . '/modules/redeem-code/load.php';
319
-require_once __DIR__ . '/modules/raptive-setup/load.php';
320
-require_once __DIR__ . '/modules/events/load.php';
321
-
322
-function _wl_update_plugins_raptive_domain( $update, $plugin_data, $plugin_file ) {
311
+require_once __DIR__.'/modules/food-kg/load.php';
312
+require_once __DIR__.'/modules/gardening-kg/load.php';
313
+require_once __DIR__.'/modules/acf4so/load.php';
314
+require_once __DIR__.'/modules/dashboard/load.php';
315
+require_once __DIR__.'/modules/pods/load.php';
316
+require_once __DIR__.'/modules/include-exclude-push-config/load.php';
317
+require_once __DIR__.'/modules/super-resolution/load.php';
318
+require_once __DIR__.'/modules/redeem-code/load.php';
319
+require_once __DIR__.'/modules/raptive-setup/load.php';
320
+require_once __DIR__.'/modules/events/load.php';
321
+
322
+function _wl_update_plugins_raptive_domain($update, $plugin_data, $plugin_file) {
323 323
 	// Bail out if it's not our plugin.
324 324
 	$update_uri = $plugin_data['UpdateURI'];
325
-	if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) {
325
+	if ('wordlift/wordlift.php' !== $plugin_file || ! isset($update_uri)) {
326 326
 		return $update;
327 327
 	}
328 328
 
329
-	$response = wp_remote_get( "$update_uri?nocache=" . time() );
329
+	$response = wp_remote_get("$update_uri?nocache=".time());
330 330
 
331
-	if ( is_wp_error( $response ) ) {
331
+	if (is_wp_error($response)) {
332 332
 		return $update;
333 333
 	}
334 334
 
335 335
 	try {
336
-		return json_decode( wp_remote_retrieve_body( $response ) );
337
-	} catch ( Exception $e ) {
336
+		return json_decode(wp_remote_retrieve_body($response));
337
+	} catch (Exception $e) {
338 338
 		return $update;
339 339
 	}
340 340
 }
Please login to merge, or discard this patch.
src/classes/api/class-default-api-service.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -7,152 +7,152 @@
 block discarded – undo
7 7
 
8 8
 class Default_Api_Service implements Api_Service, Api_Service_Ext {
9 9
 
10
-	/**
11
-	 * @var string
12
-	 */
13
-	private $wordlift_key;
14
-	/**
15
-	 * @var int
16
-	 */
17
-	private $timeout;
18
-
19
-	/**
20
-	 * @var string
21
-	 */
22
-	private $user_agent;
23
-
24
-	/**
25
-	 * @var array
26
-	 */
27
-	private $headers;
28
-	/**
29
-	 * @var string
30
-	 */
31
-	private $base_url;
32
-
33
-	/**
34
-	 * @var \Wordlift_Log_Service
35
-	 */
36
-	private $log;
37
-
38
-	/**
39
-	 * Default_Api_Service constructor.
40
-	 *
41
-	 * @param string $base_url
42
-	 * @param int    $timeout
43
-	 * @param string $user_agent
44
-	 * @param string $wordlift_key
45
-	 */
46
-	protected function __construct( $base_url, $timeout, $user_agent, $wordlift_key ) {
47
-
48
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
49
-
50
-		$this->base_url     = untrailingslashit( $base_url );
51
-		$this->timeout      = $timeout;
52
-		$this->user_agent   = $user_agent;
53
-		$this->wordlift_key = $wordlift_key;
54
-
55
-		$this->headers = array(
56
-			'Content-Type'  => 'application/json',
57
-			'Authorization' => "Key $wordlift_key",
58
-			'Expect'        => '',
59
-		);
60
-
61
-		self::$instance = $this;
62
-	}
63
-
64
-	private static $instance;
65
-
66
-	/**
67
-	 * @return Default_Api_Service
68
-	 */
69
-	public static function get_instance() {
70
-		if ( ! isset( self::$instance ) ) {
71
-			self::$instance = new self(
72
-				apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ),
73
-				60,
74
-				User_Agent::get_user_agent(),
75
-				Wordlift_Configuration_Service::get_instance()->get_key()
76
-			);
77
-		}
78
-
79
-		return self::$instance;
80
-	}
81
-
82
-	public function request( $method, $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array() ) {
83
-
84
-		// Get the timeout for this request.
85
-		$request_timeout = isset( $timeout ) ? $timeout : $this->timeout;
86
-
87
-		// Set the time limit if lesser than our request timeout.
88
-		$max_execution_time = ini_get( 'max_execution_time' );
89
-		if ( ! ( defined( 'WP_CLI' ) && WP_CLI )
90
-			 && ( 0 !== intval( $max_execution_time ) )
91
-			 && ( $max_execution_time < $request_timeout ) ) {
92
-			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
93
-			@set_time_limit( $request_timeout );
94
-		}
95
-
96
-		$request_url = $this->base_url . $path;
97
-		// Create the request args in the following order:
98
-		// 1. use `$args` as base if provided.
99
-		// 2. set the custom timeout if provided.
100
-		// 3. set the custom user-agent if provided.
101
-		// 4. merge the API headers to the provided headers.
102
-		// 5. add the body.
103
-		//
104
-		// In this way the user can fully control the request if wanted (using `$args`) and we can add our defaults.
105
-		$request_args = apply_filters(
106
-			'wl_api_service__request',
107
-			$args + array(
108
-				'method'     => $method,
109
-				'timeout'    => $request_timeout,
110
-				'user-agent' => isset( $user_agent ) ? $user_agent : $this->user_agent,
111
-				'headers'    => $headers + $this->headers + Api_Headers_Service::get_instance()->get_wp_headers(),
112
-				'body'       => $body,
113
-			)
114
-		);
115
-
116
-		/**
117
-		 * Allow 3rd parties to process the response.
118
-		 */
119
-		$response = apply_filters(
120
-			'wl_api_service__response',
121
-			wp_remote_request( $request_url, $request_args ),
122
-			$request_url,
123
-			$request_args
124
-		);
125
-
126
-		if ( defined( 'WL_DEBUG' ) && WL_DEBUG ) {
127
-			$this->log->trace(
128
-				"=== REQUEST  ===========================\n"
129
-				. "=== URL: $request_url ===========================\n"
130
-				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
131
-				. var_export( $request_args, true )
132
-				. "=== RESPONSE ===========================\n"
133
-				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
134
-				. var_export( $response, true )
135
-			);
136
-		}
137
-
138
-		return new Response( $response );
139
-	}
140
-
141
-	public function get( $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array() ) {
142
-
143
-		return $this->request( 'GET', $path, $headers, $body, $timeout, $user_agent, $args );
144
-	}
145
-
146
-	public function get_base_url() {
147
-		return $this->base_url;
148
-	}
149
-
150
-	/**
151
-	 * @return Me_Response
152
-	 * @throws Exception when an error occurs.
153
-	 */
154
-	public function me() {
155
-		return json_decode( $this->get( '/accounts/me' )->get_body() );
156
-	}
10
+    /**
11
+     * @var string
12
+     */
13
+    private $wordlift_key;
14
+    /**
15
+     * @var int
16
+     */
17
+    private $timeout;
18
+
19
+    /**
20
+     * @var string
21
+     */
22
+    private $user_agent;
23
+
24
+    /**
25
+     * @var array
26
+     */
27
+    private $headers;
28
+    /**
29
+     * @var string
30
+     */
31
+    private $base_url;
32
+
33
+    /**
34
+     * @var \Wordlift_Log_Service
35
+     */
36
+    private $log;
37
+
38
+    /**
39
+     * Default_Api_Service constructor.
40
+     *
41
+     * @param string $base_url
42
+     * @param int    $timeout
43
+     * @param string $user_agent
44
+     * @param string $wordlift_key
45
+     */
46
+    protected function __construct( $base_url, $timeout, $user_agent, $wordlift_key ) {
47
+
48
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
49
+
50
+        $this->base_url     = untrailingslashit( $base_url );
51
+        $this->timeout      = $timeout;
52
+        $this->user_agent   = $user_agent;
53
+        $this->wordlift_key = $wordlift_key;
54
+
55
+        $this->headers = array(
56
+            'Content-Type'  => 'application/json',
57
+            'Authorization' => "Key $wordlift_key",
58
+            'Expect'        => '',
59
+        );
60
+
61
+        self::$instance = $this;
62
+    }
63
+
64
+    private static $instance;
65
+
66
+    /**
67
+     * @return Default_Api_Service
68
+     */
69
+    public static function get_instance() {
70
+        if ( ! isset( self::$instance ) ) {
71
+            self::$instance = new self(
72
+                apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ),
73
+                60,
74
+                User_Agent::get_user_agent(),
75
+                Wordlift_Configuration_Service::get_instance()->get_key()
76
+            );
77
+        }
78
+
79
+        return self::$instance;
80
+    }
81
+
82
+    public function request( $method, $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array() ) {
83
+
84
+        // Get the timeout for this request.
85
+        $request_timeout = isset( $timeout ) ? $timeout : $this->timeout;
86
+
87
+        // Set the time limit if lesser than our request timeout.
88
+        $max_execution_time = ini_get( 'max_execution_time' );
89
+        if ( ! ( defined( 'WP_CLI' ) && WP_CLI )
90
+             && ( 0 !== intval( $max_execution_time ) )
91
+             && ( $max_execution_time < $request_timeout ) ) {
92
+            // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
93
+            @set_time_limit( $request_timeout );
94
+        }
95
+
96
+        $request_url = $this->base_url . $path;
97
+        // Create the request args in the following order:
98
+        // 1. use `$args` as base if provided.
99
+        // 2. set the custom timeout if provided.
100
+        // 3. set the custom user-agent if provided.
101
+        // 4. merge the API headers to the provided headers.
102
+        // 5. add the body.
103
+        //
104
+        // In this way the user can fully control the request if wanted (using `$args`) and we can add our defaults.
105
+        $request_args = apply_filters(
106
+            'wl_api_service__request',
107
+            $args + array(
108
+                'method'     => $method,
109
+                'timeout'    => $request_timeout,
110
+                'user-agent' => isset( $user_agent ) ? $user_agent : $this->user_agent,
111
+                'headers'    => $headers + $this->headers + Api_Headers_Service::get_instance()->get_wp_headers(),
112
+                'body'       => $body,
113
+            )
114
+        );
115
+
116
+        /**
117
+         * Allow 3rd parties to process the response.
118
+         */
119
+        $response = apply_filters(
120
+            'wl_api_service__response',
121
+            wp_remote_request( $request_url, $request_args ),
122
+            $request_url,
123
+            $request_args
124
+        );
125
+
126
+        if ( defined( 'WL_DEBUG' ) && WL_DEBUG ) {
127
+            $this->log->trace(
128
+                "=== REQUEST  ===========================\n"
129
+                . "=== URL: $request_url ===========================\n"
130
+                // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
131
+                . var_export( $request_args, true )
132
+                . "=== RESPONSE ===========================\n"
133
+                // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
134
+                . var_export( $response, true )
135
+            );
136
+        }
137
+
138
+        return new Response( $response );
139
+    }
140
+
141
+    public function get( $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array() ) {
142
+
143
+        return $this->request( 'GET', $path, $headers, $body, $timeout, $user_agent, $args );
144
+    }
145
+
146
+    public function get_base_url() {
147
+        return $this->base_url;
148
+    }
149
+
150
+    /**
151
+     * @return Me_Response
152
+     * @throws Exception when an error occurs.
153
+     */
154
+    public function me() {
155
+        return json_decode( $this->get( '/accounts/me' )->get_body() );
156
+    }
157 157
 
158 158
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
 	 * @param string $user_agent
44 44
 	 * @param string $wordlift_key
45 45
 	 */
46
-	protected function __construct( $base_url, $timeout, $user_agent, $wordlift_key ) {
46
+	protected function __construct($base_url, $timeout, $user_agent, $wordlift_key) {
47 47
 
48
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
48
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
49 49
 
50
-		$this->base_url     = untrailingslashit( $base_url );
50
+		$this->base_url     = untrailingslashit($base_url);
51 51
 		$this->timeout      = $timeout;
52 52
 		$this->user_agent   = $user_agent;
53 53
 		$this->wordlift_key = $wordlift_key;
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
 	 * @return Default_Api_Service
68 68
 	 */
69 69
 	public static function get_instance() {
70
-		if ( ! isset( self::$instance ) ) {
70
+		if ( ! isset(self::$instance)) {
71 71
 			self::$instance = new self(
72
-				apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ),
72
+				apply_filters('wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE),
73 73
 				60,
74 74
 				User_Agent::get_user_agent(),
75 75
 				Wordlift_Configuration_Service::get_instance()->get_key()
@@ -79,21 +79,21 @@  discard block
 block discarded – undo
79 79
 		return self::$instance;
80 80
 	}
81 81
 
82
-	public function request( $method, $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array() ) {
82
+	public function request($method, $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array()) {
83 83
 
84 84
 		// Get the timeout for this request.
85
-		$request_timeout = isset( $timeout ) ? $timeout : $this->timeout;
85
+		$request_timeout = isset($timeout) ? $timeout : $this->timeout;
86 86
 
87 87
 		// Set the time limit if lesser than our request timeout.
88
-		$max_execution_time = ini_get( 'max_execution_time' );
89
-		if ( ! ( defined( 'WP_CLI' ) && WP_CLI )
90
-			 && ( 0 !== intval( $max_execution_time ) )
91
-			 && ( $max_execution_time < $request_timeout ) ) {
88
+		$max_execution_time = ini_get('max_execution_time');
89
+		if ( ! (defined('WP_CLI') && WP_CLI)
90
+			 && (0 !== intval($max_execution_time))
91
+			 && ($max_execution_time < $request_timeout)) {
92 92
 			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
93
-			@set_time_limit( $request_timeout );
93
+			@set_time_limit($request_timeout);
94 94
 		}
95 95
 
96
-		$request_url = $this->base_url . $path;
96
+		$request_url = $this->base_url.$path;
97 97
 		// Create the request args in the following order:
98 98
 		// 1. use `$args` as base if provided.
99 99
 		// 2. set the custom timeout if provided.
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 			$args + array(
108 108
 				'method'     => $method,
109 109
 				'timeout'    => $request_timeout,
110
-				'user-agent' => isset( $user_agent ) ? $user_agent : $this->user_agent,
110
+				'user-agent' => isset($user_agent) ? $user_agent : $this->user_agent,
111 111
 				'headers'    => $headers + $this->headers + Api_Headers_Service::get_instance()->get_wp_headers(),
112 112
 				'body'       => $body,
113 113
 			)
@@ -118,29 +118,29 @@  discard block
 block discarded – undo
118 118
 		 */
119 119
 		$response = apply_filters(
120 120
 			'wl_api_service__response',
121
-			wp_remote_request( $request_url, $request_args ),
121
+			wp_remote_request($request_url, $request_args),
122 122
 			$request_url,
123 123
 			$request_args
124 124
 		);
125 125
 
126
-		if ( defined( 'WL_DEBUG' ) && WL_DEBUG ) {
126
+		if (defined('WL_DEBUG') && WL_DEBUG) {
127 127
 			$this->log->trace(
128 128
 				"=== REQUEST  ===========================\n"
129 129
 				. "=== URL: $request_url ===========================\n"
130 130
 				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
131
-				. var_export( $request_args, true )
131
+				. var_export($request_args, true)
132 132
 				. "=== RESPONSE ===========================\n"
133 133
 				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
134
-				. var_export( $response, true )
134
+				. var_export($response, true)
135 135
 			);
136 136
 		}
137 137
 
138
-		return new Response( $response );
138
+		return new Response($response);
139 139
 	}
140 140
 
141
-	public function get( $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array() ) {
141
+	public function get($path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array()) {
142 142
 
143
-		return $this->request( 'GET', $path, $headers, $body, $timeout, $user_agent, $args );
143
+		return $this->request('GET', $path, $headers, $body, $timeout, $user_agent, $args);
144 144
 	}
145 145
 
146 146
 	public function get_base_url() {
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 * @throws Exception when an error occurs.
153 153
 	 */
154 154
 	public function me() {
155
-		return json_decode( $this->get( '/accounts/me' )->get_body() );
155
+		return json_decode($this->get('/accounts/me')->get_body());
156 156
 	}
157 157
 
158 158
 }
Please login to merge, or discard this patch.