Completed
Push — develop ( 0af133...0b4679 )
by Naveen
02:17 queued 01:08
created
src/admin/class-wordlift-admin-setup.php 1 patch
Indentation   +257 added lines, -257 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  */
14 14
 
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -28,126 +28,126 @@  discard block
 block discarded – undo
28 28
  */
29 29
 class Wordlift_Admin_Setup {
30 30
 
31
-	/**
32
-	 * A {@link Wordlift_Key_Validation_Service} instance.
33
-	 *
34
-	 * @since  3.9.0
35
-	 * @access private
36
-	 * @var Wordlift_Key_Validation_Service A {@link Wordlift_Key_Validation_Service} instance.
37
-	 */
38
-	private $key_validation_service;
39
-
40
-	/**
41
-	 * A {@link Wordlift_Entity_Service} instance.
42
-	 *
43
-	 * @since  3.9.0
44
-	 * @access private
45
-	 * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
46
-	 */
47
-	private $entity_service;
48
-
49
-	/**
50
-	 * A {@link Wordlift_Admin_Language_Select_Element} element renderer.
51
-	 *
52
-	 * @since  3.20.0
53
-	 * @access private
54
-	 * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
55
-	 */
56
-	private $language_select_element;
57
-
58
-	/**
59
-	 * A {@link Wordlift_Admin_Country_Select_Element} element renderer.
60
-	 *
61
-	 * @since  3.20.0
62
-	 * @access private
63
-	 * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer.
64
-	 */
65
-	private $country_select_element;
66
-
67
-	/**
68
-	 * Initialize the class and set its properties.
69
-	 *
70
-	 * @param \Wordlift_Key_Validation_Service        $key_validation_service A {@link Wordlift_Key_Validation_Service} instance.
71
-	 * @param \Wordlift_Entity_Service                $entity_service A {@link Wordlift_Entity_Service} instance.
72
-	 * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
73
-	 * @param \Wordlift_Admin_Country_Select_Element  $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer.
74
-	 *
75
-	 * @since    3.9.0
76
-	 */
77
-	public function __construct( $key_validation_service, $entity_service, $language_select_element, $country_select_element ) {
78
-
79
-		// Set a reference to the key validation service.
80
-		$this->key_validation_service = $key_validation_service;
81
-
82
-		// Set a reference to the entity service.
83
-		$this->entity_service = $entity_service;
84
-
85
-		// Set a reference to the UI elements language and country.
86
-		$this->language_select_element = $language_select_element;
87
-		$this->country_select_element  = $country_select_element;
88
-
89
-		// Hook to some WP's events:
90
-		// When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up.
91
-		add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
92
-
93
-		// Hook to `admin_menu` in order to add our own setup wizard page.
94
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
95
-
96
-		// Triggered when the user accesses the admin area, we decide whether to show our own wizard.
97
-		add_action( 'admin_init', array( $this, 'show_page' ) );
98
-
99
-		/**
100
-		 * Filter: wl_feature__enable__notices.
101
-		 *
102
-		 * @param bool whether the notices needs to be enabled or not.
103
-		 *
104
-		 * @return bool
105
-		 * @since 3.27.6
106
-		 */
107
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
108
-			// Hook to `admin_notices` to display our notices.
109
-			add_action( 'admin_notices', array( $this, 'admin_notices' ) );
110
-		}
111
-	}
112
-
113
-	/**
114
-	 * Hook to `admin_init` and redirect to WordLift's setup page if the `_wl_activation_redirect` transient flag is set.
115
-	 *
116
-	 * @since 3.9.0
117
-	 */
118
-	public function admin_init() {
119
-
120
-		// If the `_wl_activation_redirect` is set, the redirect to the setup page.
121
-		if ( get_transient( '_wl_activation_redirect' ) ) {
122
-			delete_transient( '_wl_activation_redirect' );
123
-
124
-			// If the user asked to skip the wizard then comply.
125
-			if ( Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) {
126
-				return;
127
-			}
128
-
129
-			// If we're already on the page or the user doesn't have permissions, return.
130
-			if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
131
-				return;
132
-			}
133
-
134
-			// Finally redirect to the setup page.
135
-			wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) );
136
-
137
-			exit;
138
-		}
139
-
140
-	}
141
-
142
-	/**
143
-	 * Generate an admin notice suggesting to start the wizard if there is no configuration.
144
-	 *
145
-	 * @since    3.9.0
146
-	 */
147
-	public function admin_notices() {
148
-
149
-		// Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard.
150
-		if ( '' === Wordlift_Configuration_Service::get_instance()->get_key() && ! Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { ?>
31
+    /**
32
+     * A {@link Wordlift_Key_Validation_Service} instance.
33
+     *
34
+     * @since  3.9.0
35
+     * @access private
36
+     * @var Wordlift_Key_Validation_Service A {@link Wordlift_Key_Validation_Service} instance.
37
+     */
38
+    private $key_validation_service;
39
+
40
+    /**
41
+     * A {@link Wordlift_Entity_Service} instance.
42
+     *
43
+     * @since  3.9.0
44
+     * @access private
45
+     * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
46
+     */
47
+    private $entity_service;
48
+
49
+    /**
50
+     * A {@link Wordlift_Admin_Language_Select_Element} element renderer.
51
+     *
52
+     * @since  3.20.0
53
+     * @access private
54
+     * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
55
+     */
56
+    private $language_select_element;
57
+
58
+    /**
59
+     * A {@link Wordlift_Admin_Country_Select_Element} element renderer.
60
+     *
61
+     * @since  3.20.0
62
+     * @access private
63
+     * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer.
64
+     */
65
+    private $country_select_element;
66
+
67
+    /**
68
+     * Initialize the class and set its properties.
69
+     *
70
+     * @param \Wordlift_Key_Validation_Service        $key_validation_service A {@link Wordlift_Key_Validation_Service} instance.
71
+     * @param \Wordlift_Entity_Service                $entity_service A {@link Wordlift_Entity_Service} instance.
72
+     * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
73
+     * @param \Wordlift_Admin_Country_Select_Element  $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer.
74
+     *
75
+     * @since    3.9.0
76
+     */
77
+    public function __construct( $key_validation_service, $entity_service, $language_select_element, $country_select_element ) {
78
+
79
+        // Set a reference to the key validation service.
80
+        $this->key_validation_service = $key_validation_service;
81
+
82
+        // Set a reference to the entity service.
83
+        $this->entity_service = $entity_service;
84
+
85
+        // Set a reference to the UI elements language and country.
86
+        $this->language_select_element = $language_select_element;
87
+        $this->country_select_element  = $country_select_element;
88
+
89
+        // Hook to some WP's events:
90
+        // When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up.
91
+        add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
92
+
93
+        // Hook to `admin_menu` in order to add our own setup wizard page.
94
+        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
95
+
96
+        // Triggered when the user accesses the admin area, we decide whether to show our own wizard.
97
+        add_action( 'admin_init', array( $this, 'show_page' ) );
98
+
99
+        /**
100
+         * Filter: wl_feature__enable__notices.
101
+         *
102
+         * @param bool whether the notices needs to be enabled or not.
103
+         *
104
+         * @return bool
105
+         * @since 3.27.6
106
+         */
107
+        if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
108
+            // Hook to `admin_notices` to display our notices.
109
+            add_action( 'admin_notices', array( $this, 'admin_notices' ) );
110
+        }
111
+    }
112
+
113
+    /**
114
+     * Hook to `admin_init` and redirect to WordLift's setup page if the `_wl_activation_redirect` transient flag is set.
115
+     *
116
+     * @since 3.9.0
117
+     */
118
+    public function admin_init() {
119
+
120
+        // If the `_wl_activation_redirect` is set, the redirect to the setup page.
121
+        if ( get_transient( '_wl_activation_redirect' ) ) {
122
+            delete_transient( '_wl_activation_redirect' );
123
+
124
+            // If the user asked to skip the wizard then comply.
125
+            if ( Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) {
126
+                return;
127
+            }
128
+
129
+            // If we're already on the page or the user doesn't have permissions, return.
130
+            if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
131
+                return;
132
+            }
133
+
134
+            // Finally redirect to the setup page.
135
+            wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) );
136
+
137
+            exit;
138
+        }
139
+
140
+    }
141
+
142
+    /**
143
+     * Generate an admin notice suggesting to start the wizard if there is no configuration.
144
+     *
145
+     * @since    3.9.0
146
+     */
147
+    public function admin_notices() {
148
+
149
+        // Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard.
150
+        if ( '' === Wordlift_Configuration_Service::get_instance()->get_key() && ! Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { ?>
151 151
 			<div id="wl-message" class="updated">
152 152
 				<p><?php esc_html_e( 'Welcome to WordLift &#8211; You&lsquo;re almost ready to start', 'wordlift' ); ?></p>
153 153
 				<p class="submit">
@@ -158,141 +158,141 @@  discard block
 block discarded – undo
158 158
 				</p>
159 159
 			</div>
160 160
 			<?php
161
-		}
162
-
163
-	}
164
-
165
-	/**
166
-	 * Handle hiding the wizard notices by user request.
167
-	 *
168
-	 * @since    3.9.0
169
-	 */
170
-	public function hide_notices() {
171
-
172
-		// If it's not a `wl-hide-notice` or the nonce is not set, return.
173
-		if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) {
174
-			return;
175
-		}
176
-
177
-		// If the nonce is invalid, return an error.
178
-		if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wl_notice_nonce'] ) ), 'wordlift_hide_notices_nonce' ) ) {
179
-			wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'wordlift' ) );
180
-		}
181
-
182
-		// If the user doesn't have the right privileges, return an error.
183
-		if ( ! current_user_can( 'manage_options' ) ) {
184
-			wp_die( esc_html__( 'Cheatin&#8217; huh?', 'wordlift' ) );
185
-		}
186
-
187
-		// Store a flag telling to skip the wizard.
188
-		Wordlift_Configuration_Service::get_instance()->set_skip_wizard( true );
189
-
190
-	}
191
-
192
-	/**
193
-	 * Register the wizard page to be able to access it.
194
-	 *
195
-	 * @since    3.9.0
196
-	 */
197
-	public function admin_menu() {
198
-		/**
199
-		 *
200
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/1209
201
-		 * @since 3.27.7
202
-		 */
203
-		// @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu.
204
-		add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' );
205
-	}
206
-
207
-	/**
208
-	 * Displays the wizard page.
209
-	 *
210
-	 * @since    3.9.0
211
-	 */
212
-	public function show_page() {
213
-
214
-		// First check if we are in the wizard page at all, if not do nothing.
215
-		if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) {
216
-			return;
217
-		}
218
-
219
-		// Allow 3rd parties to provide alternative setups, this is useful for whitelabel setups.
220
-		do_action( 'wl_admin_setup__pre' );
221
-
222
-		// If it's a POST and the `wl-save-configuration` action is set, save the configuration.
223
-		if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) {
224
-
225
-			// Check the nonce and the user capabilities.
226
-			check_admin_referer( 'wl-save-configuration' );
227
-
228
-			// Check if the user has the right privileges.
229
-			if ( ! current_user_can( 'manage_options' ) ) {
230
-				wp_die( esc_html__( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) );
231
-			}
232
-
233
-			// Save the configuration.
234
-			$this->save_configuration( $_POST );
235
-
236
-			// Redirect to the admin's page.
237
-			wp_safe_redirect( admin_url() );
238
-			exit();
239
-		}
240
-
241
-		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
242
-		$language_select = $this->language_select_element;
243
-		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
244
-		$country_select = $this->country_select_element;
245
-
246
-		include plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-setup.php';
247
-
248
-		exit;
249
-	}
250
-
251
-	/**
252
-	 * Save WordLift's configuration using the provided parameters.
253
-	 *
254
-	 * @param array $params An array of configuration parameters.
255
-	 *
256
-	 * @since 3.9.0
257
-	 */
258
-	public function save_configuration( $params ) {
259
-
260
-		// We have the following parameters:
261
-		// `key`, holding WL's key,
262
-		// `vocabulary`, holding the vocabulary path,
263
-		// `wl-country-code` with the country code (e.g. `us`),
264
-		// `share-diagnostic`, the user preferences about sharing data with us.
265
-		// `user_type`, the user type either `personal` or `company`,
266
-		// `name`, with the `personal` or `company`'s name,
267
-		// `logo`, the attachment id for the `personal` or `company` entity.
268
-
269
-		// Store the key:
270
-		Wordlift_Configuration_Service::get_instance()->set_key( $params['key'] );
271
-
272
-		// Store the vocabulary path:
273
-		Wordlift_Configuration_Service::get_instance()->set_entity_base_path( $params['vocabulary'] );
274
-
275
-		// Store the site's country:
276
-		Wordlift_Configuration_Service::get_instance()->set_country_code( $params['wl-country-code'] );
277
-
278
-		// Store the preferences in variable, because if the checkbox is not checked
279
-		// the `share-diagnostic` will not exists in `$params` array.
280
-		$share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes';
281
-
282
-		// Store the diagnostic preferences:
283
-		Wordlift_Configuration_Service::get_instance()->set_diagnostic_preferences( $share_diagnostic_preferences );
284
-
285
-		// Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
286
-		$type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' );
287
-
288
-		// Create an entity for the publisher.
289
-		$publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' );
290
-
291
-		// Store the publisher entity post id in the configuration.
292
-		Wordlift_Configuration_Service::get_instance()->set_publisher_id( $publisher_post_id );
293
-
294
-		flush_rewrite_rules(); // Needed because of possible change to the entity base path.
295
-
296
-	}
161
+        }
162
+
163
+    }
164
+
165
+    /**
166
+     * Handle hiding the wizard notices by user request.
167
+     *
168
+     * @since    3.9.0
169
+     */
170
+    public function hide_notices() {
171
+
172
+        // If it's not a `wl-hide-notice` or the nonce is not set, return.
173
+        if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) {
174
+            return;
175
+        }
176
+
177
+        // If the nonce is invalid, return an error.
178
+        if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wl_notice_nonce'] ) ), 'wordlift_hide_notices_nonce' ) ) {
179
+            wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'wordlift' ) );
180
+        }
181
+
182
+        // If the user doesn't have the right privileges, return an error.
183
+        if ( ! current_user_can( 'manage_options' ) ) {
184
+            wp_die( esc_html__( 'Cheatin&#8217; huh?', 'wordlift' ) );
185
+        }
186
+
187
+        // Store a flag telling to skip the wizard.
188
+        Wordlift_Configuration_Service::get_instance()->set_skip_wizard( true );
189
+
190
+    }
191
+
192
+    /**
193
+     * Register the wizard page to be able to access it.
194
+     *
195
+     * @since    3.9.0
196
+     */
197
+    public function admin_menu() {
198
+        /**
199
+         *
200
+         * @see https://github.com/insideout10/wordlift-plugin/issues/1209
201
+         * @since 3.27.7
202
+         */
203
+        // @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu.
204
+        add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' );
205
+    }
206
+
207
+    /**
208
+     * Displays the wizard page.
209
+     *
210
+     * @since    3.9.0
211
+     */
212
+    public function show_page() {
213
+
214
+        // First check if we are in the wizard page at all, if not do nothing.
215
+        if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) {
216
+            return;
217
+        }
218
+
219
+        // Allow 3rd parties to provide alternative setups, this is useful for whitelabel setups.
220
+        do_action( 'wl_admin_setup__pre' );
221
+
222
+        // If it's a POST and the `wl-save-configuration` action is set, save the configuration.
223
+        if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) {
224
+
225
+            // Check the nonce and the user capabilities.
226
+            check_admin_referer( 'wl-save-configuration' );
227
+
228
+            // Check if the user has the right privileges.
229
+            if ( ! current_user_can( 'manage_options' ) ) {
230
+                wp_die( esc_html__( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) );
231
+            }
232
+
233
+            // Save the configuration.
234
+            $this->save_configuration( $_POST );
235
+
236
+            // Redirect to the admin's page.
237
+            wp_safe_redirect( admin_url() );
238
+            exit();
239
+        }
240
+
241
+        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
242
+        $language_select = $this->language_select_element;
243
+        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
244
+        $country_select = $this->country_select_element;
245
+
246
+        include plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-setup.php';
247
+
248
+        exit;
249
+    }
250
+
251
+    /**
252
+     * Save WordLift's configuration using the provided parameters.
253
+     *
254
+     * @param array $params An array of configuration parameters.
255
+     *
256
+     * @since 3.9.0
257
+     */
258
+    public function save_configuration( $params ) {
259
+
260
+        // We have the following parameters:
261
+        // `key`, holding WL's key,
262
+        // `vocabulary`, holding the vocabulary path,
263
+        // `wl-country-code` with the country code (e.g. `us`),
264
+        // `share-diagnostic`, the user preferences about sharing data with us.
265
+        // `user_type`, the user type either `personal` or `company`,
266
+        // `name`, with the `personal` or `company`'s name,
267
+        // `logo`, the attachment id for the `personal` or `company` entity.
268
+
269
+        // Store the key:
270
+        Wordlift_Configuration_Service::get_instance()->set_key( $params['key'] );
271
+
272
+        // Store the vocabulary path:
273
+        Wordlift_Configuration_Service::get_instance()->set_entity_base_path( $params['vocabulary'] );
274
+
275
+        // Store the site's country:
276
+        Wordlift_Configuration_Service::get_instance()->set_country_code( $params['wl-country-code'] );
277
+
278
+        // Store the preferences in variable, because if the checkbox is not checked
279
+        // the `share-diagnostic` will not exists in `$params` array.
280
+        $share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes';
281
+
282
+        // Store the diagnostic preferences:
283
+        Wordlift_Configuration_Service::get_instance()->set_diagnostic_preferences( $share_diagnostic_preferences );
284
+
285
+        // Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
286
+        $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' );
287
+
288
+        // Create an entity for the publisher.
289
+        $publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' );
290
+
291
+        // Store the publisher entity post id in the configuration.
292
+        Wordlift_Configuration_Service::get_instance()->set_publisher_id( $publisher_post_id );
293
+
294
+        flush_rewrite_rules(); // Needed because of possible change to the entity base path.
295
+
296
+    }
297 297
 
