Completed
Push — master ( f3a6aa...8848c4 )
by Naveen
01:08
created
src/includes/class-wordlift-key-validation-service.php 2 patches
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -20,192 +20,192 @@
 block discarded – undo
20 20
  */
21 21
 class Wordlift_Key_Validation_Service {
22 22
 
23
-	/**
24
-	 * A {@link Wordlift_Log_Service} instance.
25
-	 *
26
-	 * @since  3.14.0
27
-	 * @access private
28
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
29
-	 */
30
-	private $log;
31
-
32
-	/**
33
-	 * @var Ttl_Cache
34
-	 */
35
-	private $ttl_cache_service;
36
-
37
-	/**
38
-	 * Create a {@link Wordlift_Key_Validation_Service} instance.
39
-	 *
40
-	 * @since 3.14.0
41
-	 */
42
-	public function __construct() {
43
-
44
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' );
45
-
46
-		add_action( 'admin_init', array( $this, 'wl_load_plugin' ) );
47
-		/**
48
-		 * Filter: wl_feature__enable__notices.
49
-		 *
50
-		 * @param bool whether notices need to be enabled or not.
51
-		 *
52
-		 * @return bool
53
-		 * @since 3.27.6
54
-		 */
55
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
56
-			add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) );
57
-		}
58
-
59
-		$this->ttl_cache_service = new Ttl_Cache( 'key-validation-notification' );
60
-
61
-	}
62
-
63
-	/**
64
-	 * Validate the provided key.
65
-	 *
66
-	 * @param string $key WordLift's key to validate.
67
-	 *
68
-	 * @return WP_Error|array The response or WP_Error on failure.
69
-	 * @since 3.9.0
70
-	 */
71
-	public function get_account_info( $key ) {
72
-
73
-		$this->log->debug( 'Validating key...' );
74
-
75
-		return Default_Api_Service::get_instance()->get(
76
-			'/accounts/info',
77
-			array(
78
-				'Authorization' => "Key $key",
79
-			)
80
-		)->get_response();
81
-	}
82
-
83
-	/**
84
-	 * Check if key is valid
85
-	 *
86
-	 * @param $key string
87
-	 *
88
-	 * @return bool
89
-	 */
90
-	public function is_key_valid( $key ) {
91
-
92
-		$response = $this->get_account_info( $key );
93
-
94
-		if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) {
95
-			return false;
96
-		}
97
-		$res_body = json_decode( wp_remote_retrieve_body( $response ), true );
98
-
99
-		$url = $res_body['url'];
100
-
101
-		// Considering that production URL may be filtered.
102
-		$home_url = get_option( 'home' );
103
-		$site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) );
104
-		if ( $url === null || $url === $site_url ) {
105
-			return true;
106
-		}
107
-
108
-		return false;
109
-	}
110
-
111
-	/**
112
-	 * This function is hooked to the `wl_validate_key` AJAX call.
113
-	 *
114
-	 * @since 3.9.0
115
-	 */
116
-	public function validate_key() {
117
-
118
-		// Ensure we don't have garbage before us.
119
-		ob_clean();
120
-
121
-		// Check if we have a key.
122
-		if ( ! isset( $_POST['key'] ) ) {  //phpcs:ignore WordPress.Security.NonceVerification.Missing
123
-			wp_send_json_error( 'The key parameter is required.' );
124
-		}
125
-
126
-		$response = $this->get_account_info( sanitize_text_field( wp_unslash( (string) $_POST['key'] ) ) );  //phpcs:ignore WordPress.Security.NonceVerification.Missing
127
-
128
-		// If we got an error, return invalid.
129
-		if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) {
130
-			wp_send_json_success(
131
-				array(
132
-					'valid'    => false,
133
-					'message'  => '',
134
-					'response' => $response,
135
-					'api_url'  => Default_Api_Service::get_instance()->get_base_url(),
136
-				)
137
-			);
138
-		}
139
-
140
-		$res_body = json_decode( wp_remote_retrieve_body( $response ), true );
141
-
142
-		// The URL stored in WLS. If this is the initial install the URL may be null.
143
-		$url = $res_body['url'];
144
-
145
-		// Considering that production URL may be filtered.
146
-		$home_url = get_option( 'home' );
147
-		$site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) );
148
-
149
-		// If the URL isn't set or matches, then it's valid.
150
-		if ( $url === null || $url === $site_url ) {
151
-			// Invalidate the cache key
152
-			$this->ttl_cache_service->delete( 'is_key_valid' );
153
-			wp_send_json_success(
154
-				array(
155
-					'valid'   => true,
156
-					'message' => '',
157
-				)
158
-			);
159
-		}
160
-
161
-		// If the URL doesn't match it means that this key has been configured elsewhere already.
162
-		if ( $url !== $site_url ) {
163
-			Wordlift_Configuration_Service::get_instance()->set_key( '' );
164
-			wp_send_json_success(
165
-				array(
166
-					'valid'   => false,
167
-					'message' => __( 'The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift' ),
168
-				)
169
-			);
170
-		}
171
-
172
-		// Set a response with valid set to true or false according to the key validity with message.
173
-		wp_send_json_success(
174
-			array(
175
-				'valid'   => false,
176
-				'message' => __( 'An error occurred, please contact us at [email protected]', 'wordlift' ),
177
-			)
178
-		);
179
-	}
180
-
181
-	/**
182
-	 * This function is hooked `admin_init` to check _wl_blog_url.
183
-	 */
184
-	public function wl_load_plugin() {
185
-
186
-		$wl_blog_url = get_option( '_wl_blog_url' );
187
-		$home_url    = get_option( 'home' );
188
-
189
-		if ( ! $wl_blog_url ) {
190
-			update_option( '_wl_blog_url', $home_url, true );
191
-		} elseif ( $wl_blog_url !== $home_url ) {
192
-			update_option( '_wl_blog_url', $home_url, true );
193
-			Wordlift_Configuration_Service::get_instance()->set_key( '' );
194
-			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 );
195
-		}
196
-
197
-	}
198
-
199
-	/**
200
-	 * This function is hooked to the `admin_notices` to show admin notification.
201
-	 */
202
-	public function wl_key_update_notice() {
203
-		if ( get_transient( 'wl-key-error-msg' ) ) {
204
-			?>
23
+    /**
24
+     * A {@link Wordlift_Log_Service} instance.
25
+     *
26
+     * @since  3.14.0
27
+     * @access private
28
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
29
+     */
30
+    private $log;
31
+
32
+    /**
33
+     * @var Ttl_Cache
34
+     */
35
+    private $ttl_cache_service;
36
+
37
+    /**
38
+     * Create a {@link Wordlift_Key_Validation_Service} instance.
39
+     *
40
+     * @since 3.14.0
41
+     */
42
+    public function __construct() {
43
+
44
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' );
45
+
46
+        add_action( 'admin_init', array( $this, 'wl_load_plugin' ) );
47
+        /**
48
+         * Filter: wl_feature__enable__notices.
49
+         *
50
+         * @param bool whether notices need to be enabled or not.
51
+         *
52
+         * @return bool
53
+         * @since 3.27.6
54
+         */
55
+        if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
56
+            add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) );
57
+        }
58
+
59
+        $this->ttl_cache_service = new Ttl_Cache( 'key-validation-notification' );
60
+
61
+    }
62
+
63
+    /**
64
+     * Validate the provided key.
65
+     *
66
+     * @param string $key WordLift's key to validate.
67
+     *
68
+     * @return WP_Error|array The response or WP_Error on failure.
69
+     * @since 3.9.0
70
+     */
71
+    public function get_account_info( $key ) {
72
+
73
+        $this->log->debug( 'Validating key...' );
74
+
75
+        return Default_Api_Service::get_instance()->get(
76
+            '/accounts/info',
77
+            array(
78
+                'Authorization' => "Key $key",
79
+            )
80
+        )->get_response();
81
+    }
82
+
83
+    /**
84
+     * Check if key is valid
85
+     *
86
+     * @param $key string
87
+     *
88
+     * @return bool
89
+     */
90
+    public function is_key_valid( $key ) {
91
+
92
+        $response = $this->get_account_info( $key );
93
+
94
+        if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) {
95
+            return false;
96
+        }
97
+        $res_body = json_decode( wp_remote_retrieve_body( $response ), true );
98
+
99
+        $url = $res_body['url'];
100
+
101
+        // Considering that production URL may be filtered.
102
+        $home_url = get_option( 'home' );
103
+        $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) );
104
+        if ( $url === null || $url === $site_url ) {
105
+            return true;
106
+        }
107
+
108
+        return false;
109
+    }
110
+
111
+    /**
112
+     * This function is hooked to the `wl_validate_key` AJAX call.
113
+     *
114
+     * @since 3.9.0
115
+     */
116
+    public function validate_key() {
117
+
118
+        // Ensure we don't have garbage before us.
119
+        ob_clean();
120
+
121
+        // Check if we have a key.
122
+        if ( ! isset( $_POST['key'] ) ) {  //phpcs:ignore WordPress.Security.NonceVerification.Missing
123
+            wp_send_json_error( 'The key parameter is required.' );
124
+        }
125
+
126
+        $response = $this->get_account_info( sanitize_text_field( wp_unslash( (string) $_POST['key'] ) ) );  //phpcs:ignore WordPress.Security.NonceVerification.Missing
127
+
128
+        // If we got an error, return invalid.
129
+        if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) {
130
+            wp_send_json_success(
131
+                array(
132
+                    'valid'    => false,
133
+                    'message'  => '',
134
+                    'response' => $response,
135
+                    'api_url'  => Default_Api_Service::get_instance()->get_base_url(),
136
+                )
137
+            );
138
+        }
139
+
140
+        $res_body = json_decode( wp_remote_retrieve_body( $response ), true );
141
+
142
+        // The URL stored in WLS. If this is the initial install the URL may be null.
143
+        $url = $res_body['url'];
144
+
145
+        // Considering that production URL may be filtered.
146
+        $home_url = get_option( 'home' );
147
+        $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) );
148
+
149
+        // If the URL isn't set or matches, then it's valid.
150
+        if ( $url === null || $url === $site_url ) {
151
+            // Invalidate the cache key
152
+            $this->ttl_cache_service->delete( 'is_key_valid' );
153
+            wp_send_json_success(
154
+                array(
155
+                    'valid'   => true,
156
+                    'message' => '',
157
+                )
158
+            );
159
+        }
160
+
161
+        // If the URL doesn't match it means that this key has been configured elsewhere already.
162
+        if ( $url !== $site_url ) {
163
+            Wordlift_Configuration_Service::get_instance()->set_key( '' );
164
+            wp_send_json_success(
165
+                array(
166
+                    'valid'   => false,
167
+                    'message' => __( 'The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift' ),
168
+                )
169
+            );
170
+        }
171
+
172
+        // Set a response with valid set to true or false according to the key validity with message.
173
+        wp_send_json_success(
174
+            array(
175
+                'valid'   => false,
176
+                'message' => __( 'An error occurred, please contact us at [email protected]', 'wordlift' ),
177
+            )
178
+        );
179
+    }
180
+
181
+    /**
182
+     * This function is hooked `admin_init` to check _wl_blog_url.
183
+     */
184
+    public function wl_load_plugin() {
185
+
186
+        $wl_blog_url = get_option( '_wl_blog_url' );
187
+        $home_url    = get_option( 'home' );
188
+
189
+        if ( ! $wl_blog_url ) {
190
+            update_option( '_wl_blog_url', $home_url, true );
191
+        } elseif ( $wl_blog_url !== $home_url ) {
192
+            update_option( '_wl_blog_url', $home_url, true );
193
+            Wordlift_Configuration_Service::get_instance()->set_key( '' );
194
+            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 );
195
+        }
196
+
197
+    }
198
+
199
+    /**
200
+     * This function is hooked to the `admin_notices` to show admin notification.
201
+     */
202
+    public function wl_key_update_notice() {
203
+        if ( get_transient( 'wl-key-error-msg' ) ) {
204
+            ?>
205 205
 			<div class="updated notice is-dismissible error">
206 206
 				<p><?php esc_html( get_transient( 'wl-key-error-msg' ) ); ?></p>
207 207
 			</div>
208 208
 			<?php
209
-		}
210
-	}
209
+        }
210
+    }
211 211
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	public function __construct() {
43 43
 
44
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' );
44
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Key_Validation_Service');
45 45
 
46
-		add_action( 'admin_init', array( $this, 'wl_load_plugin' ) );
46
+		add_action('admin_init', array($this, 'wl_load_plugin'));
47 47
 		/**
48 48
 		 * Filter: wl_feature__enable__notices.
49 49
 		 *
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
 		 * @return bool
53 53
 		 * @since 3.27.6
54 54
 		 */
55
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
56
-			add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) );
55
+		if (apply_filters('wl_feature__enable__notices', true)) {
56
+			add_action('admin_notices', array($this, 'wl_key_update_notice'));
57 57
 		}
58 58
 
59
-		$this->ttl_cache_service = new Ttl_Cache( 'key-validation-notification' );
59
+		$this->ttl_cache_service = new Ttl_Cache('key-validation-notification');
60 60
 
61 61
 	}
62 62
 
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
 	 * @return WP_Error|array The response or WP_Error on failure.
69 69
 	 * @since 3.9.0
70 70
 	 */
