Completed
Pull Request — develop (#1657)
by Naveen
01:38
created
src/wordlift/vocabulary/cache/class-options-cache.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,27 +11,27 @@
 block discarded – undo
11 11
 	 *
12 12
 	 * @param $namespace
13 13
 	 */
14
-	public function __construct( $namespace ) {
14
+	public function __construct($namespace) {
15 15
 		$this->namespace = $namespace;
16 16
 	}
17 17
 
18
-	public function get( $cache_key ) {
18
+	public function get($cache_key) {
19 19
 
20
-		return get_option( $this->namespace . '__' . $cache_key, false );
20
+		return get_option($this->namespace.'__'.$cache_key, false);
21 21
 
22 22
 	}
23 23
 
24
-	public function put( $cache_key, $value ) {
24
+	public function put($cache_key, $value) {
25 25
 
26
-		return update_option( $this->namespace . '__' . $cache_key, $value, false );
26
+		return update_option($this->namespace.'__'.$cache_key, $value, false);
27 27
 
28 28
 	}
29 29
 
30 30
 	public function flush_all() {
31
-		if ( '' !== $this->namespace ) {
31
+		if ('' !== $this->namespace) {
32 32
 			global $wpdb;
33
-			$namespace_esc = $wpdb->esc_like( $this->namespace ) . '__%';
34
-			$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", $namespace_esc ) );
33
+			$namespace_esc = $wpdb->esc_like($this->namespace).'__%';
34
+			$wpdb->query($wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE %s", $namespace_esc));
35 35
 		}
36 36
 	}
37 37
 
Please login to merge, or discard this patch.
src/wordlift/task/action-scheduler/class-background-task.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -26,27 +26,27 @@  discard block
 block discarded – undo
26 26
 	 */
27 27
 	private $batch_size;
28 28
 
29
-	public function __construct( $hook, $group, $task, $option_prefix, $batch_size = 5 ) {
30
-		parent::__construct( $hook, $group );
29
+	public function __construct($hook, $group, $task, $option_prefix, $batch_size = 5) {
30
+		parent::__construct($hook, $group);
31 31
 		$this->task          = $task;
32 32
 		$this->option_prefix = $option_prefix;
33 33
 		$this->batch_size    = $batch_size;
34 34
 	}
35 35
 
36 36
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
37
-	public function do_task( $args ) {
38
-		if ( self::STATE_STOPPED === $this->get_process_state() ) {
37
+	public function do_task($args) {
38
+		if (self::STATE_STOPPED === $this->get_process_state()) {
39 39
 			return State::complete();
40 40
 		}
41 41
 		$context = $this->get_context();
42
-		$this->task->tick( null, $context->get_data() + array( 'batch_size' => $this->batch_size ) );
42
+		$this->task->tick(null, $context->get_data() + array('batch_size' => $this->batch_size));
43 43
 
44
-		if ( ( $context->get_count() - $context->get_offset() ) >= 0 ) {
45
-			$context->set_offset( $context->get_offset() + $this->batch_size )->set_updated( time() );
46
-			$this->set_info( $context );
44
+		if (($context->get_count() - $context->get_offset()) >= 0) {
45
+			$context->set_offset($context->get_offset() + $this->batch_size)->set_updated(time());
46
+			$this->set_info($context);
47 47
 			return State::items_in_queue();
48 48
 		} else {
49
-			$this->set_process_state( self::STATE_STOPPED );
49
+			$this->set_process_state(self::STATE_STOPPED);
50 50
 			return State::complete();
51 51
 		}
52 52
 
@@ -54,22 +54,22 @@  discard block
 block discarded – undo
54 54
 
55 55
 	public function start() {
56 56
 		$this->delete_info();
57
-		$this->set_process_state( self::STATE_STARTED );
57
+		$this->set_process_state(self::STATE_STARTED);
58 58
 		$this->schedule();
59 59
 	}
60 60
 
61 61
 	public function stop() {
62
-		$this->set_process_state( self::STATE_STOPPED );
62
+		$this->set_process_state(self::STATE_STOPPED);
63 63
 		$this->unschedule();
64 64
 	}
65 65
 
66 66
 	public function resume() {
67
-		$this->set_process_state( self::STATE_STARTED );
67
+		$this->set_process_state(self::STATE_STARTED);
68 68
 		$this->schedule();
69 69
 	}
70 70
 
71 71
 	public function get_info() {
72
-		return $this->get_context()->get_data() + array( 'state' => $this->get_process_state() );
72
+		return $this->get_context()->get_data() + array('state' => $this->get_process_state());
73 73
 	}
74 74
 
75 75
 	public function get_context() {
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
 			null
79 79
 		);
80 80
 
81
-		if ( null === $data ) {
82
-			return Context::from( (int) $this->task->starting() );
81
+		if (null === $data) {
82
+			return Context::from((int) $this->task->starting());
83 83
 		}
84 84
 
85
-		return Context::from_data( $data );
85
+		return Context::from_data($data);
86 86
 	}
87 87
 
88 88
 	/**
@@ -90,19 +90,19 @@  discard block
 block discarded – undo
90 90
 	 *
91 91
 	 * @return void
92 92
 	 */
93
-	public function set_info( $context ) {
94
-		update_option( "{$this->option_prefix}_state", $context->get_data(), false );
93
+	public function set_info($context) {
94
+		update_option("{$this->option_prefix}_state", $context->get_data(), false);
95 95
 	}
96 96
 
97 97
 	private function delete_info() {
98
-		delete_option( "{$this->option_prefix}_state" );
98
+		delete_option("{$this->option_prefix}_state");
99 99
 	}
100 100
 
101 101
 	private function get_process_state() {
102
-		return get_option( "{$this->option_prefix}_action_scheduler_state", self::STATE_STOPPED );
102
+		return get_option("{$this->option_prefix}_action_scheduler_state", self::STATE_STOPPED);
103 103
 	}
104 104
 
105
-	private function set_process_state( $state ) {
106
-		update_option( "{$this->option_prefix}_action_scheduler_state", $state );
105
+	private function set_process_state($state) {
106
+		update_option("{$this->option_prefix}_action_scheduler_state", $state);
107 107
 	}
108 108
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-key-validation-service.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -42,9 +42,9 @@  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
 		 *
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 		 * @return bool
54 54
 		 * @since 3.27.6
55 55
 		 */
56
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
57
-			add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) );
56
+		if (apply_filters('wl_feature__enable__notices', true)) {
57
+			add_action('admin_notices', array($this, 'wl_key_update_notice'));
58 58
 		}
59 59
 
60
-		$this->ttl_cache_service = new Ttl_Cache( 'key-validation-notification' );
60
+		$this->ttl_cache_service = new Ttl_Cache('key-validation-notification');
61 61
 
62 62
 	}
63 63
 
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 	 * @return WP_Error|array The response or WP_Error on failure.
70 70
 	 * @since 3.9.0
71 71
 	 */
72
-	public function get_account_info( $key ) {
72
+	public function get_account_info($key) {
73 73
 
74
-		$this->log->debug( 'Validating key...' );
74
+		$this->log->debug('Validating key...');
75 75
 
76 76
 		$response = Default_Api_Service::get_instance()->get(
77 77
 			'/accounts/info',
@@ -85,35 +85,35 @@  discard block
 block discarded – undo
85 85
 		 * This action is fired when the key is validated.
86 86
 		 * @param $response \Wordlift\Api\Response
87 87
 		 */
88
-		do_action( 'wl_key_validation_response', $response );
88
+		do_action('wl_key_validation_response', $response);
89 89
 
90 90
 		return $response->get_response();
91 91
 	}
92 92
 
93
-	private function key_validation_request( $key ) {
94
-		$response = $this->get_account_info( $key );
93
+	private function key_validation_request($key) {
94
+		$response = $this->get_account_info($key);
95 95
 
96
-		if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) {
97
-			throw new \Exception( __( 'An error occurred, please contact us at [email protected]', 'wordlift' ) );
96
+		if (is_wp_error($response) || 2 !== (int) $response['response']['code'] / 100) {
97
+			throw new \Exception(__('An error occurred, please contact us at [email protected]', 'wordlift'));
98 98
 		}
99 99
 
100
-		$res_body = json_decode( wp_remote_retrieve_body( $response ), true );
100
+		$res_body = json_decode(wp_remote_retrieve_body($response), true);
101 101
 
102 102
 		$url = $res_body['url'];
103 103
 
104
-		$enabled_features = array_keys( array_filter( $res_body['features'] ) );
105
-		$plugin_features  = array( Entity_Type_Setter::STARTER_PLAN, Entity_Type_Setter::PROFESSIONAL_PLAN, Entity_Type_Setter::BUSINESS_PLAN );
104
+		$enabled_features = array_keys(array_filter($res_body['features']));
105
+		$plugin_features  = array(Entity_Type_Setter::STARTER_PLAN, Entity_Type_Setter::PROFESSIONAL_PLAN, Entity_Type_Setter::BUSINESS_PLAN);
106 106
 
107
-		if ( count( array_intersect( $enabled_features, $plugin_features ) ) === 0 ) {
108
-			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' ) );
107
+		if (count(array_intersect($enabled_features, $plugin_features)) === 0) {
108
+			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'));
109 109
 		}
110 110
 
111 111
 		// Considering that production URL may be filtered.
112
-		$home_url = get_option( 'home' );
113
-		$site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) );
112
+		$home_url = get_option('home');
113
+		$site_url = apply_filters('wl_production_site_url', untrailingslashit($home_url));
114 114
 
115
-		if ( $url !== $site_url ) {
116
-			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' ) );
115
+		if ($url !== $site_url) {
116
+			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'));
117 117
 		}
118 118
 
119 119
 		return true;
@@ -126,11 +126,11 @@  discard block
 block discarded – undo
126 126
 	 *
127 127
 	 * @return bool
128 128
 	 */
129
-	public function is_key_valid( $key ) {
129
+	public function is_key_valid($key) {
130 130
 		try {
131
-			$this->key_validation_request( $key );
131
+			$this->key_validation_request($key);
132 132
 			return true;
133
-		} catch ( \Exception $e ) {
133
+		} catch (\Exception $e) {
134 134
 			return false;
135 135
 		}
136 136
 	}
@@ -146,14 +146,14 @@  discard block
 block discarded – undo
146 146
 		ob_clean();
147 147
 
148 148
 		// Check if we have a key.
149
-		if ( ! isset( $_POST['key'] ) ) {  //phpcs:ignore WordPress.Security.NonceVerification.Missing
150
-			wp_send_json_error( 'The key parameter is required.' );
149
+		if ( ! isset($_POST['key'])) {  //phpcs:ignore WordPress.Security.NonceVerification.Missing
150
+			wp_send_json_error('The key parameter is required.');
151 151
 		}
152 152
 
153
-		$this->ttl_cache_service->delete( 'is_key_valid' );
153
+		$this->ttl_cache_service->delete('is_key_valid');
154 154
 
155 155
 		try {
156
-			$this->key_validation_request( sanitize_text_field( wp_unslash( (string) $_POST['key'] ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Missing
156
+			$this->key_validation_request(sanitize_text_field(wp_unslash((string) $_POST['key']))); //phpcs:ignore WordPress.Security.NonceVerification.Missing
157 157
 			wp_send_json_success(
158 158
 				array(
159 159
 					'valid'   => true,
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 				)
162 162
 			);
163 163
 
164
-		} catch ( \Exception $e ) {
165
-			Wordlift_Configuration_Service::get_instance()->set_key( '' );
164
+		} catch (\Exception $e) {
165
+			Wordlift_Configuration_Service::get_instance()->set_key('');
166 166
 			wp_send_json_success(
167 167
 				array(
168 168
 					'valid'   => false,
@@ -178,15 +178,15 @@  discard block
 block discarded – undo
178 178
 	 */
179 179
 	public function wl_load_plugin() {
180 180
 
181
-		$wl_blog_url = get_option( '_wl_blog_url' );
182
-		$home_url    = get_option( 'home' );
181
+		$wl_blog_url = get_option('_wl_blog_url');
182
+		$home_url    = get_option('home');
183 183
 
184
-		if ( ! $wl_blog_url ) {
185
-			update_option( '_wl_blog_url', $home_url, true );
186
-		} elseif ( $wl_blog_url !== $home_url ) {
187
-			update_option( '_wl_blog_url', $home_url, true );
188
-			Wordlift_Configuration_Service::get_instance()->set_key( '' );
189
-			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 );
184
+		if ( ! $wl_blog_url) {
185
+			update_option('_wl_blog_url', $home_url, true);
186
+		} elseif ($wl_blog_url !== $home_url) {
187
+			update_option('_wl_blog_url', $home_url, true);
188
+			Wordlift_Configuration_Service::get_instance()->set_key('');
189
+			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);
190 190
 		}
191 191
 
192 192
 	}
@@ -195,10 +195,10 @@  discard block
 block discarded – undo
195 195
 	 * This function is hooked to the `admin_notices` to show admin notification.
196 196
 	 */
197 197
 	public function wl_key_update_notice() {
198
-		if ( get_transient( 'wl-key-error-msg' ) ) {
198
+		if (get_transient('wl-key-error-msg')) {
199 199
 			?>
200 200
 			<div class="updated notice is-dismissible error">
201
-				<p><?php esc_html( get_transient( 'wl-key-error-msg' ) ); ?></p>
201
+				<p><?php esc_html(get_transient('wl-key-error-msg')); ?></p>
202 202
 			</div>
203 203
 			<?php
204 204
 		}
Please login to merge, or discard this patch.
src/wordlift/api/class-api-headers-service.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@  discard block
 block discarded – undo
17 17
 	 */
18 18
 	public function get_wp_headers() {
19 19
 		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
20
-		$is_plugin_subscription = apply_filters( 'wl_feature__enable__entity-types-professional', false ) ||
20
+		$is_plugin_subscription = apply_filters('wl_feature__enable__entity-types-professional', false) ||
21 21
 		                          // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
22
-										   apply_filters( 'wl_feature__enable__entity-types-business', false ) ||
22
+										   apply_filters('wl_feature__enable__entity-types-business', false) ||
23 23
 		                          // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
24
-										   apply_filters( 'wl_feature__enable__entity-types-starter', false );
24
+										   apply_filters('wl_feature__enable__entity-types-starter', false);
25 25
 		return $is_plugin_subscription ? array(
26
-			'X-Wordlift-Plugin-Wp-Admin' => untrailingslashit( get_admin_url() ),
27
-			'X-Wordlift-Plugin-Wp-Json'  => untrailingslashit( get_rest_url() ),
26
+			'X-Wordlift-Plugin-Wp-Admin' => untrailingslashit(get_admin_url()),
27
+			'X-Wordlift-Plugin-Wp-Json'  => untrailingslashit(get_rest_url()),
28 28
 		) : array();
29 29
 	}
30 30
 
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 * @return Api_Headers_Service
33 33
 	 */
34 34
 	public static function get_instance() {
35
-		if ( null === self::$instance ) {
35
+		if (null === self::$instance) {
36 36
 			self::$instance = new Api_Headers_Service();
37 37
 		}
38 38
 
Please login to merge, or discard this patch.