298 298
 }
Please login to merge, or discard this patch.
src/wordlift.php 1 patch
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
  * @since 3.33.6
49 49
  */
50 50
 if ( ! apply_filters( 'wl_is_enabled', true ) ) {
51
-	return;
51
+    return;
52 52
 }
53 53
 
54 54
 require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
@@ -77,33 +77,33 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function activate_wordlift() {
79 79
 
80
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
80
+    $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
81 81
 
82
-	$log->info( 'Activating WordLift...' );
82
+    $log->info( 'Activating WordLift...' );
83 83
 
84
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
85
-	Wordlift_Activator::activate();
84
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
85
+    Wordlift_Activator::activate();
86 86
 
87
-	/**
88
-	 * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
89
-	 *
90
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
91
-	 * @since 3.19.2
92
-	 */
93
-	Wordlift_Http_Api::activate();
87
+    /**
88
+     * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
89
+     *
90
+     * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
91
+     * @since 3.19.2
92
+     */
93
+    Wordlift_Http_Api::activate();
94 94
 
95
-	// Ensure the post type is registered before flushing the rewrite rules.
96
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
97
-	flush_rewrite_rules();
98
-	/**
99
-	 * @since 3.27.7
100
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
101
-	 */
102
-	Top_Entities::activate();
95
+    // Ensure the post type is registered before flushing the rewrite rules.
96
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
97
+    flush_rewrite_rules();
98
+    /**
99
+     * @since 3.27.7
100
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1214
101
+     */
102
+    Top_Entities::activate();
103 103
 
104
-	if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) {
105
-		wp_schedule_event( time(), 'daily', 'wl_daily_cron' );
106
-	}
104
+    if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) {
105
+        wp_schedule_event( time(), 'daily', 'wl_daily_cron' );
106
+    }
107 107
 