71
-	public function get_account_info( $key ) {
71
+	public function get_account_info($key) {
72 72
 
73
-		$this->log->debug( 'Validating key...' );
73
+		$this->log->debug('Validating key...');
74 74
 
75 75
 		return Default_Api_Service::get_instance()->get(
76 76
 			'/accounts/info',
@@ -87,21 +87,21 @@  discard block
 block discarded – undo
87 87
 	 *
88 88
 	 * @return bool
89 89
 	 */
90
-	public function is_key_valid( $key ) {
90
+	public function is_key_valid($key) {
91 91
 
92
-		$response = $this->get_account_info( $key );
92
+		$response = $this->get_account_info($key);
93 93
 
94
-		if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) {
94
+		if (is_wp_error($response) || 2 !== (int) $response['response']['code'] / 100) {
95 95
 			return false;
96 96
 		}
97
-		$res_body = json_decode( wp_remote_retrieve_body( $response ), true );
97
+		$res_body = json_decode(wp_remote_retrieve_body($response), true);
98 98
 
99 99
 		$url = $res_body['url'];
100 100
 
101 101
 		// Considering that production URL may be filtered.
102
-		$home_url = get_option( 'home' );
103
-		$site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) );
104
-		if ( $url === null || $url === $site_url ) {
102
+		$home_url = get_option('home');
103
+		$site_url = apply_filters('wl_production_site_url', untrailingslashit($home_url));
104
+		if ($url === null || $url === $site_url) {
105 105
 			return true;
106 106
 		}
107 107
 
@@ -119,14 +119,14 @@  discard block
 block discarded – undo
119 119
 		ob_clean();
120 120
 
121 121
 		// Check if we have a key.
122
-		if ( ! isset( $_POST['key'] ) ) {  //phpcs:ignore WordPress.Security.NonceVerification.Missing
123
-			wp_send_json_error( 'The key parameter is required.' );
122
+		if ( ! isset($_POST['key'])) {  //phpcs:ignore WordPress.Security.NonceVerification.Missing
123
+			wp_send_json_error('The key parameter is required.');
124 124
 		}
125 125
 
126
-		$response = $this->get_account_info( sanitize_text_field( wp_unslash( (string) $_POST['key'] ) ) );  //phpcs:ignore WordPress.Security.NonceVerification.Missing
126
+		$response = $this->get_account_info(sanitize_text_field(wp_unslash((string) $_POST['key']))); //phpcs:ignore WordPress.Security.NonceVerification.Missing
127 127
 
128 128
 		// If we got an error, return invalid.
129
-		if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) {
129
+		if (is_wp_error($response) || 2 !== (int) $response['response']['code'] / 100) {
130 130
 			wp_send_json_success(
131 131
 				array(
132 132
 					'valid'    => false,
@@ -137,19 +137,19 @@  discard block
 block discarded – undo
137 137
 			);
138 138
 		}
139 139
 
140
-		$res_body = json_decode( wp_remote_retrieve_body( $response ), true );
140
+		$res_body = json_decode(wp_remote_retrieve_body($response), true);
141 141
 
142 142
 		// The URL stored in WLS. If this is the initial install the URL may be null.
143 143
 		$url = $res_body['url'];
144 144
 
145 145
 		// Considering that production URL may be filtered.
146
-		$home_url = get_option( 'home' );
147
-		$site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) );
146
+		$home_url = get_option('home');
147
+		$site_url = apply_filters('wl_production_site_url', untrailingslashit($home_url));
148 148
 
149 149
 		// If the URL isn't set or matches, then it's valid.
150
-		if ( $url === null || $url === $site_url ) {
150
+		if ($url === null || $url === $site_url) {
151 151
 			// Invalidate the cache key
152
-			$this->ttl_cache_service->delete( 'is_key_valid' );
152
+			$this->ttl_cache_service->delete('is_key_valid');
153 153
 			wp_send_json_success(
154 154
 				array(
155 155
 					'valid'   => true,
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
 		}
160 160
 
161 161
 		// If the URL doesn't match it means that this key has been configured elsewhere already.
162
-		if ( $url !== $site_url ) {
163
-			Wordlift_Configuration_Service::get_instance()->set_key( '' );
162
+		if ($url !== $site_url) {
163
+			Wordlift_Configuration_Service::get_instance()->set_key('');
164 164
 			wp_send_json_success(
165 165
 				array(
166 166
 					'valid'   => false,
167
-					'message' => __( 'The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift' ),
167
+					'message' => __('The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift'),
168 168
 				)
169 169
 			);
170 170
 		}
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		wp_send_json_success(
174 174
 			array(
175 175
 				'valid'   => false,
176
-				'message' => __( 'An error occurred, please contact us at [email protected]', 'wordlift' ),
176
+				'message' => __('An error occurred, please contact us at [email protected]', 'wordlift'),
177 177
 			)
178 178
 		);
179 179
 	}
@@ -183,15 +183,15 @@  discard block
 block discarded – undo
183 183
 	 */
184 184
 	public function wl_load_plugin() {
185 185
 
186
-		$wl_blog_url = get_option( '_wl_blog_url' );
187
-		$home_url    = get_option( 'home' );
186
+		$wl_blog_url = get_option('_wl_blog_url');
187
+		$home_url    = get_option('home');
188 188
 
189
-		if ( ! $wl_blog_url ) {
190
-			update_option( '_wl_blog_url', $home_url, true );
191
-		} elseif ( $wl_blog_url !== $home_url ) {
192
-			update_option( '_wl_blog_url', $home_url, true );
193
-			Wordlift_Configuration_Service::get_instance()->set_key( '' );
194
-			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 );
189
+		if ( ! $wl_blog_url) {
190
+			update_option('_wl_blog_url', $home_url, true);
191
+		} elseif ($wl_blog_url !== $home_url) {
192
+			update_option('_wl_blog_url', $home_url, true);
193
+			Wordlift_Configuration_Service::get_instance()->set_key('');
194
+			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);
195 195
 		}
196 196
 
197 197
 	}
@@ -200,10 +200,10 @@  discard block
 block discarded – undo
200 200
 	 * This function is hooked to the `admin_notices` to show admin notification.
201 201
 	 */
202 202
 	public function wl_key_update_notice() {
203
-		if ( get_transient( 'wl-key-error-msg' ) ) {
203
+		if (get_transient('wl-key-error-msg')) {
204 204
 			?>
205 205
 			<div class="updated notice is-dismissible error">
206
-				<p><?php esc_html( get_transient( 'wl-key-error-msg' ) ); ?></p>
206
+				<p><?php esc_html(get_transient('wl-key-error-msg')); ?></p>
207 207
 			</div>
208 208
 			<?php
209 209
 		}
Please login to merge, or discard this patch.
src/includes/class-wordlift-google-analytics-export-service.php 2 patches
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -18,103 +18,103 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Google_Analytics_Export_Service {
20 20
 
21
-	/**
22
-	 * Export the site data that could be imported in Google Analytics.
23
-	 * It will works only when permalink structure is set to "Postname".
24
-	 *
25
-	 * @since 3.16.0
26
-	 *
27
-	 * @return void
28
-	 */
29
-	public function export() {
30
-		// Bail if the permalink structure is different from "Post name".
31
-		if ( ! $this->is_postname_permalink_structure() ) {
32
-			wp_die( 'The current permalink structure do not allow to export your data. Please change the permalink structure to "Post name".' );
33
-		}
34
-
35
-		// Output the file data. @codingStandardsIgnoreLine
36
-		@ob_end_clean();
37
-
38
-		// Generate unique filename using current timestamp.
39
-		$filename = 'wl-ga-export-' . gmdate( 'Y-m-d-H-i-s' ) . '.csv';
40
-
41
-		// Add proper file headers.
42
-		header( "Content-Disposition: attachment; filename=$filename" );
43
-		header( 'Content-Type: text/csv; charset=' . get_bloginfo( 'charset' ) );
44
-
45
-		// Do not cache the file.
46
-		header( 'Pragma: no-cache' );
47
-		header( 'Expires: 0' );
48
-
49
-		// Build the CSV file.
50
-		$this->create_csv();
51
-
52
-		wp_die();
53
-	}
54
-
55
-	/**
56
-	 * Return site path. Some installations are in subdirectories
57
-	 * and we need add them to expported permalinks.
58
-	 *
59
-	 * @since 3.16.0
60
-	 *
61
-	 * @return string The site path.
62
-	 */
63
-	public function get_site_path() {
64
-		// Get home url from database.
65
-		$home_url = home_url( '/' );
66
-
67
-		// Parse the url.
68
-		$parsed = wp_parse_url( $home_url );
69
-
70
-		// Return the path.
71
-		return $parsed['path'];
72
-	}
73
-
74
-	/**
75
-	 * Check if the current permalink structure is set to "Post name".
76
-	 *
77
-	 * @since 3.16.0
78
-	 *
79
-	 * @return bool whether the structure is "Post name" or not.
80
-	 */
81
-	public static function is_postname_permalink_structure() {
82
-		// Get current permalink structure.
83
-		$structure = get_option( 'permalink_structure' );
84
-
85
-		// The regular expression. It will check if the site structure contains postname.
86
-		$regex = '~^/\%postname\%/$~';
87
-
88
-		// Check if the site structure match the rquired one.
89
-		preg_match( $regex, $structure, $matches );
90
-
91
-		// Bail if the site have different structure.
92
-		if ( empty( $matches ) ) {
93
-			return false;
94
-		}
95
-
96
-		return true;
97
-	}
98
-
99
-	/**
100
-	 * Generate array data, that should be exported as csv.
101
-	 * The data contains the post/page title, entity name and type.
102
-	 *
103
-	 * @since 3.16.0
104
-	 *
105
-	 * @return array $items Content data.
106
-	 */
107
-	public function get_content_data() {
108
-		// Get the global $wpdb.
109
-		global $wpdb;
110
-
111
-		// Site path (optional).
112
-		$path = $this->get_site_path();
113
-
114
-		// Get the data.
115
-		$items = $wpdb->get_results(
116
-			$wpdb->prepare(
117
-				"SELECT
21
+    /**
22
+     * Export the site data that could be imported in Google Analytics.
23
+     * It will works only when permalink structure is set to "Postname".
24
+     *
25
+     * @since 3.16.0
26
+     *
27
+     * @return void
28
+     */
29
+    public function export() {
30
+        // Bail if the permalink structure is different from "Post name".
31
+        if ( ! $this->is_postname_permalink_structure() ) {
32
+            wp_die( 'The current permalink structure do not allow to export your data. Please change the permalink structure to "Post name".' );
33
+        }
34
+
35
+        // Output the file data. @codingStandardsIgnoreLine
36
+        @ob_end_clean();
37
+
38
+        // Generate unique filename using current timestamp.
39
+        $filename = 'wl-ga-export-' . gmdate( 'Y-m-d-H-i-s' ) . '.csv';
40
+
41
+        // Add proper file headers.
42
+        header( "Content-Disposition: attachment; filename=$filename" );
43
+        header( 'Content-Type: text/csv; charset=' . get_bloginfo( 'charset' ) );
44
+
45
+        // Do not cache the file.
46
+        header( 'Pragma: no-cache' );
47
+        header( 'Expires: 0' );
48
+
49
+        // Build the CSV file.
50
+        $this->create_csv();
51
+
52
+        wp_die();
53
+    }
54
+
55
+    /**
56
+     * Return site path. Some installations are in subdirectories
57
+     * and we need add them to expported permalinks.
58
+     *
59
+     * @since 3.16.0
60
+     *
61
+     * @return string The site path.
62
+     */
63
+    public function get_site_path() {
64
+        // Get home url from database.
65
+        $home_url = home_url( '/' );
66
+
67
+        // Parse the url.
68
+        $parsed = wp_parse_url( $home_url );
69
+
70
+        // Return the path.
71
+        return $parsed['path'];
72
+    }
73
+
74
+    /**
75
+     * Check if the current permalink structure is set to "Post name".
76
+     *
77
+     * @since 3.16.0
78
+     *
79
+     * @return bool whether the structure is "Post name" or not.
80
+     */
81
+    public static function is_postname_permalink_structure() {
82
+        // Get current permalink structure.
83
+        $structure = get_option( 'permalink_structure' );
84
+
85
+        // The regular expression. It will check if the site structure contains postname.
86
+        $regex = '~^/\%postname\%/$~';
87
+
88
+        // Check if the site structure match the rquired one.
89
+        preg_match( $regex, $structure, $matches );
90
+
91
+        // Bail if the site have different structure.
92
+        if ( empty( $matches ) ) {
93
+            return false;
94
+        }
95
+
96
+        return true;
97
+    }
98
+
99
+    /**
100
+     * Generate array data, that should be exported as csv.
101
+     * The data contains the post/page title, entity name and type.
102
+     *
103
+     * @since 3.16.0
104
+     *
105
+     * @return array $items Content data.
106
+     */
107
+    public function get_content_data() {
108
+        // Get the global $wpdb.
109
+        global $wpdb;
110
+
111
+        // Site path (optional).
112
+        $path = $this->get_site_path();
113
+
114
+        // Get the data.
115
+        $items = $wpdb->get_results(
116
+            $wpdb->prepare(
117
+                "SELECT
118 118
 					CONCAT( %s, p.post_name, '/' ) AS 'post_name',
119 119
 					p1.post_name AS 'entity_name',
120 120
 					t.slug AS 'entity_type'
@@ -131,43 +131,43 @@  discard block
 block discarded – undo
131 131
 					INNER JOIN {$wpdb->prefix}terms t
132 132
 						ON t.term_id = tt.term_id
133 133
 					WHERE p.post_type IN ( 'page', 'post' );",
134
-				$path
135
-			)
136
-		); // db call ok; no-cache ok.
137
-
138
-		return $items;
139
-	}
140
-
141
-	/**
142
-	 * Create the CSV file that will be downloaded.
143
-	 *
144
-	 * @since 3.16.0
145
-	 *
146
-	 * @return void
147
-	 */
148
-	public function create_csv() {
149
-		// Create a file pointer connected to the output stream.
150
-		// Ignoring linter notices below that complain about file output which do not actually happen.
151
-		$file = fopen( 'php://output', 'w' );
152
-
153
-		// Add the column headers. @codingStandardsIgnoreLine
154
-		fputcsv(
155
-			$file,
156
-			array(
157
-				'ga:pagePath',
158
-				'ga:dimension1',
159
-				'ga:dimension2',
160
-			)
161
-		);
162
-
163
-		// Cycle through items and add each item data to the file.
164
-		foreach ( $this->get_content_data() as $row ) {
165
-			// Add new line in the file. @codingStandardsIgnoreLine
166
-			fputcsv(
167
-				$file,
168
-				(array) $row // convert the object to array.
169
-			);
170
-		}
171
-	}
134
+                $path
135
+            )
136
+        ); // db call ok; no-cache ok.
137
+
138
+        return $items;
139
+    }
140
+
141
+    /**
142
+     * Create the CSV file that will be downloaded.
143
+     *
144
+     * @since 3.16.0
145
+     *
146
+     * @return void
147
+     */
148
+    public function create_csv() {
149
+        // Create a file pointer connected to the output stream.
150
+        // Ignoring linter notices below that complain about file output which do not actually happen.
151
+        $file = fopen( 'php://output', 'w' );
152
+
153
+        // Add the column headers. @codingStandardsIgnoreLine
154
+        fputcsv(
155
+            $file,
156
+            array(
157
+                'ga:pagePath',
158
+                'ga:dimension1',
159
+                'ga:dimension2',
160
+            )
161
+        );
162
+
163
+        // Cycle through items and add each item data to the file.
164
+        foreach ( $this->get_content_data() as $row ) {
165
+            // Add new line in the file. @codingStandardsIgnoreLine
166
+            fputcsv(
167
+                $file,
168
+                (array) $row // convert the object to array.
169
+            );
170
+        }
171
+    }
172 172
 
173 173
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -28,23 +28,23 @@  discard block
 block discarded – undo
28 28
 	 */
29 29
 	public function export() {
30 30
 		// Bail if the permalink structure is different from "Post name".
31
-		if ( ! $this->is_postname_permalink_structure() ) {
32
-			wp_die( 'The current permalink structure do not allow to export your data. Please change the permalink structure to "Post name".' );
31
+		if ( ! $this->is_postname_permalink_structure()) {
32
+			wp_die('The current permalink structure do not allow to export your data. Please change the permalink structure to "Post name".');
33 33
 		}
34 34
 
35 35
 		// Output the file data. @codingStandardsIgnoreLine
36 36
 		@ob_end_clean();
37 37
 
38 38
 		// Generate unique filename using current timestamp.
39
-		$filename = 'wl-ga-export-' . gmdate( 'Y-m-d-H-i-s' ) . '.csv';
39
+		$filename = 'wl-ga-export-'.gmdate('Y-m-d-H-i-s').'.csv';
40 40
 
41 41
 		// Add proper file headers.
42
-		header( "Content-Disposition: attachment; filename=$filename" );
43
-		header( 'Content-Type: text/csv; charset=' . get_bloginfo( 'charset' ) );
42
+		header("Content-Disposition: attachment; filename=$filename");
43
+		header('Content-Type: text/csv; charset='.get_bloginfo('charset'));
44 44
 
45 45
 		// Do not cache the file.
46
-		header( 'Pragma: no-cache' );
47
-		header( 'Expires: 0' );
46
+		header('Pragma: no-cache');
47
+		header('Expires: 0');
48 48
 
49 49
 		// Build the CSV file.
50 50
 		$this->create_csv();
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	public function get_site_path() {
64 64
 		// Get home url from database.
65
-		$home_url = home_url( '/' );
65
+		$home_url = home_url('/');
66 66
 
67 67
 		// Parse the url.
68
-		$parsed = wp_parse_url( $home_url );
68
+		$parsed = wp_parse_url($home_url);
69 69
 
70 70
 		// Return the path.
71 71
 		return $parsed['path'];
@@ -80,16 +80,16 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	public static function is_postname_permalink_structure() {
82 82
 		// Get current permalink structure.
83
-		$structure = get_option( 'permalink_structure' );
83
+		$structure = get_option('permalink_structure');
84 84
 
85 85
 		// The regular expression. It will check if the site structure contains postname.
86 86
 		$regex = '~^/\%postname\%/$~';
87 87
 
88 88
 		// Check if the site structure match the rquired one.
89
-		preg_match( $regex, $structure, $matches );
89
+		preg_match($regex, $structure, $matches);
90 90
 
91 91
 		// Bail if the site have different structure.
92
-		if ( empty( $matches ) ) {
92
+		if (empty($matches)) {
93 93
 			return false;
94 94
 		}
95 95
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	public function create_csv() {
149 149
 		// Create a file pointer connected to the output stream.
150 150
 		// Ignoring linter notices below that complain about file output which do not actually happen.
151
-		$file = fopen( 'php://output', 'w' );
151
+		$file = fopen('php://output', 'w');
152 152
 
153 153
 		// Add the column headers. @codingStandardsIgnoreLine
154 154
 		fputcsv(
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 		);
162 162
 
163 163
 		// Cycle through items and add each item data to the file.
164
-		foreach ( $this->get_content_data() as $row ) {
164
+		foreach ($this->get_content_data() as $row) {
165 165
 			// Add new line in the file. @codingStandardsIgnoreLine
166 166
 			fputcsv(
167 167
 				$file,
Please login to merge, or discard this patch.
src/includes/class-wordlift-configuration-service.php 2 patches
Indentation   +695 added lines, -695 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 use Wordlift\Api\Default_Api_Service;
14 14
 
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -23,703 +23,703 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class Wordlift_Configuration_Service {
25 25
 
26
-	/**
27
-	 * The entity base path option name.
28
-	 *
29
-	 * @since 3.6.0
30
-	 */
31
-	const ENTITY_BASE_PATH_KEY = 'wl_entity_base_path';
32
-
33
-	/**
34
-	 * The skip wizard (admin installation wizard) option name.
35
-	 *
36
-	 * @since 3.9.0
37
-	 */
38
-	const SKIP_WIZARD = 'wl_skip_wizard';
39
-
40
-	/**
41
-	 * WordLift's key option name.
42
-	 *
43
-	 * @since 3.9.0
44
-	 */
45
-	const KEY = 'key';
46
-
47
-	/**
48
-	 * WordLift's configured language option name.
49
-	 *
50
-	 * @since 3.9.0
51
-	 */
52
-	const LANGUAGE = 'site_language';
53
-
54
-	/**
55
-	 * WordLift's configured country code.
56
-	 *
57
-	 * @since 3.18.0
58
-	 */
59
-	const COUNTRY_CODE = 'country_code';
60
-
61
-	/**
62
-	 * The publisher entity post ID option name.
63
-	 *
64
-	 * @since 3.9.0
65
-	 */
66
-	const PUBLISHER_ID = 'publisher_id';
67
-
68
-	/**
69
-	 * The dataset URI option name
70
-	 *
71
-	 * @since 3.10.0
72
-	 */
73
-	const DATASET_URI = 'redlink_dataset_uri';
74
-
75
-	/**
76
-	 * The link by default option name.
77
-	 *
78
-	 * @since 3.11.0
79
-	 */
80
-	const LINK_BY_DEFAULT = 'link_by_default';
81
-
82
-	/**
83
-	 * The analytics enable option.
84
-	 *
85
-	 * @since 3.21.0
86
-	 */
87
-	const ANALYTICS_ENABLE = 'analytics_enable';
88
-
89
-	/**
90
-	 * The analytics entity uri dimension option.
91
-	 *
92
-	 * @since 3.21.0
93
-	 */
94
-	const ANALYTICS_ENTITY_URI_DIMENSION = 'analytics_entity_uri_dimension';
95
-
96
-	/**
97
-	 * The analytics entity type dimension option.
98
-	 *
99
-	 * @since 3.21.0
100
-	 */
101
-	const ANALYTICS_ENTITY_TYPE_DIMENSION = 'analytics_entity_type_dimension';
102
-
103
-	/**
104
-	 * The user preferences about sharing data option.
105
-	 *
106
-	 * @since 3.19.0
107
-	 */
108
-	const SEND_DIAGNOSTIC = 'send_diagnostic';
109
-
110
-	/**
111
-	 * The package type configuration key.
112
-	 *
113
-	 * @since 3.20.0
114
-	 */
115
-	const PACKAGE_TYPE = 'package_type';
116
-
117
-	/**
118
-	 * The {@link Wordlift_Log_Service} instance.
119
-	 *
120
-	 * @since 3.16.0
121
-	 *
122
-	 * @var \Wordlift_Log_Service $log The {@link Wordlift_Log_Service} instance.
123
-	 */
124
-	private $log;
125
-
126
-	/**
127
-	 * Create a Wordlift_Configuration_Service's instance.
128
-	 *
129
-	 * @since 3.6.0
130
-	 */
131
-	protected function __construct() {
132
-
133
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
134
-
135
-	}
136
-
137
-	/**
138
-	 * The Wordlift_Configuration_Service's singleton instance.
139
-	 *
140
-	 * @since  3.6.0
141
-	 *
142
-	 * @access private
143
-	 * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance.
144
-	 */
145
-	private static $instance = null;
146
-
147
-	/**
148
-	 * Get the singleton instance.
149
-	 *
150
-	 * @return \Wordlift_Configuration_Service
151
-	 * @since 3.6.0
152
-	 */
153
-	public static function get_instance() {
154
-
155
-		if ( ! isset( self::$instance ) ) {
156
-			self::$instance = new self();
157
-		}
158
-
159
-		return self::$instance;
160
-	}
161
-
162
-	/**
163
-	 * Get a configuration given the option name and a key. The option value is
164
-	 * expected to be an array.
165
-	 *
166
-	 * @param string $option The option name.
167
-	 * @param string $key A key in the option value array.
168
-	 * @param string $default The default value in case the key is not found (by default an empty string).
169
-	 *
170
-	 * @return mixed The configuration value or the default value if not found.
171
-	 * @since 3.6.0
172
-	 */
173
-	private function get( $option, $key, $default = '' ) {
174
-
175
-		$options = get_option( $option, array() );
176
-
177
-		return isset( $options[ $key ] ) ? $options[ $key ] : $default;
178
-	}
179
-
180
-	/**
181
-	 * Set a configuration parameter.
182
-	 *
183
-	 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
184
-	 * @param string $key The value key.
185
-	 * @param mixed  $value The value.
186
-	 *
187
-	 * @since 3.9.0
188
-	 */
189
-	private function set( $option, $key, $value ) {
190
-
191
-		$values         = get_option( $option );
192
-		$values         = isset( $values ) ? $values : array();
193
-		$values[ $key ] = $value;
194
-		update_option( $option, $values );
195
-
196
-	}
197
-
198
-	/**
199
-	 * Get the entity base path, by default 'entity'.
200
-	 *
201
-	 * @return string The entity base path.
202
-	 * @since 3.6.0
203
-	 */
204
-	public function get_entity_base_path() {
205
-
206
-		return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' );
207
-	}
208
-
209
-	/**
210
-	 * Get the entity base path.
211
-	 *
212
-	 * @param string $value The entity base path.
213
-	 *
214
-	 * @since 3.9.0
215
-	 */
216
-	public function set_entity_base_path( $value ) {
217
-
218
-		$this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value );
219
-
220
-	}
221
-
222
-	/**
223
-	 * Whether the installation skip wizard should be skipped.
224
-	 *
225
-	 * @return bool True if it should be skipped otherwise false.
226
-	 * @since 3.9.0
227
-	 */
228
-	public function is_skip_wizard() {
229
-
230
-		return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false );
231
-	}
232
-
233
-	/**
234
-	 * Set the skip wizard parameter.
235
-	 *
236
-	 * @param bool $value True to skip the wizard. We expect a boolean value.
237
-	 *
238
-	 * @since 3.9.0
239
-	 */
240
-	public function set_skip_wizard( $value ) {
241
-
242
-		$this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value );
243
-
244
-	}
245
-
246
-	/**
247
-	 * Get WordLift's key.
248
-	 *
249
-	 * @return string WordLift's key or an empty string if not set.
250
-	 * @since 3.9.0
251
-	 */
252
-	public function get_key() {
253
-
254
-		return $this->get( 'wl_general_settings', self::KEY, '' );
255
-	}
256
-
257
-	/**
258
-	 * Set WordLift's key.
259
-	 *
260
-	 * @param string $value WordLift's key.
261
-	 *
262
-	 * @since 3.9.0
263
-	 */
264
-	public function set_key( $value ) {
265
-
266
-		$this->set( 'wl_general_settings', self::KEY, $value );
267
-	}
268
-
269
-	/**
270
-	 * Get WordLift's configured language, by default 'en'.
271
-	 *
272
-	 * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis.
273
-	 *
274
-	 * @return string WordLift's configured language code ('en' by default).
275
-	 * @since 3.9.0
276
-	 */
277
-	public function get_language_code() {
278
-
279
-		$language = get_locale();
280
-		if ( ! $language ) {
281
-			return 'en';
282
-		}
283
-
284
-		return substr( $language, 0, 2 );
285
-	}
286
-
287
-	/**
288
-	 * @param string $value WordLift's language code.
289
-	 *
290
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1466
291
-	 *
292
-	 * Set WordLift's language code, used when storing strings to the Linked Data dataset.
293
-	 *
294
-	 * @deprecated As of 3.32.7 this below method has no effect on setting the language, we use the
295
-	 * language code form WordPress directly.
296
-	 *
297
-	 * @since 3.9.0
298
-	 */
299
-	public function set_language_code( $value ) {
300
-
301
-		$this->set( 'wl_general_settings', self::LANGUAGE, $value );
302
-
303
-	}
304
-
305
-	/**
306
-	 * Set the user preferences about sharing diagnostic with us.
307
-	 *
308
-	 * @param string $value The user preferences(yes/no).
309
-	 *
310
-	 * @since 3.19.0
311
-	 */
312
-	public function set_diagnostic_preferences( $value ) {
313
-
314
-		$this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value );
315
-
316
-	}
317
-
318
-	/**
319
-	 * Get the user preferences about sharing diagnostic.
320
-	 *
321
-	 * @since 3.19.0
322
-	 */
323
-	public function get_diagnostic_preferences() {
324
-
325
-		return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' );
326
-	}
327
-
328
-	/**
329
-	 * Get WordLift's configured country code, by default 'us'.
330
-	 *
331
-	 * @return string WordLift's configured country code ('us' by default).
332
-	 * @since 3.18.0
333
-	 */
334
-	public function get_country_code() {
335
-
336
-		return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' );
337
-	}
338
-
339
-	/**
340
-	 * Set WordLift's country code.
341
-	 *
342
-	 * @param string $value WordLift's country code.
343
-	 *
344
-	 * @since 3.18.0
345
-	 */
346
-	public function set_country_code( $value ) {
347
-
348
-		$this->set( 'wl_general_settings', self::COUNTRY_CODE, $value );
349
-
350
-	}
351
-
352
-	/**
353
-	 * Get the publisher entity post id.
354
-	 *
355
-	 * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org
356
-	 * Article markup.
357
-	 *
358
-	 * @return int|NULL The publisher entity post id or NULL if not set.
359
-	 * @since 3.9.0
360
-	 */
361
-	public function get_publisher_id() {
362
-
363
-		return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null );
364
-	}
365
-
366
-	/**
367
-	 * Set the publisher entity post id.
368
-	 *
369
-	 * @param int $value The publisher entity post id.
370
-	 *
371
-	 * @since 3.9.0
372
-	 */
373
-	public function set_publisher_id( $value ) {
374
-
375
-		$this->set( 'wl_general_settings', self::PUBLISHER_ID, $value );
376
-
377
-	}
378
-
379
-	/**
380
-	 * Get the dataset URI.
381
-	 *
382
-	 * @return string The dataset URI or an empty string if not set.
383
-	 * @since 3.10.0
384
-	 * @since 3.27.7 Always return null if `wl_features__enable__dataset` is disabled.
385
-	 */
386
-	public function get_dataset_uri() {
387
-
388
-		if ( apply_filters( 'wl_feature__enable__dataset', true ) ) {
389
-			return $this->get( 'wl_advanced_settings', self::DATASET_URI, null );
390
-		} else {
391
-			return null;
392
-		}
393
-	}
394
-
395
-	/**
396
-	 * Set the dataset URI.
397
-	 *
398
-	 * @param string $value The dataset URI.
399
-	 *
400
-	 * @since 3.10.0
401
-	 */
402
-	public function set_dataset_uri( $value ) {
403
-
404
-		$this->set( 'wl_advanced_settings', self::DATASET_URI, $value );
405
-	}
406
-
407
-	/**
408
-	 * Get the package type.
409
-	 *
410
-	 * @return string The package type or an empty string if not set.
411
-	 * @since 3.20.0
412
-	 */
413
-	public function get_package_type() {
414
-
415
-		return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null );
416
-	}
417
-
418
-	/**
419
-	 * Set the package type.
420
-	 *
421
-	 * @param string $value The package type.
422
-	 *
423
-	 * @since 3.20.0
424
-	 */
425
-	public function set_package_type( $value ) {
426
-		$this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value );
427
-	}
428
-
429
-	/**
430
-	 * Intercept the change of the WordLift key in order to set the dataset URI.
431
-	 *
432
-	 * @since 3.20.0 as of #761, we save settings every time a key is set, not only when the key changes, so to
433
-	 *               store the configuration parameters such as country or language.
434
-	 * @since 3.11.0
435
-	 *
436
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/761
437
-	 *
438
-	 * @param array $old_value The old settings.
439
-	 * @param array $new_value The new settings.
440
-	 */
441
-	public function update_key( $old_value, $new_value ) {
442
-
443
-		// Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed.
444
-		// $old_key = isset( $old_value['key'] ) ? $old_value['key'] : '';
445
-		$new_key = isset( $new_value['key'] ) ? $new_value['key'] : '';
446
-
447
-		// If the key hasn't changed, don't do anything.
448
-		// WARN The 'update_option' hook is fired only if the new and old value are not equal.
449
-		// if ( $old_key === $new_key ) {
450
-		// return;
451
-		// }
452
-
453
-		// If the key is empty, empty the dataset URI.
454
-		if ( '' === $new_key ) {
455
-			$this->set_dataset_uri( '' );
456
-		}
457
-
458
-		// make the request to the remote server.
459
-		$this->get_remote_dataset_uri( $new_key );
460
-
461
-		do_action( 'wl_key_updated' );
462
-
463
-	}
464
-
465
-	/**
466
-	 * Handle retrieving the dataset uri from the remote server.
467
-	 *
468
-	 * If a valid dataset uri is returned it is stored in the appropriate option,
469
-	 * otherwise the option is set to empty string.
470
-	 *
471
-	 * @param string $key The key to be used.
472
-	 *
473
-	 * @since 3.12.0
474
-	 *
475
-	 * @since 3.17.0 send the site URL and get the dataset URI.
476
-	 */
477
-	public function get_remote_dataset_uri( $key ) {
478
-
479
-		$this->log->trace( 'Getting the remote dataset URI and package type...' );
480
-
481
-		if ( empty( $key ) ) {
482
-			$this->log->warn( 'Key set to empty value.' );
483
-
484
-			$this->set_dataset_uri( '' );
485
-			$this->set_package_type( null );
486
-
487
-			return;
488
-		}
489
-
490
-		/**
491
-		 * Allow 3rd parties to change the site_url.
492
-		 *
493
-		 * @param string $site_url The site url.
494
-		 *
495
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/850
496
-		 *
497
-		 * @since 3.20.0
498
-		 */
499
-		$home_url = get_option( 'home' );
500
-		$site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) );
501
-
502
-		// Build the URL.
503
-		$url = '/accounts'
504
-			   . '?key=' . rawurlencode( $key )
505
-			   . '&url=' . rawurlencode( $site_url )
506
-			   . '&country=' . $this->get_country_code()
507
-			   . '&language=' . $this->get_language_code();
508
-
509
-		$api_service = Default_Api_Service::get_instance();
510
-		/**
511
-		 * @since 3.27.7.1
512
-		 * The Key should be passed to headers, otherwise api would return null.
513
-		 */
514
-		$headers  = array(
515
-			'Authorization' => "Key $key",
516
-		);
517
-		$response = $api_service->request( 'PUT', $url, $headers )->get_response();
518
-
519
-		// The response is an error.
520
-		if ( is_wp_error( $response ) ) {
521
-			$this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() );
522
-
523
-			$this->set_dataset_uri( '' );
524
-			$this->set_package_type( null );
525
-
526
-			return;
527
-		}
528
-
529
-		// The response is not OK.
530
-		if ( ! is_array( $response ) || 200 !== (int) $response['response']['code'] ) {
531
-			$base_url = $api_service->get_base_url();
532
-
533
-			if ( ! is_array( $response ) ) {
534
-				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
535
-				$this->log->error( "Unexpected response when opening URL $base_url$url: " . var_export( $response, true ) );
536
-			} else {
537
-				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
538
-				$this->log->error( "Unexpected status code when opening URL $base_url$url: " . $response['response']['code'] . "\n" . var_export( $response, true ) );
539
-			}
540
-
541
-			$this->set_dataset_uri( '' );
542
-			$this->set_package_type( null );
543
-
544
-			return;
545
-		}
546
-
547
-		/*
26
+    /**
27
+     * The entity base path option name.
28
+     *
29
+     * @since 3.6.0
30
+     */
31
+    const ENTITY_BASE_PATH_KEY = 'wl_entity_base_path';
32
+
33
+    /**
34
+     * The skip wizard (admin installation wizard) option name.
35
+     *
36
+     * @since 3.9.0
37
+     */
38
+    const SKIP_WIZARD = 'wl_skip_wizard';
39
+
40
+    /**
41
+     * WordLift's key option name.
42
+     *
43
+     * @since 3.9.0
44
+     */
45
+    const KEY = 'key';
46
+
47
+    /**
48
+     * WordLift's configured language option name.
49
+     *
50
+     * @since 3.9.0
51
+     */
52
+    const LANGUAGE = 'site_language';
53
+
54
+    /**
55
+     * WordLift's configured country code.
56
+     *
57
+     * @since 3.18.0
58
+     */
59
+    const COUNTRY_CODE = 'country_code';
60
+
61
+    /**
62
+     * The publisher entity post ID option name.
63
+     *
64
+     * @since 3.9.0
65
+     */
66
+    const PUBLISHER_ID = 'publisher_id';
67
+
68
+    /**
69
+     * The dataset URI option name
70
+     *
71
+     * @since 3.10.0
72
+     */
73
+    const DATASET_URI = 'redlink_dataset_uri';
74
+
75
+    /**
76
+     * The link by default option name.
77
+     *
78
+     * @since 3.11.0
79
+     */
80
+    const LINK_BY_DEFAULT = 'link_by_default';
81
+
82
+    /**
83
+     * The analytics enable option.
84
+     *
85
+     * @since 3.21.0
86
+     */
87
+    const ANALYTICS_ENABLE = 'analytics_enable';
88
+
89
+    /**
90
+     * The analytics entity uri dimension option.
91
+     *
92
+     * @since 3.21.0
93
+     */
94
+    const ANALYTICS_ENTITY_URI_DIMENSION = 'analytics_entity_uri_dimension';
95
+
96
+    /**
97
+     * The analytics entity type dimension option.
98
+     *
99
+     * @since 3.21.0
100
+     */
101
+    const ANALYTICS_ENTITY_TYPE_DIMENSION = 'analytics_entity_type_dimension';
102
+
103
+    /**
104
+     * The user preferences about sharing data option.
105
+     *
106
+     * @since 3.19.0
107
+     */
108
+    const SEND_DIAGNOSTIC = 'send_diagnostic';
109
+
110
+    /**
111
+     * The package type configuration key.
112
+     *
113
+     * @since 3.20.0
114
+     */
115
+    const PACKAGE_TYPE = 'package_type';
116
+
117
+    /**
118
+     * The {@link Wordlift_Log_Service} instance.
119
+     *
120
+     * @since 3.16.0
121
+     *
122
+     * @var \Wordlift_Log_Service $log The {@link Wordlift_Log_Service} instance.
123
+     */
124
+    private $log;
125
+
126
+    /**
127
+     * Create a Wordlift_Configuration_Service's instance.
128
+     *
129
+     * @since 3.6.0
130
+     */
131
+    protected function __construct() {
132
+
133
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
134
+
135
+    }
136
+
137
+    /**
138
+     * The Wordlift_Configuration_Service's singleton instance.
139
+     *
140
+     * @since  3.6.0
141
+     *
142
+     * @access private
143
+     * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance.
144
+     */
145
+    private static $instance = null;
146
+
147
+    /**
148
+     * Get the singleton instance.
149
+     *
150
+     * @return \Wordlift_Configuration_Service
151
+     * @since 3.6.0
152
+     */
153
+    public static function get_instance() {
154
+
155
+        if ( ! isset( self::$instance ) ) {
156
+            self::$instance = new self();
157
+        }
158
+
159
+        return self::$instance;
160
+    }
161
+
162
+    /**
163
+     * Get a configuration given the option name and a key. The option value is
164
+     * expected to be an array.
165
+     *
166
+     * @param string $option The option name.
167
+     * @param string $key A key in the option value array.
168
+     * @param string $default The default value in case the key is not found (by default an empty string).
169
+     *
170
+     * @return mixed The configuration value or the default value if not found.
171
+     * @since 3.6.0
172
+     */
173
+    private function get( $option, $key, $default = '' ) {
174
+
175
+        $options = get_option( $option, array() );
176
+
177
+        return isset( $options[ $key ] ) ? $options[ $key ] : $default;
178
+    }
179
+
180
+    /**
181
+     * Set a configuration parameter.
182
+     *
183
+     * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
184
+     * @param string $key The value key.
185
+     * @param mixed  $value The value.
186
+     *
187
+     * @since 3.9.0
188
+     */
189
+    private function set( $option, $key, $value ) {
190
+
191
+        $values         = get_option( $option );
192
+        $values         = isset( $values ) ? $values : array();
193
+        $values[ $key ] = $value;
194
+        update_option( $option, $values );
195
+
196
+    }
197
+
198
+    /**
199
+     * Get the entity base path, by default 'entity'.
200
+     *
201
+     * @return string The entity base path.
202
+     * @since 3.6.0
203
+     */
204
+    public function get_entity_base_path() {
205
+
206
+        return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' );
207
+    }
208
+
209
+    /**
210
+     * Get the entity base path.
211
+     *
212
+     * @param string $value The entity base path.
213
+     *
214
+     * @since 3.9.0
215
+     */
216
+    public function set_entity_base_path( $value ) {
217
+
218
+        $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value );
219
+
220
+    }
221
+
222
+    /**
223
+     * Whether the installation skip wizard should be skipped.
224
+     *
225
+     * @return bool True if it should be skipped otherwise false.
226
+     * @since 3.9.0
227
+     */
228
+    public function is_skip_wizard() {
229
+
230
+        return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false );
231
+    }
232
+
233
+    /**
234
+     * Set the skip wizard parameter.
235
+     *
236
+     * @param bool $value True to skip the wizard. We expect a boolean value.
237
+     *
238
+     * @since 3.9.0
239
+     */
240
+    public function set_skip_wizard( $value ) {
241
+
242
+        $this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value );
243
+
244
+    }
245
+
246
+    /**
247
+     * Get WordLift's key.
248
+     *
249
+     * @return string WordLift's key or an empty string if not set.
250
+     * @since 3.9.0
251
+     */
252
+    public function get_key() {
253
+
254
+        return $this->get( 'wl_general_settings', self::KEY, '' );
255
+    }
256
+
257
+    /**
258
+     * Set WordLift's key.
259
+     *
260
+     * @param string $value WordLift's key.
261
+     *
262
+     * @since 3.9.0
263
+     */
264
+    public function set_key( $value ) {
265
+
266
+        $this->set( 'wl_general_settings', self::KEY, $value );
267
+    }
268
+
269
+    /**
270
+     * Get WordLift's configured language, by default 'en'.
271
+     *
272
+     * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis.
273
+     *
274
+     * @return string WordLift's configured language code ('en' by default).
275
+     * @since 3.9.0
276
+     */
277
+    public function get_language_code() {
278
+
279
+        $language = get_locale();
280
+        if ( ! $language ) {
281
+            return 'en';
282
+        }
283
+
284
+        return substr( $language, 0, 2 );
285
+    }
286
+
287
+    /**
288
+     * @param string $value WordLift's language code.
289
+     *
290
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1466
291
+     *
292
+     * Set WordLift's language code, used when storing strings to the Linked Data dataset.
293
+     *
294
+     * @deprecated As of 3.32.7 this below method has no effect on setting the language, we use the
295
+     * language code form WordPress directly.
296
+     *
297
+     * @since 3.9.0
298
+     */
299
+    public function set_language_code( $value ) {
300
+
301
+        $this->set( 'wl_general_settings', self::LANGUAGE, $value );
302
+
303
+    }
304
+
305
+    /**
306
+     * Set the user preferences about sharing diagnostic with us.
307
+     *
308
+     * @param string $value The user preferences(yes/no).
309
+     *
310
+     * @since 3.19.0
311
+     */
312
+    public function set_diagnostic_preferences( $value ) {
313
+
314
+        $this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value );
315
+
316
+    }
317
+
318
+    /**
319
+     * Get the user preferences about sharing diagnostic.
320
+     *
321
+     * @since 3.19.0
322
+     */
323
+    public function get_diagnostic_preferences() {
324
+
325
+        return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' );
326
+    }
327
+
328
+    /**
329
+     * Get WordLift's configured country code, by default 'us'.
330
+     *
331
+     * @return string WordLift's configured country code ('us' by default).
332
+     * @since 3.18.0
333
+     */
334
+    public function get_country_code() {
335
+
336
+        return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' );
337
+    }
338
+
339
+    /**
340
+     * Set WordLift's country code.
341
+     *
342
+     * @param string $value WordLift's country code.
343
+     *
344
+     * @since 3.18.0
345
+     */
346
+    public function set_country_code( $value ) {
347
+
348
+        $this->set( 'wl_general_settings', self::COUNTRY_CODE, $value );
349
+
350
+    }
351
+
352
+    /**
353
+     * Get the publisher entity post id.
354
+     *
355
+     * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org
356
+     * Article markup.
357
+     *
358
+     * @return int|NULL The publisher entity post id or NULL if not set.
359
+     * @since 3.9.0
360
+     */
361
+    public function get_publisher_id() {
362
+
363
+        return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null );
364
+    }
365
+
366
+    /**
367
+     * Set the publisher entity post id.
368
+     *
369
+     * @param int $value The publisher entity post id.
370
+     *
371
+     * @since 3.9.0
372
+     */
373
+    public function set_publisher_id( $value ) {
374
+
375
+        $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value );
376
+
377
+    }
378
+
379
+    /**
380
+     * Get the dataset URI.
381
+     *
382
+     * @return string The dataset URI or an empty string if not set.
383
+     * @since 3.10.0
384
+     * @since 3.27.7 Always return null if `wl_features__enable__dataset` is disabled.
385
+     */
386
+    public function get_dataset_uri() {
387
+
388
+        if ( apply_filters( 'wl_feature__enable__dataset', true ) ) {
389
+            return $this->get( 'wl_advanced_settings', self::DATASET_URI, null );
390
+        } else {
391
+            return null;
392
+        }
393
+    }
394
+
395
+    /**
396
+     * Set the dataset URI.
397
+     *
398
+     * @param string $value The dataset URI.
399
+     *
400
+     * @since 3.10.0
401
+     */
402
+    public function set_dataset_uri( $value ) {
403
+
404
+        $this->set( 'wl_advanced_settings', self::DATASET_URI, $value );
405
+    }
406
+
407
+    /**
408
+     * Get the package type.
409
+     *
410
+     * @return string The package type or an empty string if not set.
411
+     * @since 3.20.0
412
+     */
413
+    public function get_package_type() {
414
+
415
+        return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null );
416
+    }
417
+
418
+    /**
419
+     * Set the package type.
420
+     *
421
+     * @param string $value The package type.
422
+     *
423
+     * @since 3.20.0
424
+     */
425
+    public function set_package_type( $value ) {
426
+        $this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value );
427
+    }
428
+
429
+    /**
430
+     * Intercept the change of the WordLift key in order to set the dataset URI.
431
+     *
432
+     * @since 3.20.0 as of #761, we save settings every time a key is set, not only when the key changes, so to
433
+     *               store the configuration parameters such as country or language.
434
+     * @since 3.11.0
435
+     *
436
+     * @see https://github.com/insideout10/wordlift-plugin/issues/761
437
+     *
438
+     * @param array $old_value The old settings.
439
+     * @param array $new_value The new settings.
440
+     */
441
+    public function update_key( $old_value, $new_value ) {
442
+
443
+        // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed.
444
+        // $old_key = isset( $old_value['key'] ) ? $old_value['key'] : '';
445
+        $new_key = isset( $new_value['key'] ) ? $new_value['key'] : '';
446
+
447
+        // If the key hasn't changed, don't do anything.
448
+        // WARN The 'update_option' hook is fired only if the new and old value are not equal.
449
+        // if ( $old_key === $new_key ) {
450
+        // return;
451
+        // }
452
+
453
+        // If the key is empty, empty the dataset URI.
454
+        if ( '' === $new_key ) {
455
+            $this->set_dataset_uri( '' );
456
+        }
457
+
458
+        // make the request to the remote server.
459
+        $this->get_remote_dataset_uri( $new_key );
460
+
461
+        do_action( 'wl_key_updated' );
462
+
463
+    }
464
+
465
+    /**
466
+     * Handle retrieving the dataset uri from the remote server.
467
+     *
468
+     * If a valid dataset uri is returned it is stored in the appropriate option,
469
+     * otherwise the option is set to empty string.
470
+     *
471
+     * @param string $key The key to be used.
472
+     *
473
+     * @since 3.12.0
474
+     *
475
+     * @since 3.17.0 send the site URL and get the dataset URI.
476
+     */
477
+    public function get_remote_dataset_uri( $key ) {
478
+
479
+        $this->log->trace( 'Getting the remote dataset URI and package type...' );
480
+
481
+        if ( empty( $key ) ) {
482
+            $this->log->warn( 'Key set to empty value.' );
483
+
484
+            $this->set_dataset_uri( '' );
485
+            $this->set_package_type( null );
486
+
487
+            return;
488
+        }
489
+
490
+        /**
491
+         * Allow 3rd parties to change the site_url.
492
+         *
493
+         * @param string $site_url The site url.
494
+         *
495
+         * @see https://github.com/insideout10/wordlift-plugin/issues/850
496
+         *
497
+         * @since 3.20.0
498
+         */
499
+        $home_url = get_option( 'home' );
500
+        $site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) );
501
+
502
+        // Build the URL.
503
+        $url = '/accounts'
504
+                . '?key=' . rawurlencode( $key )
505
+                . '&url=' . rawurlencode( $site_url )
506
+                . '&country=' . $this->get_country_code()
507
+                . '&language=' . $this->get_language_code();
508
+
509
+        $api_service = Default_Api_Service::get_instance();
510
+        /**
511
+         * @since 3.27.7.1
512
+         * The Key should be passed to headers, otherwise api would return null.
513
+         */
514
+        $headers  = array(
515
+            'Authorization' => "Key $key",
516
+        );
517
+        $response = $api_service->request( 'PUT', $url, $headers )->get_response();
518
+
519
+        // The response is an error.
520
+        if ( is_wp_error( $response ) ) {
521
+            $this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() );
522
+
523
+            $this->set_dataset_uri( '' );
524
+            $this->set_package_type( null );
525
+
526
+            return;
527
+        }
528
+
529
+        // The response is not OK.
530
+        if ( ! is_array( $response ) || 200 !== (int) $response['response']['code'] ) {
531
+            $base_url = $api_service->get_base_url();
532
+
533
+            if ( ! is_array( $response ) ) {
534
+                // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
535
+                $this->log->error( "Unexpected response when opening URL $base_url$url: " . var_export( $response, true ) );
536
+            } else {
537
+                // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
538
+                $this->log->error( "Unexpected status code when opening URL $base_url$url: " . $response['response']['code'] . "\n" . var_export( $response, true ) );
539
+            }
540
+
541
+            $this->set_dataset_uri( '' );
542
+            $this->set_package_type( null );
543
+
544
+            return;
545
+        }
546
+
547
+        /*
548 548
 		 * We also store the package type.
549 549
 		 *
550 550
 		 * @since 3.20.0
551 551
 		 */