108 108
 }
109 109
 
@@ -113,23 +113,23 @@  discard block
 block discarded – undo
113 113
  */
114 114
 function deactivate_wordlift() {
115 115
 
116
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
117
-	Wordlift_Deactivator::deactivate();
118
-	Wordlift_Http_Api::deactivate();
119
-	Ttl_Cache_Cleaner::deactivate();
120
-	/**
121
-	 * @since 3.27.7
122
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
123
-	 */
124
-	Top_Entities::deactivate();
125
-	/**
126
-	 * @since 3.27.8
127
-	 * Remove notification flag on deactivation.
128
-	 */
129
-	Key_Validation_Notice::remove_notification_flag();
130
-	flush_rewrite_rules();
131
-
132
-	wp_clear_scheduled_hook( 'wl_daily_cron' );
116
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
117
+    Wordlift_Deactivator::deactivate();
118
+    Wordlift_Http_Api::deactivate();
119
+    Ttl_Cache_Cleaner::deactivate();
120
+    /**
121
+     * @since 3.27.7
122
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1214
123
+     */
124
+    Top_Entities::deactivate();
125
+    /**
126
+     * @since 3.27.8
127
+     * Remove notification flag on deactivation.
128
+     */
129
+    Key_Validation_Notice::remove_notification_flag();
130
+    flush_rewrite_rules();
131
+
132
+    wp_clear_scheduled_hook( 'wl_daily_cron' );
133 133
 
134 134
 }
135 135
 
@@ -152,84 +152,84 @@  discard block
 block discarded – undo
152 152
  * @since    1.0.0
153 153
  */
154 154
 function run_wordlift() {
155
-	/**
156
-	 * Filter: wl_feature__enable__widgets.
157
-	 *
158
-	 * @param bool whether the widgets needed to be registered, defaults to true.
159
-	 *
160
-	 * @return bool
161
-	 * @since 3.27.6
162
-	 */
163
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
164
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
165
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
166
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
167
-	}
168
-	add_filter( 'widget_text', 'do_shortcode' );
169
-
170
-	/**
171
-	 * Filter: wl_feature__enable__analysis
172
-	 *
173
-	 * @param bool Whether to send api request to analysis or not
174
-	 *
175
-	 * @return bool
176
-	 * @since 3.27.6
177
-	 */
178
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
179
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
180
-	} else {
181
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
182
-	}
183
-
184
-	$plugin = new Wordlift();
185
-	$plugin->run();
186
-
187
-	// Initialize the TTL Cache Cleaner.
188
-	new Ttl_Cache_Cleaner();
189
-
190
-	// Load the new Post Adapter.
191
-	new Post_Adapter();
192
-
193
-	// Load the API Data Hooks.
194
-	new Api_Data_Hooks();
195
-
196
-	add_action(
197
-		'plugins_loaded',
198
-		function () {
199
-			// All features from registry should be initialized here.
200
-			$features_registry = Features_Registry::get_instance();
201
-			$features_registry->initialize_all_features();
202
-		},
203
-		5
204
-	);
205
-
206
-	add_action(
207
-		'plugins_loaded',
208
-		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
209
-		function () use ( $plugin ) {
210
-
211
-			new Wordlift_Products_Navigator_Shortcode_REST();
212
-
213
-			// Register the Dataset module, requires `$api_service`.
214
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
215
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
216
-
217
-			/*
155
+    /**
156
+     * Filter: wl_feature__enable__widgets.
157
+     *
158
+     * @param bool whether the widgets needed to be registered, defaults to true.
159
+     *
160
+     * @return bool
161
+     * @since 3.27.6
162
+     */
163
+    if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
164
+        add_action( 'widgets_init', 'wl_register_chord_widget' );
165
+        add_action( 'widgets_init', 'wl_register_geo_widget' );
166
+        add_action( 'widgets_init', 'wl_register_timeline_widget' );
167
+    }
168
+    add_filter( 'widget_text', 'do_shortcode' );
169
+
170
+    /**
171
+     * Filter: wl_feature__enable__analysis
172
+     *
173
+     * @param bool Whether to send api request to analysis or not
174
+     *
175
+     * @return bool
176
+     * @since 3.27.6
177
+     */
178
+    if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
179
+        add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
180
+    } else {
181
+        add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
182
+    }
183
+
184
+    $plugin = new Wordlift();
185
+    $plugin->run();
186
+
187
+    // Initialize the TTL Cache Cleaner.
188
+    new Ttl_Cache_Cleaner();
189
+
190
+    // Load the new Post Adapter.
191
+    new Post_Adapter();
192
+
193
+    // Load the API Data Hooks.
194
+    new Api_Data_Hooks();
195
+
196
+    add_action(
197
+        'plugins_loaded',
198
+        function () {
199
+            // All features from registry should be initialized here.
200
+            $features_registry = Features_Registry::get_instance();
201
+            $features_registry->initialize_all_features();
202
+        },
203
+        5
204
+    );
205
+
206
+    add_action(
207
+        'plugins_loaded',
208
+        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
209
+        function () use ( $plugin ) {
210
+
211
+            new Wordlift_Products_Navigator_Shortcode_REST();
212
+
213
+            // Register the Dataset module, requires `$api_service`.
214
+            require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
215
+            require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
216
+
217
+            /*
218 218
 			* Require the Entity annotation cleanup module.
219 219
 			*
220 220
 			* @since 3.34.6
221 221
 			*/
222
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
222
+            require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
223 223
 
224
-			/*
224
+            /*
225 225
 			* Import LOD entities.
226 226
 			*
227 227
 			* @since 3.35.0
228 228
 			*/
229
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php';
229
+            require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php';
230 230
 
231
-		}
232
-	);
231
+        }
232
+    );
233 233
 