552
-		$json = json_decode( $response['body'] );
553
-		/**
554
-		 * @since 3.27.7
555
-		 * Remove the trailing slash returned from the new platform api.
556
-		 */
557
-		// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
558
-		$dataset_uri = untrailingslashit( $json->datasetURI );
559
-		// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
560
-		$package_type = isset( $json->packageType ) ? $json->packageType : null;
561
-
562
-		$this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." );
563
-
564
-		$this->set_dataset_uri( $dataset_uri );
565
-		$this->set_package_type( $package_type );
566
-	}
567
-
568
-	/**
569
-	 * Handle the edge case where a user submits the same key again
570
-	 * when he does not have the dataset uri to regain it.
571
-	 *
572
-	 * This can not be handled in the normal option update hook because
573
-	 * it is not being triggered when the save value equals to the one already
574
-	 * in the DB.
575
-	 *
576
-	 * @param mixed $value The new, unserialized option value.
577
-	 * @param mixed $old_value The old option value.
578
-	 *
579
-	 * @return mixed The same value in the $value parameter
580
-	 * @since 3.12.0
581
-	 */
582
-	public function maybe_update_dataset_uri( $value, $old_value ) {
583
-
584
-		// Check the old key value and the new one. Here we're only handling the
585
-		// case where the key hasn't changed and the dataset URI isn't set. The
586
-		// other case, i.e. a new key is inserted, is handled at `update_key`.
587
-		$old_key = isset( $old_value['key'] ) ? $old_value['key'] : '';
588
-		$new_key = isset( $value['key'] ) ? $value['key'] : '';
589
-
590
-		$dataset_uri = $this->get_dataset_uri();
591
-
592
-		if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) {
593
-
594
-			// make the request to the remote server to try to get the dataset uri.
595
-			$this->get_remote_dataset_uri( $new_key );
596
-		}
597
-
598
-		return $value;
599
-	}
600
-
601
-	/**
602
-	 * Get the API URI to retrieve the dataset URI using the WordLift Key.
603
-	 *
604
-	 * @param string $key The WordLift key to use.
605
-	 *
606
-	 * @return string The API URI.
607
-	 * @since 3.11.0
608
-	 */
609
-	public function get_accounts_by_key_dataset_uri( $key ) {
610
-
611
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri";
612
-	}
613
-
614
-	/**
615
-	 * Get the `accounts` end point.
616
-	 *
617
-	 * @return string The `accounts` end point.
618
-	 * @since 3.16.0
619
-	 */
620
-	public function get_accounts() {
621
-
622
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts';
623
-	}
624
-
625
-	/**
626
-	 * Get the `link by default` option.
627
-	 *
628
-	 * @return bool True if entities must be linked by default otherwise false.
629
-	 * @since 3.13.0
630
-	 */
631
-	public function is_link_by_default() {
632
-
633
-		return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' );
634
-	}
635
-
636
-	/**
637
-	 * Set the `link by default` option.
638
-	 *
639
-	 * @param bool $value True to enabling linking by default, otherwise false.
640
-	 *
641
-	 * @since 3.13.0
642
-	 */
643
-	public function set_link_by_default( $value ) {
644
-
645
-		$this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' );
646
-	}
647
-
648
-	/**
649
-	 * Get the 'analytics-enable' option.
650
-	 *
651
-	 * @return string 'no' or 'yes' representing bool.
652
-	 * @since 3.21.0
653
-	 */
654
-	public function is_analytics_enable() {
655
-		return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' );
656
-	}
657
-
658
-	/**
659
-	 * Set the `analytics-enable` option.
660
-	 *
661
-	 * @param bool $value True to enabling analytics, otherwise false.
662
-	 *
663
-	 * @since 3.21.0
664
-	 */
665
-	public function set_is_analytics_enable( $value ) {
666
-
667
-		$this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' );
668
-	}
669
-
670
-	/**
671
-	 * Get the 'analytics-entity-uri-dimention' option.
672
-	 *
673
-	 * @return int
674
-	 * @since 3.21.0
675
-	 */
676
-	public function get_analytics_entity_uri_dimension() {
677
-		return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 );
678
-	}
679
-
680
-	/**
681
-	 * Get the 'analytics-entity-type-dimension' option.
682
-	 *
683
-	 * @return int
684
-	 * @since 3.21.0
685
-	 */
686
-	public function get_analytics_entity_type_dimension() {
687
-		return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 );
688
-	}
689
-
690
-	/**
691
-	 * Get the URL to perform autocomplete request.
692
-	 *
693
-	 * @return string The URL to call to perform the autocomplete request.
694
-	 * @since 3.15.0
695
-	 */
696
-	public function get_autocomplete_url() {
697
-
698
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete';
699
-
700
-	}
701
-
702
-	/**
703
-	 * Get the URL to perform feedback deactivation request.
704
-	 *
705
-	 * @return string The URL to call to perform the feedback deactivation request.
706
-	 * @since 3.19.0
707
-	 */
708
-	public function get_deactivation_feedback_url() {
709
-
710
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks';
711
-
712
-	}
713
-
714
-	/**
715
-	 * Get the base API URL.
716
-	 *
717
-	 * @return string The base API URL.
718
-	 * @since 3.20.0
719
-	 */
720
-	public function get_api_url() {
721
-
722
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE;
723
-	}
552
+        $json = json_decode( $response['body'] );
553
+        /**
554
+         * @since 3.27.7
555
+         * Remove the trailing slash returned from the new platform api.
556
+         */
557
+        // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
558
+        $dataset_uri = untrailingslashit( $json->datasetURI );
559
+        // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
560
+        $package_type = isset( $json->packageType ) ? $json->packageType : null;
561
+
562
+        $this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." );
563
+
564
+        $this->set_dataset_uri( $dataset_uri );
565
+        $this->set_package_type( $package_type );
566
+    }
567
+
568
+    /**
569
+     * Handle the edge case where a user submits the same key again
570
+     * when he does not have the dataset uri to regain it.
571
+     *
572
+     * This can not be handled in the normal option update hook because
573
+     * it is not being triggered when the save value equals to the one already
574
+     * in the DB.
575
+     *
576
+     * @param mixed $value The new, unserialized option value.
577
+     * @param mixed $old_value The old option value.
578
+     *
579
+     * @return mixed The same value in the $value parameter
580
+     * @since 3.12.0
581
+     */
582
+    public function maybe_update_dataset_uri( $value, $old_value ) {
583
+
584
+        // Check the old key value and the new one. Here we're only handling the
585
+        // case where the key hasn't changed and the dataset URI isn't set. The
586
+        // other case, i.e. a new key is inserted, is handled at `update_key`.
587
+        $old_key = isset( $old_value['key'] ) ? $old_value['key'] : '';
588
+        $new_key = isset( $value['key'] ) ? $value['key'] : '';
589
+
590
+        $dataset_uri = $this->get_dataset_uri();
591
+
592
+        if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) {
593
+
594
+            // make the request to the remote server to try to get the dataset uri.
595
+            $this->get_remote_dataset_uri( $new_key );
596
+        }
597
+
598
+        return $value;
599
+    }
600
+
601
+    /**
602
+     * Get the API URI to retrieve the dataset URI using the WordLift Key.
603
+     *
604
+     * @param string $key The WordLift key to use.
605
+     *
606
+     * @return string The API URI.
607
+     * @since 3.11.0
608
+     */
609
+    public function get_accounts_by_key_dataset_uri( $key ) {
610
+
611
+        return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri";
612
+    }
613
+
614
+    /**
615
+     * Get the `accounts` end point.
616
+     *
617
+     * @return string The `accounts` end point.
618
+     * @since 3.16.0
619
+     */
620
+    public function get_accounts() {
621
+
622
+        return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts';
623
+    }
624
+
625
+    /**
626
+     * Get the `link by default` option.
627
+     *
628
+     * @return bool True if entities must be linked by default otherwise false.
629
+     * @since 3.13.0
630
+     */
631
+    public function is_link_by_default() {
632
+
633
+        return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' );
634
+    }
635
+
636
+    /**
637
+     * Set the `link by default` option.
638
+     *
639
+     * @param bool $value True to enabling linking by default, otherwise false.
640
+     *
641
+     * @since 3.13.0
642
+     */
643
+    public function set_link_by_default( $value ) {
644
+
645
+        $this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' );
646
+    }
647
+
648
+    /**
649
+     * Get the 'analytics-enable' option.
650
+     *
651
+     * @return string 'no' or 'yes' representing bool.
652
+     * @since 3.21.0
653
+     */
654
+    public function is_analytics_enable() {
655
+        return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' );
656
+    }
657
+
658
+    /**
659
+     * Set the `analytics-enable` option.
660
+     *
661
+     * @param bool $value True to enabling analytics, otherwise false.
662
+     *
663
+     * @since 3.21.0
664
+     */
665
+    public function set_is_analytics_enable( $value ) {
666
+
667
+        $this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' );
668
+    }
669
+
670
+    /**
671
+     * Get the 'analytics-entity-uri-dimention' option.
672
+     *
673
+     * @return int
674
+     * @since 3.21.0
675
+     */
676
+    public function get_analytics_entity_uri_dimension() {
677
+        return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 );
678
+    }
679
+
680
+    /**
681
+     * Get the 'analytics-entity-type-dimension' option.
682
+     *
683
+     * @return int
684
+     * @since 3.21.0
685
+     */
686
+    public function get_analytics_entity_type_dimension() {
687
+        return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 );
688
+    }
689
+
690
+    /**
691
+     * Get the URL to perform autocomplete request.
692
+     *
693
+     * @return string The URL to call to perform the autocomplete request.
694
+     * @since 3.15.0
695
+     */
696
+    public function get_autocomplete_url() {
697
+
698
+        return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete';
699
+
700
+    }
701
+
702
+    /**
703
+     * Get the URL to perform feedback deactivation request.
704
+     *
705
+     * @return string The URL to call to perform the feedback deactivation request.
706
+     * @since 3.19.0
707
+     */
708
+    public function get_deactivation_feedback_url() {
709
+
710
+        return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks';
711
+
712
+    }
713
+
714
+    /**
715
+     * Get the base API URL.
716
+     *
717
+     * @return string The base API URL.
718
+     * @since 3.20.0
719
+     */
720
+    public function get_api_url() {
721
+
722
+        return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE;
723
+    }
724 724
 