234 234
 }
235 235
 
@@ -243,45 +243,45 @@  discard block
 block discarded – undo
243 243
  */
244 244
 function wordlift_plugin_autoload_register() {
245 245
 
246
-	spl_autoload_register(
247
-		function ( $class_name ) {
246
+    spl_autoload_register(
247
+        function ( $class_name ) {
248 248
 
249
-			// Bail out if these are not our classes.
250
-			if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
251
-				return false;
252
-			}
249
+            // Bail out if these are not our classes.
250
+            if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
251
+                return false;
252
+            }
253 253
 
254
-			$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
254
+            $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
255 255
 
256
-			preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
256
+            preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
257 257
 
258
-			$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
259
-			$file = 'class-' . $matches[2] . '.php';
258
+            $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
259
+            $file = 'class-' . $matches[2] . '.php';
260 260
 
261
-			$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
261
+            $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
262 262
 
263
-			if ( ! file_exists( $full_path ) ) {
264
-				return false;
265
-			}
263
+            if ( ! file_exists( $full_path ) ) {
264
+                return false;
265
+            }
266 266
 
267
-			require_once $full_path;
267
+            require_once $full_path;
268 268
 
269
-			return true;
270
-		}
271
-	);
269
+            return true;
270
+        }
271
+    );
272 272
 
273 273
 }
274 274
 
275 275
 function wl_block_categories( $categories ) {
276
-	return array_merge(
277
-		$categories,
278
-		array(
279
-			array(
280
-				'slug'  => 'wordlift',
281
-				'title' => __( 'WordLift', 'wordlift' ),
282
-			),
283
-		)
284
-	);
276
+    return array_merge(
277
+        $categories,
278
+        array(
279
+            array(
280
+                'slug'  => 'wordlift',
281
+                'title' => __( 'WordLift', 'wordlift' ),
282
+            ),
283
+        )
284
+    );
285 285
 }
286 286
 
287 287
 /**
@@ -289,19 +289,19 @@  discard block
 block discarded – undo
289 289
  * this has to be removed when removing the legacy fields from the ui.
290 290
  */
291 291
 function wl_enqueue_leaflet( $in_footer = false ) {
292
-	// Leaflet.
293
-	wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
294
-	wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
292
+    // Leaflet.
293
+    wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
294
+    wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
295 295
 }
296 296
 
297 297
 add_filter( 'block_categories', 'wl_block_categories', 10 );
298 298
 
299 299
 // Temporary fix for a typo in WooCommerce Extension.
300 300
 add_filter(
301
-	'wl_feature__enable__dataset',
302
-	function ( $value ) {
303
-		return apply_filters( 'wl_features__enable__dataset', $value );
304
-	}
301
+    'wl_feature__enable__dataset',
302
+    function ( $value ) {
303
+        return apply_filters( 'wl_features__enable__dataset', $value );
304
+    }
305 305
 );
306 306
 
307 307
 require_once __DIR__ . '/modules/food-kg/load.php';
@@ -315,35 +315,35 @@  discard block
 block discarded – undo
315 315
 require_once __DIR__ . '/modules/raptive-setup/load.php';
316 316
 
317 317
 function _wl_update_plugins_raptive_domain( $update, $plugin_data, $plugin_file ) {
318
-	// Bail out if it's not our plugin.
319
-	$update_uri = $plugin_data['UpdateURI'];
320
-	if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) {
321
-		return $update;
322
-	}
323
-
324
-	$response = wp_remote_get( "$update_uri?nocache=" . time() );
325
-
326
-	if ( is_wp_error( $response ) ) {
327
-		return $update;
328
-	}
329
-
330
-	try {
331
-		return json_decode( wp_remote_retrieve_body( $response ) );
332
-	} catch ( Exception $e ) {
333
-		return $update;
334
-	}
318
+    // Bail out if it's not our plugin.
319
+    $update_uri = $plugin_data['UpdateURI'];
320
+    if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) {
321
+        return $update;
322
+    }
323
+
324
+    $response = wp_remote_get( "$update_uri?nocache=" . time() );
325
+
326
+    if ( is_wp_error( $response ) ) {
327
+        return $update;
328
+    }
329
+
330
+    try {
331
+        return json_decode( wp_remote_retrieve_body( $response ) );
332
+    } catch ( Exception $e ) {
333
+        return $update;
334
+    }
335 335
 }
336 336
 
337 337
 add_action(
338
-	'update_plugins_adthrive.wordlift.io',
339
-	'_wl_update_plugins_raptive_domain',
340
-	10,
341
-	3
338
+    'update_plugins_adthrive.wordlift.io',
339
+    '_wl_update_plugins_raptive_domain',
340
+    10,
341
+    3
342 342
 );
343 343
 
344 344
 add_action(
345
-	'update_plugins_raptive.wordlift.io',
346
-	'_wl_update_plugins_raptive_domain',
347
-	10,
348
-	3
345
+    'update_plugins_raptive.wordlift.io',
346
+    '_wl_update_plugins_raptive_domain',
347
+    10,
348
+    3
349 349
 );
Please login to merge, or discard this patch.
src/modules/raptive-setup/load.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -9,15 +9,15 @@  discard block
 block discarded – undo
9 9
 
10 10
 // Exit if this is not a Raptive install.
11 11
 if ( ! defined( 'WL_RAPTIVE' ) || ! WL_RAPTIVE ) {
12
-	return;
12
+    return;
13 13
 }
14 14
 
15 15
 function __wl_raptive_admin_setup() {
16 16
 
17
-	wp_print_scripts( WL_ANGULAR_APP_SCRIPT_HANDLE );
18
-	$iframe_src = WL_ANGULAR_APP_URL . '#/raptive/setup/welcome';
19
-	// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
20
-	echo "
17
+    wp_print_scripts( WL_ANGULAR_APP_SCRIPT_HANDLE );
18
+    $iframe_src = WL_ANGULAR_APP_URL . '#/raptive/setup/welcome';
19
+    // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
20
+    echo "
21 21
 			<style>
22 22
 			    #wlx-plugin-app {
23 23
 					border: 0;
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 			<iframe id='wlx-plugin-app' src='$iframe_src'></iframe>
34 34
             ";
35 35
 
36
-	exit;
36
+    exit;
37 37
 }
38 38
 
39 39
 add_action( 'wl_admin_setup__pre', '__wl_raptive_admin_setup' );
Please login to merge, or discard this patch.
src/modules/app/load.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -14,36 +14,36 @@
 block discarded – undo
14 14
 use Wordlift\Modules\Common\Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
15 15
 
16 16
 if ( ! defined( 'WL_ANGULAR_APP_URL' ) ) {
17
-	define( 'WL_ANGULAR_APP_URL', esc_url( plugin_dir_url( __DIR__ ) . 'app/app/iframe.html' ) . '?v=' . WORDLIFT_VERSION );
17
+    define( 'WL_ANGULAR_APP_URL', esc_url( plugin_dir_url( __DIR__ ) . 'app/app/iframe.html' ) . '?v=' . WORDLIFT_VERSION );
18 18
 }
19 19
 
20 20
 if ( ! defined( 'WL_ANGULAR_APP_SCRIPT_HANDLE' ) ) {
21
-	define( 'WL_ANGULAR_APP_SCRIPT_HANDLE', 'wl-angular-app' );
21
+    define( 'WL_ANGULAR_APP_SCRIPT_HANDLE', 'wl-angular-app' );
22 22
 }
23 23
 
24 24
 function __wl_app__init() {
25 25
 
26
-	// Load the rest of the module only on admin calls.
27
-	if ( ! is_admin() ) {
28
-		return;
29
-	}
30
-
31
-	// Autoloader for plugin itself.
32
-	if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
33
-		require_once __DIR__ . '/vendor/autoload.php';
34
-	}
35
-
36
-	/**
37
-	 * @var $app Plugin_App
38
-	 */
39
-	$container_builder = new ContainerBuilder();
40
-	$loader            = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) );
41
-	$loader->load( 'services.yml' );
42
-	$container_builder->compile();
43
-
44
-	/** @var Plugin_App $app */
45
-	$app = $container_builder->get( Plugin_App::class );
46
-	$app->register_handle();
26
+    // Load the rest of the module only on admin calls.
27
+    if ( ! is_admin() ) {
28
+        return;
29
+    }
30
+
31
+    // Autoloader for plugin itself.
32
+    if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
33
+        require_once __DIR__ . '/vendor/autoload.php';
34
+    }
35
+
36
+    /**
37
+     * @var $app Plugin_App
38
+     */
39
+    $container_builder = new ContainerBuilder();
40
+    $loader            = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) );
41
+    $loader->load( 'services.yml' );
42
+    $container_builder->compile();
43
+
44
+    /** @var Plugin_App $app */
45
+    $app = $container_builder->get( Plugin_App::class );
46
+    $app->register_handle();
47 47
 }
48 48
 
49 49
 add_action( 'init', '__wl_app__init' );
Please login to merge, or discard this patch.
src/modules/app/includes/Plugin_App.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -4,41 +4,41 @@
 block discarded – undo
4 4
 
5 5
 class Plugin_App {
6 6
 
7
-	public function register_handle() {
7
+    public function register_handle() {
8 8
 
9
-		wp_register_script(
10
-			WL_ANGULAR_APP_SCRIPT_HANDLE,
11
-			plugin_dir_url( __DIR__ ) . 'js/app.js',
12
-			array(),
13
-			WORDLIFT_VERSION,
14
-			true
15
-		);
16
-		$settings = wp_json_encode( $this->get_settings() );
17
-		wp_add_inline_script( WL_ANGULAR_APP_SCRIPT_HANDLE, "var _wlPluginAppSettings = {$settings};" );
9
+        wp_register_script(
10
+            WL_ANGULAR_APP_SCRIPT_HANDLE,
11
+            plugin_dir_url( __DIR__ ) . 'js/app.js',
12
+            array(),
13
+            WORDLIFT_VERSION,
14
+            true
15
+        );
16
+        $settings = wp_json_encode( $this->get_settings() );
17
+        wp_add_inline_script( WL_ANGULAR_APP_SCRIPT_HANDLE, "var _wlPluginAppSettings = {$settings};" );
18 18
 
19
-		// add_action(
20
-		// 'admin_enqueue_scripts',
21
-		// array( $this, 'print_settings' ),
22
-		// PHP_INT_MAX // This hook is running at last because we want to check if it was enqueued.
23
-		// );
24
-	}
19
+        // add_action(
20
+        // 'admin_enqueue_scripts',
21
+        // array( $this, 'print_settings' ),
22
+        // PHP_INT_MAX // This hook is running at last because we want to check if it was enqueued.
23
+        // );
24
+    }
25 25
 
26
-	/**
27
-	 * @return mixed|null
28
-	 */
29
-	private function get_settings() {
30
-		return apply_filters(
31
-			'wl_plugin_app_settings',
32
-			array(
33
-				// @see https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
34
-				'wp_api_nonce'      => wp_create_nonce( 'wp_rest' ),
35
-				'wp_api_base'       => untrailingslashit( rest_url() ),
36
-				// Load wordlift api url and key.
37
-				'wl_api_base'       => apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ),
38
-				'wl_api_key'        => \Wordlift_Configuration_Service::get_instance()->get_key(),
39
-				'wl_dashboard_link' => admin_url( 'admin.php?page=wl_admin_menu' ),
40
-			)
41
-		);
42
-	}
26
+    /**
27
+     * @return mixed|null
28
+     */
29
+    private function get_settings() {
30
+        return apply_filters(
31
+            'wl_plugin_app_settings',
32
+            array(
33
+                // @see https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
34
+                'wp_api_nonce'      => wp_create_nonce( 'wp_rest' ),
35
+                'wp_api_base'       => untrailingslashit( rest_url() ),
36
+                // Load wordlift api url and key.
37
+                'wl_api_base'       => apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ),
38
+                'wl_api_key'        => \Wordlift_Configuration_Service::get_instance()->get_key(),
39
+                'wl_dashboard_link' => admin_url( 'admin.php?page=wl_admin_menu' ),
40
+            )
41
+        );
42
+    }
43 43
 