725 725
 }
Please login to merge, or discard this patch.
Spacing   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 use Wordlift\Api\Default_Api_Service;
14 14
 
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 */
131 131
 	protected function __construct() {
132 132
 
133
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
133
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
134 134
 
135 135
 	}
136 136
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public static function get_instance() {
154 154
 
155
-		if ( ! isset( self::$instance ) ) {
155
+		if ( ! isset(self::$instance)) {
156 156
 			self::$instance = new self();
157 157
 		}
158 158
 
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
 	 * @return mixed The configuration value or the default value if not found.
171 171
 	 * @since 3.6.0
172 172
 	 */
173
-	private function get( $option, $key, $default = '' ) {
173
+	private function get($option, $key, $default = '') {
174 174
 
175
-		$options = get_option( $option, array() );
175
+		$options = get_option($option, array());
176 176
 
177
-		return isset( $options[ $key ] ) ? $options[ $key ] : $default;
177
+		return isset($options[$key]) ? $options[$key] : $default;
178 178
 	}
179 179
 
180 180
 	/**
@@ -186,12 +186,12 @@  discard block
 block discarded – undo
186 186
 	 *
187 187
 	 * @since 3.9.0
188 188
 	 */
189
-	private function set( $option, $key, $value ) {
189
+	private function set($option, $key, $value) {
190 190
 
191
-		$values         = get_option( $option );
192
-		$values         = isset( $values ) ? $values : array();
193
-		$values[ $key ] = $value;
194
-		update_option( $option, $values );
191
+		$values         = get_option($option);
192
+		$values         = isset($values) ? $values : array();
193
+		$values[$key] = $value;
194
+		update_option($option, $values);
195 195
 
196 196
 	}
197 197
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 */
204 204
 	public function get_entity_base_path() {
205 205
 
206
-		return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' );
206
+		return $this->get('wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity');
207 207
 	}
208 208
 
209 209
 	/**
@@ -213,9 +213,9 @@  discard block
 block discarded – undo
213 213
 	 *
214 214
 	 * @since 3.9.0
215 215
 	 */
216
-	public function set_entity_base_path( $value ) {
216
+	public function set_entity_base_path($value) {
217 217
 
218
-		$this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value );
218
+		$this->set('wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value);
219 219
 
220 220
 	}
221 221
 
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 */
228 228
 	public function is_skip_wizard() {
229 229
 
230
-		return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false );
230
+		return $this->get('wl_general_settings', self::SKIP_WIZARD, false);
231 231
 	}
232 232
 
233 233
 	/**
@@ -237,9 +237,9 @@  discard block
 block discarded – undo
237 237
 	 *
238 238
 	 * @since 3.9.0
239 239
 	 */
240
-	public function set_skip_wizard( $value ) {
240
+	public function set_skip_wizard($value) {
241 241
 
242
-		$this->set( 'wl_general_settings', self::SKIP_WIZARD, true === $value );
242
+		$this->set('wl_general_settings', self::SKIP_WIZARD, true === $value);
243 243
 
244 244
 	}
245 245
 
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 */
252 252
 	public function get_key() {
253 253
 
254
-		return $this->get( 'wl_general_settings', self::KEY, '' );
254
+		return $this->get('wl_general_settings', self::KEY, '');
255 255
 	}
256 256
 
257 257
 	/**
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
 	 *
262 262
 	 * @since 3.9.0
263 263
 	 */
264
-	public function set_key( $value ) {
264
+	public function set_key($value) {
265 265
 
266
-		$this->set( 'wl_general_settings', self::KEY, $value );
266
+		$this->set('wl_general_settings', self::KEY, $value);
267 267
 	}
268 268
 
269 269
 	/**
@@ -277,11 +277,11 @@  discard block
 block discarded – undo
277 277
 	public function get_language_code() {
278 278
 
279 279
 		$language = get_locale();
280
-		if ( ! $language ) {
280
+		if ( ! $language) {
281 281
 			return 'en';
282 282
 		}
283 283
 
284
-		return substr( $language, 0, 2 );
284
+		return substr($language, 0, 2);
285 285
 	}
286 286
 
287 287
 	/**
@@ -296,9 +296,9 @@  discard block
 block discarded – undo
296 296
 	 *
297 297
 	 * @since 3.9.0
298 298
 	 */
299
-	public function set_language_code( $value ) {
299
+	public function set_language_code($value) {
300 300
 
301
-		$this->set( 'wl_general_settings', self::LANGUAGE, $value );
301
+		$this->set('wl_general_settings', self::LANGUAGE, $value);
302 302
 
303 303
 	}
304 304
 
@@ -309,9 +309,9 @@  discard block
 block discarded – undo
309 309
 	 *
310 310
 	 * @since 3.19.0
311 311
 	 */
312
-	public function set_diagnostic_preferences( $value ) {
312
+	public function set_diagnostic_preferences($value) {
313 313
 
314
-		$this->set( 'wl_general_settings', self::SEND_DIAGNOSTIC, $value );
314
+		$this->set('wl_general_settings', self::SEND_DIAGNOSTIC, $value);
315 315
 
316 316
 	}
317 317
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 */
323 323
 	public function get_diagnostic_preferences() {
324 324
 
325
-		return $this->get( 'wl_general_settings', self::SEND_DIAGNOSTIC, 'no' );
325
+		return $this->get('wl_general_settings', self::SEND_DIAGNOSTIC, 'no');
326 326
 	}
327 327
 
328 328
 	/**
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 */
334 334
 	public function get_country_code() {
335 335
 
336
-		return $this->get( 'wl_general_settings', self::COUNTRY_CODE, 'us' );
336
+		return $this->get('wl_general_settings', self::COUNTRY_CODE, 'us');
337 337
 	}
338 338
 
339 339
 	/**
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
 	 *
344 344
 	 * @since 3.18.0
345 345
 	 */
346
-	public function set_country_code( $value ) {
346
+	public function set_country_code($value) {
347 347
 
348
-		$this->set( 'wl_general_settings', self::COUNTRY_CODE, $value );
348
+		$this->set('wl_general_settings', self::COUNTRY_CODE, $value);
349 349
 
350 350
 	}
351 351
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 	 */
361 361
 	public function get_publisher_id() {
362 362
 
363
-		return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null );
363
+		return $this->get('wl_general_settings', self::PUBLISHER_ID, null);
364 364
 	}
365 365
 
366 366
 	/**
@@ -370,9 +370,9 @@  discard block
 block discarded – undo
370 370
 	 *
371 371
 	 * @since 3.9.0
372 372
 	 */
373
-	public function set_publisher_id( $value ) {
373
+	public function set_publisher_id($value) {
374 374
 
375
-		$this->set( 'wl_general_settings', self::PUBLISHER_ID, $value );
375
+		$this->set('wl_general_settings', self::PUBLISHER_ID, $value);
376 376
 
377 377
 	}
378 378
 
@@ -385,8 +385,8 @@  discard block
 block discarded – undo
385 385
 	 */
386 386
 	public function get_dataset_uri() {
387 387
 
388
-		if ( apply_filters( 'wl_feature__enable__dataset', true ) ) {
389
-			return $this->get( 'wl_advanced_settings', self::DATASET_URI, null );
388
+		if (apply_filters('wl_feature__enable__dataset', true)) {
389
+			return $this->get('wl_advanced_settings', self::DATASET_URI, null);
390 390
 		} else {
391 391
 			return null;
392 392
 		}
@@ -399,9 +399,9 @@  discard block
 block discarded – undo
399 399
 	 *
400 400
 	 * @since 3.10.0
401 401
 	 */
402
-	public function set_dataset_uri( $value ) {
402
+	public function set_dataset_uri($value) {
403 403
 
404
-		$this->set( 'wl_advanced_settings', self::DATASET_URI, $value );
404
+		$this->set('wl_advanced_settings', self::DATASET_URI, $value);
405 405
 	}
406 406
 
407 407
 	/**
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 	 */
413 413
 	public function get_package_type() {
414 414
 
415
-		return $this->get( 'wl_advanced_settings', self::PACKAGE_TYPE, null );
415
+		return $this->get('wl_advanced_settings', self::PACKAGE_TYPE, null);
416 416
 	}
417 417
 
418 418
 	/**
@@ -422,8 +422,8 @@  discard block
 block discarded – undo
422 422
 	 *
423 423
 	 * @since 3.20.0
424 424
 	 */
425
-	public function set_package_type( $value ) {
426
-		$this->set( 'wl_advanced_settings', self::PACKAGE_TYPE, $value );
425
+	public function set_package_type($value) {
426
+		$this->set('wl_advanced_settings', self::PACKAGE_TYPE, $value);
427 427
 	}
428 428
 
429 429
 	/**
@@ -438,11 +438,11 @@  discard block
 block discarded – undo
438 438
 	 * @param array $old_value The old settings.
439 439
 	 * @param array $new_value The new settings.
440 440
 	 */
441
-	public function update_key( $old_value, $new_value ) {
441
+	public function update_key($old_value, $new_value) {
442 442
 
443 443
 		// Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed.
444 444
 		// $old_key = isset( $old_value['key'] ) ? $old_value['key'] : '';
445
-		$new_key = isset( $new_value['key'] ) ? $new_value['key'] : '';
445
+		$new_key = isset($new_value['key']) ? $new_value['key'] : '';
446 446
 
447 447
 		// If the key hasn't changed, don't do anything.
448 448
 		// WARN The 'update_option' hook is fired only if the new and old value are not equal.
@@ -451,14 +451,14 @@  discard block
 block discarded – undo
451 451
 		// }
452 452
 
453 453
 		// If the key is empty, empty the dataset URI.
454
-		if ( '' === $new_key ) {
455
-			$this->set_dataset_uri( '' );
454
+		if ('' === $new_key) {
455
+			$this->set_dataset_uri('');
456 456
 		}
457 457
 
458 458
 		// make the request to the remote server.
459
-		$this->get_remote_dataset_uri( $new_key );
459
+		$this->get_remote_dataset_uri($new_key);
460 460
 
461
-		do_action( 'wl_key_updated' );
461
+		do_action('wl_key_updated');
462 462
 
463 463
 	}
464 464
 
@@ -474,15 +474,15 @@  discard block
 block discarded – undo
474 474
 	 *
475 475
 	 * @since 3.17.0 send the site URL and get the dataset URI.
476 476
 	 */
477
-	public function get_remote_dataset_uri( $key ) {
477
+	public function get_remote_dataset_uri($key) {
478 478
 
479
-		$this->log->trace( 'Getting the remote dataset URI and package type...' );
479
+		$this->log->trace('Getting the remote dataset URI and package type...');
480 480
 
481
-		if ( empty( $key ) ) {
482
-			$this->log->warn( 'Key set to empty value.' );
481
+		if (empty($key)) {
482
+			$this->log->warn('Key set to empty value.');
483 483
 
484
-			$this->set_dataset_uri( '' );
485
-			$this->set_package_type( null );
484
+			$this->set_dataset_uri('');
485
+			$this->set_package_type(null);
486 486
 
487 487
 			return;
488 488
 		}
@@ -496,15 +496,15 @@  discard block
 block discarded – undo
496 496
 		 *
497 497
 		 * @since 3.20.0
498 498
 		 */
499
-		$home_url = get_option( 'home' );
500
-		$site_url = apply_filters( 'wl_production_site_url', untrailingslashit( $home_url ) );
499
+		$home_url = get_option('home');
500
+		$site_url = apply_filters('wl_production_site_url', untrailingslashit($home_url));
501 501
 
502 502
 		// Build the URL.
503 503
 		$url = '/accounts'
504
-			   . '?key=' . rawurlencode( $key )
505
-			   . '&url=' . rawurlencode( $site_url )
506
-			   . '&country=' . $this->get_country_code()
507
-			   . '&language=' . $this->get_language_code();
504
+			   . '?key='.rawurlencode($key)
505
+			   . '&url='.rawurlencode($site_url)
506
+			   . '&country='.$this->get_country_code()
507
+			   . '&language='.$this->get_language_code();
508 508
 
509 509
 		$api_service = Default_Api_Service::get_instance();
510 510
 		/**
@@ -514,32 +514,32 @@  discard block
 block discarded – undo
514 514
 		$headers  = array(
515 515
 			'Authorization' => "Key $key",
516 516
 		);
517
-		$response = $api_service->request( 'PUT', $url, $headers )->get_response();
517
+		$response = $api_service->request('PUT', $url, $headers)->get_response();
518 518
 
519 519
 		// The response is an error.
520
-		if ( is_wp_error( $response ) ) {
521
-			$this->log->error( 'An error occurred setting the dataset URI: ' . $response->get_error_message() );
520
+		if (is_wp_error($response)) {
521
+			$this->log->error('An error occurred setting the dataset URI: '.$response->get_error_message());
522 522
 
523
-			$this->set_dataset_uri( '' );
524
-			$this->set_package_type( null );
523
+			$this->set_dataset_uri('');
524
+			$this->set_package_type(null);
525 525
 
526 526
 			return;
527 527
 		}
528 528
 
529 529
 		// The response is not OK.
530
-		if ( ! is_array( $response ) || 200 !== (int) $response['response']['code'] ) {
530
+		if ( ! is_array($response) || 200 !== (int) $response['response']['code']) {
531 531
 			$base_url = $api_service->get_base_url();
532 532
 
533
-			if ( ! is_array( $response ) ) {
533
+			if ( ! is_array($response)) {
534 534
 				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
535
-				$this->log->error( "Unexpected response when opening URL $base_url$url: " . var_export( $response, true ) );
535
+				$this->log->error("Unexpected response when opening URL $base_url$url: ".var_export($response, true));
536 536
 			} else {
537 537
 				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
538
-				$this->log->error( "Unexpected status code when opening URL $base_url$url: " . $response['response']['code'] . "\n" . var_export( $response, true ) );
538
+				$this->log->error("Unexpected status code when opening URL $base_url$url: ".$response['response']['code']."\n".var_export($response, true));
539 539
 			}
540 540
 
541
-			$this->set_dataset_uri( '' );
542
-			$this->set_package_type( null );
541
+			$this->set_dataset_uri('');
542
+			$this->set_package_type(null);
543 543
 
544 544
 			return;
545 545
 		}
@@ -549,20 +549,20 @@  discard block
 block discarded – undo
549 549
 		 *
550 550
 		 * @since 3.20.0
551 551
 		 */
552
-		$json = json_decode( $response['body'] );
552
+		$json = json_decode($response['body']);
553 553
 		/**
554 554
 		 * @since 3.27.7
555 555
 		 * Remove the trailing slash returned from the new platform api.
556 556
 		 */
557 557
 		// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
558
-		$dataset_uri = untrailingslashit( $json->datasetURI );
558
+		$dataset_uri = untrailingslashit($json->datasetURI);
559 559
 		// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
560
-		$package_type = isset( $json->packageType ) ? $json->packageType : null;
560
+		$package_type = isset($json->packageType) ? $json->packageType : null;
561 561
 
562
-		$this->log->info( "Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]..." );
562
+		$this->log->info("Updating [ dataset uri :: $dataset_uri ][ package type :: $package_type ]...");
563 563
 
564
-		$this->set_dataset_uri( $dataset_uri );
565
-		$this->set_package_type( $package_type );
564
+		$this->set_dataset_uri($dataset_uri);
565
+		$this->set_package_type($package_type);
566 566
 	}
567 567
 
568 568
 	/**
@@ -579,20 +579,20 @@  discard block
 block discarded – undo
579 579
 	 * @return mixed The same value in the $value parameter
580 580
 	 * @since 3.12.0
581 581
 	 */
582
-	public function maybe_update_dataset_uri( $value, $old_value ) {
582
+	public function maybe_update_dataset_uri($value, $old_value) {
583 583
 
584 584
 		// Check the old key value and the new one. Here we're only handling the
585 585
 		// case where the key hasn't changed and the dataset URI isn't set. The
586 586
 		// other case, i.e. a new key is inserted, is handled at `update_key`.
587
-		$old_key = isset( $old_value['key'] ) ? $old_value['key'] : '';
588
-		$new_key = isset( $value['key'] ) ? $value['key'] : '';
587
+		$old_key = isset($old_value['key']) ? $old_value['key'] : '';
588
+		$new_key = isset($value['key']) ? $value['key'] : '';
589 589
 
590 590
 		$dataset_uri = $this->get_dataset_uri();
591 591
 
592
-		if ( ! empty( $new_key ) && $new_key === $old_key && empty( $dataset_uri ) ) {
592
+		if ( ! empty($new_key) && $new_key === $old_key && empty($dataset_uri)) {
593 593
 
594 594
 			// make the request to the remote server to try to get the dataset uri.
595
-			$this->get_remote_dataset_uri( $new_key );
595
+			$this->get_remote_dataset_uri($new_key);
596 596
 		}
597 597
 
598 598
 		return $value;
@@ -606,9 +606,9 @@  discard block
 block discarded – undo
606 606
 	 * @return string The API URI.
607 607
 	 * @since 3.11.0
608 608
 	 */
609
-	public function get_accounts_by_key_dataset_uri( $key ) {
609
+	public function get_accounts_by_key_dataset_uri($key) {
610 610
 
611
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri";
611
+		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."accounts/key=$key/dataset_uri";
612 612
 	}
613 613
 
614 614
 	/**
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
 	 */
620 620
 	public function get_accounts() {
621 621
 
622
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'accounts';
622
+		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'accounts';
623 623
 	}
624 624
 
625 625
 	/**
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 	 */
631 631
 	public function is_link_by_default() {
632 632
 
633
-		return 'yes' === $this->get( 'wl_general_settings', self::LINK_BY_DEFAULT, 'yes' );
633
+		return 'yes' === $this->get('wl_general_settings', self::LINK_BY_DEFAULT, 'yes');
634 634
 	}
635 635
 
636 636
 	/**
@@ -640,9 +640,9 @@  discard block
 block discarded – undo
640 640
 	 *
641 641
 	 * @since 3.13.0
642 642
 	 */
643
-	public function set_link_by_default( $value ) {
643
+	public function set_link_by_default($value) {
644 644
 
645
-		$this->set( 'wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no' );
645
+		$this->set('wl_general_settings', self::LINK_BY_DEFAULT, true === $value ? 'yes' : 'no');
646 646
 	}
647 647
 
648 648
 	/**
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 	 * @since 3.21.0
653 653
 	 */
654 654
 	public function is_analytics_enable() {
655
-		return 'yes' === $this->get( 'wl_analytics_settings', self::ANALYTICS_ENABLE, 'no' );
655
+		return 'yes' === $this->get('wl_analytics_settings', self::ANALYTICS_ENABLE, 'no');
656 656
 	}
657 657
 
658 658
 	/**
@@ -662,9 +662,9 @@  discard block
 block discarded – undo
662 662
 	 *
663 663
 	 * @since 3.21.0
664 664
 	 */
665
-	public function set_is_analytics_enable( $value ) {
665
+	public function set_is_analytics_enable($value) {
666 666
 
667
-		$this->set( 'wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no' );
667
+		$this->set('wl_general_settings', self::ANALYTICS_ENABLE, true === $value ? 'yes' : 'no');
668 668
 	}
669 669
 
670 670
 	/**
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
 	 * @since 3.21.0
675 675
 	 */
676 676
 	public function get_analytics_entity_uri_dimension() {
677
-		return (int) $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1 );
677
+		return (int) $this->get('wl_analytics_settings', self::ANALYTICS_ENTITY_URI_DIMENSION, 1);
678 678
 	}
679 679
 
680 680
 	/**
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
 	 * @since 3.21.0
685 685
 	 */
686 686
 	public function get_analytics_entity_type_dimension() {
687
-		return $this->get( 'wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2 );
687
+		return $this->get('wl_analytics_settings', self::ANALYTICS_ENTITY_TYPE_DIMENSION, 2);
688 688
 	}
689 689
 
690 690
 	/**
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 	 */
696 696
 	public function get_autocomplete_url() {
697 697
 
698
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'autocomplete';
698
+		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'autocomplete';
699 699
 
700 700
 	}
701 701
 
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 	 */
708 708
 	public function get_deactivation_feedback_url() {
709 709
 
710
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . 'feedbacks';
710
+		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE.'feedbacks';
711 711
 
712 712
 	}
713 713
 
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-url-property-service.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -16,37 +16,37 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Url_Property_Service extends Wordlift_Simple_Property_Service {
18 18
 
19
-	/**
20
-	 * The meta key for the schema:url property.
21
-	 */
22
-	const META_KEY = 'wl_schema_url';
19
+    /**
20
+     * The meta key for the schema:url property.
21
+     */
22
+    const META_KEY = 'wl_schema_url';
23 23
 
24
-	/**
25
-	 * Get the URLs associated with the post.
26
-	 *
27
-	 * @param int    $id The post id.
28
-	 * @param string $meta_key The meta key.
29
-	 *
30
-	 * @return array An array of URLs.
31
-	 */
32
-	public function get( $id, $meta_key, $type ) {
24
+    /**
25
+     * Get the URLs associated with the post.
26
+     *
27
+     * @param int    $id The post id.
28
+     * @param string $meta_key The meta key.
29
+     *
30
+     * @return array An array of URLs.
31
+     */
32
+    public function get( $id, $meta_key, $type ) {
33 33
 
34
-		// Get the meta values and push the <permalink> to
35
-		// ensure that default url will be added to the schema:url's.
36
-		/*
34
+        // Get the meta values and push the <permalink> to
35
+        // ensure that default url will be added to the schema:url's.
36
+        /*
37 37
 		 * Do not add `<permalink>` if one or more URLs have been provided by the editor.
38 38
 		 *
39 39
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/913
40 40
 		 *
41 41
 		 * @since 3.21.1
42 42
 		 */
43
-		$urls = parent::get( $id, $meta_key, $type );
44
-		$urls = array_filter( $urls ? $urls : array( '<permalink>' ) );
43
+        $urls = parent::get( $id, $meta_key, $type );
44
+        $urls = array_filter( $urls ? $urls : array( '<permalink>' ) );
45 45
 
46
-		// Convert <permalink> in actual permalink values.
47
-		return array_map(
48
-			function ( $item ) use ( $id, $type ) {
49
-				/*
46
+        // Convert <permalink> in actual permalink values.
47
+        return array_map(
48
+            function ( $item ) use ( $id, $type ) {
49
+                /*
50 50
 					* If `<permalink>` get the production permalink.
51 51
 					*
52 52
 					* @since 3.20.0
@@ -54,22 +54,22 @@  discard block
 block discarded – undo
54 54
 					* @see https://github.com/insideout10/wordlift-plugin/issues/850.
55 55
 					*/
56 56
 
57
-				if ( '<permalink>' !== $item ) {
58
-					  return $item;
59
-				}
57
+                if ( '<permalink>' !== $item ) {
58
+                        return $item;
59
+                }
60 60
 
61
-				// Permalinks.
62
-				switch ( $type ) {
63
-					case Object_Type_Enum::POST:
64
-						return Wordlift_Post_Adapter::get_production_permalink( $id );
65
-					case Object_Type_Enum::TERM:
66
-						return get_term_link( $id );
67
-					default:
68
-						return $item;
69
-				}
70
-			},
71
-			array_unique( $urls )
72
-		);
73
-	}
61
+                // Permalinks.
62
+                switch ( $type ) {
63
+                    case Object_Type_Enum::POST:
64
+                        return Wordlift_Post_Adapter::get_production_permalink( $id );
65
+                    case Object_Type_Enum::TERM:
66
+                        return get_term_link( $id );
67
+                    default:
68
+                        return $item;
69
+                }
70
+            },
71
+            array_unique( $urls )
72
+        );
73
+    }
74 74
 
75 75
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @return array An array of URLs.
31 31
 	 */
32
-	public function get( $id, $meta_key, $type ) {
32
+	public function get($id, $meta_key, $type) {
33 33
 
34 34
 		// Get the meta values and push the <permalink> to
35 35
 		// ensure that default url will be added to the schema:url's.
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
 		 *
41 41
 		 * @since 3.21.1
42 42
 		 */
43
-		$urls = parent::get( $id, $meta_key, $type );
44
-		$urls = array_filter( $urls ? $urls : array( '<permalink>' ) );
43
+		$urls = parent::get($id, $meta_key, $type);
44
+		$urls = array_filter($urls ? $urls : array('<permalink>'));
45 45
 
46 46
 		// Convert <permalink> in actual permalink values.
47 47
 		return array_map(
48
-			function ( $item ) use ( $id, $type ) {
48
+			function($item) use ($id, $type) {
49 49
 				/*
50 50
 					* If `<permalink>` get the production permalink.
51 51
 					*
@@ -54,21 +54,21 @@  discard block
 block discarded – undo
54 54
 					* @see https://github.com/insideout10/wordlift-plugin/issues/850.
55 55
 					*/
56 56
 
57
-				if ( '<permalink>' !== $item ) {
57
+				if ('<permalink>' !== $item) {
58 58
 					  return $item;
59 59
 				}
60 60
 
61 61
 				// Permalinks.
62
-				switch ( $type ) {
62
+				switch ($type) {
63 63
 					case Object_Type_Enum::POST:
64
-						return Wordlift_Post_Adapter::get_production_permalink( $id );
64
+						return Wordlift_Post_Adapter::get_production_permalink($id);
65 65
 					case Object_Type_Enum::TERM:
66
-						return get_term_link( $id );
66
+						return get_term_link($id);
67 67
 					default:
68 68
 						return $item;
69 69
 				}
70 70
 			},
71
-			array_unique( $urls )
71
+			array_unique($urls)
72 72
 		);
73 73
 	}
74 74
 
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-duration-property-service.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -19,31 +19,31 @@
 block discarded – undo
19 19
  */
20 20
 class Wordlift_Duration_Property_Service extends Wordlift_Simple_Property_Service {
21 21
 
22
-	/**
23
-	 * {@inheritdoc}
24
-	 */
25
-	public function get( $id, $meta_key, $type ) {
22
+    /**
23
+     * {@inheritdoc}
24
+     */
25
+    public function get( $id, $meta_key, $type ) {
26 26
 
27
-		// Get the values and filter out the empty ones (or the ones with 00:00).
28
-		$values = array_filter(
29
-			parent::get( $id, $meta_key, $type ),
30
-			function ( $item ) {
31
-				return ! empty( $item ) && '00:00' !== $item;
32
-			}
33
-		);
27
+        // Get the values and filter out the empty ones (or the ones with 00:00).
28
+        $values = array_filter(
29
+            parent::get( $id, $meta_key, $type ),
30
+            function ( $item ) {
31
+                return ! empty( $item ) && '00:00' !== $item;
32
+            }
33
+        );
34 34
 
35
-		/*
35
+        /*
36 36
 		 * Map the value in the meta
37 37
 		 * The UI for the meta date enable two forms, a number of minutes
38 38
 		 * or an h:mm format.
39 39
 		 * Both needs to be adjusted to the iso format.
40 40
 		 */
41
-		return array_map(
42
-			function ( $value ) {
43
-				return 'PT' . str_replace( ':', 'H', $value ) . 'M';
44
-			},
45
-			$values
46
-		);
47
-	}
41
+        return array_map(
42
+            function ( $value ) {
43
+                return 'PT' . str_replace( ':', 'H', $value ) . 'M';
44
+            },
45
+            $values
46
+        );
47
+    }
48 48
 
49 49
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * {@inheritdoc}
24 24
 	 */
25
-	public function get( $id, $meta_key, $type ) {
25
+	public function get($id, $meta_key, $type) {
26 26
 
27 27
 		// Get the values and filter out the empty ones (or the ones with 00:00).
28 28
 		$values = array_filter(
29
-			parent::get( $id, $meta_key, $type ),
30
-			function ( $item ) {
31
-				return ! empty( $item ) && '00:00' !== $item;
29
+			parent::get($id, $meta_key, $type),
30
+			function($item) {
31
+				return ! empty($item) && '00:00' !== $item;
32 32
 			}
33 33
 		);
34 34
 
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 		 * Both needs to be adjusted to the iso format.
40 40
 		 */
41 41
 		return array_map(
42
-			function ( $value ) {
43
-				return 'PT' . str_replace( ':', 'H', $value ) . 'M';
42
+			function($value) {
43
+				return 'PT'.str_replace(':', 'H', $value).'M';
44 44
 			},
45 45
 			$values
46 46
 		);
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-property-getter.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -9,74 +9,74 @@
 block discarded – undo
9 9
  */
10 10
 class Wordlift_Property_Getter {
11 11
 
12
-	/**
13
-	 * An array of {@link Wordlift_Simple_Property_Service}s which can access a
14
-	 * property.
15
-	 *
16
-	 * @since 3.8.0
17
-	 * @access private
18
-	 * @var Wordlift_Simple_Property_Service[] $services An array of {@link Wordlift_Simple_Property_Service}s.
19
-	 */
20
-	private $services = array();
12
+    /**
13
+     * An array of {@link Wordlift_Simple_Property_Service}s which can access a
14
+     * property.
15
+     *
16
+     * @since 3.8.0
17
+     * @access private
18
+     * @var Wordlift_Simple_Property_Service[] $services An array of {@link Wordlift_Simple_Property_Service}s.
19
+     */
20
+    private $services = array();
21 21
 
22
-	/**
23
-	 * The default {@link Wordlift_Simple_Property_Service} which is used to access
24
-	 * a property when no specific {@link Wordlift_Simple_Property_Service} is found
25
-	 * in the {@see $services} array.
26
-	 *
27
-	 * @var Wordlift_Simple_Property_Service
28
-	 */
29
-	private $default;
22
+    /**
23
+     * The default {@link Wordlift_Simple_Property_Service} which is used to access
24
+     * a property when no specific {@link Wordlift_Simple_Property_Service} is found
25
+     * in the {@see $services} array.
26
+     *
27
+     * @var Wordlift_Simple_Property_Service
28
+     */
29
+    private $default;
30 30
 
31
-	/**
32
-	 * Create a property service with the provided {@link Wordlift_Simple_Property_Service}
33
-	 * as default.
34
-	 *
35
-	 * @param $default
36
-	 *
37
-	 * @since 3.8.0
38
-	 */
39
-	public function __construct( $default ) {
31
+    /**
32
+     * Create a property service with the provided {@link Wordlift_Simple_Property_Service}
33
+     * as default.
34
+     *
35
+     * @param $default
36
+     *
37
+     * @since 3.8.0
38
+     */
39
+    public function __construct( $default ) {
40 40
 
41
-		$this->default = $default;
41
+        $this->default = $default;
42 42
 
43
-	}
43
+    }
44 44
 
45
-	/**
46
-	 * Register a {@link Wordlift_Simple_Property_Service} for the specified meta keys.
47
-	 *
48
-	 * @param \Wordlift_Simple_Property_Service $property_service A {@link Wordlift_Simple_Property_Service} instance.
49
-	 * @param array                             $meta_keys An array of meta keys that the provided {@link Wordlift_Simple_Property_Service} will handle.
50
-	 *
51
-	 * @since 3.8.0
52
-	 */
53
-	public function register( $property_service, $meta_keys ) {
45
+    /**
46
+     * Register a {@link Wordlift_Simple_Property_Service} for the specified meta keys.
47
+     *
48
+     * @param \Wordlift_Simple_Property_Service $property_service A {@link Wordlift_Simple_Property_Service} instance.
49
+     * @param array                             $meta_keys An array of meta keys that the provided {@link Wordlift_Simple_Property_Service} will handle.
50
+     *
51
+     * @since 3.8.0
52
+     */
53
+    public function register( $property_service, $meta_keys ) {
54 54
 
55
-		// Register the specified property service for each meta key.
56
-		foreach ( $meta_keys as $meta_key ) {
57
-			$this->services[ $meta_key ] = $property_service;
58
-		}
55
+        // Register the specified property service for each meta key.
56
+        foreach ( $meta_keys as $meta_key ) {
57
+            $this->services[ $meta_key ] = $property_service;
58
+        }
59 59
 
60
-	}
60
+    }
61 61
 
62
-	/**
63
-	 * Get the value for the specified entity post id and WP's meta key.
64
-	 *
65
-	 * @param int    $post_id The post id.
66
-	 * @param string $meta_key The meta key.
67
-	 *
68
-	 * @param int    $type Term or Post, by default Post is used.
69
-	 *
70
-	 * @return mixed|null The property value or null.
71
-	 * @since 3.8.0
72
-	 */
73
-	public function get( $post_id, $meta_key, $type ) {
62
+    /**
63
+     * Get the value for the specified entity post id and WP's meta key.
64
+     *
65
+     * @param int    $post_id The post id.
66
+     * @param string $meta_key The meta key.
67
+     *
68
+     * @param int    $type Term or Post, by default Post is used.
69
+     *
70
+     * @return mixed|null The property value or null.
71
+     * @since 3.8.0
72
+     */
73
+    public function get( $post_id, $meta_key, $type ) {
74 74
 
75
-		return isset( $this->services[ $meta_key ] )
76
-			// Use a specific property service.
77
-			? $this->services[ $meta_key ]->get( $post_id, $meta_key, $type )
78
-			// Use the default property service.
79
-			: $this->default->get( $post_id, $meta_key, $type );
80
-	}
75
+        return isset( $this->services[ $meta_key ] )
76
+            // Use a specific property service.
77
+            ? $this->services[ $meta_key ]->get( $post_id, $meta_key, $type )
78
+            // Use the default property service.
79
+            : $this->default->get( $post_id, $meta_key, $type );
80
+    }
81 81
 
82 82
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 *
37 37
 	 * @since 3.8.0
38 38
 	 */
39
-	public function __construct( $default ) {
39
+	public function __construct($default) {
40 40
 
41 41
 		$this->default = $default;
42 42
 
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @since 3.8.0
52 52
 	 */
53
-	public function register( $property_service, $meta_keys ) {
53
+	public function register($property_service, $meta_keys) {
54 54
 
55 55
 		// Register the specified property service for each meta key.
56
-		foreach ( $meta_keys as $meta_key ) {
57
-			$this->services[ $meta_key ] = $property_service;
56
+		foreach ($meta_keys as $meta_key) {
57
+			$this->services[$meta_key] = $property_service;
58 58
 		}
59 59
 
60 60
 	}
@@ -70,13 +70,13 @@  discard block
 block discarded – undo
70 70
 	 * @return mixed|null The property value or null.
71 71
 	 * @since 3.8.0
72 72
 	 */
73
-	public function get( $post_id, $meta_key, $type ) {
73
+	public function get($post_id, $meta_key, $type) {
74 74
 
75
-		return isset( $this->services[ $meta_key ] )
75
+		return isset($this->services[$meta_key])
76 76
 			// Use a specific property service.
77
-			? $this->services[ $meta_key ]->get( $post_id, $meta_key, $type )
77
+			? $this->services[$meta_key]->get($post_id, $meta_key, $type)
78 78
 			// Use the default property service.
79
-			: $this->default->get( $post_id, $meta_key, $type );
79
+			: $this->default->get($post_id, $meta_key, $type);
80 80
 	}
81 81
 
82 82
 }
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-property-getter-factory.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -26,60 +26,60 @@
 block discarded – undo
26 26
  */
27 27
 class Wordlift_Property_Getter_Factory {
28 28
 
29
-	/**
30
-	 * Create a {@link Wordlift_Property_Getter} instance.
31
-	 *
32
-	 * @return \Wordlift_Property_Getter A {@link Wordlift_Property_Getter} instance.
33
-	 * @since 3.8.0
34
-	 */
35
-	public static function create() {
29
+    /**
30
+     * Create a {@link Wordlift_Property_Getter} instance.
31
+     *
32
+     * @return \Wordlift_Property_Getter A {@link Wordlift_Property_Getter} instance.
33
+     * @since 3.8.0
34
+     */
35
+    public static function create() {
36 36
 
37
-		$property_getter = new Wordlift_Property_Getter( new Wordlift_Simple_Property_Service() );
38
-		$property_getter->register(
39
-			new Wordlift_Entity_Property_Service(),
40
-			array(
41
-				Wordlift_Schema_Service::FIELD_FOUNDER,
42
-				Wordlift_Schema_Service::FIELD_AUTHOR,
43
-				Wordlift_Schema_Service::FIELD_KNOWS,
44
-				Wordlift_Schema_Service::FIELD_BIRTH_PLACE,
45
-				Wordlift_Schema_Service::FIELD_AFFILIATION,
46
-				Wordlift_Schema_Service::FIELD_PERFORMER,
47
-				Wordlift_Schema_Service::FIELD_OFFERS,
48
-				Wordlift_Schema_Service::FIELD_ITEM_OFFERED,
49
-			)
50
-		);
51
-		$property_getter->register(
52
-			new Wordlift_Location_Property_Service(),
53
-			array(
54
-				Wordlift_Schema_Service::FIELD_LOCATION,
55
-			)
56
-		);
57
-		$property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) );
58
-		$property_getter->register(
59
-			new Wordlift_Double_Property_Service(),
60
-			array(
61
-				Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
62
-				Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
63
-			)
64
-		);
37
+        $property_getter = new Wordlift_Property_Getter( new Wordlift_Simple_Property_Service() );
38
+        $property_getter->register(
39
+            new Wordlift_Entity_Property_Service(),
40
+            array(
41
+                Wordlift_Schema_Service::FIELD_FOUNDER,
42
+                Wordlift_Schema_Service::FIELD_AUTHOR,
43
+                Wordlift_Schema_Service::FIELD_KNOWS,
44
+                Wordlift_Schema_Service::FIELD_BIRTH_PLACE,
45
+                Wordlift_Schema_Service::FIELD_AFFILIATION,
46
+                Wordlift_Schema_Service::FIELD_PERFORMER,
47
+                Wordlift_Schema_Service::FIELD_OFFERS,
48
+                Wordlift_Schema_Service::FIELD_ITEM_OFFERED,
49
+            )
50
+        );
51
+        $property_getter->register(
52
+            new Wordlift_Location_Property_Service(),
53
+            array(
54
+                Wordlift_Schema_Service::FIELD_LOCATION,
55
+            )
56
+        );
57
+        $property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) );
58
+        $property_getter->register(
59
+            new Wordlift_Double_Property_Service(),
60
+            array(
61
+                Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
62
+                Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
63
+            )
64
+        );
65 65
 
66
-		$property_getter->register(
67
-			new Wordlift_Duration_Property_Service(),
68
-			array(
69
-				Wordlift_Schema_Service::FIELD_PREP_TIME,
70
-				Wordlift_Schema_Service::FIELD_COOK_TIME,
71
-				Wordlift_Schema_Service::FIELD_TOTAL_TIME,
72
-			)
73
-		);
66
+        $property_getter->register(
67
+            new Wordlift_Duration_Property_Service(),
68
+            array(
69
+                Wordlift_Schema_Service::FIELD_PREP_TIME,
70
+                Wordlift_Schema_Service::FIELD_COOK_TIME,
71
+                Wordlift_Schema_Service::FIELD_TOTAL_TIME,
72
+            )
73
+        );
74 74
 
75
-		add_action(
76
-			'after_setup_theme',
77
-			function () use ( $property_getter ) {
78
-				$property_getter->register( new Wordlift_Required_Property_Service(), apply_filters( 'wl_required_property', array() ) );
79
-			}
80
-		);
75
+        add_action(
76
+            'after_setup_theme',
77
+            function () use ( $property_getter ) {
78
+                $property_getter->register( new Wordlift_Required_Property_Service(), apply_filters( 'wl_required_property', array() ) );
79
+            }
80
+        );
81 81
 
82
-		return $property_getter;
83
-	}
82
+        return $property_getter;
83
+    }
84 84
 
85 85
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	public static function create() {
36 36
 
37
-		$property_getter = new Wordlift_Property_Getter( new Wordlift_Simple_Property_Service() );
37
+		$property_getter = new Wordlift_Property_Getter(new Wordlift_Simple_Property_Service());
38 38
 		$property_getter->register(
39 39
 			new Wordlift_Entity_Property_Service(),
40 40
 			array(
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 				Wordlift_Schema_Service::FIELD_LOCATION,
55 55
 			)
56 56
 		);
57
-		$property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) );
57
+		$property_getter->register(new Wordlift_Url_Property_Service(), array(Wordlift_Url_Property_Service::META_KEY));
58 58
 		$property_getter->register(
59 59
 			new Wordlift_Double_Property_Service(),
60 60
 			array(
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 
75 75
 		add_action(
76 76
 			'after_setup_theme',
77
-			function () use ( $property_getter ) {
78
-				$property_getter->register( new Wordlift_Required_Property_Service(), apply_filters( 'wl_required_property', array() ) );
77
+			function() use ($property_getter) {
78
+				$property_getter->register(new Wordlift_Required_Property_Service(), apply_filters('wl_required_property', array()));
79 79
 			}
80 80
 		);
81 81
 
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-simple-property-service.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -12,33 +12,33 @@
 block discarded – undo
12 12
  */
13 13
 class Wordlift_Simple_Property_Service {
14 14
 
15
-	/**
16
-	 * The meta key for this property service.
17
-	 *
18
-	 * @since 3.8.0
19
-	 */
20
-	const META_KEY = '*';
15
+    /**
16
+     * The meta key for this property service.
17
+     *
18
+     * @since 3.8.0
19
+     */
20
+    const META_KEY = '*';
21 21
 
22
-	/**
23
-	 * Get the property value for the specified post id and meta with the specified key.
24
-	 *
25
-	 * @param int                   $id The post id.
26
-	 * @param string                $meta_key The meta key.
27
-	 *
28
-	 * @param $type int Post or Term
29
-	 *
30
-	 * @return mixed|null The property value.
31
-	 * @since 3.8.0
32
-	 */
33
-	public function get( $id, $meta_key, $type ) {
22
+    /**
23
+     * Get the property value for the specified post id and meta with the specified key.
24
+     *
25
+     * @param int                   $id The post id.
26
+     * @param string                $meta_key The meta key.
27
+     *
28
+     * @param $type int Post or Term
29
+     *
30
+     * @return mixed|null The property value.
31
+     * @since 3.8.0
32
+     */
33
+    public function get( $id, $meta_key, $type ) {
34 34
 
35
-		if ( Object_Type_Enum::POST === $type ) {
36
-			// Get the value stored in WP.
37
-			return get_post_meta( $id, $meta_key );
38
-		} elseif ( Object_Type_Enum::TERM === $type ) {
39
-			return get_term_meta( $id, $meta_key );
40
-		}
41
-		return null;
42
-	}
35
+        if ( Object_Type_Enum::POST === $type ) {
36
+            // Get the value stored in WP.
37
+            return get_post_meta( $id, $meta_key );
38
+        } elseif ( Object_Type_Enum::TERM === $type ) {
39
+            return get_term_meta( $id, $meta_key );
40
+        }
41
+        return null;
42
+    }
43 43
 
44 44
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,13 +30,13 @@
 block discarded – undo
30 30
 	 * @return mixed|null The property value.
31 31
 	 * @since 3.8.0
32 32
 	 */
33
-	public function get( $id, $meta_key, $type ) {
33
+	public function get($id, $meta_key, $type) {
34 34
 
35
-		if ( Object_Type_Enum::POST === $type ) {
35
+		if (Object_Type_Enum::POST === $type) {
36 36
 			// Get the value stored in WP.
37
-			return get_post_meta( $id, $meta_key );
38
-		} elseif ( Object_Type_Enum::TERM === $type ) {
39
-			return get_term_meta( $id, $meta_key );
37
+			return get_post_meta($id, $meta_key);
38
+		} elseif (Object_Type_Enum::TERM === $type) {
39
+			return get_term_meta($id, $meta_key);
40 40
 		}
41 41
 		return null;
42 42
 	}
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-entity-property-service.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -8,25 +8,25 @@
 block discarded – undo
8 8
  */
9 9
 class Wordlift_Entity_Property_Service extends Wordlift_Simple_Property_Service {
10 10
 
11
-	/**
12
-	 * {@inheritdoc}
13
-	 */
14
-	public function get( $id, $meta_key, $type ) {
11
+    /**
12
+     * {@inheritdoc}
13
+     */
14
+    public function get( $id, $meta_key, $type ) {
15 15
 
16
-		$entity_service = Wordlift_Entity_Service::get_instance();
16
+        $entity_service = Wordlift_Entity_Service::get_instance();
17 17
 
18
-		// Map each returned value to a Wordlift_Property_Entity_Reference.
19
-		return array_map(
20
-			function ( $item ) use ( $entity_service ) {
18
+        // Map each returned value to a Wordlift_Property_Entity_Reference.
19
+        return array_map(
20
+            function ( $item ) use ( $entity_service ) {
21 21
 
22
-				// If the $item is a number and it's an existing post, return the
23
-				// URI of the referenced entity. Otherwise return the value.
24
-				return is_numeric( $item ) && null !== get_post( $item )
25
-				? new Wordlift_Property_Entity_Reference( $entity_service->get_uri( $item ), (int) $item )
26
-				: $item;
27
-			},
28
-			parent::get( $id, $meta_key, $type )
29
-		);
30
-	}
22
+                // If the $item is a number and it's an existing post, return the
23
+                // URI of the referenced entity. Otherwise return the value.
24
+                return is_numeric( $item ) && null !== get_post( $item )
25
+                ? new Wordlift_Property_Entity_Reference( $entity_service->get_uri( $item ), (int) $item )
26
+                : $item;
27
+            },
28
+            parent::get( $id, $meta_key, $type )
29
+        );
30
+    }
31 31
 
32 32
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -11,21 +11,21 @@
 block discarded – undo
11 11
 	/**
12 12
 	 * {@inheritdoc}
13 13
 	 */
14
-	public function get( $id, $meta_key, $type ) {
14
+	public function get($id, $meta_key, $type) {
15 15
 
16 16
 		$entity_service = Wordlift_Entity_Service::get_instance();
17 17
 
18 18
 		// Map each returned value to a Wordlift_Property_Entity_Reference.
19 19
 		return array_map(
20
-			function ( $item ) use ( $entity_service ) {
20
+			function($item) use ($entity_service) {
21 21
 
22 22
 				// If the $item is a number and it's an existing post, return the
23 23
 				// URI of the referenced entity. Otherwise return the value.
24
-				return is_numeric( $item ) && null !== get_post( $item )
25
-				? new Wordlift_Property_Entity_Reference( $entity_service->get_uri( $item ), (int) $item )
24
+				return is_numeric($item) && null !== get_post($item)
25
+				? new Wordlift_Property_Entity_Reference($entity_service->get_uri($item), (int) $item)
26 26
 				: $item;
27 27
 			},
28
-			parent::get( $id, $meta_key, $type )
28
+			parent::get($id, $meta_key, $type)
29 29
 		);
30 30
 	}
31 31
 
Please login to merge, or discard this patch.