44 44
 }
Please login to merge, or discard this patch.
src/modules/redeem-code/load.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -19,21 +19,21 @@
 block discarded – undo
19 19
  * @return void
20 20
  */
21 21
 function __wl_redeem_code() {
22
-	// Autoloader for plugin itself.
22
+    // Autoloader for plugin itself.
23 23
 	
24
-	if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
25
-		require_once __DIR__ . '/vendor/autoload.php';
26
-	}
24
+    if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
25
+        require_once __DIR__ . '/vendor/autoload.php';
26
+    }
27 27
 
28
-	$container_builder = new ContainerBuilder();
29
-	$loader            = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) );
30
-	$loader->load( 'services.yml' );
31
-	$container_builder->compile();
28
+    $container_builder = new ContainerBuilder();
29
+    $loader            = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) );
30
+    $loader->load( 'services.yml' );
31
+    $container_builder->compile();
32 32
 
33
-	/**
34
-	 * @var $rest_controller Rest_Controller
35
-	 */
36
-	$rest_controller = $container_builder->get( 'Wordlift\Modules\Redeem_Code\Rest_Controller' );
37
-	$rest_controller->register_hooks();
33
+    /**
34
+     * @var $rest_controller Rest_Controller
35
+     */
36
+    $rest_controller = $container_builder->get( 'Wordlift\Modules\Redeem_Code\Rest_Controller' );
37
+    $rest_controller->register_hooks();
38 38
 }
39 39
 __wl_redeem_code();
Please login to merge, or discard this patch.
src/modules/redeem-code/includes/Rest_Controller.php 1 patch
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -7,150 +7,150 @@
 block discarded – undo
7 7
 
8 8
 class Rest_Controller {
9 9
 
10
-	/**
11
-	 * @var Wordlift_Configuration_Service
12
-	 */
13
-
14
-	private $configuration_service;
15
-
16
-	public function __construct() {
17
-		$this->configuration_service = Wordlift_Configuration_Service::get_instance();
18
-	}
19
-
20
-	public function register_hooks() {
21
-		add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
22
-	}
23
-
24
-	public function rest_api_init() {
25
-		register_rest_route(
26
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
27
-			'/redeem-codes',
28
-			array(
29
-				'methods'             => 'POST',
30
-				'callback'            => array( $this, 'create_sync' ),
31
-				'args'                => array(
32
-					'redeem_code'        => array(
33
-						'required'          => true,
34
-						'validate_callback' => 'rest_validate_request_arg',
35
-					),
36
-					'enable_diagnostics' => array(
37
-						'required'          => true,
38
-						'validate_callback' => 'rest_validate_request_arg',
39
-					),
40
-				),
41
-				'permission_callback' => function () {
42
-					return current_user_can( 'manage_options' );
43
-				},
44
-			)
45
-		);
46
-
47
-		/**
48
-		 * POST /redeem-codes
49
-		 * Accept: application/json
50
-		 * Content-Type: application/json
51
-		 *
52
-		 * { "redeem_code": "a_redeem_code" }
53
-		 *
54
-		 *
55
-		 * Successful Response:
56
-		 *
57
-		 * Content-Type: application/json
58
-		 *
59
-		 * { "key": "a_key" }
60
-		 *
61
-		 *
62
-		 * Unsuccessful Response:
63
-		 *
64
-		 * Content-Type: application/json
65
-		 *
66
-		 * {
67
-		 * "title": "Invalid Redeem Code",
68
-		 * "status": 404,
69
-		 * "detail": "The redeem code is invalid, check for typos or try with another code."
70
-		 * }
71
-		 *
72
-		 * or
73
-		 *
74
-		 * {
75
-		 * "title": "Redeem Code already used",
76
-		 * "status": 409,
77
-		 * "detail": "The redeem code has been used already, try with another redeem code."
78
-		 * }
79
-		 */
80
-	}
81
-
82
-	public function create_sync( $request ) {
83
-		$redeem_code        = $request->get_param( 'redeem_code' );
84
-		$enable_diagnostics = $request->get_param( 'enable_diagnostics' );
85
-
86
-		$url = trailingslashit( WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ) . 'redeem-codes';
87
-
88
-		$body = wp_json_encode(
89
-			array(
90
-				'redeem_code' => $redeem_code,
91
-			)
92
-		);
93
-
94
-		$response = wp_remote_post(
95
-			$url,
96
-			array(
97
-				'timeout'    => 60,
98
-				'user-agent' => User_Agent::get_user_agent(),
99
-				'headers'    => array(
100
-					'Content-Type' => 'application/json',
101
-					'Expect'       => '',
102
-				),
103
-				'body'       => $body,
104
-			)
105
-		);
106
-
107
-		$code    = wp_remote_retrieve_response_code( $response );
108
-		$message = wp_remote_retrieve_response_message( $response );
109
-
110
-		if ( empty( $code ) || ! is_numeric( $code ) ) {
111
-			wp_send_json_error( $message, $code );
112
-		}
113
-
114
-		if ( 409 === $code ) {
115
-			return new \WP_REST_Response(
116
-				array(
117
-					'title'  => 'Redeem Code already used',
118
-					'status' => $code,
119
-					'detail' => 'The redeem code has been used already, try with another redeem code.',
120
-				),
121
-				$code
122
-			);
123
-		}
124
-
125
-		if ( 404 === $code ) {
126
-			return new \WP_REST_Response(
127
-				array(
128
-					'title'  => 'Invalid Redeem Code',
129
-					'status' => $code,
130
-					'detail' => 'The redeem code is invalid, check for typos or try with another code.',
131
-				),
132
-				$code
133
-			);
134
-		}
135
-
136
-		if ( 500 === $code ) {
137
-			return new \WP_REST_Response( json_decode( $response['body'] ), $code );
138
-		}
139
-
140
-		$key_array = json_decode( $response['body'] );
141
-		$key       = $key_array->key;
142
-
143
-		$this->configuration_service->set_key( $key );
144
-		$this->configuration_service->set_diagnostic_preferences( $enable_diagnostics );
145
-
146
-		return new \WP_REST_Response(
147
-			array(
148
-				'key'      => $key,
149
-				'status'   => $this->configuration_service->get_dataset_uri(),
150
-				'language' => 'en',
151
-			),
152
-			$code
153
-		);
154
-	}
10
+    /**
11
+     * @var Wordlift_Configuration_Service
12
+     */
13
+
14
+    private $configuration_service;
15
+
16
+    public function __construct() {
17
+        $this->configuration_service = Wordlift_Configuration_Service::get_instance();
18
+    }
19
+
20
+    public function register_hooks() {
21
+        add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
22
+    }
23
+
24
+    public function rest_api_init() {
25
+        register_rest_route(
26
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
27
+            '/redeem-codes',
28
+            array(
29
+                'methods'             => 'POST',
30
+                'callback'            => array( $this, 'create_sync' ),
31
+                'args'                => array(
32
+                    'redeem_code'        => array(
33
+                        'required'          => true,
34
+                        'validate_callback' => 'rest_validate_request_arg',
35
+                    ),
36
+                    'enable_diagnostics' => array(
37
+                        'required'          => true,
38
+                        'validate_callback' => 'rest_validate_request_arg',
39
+                    ),
40
+                ),
41
+                'permission_callback' => function () {
42
+                    return current_user_can( 'manage_options' );
43
+                },
44
+            )
45
+        );
46
+
47
+        /**
48
+         * POST /redeem-codes
49
+         * Accept: application/json
50
+         * Content-Type: application/json
51
+         *
52
+         * { "redeem_code": "a_redeem_code" }
53
+         *
54
+         *
55
+         * Successful Response:
56
+         *
57
+         * Content-Type: application/json
58
+         *
59
+         * { "key": "a_key" }
60
+         *
61
+         *
62
+         * Unsuccessful Response:
63
+         *
64
+         * Content-Type: application/json
65
+         *
66
+         * {
67
+         * "title": "Invalid Redeem Code",
68
+         * "status": 404,
69
+         * "detail": "The redeem code is invalid, check for typos or try with another code."
70
+         * }
71
+         *
72
+         * or
73
+         *
74
+         * {
75
+         * "title": "Redeem Code already used",
76
+         * "status": 409,
77
+         * "detail": "The redeem code has been used already, try with another redeem code."
78
+         * }
79
+         */
80
+    }
81
+
82
+    public function create_sync( $request ) {
83
+        $redeem_code        = $request->get_param( 'redeem_code' );
84
+        $enable_diagnostics = $request->get_param( 'enable_diagnostics' );
85
+
86
+        $url = trailingslashit( WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ) . 'redeem-codes';
87
+
88
+        $body = wp_json_encode(
89
+            array(
90
+                'redeem_code' => $redeem_code,
91
+            )
92
+        );
93
+
94
+        $response = wp_remote_post(
95
+            $url,
96
+            array(
97
+                'timeout'    => 60,
98
+                'user-agent' => User_Agent::get_user_agent(),
99
+                'headers'    => array(
100
+                    'Content-Type' => 'application/json',
101
+                    'Expect'       => '',
102
+                ),
103
+                'body'       => $body,
104
+            )
105
+        );
106
+
107
+        $code    = wp_remote_retrieve_response_code( $response );
108
+        $message = wp_remote_retrieve_response_message( $response );
109
+
110
+        if ( empty( $code ) || ! is_numeric( $code ) ) {
111
+            wp_send_json_error( $message, $code );
112
+        }
113
+
114
+        if ( 409 === $code ) {
115
+            return new \WP_REST_Response(
116
+                array(
117
+                    'title'  => 'Redeem Code already used',
118
+                    'status' => $code,
119
+                    'detail' => 'The redeem code has been used already, try with another redeem code.',
120
+                ),
121
+                $code
122
+            );
123
+        }
124
+
125
+        if ( 404 === $code ) {
126
+            return new \WP_REST_Response(
127
+                array(
128
+                    'title'  => 'Invalid Redeem Code',
129
+                    'status' => $code,
130
+                    'detail' => 'The redeem code is invalid, check for typos or try with another code.',
131
+                ),
132
+                $code
133
+            );
134
+        }
135
+
136
+        if ( 500 === $code ) {
137
+            return new \WP_REST_Response( json_decode( $response['body'] ), $code );
138
+        }
139
+
140
+        $key_array = json_decode( $response['body'] );
141
+        $key       = $key_array->key;
142
+
143
+        $this->configuration_service->set_key( $key );
144
+        $this->configuration_service->set_diagnostic_preferences( $enable_diagnostics );
145
+
146
+        return new \WP_REST_Response(
147
+            array(
148
+                'key'      => $key,
149
+                'status'   => $this->configuration_service->get_dataset_uri(),
150
+                'language' => 'en',
151
+            ),
152
+            $code
153
+        );
154
+    }
155 155
 
156 156
 }
Please login to merge, or discard this patch.